mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2026-01-03 07:00:15 +01:00
pdiff: Replace CompareArgs class with args_t struct
This gets rid of nearly the last vestiges of C++ from the pdiff code.
This commit is contained in:
parent
871aba6c80
commit
18a4fa448f
5 changed files with 160 additions and 32 deletions
|
|
@ -56,12 +56,14 @@ CompareArgs::~CompareArgs()
|
|||
|
||||
bool CompareArgs::Parse_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) {
|
||||
surface_a = cairo_image_surface_create_from_png (argv[1]);
|
||||
if (cairo_surface_status (surface_a))
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ libpdiff_la_SOURCES = \
|
|||
pdiff.cpp
|
||||
|
||||
perceptualdiff_SOURCES = \
|
||||
CompareArgs.cpp \
|
||||
CompareArgs.h \
|
||||
args.cpp \
|
||||
args.h \
|
||||
PerceptualDiff.cpp
|
||||
|
||||
INCLUDES = -I$(top_srcdir)/src
|
||||
|
|
|
|||
|
|
@ -21,10 +21,10 @@
|
|||
#include <math.h>
|
||||
#include <string>
|
||||
#include "lpyramid.h"
|
||||
#include "CompareArgs.h"
|
||||
#include "args.h"
|
||||
#include "pdiff.h"
|
||||
|
||||
static bool Yee_Compare(CompareArgs &args)
|
||||
static bool Yee_Compare(args_t *args)
|
||||
{
|
||||
int width_a, height_a, stride_a;
|
||||
unsigned char *data_a, *row_a;
|
||||
|
|
@ -35,15 +35,15 @@ static bool Yee_Compare(CompareArgs &args)
|
|||
unsigned int x, y, dim, pixels_failed;
|
||||
bool identical = true;
|
||||
|
||||
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_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);
|
||||
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)) {
|
||||
printf ("FAIL: Image dimensions do not match\n");
|
||||
|
|
@ -70,11 +70,11 @@ static bool Yee_Compare(CompareArgs &args)
|
|||
return true;
|
||||
}
|
||||
|
||||
pixels_failed = pdiff_compare (args.surface_a, args.surface_b,
|
||||
args.Gamma, args.Luminance,
|
||||
args.FieldOfView);
|
||||
pixels_failed = pdiff_compare (args->surface_a, args->surface_b,
|
||||
args->Gamma, args->Luminance,
|
||||
args->FieldOfView);
|
||||
|
||||
if (pixels_failed < args.ThresholdPixels) {
|
||||
if (pixels_failed < args->ThresholdPixels) {
|
||||
printf ("PASS: Images are perceptually indistinguishable\n");
|
||||
return true;
|
||||
}
|
||||
|
|
@ -87,12 +87,15 @@ static bool Yee_Compare(CompareArgs &args)
|
|||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
CompareArgs args;
|
||||
args_t args;
|
||||
|
||||
if (!args.Parse_Args(argc, argv)) {
|
||||
args_init (&args);
|
||||
|
||||
if (!args_parse (&args, argc, argv)) {
|
||||
return -1;
|
||||
} else {
|
||||
if (args.Verbose) args.Print_Args();
|
||||
if (args.Verbose)
|
||||
args_print (&args);
|
||||
}
|
||||
return ! Yee_Compare(args);
|
||||
return ! Yee_Compare(&args);
|
||||
}
|
||||
|
|
|
|||
118
test/pdiff/args.cpp
Normal file
118
test/pdiff/args.cpp
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
/*
|
||||
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 "args.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.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";
|
||||
|
||||
void
|
||||
args_init (args_t *args)
|
||||
{
|
||||
args->surface_a = NULL;
|
||||
args->surface_b = NULL;
|
||||
args->Verbose = false;
|
||||
args->FieldOfView = 45.0f;
|
||||
args->Gamma = 2.2f;
|
||||
args->ThresholdPixels = 100;
|
||||
args->Luminance = 100.0f;
|
||||
}
|
||||
|
||||
void
|
||||
args_fini (args_t *args)
|
||||
{
|
||||
cairo_surface_destroy (args->surface_a);
|
||||
cairo_surface_destroy (args->surface_b);
|
||||
}
|
||||
|
||||
bool
|
||||
args_parse (args_t *args, int argc, char **argv)
|
||||
{
|
||||
if (argc < 3) {
|
||||
fprintf (stderr, "%s", copyright);
|
||||
fprintf (stderr, "%s", usage);
|
||||
return false;
|
||||
}
|
||||
for (int 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))
|
||||
{
|
||||
fprintf (stderr, "FAIL: Cannot open %s: %s\n",
|
||||
argv[1], cairo_status_to_string (cairo_surface_status (args->surface_a)));
|
||||
return false;
|
||||
}
|
||||
} else if (i == 2) {
|
||||
args->surface_b = cairo_image_surface_create_from_png (argv[2]);
|
||||
if (cairo_surface_status (args->surface_b))
|
||||
{
|
||||
fprintf (stderr, "FAIL: Cannot open %s: %s\n",
|
||||
argv[2], cairo_status_to_string (cairo_surface_status (args->surface_b)));
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (strstr(argv[i], "-fov")) {
|
||||
if (i + 1 < argc) {
|
||||
args->FieldOfView = (float) atof(argv[i + 1]);
|
||||
}
|
||||
} else if (strstr(argv[i], "-verbose")) {
|
||||
args->Verbose = true;
|
||||
} else if (strstr(argv[i], "-threshold")) {
|
||||
if (i + 1 < argc) {
|
||||
args->ThresholdPixels = atoi(argv[i + 1]);
|
||||
}
|
||||
} else if (strstr(argv[i], "-gamma")) {
|
||||
if (i + 1 < argc) {
|
||||
args->Gamma = (float) atof(argv[i + 1]);
|
||||
}
|
||||
}else if (strstr(argv[i], "-luminance")) {
|
||||
if (i + 1 < argc) {
|
||||
args->Luminance = (float) atof(argv[i + 1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
} /* i */
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
args_print (args_t *args)
|
||||
{
|
||||
printf("Field of view is %f degrees\n", args->FieldOfView);
|
||||
printf("Threshold pixels is %d pixels\n", args->ThresholdPixels);
|
||||
printf("The Gamma is %f\n", args->Gamma);
|
||||
printf("The Display's luminance is %f candela per meter squared\n", args->Luminance);
|
||||
}
|
||||
|
|
@ -14,21 +14,14 @@
|
|||
if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef _COMPAREARGS_H
|
||||
#define _COMPAREARGS_H
|
||||
#ifndef _ARGS_H
|
||||
#define _ARGS_H
|
||||
|
||||
#include <string>
|
||||
#include <cairo.h>
|
||||
|
||||
/* Args to pass into the comparison function */
|
||||
class CompareArgs
|
||||
typedef struct _args
|
||||
{
|
||||
public:
|
||||
CompareArgs();
|
||||
~CompareArgs();
|
||||
bool Parse_Args(int argc, char **argv);
|
||||
void Print_Args();
|
||||
|
||||
cairo_surface_t *surface_a; /* Image A */
|
||||
cairo_surface_t *surface_b; /* Image B */
|
||||
bool Verbose; /* Print lots of text or not */
|
||||
|
|
@ -36,6 +29,18 @@ public:
|
|||
float Gamma; /* The gamma to convert to linear color space */
|
||||
float Luminance; /* the display's luminance */
|
||||
unsigned int ThresholdPixels; /* How many pixels different to ignore */
|
||||
};
|
||||
} args_t;
|
||||
|
||||
void
|
||||
args_init (args_t *args);
|
||||
|
||||
void
|
||||
args_fini (args_t *args);
|
||||
|
||||
bool
|
||||
args_parse (args_t *args, int argc, char **argv);
|
||||
|
||||
void
|
||||
args_print (args_t *args);
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Reference in a new issue