summaryrefslogtreecommitdiff
path: root/test/pdiff
diff options
context:
space:
mode:
authorCarl Worth <cworth@cworth.org>2006-12-14 01:00:43 -0800
committerCarl Worth <cworth@cworth.org>2006-12-14 07:58:01 -0800
commit53c3a2f75b7f065b4c769ad087bbc9aaaaf6d7ee (patch)
treed21fc9b5952e9c77647d08004dc52234adeca8af /test/pdiff
parent358645d6eb68b4eaf79159e7aefa01bca4cb0acf (diff)
downloadcairo-53c3a2f75b7f065b4c769ad087bbc9aaaaf6d7ee.tar.gz
pdiff: Rewrite main program to use cairo-based pdiff_compare interface
Diffstat (limited to 'test/pdiff')
-rw-r--r--test/pdiff/CompareArgs.cpp23
-rw-r--r--test/pdiff/CompareArgs.h5
-rw-r--r--test/pdiff/Makefile.am1
-rw-r--r--test/pdiff/Metric.cpp35
-rw-r--r--test/pdiff/Metric.h32
-rw-r--r--test/pdiff/PerceptualDiff.cpp47
6 files changed, 65 insertions, 78 deletions
diff --git a/test/pdiff/CompareArgs.cpp b/test/pdiff/CompareArgs.cpp
index 0f9cb0f6a..38ff1f65b 100644
--- a/test/pdiff/CompareArgs.cpp
+++ b/test/pdiff/CompareArgs.cpp
@@ -40,8 +40,8 @@ static const char *usage =
CompareArgs::CompareArgs()
{
- ImgA = NULL;
- ImgB = NULL;
+ surface_a = NULL;
+ surface_b = NULL;
Verbose = false;
FieldOfView = 45.0f;
Gamma = 2.2f;
@@ -51,13 +51,12 @@ CompareArgs::CompareArgs()
CompareArgs::~CompareArgs()
{
- if (ImgA) delete ImgA;
- if (ImgB) delete ImgB;
+ cairo_surface_destroy (surface_a);
+ cairo_surface_destroy (surface_b);
}
bool CompareArgs::Parse_Args(int argc, char **argv)
{
- cairo_surface_t *surface;
if (argc < 3) {
ErrorStr = copyright;
ErrorStr += usage;
@@ -65,29 +64,27 @@ bool CompareArgs::Parse_Args(int argc, char **argv)
}
for (int i = 0; i < argc; i++) {
if (i == 1) {
- surface = cairo_image_surface_create_from_png (argv[1]);
- if (cairo_surface_status (surface))
+ surface_a = cairo_image_surface_create_from_png (argv[1]);
+ if (cairo_surface_status (surface_a))
{
ErrorStr = "FAIL: Cannot open ";
ErrorStr += argv[1];
ErrorStr += " ";
- ErrorStr += cairo_status_to_string (cairo_surface_status (surface));
+ ErrorStr += cairo_status_to_string (cairo_surface_status (surface_a));
ErrorStr += "\n";
return false;
}
- ImgA = new RGBACairoImage (surface);
} else if (i == 2) {
- surface = cairo_image_surface_create_from_png (argv[2]);
- if (cairo_surface_status (surface))
+ surface_b = cairo_image_surface_create_from_png (argv[2]);
+ if (cairo_surface_status (surface_b))
{
ErrorStr = "FAIL: Cannot open ";
ErrorStr += argv[2];
ErrorStr += " ";
- ErrorStr += cairo_status_to_string (cairo_surface_status (surface));
+ ErrorStr += cairo_status_to_string (cairo_surface_status (surface_b));
ErrorStr += "\n";
return false;
}
- ImgB = new RGBACairoImage (surface);
} else {
if (strstr(argv[i], "-fov")) {
if (i + 1 < argc) {
diff --git a/test/pdiff/CompareArgs.h b/test/pdiff/CompareArgs.h
index 1cab0da08..ca51bf099 100644
--- a/test/pdiff/CompareArgs.h
+++ b/test/pdiff/CompareArgs.h
@@ -18,6 +18,7 @@
#define _COMPAREARGS_H
#include <string>
+#include <cairo.h>
class RGBAImage;
class RGBACairoImage;
@@ -31,8 +32,8 @@ public:
bool Parse_Args(int argc, char **argv);
void Print_Args();
- RGBAImage *ImgA; /* Image A */
- RGBAImage *ImgB; /* Image B */
+ cairo_surface_t *surface_a; /* Image A */
+ cairo_surface_t *surface_b; /* Image B */
bool Verbose; /* Print lots of text or not */
float FieldOfView; /* Field of view in degrees */
float Gamma; /* The gamma to convert to linear color space */
diff --git a/test/pdiff/Makefile.am b/test/pdiff/Makefile.am
index 0179f0588..5dd400380 100644
--- a/test/pdiff/Makefile.am
+++ b/test/pdiff/Makefile.am
@@ -6,7 +6,6 @@ libpdiff_la_SOURCES = \
lpyramid.c \
lpyramid.h \
Metric.cpp \
- Metric.h \
RGBAImage.cpp \
RGBAImage.h
diff --git a/test/pdiff/Metric.cpp b/test/pdiff/Metric.cpp
index 44a704dff..d9e56ac24 100644
--- a/test/pdiff/Metric.cpp
+++ b/test/pdiff/Metric.cpp
@@ -14,7 +14,6 @@
if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include "Metric.h"
#include "CompareArgs.h"
#include "RGBAImage.h"
#include "lpyramid.h"
@@ -125,23 +124,6 @@ void XYZToLAB(float x, float y, float z, float &L, float &A, float &B)
B = 200.0f * (f[1] - f[2]);
}
-int
-pdiff_compare (cairo_surface_t *surface_a,
- cairo_surface_t *surface_b,
- double gamma,
- double luminance,
- double field_of_view)
-{
- RGBAImage *image_a, *image_b;
-
- image_a = new RGBACairoImage (surface_a);
- image_b = new RGBACairoImage (surface_b);
-
- return Yee_Compare_Images (image_a, image_b,
- gamma, luminance,
- field_of_view, false);
-}
-
int Yee_Compare_Images(RGBAImage *image_a,
RGBAImage *image_b,
float gamma,
@@ -294,3 +276,20 @@ int Yee_Compare_Images(RGBAImage *image_a,
return pixels_failed;
}
+
+int
+pdiff_compare (cairo_surface_t *surface_a,
+ cairo_surface_t *surface_b,
+ double gamma,
+ double luminance,
+ double field_of_view)
+{
+ RGBAImage *image_a, *image_b;
+
+ image_a = new RGBACairoImage (surface_a);
+ image_b = new RGBACairoImage (surface_b);
+
+ return Yee_Compare_Images (image_a, image_b,
+ gamma, luminance,
+ field_of_view, false);
+}
diff --git a/test/pdiff/Metric.h b/test/pdiff/Metric.h
deleted file mode 100644
index 8235a0e62..000000000
--- a/test/pdiff/Metric.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
-Metric
-Copyright (C) 2006 Yangli Hector Yee
-
-This program is free software; you can redistribute it and/or modify it under the terms of the
-GNU General Public License as published by the Free Software Foundation; either version 2 of the License,
-or (at your option) any later version.
-
-This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
-without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-See the GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License along with this program;
-if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-*/
-
-#ifndef _METRIC_H
-#define _METRIC_H
-
-#include "RGBAImage.h"
-
-/* Image comparison metric using Yee's method
- * References: A Perceptual Metric for Production Testing, Hector Yee, Journal of Graphics Tools 2004
- */
-int Yee_Compare_Images(RGBAImage *image_a,
- RGBAImage *image_b,
- float gamma,
- float luminance,
- float field_of_view,
- bool verbose);
-
-#endif
diff --git a/test/pdiff/PerceptualDiff.cpp b/test/pdiff/PerceptualDiff.cpp
index 3affa16d9..eb89fbf5d 100644
--- a/test/pdiff/PerceptualDiff.cpp
+++ b/test/pdiff/PerceptualDiff.cpp
@@ -23,23 +23,46 @@
#include "lpyramid.h"
#include "RGBAImage.h"
#include "CompareArgs.h"
-#include "Metric.h"
+#include "pdiff.h"
static bool Yee_Compare(CompareArgs &args)
{
- if ((args.ImgA->Get_Width() != args.ImgB->Get_Width()) ||
- (args.ImgA->Get_Height() != args.ImgB->Get_Height())) {
+ int width_a, height_a, stride_a;
+ unsigned char *data_a, *row_a;
+ uint32_t *pixel_a;
+ int width_b, height_b, stride_b;
+ unsigned char *data_b, *row_b;
+ uint32_t *pixel_b;
+
+ width_a = cairo_image_surface_get_width (args.surface_a);
+ height_a = cairo_image_surface_get_height (args.surface_a);
+ stride_a = cairo_image_surface_get_stride (args.surface_a);
+ data_a = cairo_image_surface_get_data (args.surface_a);
+
+ width_b = cairo_image_surface_get_width (args.surface_b);
+ height_b = cairo_image_surface_get_height (args.surface_b);
+ stride_b = cairo_image_surface_get_stride (args.surface_b);
+ data_b = cairo_image_surface_get_data (args.surface_b);
+
+ if ((width_a != width_b) || (height_a != height_b)) {
args.ErrorStr = "Image dimensions do not match\n";
return false;
}
- unsigned int i, dim, pixels_failed;
- dim = args.ImgA->Get_Width() * args.ImgA->Get_Height();
+ unsigned int x, y, dim, pixels_failed;
bool identical = true;
- for (i = 0; i < dim; i++) {
- if (args.ImgA->Get(i) != args.ImgB->Get(i)) {
- identical = false;
- break;
+
+ for (y = 0; y < height_a; y++) {
+ row_a = data_a + y * stride_a;
+ row_b = data_b + y * stride_b;
+ pixel_a = (uint32_t *) row_a;
+ pixel_b = (uint32_t *) row_b;
+ for (x = 0; x < width_a; x++) {
+ if (*pixel_a != *pixel_b) {
+ identical = false;
+ }
+ pixel_a++;
+ pixel_b++;
}
}
if (identical) {
@@ -47,9 +70,9 @@ static bool Yee_Compare(CompareArgs &args)
return true;
}
- pixels_failed = Yee_Compare_Images (args.ImgA, args.ImgB,
- args.Gamma, args.Luminance,
- args.FieldOfView, args.Verbose);
+ pixels_failed = pdiff_compare (args.surface_a, args.surface_b,
+ args.Gamma, args.Luminance,
+ args.FieldOfView);
if (pixels_failed < args.ThresholdPixels) {
args.ErrorStr = "Images are perceptually indistinguishable\n";