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>).
This commit is contained in:
Carl Worth 2006-12-14 03:49:31 -08:00
parent 18a4fa448f
commit f175b23559
8 changed files with 53 additions and 152 deletions

View file

@ -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);
}

View file

@ -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

View file

@ -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))

View file

@ -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

View file

@ -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 *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 = new float[dim];
float *bA = new float[dim];
float *aB = new float[dim];
float *bB = new float[dim];
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;
}

View file

@ -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

View file

@ -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"