[check] Filter programlistings for check-doc-syntax.sh
[cairo/haiku.git] / test / pdiff / args.c
blob0dfbea542afc0ca9776a47aad08cbe75fd9a2d5c
1 /*
2 Comapre Args
3 Copyright (C) 2006 Yangli Hector Yee
5 This program is free software; you can redistribute it and/or modify it under the terms of the
6 GNU General Public License as published by the Free Software Foundation; either version 2 of the License,
7 or (at your option) any later version.
9 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 See the GNU General Public License for more details.
13 You should have received a copy of the GNU General Public License along with this program;
14 if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 #include "args.h"
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <string.h>
22 static const char* copyright =
23 "PerceptualDiff version 1.0, Copyright (C) 2006 Yangli Hector Yee\n\
24 PerceptualDiff comes with ABSOLUTELY NO WARRANTY;\n\
25 This is free software, and you are welcome\n\
26 to redistribute it under certain conditions;\n\
27 See the GPL page for details: http://www.gnu.org/copyleft/gpl.html\n\n";
29 static const char *usage =
30 "PeceptualDiff image1.tif image2.tif\n\n\
31 Compares image1.tif and image2.tif using a perceptually based image metric\n\
32 Options:\n\
33 \t-verbose : Turns on verbose mode\n\
34 \t-fov deg : Field of view in degrees (0.1 to 89.9)\n\
35 \t-threshold p : #pixels p below which differences are ignored\n\
36 \t-gamma g : Value to convert rgb into linear space (default 2.2)\n\
37 \t-luminance l : White luminance (default 100.0 cdm^-2)\n\
38 \n\
39 \n Note: Input files can also be in the PNG format\
40 \n";
42 void
43 args_init (args_t *args)
45 args->surface_a = NULL;
46 args->surface_b = NULL;
47 args->Verbose = false;
48 args->FieldOfView = 45.0f;
49 args->Gamma = 2.2f;
50 args->ThresholdPixels = 100;
51 args->Luminance = 100.0f;
54 void
55 args_fini (args_t *args)
57 cairo_surface_destroy (args->surface_a);
58 cairo_surface_destroy (args->surface_b);
61 bool
62 args_parse (args_t *args, int argc, char **argv)
64 int i;
65 if (argc < 3) {
66 fprintf (stderr, "%s", copyright);
67 fprintf (stderr, "%s", usage);
68 return false;
70 for (i = 0; i < argc; i++) {
71 if (i == 1) {
72 args->surface_a = cairo_image_surface_create_from_png (argv[1]);
73 if (cairo_surface_status (args->surface_a))
75 fprintf (stderr, "FAIL: Cannot open %s: %s\n",
76 argv[1], cairo_status_to_string (cairo_surface_status (args->surface_a)));
77 return false;
79 } else if (i == 2) {
80 args->surface_b = cairo_image_surface_create_from_png (argv[2]);
81 if (cairo_surface_status (args->surface_b))
83 fprintf (stderr, "FAIL: Cannot open %s: %s\n",
84 argv[2], cairo_status_to_string (cairo_surface_status (args->surface_b)));
85 return false;
87 } else {
88 if (strstr(argv[i], "-fov")) {
89 if (i + 1 < argc) {
90 args->FieldOfView = (float) atof(argv[i + 1]);
92 } else if (strstr(argv[i], "-verbose")) {
93 args->Verbose = true;
94 } else if (strstr(argv[i], "-threshold")) {
95 if (i + 1 < argc) {
96 args->ThresholdPixels = atoi(argv[i + 1]);
98 } else if (strstr(argv[i], "-gamma")) {
99 if (i + 1 < argc) {
100 args->Gamma = (float) atof(argv[i + 1]);
102 }else if (strstr(argv[i], "-luminance")) {
103 if (i + 1 < argc) {
104 args->Luminance = (float) atof(argv[i + 1]);
108 } /* i */
109 return true;
112 void
113 args_print (args_t *args)
115 printf("Field of view is %f degrees\n", args->FieldOfView);
116 printf("Threshold pixels is %d pixels\n", args->ThresholdPixels);
117 printf("The Gamma is %f\n", args->Gamma);
118 printf("The Display's luminance is %f candela per meter squared\n", args->Luminance);