args.c 3.7 KB

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