X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=image.cpp;h=937f486bfbc01cbe3676b54ce67be52f84b1a754;hb=52eaaa2f3749692d587a41145da900f9014e9002;hp=ce37c190c097cff6a624d4870e9dca5a58adfad3;hpb=4cebb746f86d7ff67d816e15a68921885c2958c9;p=apitrace diff --git a/image.cpp b/image.cpp index ce37c19..937f486 100644 --- a/image.cpp +++ b/image.cpp @@ -26,6 +26,7 @@ #include +#include #include #include @@ -164,7 +165,7 @@ Image::writePNG(const char *filename) const { png_set_IHDR(png_ptr, info_ptr, width, height, 8, PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); - png_set_compression_level(png_ptr, Z_BEST_COMPRESSION); + png_set_compression_level(png_ptr, Z_DEFAULT_COMPRESSION); png_write_info(png_ptr, info_ptr); @@ -273,4 +274,41 @@ no_fp: } +double Image::compare(Image &ref) +{ + if (width != ref.width || + height != ref.height) { + return 0.0; + } + + const unsigned char *pSrc = start(); + const unsigned char *pRef = ref.start(); + + unsigned long long error = 0; + for (unsigned y = 0; y < height; ++y) { + for (unsigned x = 0; x < width; ++x) { + // FIXME: Ignore alpha channel until we are able to pick a visual + // that matches the traces + for (unsigned c = 0; c < 3; ++c) { + int delta = pSrc[x*4 + c] - pRef[x*4 + c]; + error += delta*delta; + } + } + + pSrc += stride(); + pRef += ref.stride(); + } + + double numerator = error*2 + 1; + double denominator = height*width*3ULL*255ULL*255ULL*2; + double quotient = numerator/denominator; + + // Precision in bits + double precision = -log(quotient)/log(2.0); + + return precision; +} + + + } /* namespace Image */