Coverage Report

Created: 2024-06-18 06:34

/src/mupdf/thirdparty/lcms2/src/cmsio1.c
Line
Count
Source (jump to first uncovered line)
1
//---------------------------------------------------------------------------------
2
//
3
//  Little Color Management System
4
//  Copyright (c) 1998-2022 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
#include "lcms2_internal.h"
28
29
// Read tags using low-level functions, provides necessary glue code to adapt versions, etc.
30
31
// LUT tags
32
static const cmsTagSignature Device2PCS16[]   =  {cmsSigAToB0Tag,     // Perceptual
33
                                                  cmsSigAToB1Tag,     // Relative colorimetric
34
                                                  cmsSigAToB2Tag,     // Saturation
35
                                                  cmsSigAToB1Tag };   // Absolute colorimetric
36
37
static const cmsTagSignature Device2PCSFloat[] = {cmsSigDToB0Tag,     // Perceptual
38
                                                  cmsSigDToB1Tag,     // Relative colorimetric
39
                                                  cmsSigDToB2Tag,     // Saturation
40
                                                  cmsSigDToB3Tag };   // Absolute colorimetric
41
42
static const cmsTagSignature PCS2Device16[]    = {cmsSigBToA0Tag,     // Perceptual
43
                                                  cmsSigBToA1Tag,     // Relative colorimetric
44
                                                  cmsSigBToA2Tag,     // Saturation
45
                                                  cmsSigBToA1Tag };   // Absolute colorimetric
46
47
static const cmsTagSignature PCS2DeviceFloat[] = {cmsSigBToD0Tag,     // Perceptual
48
                                                  cmsSigBToD1Tag,     // Relative colorimetric
49
                                                  cmsSigBToD2Tag,     // Saturation
50
                                                  cmsSigBToD3Tag };   // Absolute colorimetric
51
52
53
// Factors to convert from 1.15 fixed point to 0..1.0 range and vice-versa
54
65.4k
#define InpAdj   (1.0/MAX_ENCODEABLE_XYZ)     // (65536.0/(65535.0*2.0))
55
38.5k
#define OutpAdj  (MAX_ENCODEABLE_XYZ)         // ((2.0*65535.0)/65536.0)
56
57
// Several resources for gray conversions.
58
static const cmsFloat64Number GrayInputMatrix[] = { (InpAdj*cmsD50X),  (InpAdj*cmsD50Y),  (InpAdj*cmsD50Z) };
59
static const cmsFloat64Number OneToThreeInputMatrix[] = { 1, 1, 1 };
60
static const cmsFloat64Number PickYMatrix[] = { 0, (OutpAdj*cmsD50Y), 0 };
61
static const cmsFloat64Number PickLstarMatrix[] = { 1, 0, 0 };
62
63
// Get a media white point fixing some issues found in certain old profiles
64
cmsBool  _cmsReadMediaWhitePoint(cmsContext ContextID, cmsCIEXYZ* Dest, cmsHPROFILE hProfile)
65
0
{
66
0
    cmsCIEXYZ* Tag;
67
68
0
    _cmsAssert(Dest != NULL);
69
70
0
    Tag = (cmsCIEXYZ*) cmsReadTag(ContextID, hProfile, cmsSigMediaWhitePointTag);
71
72
    // If no wp, take D50
73
0
    if (Tag == NULL) {
74
0
        *Dest = *cmsD50_XYZ(ContextID);
75
0
        return TRUE;
76
0
    }
77
78
    // V2 display profiles should give D50
79
0
    if (cmsGetEncodedICCversion(ContextID, hProfile) < 0x4000000) {
80
81
0
        if (cmsGetDeviceClass(ContextID, hProfile) == cmsSigDisplayClass) {
82
0
            *Dest = *cmsD50_XYZ(ContextID);
83
0
            return TRUE;
84
0
        }
85
0
    }
86
87
    // All seems ok
88
0
    *Dest = *Tag;
89
0
    return TRUE;
90
0
}
91
92
93
// Chromatic adaptation matrix. Fix some issues as well
94
cmsBool  _cmsReadCHAD(cmsContext ContextID, cmsMAT3* Dest, cmsHPROFILE hProfile)
95
0
{
96
0
    cmsMAT3* Tag;
97
98
0
    _cmsAssert(Dest != NULL);
99
100
0
    Tag = (cmsMAT3*) cmsReadTag(ContextID, hProfile, cmsSigChromaticAdaptationTag);
101
102
0
    if (Tag != NULL) {
103
0
        *Dest = *Tag;
104
0
        return TRUE;
105
0
    }
106
107
    // No CHAD available, default it to identity
108
0
    _cmsMAT3identity(ContextID, Dest);
109
110
    // V2 display profiles should give D50
111
0
    if (cmsGetEncodedICCversion(ContextID, hProfile) < 0x4000000) {
112
113
0
        if (cmsGetDeviceClass(ContextID, hProfile) == cmsSigDisplayClass) {
114
115
0
            cmsCIEXYZ* White = (cmsCIEXYZ*) cmsReadTag(ContextID, hProfile, cmsSigMediaWhitePointTag);
116
117
0
            if (White == NULL) {
118
119
0
                _cmsMAT3identity(ContextID, Dest);
120
0
                return TRUE;
121
0
            }
122
123
0
            return _cmsAdaptationMatrix(ContextID, Dest, NULL, White, cmsD50_XYZ(ContextID));
124
0
        }
125
0
    }
126
127
0
    return TRUE;
128
0
}
129
130
131
// Auxiliary, read colorants as a MAT3 structure. Used by any function that needs a matrix-shaper
132
static
133
cmsBool ReadICCMatrixRGB2XYZ(cmsContext ContextID, cmsMAT3* r, cmsHPROFILE hProfile)
134
10.8k
{
135
10.8k
    cmsCIEXYZ *PtrRed, *PtrGreen, *PtrBlue;
136
137
10.8k
    _cmsAssert(r != NULL);
138
139
10.8k
    PtrRed   = (cmsCIEXYZ *) cmsReadTag(ContextID, hProfile, cmsSigRedColorantTag);
140
10.8k
    PtrGreen = (cmsCIEXYZ *) cmsReadTag(ContextID, hProfile, cmsSigGreenColorantTag);
141
10.8k
    PtrBlue  = (cmsCIEXYZ *) cmsReadTag(ContextID, hProfile, cmsSigBlueColorantTag);
142
143
10.8k
    if (PtrRed == NULL || PtrGreen == NULL || PtrBlue == NULL)
144
440
        return FALSE;
145
146
10.4k
    _cmsVEC3init(ContextID, &r -> v[0], PtrRed -> X, PtrGreen -> X,  PtrBlue -> X);
147
10.4k
    _cmsVEC3init(ContextID, &r -> v[1], PtrRed -> Y, PtrGreen -> Y,  PtrBlue -> Y);
148
10.4k
    _cmsVEC3init(ContextID, &r -> v[2], PtrRed -> Z, PtrGreen -> Z,  PtrBlue -> Z);
149
150
10.4k
    return TRUE;
151
10.8k
}
152
153
154
// Gray input pipeline
155
static
156
cmsPipeline* BuildGrayInputMatrixPipeline(cmsContext ContextID, cmsHPROFILE hProfile)
157
7.05k
{
158
7.05k
    cmsToneCurve *GrayTRC;
159
7.05k
    cmsPipeline* Lut;
160
161
7.05k
    GrayTRC = (cmsToneCurve *) cmsReadTag(ContextID, hProfile, cmsSigGrayTRCTag);
162
7.05k
    if (GrayTRC == NULL) return NULL;
163
164
7.05k
    Lut = cmsPipelineAlloc(ContextID, 1, 3);
165
7.05k
    if (Lut == NULL)
166
0
        goto Error;
167
168
7.05k
    if (cmsGetPCS(ContextID, hProfile) == cmsSigLabData) {
169
170
        // In this case we implement the profile as an  identity matrix plus 3 tone curves
171
0
        cmsUInt16Number Zero[2] = { 0x8080, 0x8080 };
172
0
        cmsToneCurve* EmptyTab;
173
0
        cmsToneCurve* LabCurves[3];
174
175
0
        EmptyTab = cmsBuildTabulatedToneCurve16(ContextID, 2, Zero);
176
177
0
        if (EmptyTab == NULL)
178
0
            goto Error;
179
180
0
        LabCurves[0] = GrayTRC;
181
0
        LabCurves[1] = EmptyTab;
182
0
        LabCurves[2] = EmptyTab;
183
184
0
        if (!cmsPipelineInsertStage(ContextID, Lut, cmsAT_END, cmsStageAllocMatrix(ContextID, 3,  1, OneToThreeInputMatrix, NULL)) ||
185
0
            !cmsPipelineInsertStage(ContextID, Lut, cmsAT_END, cmsStageAllocToneCurves(ContextID, 3, LabCurves))) {
186
0
                cmsFreeToneCurve(ContextID, EmptyTab);
187
0
                goto Error;
188
0
        }
189
190
0
        cmsFreeToneCurve(ContextID, EmptyTab);
191
192
0
    }
193
7.05k
    else  {
194
195
7.05k
        if (!cmsPipelineInsertStage(ContextID, Lut, cmsAT_END, cmsStageAllocToneCurves(ContextID, 1, &GrayTRC)) ||
196
7.05k
            !cmsPipelineInsertStage(ContextID, Lut, cmsAT_END, cmsStageAllocMatrix(ContextID, 3,  1, GrayInputMatrix, NULL)))
197
0
            goto Error;
198
7.05k
    }
199
200
7.05k
    return Lut;
201
202
0
Error:
203
0
    cmsPipelineFree(ContextID, Lut);
204
0
    return NULL;
205
7.05k
}
206
207
// RGB Matrix shaper
208
static
209
cmsPipeline* BuildRGBInputMatrixShaper(cmsContext ContextID, cmsHPROFILE hProfile)
210
6.96k
{
211
6.96k
    cmsPipeline* Lut;
212
6.96k
    cmsMAT3 Mat;
213
6.96k
    cmsToneCurve *Shapes[3];
214
6.96k
    int i, j;
215
216
6.96k
    if (!ReadICCMatrixRGB2XYZ(ContextID, &Mat, hProfile)) return NULL;
217
218
    // XYZ PCS in encoded in 1.15 format, and the matrix output comes in 0..0xffff range, so
219
    // we need to adjust the output by a factor of (0x10000/0xffff) to put data in
220
    // a 1.16 range, and then a >> 1 to obtain 1.15. The total factor is (65536.0)/(65535.0*2)
221
222
26.1k
    for (i=0; i < 3; i++)
223
78.5k
        for (j=0; j < 3; j++)
224
58.8k
            Mat.v[i].n[j] *= InpAdj;
225
226
227
6.54k
    Shapes[0] = (cmsToneCurve *) cmsReadTag(ContextID, hProfile, cmsSigRedTRCTag);
228
6.54k
    Shapes[1] = (cmsToneCurve *) cmsReadTag(ContextID, hProfile, cmsSigGreenTRCTag);
229
6.54k
    Shapes[2] = (cmsToneCurve *) cmsReadTag(ContextID, hProfile, cmsSigBlueTRCTag);
230
231
6.54k
    if (!Shapes[0] || !Shapes[1] || !Shapes[2])
232
1.11k
        return NULL;
233
234
5.43k
    Lut = cmsPipelineAlloc(ContextID, 3, 3);
235
5.43k
    if (Lut != NULL) {
236
237
5.43k
        if (!cmsPipelineInsertStage(ContextID, Lut, cmsAT_END, cmsStageAllocToneCurves(ContextID, 3, Shapes)) ||
238
5.43k
            !cmsPipelineInsertStage(ContextID, Lut, cmsAT_END, cmsStageAllocMatrix(ContextID, 3, 3, (cmsFloat64Number*) &Mat, NULL)))
239
0
            goto Error;
240
241
        // Note that it is certainly possible a single profile would have a LUT based
242
        // tag for output working in lab and a matrix-shaper for the fallback cases.
243
        // This is not allowed by the spec, but this code is tolerant to those cases
244
5.43k
        if (cmsGetPCS(ContextID, hProfile) == cmsSigLabData) {
245
246
0
            if (!cmsPipelineInsertStage(ContextID, Lut, cmsAT_END, _cmsStageAllocXYZ2Lab(ContextID)))
247
0
                goto Error;
248
0
        }
249
250
5.43k
    }
251
252
5.43k
    return Lut;
253
254
0
Error:
255
0
    cmsPipelineFree(ContextID, Lut);
256
0
    return NULL;
257
5.43k
}
258
259
260
261
// Read the DToAX tag, adjusting the encoding of Lab or XYZ if needed
262
static
263
cmsPipeline* _cmsReadFloatInputTag(cmsContext ContextID, cmsHPROFILE hProfile, cmsTagSignature tagFloat)
264
0
{
265
0
    cmsPipeline* Lut           = cmsPipelineDup(ContextID, (cmsPipeline*) cmsReadTag(ContextID, hProfile, tagFloat));
266
0
    cmsColorSpaceSignature spc = cmsGetColorSpace(ContextID, hProfile);
267
0
    cmsColorSpaceSignature PCS = cmsGetPCS(ContextID, hProfile);
268
269
0
    if (Lut == NULL) return NULL;
270
271
    // input and output of transform are in lcms 0..1 encoding.  If XYZ or Lab spaces are used,
272
    //  these need to be normalized into the appropriate ranges (Lab = 100,0,0, XYZ=1.0,1.0,1.0)
273
0
    if ( spc == cmsSigLabData)
274
0
    {
275
0
        if (!cmsPipelineInsertStage(ContextID, Lut, cmsAT_BEGIN, _cmsStageNormalizeToLabFloat(ContextID)))
276
0
            goto Error;
277
0
    }
278
0
    else if (spc == cmsSigXYZData)
279
0
    {
280
0
        if (!cmsPipelineInsertStage(ContextID, Lut, cmsAT_BEGIN, _cmsStageNormalizeToXyzFloat(ContextID)))
281
0
            goto Error;
282
0
    }
283
284
0
    if ( PCS == cmsSigLabData)
285
0
    {
286
0
        if (!cmsPipelineInsertStage(ContextID, Lut, cmsAT_END, _cmsStageNormalizeFromLabFloat(ContextID)))
287
0
            goto Error;
288
0
    }
289
0
    else if( PCS == cmsSigXYZData)
290
0
    {
291
0
        if (!cmsPipelineInsertStage(ContextID, Lut, cmsAT_END, _cmsStageNormalizeFromXyzFloat(ContextID)))
292
0
            goto Error;
293
0
    }
294
295
0
    return Lut;
296
297
0
Error:
298
0
    cmsPipelineFree(ContextID, Lut);
299
0
    return NULL;
300
0
}
301
302
303
// Read and create a BRAND NEW MPE LUT from a given profile. All stuff dependent of version, etc
304
// is adjusted here in order to create a LUT that takes care of all those details.
305
// We add intent = 0xffffffff as a way to read matrix shaper always, no matter of other LUT
306
cmsPipeline* CMSEXPORT _cmsReadInputLUT(cmsContext ContextID, cmsHPROFILE hProfile, cmsUInt32Number Intent)
307
14.7k
{
308
14.7k
    cmsTagTypeSignature OriginalType;
309
14.7k
    cmsTagSignature tag16;
310
14.7k
    cmsTagSignature tagFloat;
311
312
    // On named color, take the appropriate tag
313
14.7k
    if (cmsGetDeviceClass(ContextID, hProfile) == cmsSigNamedColorClass) {
314
315
0
        cmsPipeline* Lut;
316
0
        cmsNAMEDCOLORLIST* nc = (cmsNAMEDCOLORLIST*) cmsReadTag(ContextID, hProfile, cmsSigNamedColor2Tag);
317
318
0
        if (nc == NULL) return NULL;
319
320
0
        Lut = cmsPipelineAlloc(ContextID, 0, 0);
321
0
        if (Lut == NULL) {
322
            //cmsFreeNamedColorList(ContextID, nc);
323
0
            return NULL;
324
0
        }
325
326
0
        if (!cmsPipelineInsertStage(ContextID, Lut, cmsAT_BEGIN, _cmsStageAllocNamedColor(ContextID, nc, TRUE)) ||
327
0
            !cmsPipelineInsertStage(ContextID, Lut, cmsAT_END, _cmsStageAllocLabV2ToV4(ContextID))) {
328
0
            cmsPipelineFree(ContextID, Lut);
329
0
            return NULL;
330
0
        }
331
0
        return Lut;
332
0
    }
333
334
    // This is an attempt to reuse this function to retrieve the matrix-shaper as pipeline no
335
    // matter other LUT are present and have precedence. Intent = 0xffffffff can be used for that.
336
14.7k
    if (Intent <= INTENT_ABSOLUTE_COLORIMETRIC) {
337
338
14.7k
        tag16 = Device2PCS16[Intent];
339
14.7k
        tagFloat = Device2PCSFloat[Intent];
340
341
14.7k
        if (cmsIsTag(ContextID, hProfile, tagFloat)) {  // Float tag takes precedence
342
343
            // Floating point LUT are always V4, but the encoding range is no
344
            // longer 0..1.0, so we need to add an stage depending on the color space
345
0
            return _cmsReadFloatInputTag(ContextID, hProfile, tagFloat);
346
0
        }
347
348
        // Revert to perceptual if no tag is found
349
14.7k
        if (!cmsIsTag(ContextID, hProfile, tag16)) {
350
14.0k
            tag16 = Device2PCS16[0];
351
14.0k
        }
352
353
14.7k
        if (cmsIsTag(ContextID, hProfile, tag16)) { // Is there any LUT-Based table?
354
355
            // Check profile version and LUT type. Do the necessary adjustments if needed
356
357
            // First read the tag
358
751
            cmsPipeline* Lut = (cmsPipeline*) cmsReadTag(ContextID, hProfile, tag16);
359
751
            if (Lut == NULL) return NULL;
360
361
            // After reading it, we have now info about the original type
362
751
            OriginalType =  _cmsGetTagTrueType(ContextID, hProfile, tag16);
363
364
            // The profile owns the Lut, so we need to copy it
365
751
            Lut = cmsPipelineDup(ContextID, Lut);
366
367
            // We need to adjust data only for Lab16 on output
368
751
            if (OriginalType != cmsSigLut16Type || cmsGetPCS(ContextID, hProfile) != cmsSigLabData)
369
16
                return Lut;
370
371
            // If the input is Lab, add also a conversion at the begin
372
735
            if (cmsGetColorSpace(ContextID, hProfile) == cmsSigLabData &&
373
735
                !cmsPipelineInsertStage(ContextID, Lut, cmsAT_BEGIN, _cmsStageAllocLabV4ToV2(ContextID)))
374
0
                goto Error;
375
376
            // Add a matrix for conversion V2 to V4 Lab PCS
377
735
            if (!cmsPipelineInsertStage(ContextID, Lut, cmsAT_END, _cmsStageAllocLabV2ToV4(ContextID)))
378
0
                goto Error;
379
380
735
            return Lut;
381
0
Error:
382
0
            cmsPipelineFree(ContextID, Lut);
383
0
            return NULL;
384
735
        }
385
14.7k
    }
386
387
    // Lut was not found, try to create a matrix-shaper
388
389
    // Check if this is a grayscale profile.
390
14.0k
    if (cmsGetColorSpace(ContextID, hProfile) == cmsSigGrayData) {
391
392
        // if so, build appropriate conversion tables.
393
        // The tables are the PCS iluminant, scaled across GrayTRC
394
7.05k
        return BuildGrayInputMatrixPipeline(ContextID, hProfile);
395
7.05k
    }
396
397
    // Not gray, create a normal matrix-shaper
398
6.96k
    return BuildRGBInputMatrixShaper(ContextID, hProfile);
399
14.0k
}
400
401
// ---------------------------------------------------------------------------------------------------------------
402
403
// Gray output pipeline.
404
// XYZ -> Gray or Lab -> Gray. Since we only know the GrayTRC, we need to do some assumptions. Gray component will be
405
// given by Y on XYZ PCS and by L* on Lab PCS, Both across inverse TRC curve.
406
// The complete pipeline on XYZ is Matrix[3:1] -> Tone curve and in Lab Matrix[3:1] -> Tone Curve as well.
407
408
static
409
cmsPipeline* BuildGrayOutputPipeline(cmsContext ContextID, cmsHPROFILE hProfile)
410
383
{
411
383
    cmsToneCurve *GrayTRC, *RevGrayTRC;
412
383
    cmsPipeline* Lut;
413
414
383
    GrayTRC = (cmsToneCurve *) cmsReadTag(ContextID, hProfile, cmsSigGrayTRCTag);
415
383
    if (GrayTRC == NULL) return NULL;
416
417
383
    RevGrayTRC = cmsReverseToneCurve(ContextID, GrayTRC);
418
383
    if (RevGrayTRC == NULL) return NULL;
419
420
383
    Lut = cmsPipelineAlloc(ContextID, 3, 1);
421
383
    if (Lut == NULL) {
422
0
        cmsFreeToneCurve(ContextID, RevGrayTRC);
423
0
        return NULL;
424
0
    }
425
426
383
    if (cmsGetPCS(ContextID, hProfile) == cmsSigLabData) {
427
428
0
        if (!cmsPipelineInsertStage(ContextID, Lut, cmsAT_END, cmsStageAllocMatrix(ContextID, 1,  3, PickLstarMatrix, NULL)))
429
0
            goto Error;
430
0
    }
431
383
    else  {
432
383
        if (!cmsPipelineInsertStage(ContextID, Lut, cmsAT_END, cmsStageAllocMatrix(ContextID, 1,  3, PickYMatrix, NULL)))
433
0
            goto Error;
434
383
    }
435
436
383
    if (!cmsPipelineInsertStage(ContextID, Lut, cmsAT_END, cmsStageAllocToneCurves(ContextID, 1, &RevGrayTRC)))
437
0
        goto Error;
438
439
383
    cmsFreeToneCurve(ContextID, RevGrayTRC);
440
383
    return Lut;
441
442
0
Error:
443
0
    cmsFreeToneCurve(ContextID, RevGrayTRC);
444
0
    cmsPipelineFree(ContextID, Lut);
445
0
    return NULL;
446
383
}
447
448
449
static
450
cmsPipeline* BuildRGBOutputMatrixShaper(cmsContext ContextID, cmsHPROFILE hProfile)
451
3.88k
{
452
3.88k
    cmsPipeline* Lut;
453
3.88k
    cmsToneCurve *Shapes[3], *InvShapes[3];
454
3.88k
    cmsMAT3 Mat, Inv;
455
3.88k
    int i, j;
456
457
3.88k
    if (!ReadICCMatrixRGB2XYZ(ContextID, &Mat, hProfile))
458
24
        return NULL;
459
460
3.86k
    if (!_cmsMAT3inverse(ContextID, &Mat, &Inv))
461
1
        return NULL;
462
463
    // XYZ PCS in encoded in 1.15 format, and the matrix input should come in 0..0xffff range, so
464
    // we need to adjust the input by a << 1 to obtain a 1.16 fixed and then by a factor of
465
    // (0xffff/0x10000) to put data in 0..0xffff range. Total factor is (2.0*65535.0)/65536.0;
466
467
15.4k
    for (i=0; i < 3; i++)
468
46.3k
        for (j=0; j < 3; j++)
469
34.7k
            Inv.v[i].n[j] *= OutpAdj;
470
471
3.85k
    Shapes[0] = (cmsToneCurve *) cmsReadTag(ContextID, hProfile, cmsSigRedTRCTag);
472
3.85k
    Shapes[1] = (cmsToneCurve *) cmsReadTag(ContextID, hProfile, cmsSigGreenTRCTag);
473
3.85k
    Shapes[2] = (cmsToneCurve *) cmsReadTag(ContextID, hProfile, cmsSigBlueTRCTag);
474
475
3.85k
    if (!Shapes[0] || !Shapes[1] || !Shapes[2])
476
12
        return NULL;
477
478
3.84k
    InvShapes[0] = cmsReverseToneCurve(ContextID, Shapes[0]);
479
3.84k
    InvShapes[1] = cmsReverseToneCurve(ContextID, Shapes[1]);
480
3.84k
    InvShapes[2] = cmsReverseToneCurve(ContextID, Shapes[2]);
481
482
3.84k
    if (!InvShapes[0] || !InvShapes[1] || !InvShapes[2]) {
483
0
        cmsFreeToneCurveTriple(ContextID, InvShapes);
484
0
        return NULL;
485
0
    }
486
487
3.84k
    Lut = cmsPipelineAlloc(ContextID, 3, 3);
488
3.84k
    if (Lut != NULL) {
489
490
        // Note that it is certainly possible a single profile would have a LUT based
491
        // tag for output working in lab and a matrix-shaper for the fallback cases.
492
        // This is not allowed by the spec, but this code is tolerant to those cases
493
3.84k
        if (cmsGetPCS(ContextID, hProfile) == cmsSigLabData) {
494
495
0
            if (!cmsPipelineInsertStage(ContextID, Lut, cmsAT_END, _cmsStageAllocLab2XYZ(ContextID)))
496
0
                goto Error;
497
0
        }
498
499
3.84k
        if (!cmsPipelineInsertStage(ContextID, Lut, cmsAT_END, cmsStageAllocMatrix(ContextID, 3, 3, (cmsFloat64Number*) &Inv, NULL)) ||
500
3.84k
            !cmsPipelineInsertStage(ContextID, Lut, cmsAT_END, cmsStageAllocToneCurves(ContextID, 3, InvShapes)))
501
0
            goto Error;
502
3.84k
    }
503
504
3.84k
    cmsFreeToneCurveTriple(ContextID, InvShapes);
505
3.84k
    return Lut;
506
0
Error:
507
0
    cmsFreeToneCurveTriple(ContextID, InvShapes);
508
0
    cmsPipelineFree(ContextID, Lut);
509
0
    return NULL;
510
3.84k
}
511
512
513
// Change CLUT interpolation to trilinear
514
static
515
void ChangeInterpolationToTrilinear(cmsContext ContextID, cmsPipeline* Lut)
516
9.25k
{
517
9.25k
    cmsStage* Stage;
518
519
9.25k
    for (Stage = cmsPipelineGetPtrToFirstStage(ContextID, Lut);
520
19.2k
        Stage != NULL;
521
10.0k
        Stage = cmsStageNext(ContextID, Stage)) {
522
523
10.0k
            if (cmsStageType(ContextID, Stage) == cmsSigCLutElemType) {
524
525
8.52k
                _cmsStageCLutData* CLUT = (_cmsStageCLutData*) Stage ->Data;
526
527
8.52k
                CLUT ->Params->dwFlags |= CMS_LERP_FLAGS_TRILINEAR;
528
8.52k
                _cmsSetInterpolationRoutine(ContextID, CLUT ->Params);
529
8.52k
            }
530
10.0k
    }
531
9.25k
}
532
533
534
// Read the DToAX tag, adjusting the encoding of Lab or XYZ if needed
535
static
536
cmsPipeline* _cmsReadFloatOutputTag(cmsContext ContextID, cmsHPROFILE hProfile, cmsTagSignature tagFloat)
537
0
{
538
0
    cmsPipeline* Lut           = cmsPipelineDup(ContextID, (cmsPipeline*) cmsReadTag(ContextID, hProfile, tagFloat));
539
0
    cmsColorSpaceSignature PCS = cmsGetPCS(ContextID, hProfile);
540
0
    cmsColorSpaceSignature dataSpace = cmsGetColorSpace(ContextID, hProfile);
541
542
0
    if (Lut == NULL) return NULL;
543
544
    // If PCS is Lab or XYZ, the floating point tag is accepting data in the space encoding,
545
    // and since the formatter has already accommodated to 0..1.0, we should undo this change
546
0
    if ( PCS == cmsSigLabData)
547
0
    {
548
0
        if (!cmsPipelineInsertStage(ContextID, Lut, cmsAT_BEGIN, _cmsStageNormalizeToLabFloat(ContextID)))
549
0
            goto Error;
550
0
    }
551
0
    else
552
0
        if (PCS == cmsSigXYZData)
553
0
        {
554
0
            if (!cmsPipelineInsertStage(ContextID, Lut, cmsAT_BEGIN, _cmsStageNormalizeToXyzFloat(ContextID)))
555
0
                goto Error;
556
0
        }
557
558
    // the output can be Lab or XYZ, in which case normalisation is needed on the end of the pipeline
559
0
    if ( dataSpace == cmsSigLabData)
560
0
    {
561
0
        if (!cmsPipelineInsertStage(ContextID, Lut, cmsAT_END, _cmsStageNormalizeFromLabFloat(ContextID)))
562
0
            goto Error;
563
0
    }
564
0
    else if (dataSpace == cmsSigXYZData)
565
0
    {
566
0
        if (!cmsPipelineInsertStage(ContextID, Lut, cmsAT_END, _cmsStageNormalizeFromXyzFloat(ContextID)))
567
0
            goto Error;
568
0
    }
569
570
0
    return Lut;
571
572
0
Error:
573
0
    cmsPipelineFree(ContextID, Lut);
574
0
    return NULL;
575
0
}
576
577
// Create an output MPE LUT from agiven profile. Version mismatches are handled here
578
cmsPipeline* CMSEXPORT _cmsReadOutputLUT(cmsContext ContextID, cmsHPROFILE hProfile, cmsUInt32Number Intent)
579
4.65k
{
580
4.65k
    cmsTagTypeSignature OriginalType;
581
4.65k
    cmsTagSignature tag16;
582
4.65k
    cmsTagSignature tagFloat;
583
584
4.65k
    if (Intent <= INTENT_ABSOLUTE_COLORIMETRIC) {
585
586
4.65k
        tag16 = PCS2Device16[Intent];
587
4.65k
        tagFloat = PCS2DeviceFloat[Intent];
588
589
4.65k
        if (cmsIsTag(ContextID, hProfile, tagFloat)) {  // Float tag takes precedence
590
591
            // Floating point LUT are always V4
592
0
            return _cmsReadFloatOutputTag(ContextID, hProfile, tagFloat);
593
0
        }
594
595
        // Revert to perceptual if no tag is found
596
4.65k
        if (!cmsIsTag(ContextID, hProfile, tag16)) {
597
4.26k
            tag16 = PCS2Device16[0];
598
4.26k
        }
599
600
4.65k
        if (cmsIsTag(ContextID, hProfile, tag16)) { // Is there any LUT-Based table?
601
602
            // Check profile version and LUT type. Do the necessary adjustments if needed
603
604
            // First read the tag
605
388
            cmsPipeline* Lut = (cmsPipeline*) cmsReadTag(ContextID, hProfile, tag16);
606
388
            if (Lut == NULL) return NULL;
607
608
            // After reading it, we have info about the original type
609
388
            OriginalType =  _cmsGetTagTrueType(ContextID, hProfile, tag16);
610
611
            // The profile owns the Lut, so we need to copy it
612
388
            Lut = cmsPipelineDup(ContextID, Lut);
613
388
            if (Lut == NULL) return NULL;
614
615
            // Now it is time for a controversial stuff. I found that for 3D LUTS using
616
            // Lab used as indexer space,  trilinear interpolation should be used
617
388
            if (cmsGetPCS(ContextID, hProfile) == cmsSigLabData)
618
388
                ChangeInterpolationToTrilinear(ContextID, Lut);
619
620
            // We need to adjust data only for Lab and Lut16 type
621
388
            if (OriginalType != cmsSigLut16Type || cmsGetPCS(ContextID, hProfile) != cmsSigLabData)
622
388
                return Lut;
623
624
            // Add a matrix for conversion V4 to V2 Lab PCS
625
0
            if (!cmsPipelineInsertStage(ContextID, Lut, cmsAT_BEGIN, _cmsStageAllocLabV4ToV2(ContextID)))
626
0
                goto Error;
627
628
            // If the output is Lab, add also a conversion at the end
629
0
            if (cmsGetColorSpace(ContextID, hProfile) == cmsSigLabData)
630
0
                if (!cmsPipelineInsertStage(ContextID, Lut, cmsAT_END, _cmsStageAllocLabV2ToV4(ContextID)))
631
0
                    goto Error;
632
633
0
            return Lut;
634
0
Error:
635
0
            cmsPipelineFree(ContextID, Lut);
636
0
            return NULL;
637
0
        }
638
4.65k
    }
639
640
    // Lut not found, try to create a matrix-shaper
641
642
    // Check if this is a grayscale profile.
643
4.26k
    if (cmsGetColorSpace(ContextID, hProfile) == cmsSigGrayData) {
644
645
        // if so, build appropriate conversion tables.
646
        // The tables are the PCS iluminant, scaled across GrayTRC
647
383
        return BuildGrayOutputPipeline(ContextID, hProfile);
648
383
    }
649
650
    // Not gray, create a normal matrix-shaper, which only operates in XYZ space
651
3.88k
    return BuildRGBOutputMatrixShaper(ContextID, hProfile);
652
4.26k
}
653
654
// ---------------------------------------------------------------------------------------------------------------
655
656
// Read the AToD0 tag, adjusting the encoding of Lab or XYZ if needed
657
static
658
cmsPipeline* _cmsReadFloatDevicelinkTag(cmsContext ContextID, cmsHPROFILE hProfile, cmsTagSignature tagFloat)
659
0
{
660
0
    cmsPipeline* Lut           = cmsPipelineDup(ContextID, (cmsPipeline*) cmsReadTag(ContextID, hProfile, tagFloat));
661
0
    cmsColorSpaceSignature PCS = cmsGetPCS(ContextID, hProfile);
662
0
    cmsColorSpaceSignature spc = cmsGetColorSpace(ContextID, hProfile);
663
664
0
    if (Lut == NULL) return NULL;
665
666
0
    if (spc == cmsSigLabData)
667
0
    {
668
0
        if (!cmsPipelineInsertStage(ContextID, Lut, cmsAT_BEGIN, _cmsStageNormalizeToLabFloat(ContextID)))
669
0
            goto Error;
670
0
    }
671
0
    else
672
0
        if (spc == cmsSigXYZData)
673
0
        {
674
0
            if (!cmsPipelineInsertStage(ContextID, Lut, cmsAT_BEGIN, _cmsStageNormalizeToXyzFloat(ContextID)))
675
0
                goto Error;
676
0
        }
677
678
0
    if (PCS == cmsSigLabData)
679
0
    {
680
0
        if (!cmsPipelineInsertStage(ContextID, Lut, cmsAT_END, _cmsStageNormalizeFromLabFloat(ContextID)))
681
0
            goto Error;
682
0
    }
683
0
    else
684
0
        if (PCS == cmsSigXYZData)
685
0
        {
686
0
            if (!cmsPipelineInsertStage(ContextID, Lut, cmsAT_END, _cmsStageNormalizeFromXyzFloat(ContextID)))
687
0
                goto Error;
688
0
        }
689
690
0
    return Lut;
691
0
Error:
692
0
    cmsPipelineFree(ContextID, Lut);
693
0
    return NULL;
694
0
}
695
696
// This one includes abstract profiles as well. Matrix-shaper cannot be obtained on that device class. The
697
// tag name here may default to AToB0
698
cmsPipeline* CMSEXPORT _cmsReadDevicelinkLUT(cmsContext ContextID, cmsHPROFILE hProfile, cmsUInt32Number Intent)
699
9.30k
{
700
9.30k
    cmsPipeline* Lut;
701
9.30k
    cmsTagTypeSignature OriginalType;
702
9.30k
    cmsTagSignature tag16;
703
9.30k
    cmsTagSignature tagFloat;
704
705
9.30k
    if (Intent > INTENT_ABSOLUTE_COLORIMETRIC)
706
0
        return NULL;
707
708
9.30k
    tag16 = Device2PCS16[Intent];
709
9.30k
    tagFloat = Device2PCSFloat[Intent];
710
711
    // On named color, take the appropriate tag
712
9.30k
    if (cmsGetDeviceClass(ContextID, hProfile) == cmsSigNamedColorClass) {
713
714
0
        cmsNAMEDCOLORLIST* nc = (cmsNAMEDCOLORLIST*)cmsReadTag(ContextID, hProfile, cmsSigNamedColor2Tag);
715
716
0
        if (nc == NULL) return NULL;
717
718
0
        Lut = cmsPipelineAlloc(ContextID, 0, 0);
719
0
        if (Lut == NULL)
720
0
            goto Error;
721
722
0
        if (!cmsPipelineInsertStage(ContextID, Lut, cmsAT_BEGIN, _cmsStageAllocNamedColor(ContextID, nc, FALSE)))
723
0
            goto Error;
724
725
0
        if (cmsGetColorSpace(ContextID, hProfile) == cmsSigLabData)
726
0
            if (!cmsPipelineInsertStage(ContextID, Lut, cmsAT_END, _cmsStageAllocLabV2ToV4(ContextID)))
727
0
                goto Error;
728
729
0
        return Lut;
730
0
    Error:
731
0
        cmsPipelineFree(ContextID, Lut);
732
        //cmsFreeNamedColorList(ContextID, nc);
733
0
        return NULL;
734
0
    }
735
736
737
9.30k
    if (cmsIsTag(ContextID, hProfile, tagFloat)) {  // Float tag takes precedence
738
739
        // Floating point LUT are always V
740
0
        return _cmsReadFloatDevicelinkTag(ContextID, hProfile, tagFloat);
741
0
    }
742
743
9.30k
    tagFloat = Device2PCSFloat[0];
744
9.30k
    if (cmsIsTag(ContextID, hProfile, tagFloat)) {
745
746
0
        return cmsPipelineDup(ContextID, (cmsPipeline*)cmsReadTag(ContextID, hProfile, tagFloat));
747
0
    }
748
749
9.30k
    if (!cmsIsTag(ContextID, hProfile, tag16)) {  // Is there any LUT-Based table?
750
751
9.15k
        tag16 = Device2PCS16[0];
752
9.15k
        if (!cmsIsTag(ContextID, hProfile, tag16)) return NULL;
753
9.15k
    }
754
755
    // Check profile version and LUT type. Do the necessary adjustments if needed
756
757
    // Read the tag
758
9.30k
    Lut = (cmsPipeline*)cmsReadTag(ContextID, hProfile, tag16);
759
9.30k
    if (Lut == NULL) return NULL;
760
761
    // The profile owns the Lut, so we need to copy it
762
9.30k
    Lut = cmsPipelineDup(ContextID, Lut);
763
9.30k
    if (Lut == NULL) return NULL;
764
765
    // Now it is time for a controversial stuff. I found that for 3D LUTS using
766
    // Lab used as indexer space,  trilinear interpolation should be used
767
9.30k
    if (cmsGetPCS(ContextID, hProfile) == cmsSigLabData)
768
8.86k
        ChangeInterpolationToTrilinear(ContextID, Lut);
769
770
    // After reading it, we have info about the original type
771
9.30k
    OriginalType = _cmsGetTagTrueType(ContextID, hProfile, tag16);
772
773
    // We need to adjust data for Lab16 on output
774
9.30k
    if (OriginalType != cmsSigLut16Type) return Lut;
775
776
    // Here it is possible to get Lab on both sides
777
778
8.13k
    if (cmsGetColorSpace(ContextID, hProfile) == cmsSigLabData) {
779
8.13k
        if (!cmsPipelineInsertStage(ContextID, Lut, cmsAT_BEGIN, _cmsStageAllocLabV4ToV2(ContextID)))
780
0
            goto Error2;
781
8.13k
    }
782
783
8.13k
    if (cmsGetPCS(ContextID, hProfile) == cmsSigLabData) {
784
8.13k
        if (!cmsPipelineInsertStage(ContextID, Lut, cmsAT_END, _cmsStageAllocLabV2ToV4(ContextID)))
785
0
            goto Error2;
786
8.13k
    }
787
788
8.13k
    return Lut;
789
790
0
Error2:
791
0
    cmsPipelineFree(ContextID, Lut);
792
0
    return NULL;
793
8.13k
}
794
795
// ---------------------------------------------------------------------------------------------------------------
796
797
// Returns TRUE if the profile is implemented as matrix-shaper
798
cmsBool  CMSEXPORT cmsIsMatrixShaper(cmsContext ContextID, cmsHPROFILE hProfile)
799
8.13k
{
800
8.13k
    switch (cmsGetColorSpace(ContextID, hProfile)) {
801
802
3.70k
    case cmsSigGrayData:
803
804
3.70k
        return cmsIsTag(ContextID, hProfile, cmsSigGrayTRCTag);
805
806
4.41k
    case cmsSigRgbData:
807
808
4.41k
        return (cmsIsTag(ContextID, hProfile, cmsSigRedColorantTag) &&
809
4.41k
                cmsIsTag(ContextID, hProfile, cmsSigGreenColorantTag) &&
810
4.41k
                cmsIsTag(ContextID, hProfile, cmsSigBlueColorantTag) &&
811
4.41k
                cmsIsTag(ContextID, hProfile, cmsSigRedTRCTag) &&
812
4.41k
                cmsIsTag(ContextID, hProfile, cmsSigGreenTRCTag) &&
813
4.41k
                cmsIsTag(ContextID, hProfile, cmsSigBlueTRCTag));
814
815
16
    default:
816
817
16
        return FALSE;
818
8.13k
    }
819
8.13k
}
820
821
// Returns TRUE if the intent is implemented as CLUT
822
cmsBool  CMSEXPORT cmsIsCLUT(cmsContext ContextID, cmsHPROFILE hProfile, cmsUInt32Number Intent, cmsUInt32Number UsedDirection)
823
12.7k
{
824
12.7k
    const cmsTagSignature* TagTable;
825
826
    // For devicelinks, the supported intent is that one stated in the header
827
12.7k
    if (cmsGetDeviceClass(ContextID, hProfile) == cmsSigLinkClass) {
828
0
            return (cmsGetHeaderRenderingIntent(ContextID, hProfile) == Intent);
829
0
    }
830
831
12.7k
    switch (UsedDirection) {
832
833
8.49k
       case LCMS_USED_AS_INPUT: TagTable = Device2PCS16; break;
834
4.25k
       case LCMS_USED_AS_OUTPUT:TagTable = PCS2Device16; break;
835
836
       // For proofing, we need rel. colorimetric in output. Let's do some recursion
837
0
       case LCMS_USED_AS_PROOF:
838
0
           return cmsIsIntentSupported(ContextID, hProfile, Intent, LCMS_USED_AS_INPUT) &&
839
0
                  cmsIsIntentSupported(ContextID, hProfile, INTENT_RELATIVE_COLORIMETRIC, LCMS_USED_AS_OUTPUT);
840
841
0
       default:
842
0
           cmsSignalError(ContextID, cmsERROR_RANGE, "Unexpected direction (%d)", UsedDirection);
843
0
           return FALSE;
844
12.7k
    }
845
846
12.7k
    return cmsIsTag(ContextID, hProfile, TagTable[Intent]);
847
848
12.7k
}
849
850
851
// Return info about supported intents
852
cmsBool  CMSEXPORT cmsIsIntentSupported(cmsContext ContextID, cmsHPROFILE hProfile,
853
                                        cmsUInt32Number Intent, cmsUInt32Number UsedDirection)
854
8.49k
{
855
856
8.49k
    if (cmsIsCLUT(ContextID, hProfile, Intent, UsedDirection)) return TRUE;
857
858
    // Is there any matrix-shaper? If so, the intent is supported. This is a bit odd, since V2 matrix shaper
859
    // does not fully support relative colorimetric because they cannot deal with non-zero black points, but
860
    // many profiles claims that, and this is certainly not true for V4 profiles. Lets answer "yes" no matter
861
    // the accuracy would be less than optimal in rel.col and v2 case.
862
863
8.13k
    return cmsIsMatrixShaper(ContextID, hProfile);
864
8.49k
}
865
866
867
// ---------------------------------------------------------------------------------------------------------------
868
869
// Read both, profile sequence description and profile sequence id if present. Then combine both to
870
// create qa unique structure holding both. Shame on ICC to store things in such complicated way.
871
cmsSEQ* _cmsReadProfileSequence(cmsContext ContextID, cmsHPROFILE hProfile)
872
0
{
873
0
    cmsSEQ* ProfileSeq;
874
0
    cmsSEQ* ProfileId;
875
0
    cmsSEQ* NewSeq;
876
0
    cmsUInt32Number i;
877
878
    // Take profile sequence description first
879
0
    ProfileSeq = (cmsSEQ*) cmsReadTag(ContextID, hProfile, cmsSigProfileSequenceDescTag);
880
881
    // Take profile sequence ID
882
0
    ProfileId  = (cmsSEQ*) cmsReadTag(ContextID, hProfile, cmsSigProfileSequenceIdTag);
883
884
0
    if (ProfileSeq == NULL && ProfileId == NULL) return NULL;
885
886
0
    if (ProfileSeq == NULL) return cmsDupProfileSequenceDescription(ContextID, ProfileId);
887
0
    if (ProfileId  == NULL) return cmsDupProfileSequenceDescription(ContextID, ProfileSeq);
888
889
    // We have to mix both together. For that they must agree
890
0
    if (ProfileSeq ->n != ProfileId ->n) return cmsDupProfileSequenceDescription(ContextID, ProfileSeq);
891
892
0
    NewSeq = cmsDupProfileSequenceDescription(ContextID, ProfileSeq);
893
894
    // Ok, proceed to the mixing
895
0
    if (NewSeq != NULL) {
896
0
        for (i=0; i < ProfileSeq ->n; i++) {
897
898
0
            memmove(&NewSeq ->seq[i].ProfileID, &ProfileId ->seq[i].ProfileID, sizeof(cmsProfileID));
899
0
            NewSeq ->seq[i].Description = cmsMLUdup(ContextID, ProfileId ->seq[i].Description);
900
0
        }
901
0
    }
902
0
    return NewSeq;
903
0
}
904
905
// Dump the contents of profile sequence in both tags (if v4 available)
906
cmsBool _cmsWriteProfileSequence(cmsContext ContextID, cmsHPROFILE hProfile, const cmsSEQ* seq)
907
0
{
908
0
    if (!cmsWriteTag(ContextID, hProfile, cmsSigProfileSequenceDescTag, seq)) return FALSE;
909
910
0
    if (cmsGetEncodedICCversion(ContextID, hProfile) >= 0x4000000) {
911
912
0
            if (!cmsWriteTag(ContextID, hProfile, cmsSigProfileSequenceIdTag, seq)) return FALSE;
913
0
    }
914
915
0
    return TRUE;
916
0
}
917
918
919
// Auxiliary, read and duplicate a MLU if found.
920
static
921
cmsMLU* GetMLUFromProfile(cmsContext ContextID, cmsHPROFILE h, cmsTagSignature sig)
922
0
{
923
0
    cmsMLU* mlu = (cmsMLU*) cmsReadTag(ContextID, h, sig);
924
0
    if (mlu == NULL) return NULL;
925
926
0
    return cmsMLUdup(ContextID, mlu);
927
0
}
928
929
// Create a sequence description out of an array of profiles
930
cmsSEQ* _cmsCompileProfileSequence(cmsContext ContextID, cmsUInt32Number nProfiles, cmsHPROFILE hProfiles[])
931
0
{
932
0
    cmsUInt32Number i;
933
0
    cmsSEQ* seq = cmsAllocProfileSequenceDescription(ContextID, nProfiles);
934
935
0
    if (seq == NULL) return NULL;
936
937
0
    for (i=0; i < nProfiles; i++) {
938
939
0
        cmsPSEQDESC* ps = &seq ->seq[i];
940
0
        cmsHPROFILE h = hProfiles[i];
941
0
        cmsTechnologySignature* techpt;
942
943
0
        cmsGetHeaderAttributes(ContextID, h, &ps ->attributes);
944
0
        cmsGetHeaderProfileID(ContextID, h, ps ->ProfileID.ID8);
945
0
        ps ->deviceMfg   = cmsGetHeaderManufacturer(ContextID, h);
946
0
        ps ->deviceModel = cmsGetHeaderModel(ContextID, h);
947
948
0
        techpt = (cmsTechnologySignature*) cmsReadTag(ContextID, h, cmsSigTechnologyTag);
949
0
        if (techpt == NULL)
950
0
            ps ->technology   =  (cmsTechnologySignature) 0;
951
0
        else
952
0
            ps ->technology   = *techpt;
953
954
0
        ps ->Manufacturer = GetMLUFromProfile(ContextID, h,  cmsSigDeviceMfgDescTag);
955
0
        ps ->Model        = GetMLUFromProfile(ContextID, h,  cmsSigDeviceModelDescTag);
956
0
        ps ->Description  = GetMLUFromProfile(ContextID, h, cmsSigProfileDescriptionTag);
957
958
0
    }
959
960
0
    return seq;
961
0
}
962
963
// -------------------------------------------------------------------------------------------------------------------
964
965
966
static
967
const cmsMLU* GetInfo(cmsContext ContextID, cmsHPROFILE hProfile, cmsInfoType Info)
968
0
{
969
0
    cmsTagSignature sig;
970
971
0
    switch (Info) {
972
973
0
    case cmsInfoDescription:
974
0
        sig = cmsSigProfileDescriptionTag;
975
0
        break;
976
977
0
    case cmsInfoManufacturer:
978
0
        sig = cmsSigDeviceMfgDescTag;
979
0
        break;
980
981
0
    case cmsInfoModel:
982
0
        sig = cmsSigDeviceModelDescTag;
983
0
         break;
984
985
0
    case cmsInfoCopyright:
986
0
        sig = cmsSigCopyrightTag;
987
0
        break;
988
989
0
    default: return NULL;
990
0
    }
991
992
993
0
    return (cmsMLU*) cmsReadTag(ContextID, hProfile, sig);
994
0
}
995
996
997
998
cmsUInt32Number CMSEXPORT cmsGetProfileInfo(cmsContext ContextID, cmsHPROFILE hProfile, cmsInfoType Info,
999
                                            const char LanguageCode[3], const char CountryCode[3],
1000
                                            wchar_t* Buffer, cmsUInt32Number BufferSize)
1001
0
{
1002
0
    const cmsMLU* mlu = GetInfo(ContextID, hProfile, Info);
1003
0
    if (mlu == NULL) return 0;
1004
1005
0
    return cmsMLUgetWide(ContextID, mlu, LanguageCode, CountryCode, Buffer, BufferSize);
1006
0
}
1007
1008
1009
cmsUInt32Number  CMSEXPORT cmsGetProfileInfoASCII(cmsContext ContextID, cmsHPROFILE hProfile, cmsInfoType Info,
1010
                                                          const char LanguageCode[3], const char CountryCode[3],
1011
                                                          char* Buffer, cmsUInt32Number BufferSize)
1012
0
{
1013
0
    const cmsMLU* mlu = GetInfo(ContextID, hProfile, Info);
1014
0
    if (mlu == NULL) return 0;
1015
1016
0
    return cmsMLUgetASCII(ContextID, mlu, LanguageCode, CountryCode, Buffer, BufferSize);
1017
0
}