static void compute_diff(Pnm_ppm image1, Pnm_ppm image2) { int sm_width = compare(image1->width, image2->width); int sm_height = compare(image1->height, image2->height); const struct A2Methods_T *methods1 = image1 -> methods; const struct A2Methods_T *methods2 = image2 -> methods; float sum = 0; float E; for (int row = 0; row < sm_height; row++) { for (int col = 0; col < sm_width; col++) { Pnm_rgb pixel1 = methods1->at(image1->pixels, col, row); Pnm_rgb pixel2 = methods2->at(image2->pixels, col, row); sum += rgb_diff(pixel1, pixel2); //printf("Sum %f\n\n", sum); } } sum /= (3 * sm_width * sm_height); E = sqrtf(sum); fprintf(stdout, "%1.4f\n", E); }
static uint32_t rgb_to_256(uint32_t c) { uint32_t c1 = rgb_to_16(c); uint32_t bd = rgb_diff(c, col256_to_rgb(c1)); uint32_t res = c1; uint32_t c2 = rgb_to_color_cube(c); uint32_t d = rgb_diff(c, col256_to_rgb(c2)); if (d < bd) bd = d, res = c2; uint32_t c3 = rgb_to_grayscale_gradient(c); d = rgb_diff(c, col256_to_rgb(c3)); if (d < bd) res = c3; return res; }