summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Muizelaar <jeff@freiheit.infidigm.net>2007-09-22 23:16:12 -0400
committerJeff Muizelaar <jeff@freiheit.infidigm.net>2007-09-22 23:16:12 -0400
commitcc98cc9c34bffe90468fa3205b53e86840a45a41 (patch)
tree0c97e06577a1e1460304017cb63a46b16fd12bc2
parent5b4e595a0ab4d44184349efdd9f46f561132c89f (diff)
Report # of pixels and max difference when there are image differences.
-rw-r--r--buffer-diff.c28
-rw-r--r--buffer-diff.h9
-rw-r--r--test-poppler.c20
3 files changed, 34 insertions, 23 deletions
diff --git a/buffer-diff.c b/buffer-diff.c
index cbfe986..f0d2d18 100644
--- a/buffer-diff.c
+++ b/buffer-diff.c
@@ -32,7 +32,7 @@
#include "util.h"
#include "read-cache.h"
-int
+struct diff_results
buffer_diff (unsigned char *buf_a,
unsigned char *buf_b,
unsigned char *buf_diff,
@@ -42,7 +42,7 @@ buffer_diff (unsigned char *buf_a,
{
int x, y;
unsigned char *row_a, *row_b, *row;
- int pixels_changed = 0;
+ struct diff_results results = { .pixels_changed = 0, .max_difference = 0 };
for (y = 0; y < height; y++)
{
@@ -67,19 +67,21 @@ buffer_diff (unsigned char *buf_a,
if (channel_value_a != channel_value_b) {
pixel_differs = 1;
diff = channel_value_a - channel_value_b;
+ if (diff > results.max_difference)
+ results.max_difference = diff;
row[x * 4 + channel] = 128 + diff / 3.0;
}
}
}
if (pixel_differs) {
- pixels_changed++;
+ results.pixels_changed++;
*(uint32_t*)(&(row[x*4])) |= 0xff000000; /* Set ALPHA to 100% (opaque) */
} else {
*(uint32_t*)(&(row[x*4])) = 0xff000000; /* Set ALPHA to 100% (opaque) */
}
}
}
- return pixels_changed;
+ return results;
}
static int copy_file(const char *filename_a, const char *filename_b)
@@ -99,13 +101,13 @@ static int copy_file(const char *filename_a, const char *filename_b)
return 0;
}
-int
+struct diff_results
image_buf_diff (void *buf, int width_a, int height_a, int stride_a,
const char *filename_a,
const char *filename_b,
const char *filename_diff)
{
- int pixels_changed;
+ struct diff_results results = { .pixels_changed = 0 };
unsigned int width_b, height_b, stride_b;
unsigned char *buf_b, *buf_diff;
unsigned char *buf_a = buf;
@@ -114,7 +116,7 @@ image_buf_diff (void *buf, int width_a, int height_a, int stride_a,
if (cache_compare(filename_b, buf_a, height_a * stride_a)) {
if (copy_file(filename_b, filename_a) == 0) {
xunlink (filename_diff);
- return 0;
+ return results;
}
}
@@ -139,10 +141,10 @@ image_buf_diff (void *buf, int width_a, int height_a, int stride_a,
buf_diff = xcalloc (stride_a * height_a, 1);
- pixels_changed = buffer_diff (buf_a, buf_b, buf_diff,
+ results = buffer_diff (buf_a, buf_b, buf_diff,
width_a, height_a, stride_a);
- if (pixels_changed) {
+ if (results.pixels_changed) {
FILE *png_file = fopen (filename_diff, "wb");
write_png_argb32 (buf_diff, png_file, width_a, height_a, stride_a);
fclose (png_file);
@@ -157,7 +159,7 @@ image_buf_diff (void *buf, int width_a, int height_a, int stride_a,
free (buf_b);
free (buf_diff);
- return pixels_changed;
+ return results;
fail:
{
@@ -165,10 +167,11 @@ fail:
FILE *png_file = fopen (filename_a, "wb");
write_png_argb32 (buf_a, png_file, width_a, height_a, stride_a);
fclose (png_file);
- return -1;
+ results.pixels_changed = -1;
+ return results;
}
}
-
+#if 0
/* Image comparison code courtesy of Richard Worth <richard@theworths.org>
* Returns number of pixels changed, (or -1 on error).
* Also saves a "diff" image intended to visually show where the
@@ -229,3 +232,4 @@ image_diff (const char *filename_a,
return pixels_changed;
}
+#endif
diff --git a/buffer-diff.h b/buffer-diff.h
index a37fdc5..54034d5 100644
--- a/buffer-diff.h
+++ b/buffer-diff.h
@@ -26,11 +26,16 @@
#ifndef BUFFER_DIFF_H
#define BUFFER_DIFF_H
+struct diff_results {
+ int pixels_changed;
+ int max_difference;
+};
+
/* Returns number of pixels changed, (or -1 on error).
* Also fills in a "diff" buffer intended to visually show where the
* images differ.
*/
-int
+struct diff_results
buffer_diff (unsigned char *buf_a,
unsigned char *buf_b,
unsigned char *buf_diff,
@@ -38,7 +43,7 @@ buffer_diff (unsigned char *buf_a,
int height,
int stride);
-int
+struct diff_results
image_buf_diff (void *buf_a, int width_a, int height_a, int stride_a,
const char *filename_a,
const char *filename_b,
diff --git a/test-poppler.c b/test-poppler.c
index f9f2aed..24e462b 100644
--- a/test-poppler.c
+++ b/test-poppler.c
@@ -49,11 +49,11 @@ int ilog10(int a)
return log;
}
-poppler_test_status_t gdk_pixbuf_compare(GdkPixbuf *pixbuf, char *page_name)
+struct diff_results gdk_pixbuf_compare(GdkPixbuf *pixbuf, char *page_name)
{
char *png_name, *ref_name, *diff_name;
char *srcdir;
- int pixels_changed;
+ struct diff_results results;
const char *backend = poppler_get_backend() == POPPLER_BACKEND_SPLASH ? "splash" : "cairo";
/* Get the strings ready that we'll need. */
srcdir = getenv ("srcdir");
@@ -80,14 +80,14 @@ poppler_test_status_t gdk_pixbuf_compare(GdkPixbuf *pixbuf, char *page_name)
}
}
- pixels_changed = image_buf_diff (cairo_pixels, width, height, width*4, png_name, ref_name, diff_name);
+ results = image_buf_diff (cairo_pixels, width, height, width*4, png_name, ref_name, diff_name);
free (cairo_pixels);
free (png_name);
free (ref_name);
free (diff_name);
- return pixels_changed ? POPPLER_TEST_FAILURE : POPPLER_TEST_SUCCESS;
+ return results;
}
PopplerPSFile *poppler_ps_file_new (PopplerDocument *document,
@@ -188,7 +188,7 @@ poppler_test_status_t poppler_test_page_text(PopplerPage *page, char *text_name)
return ret;
}
-poppler_test_status_t poppler_test_page(char *pdf_file, PopplerDocument *document, int page_index, int n_pages) {
+poppler_test_status_t poppler_test_page(char *pdf_file, PopplerDocument *document, int page_index, int n_pages, struct diff_results *results) {
GdkPixbuf *pixbuf, *thumb;
double width, height;
PopplerPage *page;
@@ -212,14 +212,15 @@ poppler_test_status_t poppler_test_page(char *pdf_file, PopplerDocument *documen
pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, width, height);
poppler_page_render_to_pixbuf (page, 0, 0, width, height, 1.0, 0, pixbuf);
- ret = gdk_pixbuf_compare(pixbuf, page_name);
+ *results = gdk_pixbuf_compare(pixbuf, page_name);
+ ret = results->pixels_changed ? POPPLER_TEST_FAILURE : POPPLER_TEST_SUCCESS;
if (text_output)
ret |= poppler_test_page_text(page, text_name);
thumb = poppler_page_get_thumbnail(page);
if (thumb)
- ret |= gdk_pixbuf_compare(thumb, thumb_name);
+ ret |= gdk_pixbuf_compare(thumb, thumb_name).pixels_changed ? POPPLER_TEST_FAILURE : POPPLER_TEST_SUCCESS;
if (thumb)
g_object_unref (G_OBJECT (thumb));
@@ -251,10 +252,11 @@ void poppler_test(char *pdf_file)
int i;
int n_pages = poppler_document_get_n_pages(document);
for (i=0; i<n_pages; i++) {
+ struct diff_results results;
printf("%s-%d ", pdf_file, i);
fflush(stdout);
- if (poppler_test_page(pdf_file, document, i, n_pages))
- printf("FAIL\n");
+ if (poppler_test_page(pdf_file, document, i, n_pages, &results))
+ printf("FAIL (%d %d)\n", results.pixels_changed, results.max_difference);
else
printf("PASS\n");
}