/*----------------------------------------------- * * Vector Quantization Image Compression (C-RAM) * */ #include #include "vq.h" #define TRACING user1 /* PEs = VECTORS -> 16MB */ void vq( /* image stored in vector order, 1 vector/PE */ const cuint image[VECTORSIZE], const int codebook[VECTORSIZE][ CODEBOOKSIZE], cuint &codedimage) { int pix, code; cuint error(16, UNALIGNED), besterror(16, UNALIGNED); for (code = 0; code < CODEBOOKSIZE; code++) { if(traces[TRACING]) cRuntime("outer loop"); error = 0; for (pix = 0; pix < VECTORSIZE; pix++) { #ifdef RMSERROR /* error must be large enough to hold it */ error += sqr(image[pix] - codebook[pix][ code]); #else /* RMSERROR */ error += abs(image[pix] - codebook[pix][ code]); #endif /* RMSERROR */ } if (code == 0) { besterror = error; codedimage = code; } else { cif(error < besterror) besterror = error; codedimage = code; cend } } }