perceptualdiff.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. PerceptualDiff - a program that compares two images using a perceptual metric
  3. based on the paper :
  4. A perceptual metric for production testing. Journal of graphics tools, 9(4):33-40, 2004, Hector Yee
  5. Copyright (C) 2006 Yangli Hector Yee
  6. This program is free software; you can redistribute it and/or modify it under the terms of the
  7. GNU General Public License as published by the Free Software Foundation; either version 2 of the License,
  8. 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.
  12. You should have received a copy of the GNU General Public License along with this program;
  13. if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
  14. */
  15. #include <stdio.h>
  16. #include <stdint.h>
  17. #include <string.h>
  18. #include <math.h>
  19. #include "lpyramid.h"
  20. #include "args.h"
  21. #include "pdiff.h"
  22. static bool Yee_Compare(args_t *args)
  23. {
  24. unsigned int width_a, height_a, stride_a;
  25. unsigned char *data_a, *row_a;
  26. uint32_t *pixel_a;
  27. unsigned int width_b, height_b, stride_b;
  28. unsigned char *data_b, *row_b;
  29. uint32_t *pixel_b;
  30. unsigned int x, y, pixels_failed;
  31. bool identical = true;
  32. width_a = cairo_image_surface_get_width (args->surface_a);
  33. height_a = cairo_image_surface_get_height (args->surface_a);
  34. stride_a = cairo_image_surface_get_stride (args->surface_a);
  35. data_a = cairo_image_surface_get_data (args->surface_a);
  36. width_b = cairo_image_surface_get_width (args->surface_b);
  37. height_b = cairo_image_surface_get_height (args->surface_b);
  38. stride_b = cairo_image_surface_get_stride (args->surface_b);
  39. data_b = cairo_image_surface_get_data (args->surface_b);
  40. if ((width_a != width_b) || (height_a != height_b)) {
  41. printf ("FAIL: Image dimensions do not match\n");
  42. return false;
  43. }
  44. identical = true;
  45. for (y = 0; y < height_a; y++) {
  46. row_a = data_a + y * stride_a;
  47. row_b = data_b + y * stride_b;
  48. pixel_a = (uint32_t *) row_a;
  49. pixel_b = (uint32_t *) row_b;
  50. for (x = 0; x < width_a; x++) {
  51. if (*pixel_a != *pixel_b) {
  52. identical = false;
  53. }
  54. pixel_a++;
  55. pixel_b++;
  56. }
  57. }
  58. if (identical) {
  59. printf ("PASS: Images are binary identical\n");
  60. return true;
  61. }
  62. pixels_failed = pdiff_compare (args->surface_a, args->surface_b,
  63. args->Gamma, args->Luminance,
  64. args->FieldOfView);
  65. if (pixels_failed < args->ThresholdPixels) {
  66. printf ("PASS: Images are perceptually indistinguishable\n");
  67. return true;
  68. }
  69. printf("FAIL: Images are visibly different\n"
  70. "%d pixels are different\n", pixels_failed);
  71. return false;
  72. }
  73. int main(int argc, char **argv)
  74. {
  75. args_t args;
  76. args_init (&args);
  77. if (!args_parse (&args, argc, argv)) {
  78. return -1;
  79. } else {
  80. if (args.Verbose)
  81. args_print (&args);
  82. }
  83. return ! Yee_Compare(&args);
  84. }