To je ta druha funkce, ktera pouziva prave tu get_pixel. Radeji to sem dam, aby bylo jasnejsi, jak jsou ulozena data v tom obrazku. Pocet comps=3. Takze to nacita data, podle mne, jako RGBRGB... (0,3,6,... az do sirka*vyska orbrazku). Ale mozna, ze to chapu spatne :)
// Compute image error metrics.
static void image_compare(image_compare_results *pResults, int width, int height, const uint8 *pComp_image, int comp_image_comps, const uint8 *pUncomp_image_data, int uncomp_comps, int luma_only)
{
double hist[256];
double sum = 0.0f, sum2 = 0.0f;
double total_values;
const uint first_channel = 0, num_channels = 3;
int x, y;
uint i;
memset(hist, 0, sizeof(hist));
for (y = 0; y < height; y++)
{
for (x = 0; x < width; x++)
{
uint c;
int a[3];
int b[3];
get_pixel(a, pComp_image + (y * width + x) * comp_image_comps, luma_only, comp_image_comps);
get_pixel(b, pUncomp_image_data + (y * width + x) * uncomp_comps, luma_only, uncomp_comps);
for (c = 0; c < num_channels; c++)
hist[labs(a[first_channel + c] - b[first_channel + c])]++;
}
}
pResults->max_err = 0;
for (i = 0; i < 256; i++)
{
double x;
if (!hist[i])
continue;
if (i > pResults->max_err)
pResults->max_err = i;
x = i * hist[i];
sum += x;
sum2 += i * x;
}
// See http://bmrc.berkeley.edu/…nt/psnr.html
total_values = width * height;
pResults->mean = sum / total_values;
pResults->mean_squared = sum2 / total_values;
pResults->root_mean_squared = sqrt(pResults->mean_squared);
if (!pResults->root_mean_squared)
pResults->peak_snr = 1e+10f;
else
pResults->peak_snr = log10(255.0f / pResults->root_mean_squared) * 20.0f;
}