|
@@ -33,7 +33,7 @@ double pipi_measure_msd(pipi_image_t *i1, pipi_image_t *i2) |
|
|
pipi_format_t f1, f2; |
|
|
pipi_format_t f1, f2; |
|
|
double ret = 0.0; |
|
|
double ret = 0.0; |
|
|
float *p1, *p2; |
|
|
float *p1, *p2; |
|
|
int x, y, w, h; |
|
|
|
|
|
|
|
|
int x, y, w, h, gray; |
|
|
|
|
|
|
|
|
w = i1->w < i2->w ? i1->w : i2->w; |
|
|
w = i1->w < i2->w ? i1->w : i2->w; |
|
|
h = i1->h < i2->h ? i1->h : i2->h; |
|
|
h = i1->h < i2->h ? i1->h : i2->h; |
|
@@ -41,20 +41,54 @@ double pipi_measure_msd(pipi_image_t *i1, pipi_image_t *i2) |
|
|
f1 = i1->last_modified; |
|
|
f1 = i1->last_modified; |
|
|
f2 = i2->last_modified; |
|
|
f2 = i2->last_modified; |
|
|
|
|
|
|
|
|
|
|
|
gray = f1 == PIPI_PIXELS_Y_F32 && f2 == PIPI_PIXELS_Y_F32; |
|
|
|
|
|
|
|
|
/* FIXME: this is not right */ |
|
|
/* FIXME: this is not right */ |
|
|
pipi_get_pixels(i1, PIPI_PIXELS_Y_F32); |
|
|
|
|
|
pipi_get_pixels(i2, PIPI_PIXELS_Y_F32); |
|
|
|
|
|
|
|
|
|
|
|
p1 = (float *)i1->p[PIPI_PIXELS_Y_F32].pixels; |
|
|
|
|
|
p2 = (float *)i2->p[PIPI_PIXELS_Y_F32].pixels; |
|
|
|
|
|
|
|
|
|
|
|
for(y = 0; y < h; y++) |
|
|
|
|
|
for(x = 0; x < w; x++) |
|
|
|
|
|
{ |
|
|
|
|
|
float a = p1[y * i1->w + x]; |
|
|
|
|
|
float b = p2[y * i2->w + x]; |
|
|
|
|
|
ret += (a - b) * (a - b); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if(gray) |
|
|
|
|
|
{ |
|
|
|
|
|
p1 = (float *)i1->p[PIPI_PIXELS_Y_F32].pixels; |
|
|
|
|
|
p2 = (float *)i2->p[PIPI_PIXELS_Y_F32].pixels; |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
pipi_get_pixels(i1, PIPI_PIXELS_RGBA_F32); |
|
|
|
|
|
pipi_get_pixels(i2, PIPI_PIXELS_RGBA_F32); |
|
|
|
|
|
p1 = (float *)i1->p[PIPI_PIXELS_RGBA_F32].pixels; |
|
|
|
|
|
p2 = (float *)i2->p[PIPI_PIXELS_RGBA_F32].pixels; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(gray) |
|
|
|
|
|
{ |
|
|
|
|
|
for(y = 0; y < h; y++) |
|
|
|
|
|
for(x = 0; x < w; x++) |
|
|
|
|
|
{ |
|
|
|
|
|
float a = p1[y * i1->w + x]; |
|
|
|
|
|
float b = p2[y * i2->w + x]; |
|
|
|
|
|
ret += (a - b) * (a - b); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
for(y = 0; y < h; y++) |
|
|
|
|
|
for(x = 0; x < w; x++) |
|
|
|
|
|
{ |
|
|
|
|
|
float a, b, sum = 0.0; |
|
|
|
|
|
|
|
|
|
|
|
a = p1[(y * i1->w + x) * 4]; |
|
|
|
|
|
b = p2[(y * i2->w + x) * 4]; |
|
|
|
|
|
sum += (a - b) * (a - b); |
|
|
|
|
|
|
|
|
|
|
|
a = p1[(y * i1->w + x) * 4 + 1]; |
|
|
|
|
|
b = p2[(y * i2->w + x) * 4 + 1]; |
|
|
|
|
|
sum += (a - b) * (a - b); |
|
|
|
|
|
|
|
|
|
|
|
a = p1[(y * i1->w + x) * 4 + 2]; |
|
|
|
|
|
b = p2[(y * i2->w + x) * 4 + 2]; |
|
|
|
|
|
sum += (a - b) * (a - b); |
|
|
|
|
|
|
|
|
|
|
|
ret += sum / 3; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/* TODO: free pixels if they were allocated */ |
|
|
/* TODO: free pixels if they were allocated */ |
|
|
|
|
|
|
|
|