1 //---------------------------------------------------------------------------------
2 //
3 // Little Color Management System
4 // Copyright (c) 1998-2017 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
27
28 #include "testcms2.h"
29
30
31 // ZOO checks ------------------------------------------------------------------------------------------------------------
32
33
34 #ifdef CMS_IS_WINDOWS_
35
36 static char ZOOfolder[cmsMAX_PATH] = "c:\\colormaps\\";
37 static char ZOOwrite[cmsMAX_PATH] = "c:\\colormaps\\write\\";
38 static char ZOORawWrite[cmsMAX_PATH] = "c:\\colormaps\\rawwrite\\";
39
40
41 // Read all tags on a profile given by its handle
42 static
ReadAllTags(cmsContext ContextID,cmsHPROFILE h)43 void ReadAllTags(cmsContext ContextID, cmsHPROFILE h)
44 {
45 cmsInt32Number i, n;
46 cmsTagSignature sig;
47
48 n = cmsGetTagCount(ContextID, h);
49 for (i=0; i < n; i++) {
50
51 sig = cmsGetTagSignature(ContextID, h, i);
52 if (cmsReadTag(ContextID, h, sig) == NULL) return;
53 }
54 }
55
56
57 // Read all tags on a profile given by its handle
58 static
ReadAllRAWTags(cmsContext ContextID,cmsHPROFILE h)59 void ReadAllRAWTags(cmsContext ContextID, cmsHPROFILE h)
60 {
61 cmsInt32Number i, n;
62 cmsTagSignature sig;
63 cmsInt32Number len;
64
65 n = cmsGetTagCount(ContextID, h);
66 for (i=0; i < n; i++) {
67
68 sig = cmsGetTagSignature(ContextID, h, i);
69 len = cmsReadRawTag(ContextID, h, sig, NULL, 0);
70 }
71 }
72
73
74 static
PrintInfo(cmsContext ContextID,cmsHPROFILE h,cmsInfoType Info)75 void PrintInfo(cmsContext ContextID, cmsHPROFILE h, cmsInfoType Info)
76 {
77 wchar_t* text;
78 cmsInt32Number len;
79 cmsContext id = 0;
80
81 len = cmsGetProfileInfo(ContextID, h, Info, "en", "US", NULL, 0);
82 if (len == 0) return;
83
84 text = _cmsMalloc(id, len);
85 cmsGetProfileInfo(ContextID, h, Info, "en", "US", text, len);
86
87 wprintf(L"%s\n", text);
88 _cmsFree(id, text);
89 }
90
91
92 static
PrintAllInfos(cmsContext ContextID,cmsHPROFILE h)93 void PrintAllInfos(cmsContext ContextID, cmsHPROFILE h)
94 {
95 PrintInfo(ContextID, h, cmsInfoDescription);
96 PrintInfo(ContextID, h, cmsInfoManufacturer);
97 PrintInfo(ContextID, h, cmsInfoModel);
98 PrintInfo(ContextID, h, cmsInfoCopyright);
99 printf("\n\n");
100 }
101
102 static
ReadAllLUTS(cmsContext ContextID,cmsHPROFILE h)103 void ReadAllLUTS(cmsContext ContextID, cmsHPROFILE h)
104 {
105 cmsPipeline* a;
106 cmsCIEXYZ Black;
107
108 a = _cmsReadInputLUT(ContextID, h, INTENT_PERCEPTUAL);
109 if (a) cmsPipelineFree(ContextID, a);
110
111 a = _cmsReadInputLUT(ContextID, h, INTENT_RELATIVE_COLORIMETRIC);
112 if (a) cmsPipelineFree(ContextID, a);
113
114 a = _cmsReadInputLUT(ContextID, h, INTENT_SATURATION);
115 if (a) cmsPipelineFree(ContextID, a);
116
117 a = _cmsReadInputLUT(ContextID, h, INTENT_ABSOLUTE_COLORIMETRIC);
118 if (a) cmsPipelineFree(ContextID, a);
119
120
121 a = _cmsReadOutputLUT(ContextID, h, INTENT_PERCEPTUAL);
122 if (a) cmsPipelineFree(ContextID, a);
123
124 a = _cmsReadOutputLUT(ContextID, h, INTENT_RELATIVE_COLORIMETRIC);
125 if (a) cmsPipelineFree(ContextID, a);
126
127 a = _cmsReadOutputLUT(ContextID, h, INTENT_SATURATION);
128 if (a) cmsPipelineFree(ContextID, a);
129
130 a = _cmsReadOutputLUT(ContextID, h, INTENT_ABSOLUTE_COLORIMETRIC);
131 if (a) cmsPipelineFree(ContextID, a);
132
133
134 a = _cmsReadDevicelinkLUT(ContextID, h, INTENT_PERCEPTUAL);
135 if (a) cmsPipelineFree(ContextID, a);
136
137 a = _cmsReadDevicelinkLUT(ContextID, h, INTENT_RELATIVE_COLORIMETRIC);
138 if (a) cmsPipelineFree(ContextID, a);
139
140 a = _cmsReadDevicelinkLUT(ContextID, h, INTENT_SATURATION);
141 if (a) cmsPipelineFree(ContextID, a);
142
143 a = _cmsReadDevicelinkLUT(ContextID, h, INTENT_ABSOLUTE_COLORIMETRIC);
144 if (a) cmsPipelineFree(ContextID, a);
145
146
147 cmsDetectDestinationBlackPoint(ContextID, &Black, h, INTENT_PERCEPTUAL, 0);
148 cmsDetectDestinationBlackPoint(ContextID, &Black, h, INTENT_RELATIVE_COLORIMETRIC, 0);
149 cmsDetectDestinationBlackPoint(ContextID, &Black, h, INTENT_SATURATION, 0);
150 cmsDetectDestinationBlackPoint(ContextID, &Black, h, INTENT_ABSOLUTE_COLORIMETRIC, 0);
151 cmsDetectTAC(ContextID, h);
152 }
153
154 // Check one specimen in the ZOO
155
156 static
CheckSingleSpecimen(cmsContext ContextID,const char * Profile)157 cmsInt32Number CheckSingleSpecimen(cmsContext ContextID, const char* Profile)
158 {
159 char BuffSrc[256];
160 char BuffDst[256];
161 cmsHPROFILE h;
162
163 sprintf(BuffSrc, "%s%s", ZOOfolder, Profile);
164 sprintf(BuffDst, "%s%s", ZOOwrite, Profile);
165
166 h = cmsOpenProfileFromFile(ContextID, BuffSrc, "r");
167 if (h == NULL) return 0;
168
169 printf("%s\n", Profile);
170
171 PrintAllInfos(ContextID, h);
172 ReadAllTags(ContextID, h);
173 ReadAllLUTS(ContextID, h);
174 // ReadAllRAWTags(ContextID, h);
175
176
177 cmsSaveProfileToFile(ContextID, h, BuffDst);
178 cmsCloseProfile(ContextID, h);
179
180 h = cmsOpenProfileFromFile(ContextID, BuffDst, "r");
181 if (h == NULL) return 0;
182 ReadAllTags(ContextID, h);
183
184
185 cmsCloseProfile(ContextID, h);
186
187 return 1;
188 }
189
190 static
CheckRAWSpecimen(cmsContext ContextID,const char * Profile)191 cmsInt32Number CheckRAWSpecimen(cmsContext ContextID, const char* Profile)
192 {
193 char BuffSrc[256];
194 char BuffDst[256];
195 cmsHPROFILE h;
196
197 sprintf(BuffSrc, "%s%s", ZOOfolder, Profile);
198 sprintf(BuffDst, "%s%s", ZOORawWrite, Profile);
199
200 h = cmsOpenProfileFromFile(ContextID, BuffSrc, "r");
201 if (h == NULL) return 0;
202
203 ReadAllTags(ContextID, h);
204 ReadAllRAWTags(ContextID, h);
205 cmsSaveProfileToFile(ContextID, h, BuffDst);
206 cmsCloseProfile(ContextID, h);
207
208 h = cmsOpenProfileFromFile(ContextID, BuffDst, "r");
209 if (h == NULL) return 0;
210 ReadAllTags(ContextID, h);
211 cmsCloseProfile(ContextID, h);
212
213 return 1;
214 }
215
216
217 static int input = 0,
218 disp = 0,
219 output = 0,
220 link = 0,
221 abst = 0,
222 color = 0,
223 named = 0;
224
225 static int rgb = 0,
226 cmyk = 0,
227 gray = 0,
228 other = 0;
229
230
231
232 static
count_stats(cmsContext ContextID,const char * Profile)233 int count_stats(cmsContext ContextID, const char* Profile)
234 {
235 char BuffSrc[256];
236 cmsHPROFILE h;
237 cmsCIEXYZ Black;
238
239 sprintf(BuffSrc, "%s%s", ZOOfolder, Profile);
240
241 h = cmsOpenProfileFromFile(ContextID, BuffSrc, "r");
242 if (h == NULL) return 0;
243
244
245 switch (cmsGetDeviceClass(ContextID, h)) {
246
247 case cmsSigInputClass : input++; break;
248 case cmsSigDisplayClass : disp++; break;
249 case cmsSigOutputClass : output++; break;
250 case cmsSigLinkClass : link++; break;
251 case cmsSigAbstractClass : abst++; break;
252 case cmsSigColorSpaceClass : color++; break;
253 case cmsSigNamedColorClass : named ++; break;
254 }
255
256
257 switch (cmsGetColorSpace(ContextID, h)) {
258
259 case cmsSigRgbData: rgb++; break;
260 case cmsSigCmykData: cmyk++; break;
261 case cmsSigGrayData: gray++; break;
262 default: other++;
263 }
264
265 cmsDetectDestinationBlackPoint(ContextID, &Black, h, INTENT_PERCEPTUAL, 0);
266 cmsDetectDestinationBlackPoint(ContextID, &Black, h, INTENT_RELATIVE_COLORIMETRIC, 0);
267 cmsDetectDestinationBlackPoint(ContextID, &Black, h, INTENT_SATURATION, 0);
268
269 cmsCloseProfile(ContextID, h);
270
271 return 1;
272 }
273
274
275
CheckProfileZOO(cmsContext ContextID)276 void CheckProfileZOO(cmsContext ContextID)
277 {
278 struct _finddata_t c_file;
279 intptr_t hFile;
280
281 cmsSetLogErrorHandler(ContextID, NULL);
282
283 if ( (hFile = _findfirst("c:\\colormaps\\*.*", &c_file)) == -1L )
284 printf("No files in current directory");
285 else
286 {
287 do
288 {
289 if (strcmp(c_file.name, ".") != 0 &&
290 strcmp(c_file.name, "..") != 0) {
291
292 CheckSingleSpecimen(ContextID, c_file.name);
293 CheckRAWSpecimen(ContextID, c_file.name);
294
295 count_stats(ContextID, c_file.name);
296
297 TestMemoryLeaks(FALSE);
298
299 }
300
301 } while ( _findnext(hFile, &c_file) == 0 );
302
303 _findclose(hFile);
304 }
305
306 ResetFatalError(ContextID);
307 }
308
309 #endif
310