/*----------------------------------------------- * * Vector Quantization Image Compression (Host) * */ #include #include #include "vq.h" void vq( /* image stored in vector order */ const int image[FRAMESIZE], const int codebook[VECTORSIZE][ CODEBOOKSIZE], int codedimage[VECTORS]) { int vec, pix, error, code, bestcode, besterror; for (vec = 0; vec < VECTORS; vec++) { for (code = 0; code < CODEBOOKSIZE; code++) { error = 0; for (pix = 0; pix < VECTORSIZE; pix++) { #ifdef RMSERROR /* error must be large enough to hold it */ error += sqr(image[vec * VECTORSIZE + pix] - codebook[pix][ code]); #else /* RMSERROR */ error += abs(image[vec * VECTORSIZE + pix] - codebook[pix][ code]); #endif /* RMSERROR */ } if (code == 0) { besterror = error; bestcode = code; } else if (error < besterror) { besterror = error; bestcode = code; } } codedimage[vec] = bestcode; } }