diff options
author | Jeff Muizelaar <jeff@infidigm.net> | 2006-09-06 23:28:53 +0000 |
---|---|---|
committer | Jeff Muizelaar <jeff@infidigm.net> | 2006-09-06 23:28:53 +0000 |
commit | f6d8d8e8a9b57f8c6ebec9a2f9e82fea8a52403e (patch) | |
tree | c1d76cba71b38c5c5b7865e07d8dbbfe8d3d8557 /buffer-diff.c | |
parent | 1e0195ed5c1d9562af9138ad782fc8ee68443390 (diff) |
Add support for a reference cache file that contains SHA1 hashes of the
reference images. Having the cache avoids the performance hit of reading and
decompressing the reference pngs.
Diffstat (limited to 'buffer-diff.c')
-rw-r--r-- | buffer-diff.c | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/buffer-diff.c b/buffer-diff.c index c87e935..c0fa2eb 100644 --- a/buffer-diff.c +++ b/buffer-diff.c @@ -66,6 +66,7 @@ buffer_diff (unsigned char *buf_a, int channel; uint32_t value_a, value_b; int pixel_differs = 0; + //XXX: it looks like this might overread... value_a = *(uint32_t*)(&(row_a[x*4])); value_b = *(uint32_t*)(&(row_b[x*4])); if (value_a != value_b) { @@ -93,6 +94,21 @@ buffer_diff (unsigned char *buf_a, return pixels_changed; } +static void copy_file(const char *filename_a, const char *filename_b) +{ + char buf[4096]; + FILE *filea = fopen(filename_a, "r"); + FILE *fileb = fopen (filename_b, "wb"); + int count = sizeof(buf); + while (count == sizeof(buf)) { + count = fread(buf, 1, sizeof(buf), filea); + fwrite(buf, 1, count, fileb); + } + fclose(filea); + fclose(fileb); + +} + int image_buf_diff (char *buf_a, int width_a, int height_a, int stride_a, const char *filename_a, @@ -104,6 +120,12 @@ image_buf_diff (char *buf_a, int width_a, int height_a, int stride_a, unsigned char *buf_b, *buf_diff; read_png_status_t status; + if (cache_compare(filename_b, buf_a, height_a * stride_a)) { + copy_file(filename_b, filename_a); + xunlink (filename_diff); + return 0; + } + status = read_png_argb32 (filename_b, &buf_b, &width_b, &height_b, &stride_b); if (status) { // write out the buffer on failure @@ -140,16 +162,7 @@ image_buf_diff (char *buf_a, int width_a, int height_a, int stride_a, write_png_argb32 (buf_a, png_file, width_a, height_a, stride_a); fclose (png_file); } else { - char buf[4096]; - FILE *ref_file = fopen(filename_b, "r"); - FILE *png_file = fopen (filename_a, "wb"); - int count = sizeof(buf); - while (count == sizeof(buf)) { - count = fread(buf, 1, sizeof(buf), ref_file); - fwrite(buf, 1, count, png_file); - } - fclose(ref_file); - fclose(png_file); + copy_file(filename_b, filename_a); xunlink (filename_diff); } |