13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 */
24
25 // This file is available under and governed by the GNU General Public
26 // License version 2 only, as published by the Free Software Foundation.
27 // However, the following notice accompanied the original version of this
28 // file:
29 //
30 //---------------------------------------------------------------------------------
31 //
32 // Little Color Management System
33 // Copyright (c) 1998-2010 Marti Maria Saguer
34 //
35 // Permission is hereby granted, free of charge, to any person obtaining
36 // a copy of this software and associated documentation files (the "Software"),
37 // to deal in the Software without restriction, including without limitation
38 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
39 // and/or sell copies of the Software, and to permit persons to whom the Software
40 // is furnished to do so, subject to the following conditions:
41 //
42 // The above copyright notice and this permission notice shall be included in
43 // all copies or substantial portions of the Software.
44 //
45 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
46 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
47 // THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
48 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
49 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
50 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
51 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
52 //
53 //---------------------------------------------------------------------------------
119 pOut[6] = pIn[1];
120 pOut[5] = pIn[2];
121 pOut[4] = pIn[3];
122 pOut[3] = pIn[4];
123 pOut[2] = pIn[5];
124 pOut[1] = pIn[6];
125 pOut[0] = pIn[7];
126
127 #else
128 _cmsAssert(Result != NULL);
129
130 # ifdef CMS_DONT_USE_INT64
131 (*Result)[0] = QWord[0];
132 (*Result)[1] = QWord[1];
133 # else
134 *Result = *QWord;
135 # endif
136 #endif
137 }
138
139 // Auxiliar -- read 8, 16 and 32-bit numbers
140 cmsBool CMSEXPORT _cmsReadUInt8Number(cmsIOHANDLER* io, cmsUInt8Number* n)
141 {
142 cmsUInt8Number tmp;
143
144 _cmsAssert(io != NULL);
145
146 if (io -> Read(io, &tmp, sizeof(cmsUInt8Number), 1) != 1)
147 return FALSE;
148
149 if (n != NULL) *n = tmp;
150 return TRUE;
151 }
152
153 cmsBool CMSEXPORT _cmsReadUInt16Number(cmsIOHANDLER* io, cmsUInt16Number* n)
154 {
155 cmsUInt16Number tmp;
156
157 _cmsAssert(io != NULL);
158
159 if (io -> Read(io, &tmp, sizeof(cmsUInt16Number), 1) != 1)
184
185 cmsBool CMSEXPORT _cmsReadUInt32Number(cmsIOHANDLER* io, cmsUInt32Number* n)
186 {
187 cmsUInt32Number tmp;
188
189 _cmsAssert(io != NULL);
190
191 if (io -> Read(io, &tmp, sizeof(cmsUInt32Number), 1) != 1)
192 return FALSE;
193
194 if (n != NULL) *n = _cmsAdjustEndianess32(tmp);
195 return TRUE;
196 }
197
198 cmsBool CMSEXPORT _cmsReadFloat32Number(cmsIOHANDLER* io, cmsFloat32Number* n)
199 {
200 cmsUInt32Number tmp;
201
202 _cmsAssert(io != NULL);
203
204 if (io -> Read(io, &tmp, sizeof(cmsFloat32Number), 1) != 1)
205 return FALSE;
206
207 if (n != NULL) {
208
209 tmp = _cmsAdjustEndianess32(tmp);
210 *n = *(cmsFloat32Number*) &tmp;
211 }
212 return TRUE;
213 }
214
215
216 cmsBool CMSEXPORT _cmsReadUInt64Number(cmsIOHANDLER* io, cmsUInt64Number* n)
217 {
218 cmsUInt64Number tmp;
219
220 _cmsAssert(io != NULL);
221
222 if (io -> Read(io, &tmp, sizeof(cmsUInt64Number), 1) != 1)
223 return FALSE;
224
225 if (n != NULL) _cmsAdjustEndianess64(n, &tmp);
226 return TRUE;
227 }
228
229
230 cmsBool CMSEXPORT _cmsRead15Fixed16Number(cmsIOHANDLER* io, cmsFloat64Number* n)
231 {
232 cmsUInt32Number tmp;
233
234 _cmsAssert(io != NULL);
235
236 if (io -> Read(io, &tmp, sizeof(cmsUInt32Number), 1) != 1)
237 return FALSE;
238
239 if (n != NULL) {
240 *n = _cms15Fixed16toDouble(_cmsAdjustEndianess32(tmp));
241 }
242
243 return TRUE;
244 }
245
246
247 // Jun-21-2000: Some profiles (those that comes with W2K) comes
248 // with the media white (media black?) x 100. Add a sanity check
249
250 static
251 void NormalizeXYZ(cmsCIEXYZ* Dest)
252 {
253 while (Dest -> X > 2. &&
254 Dest -> Y > 2. &&
255 Dest -> Z > 2.) {
256
257 Dest -> X /= 10.;
258 Dest -> Y /= 10.;
259 Dest -> Z /= 10.;
260 }
261 }
262
263 cmsBool CMSEXPORT _cmsReadXYZNumber(cmsIOHANDLER* io, cmsCIEXYZ* XYZ)
264 {
265 cmsEncodedXYZNumber xyz;
266
267 _cmsAssert(io != NULL);
268
269 if (io ->Read(io, &xyz, sizeof(cmsEncodedXYZNumber), 1) != 1) return FALSE;
270
271 if (XYZ != NULL) {
272
273 XYZ->X = _cms15Fixed16toDouble(_cmsAdjustEndianess32(xyz.X));
274 XYZ->Y = _cms15Fixed16toDouble(_cmsAdjustEndianess32(xyz.Y));
275 XYZ->Z = _cms15Fixed16toDouble(_cmsAdjustEndianess32(xyz.Z));
276
277 NormalizeXYZ(XYZ);
278 }
279 return TRUE;
280 }
281
282 cmsBool CMSEXPORT _cmsWriteUInt8Number(cmsIOHANDLER* io, cmsUInt8Number n)
283 {
284 _cmsAssert(io != NULL);
285
286 if (io -> Write(io, sizeof(cmsUInt8Number), &n) != 1)
287 return FALSE;
288
289 return TRUE;
290 }
291
292 cmsBool CMSEXPORT _cmsWriteUInt16Number(cmsIOHANDLER* io, cmsUInt16Number n)
293 {
294 cmsUInt16Number tmp;
295
296 _cmsAssert(io != NULL);
297
319 cmsBool CMSEXPORT _cmsWriteUInt32Number(cmsIOHANDLER* io, cmsUInt32Number n)
320 {
321 cmsUInt32Number tmp;
322
323 _cmsAssert(io != NULL);
324
325 tmp = _cmsAdjustEndianess32(n);
326 if (io -> Write(io, sizeof(cmsUInt32Number), &tmp) != 1)
327 return FALSE;
328
329 return TRUE;
330 }
331
332
333 cmsBool CMSEXPORT _cmsWriteFloat32Number(cmsIOHANDLER* io, cmsFloat32Number n)
334 {
335 cmsUInt32Number tmp;
336
337 _cmsAssert(io != NULL);
338
339 tmp = *(cmsUInt32Number*) &n;
340 tmp = _cmsAdjustEndianess32(tmp);
341 if (io -> Write(io, sizeof(cmsUInt32Number), &tmp) != 1)
342 return FALSE;
343
344 return TRUE;
345 }
346
347 cmsBool CMSEXPORT _cmsWriteUInt64Number(cmsIOHANDLER* io, cmsUInt64Number* n)
348 {
349 cmsUInt64Number tmp;
350
351 _cmsAssert(io != NULL);
352
353 _cmsAdjustEndianess64(&tmp, n);
354 if (io -> Write(io, sizeof(cmsUInt64Number), &tmp) != 1)
355 return FALSE;
356
357 return TRUE;
358 }
359
515
516 memset(Buffer, 0, BytesToNextAlignedPos);
517 return io -> Write(io, BytesToNextAlignedPos, Buffer);
518 }
519
520
521 // To deal with text streams. 2K at most
522 cmsBool CMSEXPORT _cmsIOPrintf(cmsIOHANDLER* io, const char* frm, ...)
523 {
524 va_list args;
525 int len;
526 cmsUInt8Number Buffer[2048];
527 cmsBool rc;
528
529 _cmsAssert(io != NULL);
530 _cmsAssert(frm != NULL);
531
532 va_start(args, frm);
533
534 len = vsnprintf((char*) Buffer, 2047, frm, args);
535 if (len < 0) return FALSE; // Truncated, which is a fatal error for us
536
537 rc = io ->Write(io, len, Buffer);
538
539 va_end(args);
540
541 return rc;
542 }
543
544
545 // Plugin memory management -------------------------------------------------------------------------------------------------
546
547 // Specialized malloc for plug-ins, that is freed upon exit.
548 void* _cmsPluginMalloc(cmsContext ContextID, cmsUInt32Number size)
549 {
550 struct _cmsContext_struct* ctx = _cmsGetContext(ContextID);
551
552 if (ctx ->MemPool == NULL) {
553
554 if (ContextID == NULL) {
555
556 ctx->MemPool = _cmsCreateSubAlloc(0, 2*1024);
557 }
558 else {
559 cmsSignalError(ContextID, cmsERROR_CORRUPTION_DETECTED, "NULL memory pool on context");
560 return NULL;
561 }
562 }
563
564 return _cmsSubAlloc(ctx->MemPool, size);
565 }
566
567
568 // Main plug-in dispatcher
569 cmsBool CMSEXPORT cmsPlugin(void* Plug_in)
570 {
571 return cmsPluginTHR(NULL, Plug_in);
572 }
573
574 cmsBool CMSEXPORT cmsPluginTHR(cmsContext id, void* Plug_in)
575 {
576 cmsPluginBase* Plugin;
|
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 */
24
25 // This file is available under and governed by the GNU General Public
26 // License version 2 only, as published by the Free Software Foundation.
27 // However, the following notice accompanied the original version of this
28 // file:
29 //
30 //---------------------------------------------------------------------------------
31 //
32 // Little Color Management System
33 // Copyright (c) 1998-2016 Marti Maria Saguer
34 //
35 // Permission is hereby granted, free of charge, to any person obtaining
36 // a copy of this software and associated documentation files (the "Software"),
37 // to deal in the Software without restriction, including without limitation
38 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
39 // and/or sell copies of the Software, and to permit persons to whom the Software
40 // is furnished to do so, subject to the following conditions:
41 //
42 // The above copyright notice and this permission notice shall be included in
43 // all copies or substantial portions of the Software.
44 //
45 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
46 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
47 // THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
48 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
49 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
50 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
51 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
52 //
53 //---------------------------------------------------------------------------------
119 pOut[6] = pIn[1];
120 pOut[5] = pIn[2];
121 pOut[4] = pIn[3];
122 pOut[3] = pIn[4];
123 pOut[2] = pIn[5];
124 pOut[1] = pIn[6];
125 pOut[0] = pIn[7];
126
127 #else
128 _cmsAssert(Result != NULL);
129
130 # ifdef CMS_DONT_USE_INT64
131 (*Result)[0] = QWord[0];
132 (*Result)[1] = QWord[1];
133 # else
134 *Result = *QWord;
135 # endif
136 #endif
137 }
138
139 // Auxiliary -- read 8, 16 and 32-bit numbers
140 cmsBool CMSEXPORT _cmsReadUInt8Number(cmsIOHANDLER* io, cmsUInt8Number* n)
141 {
142 cmsUInt8Number tmp;
143
144 _cmsAssert(io != NULL);
145
146 if (io -> Read(io, &tmp, sizeof(cmsUInt8Number), 1) != 1)
147 return FALSE;
148
149 if (n != NULL) *n = tmp;
150 return TRUE;
151 }
152
153 cmsBool CMSEXPORT _cmsReadUInt16Number(cmsIOHANDLER* io, cmsUInt16Number* n)
154 {
155 cmsUInt16Number tmp;
156
157 _cmsAssert(io != NULL);
158
159 if (io -> Read(io, &tmp, sizeof(cmsUInt16Number), 1) != 1)
184
185 cmsBool CMSEXPORT _cmsReadUInt32Number(cmsIOHANDLER* io, cmsUInt32Number* n)
186 {
187 cmsUInt32Number tmp;
188
189 _cmsAssert(io != NULL);
190
191 if (io -> Read(io, &tmp, sizeof(cmsUInt32Number), 1) != 1)
192 return FALSE;
193
194 if (n != NULL) *n = _cmsAdjustEndianess32(tmp);
195 return TRUE;
196 }
197
198 cmsBool CMSEXPORT _cmsReadFloat32Number(cmsIOHANDLER* io, cmsFloat32Number* n)
199 {
200 cmsUInt32Number tmp;
201
202 _cmsAssert(io != NULL);
203
204 if (io -> Read(io, &tmp, sizeof(cmsUInt32Number), 1) != 1)
205 return FALSE;
206
207 if (n != NULL) {
208
209 tmp = _cmsAdjustEndianess32(tmp);
210 *n = *(cmsFloat32Number*) (void*) &tmp;
211 }
212 return TRUE;
213 }
214
215
216 cmsBool CMSEXPORT _cmsReadUInt64Number(cmsIOHANDLER* io, cmsUInt64Number* n)
217 {
218 cmsUInt64Number tmp;
219
220 _cmsAssert(io != NULL);
221
222 if (io -> Read(io, &tmp, sizeof(cmsUInt64Number), 1) != 1)
223 return FALSE;
224
225 if (n != NULL) _cmsAdjustEndianess64(n, &tmp);
226 return TRUE;
227 }
228
229
230 cmsBool CMSEXPORT _cmsRead15Fixed16Number(cmsIOHANDLER* io, cmsFloat64Number* n)
231 {
232 cmsUInt32Number tmp;
233
234 _cmsAssert(io != NULL);
235
236 if (io -> Read(io, &tmp, sizeof(cmsUInt32Number), 1) != 1)
237 return FALSE;
238
239 if (n != NULL) {
240 *n = _cms15Fixed16toDouble(_cmsAdjustEndianess32(tmp));
241 }
242
243 return TRUE;
244 }
245
246
247 cmsBool CMSEXPORT _cmsReadXYZNumber(cmsIOHANDLER* io, cmsCIEXYZ* XYZ)
248 {
249 cmsEncodedXYZNumber xyz;
250
251 _cmsAssert(io != NULL);
252
253 if (io ->Read(io, &xyz, sizeof(cmsEncodedXYZNumber), 1) != 1) return FALSE;
254
255 if (XYZ != NULL) {
256
257 XYZ->X = _cms15Fixed16toDouble(_cmsAdjustEndianess32(xyz.X));
258 XYZ->Y = _cms15Fixed16toDouble(_cmsAdjustEndianess32(xyz.Y));
259 XYZ->Z = _cms15Fixed16toDouble(_cmsAdjustEndianess32(xyz.Z));
260 }
261 return TRUE;
262 }
263
264 cmsBool CMSEXPORT _cmsWriteUInt8Number(cmsIOHANDLER* io, cmsUInt8Number n)
265 {
266 _cmsAssert(io != NULL);
267
268 if (io -> Write(io, sizeof(cmsUInt8Number), &n) != 1)
269 return FALSE;
270
271 return TRUE;
272 }
273
274 cmsBool CMSEXPORT _cmsWriteUInt16Number(cmsIOHANDLER* io, cmsUInt16Number n)
275 {
276 cmsUInt16Number tmp;
277
278 _cmsAssert(io != NULL);
279
301 cmsBool CMSEXPORT _cmsWriteUInt32Number(cmsIOHANDLER* io, cmsUInt32Number n)
302 {
303 cmsUInt32Number tmp;
304
305 _cmsAssert(io != NULL);
306
307 tmp = _cmsAdjustEndianess32(n);
308 if (io -> Write(io, sizeof(cmsUInt32Number), &tmp) != 1)
309 return FALSE;
310
311 return TRUE;
312 }
313
314
315 cmsBool CMSEXPORT _cmsWriteFloat32Number(cmsIOHANDLER* io, cmsFloat32Number n)
316 {
317 cmsUInt32Number tmp;
318
319 _cmsAssert(io != NULL);
320
321 tmp = *(cmsUInt32Number*) (void*) &n;
322 tmp = _cmsAdjustEndianess32(tmp);
323 if (io -> Write(io, sizeof(cmsUInt32Number), &tmp) != 1)
324 return FALSE;
325
326 return TRUE;
327 }
328
329 cmsBool CMSEXPORT _cmsWriteUInt64Number(cmsIOHANDLER* io, cmsUInt64Number* n)
330 {
331 cmsUInt64Number tmp;
332
333 _cmsAssert(io != NULL);
334
335 _cmsAdjustEndianess64(&tmp, n);
336 if (io -> Write(io, sizeof(cmsUInt64Number), &tmp) != 1)
337 return FALSE;
338
339 return TRUE;
340 }
341
497
498 memset(Buffer, 0, BytesToNextAlignedPos);
499 return io -> Write(io, BytesToNextAlignedPos, Buffer);
500 }
501
502
503 // To deal with text streams. 2K at most
504 cmsBool CMSEXPORT _cmsIOPrintf(cmsIOHANDLER* io, const char* frm, ...)
505 {
506 va_list args;
507 int len;
508 cmsUInt8Number Buffer[2048];
509 cmsBool rc;
510
511 _cmsAssert(io != NULL);
512 _cmsAssert(frm != NULL);
513
514 va_start(args, frm);
515
516 len = vsnprintf((char*) Buffer, 2047, frm, args);
517 if (len < 0) {
518 va_end(args);
519 return FALSE; // Truncated, which is a fatal error for us
520 }
521
522 rc = io ->Write(io, len, Buffer);
523
524 va_end(args);
525
526 return rc;
527 }
528
529
530 // Plugin memory management -------------------------------------------------------------------------------------------------
531
532 // Specialized malloc for plug-ins, that is freed upon exit.
533 void* _cmsPluginMalloc(cmsContext ContextID, cmsUInt32Number size)
534 {
535 struct _cmsContext_struct* ctx = _cmsGetContext(ContextID);
536
537 if (ctx ->MemPool == NULL) {
538
539 if (ContextID == NULL) {
540
541 ctx->MemPool = _cmsCreateSubAlloc(0, 2*1024);
542 if (ctx->MemPool == NULL) return NULL;
543 }
544 else {
545 cmsSignalError(ContextID, cmsERROR_CORRUPTION_DETECTED, "NULL memory pool on context");
546 return NULL;
547 }
548 }
549
550 return _cmsSubAlloc(ctx->MemPool, size);
551 }
552
553
554 // Main plug-in dispatcher
555 cmsBool CMSEXPORT cmsPlugin(void* Plug_in)
556 {
557 return cmsPluginTHR(NULL, Plug_in);
558 }
559
560 cmsBool CMSEXPORT cmsPluginTHR(cmsContext id, void* Plug_in)
561 {
562 cmsPluginBase* Plugin;
|