lcms-compare.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #include <stdlib.h>
  2. #include <time.h>
  3. #include "sum.h"
  4. #include "lcms.h"
  5. #include "qcms.h"
  6. int main(int argc, char **argv)
  7. {
  8. char *input_path = argv[1];
  9. char *output_path = argv[2];
  10. qcms_profile *input_profile, *output_profile;
  11. qcms_transform *transform;
  12. #define ALL
  13. #ifndef ALL
  14. #define LENGTH 1
  15. #else
  16. #define LENGTH (256*256*256)
  17. #endif
  18. static unsigned char src[LENGTH*3];
  19. static unsigned char qoutput[LENGTH*3];
  20. static unsigned char loutput[LENGTH*3];
  21. #ifdef ALL
  22. int i,j,k,l=0;
  23. for (i=0; i<256; i++) {
  24. for (j=0; j<256; j++) {
  25. for (k=0; k<256; k++) {
  26. src[l++] = i;
  27. src[l++] = j;
  28. src[l++] = k;
  29. }
  30. }
  31. }
  32. #else
  33. int i;
  34. src[0] = 19;
  35. src[1] = 28;
  36. src[2] = 56;
  37. #endif
  38. clock_t lcms_start = clock();
  39. cmsHPROFILE linput_profile, loutput_profile;
  40. cmsHTRANSFORM transformFixed;
  41. linput_profile = cmsOpenProfileFromFile(input_path, "r");
  42. loutput_profile = cmsOpenProfileFromFile(output_path, "r");
  43. #if 0
  44. cmsPrecacheProfile(loutput_profile, CMS_PRECACHE_LI168_REVERSE);
  45. cmsPrecacheProfile(linput_profile, CMS_PRECACHE_LI8F_FORWARD);
  46. int flags = cmsFLAGS_FLOATSHAPER;
  47. #else
  48. int flags = 0;
  49. #endif
  50. transformFixed = cmsCreateTransform(
  51. linput_profile, TYPE_RGB_8,
  52. loutput_profile, TYPE_RGB_8,
  53. INTENT_RELATIVE_COLORIMETRIC, flags);
  54. #if 0
  55. QCMS_INTENT_PERCEPTUAL = 0,
  56. QCMS_INTENT_RELATIVE_COLORIMETRIC = 1,
  57. QCMS_INTENT_SATURATION = 2,
  58. QCMS_INTENT_ABSOLUTE_COLORIMETRIC = 3
  59. #endif
  60. cmsDoTransform(transformFixed, src, loutput, LENGTH);
  61. clock_t lcms_time = clock() - lcms_start;
  62. clock_t qcms_start = clock();
  63. input_profile = qcms_profile_from_path(input_path);
  64. output_profile = qcms_profile_from_path(output_path);
  65. qcms_profile_precache_output_transform(output_profile);
  66. transform = qcms_transform_create(input_profile, QCMS_DATA_RGB_8, output_profile, QCMS_DATA_RGB_8, QCMS_INTENT_PERCEPTUAL);
  67. qcms_transform_data(transform, src, qoutput, LENGTH);
  68. clock_t qcms_time = clock() - qcms_start;
  69. printf("lcms: %ld\n", lcms_time);
  70. printf("qcms: %ld\n", qcms_time);
  71. int total_diff = 0;
  72. for (i=0; i<LENGTH; i++) {
  73. int diff = 0;
  74. diff += abs(loutput[i*3]-qoutput[i*3]);
  75. diff += abs(loutput[i*3+1]-qoutput[i*3+1]);
  76. diff += abs(loutput[i*3+2]-qoutput[i*3+2]);
  77. total_diff += diff;
  78. if (diff > 3) {
  79. printf("differing output(%d): (%d %d %d) -> l(%d %d %d) vs. q(%d %d %d)\n",
  80. diff, src[i*3], src[i*3+1], src[i*3+2],
  81. loutput[i*3], loutput[i*3+1], loutput[i*3+2],
  82. qoutput[i*3],
  83. qoutput[i*3+1],
  84. qoutput[i*3+2]);
  85. //exit(1);
  86. }
  87. }
  88. printf("%d - %f\n", total_diff, (double)total_diff/LENGTH);
  89. qcms_profile_release(input_profile);
  90. qcms_profile_release(output_profile);
  91. return 0;
  92. }