summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Worth <cworth@cworth.org>2006-12-14 03:49:31 -0800
committerCarl Worth <cworth@cworth.org>2006-12-14 07:58:01 -0800
commitf175b23559f3ba759d222538fd28922c1cbe2196 (patch)
tree54827b3d3c4cc28ab6636ac5e5b9f0efbd87f3d5
parent18a4fa448fcdb6a72f427e997ee2b234f96a56f7 (diff)
pdiff: Rename everything to .c and fix an last littele C++ isms.
The only things we had missed were a few new/delete pairs, and some obvious header file fixups, (like not doing <string>).
-rw-r--r--test/pdiff/CompareArgs.cpp114
-rw-r--r--test/pdiff/Makefile.am6
-rw-r--r--test/pdiff/args.c (renamed from test/pdiff/args.cpp)3
-rw-r--r--test/pdiff/args.h2
-rw-r--r--test/pdiff/lpyramid.c (renamed from test/pdiff/lpyramid.cpp)0
-rw-r--r--test/pdiff/pdiff.c (renamed from test/pdiff/pdiff.cpp)64
-rw-r--r--test/pdiff/pdiff.h16
-rw-r--r--test/pdiff/perceptualdiff.c (renamed from test/pdiff/PerceptualDiff.cpp)2
8 files changed, 54 insertions, 153 deletions
diff --git a/test/pdiff/CompareArgs.cpp b/test/pdiff/CompareArgs.cpp
deleted file mode 100644
index 3b58ff7d8..000000000
--- a/test/pdiff/CompareArgs.cpp
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- Comapre Args
- 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
-*/
-
-#include "CompareArgs.h"
-#include <stdio.h>
-
-static const char* copyright =
-"PerceptualDiff version 1.0, Copyright (C) 2006 Yangli Hector Yee\n\
-PerceptualDiff comes with ABSOLUTELY NO WARRANTY;\n\
-This is free software, and you are welcome\n\
-to redistribute it under certain conditions;\n\
-See the GPL page for details: http://www.gnu.org/copyleft/gpl.html\n\n";
-
-static const char *usage =
-"PeceptualDiff image1.tif image2.tif\n\n\
- Compares image1.tif and image2.tif using a perceptually based image metric\n\
- Options:\n\
-\t-verbose : Turns on verbose mode\n\
-\t-fov deg : Field of view in degrees (0.1 to 89.9)\n\
-\t-threshold p : #pixels p below which differences are ignored\n\
-\t-gamma g : Value to convert rgb into linear space (default 2.2)\n\
-\t-luminance l : White luminance (default 100.0 cdm^-2)\n\
-\n\
-\n Note: Input files can also be in the PNG format\
-\n";
-
-CompareArgs::CompareArgs()
-{
- surface_a = NULL;
- surface_b = NULL;
- Verbose = false;
- FieldOfView = 45.0f;
- Gamma = 2.2f;
- ThresholdPixels = 100;
- Luminance = 100.0f;
-}
-
-CompareArgs::~CompareArgs()
-{
- cairo_surface_destroy (surface_a);
- cairo_surface_destroy (surface_b);
-}
-
-bool CompareArgs::Parse_Args(int argc, char **argv)
-{
- int i;
-
- if (argc < 3) {
- fprintf (stderr, "%s", copyright);
- fprintf (stderr, "%s", usage);
- return false;
- }
- for (i = 0; i < argc; i++) {
- if (i == 1) {
- surface_a = cairo_image_surface_create_from_png (argv[1]);
- if (cairo_surface_status (surface_a))
- {
- fprintf (stderr, "FAIL: Cannot open %s: %s\n",
- argv[1], cairo_status_to_string (cairo_surface_status (surface_a)));
- return false;
- }
- } else if (i == 2) {
- surface_b = cairo_image_surface_create_from_png (argv[2]);
- if (cairo_surface_status (surface_b))
- {
- fprintf (stderr, "FAIL: Cannot open %s: %s\n",
- argv[2], cairo_status_to_string (cairo_surface_status (surface_b)));
- return false;
- }
- } else {
- if (strstr(argv[i], "-fov")) {
- if (i + 1 < argc) {
- FieldOfView = (float) atof(argv[i + 1]);
- }
- } else if (strstr(argv[i], "-verbose")) {
- Verbose = true;
- } else if (strstr(argv[i], "-threshold")) {
- if (i + 1 < argc) {
- ThresholdPixels = atoi(argv[i + 1]);
- }
- } else if (strstr(argv[i], "-gamma")) {
- if (i + 1 < argc) {
- Gamma = (float) atof(argv[i + 1]);
- }
- }else if (strstr(argv[i], "-luminance")) {
- if (i + 1 < argc) {
- Luminance = (float) atof(argv[i + 1]);
- }
- }
- }
- } /* i */
- return true;
-}
-
-void CompareArgs::Print_Args()
-{
- printf("Field of view is %f degrees\n", FieldOfView);
- printf("Threshold pixels is %d pixels\n", ThresholdPixels);
- printf("The Gamma is %f\n", Gamma);
- printf("The Display's luminance is %f candela per meter squared\n", Luminance);
-}
diff --git a/test/pdiff/Makefile.am b/test/pdiff/Makefile.am
index f53c8d2dd..d72b2732f 100644
--- a/test/pdiff/Makefile.am
+++ b/test/pdiff/Makefile.am
@@ -5,12 +5,12 @@ libpdiff_la_SOURCES = \
pdiff.h \
lpyramid.c \
lpyramid.h \
- pdiff.cpp
+ pdiff.c
perceptualdiff_SOURCES = \
- args.cpp \
+ args.c \
args.h \
- PerceptualDiff.cpp
+ perceptualdiff.c
INCLUDES = -I$(top_srcdir)/src
LDADD = libpdiff.la $(top_builddir)/src/libcairo.la
diff --git a/test/pdiff/args.cpp b/test/pdiff/args.c
index 9fbe23ed9..0dfbea542 100644
--- a/test/pdiff/args.cpp
+++ b/test/pdiff/args.c
@@ -61,12 +61,13 @@ args_fini (args_t *args)
bool
args_parse (args_t *args, int argc, char **argv)
{
+ int i;
if (argc < 3) {
fprintf (stderr, "%s", copyright);
fprintf (stderr, "%s", usage);
return false;
}
- for (int i = 0; i < argc; i++) {
+ for (i = 0; i < argc; i++) {
if (i == 1) {
args->surface_a = cairo_image_surface_create_from_png (argv[1]);
if (cairo_surface_status (args->surface_a))
diff --git a/test/pdiff/args.h b/test/pdiff/args.h
index 0197c902d..aa6cf2997 100644
--- a/test/pdiff/args.h
+++ b/test/pdiff/args.h
@@ -17,7 +17,7 @@
#ifndef _ARGS_H
#define _ARGS_H
-#include <cairo.h>
+#include "pdiff.h"
/* Args to pass into the comparison function */
typedef struct _args
diff --git a/test/pdiff/lpyramid.cpp b/test/pdiff/lpyramid.c
index 92915ab01..92915ab01 100644
--- a/test/pdiff/lpyramid.cpp
+++ b/test/pdiff/lpyramid.c
diff --git a/test/pdiff/pdiff.cpp b/test/pdiff/pdiff.c
index 1609cdad0..1b73e796c 100644
--- a/test/pdiff/pdiff.cpp
+++ b/test/pdiff/pdiff.c
@@ -16,6 +16,8 @@
#include "lpyramid.h"
#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
#include <stdint.h>
#include "pdiff.h"
@@ -184,6 +186,18 @@ _get_blue (cairo_surface_t *surface, int i)
return (((pixel & 0x000000ff) >> 0) * 255 + alpha / 2) / alpha;
}
+static void *
+xmalloc (size_t size)
+{
+ void *buf;
+
+ buf = malloc (size);
+ if (buf == NULL) {
+ fprintf (stderr, "Out of memory.\n");
+ exit (1);
+ }
+}
+
int
pdiff_compare (cairo_surface_t *surface_a,
cairo_surface_t *surface_b,
@@ -196,19 +210,19 @@ pdiff_compare (cairo_surface_t *surface_a,
unsigned int i;
/* assuming colorspaces are in Adobe RGB (1998) convert to XYZ */
- float *aX = new float[dim];
- float *aY = new float[dim];
- float *aZ = new float[dim];
- float *bX = new float[dim];
- float *bY = new float[dim];
- float *bZ = new float[dim];
- float *aLum = new float[dim];
- float *bLum = new float[dim];
-
- float *aA = new float[dim];
- float *bA = new float[dim];
- float *aB = new float[dim];
- float *bB = new float[dim];
+ float *aX = xmalloc (dim * sizeof (float));
+ float *aY = xmalloc (dim * sizeof (float));
+ float *aZ = xmalloc (dim * sizeof (float));
+ float *bX = xmalloc (dim * sizeof (float));
+ float *bY = xmalloc (dim * sizeof (float));
+ float *bZ = xmalloc (dim * sizeof (float));
+ float *aLum = xmalloc (dim * sizeof (float));
+ float *bLum = xmalloc (dim * sizeof (float));
+
+ float *aA = xmalloc (dim * sizeof (float));
+ float *bA = xmalloc (dim * sizeof (float));
+ float *aB = xmalloc (dim * sizeof (float));
+ float *bB = xmalloc (dim * sizeof (float));
unsigned int x, y, w, h;
@@ -328,20 +342,20 @@ pdiff_compare (cairo_surface_t *surface_a,
}
}
- if (aX) delete[] aX;
- if (aY) delete[] aY;
- if (aZ) delete[] aZ;
- if (bX) delete[] bX;
- if (bY) delete[] bY;
- if (bZ) delete[] bZ;
- if (aLum) delete[] aLum;
- if (bLum) delete[] bLum;
+ free (aX);
+ free (aY);
+ free (aZ);
+ free (bX);
+ free (bY);
+ free (bZ);
+ free (aLum);
+ free (bLum);
lpyramid_destroy (la);
lpyramid_destroy (lb);
- if (aA) delete aA;
- if (bA) delete bA;
- if (aB) delete aB;
- if (bB) delete bB;
+ free (aA);
+ free (bA);
+ free (aB);
+ free (bB);
return pixels_failed;
}
diff --git a/test/pdiff/pdiff.h b/test/pdiff/pdiff.h
index d20ae86d3..b398cc6fe 100644
--- a/test/pdiff/pdiff.h
+++ b/test/pdiff/pdiff.h
@@ -17,12 +17,16 @@
#ifndef _PDIFF_H
#define _PDIFF_H
-#ifdef __cplusplus
-extern "C" {
-#endif
-
#include <cairo.h>
+typedef int bool;
+#ifndef true
+#define true 1
+#endif
+#ifndef false
+#define false 0
+#endif
+
/* Image comparison metric using Yee's method (and a cairo interface)
* References: A Perceptual Metric for Production Testing, Hector Yee, Journal of Graphics Tools 2004
*/
@@ -33,8 +37,4 @@ pdiff_compare (cairo_surface_t *surface_a,
double luminance,
double field_of_view);
-#ifdef __cplusplus
-}
-#endif
-
#endif
diff --git a/test/pdiff/PerceptualDiff.cpp b/test/pdiff/perceptualdiff.c
index 1df3614ac..953558e0f 100644
--- a/test/pdiff/PerceptualDiff.cpp
+++ b/test/pdiff/perceptualdiff.c
@@ -17,9 +17,9 @@
*/
#include <stdio.h>
+#include <stdint.h>
#include <string.h>
#include <math.h>
-#include <string>
#include "lpyramid.h"
#include "args.h"
#include "pdiff.h"