zoo_icc.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. //---------------------------------------------------------------------------------
  2. //
  3. // Little Color Management System
  4. // Copyright (c) 1998-2023 Marti Maria Saguer
  5. //
  6. // Permission is hereby granted, free of charge, to any person obtaining
  7. // a copy of this software and associated documentation files (the "Software"),
  8. // to deal in the Software without restriction, including without limitation
  9. // the rights to use, copy, modify, merge, publish, distribute, sublicense,
  10. // and/or sell copies of the Software, and to permit persons to whom the Software
  11. // is furnished to do so, subject to the following conditions:
  12. //
  13. // The above copyright notice and this permission notice shall be included in
  14. // all copies or substantial portions of the Software.
  15. //
  16. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  17. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  18. // THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  19. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  20. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  21. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  22. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. //
  24. //---------------------------------------------------------------------------------
  25. //
  26. #include "testcms2.h"
  27. // ZOO checks ------------------------------------------------------------------------------------------------------------
  28. #ifdef CMS_IS_WINDOWS_
  29. static char ZOOfolder[cmsMAX_PATH] = "c:\\colormaps\\";
  30. static char ZOOwrite[cmsMAX_PATH] = "c:\\colormaps\\write\\";
  31. static char ZOORawWrite[cmsMAX_PATH] = "c:\\colormaps\\rawwrite\\";
  32. // Read all tags on a profile given by its handle
  33. static
  34. void ReadAllTags(cmsContext ContextID, cmsHPROFILE h)
  35. {
  36. cmsInt32Number i, n;
  37. cmsTagSignature sig;
  38. n = cmsGetTagCount(ContextID, h);
  39. for (i=0; i < n; i++) {
  40. sig = cmsGetTagSignature(ContextID, h, i);
  41. if (cmsReadTag(ContextID, h, sig) == NULL) return;
  42. }
  43. }
  44. // Read all tags on a profile given by its handle
  45. static
  46. void ReadAllRAWTags(cmsContext ContextID, cmsHPROFILE h)
  47. {
  48. cmsInt32Number i, n;
  49. cmsTagSignature sig;
  50. cmsInt32Number len;
  51. n = cmsGetTagCount(ContextID, h);
  52. for (i=0; i < n; i++) {
  53. sig = cmsGetTagSignature(ContextID, h, i);
  54. len = cmsReadRawTag(ContextID, h, sig, NULL, 0);
  55. }
  56. }
  57. static
  58. void PrintInfo(cmsContext ContextID, cmsHPROFILE h, cmsInfoType Info)
  59. {
  60. wchar_t* text;
  61. cmsInt32Number len;
  62. cmsContext id = 0;
  63. len = cmsGetProfileInfo(ContextID, h, Info, "en", "US", NULL, 0);
  64. if (len == 0) return;
  65. text = (wchar_t*) _cmsMalloc(id, len);
  66. cmsGetProfileInfo(ContextID, h, Info, "en", "US", text, len);
  67. wprintf(L"%s\n", text);
  68. _cmsFree(id, text);
  69. }
  70. static
  71. void PrintAllInfos(cmsContext ContextID, cmsHPROFILE h)
  72. {
  73. PrintInfo(ContextID, h, cmsInfoDescription);
  74. PrintInfo(ContextID, h, cmsInfoManufacturer);
  75. PrintInfo(ContextID, h, cmsInfoModel);
  76. PrintInfo(ContextID, h, cmsInfoCopyright);
  77. printf("\n\n");
  78. }
  79. static
  80. void ReadAllLUTS(cmsContext ContextID, cmsHPROFILE h)
  81. {
  82. cmsPipeline* a;
  83. cmsCIEXYZ Black;
  84. a = _cmsReadInputLUT(ContextID, h, INTENT_PERCEPTUAL);
  85. if (a) cmsPipelineFree(ContextID, a);
  86. a = _cmsReadInputLUT(ContextID, h, INTENT_RELATIVE_COLORIMETRIC);
  87. if (a) cmsPipelineFree(ContextID, a);
  88. a = _cmsReadInputLUT(ContextID, h, INTENT_SATURATION);
  89. if (a) cmsPipelineFree(ContextID, a);
  90. a = _cmsReadInputLUT(ContextID, h, INTENT_ABSOLUTE_COLORIMETRIC);
  91. if (a) cmsPipelineFree(ContextID, a);
  92. a = _cmsReadOutputLUT(ContextID, h, INTENT_PERCEPTUAL);
  93. if (a) cmsPipelineFree(ContextID, a);
  94. a = _cmsReadOutputLUT(ContextID, h, INTENT_RELATIVE_COLORIMETRIC);
  95. if (a) cmsPipelineFree(ContextID, a);
  96. a = _cmsReadOutputLUT(ContextID, h, INTENT_SATURATION);
  97. if (a) cmsPipelineFree(ContextID, a);
  98. a = _cmsReadOutputLUT(ContextID, h, INTENT_ABSOLUTE_COLORIMETRIC);
  99. if (a) cmsPipelineFree(ContextID, a);
  100. a = _cmsReadDevicelinkLUT(ContextID, h, INTENT_PERCEPTUAL);
  101. if (a) cmsPipelineFree(ContextID, a);
  102. a = _cmsReadDevicelinkLUT(ContextID, h, INTENT_RELATIVE_COLORIMETRIC);
  103. if (a) cmsPipelineFree(ContextID, a);
  104. a = _cmsReadDevicelinkLUT(ContextID, h, INTENT_SATURATION);
  105. if (a) cmsPipelineFree(ContextID, a);
  106. a = _cmsReadDevicelinkLUT(ContextID, h, INTENT_ABSOLUTE_COLORIMETRIC);
  107. if (a) cmsPipelineFree(ContextID, a);
  108. cmsDetectDestinationBlackPoint(ContextID, &Black, h, INTENT_PERCEPTUAL, 0);
  109. cmsDetectDestinationBlackPoint(ContextID, &Black, h, INTENT_RELATIVE_COLORIMETRIC, 0);
  110. cmsDetectDestinationBlackPoint(ContextID, &Black, h, INTENT_SATURATION, 0);
  111. cmsDetectDestinationBlackPoint(ContextID, &Black, h, INTENT_ABSOLUTE_COLORIMETRIC, 0);
  112. cmsDetectTAC(ContextID, h);
  113. }
  114. // Check one specimen in the ZOO
  115. static
  116. cmsInt32Number CheckSingleSpecimen(cmsContext ContextID, const char* Profile)
  117. {
  118. char BuffSrc[256];
  119. char BuffDst[256];
  120. cmsHPROFILE h;
  121. sprintf(BuffSrc, "%s%s", ZOOfolder, Profile);
  122. sprintf(BuffDst, "%s%s", ZOOwrite, Profile);
  123. h = cmsOpenProfileFromFile(ContextID, BuffSrc, "r");
  124. if (h == NULL) return 0;
  125. printf("%s\n", Profile);
  126. PrintAllInfos(ContextID, h);
  127. ReadAllTags(ContextID, h);
  128. ReadAllLUTS(ContextID, h);
  129. // ReadAllRAWTags(ContextID, h);
  130. cmsSaveProfileToFile(ContextID, h, BuffDst);
  131. cmsCloseProfile(ContextID, h);
  132. h = cmsOpenProfileFromFile(ContextID, BuffDst, "r");
  133. if (h == NULL) return 0;
  134. ReadAllTags(ContextID, h);
  135. cmsCloseProfile(ContextID, h);
  136. return 1;
  137. }
  138. static
  139. cmsInt32Number CheckRAWSpecimen(cmsContext ContextID, const char* Profile)
  140. {
  141. char BuffSrc[256];
  142. char BuffDst[256];
  143. cmsHPROFILE h;
  144. sprintf(BuffSrc, "%s%s", ZOOfolder, Profile);
  145. sprintf(BuffDst, "%s%s", ZOORawWrite, Profile);
  146. h = cmsOpenProfileFromFile(ContextID, BuffSrc, "r");
  147. if (h == NULL) return 0;
  148. ReadAllTags(ContextID, h);
  149. ReadAllRAWTags(ContextID, h);
  150. cmsSaveProfileToFile(ContextID, h, BuffDst);
  151. cmsCloseProfile(ContextID, h);
  152. h = cmsOpenProfileFromFile(ContextID, BuffDst, "r");
  153. if (h == NULL) return 0;
  154. ReadAllTags(ContextID, h);
  155. cmsCloseProfile(ContextID, h);
  156. return 1;
  157. }
  158. static int input = 0,
  159. disp = 0,
  160. output = 0,
  161. link = 0,
  162. abst = 0,
  163. color = 0,
  164. named = 0;
  165. static int rgb = 0,
  166. cmyk = 0,
  167. gray = 0,
  168. other = 0;
  169. static
  170. int count_stats(cmsContext ContextID, const char* Profile)
  171. {
  172. char BuffSrc[256];
  173. cmsHPROFILE h;
  174. cmsCIEXYZ Black;
  175. sprintf(BuffSrc, "%s%s", ZOOfolder, Profile);
  176. h = cmsOpenProfileFromFile(ContextID, BuffSrc, "r");
  177. if (h == NULL) return 0;
  178. switch (cmsGetDeviceClass(ContextID, h)) {
  179. case cmsSigInputClass : input++; break;
  180. case cmsSigDisplayClass : disp++; break;
  181. case cmsSigOutputClass : output++; break;
  182. case cmsSigLinkClass : link++; break;
  183. case cmsSigAbstractClass : abst++; break;
  184. case cmsSigColorSpaceClass : color++; break;
  185. case cmsSigNamedColorClass : named ++; break;
  186. }
  187. switch (cmsGetColorSpace(ContextID, h)) {
  188. case cmsSigRgbData: rgb++; break;
  189. case cmsSigCmykData: cmyk++; break;
  190. case cmsSigGrayData: gray++; break;
  191. default: other++;
  192. }
  193. cmsDetectDestinationBlackPoint(ContextID, &Black, h, INTENT_PERCEPTUAL, 0);
  194. cmsDetectDestinationBlackPoint(ContextID, &Black, h, INTENT_RELATIVE_COLORIMETRIC, 0);
  195. cmsDetectDestinationBlackPoint(ContextID, &Black, h, INTENT_SATURATION, 0);
  196. cmsCloseProfile(ContextID, h);
  197. return 1;
  198. }
  199. void CheckProfileZOO(cmsContext ContextID)
  200. {
  201. struct _finddata_t c_file;
  202. intptr_t hFile;
  203. cmsSetLogErrorHandler(ContextID, NULL);
  204. if ( (hFile = _findfirst("c:\\colormaps\\*.*", &c_file)) == -1L )
  205. printf("No files in current directory");
  206. else
  207. {
  208. do
  209. {
  210. if (strcmp(c_file.name, ".") != 0 &&
  211. strcmp(c_file.name, "..") != 0) {
  212. CheckSingleSpecimen(ContextID, c_file.name);
  213. CheckRAWSpecimen(ContextID, c_file.name);
  214. count_stats(ContextID, c_file.name);
  215. TestMemoryLeaks(FALSE);
  216. }
  217. } while ( _findnext(hFile, &c_file) == 0 );
  218. _findclose(hFile);
  219. }
  220. ResetFatalError(ContextID);
  221. }
  222. #endif