Coverage Report

Created: 2026-04-01 07:17

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ghostpdl/lcms2mt/src/extra_xform.h
Line
Count
Source
1
//
2
// Little cms
3
4
// Chameleonic header file to instantiate different versions of the
5
// transform routines.
6
//
7
// As a bare minimum the following must be defined on entry:
8
//   FUNCTION_NAME             the name of the function
9
//
10
// In addition, a range of other symbols can be optionally defined on entry
11
// to make the generated code more efficient. All these symbols (and
12
// FUNCTION_NAME) will be automatically undefined at the end of the file so
13
// that repeated #includes of this file are made simple.
14
//
15
// If caching is wanted, define CACHED.
16
//
17
// If the representation/calculations are to be done using floating point
18
// define XFORM_FLOAT. In the absence of this it is assumed that the
19
// calculations will be done in 16 bit with appropriate unpacking/repacking.
20
//
21
// If you know the number of input/output channels, define NUMINCHANNELS and
22
// NUMOUTCHANNELS.
23
//
24
// If you know the number of bytes used for the packed version of input and/or
25
// output, define INPACKEDSAMPLESIZE and OUTPACKEDSAMPLESIZE.
26
//
27
// If you do not know the number of channels and/or the sample size, but you
28
// do know a maximum bound on the number of bytes used to represent the
29
// unpacked samples, then operation with CACHE can be accelerated by defining
30
// CMPBYTES to the number of bytes that should be compared to the cached result.
31
// Usually that is calculated from NUMINCHANNELS and INPACKEDSAMPLESIZE, so
32
// specifying it directly is only useful if either (or both) of those is not
33
// known in advance.
34
//
35
// For Premultiplied Alpha modes, you must define PREMULT. We only support
36
// premultiplied alpha where the alpha is the last 'extra' channel, and
37
// where both source and destination are packed in the same way.
38
//
39
// If you know the code to be used to unpack (or pack, or both) data to/from
40
// the simple 16 bit transform input/output format, then you can choose
41
// to this directly by defining UNPACK/PACK macros as follows:
42
//   UNPACK(T,TO,FROM,SIZE,AL) (Opt)   code to unpack input data (T = Transform
43
//                                     TO = buffer to unpack into, FROM = data,
44
//                                     SIZE = size of data, AL = Alpha)
45
//   PACK(T,FROM,TO,SIZE,AL)   (Opt)   code to pack transformed input data
46
//                                    (T = Transform, FROM = transformed data,
47
//                                    TO = output buffer to pack into,
48
//                                    SIZE = size of data, AL = Alpha)
49
//
50
// Ignore AL unless PREMULT is defined, in which case it will be in the packed
51
// format. AL is guaranteed to be non-zero.
52
//
53
// If UNPACKINCLUDESPREALPHA is defined, then UNPACK should undo the
54
// premultiplication by AL (i.e. divide by AL). Otherwise AL should be ignored
55
// and this routine will do it for you.
56
//
57
// If PACKINCLUDESPREALPHA is defined, then PACK should apply AL (i.e. multiply
58
// by AL). Otherwise AL should be ignored and this routine will do it for you.
59
//
60
// As an alternative to the above, if you know the function name that would
61
// be called, supply that in UNPACKFN and PACKFN and inlining compilers
62
// should hopefully do the hard work for you.
63
//   UNPACKFN          (Opt)   function to unpack input data
64
//   PACKFN            (Opt)   function to pack input data
65
//
66
// If the data happens to be in the correct input format anyway, we can skip
67
// unpacking it entirely and just use it direct.
68
//   NO_UNPACK         (Opt)   if defined, transform direct from the input
69
//                             data.
70
//
71
// UNPACK/PACK/UNPACKFN/PACKFN/NO_UNPACK are all expected to update their
72
// TO pointer to point to the next pixels data. This means for cases where
73
// we have extra bytes, they should skip the extra bytes too!
74
//
75
// If the data happens to be in the correct output format anyway, we can skip
76
// packing it entirely and just transform it direct into the buffer.
77
//   NO_PACK           (Opt)   if defined, transform direct to the output
78
//                             data.
79
//   COPY_MATCHED(FROM,TO)(Opt)if defined, copy output values from FROM to
80
//                             TO. Used in the case CACHED case where the
81
//                             cache matches and we have to copy forwards.
82
//
83
// GAMUTCHECK can be predefined if a gamut check needs to be done.
84
//
85
// If there are a known number of extra bytes to be dealt with, define EXTRABYTES
86
// to that number (such as 0 for none).
87
// If you want to provide your own code for copying from input to output, define
88
// COPY_EXTRAS(TRANS,FROM,TO) to do so.
89
// If none of these are defined, we call cmsHandleExtraChannels.
90
91
#ifndef CMPBYTES
92
#ifdef NUMINCHANNELS
93
#ifdef XFORM_FLOAT
94
#define CMPBYTES (NUMINCHANNELS*4)
95
#else
96
#define CMPBYTES (NUMINCHANNELS*2)
97
#endif
98
#endif
99
#endif
100
101
#ifdef CMPBYTES
102
 // Previously, we've attempted to do 'int' based checks here, but this falls
103
 // foul of some compilers with their strict pointer aliasing. We have the
104
 // choice of calling memcmp (which tests using chars, so is safe), or of
105
 // testing using the actual type.
106
 #ifdef XFORM_FLOAT
107
  #if CMPBYTES == 4
108
   #define COMPARE(A,B) ((A)[0] != (B)[0])
109
  #elif CMPBYTES == 8
110
   #define COMPARE(A,B) (((A)[0] != (B)[0]) || ((A)[1] != (B)[1]))
111
  #elif CMPBYTES == 12
112
   #define COMPARE(A,B) (((A)[0] != (B)[0]) || ((A)[1] != (B)[1]) || ((A)[2] != (B)[2]))
113
  #elif CMPBYTES == 16
114
   #define COMPARE(A,B) (((A)[0] != (B)[0]) || ((A)[1] != (B)[1]) || ((A)[2] != (B)[2]) || ((A)[3] != (B)[3]))
115
  #endif
116
 #else
117
  #if CMPBYTES == 2
118
23.6M
   #define COMPARE(A,B) ((A)[0] != (B)[0])
119
  #elif CMPBYTES == 4
120
0
   #define COMPARE(A,B) (((A)[0] != (B)[0]) || ((A)[1] != (B)[1]))
121
  #elif CMPBYTES == 6
122
1.45G
   #define COMPARE(A,B) (((A)[0] != (B)[0]) || ((A)[1] != (B)[1]) || ((A)[2] != (B)[2]))
123
  #elif CMPBYTES == 8
124
285M
   #define COMPARE(A,B) (((A)[0] != (B)[0]) || ((A)[1] != (B)[1]) || ((A)[2] != (B)[2]) || ((A)[3] != (B)[3]))
125
  #endif
126
 #endif
127
#else
128
 // Otherwise, set INBYTES to be the maximum size it could possibly be.
129
 #ifdef XFORM_FLOAT
130
  #define CMPBYTES (sizeof(cmsFloat32Number)*cmsMAXCHANNELS)
131
 #else
132
0
  #define CMPBYTES (sizeof(cmsUInt16Number)*cmsMAXCHANNELS)
133
 #endif
134
#endif
135
136
#ifndef COMPARE
137
0
 #define COMPARE(A,B) memcmp((A),(B), CMPBYTES)
138
#endif
139
140
#if   defined(UNPACK)
141
 // Nothing to do, UNPACK is already defined
142
#elif defined(NO_UNPACK)
143
 #define UNPACK(CTX,T,TO,FROM,STRIDE,AL) do { } while (0)
144
#elif defined(UNPACKFN)
145
 #define UNPACK(CTX,T,TO,FROM,STRIDE,AL) \
146
    do { (FROM) = UNPACKFN((CTX),(T),(TO),(FROM),(STRIDE),(AL)); } while (0)
147
#elif defined(XFORM_FLOAT)
148
 #define UNPACK(CTX,T,TO,FROM,STRIDE,AL) \
149
    do { (FROM) = (T)->FromInputFloat((CTX),(T),(TO),(FROM),(STRIDE)); } while (0)
150
#else
151
 #define UNPACK(CTX,T,TO,FROM,STRIDE,AL) \
152
166M
    do { (FROM) = (T)->FromInput((CTX),(T),(TO),(FROM),(STRIDE)); } while (0)
153
#endif
154
155
#if defined(PACK)
156
 // Nothing to do, PACK is already defined
157
#elif defined(NO_PACK)
158
 #define PACK(CTX,T,FROM,TO,STRIDE,AL) \
159
     do { (FROM) += (totaloutbytes/sizeof(XFORM_TYPE)); } while (0)
160
#elif defined(PACKFN)
161
 #define PACK(CTX,T,FROM,TO,STRIDE,AL) \
162
     do { (TO) = PACKFN((CTX),(T),(FROM),(TO),(STRIDE)); } while (0)
163
#elif defined(XFORM_FLOAT)
164
 #define PACK(CTX,T,FROM,TO,STRIDE,AL) \
165
     do { (TO) = (T)->ToOutputFloat((CTX),(T),(FROM),(TO),(STRIDE)); } while (0)
166
#else
167
 #define PACK(CTX,T,FROM,TO,STRIDE,AL) \
168
166M
     do { (TO) = (T)->ToOutput((CTX),(T),(FROM),(TO),(STRIDE)); } while (0)
169
#endif
170
171
#ifndef ZEROPACK
172
/* The 'default' definition of ZEROPACK only works when
173
 * inpackedsamplesize == outpackedsamplesize. */
174
0
#define ZEROPACK(CTX,T,TO,FROM) do { \
175
0
    memset((TO),0,numoutchannels*outpackedsamplesize);\
176
0
    if (numextras != 0) memcpy((TO)+numoutchannels*outpackedsamplesize,\
177
0
                               (FROM)+numinchannels*inpackedsamplesize,\
178
0
                               numextras*outpackedsamplesize);\
179
0
    (TO)+=(1+prealphaindexout)*outpackedsamplesize; } while (0)
180
#endif
181
182
#ifndef UNPRE
183
#ifdef PREALPHA
184
#else
185
#define UNPRE(CTX,T,S,A) do {} while (0)
186
#endif
187
#endif
188
189
#ifndef REPRE
190
#ifdef PREALPHA
191
#define REPRE(CTX,T,S,A) do { int i; for (i = 0; i < numoutchannels; i++) \
192
                                          (S)[i] = mul65535((S)[i],A); } while (0)
193
#else
194
#define REPRE(CTX,T,S,A) do {} while (0)
195
#endif
196
#endif
197
198
#ifndef XFORMVARS
199
#define XFORMVARS(p) do { } while (0)
200
#endif
201
202
#if defined(NUMOUTCHANNELS)
203
 #ifdef XFORM_FLOAT
204
  #define OUTBYTES (sizeof(cmsFloat32Number)*NUMOUTCHANNELS)
205
 #else
206
  #define OUTBYTES (sizeof(cmsUInt16Number)*NUMOUTCHANNELS)
207
 #endif
208
#endif
209
210
#if defined(NO_PACK) && !defined(COPY_MATCHED) && defined(OUTBYTES)
211
 #if (defined(XFORM_FLOAT) && OUTBYTES == 4) || OUTBYTES == 2
212
  #define COPY_MATCHED(FROM,TO) ((TO)[0] = (FROM)[0])
213
 #elif (defined(XFORM_FLOAT) && OUTBYTES == 8) || OUTBYTES == 4
214
  #define COPY_MATCHED(FROM,TO) ((TO)[0] = (FROM)[0],(TO)[1] = (FROM)[1])
215
 #elif (defined(XFORM_FLOAT) && OUTBYTES == 12) || OUTBYTES == 6
216
  #define COPY_MATCHED(FROM,TO) ((TO)[0] = (FROM)[0],(TO)[1] = (FROM)[1],(TO)[2] = (FROM)[2])
217
 #elif (defined(XFORM_FLOAT) && OUTBYTES == 16) || OUTBYTES == 8
218
  #define COPY_MATCHED(FROM,TO) ((TO)[0] = (FROM)[0],(TO)[1] = (FROM)[1],(TO)[2] = (FROM)[2],(TO)[3] = (FROM)[3])
219
 #else
220
  #define COPY_MATCHED(FROM,TO) memcpy((TO),(FROM),(OUTBYTES))
221
 #endif
222
#endif
223
224
#ifdef XFORM_FLOAT
225
 #define XFORM_TYPE cmsFloat32Number
226
#else
227
954M
 #define XFORM_TYPE cmsUInt16Number
228
#endif
229
230
#ifndef COPY_EXTRAS
231
 #ifdef NUMEXTRAS
232
  #if NUMEXTRAS == 0
233
1.76G
   #define COPY_EXTRAS(TRANS,FROM,TO) do { } while (0)
234
  #else
235
   #define COPY_EXTRAS(TRANS,FROM,TO) \
236
0
       do { memcpy((TO),(FROM),(NUMEXTRAS)*inpackedsamplesize); \
237
0
            (TO) += (NUMEXTRAS)*inpackedsamplesize; \
238
0
            (FROM) += (NUMEXTRAS)*inpackedsamplesize; \
239
0
       } while (0)
240
  #endif
241
 #else
242
  #define BULK_COPY_EXTRAS
243
54.7M
  #define COPY_EXTRAS(TRANS,FROM,TO) do { } while (0)
244
 #endif
245
#endif
246
247
static
248
void FUNCTION_NAME(cmsContext ContextID,
249
       _cmsTRANSFORM* p,
250
                   const void* in,
251
                   void* out,
252
                   cmsUInt32Number PixelsPerLine,
253
                   cmsUInt32Number LineCount,
254
                   const cmsStride* Stride)
255
192M
{
256
192M
    _cmsTRANSFORMCORE *core = p->core;
257
192M
#ifndef NO_UNPACK
258
 #ifdef XFORM_FLOAT
259
    cmsFloat32Number wIn[cmsMAXCHANNELS*2];
260
 #else
261
192M
    cmsUInt16Number wIn[cmsMAXCHANNELS*2];
262
192M
 #endif
263
379M
 #define wIn0 (&wIn[0])
264
382M
 #define wIn1 (&wIn[cmsMAXCHANNELS])
265
192M
#endif
266
192M
    XFORM_TYPE *currIn;
267
#ifdef CACHED
268
189M
    XFORM_TYPE *prevIn;
269
#endif /* CACHED */
270
#ifdef NO_PACK
271
    XFORM_TYPE *wOut = (XFORM_TYPE *)out;
272
    XFORM_TYPE *prevOut = (XFORM_TYPE *)p->Cache.CacheOut;
273
#else
274
192M
    XFORM_TYPE wOut[cmsMAXCHANNELS];
275
192M
#endif
276
#if defined(PREALPHA) && !defined(PACKINCLUDESPREALPHA)
277
0
    XFORM_TYPE wScaled[cmsMAXCHANNELS];
278
#endif
279
#ifdef GAMUTCHECK
280
    _cmsPipelineEval16Fn evalGamut = core->GamutCheck->Eval16Fn;
281
#endif /* GAMUTCHECK */
282
#ifdef XFORM_FLOAT
283
    _cmsPipelineEvalFloatFn eval = core->Lut->EvalFloatFn;
284
    const cmsPipeline *data = core->Lut;
285
#else
286
192M
    _cmsPipelineEval16Fn eval = core->Lut->Eval16Fn;
287
192M
    void *data = core->Lut->Data;
288
192M
#endif
289
192M
    cmsUInt32Number bppi = Stride->BytesPerPlaneIn;
290
192M
    cmsUInt32Number bppo = Stride->BytesPerPlaneOut;
291
#ifdef NUMINCHANNELS
292
189M
    int numinchannels = NUMINCHANNELS;
293
#else
294
3.02M
    int numinchannels = T_CHANNELS(p->InputFormat);
295
#endif
296
#ifdef NUMOUTCHANNELS
297
189M
    int numoutchannels = NUMOUTCHANNELS;
298
#else
299
3.02M
    int numoutchannels = T_CHANNELS(p->OutputFormat);
300
#endif
301
#ifdef NUMEXTRAS
302
189M
    int numextras = NUMEXTRAS;
303
#else
304
3.01M
    int numextras = T_EXTRA(p->InputFormat);
305
#endif
306
#ifdef INPACKEDSAMPLESIZE
307
189M
    int inpackedsamplesize = INPACKEDSAMPLESIZE;
308
#else
309
3.02M
    int inpackedsamplesize = T_BYTES(p->InputFormat);
310
#endif
311
#ifdef OUTPACKEDSAMPLESIZE
312
189M
    int outpackedsamplesize = OUTPACKEDSAMPLESIZE;
313
#else
314
3.02M
    int outpackedsamplesize = T_BYTES(p->OutputFormat);
315
#endif
316
192M
    int prealphaindexin = numinchannels + numextras - 1;
317
192M
    int prealphaindexout = numoutchannels + numextras - 1;
318
192M
    int totalinbytes = (numinchannels + numextras)*inpackedsamplesize;
319
192M
    int totaloutbytes = (numoutchannels + numextras)*outpackedsamplesize;
320
321
    /* Silence some warnings */
322
192M
    (void)bppi;
323
192M
    (void)bppo;
324
192M
    (void)prealphaindexin;
325
192M
    (void)numextras;
326
192M
    (void)prealphaindexout;
327
192M
    (void)inpackedsamplesize;
328
192M
    (void)outpackedsamplesize;
329
192M
    (void)totalinbytes;
330
192M
    (void)totaloutbytes;
331
332
#ifdef BULK_COPY_EXTRAS
333
3.01M
    if (core->dwOriginalFlags & cmsFLAGS_COPY_ALPHA)
334
0
        _cmsHandleExtraChannels(ContextID, p, in, out, PixelsPerLine, LineCount, Stride);
335
#endif
336
337
192M
    if (PixelsPerLine == 0)
338
0
        return;
339
340
#ifdef NO_UNPACK
341
    prevIn = (XFORM_TYPE *)p->Cache.CacheIn;
342
#else
343
 #ifdef CACHED
344
    // Empty buffers for quick memcmp
345
189M
    memset(wIn1, 0, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
346
347
    // Get copy of zero cache
348
189M
    memcpy(wIn0, p->Cache.CacheIn,  sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
349
189M
    memcpy(wOut, p->Cache.CacheOut, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
350
351
    // The caller guarantees us that the cache is always valid on entry; if
352
    // the representation is changed, the cache is reset.
353
189M
    prevIn = wIn0;
354
 #endif /* CACHED */
355
192M
    currIn = wIn1;
356
3.01M
#endif
357
358
385M
    while (LineCount-- > 0)
359
192M
    {
360
192M
        cmsUInt32Number n = PixelsPerLine;
361
192M
        cmsUInt8Number* accum  = (cmsUInt8Number*) in;
362
192M
        cmsUInt8Number* output = (cmsUInt8Number*) out;
363
#ifdef NO_UNPACK
364
        currIn = (XFORM_TYPE *)accum;
365
#endif
366
2.01G
        while (n-- > 0) { // prevIn == CacheIn, wOut = CacheOut
367
#ifdef PREALPHA
368
 #ifdef XFORM_FLOAT
369
            cmsFloat32Number alpha = ((cmsFloat32Number *)accum)[prealphaindexin];
370
 #else
371
0
            cmsUInt32Number alpha = inpackedsamplesize == 2 ?
372
0
                                     ((cmsUInt16Number *)accum)[prealphaindexin] :
373
0
                                     (accum[prealphaindexin]);
374
 #endif
375
0
            if (alpha == 0) {
376
0
                ZEROPACK(ContextID,p,output,accum);
377
0
                accum += inpackedsamplesize*(prealphaindexin+1);
378
0
            } else {
379
0
#endif
380
1.81G
                UNPACK(ContextID,p,currIn,accum,bppi,alpha);
381
#ifdef PREALPHA
382
 #ifndef UNPACKINCLUDESPREALPHA
383
  #ifdef XFORM_FLOAT
384
                {
385
                    int i;
386
                    cmsFloat32Number inva = 1.0f / alpha;
387
                    for (i = 0; i < numinchannels; i++)
388
                        currIn[i] *= inva;
389
                }
390
  #else
391
                {
392
                    int i;
393
0
                    cmsUInt32Number al = inpackedsamplesize == 1 ? alpha*0x101 : alpha;
394
                    cmsUInt32Number inva = 0xffff0000U / al;
395
0
                    for (i = 0; i < numinchannels; i++)
396
0
                        currIn[i] = ((currIn[i] * inva)>>16);
397
                }
398
  #endif
399
 #endif
400
#endif
401
#ifdef CACHED
402
1.76G
                if (COMPARE(currIn, prevIn))
403
380M
#endif /* CACHED */
404
380M
                {
405
#ifdef GAMUTCHECK
406
 #ifdef XFORM_FLOAT
407
                    cmsFloat32Number OutOfGamut;
408
409
                    // Evaluate gamut marker.
410
                    cmsPipelineEvalFloat(currIn, &OutOfGamut, core->GamutCheck);
411
412
                    // Is current color out of gamut?
413
                    if (OutOfGamut > 0.0)
414
                        // Certainly, out of gamut
415
                        for (j=0; j < cmsMAXCHANNELS; j++)
416
                            fOut[j] = -1.0;
417
                    else
418
 #else
419
                    cmsUInt16Number wOutOfGamut;
420
421
                    evalGamut(ContextID, currIn, &wOutOfGamut, core->GamutCheck->Data);
422
0
                    if (wOutOfGamut >= 1)
423
                        /* RJW: Could be faster? copy once to a local buffer? */
424
0
                        cmsGetAlarmCodes(ContextID, wOut);
425
0
                    else
426
0
 #endif /* FLOAT_XFORM */
427
0
#endif /* GAMUTCHECK */
428
0
                        eval(ContextID, currIn, wOut, data);
429
#ifdef NO_UNPACK
430
 #ifdef CACHED
431
                    prevIn = currIn;
432
 #endif
433
                    currIn = (XFORM_TYPE *)(((char *)currIn) + totalinbytes);
434
#else
435
 #ifdef CACHED
436
380M
                    {XFORM_TYPE *tmp = currIn; currIn = prevIn; prevIn = tmp;} // SWAP
437
 #endif /* CACHED */
438
380M
#endif /* NO_UNPACK */
439
380M
                }
440
#ifdef NO_PACK
441
                else
442
                    COPY_MATCHED(prevOut,wOut);
443
                prevOut = wOut;
444
#endif
445
#ifdef PREALPHA
446
 #ifndef PACKINCLUDESPREALPHA
447
  #ifdef XFORM_FLOAT
448
                {
449
                    int i;
450
                    for (i = 0; i < numoutchannels; i++)
451
                        wScaled = wOut[i] * alpha;
452
                }
453
  #else
454
                {
455
                    int i;
456
0
                    cmsUInt32Number al = inpackedsamplesize == 1 ? alpha*0x101 : alpha;
457
0
                    for (i = 0; i < numoutchannels; i++)
458
0
                        wScaled[i] = mul65535(wOut[i],al);
459
                }
460
  #endif
461
0
                PACK(ContextID,p,wScaled,output,bppo,alpha);
462
 #else
463
0
                PACK(ContextID,p,wOut,output,bppo,alpha);
464
 #endif
465
#else
466
1.81G
                PACK(ContextID,p,wOut,output,bppo,alpha);
467
#endif
468
1.81G
                COPY_EXTRAS(p,accum,output);
469
#ifdef PREALPHA
470
            }
471
#endif
472
1.81G
        } /* End x loop */
473
192M
        in = (void *)((cmsUInt8Number *)in + Stride->BytesPerLineIn);
474
192M
        out = (void *)((cmsUInt8Number *)out + Stride->BytesPerLineOut);
475
192M
    } /* End y loop */
476
    /* The following code is only safe if we know that a given transform is
477
     * called on one thread a time. */
478
#if 0
479
#ifdef CACHED
480
#ifdef NO_UNPACK
481
    memcpy(p->Cache.CacheIn,prevIn, CMPBYTES);
482
#else
483
    memcpy(p->Cache.CacheIn, prevIn, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
484
#endif
485
#ifdef NO_PACK
486
    COPY_MATCHED(prevOut,p->Cache.CacheOut);
487
#else
488
    memcpy(p->Cache.CacheOut, wOut, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
489
#endif /* NO_PACK */
490
#endif /* CACHED */
491
#endif
492
3.01M
}
Unexecuted instantiation: cmsxform.c:PrecalculatedXFORMGamutCheck_P
Unexecuted instantiation: cmsxform.c:PrecalculatedXFORM_P
Unexecuted instantiation: cmsxform.c:CachedXFORMGamutCheck_P
Unexecuted instantiation: cmsxform.c:PrecalculatedXFORMGamutCheck
cmsxform.c:PrecalculatedXFORM
Line
Count
Source
255
3.01M
{
256
3.01M
    _cmsTRANSFORMCORE *core = p->core;
257
3.01M
#ifndef NO_UNPACK
258
 #ifdef XFORM_FLOAT
259
    cmsFloat32Number wIn[cmsMAXCHANNELS*2];
260
 #else
261
3.01M
    cmsUInt16Number wIn[cmsMAXCHANNELS*2];
262
3.01M
 #endif
263
3.01M
 #define wIn0 (&wIn[0])
264
3.01M
 #define wIn1 (&wIn[cmsMAXCHANNELS])
265
3.01M
#endif
266
3.01M
    XFORM_TYPE *currIn;
267
#ifdef CACHED
268
    XFORM_TYPE *prevIn;
269
#endif /* CACHED */
270
#ifdef NO_PACK
271
    XFORM_TYPE *wOut = (XFORM_TYPE *)out;
272
    XFORM_TYPE *prevOut = (XFORM_TYPE *)p->Cache.CacheOut;
273
#else
274
3.01M
    XFORM_TYPE wOut[cmsMAXCHANNELS];
275
3.01M
#endif
276
#if defined(PREALPHA) && !defined(PACKINCLUDESPREALPHA)
277
    XFORM_TYPE wScaled[cmsMAXCHANNELS];
278
#endif
279
#ifdef GAMUTCHECK
280
    _cmsPipelineEval16Fn evalGamut = core->GamutCheck->Eval16Fn;
281
#endif /* GAMUTCHECK */
282
#ifdef XFORM_FLOAT
283
    _cmsPipelineEvalFloatFn eval = core->Lut->EvalFloatFn;
284
    const cmsPipeline *data = core->Lut;
285
#else
286
3.01M
    _cmsPipelineEval16Fn eval = core->Lut->Eval16Fn;
287
3.01M
    void *data = core->Lut->Data;
288
3.01M
#endif
289
3.01M
    cmsUInt32Number bppi = Stride->BytesPerPlaneIn;
290
3.01M
    cmsUInt32Number bppo = Stride->BytesPerPlaneOut;
291
#ifdef NUMINCHANNELS
292
    int numinchannels = NUMINCHANNELS;
293
#else
294
3.01M
    int numinchannels = T_CHANNELS(p->InputFormat);
295
3.01M
#endif
296
#ifdef NUMOUTCHANNELS
297
    int numoutchannels = NUMOUTCHANNELS;
298
#else
299
3.01M
    int numoutchannels = T_CHANNELS(p->OutputFormat);
300
3.01M
#endif
301
#ifdef NUMEXTRAS
302
    int numextras = NUMEXTRAS;
303
#else
304
3.01M
    int numextras = T_EXTRA(p->InputFormat);
305
3.01M
#endif
306
#ifdef INPACKEDSAMPLESIZE
307
    int inpackedsamplesize = INPACKEDSAMPLESIZE;
308
#else
309
3.01M
    int inpackedsamplesize = T_BYTES(p->InputFormat);
310
3.01M
#endif
311
#ifdef OUTPACKEDSAMPLESIZE
312
    int outpackedsamplesize = OUTPACKEDSAMPLESIZE;
313
#else
314
3.01M
    int outpackedsamplesize = T_BYTES(p->OutputFormat);
315
3.01M
#endif
316
3.01M
    int prealphaindexin = numinchannels + numextras - 1;
317
3.01M
    int prealphaindexout = numoutchannels + numextras - 1;
318
3.01M
    int totalinbytes = (numinchannels + numextras)*inpackedsamplesize;
319
3.01M
    int totaloutbytes = (numoutchannels + numextras)*outpackedsamplesize;
320
321
    /* Silence some warnings */
322
3.01M
    (void)bppi;
323
3.01M
    (void)bppo;
324
3.01M
    (void)prealphaindexin;
325
3.01M
    (void)numextras;
326
3.01M
    (void)prealphaindexout;
327
3.01M
    (void)inpackedsamplesize;
328
3.01M
    (void)outpackedsamplesize;
329
3.01M
    (void)totalinbytes;
330
3.01M
    (void)totaloutbytes;
331
332
3.01M
#ifdef BULK_COPY_EXTRAS
333
3.01M
    if (core->dwOriginalFlags & cmsFLAGS_COPY_ALPHA)
334
0
        _cmsHandleExtraChannels(ContextID, p, in, out, PixelsPerLine, LineCount, Stride);
335
3.01M
#endif
336
337
3.01M
    if (PixelsPerLine == 0)
338
0
        return;
339
340
#ifdef NO_UNPACK
341
    prevIn = (XFORM_TYPE *)p->Cache.CacheIn;
342
#else
343
 #ifdef CACHED
344
    // Empty buffers for quick memcmp
345
    memset(wIn1, 0, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
346
347
    // Get copy of zero cache
348
    memcpy(wIn0, p->Cache.CacheIn,  sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
349
    memcpy(wOut, p->Cache.CacheOut, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
350
351
    // The caller guarantees us that the cache is always valid on entry; if
352
    // the representation is changed, the cache is reset.
353
    prevIn = wIn0;
354
 #endif /* CACHED */
355
3.01M
    currIn = wIn1;
356
3.01M
#endif
357
358
6.03M
    while (LineCount-- > 0)
359
3.01M
    {
360
3.01M
        cmsUInt32Number n = PixelsPerLine;
361
3.01M
        cmsUInt8Number* accum  = (cmsUInt8Number*) in;
362
3.01M
        cmsUInt8Number* output = (cmsUInt8Number*) out;
363
#ifdef NO_UNPACK
364
        currIn = (XFORM_TYPE *)accum;
365
#endif
366
57.7M
        while (n-- > 0) { // prevIn == CacheIn, wOut = CacheOut
367
#ifdef PREALPHA
368
 #ifdef XFORM_FLOAT
369
            cmsFloat32Number alpha = ((cmsFloat32Number *)accum)[prealphaindexin];
370
 #else
371
            cmsUInt32Number alpha = inpackedsamplesize == 2 ?
372
                                     ((cmsUInt16Number *)accum)[prealphaindexin] :
373
                                     (accum[prealphaindexin]);
374
 #endif
375
            if (alpha == 0) {
376
                ZEROPACK(ContextID,p,output,accum);
377
                accum += inpackedsamplesize*(prealphaindexin+1);
378
            } else {
379
#endif
380
54.7M
                UNPACK(ContextID,p,currIn,accum,bppi,alpha);
381
#ifdef PREALPHA
382
 #ifndef UNPACKINCLUDESPREALPHA
383
  #ifdef XFORM_FLOAT
384
                {
385
                    int i;
386
                    cmsFloat32Number inva = 1.0f / alpha;
387
                    for (i = 0; i < numinchannels; i++)
388
                        currIn[i] *= inva;
389
                }
390
  #else
391
                {
392
                    int i;
393
                    cmsUInt32Number al = inpackedsamplesize == 1 ? alpha*0x101 : alpha;
394
                    cmsUInt32Number inva = 0xffff0000U / al;
395
                    for (i = 0; i < numinchannels; i++)
396
                        currIn[i] = ((currIn[i] * inva)>>16);
397
                }
398
  #endif
399
 #endif
400
#endif
401
#ifdef CACHED
402
                if (COMPARE(currIn, prevIn))
403
#endif /* CACHED */
404
54.7M
                {
405
#ifdef GAMUTCHECK
406
 #ifdef XFORM_FLOAT
407
                    cmsFloat32Number OutOfGamut;
408
409
                    // Evaluate gamut marker.
410
                    cmsPipelineEvalFloat(currIn, &OutOfGamut, core->GamutCheck);
411
412
                    // Is current color out of gamut?
413
                    if (OutOfGamut > 0.0)
414
                        // Certainly, out of gamut
415
                        for (j=0; j < cmsMAXCHANNELS; j++)
416
                            fOut[j] = -1.0;
417
                    else
418
 #else
419
                    cmsUInt16Number wOutOfGamut;
420
421
                    evalGamut(ContextID, currIn, &wOutOfGamut, core->GamutCheck->Data);
422
                    if (wOutOfGamut >= 1)
423
                        /* RJW: Could be faster? copy once to a local buffer? */
424
                        cmsGetAlarmCodes(ContextID, wOut);
425
                    else
426
 #endif /* FLOAT_XFORM */
427
#endif /* GAMUTCHECK */
428
54.7M
                        eval(ContextID, currIn, wOut, data);
429
#ifdef NO_UNPACK
430
 #ifdef CACHED
431
                    prevIn = currIn;
432
 #endif
433
                    currIn = (XFORM_TYPE *)(((char *)currIn) + totalinbytes);
434
#else
435
 #ifdef CACHED
436
                    {XFORM_TYPE *tmp = currIn; currIn = prevIn; prevIn = tmp;} // SWAP
437
 #endif /* CACHED */
438
54.7M
#endif /* NO_UNPACK */
439
54.7M
                }
440
#ifdef NO_PACK
441
                else
442
                    COPY_MATCHED(prevOut,wOut);
443
                prevOut = wOut;
444
#endif
445
#ifdef PREALPHA
446
 #ifndef PACKINCLUDESPREALPHA
447
  #ifdef XFORM_FLOAT
448
                {
449
                    int i;
450
                    for (i = 0; i < numoutchannels; i++)
451
                        wScaled = wOut[i] * alpha;
452
                }
453
  #else
454
                {
455
                    int i;
456
                    cmsUInt32Number al = inpackedsamplesize == 1 ? alpha*0x101 : alpha;
457
                    for (i = 0; i < numoutchannels; i++)
458
                        wScaled[i] = mul65535(wOut[i],al);
459
                }
460
  #endif
461
                PACK(ContextID,p,wScaled,output,bppo,alpha);
462
 #else
463
                PACK(ContextID,p,wOut,output,bppo,alpha);
464
 #endif
465
#else
466
54.7M
                PACK(ContextID,p,wOut,output,bppo,alpha);
467
54.7M
#endif
468
54.7M
                COPY_EXTRAS(p,accum,output);
469
#ifdef PREALPHA
470
            }
471
#endif
472
54.7M
        } /* End x loop */
473
3.01M
        in = (void *)((cmsUInt8Number *)in + Stride->BytesPerLineIn);
474
3.01M
        out = (void *)((cmsUInt8Number *)out + Stride->BytesPerLineOut);
475
3.01M
    } /* End y loop */
476
    /* The following code is only safe if we know that a given transform is
477
     * called on one thread a time. */
478
#if 0
479
#ifdef CACHED
480
#ifdef NO_UNPACK
481
    memcpy(p->Cache.CacheIn,prevIn, CMPBYTES);
482
#else
483
    memcpy(p->Cache.CacheIn, prevIn, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
484
#endif
485
#ifdef NO_PACK
486
    COPY_MATCHED(prevOut,p->Cache.CacheOut);
487
#else
488
    memcpy(p->Cache.CacheOut, wOut, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
489
#endif /* NO_PACK */
490
#endif /* CACHED */
491
#endif
492
3.01M
}
Unexecuted instantiation: cmsxform.c:CachedXFORMGamutCheck
Unexecuted instantiation: cmsxform.c:CachedXFORM1to1_P1
Unexecuted instantiation: cmsxform.c:CachedXFORM1x2to1x2_P2
Unexecuted instantiation: cmsxform.c:CachedXFORM1to3_P1
Unexecuted instantiation: cmsxform.c:CachedXFORM1x2to3x2_P2
Unexecuted instantiation: cmsxform.c:CachedXFORM1to4_P1
Unexecuted instantiation: cmsxform.c:CachedXFORM1x2to4x2_P2
Unexecuted instantiation: cmsxform.c:CachedXFORM3to1_P1
Unexecuted instantiation: cmsxform.c:CachedXFORM3x2to1x2_P2
Unexecuted instantiation: cmsxform.c:CachedXFORM3to3_P1
Unexecuted instantiation: cmsxform.c:CachedXFORM3x2to3x2_P2
Unexecuted instantiation: cmsxform.c:CachedXFORM3to4_P1
Unexecuted instantiation: cmsxform.c:CachedXFORM3x2to4x2_P2
Unexecuted instantiation: cmsxform.c:CachedXFORM4to1_P1
Unexecuted instantiation: cmsxform.c:CachedXFORM4x2to1x2_P2
Unexecuted instantiation: cmsxform.c:CachedXFORM4to3_P1
Unexecuted instantiation: cmsxform.c:CachedXFORM4x2to3x2_P2
Unexecuted instantiation: cmsxform.c:CachedXFORM4to4_P1
Unexecuted instantiation: cmsxform.c:CachedXFORM4x2to4x2_P2
Unexecuted instantiation: cmsxform.c:CachedXFORM1to1_1
Unexecuted instantiation: cmsxform.c:CachedXFORM1x2to1x2_2
Unexecuted instantiation: cmsxform.c:CachedXFORM1to3_1
Unexecuted instantiation: cmsxform.c:CachedXFORM1x2to3x2_2
Unexecuted instantiation: cmsxform.c:CachedXFORM1to4_1
Unexecuted instantiation: cmsxform.c:CachedXFORM1x2to4x2_2
Unexecuted instantiation: cmsxform.c:CachedXFORM3to1_1
Unexecuted instantiation: cmsxform.c:CachedXFORM3x2to1x2_2
Unexecuted instantiation: cmsxform.c:CachedXFORM3to3_1
Unexecuted instantiation: cmsxform.c:CachedXFORM3x2to3x2_2
Unexecuted instantiation: cmsxform.c:CachedXFORM3to4_1
Unexecuted instantiation: cmsxform.c:CachedXFORM3x2to4x2_2
Unexecuted instantiation: cmsxform.c:CachedXFORM4to1_1
Unexecuted instantiation: cmsxform.c:CachedXFORM4x2to1x2_2
Unexecuted instantiation: cmsxform.c:CachedXFORM4to3_1
Unexecuted instantiation: cmsxform.c:CachedXFORM4x2to3x2_2
Unexecuted instantiation: cmsxform.c:CachedXFORM4to4_1
Unexecuted instantiation: cmsxform.c:CachedXFORM4x2to4x2_2
Unexecuted instantiation: cmsxform.c:CachedXFORM_P1
Unexecuted instantiation: cmsxform.c:CachedXFORM_P2
Unexecuted instantiation: cmsxform.c:CachedXFORM
cmsxform.c:CachedXFORM1to1
Line
Count
Source
255
45
{
256
45
    _cmsTRANSFORMCORE *core = p->core;
257
45
#ifndef NO_UNPACK
258
 #ifdef XFORM_FLOAT
259
    cmsFloat32Number wIn[cmsMAXCHANNELS*2];
260
 #else
261
45
    cmsUInt16Number wIn[cmsMAXCHANNELS*2];
262
45
 #endif
263
45
 #define wIn0 (&wIn[0])
264
45
 #define wIn1 (&wIn[cmsMAXCHANNELS])
265
45
#endif
266
45
    XFORM_TYPE *currIn;
267
45
#ifdef CACHED
268
45
    XFORM_TYPE *prevIn;
269
45
#endif /* CACHED */
270
#ifdef NO_PACK
271
    XFORM_TYPE *wOut = (XFORM_TYPE *)out;
272
    XFORM_TYPE *prevOut = (XFORM_TYPE *)p->Cache.CacheOut;
273
#else
274
45
    XFORM_TYPE wOut[cmsMAXCHANNELS];
275
45
#endif
276
#if defined(PREALPHA) && !defined(PACKINCLUDESPREALPHA)
277
    XFORM_TYPE wScaled[cmsMAXCHANNELS];
278
#endif
279
#ifdef GAMUTCHECK
280
    _cmsPipelineEval16Fn evalGamut = core->GamutCheck->Eval16Fn;
281
#endif /* GAMUTCHECK */
282
#ifdef XFORM_FLOAT
283
    _cmsPipelineEvalFloatFn eval = core->Lut->EvalFloatFn;
284
    const cmsPipeline *data = core->Lut;
285
#else
286
45
    _cmsPipelineEval16Fn eval = core->Lut->Eval16Fn;
287
45
    void *data = core->Lut->Data;
288
45
#endif
289
45
    cmsUInt32Number bppi = Stride->BytesPerPlaneIn;
290
45
    cmsUInt32Number bppo = Stride->BytesPerPlaneOut;
291
45
#ifdef NUMINCHANNELS
292
45
    int numinchannels = NUMINCHANNELS;
293
#else
294
    int numinchannels = T_CHANNELS(p->InputFormat);
295
#endif
296
45
#ifdef NUMOUTCHANNELS
297
45
    int numoutchannels = NUMOUTCHANNELS;
298
#else
299
    int numoutchannels = T_CHANNELS(p->OutputFormat);
300
#endif
301
45
#ifdef NUMEXTRAS
302
45
    int numextras = NUMEXTRAS;
303
#else
304
    int numextras = T_EXTRA(p->InputFormat);
305
#endif
306
45
#ifdef INPACKEDSAMPLESIZE
307
45
    int inpackedsamplesize = INPACKEDSAMPLESIZE;
308
#else
309
    int inpackedsamplesize = T_BYTES(p->InputFormat);
310
#endif
311
45
#ifdef OUTPACKEDSAMPLESIZE
312
45
    int outpackedsamplesize = OUTPACKEDSAMPLESIZE;
313
#else
314
    int outpackedsamplesize = T_BYTES(p->OutputFormat);
315
#endif
316
45
    int prealphaindexin = numinchannels + numextras - 1;
317
45
    int prealphaindexout = numoutchannels + numextras - 1;
318
45
    int totalinbytes = (numinchannels + numextras)*inpackedsamplesize;
319
45
    int totaloutbytes = (numoutchannels + numextras)*outpackedsamplesize;
320
321
    /* Silence some warnings */
322
45
    (void)bppi;
323
45
    (void)bppo;
324
45
    (void)prealphaindexin;
325
45
    (void)numextras;
326
45
    (void)prealphaindexout;
327
45
    (void)inpackedsamplesize;
328
45
    (void)outpackedsamplesize;
329
45
    (void)totalinbytes;
330
45
    (void)totaloutbytes;
331
332
#ifdef BULK_COPY_EXTRAS
333
    if (core->dwOriginalFlags & cmsFLAGS_COPY_ALPHA)
334
        _cmsHandleExtraChannels(ContextID, p, in, out, PixelsPerLine, LineCount, Stride);
335
#endif
336
337
45
    if (PixelsPerLine == 0)
338
0
        return;
339
340
#ifdef NO_UNPACK
341
    prevIn = (XFORM_TYPE *)p->Cache.CacheIn;
342
#else
343
45
 #ifdef CACHED
344
    // Empty buffers for quick memcmp
345
45
    memset(wIn1, 0, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
346
347
    // Get copy of zero cache
348
45
    memcpy(wIn0, p->Cache.CacheIn,  sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
349
45
    memcpy(wOut, p->Cache.CacheOut, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
350
351
    // The caller guarantees us that the cache is always valid on entry; if
352
    // the representation is changed, the cache is reset.
353
45
    prevIn = wIn0;
354
45
 #endif /* CACHED */
355
45
    currIn = wIn1;
356
45
#endif
357
358
90
    while (LineCount-- > 0)
359
45
    {
360
45
        cmsUInt32Number n = PixelsPerLine;
361
45
        cmsUInt8Number* accum  = (cmsUInt8Number*) in;
362
45
        cmsUInt8Number* output = (cmsUInt8Number*) out;
363
#ifdef NO_UNPACK
364
        currIn = (XFORM_TYPE *)accum;
365
#endif
366
11.5k
        while (n-- > 0) { // prevIn == CacheIn, wOut = CacheOut
367
#ifdef PREALPHA
368
 #ifdef XFORM_FLOAT
369
            cmsFloat32Number alpha = ((cmsFloat32Number *)accum)[prealphaindexin];
370
 #else
371
            cmsUInt32Number alpha = inpackedsamplesize == 2 ?
372
                                     ((cmsUInt16Number *)accum)[prealphaindexin] :
373
                                     (accum[prealphaindexin]);
374
 #endif
375
            if (alpha == 0) {
376
                ZEROPACK(ContextID,p,output,accum);
377
                accum += inpackedsamplesize*(prealphaindexin+1);
378
            } else {
379
#endif
380
11.5k
                UNPACK(ContextID,p,currIn,accum,bppi,alpha);
381
#ifdef PREALPHA
382
 #ifndef UNPACKINCLUDESPREALPHA
383
  #ifdef XFORM_FLOAT
384
                {
385
                    int i;
386
                    cmsFloat32Number inva = 1.0f / alpha;
387
                    for (i = 0; i < numinchannels; i++)
388
                        currIn[i] *= inva;
389
                }
390
  #else
391
                {
392
                    int i;
393
                    cmsUInt32Number al = inpackedsamplesize == 1 ? alpha*0x101 : alpha;
394
                    cmsUInt32Number inva = 0xffff0000U / al;
395
                    for (i = 0; i < numinchannels; i++)
396
                        currIn[i] = ((currIn[i] * inva)>>16);
397
                }
398
  #endif
399
 #endif
400
#endif
401
11.5k
#ifdef CACHED
402
11.5k
                if (COMPARE(currIn, prevIn))
403
11.4k
#endif /* CACHED */
404
11.4k
                {
405
#ifdef GAMUTCHECK
406
 #ifdef XFORM_FLOAT
407
                    cmsFloat32Number OutOfGamut;
408
409
                    // Evaluate gamut marker.
410
                    cmsPipelineEvalFloat(currIn, &OutOfGamut, core->GamutCheck);
411
412
                    // Is current color out of gamut?
413
                    if (OutOfGamut > 0.0)
414
                        // Certainly, out of gamut
415
                        for (j=0; j < cmsMAXCHANNELS; j++)
416
                            fOut[j] = -1.0;
417
                    else
418
 #else
419
                    cmsUInt16Number wOutOfGamut;
420
421
                    evalGamut(ContextID, currIn, &wOutOfGamut, core->GamutCheck->Data);
422
                    if (wOutOfGamut >= 1)
423
                        /* RJW: Could be faster? copy once to a local buffer? */
424
                        cmsGetAlarmCodes(ContextID, wOut);
425
                    else
426
 #endif /* FLOAT_XFORM */
427
#endif /* GAMUTCHECK */
428
11.4k
                        eval(ContextID, currIn, wOut, data);
429
#ifdef NO_UNPACK
430
 #ifdef CACHED
431
                    prevIn = currIn;
432
 #endif
433
                    currIn = (XFORM_TYPE *)(((char *)currIn) + totalinbytes);
434
#else
435
11.4k
 #ifdef CACHED
436
11.4k
                    {XFORM_TYPE *tmp = currIn; currIn = prevIn; prevIn = tmp;} // SWAP
437
11.4k
 #endif /* CACHED */
438
11.4k
#endif /* NO_UNPACK */
439
11.4k
                }
440
#ifdef NO_PACK
441
                else
442
                    COPY_MATCHED(prevOut,wOut);
443
                prevOut = wOut;
444
#endif
445
#ifdef PREALPHA
446
 #ifndef PACKINCLUDESPREALPHA
447
  #ifdef XFORM_FLOAT
448
                {
449
                    int i;
450
                    for (i = 0; i < numoutchannels; i++)
451
                        wScaled = wOut[i] * alpha;
452
                }
453
  #else
454
                {
455
                    int i;
456
                    cmsUInt32Number al = inpackedsamplesize == 1 ? alpha*0x101 : alpha;
457
                    for (i = 0; i < numoutchannels; i++)
458
                        wScaled[i] = mul65535(wOut[i],al);
459
                }
460
  #endif
461
                PACK(ContextID,p,wScaled,output,bppo,alpha);
462
 #else
463
                PACK(ContextID,p,wOut,output,bppo,alpha);
464
 #endif
465
#else
466
11.5k
                PACK(ContextID,p,wOut,output,bppo,alpha);
467
11.5k
#endif
468
11.5k
                COPY_EXTRAS(p,accum,output);
469
#ifdef PREALPHA
470
            }
471
#endif
472
11.5k
        } /* End x loop */
473
45
        in = (void *)((cmsUInt8Number *)in + Stride->BytesPerLineIn);
474
45
        out = (void *)((cmsUInt8Number *)out + Stride->BytesPerLineOut);
475
45
    } /* End y loop */
476
    /* The following code is only safe if we know that a given transform is
477
     * called on one thread a time. */
478
#if 0
479
#ifdef CACHED
480
#ifdef NO_UNPACK
481
    memcpy(p->Cache.CacheIn,prevIn, CMPBYTES);
482
#else
483
    memcpy(p->Cache.CacheIn, prevIn, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
484
#endif
485
#ifdef NO_PACK
486
    COPY_MATCHED(prevOut,p->Cache.CacheOut);
487
#else
488
    memcpy(p->Cache.CacheOut, wOut, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
489
#endif /* NO_PACK */
490
#endif /* CACHED */
491
#endif
492
45
}
cmsxform.c:CachedXFORM1x2to1x2
Line
Count
Source
255
80.8k
{
256
80.8k
    _cmsTRANSFORMCORE *core = p->core;
257
80.8k
#ifndef NO_UNPACK
258
 #ifdef XFORM_FLOAT
259
    cmsFloat32Number wIn[cmsMAXCHANNELS*2];
260
 #else
261
80.8k
    cmsUInt16Number wIn[cmsMAXCHANNELS*2];
262
80.8k
 #endif
263
80.8k
 #define wIn0 (&wIn[0])
264
80.8k
 #define wIn1 (&wIn[cmsMAXCHANNELS])
265
80.8k
#endif
266
80.8k
    XFORM_TYPE *currIn;
267
80.8k
#ifdef CACHED
268
80.8k
    XFORM_TYPE *prevIn;
269
80.8k
#endif /* CACHED */
270
#ifdef NO_PACK
271
    XFORM_TYPE *wOut = (XFORM_TYPE *)out;
272
    XFORM_TYPE *prevOut = (XFORM_TYPE *)p->Cache.CacheOut;
273
#else
274
80.8k
    XFORM_TYPE wOut[cmsMAXCHANNELS];
275
80.8k
#endif
276
#if defined(PREALPHA) && !defined(PACKINCLUDESPREALPHA)
277
    XFORM_TYPE wScaled[cmsMAXCHANNELS];
278
#endif
279
#ifdef GAMUTCHECK
280
    _cmsPipelineEval16Fn evalGamut = core->GamutCheck->Eval16Fn;
281
#endif /* GAMUTCHECK */
282
#ifdef XFORM_FLOAT
283
    _cmsPipelineEvalFloatFn eval = core->Lut->EvalFloatFn;
284
    const cmsPipeline *data = core->Lut;
285
#else
286
80.8k
    _cmsPipelineEval16Fn eval = core->Lut->Eval16Fn;
287
80.8k
    void *data = core->Lut->Data;
288
80.8k
#endif
289
80.8k
    cmsUInt32Number bppi = Stride->BytesPerPlaneIn;
290
80.8k
    cmsUInt32Number bppo = Stride->BytesPerPlaneOut;
291
80.8k
#ifdef NUMINCHANNELS
292
80.8k
    int numinchannels = NUMINCHANNELS;
293
#else
294
    int numinchannels = T_CHANNELS(p->InputFormat);
295
#endif
296
80.8k
#ifdef NUMOUTCHANNELS
297
80.8k
    int numoutchannels = NUMOUTCHANNELS;
298
#else
299
    int numoutchannels = T_CHANNELS(p->OutputFormat);
300
#endif
301
80.8k
#ifdef NUMEXTRAS
302
80.8k
    int numextras = NUMEXTRAS;
303
#else
304
    int numextras = T_EXTRA(p->InputFormat);
305
#endif
306
80.8k
#ifdef INPACKEDSAMPLESIZE
307
80.8k
    int inpackedsamplesize = INPACKEDSAMPLESIZE;
308
#else
309
    int inpackedsamplesize = T_BYTES(p->InputFormat);
310
#endif
311
80.8k
#ifdef OUTPACKEDSAMPLESIZE
312
80.8k
    int outpackedsamplesize = OUTPACKEDSAMPLESIZE;
313
#else
314
    int outpackedsamplesize = T_BYTES(p->OutputFormat);
315
#endif
316
80.8k
    int prealphaindexin = numinchannels + numextras - 1;
317
80.8k
    int prealphaindexout = numoutchannels + numextras - 1;
318
80.8k
    int totalinbytes = (numinchannels + numextras)*inpackedsamplesize;
319
80.8k
    int totaloutbytes = (numoutchannels + numextras)*outpackedsamplesize;
320
321
    /* Silence some warnings */
322
80.8k
    (void)bppi;
323
80.8k
    (void)bppo;
324
80.8k
    (void)prealphaindexin;
325
80.8k
    (void)numextras;
326
80.8k
    (void)prealphaindexout;
327
80.8k
    (void)inpackedsamplesize;
328
80.8k
    (void)outpackedsamplesize;
329
80.8k
    (void)totalinbytes;
330
80.8k
    (void)totaloutbytes;
331
332
#ifdef BULK_COPY_EXTRAS
333
    if (core->dwOriginalFlags & cmsFLAGS_COPY_ALPHA)
334
        _cmsHandleExtraChannels(ContextID, p, in, out, PixelsPerLine, LineCount, Stride);
335
#endif
336
337
80.8k
    if (PixelsPerLine == 0)
338
0
        return;
339
340
#ifdef NO_UNPACK
341
    prevIn = (XFORM_TYPE *)p->Cache.CacheIn;
342
#else
343
80.8k
 #ifdef CACHED
344
    // Empty buffers for quick memcmp
345
80.8k
    memset(wIn1, 0, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
346
347
    // Get copy of zero cache
348
80.8k
    memcpy(wIn0, p->Cache.CacheIn,  sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
349
80.8k
    memcpy(wOut, p->Cache.CacheOut, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
350
351
    // The caller guarantees us that the cache is always valid on entry; if
352
    // the representation is changed, the cache is reset.
353
80.8k
    prevIn = wIn0;
354
80.8k
 #endif /* CACHED */
355
80.8k
    currIn = wIn1;
356
80.8k
#endif
357
358
161k
    while (LineCount-- > 0)
359
80.8k
    {
360
80.8k
        cmsUInt32Number n = PixelsPerLine;
361
80.8k
        cmsUInt8Number* accum  = (cmsUInt8Number*) in;
362
80.8k
        cmsUInt8Number* output = (cmsUInt8Number*) out;
363
#ifdef NO_UNPACK
364
        currIn = (XFORM_TYPE *)accum;
365
#endif
366
161k
        while (n-- > 0) { // prevIn == CacheIn, wOut = CacheOut
367
#ifdef PREALPHA
368
 #ifdef XFORM_FLOAT
369
            cmsFloat32Number alpha = ((cmsFloat32Number *)accum)[prealphaindexin];
370
 #else
371
            cmsUInt32Number alpha = inpackedsamplesize == 2 ?
372
                                     ((cmsUInt16Number *)accum)[prealphaindexin] :
373
                                     (accum[prealphaindexin]);
374
 #endif
375
            if (alpha == 0) {
376
                ZEROPACK(ContextID,p,output,accum);
377
                accum += inpackedsamplesize*(prealphaindexin+1);
378
            } else {
379
#endif
380
80.8k
                UNPACK(ContextID,p,currIn,accum,bppi,alpha);
381
#ifdef PREALPHA
382
 #ifndef UNPACKINCLUDESPREALPHA
383
  #ifdef XFORM_FLOAT
384
                {
385
                    int i;
386
                    cmsFloat32Number inva = 1.0f / alpha;
387
                    for (i = 0; i < numinchannels; i++)
388
                        currIn[i] *= inva;
389
                }
390
  #else
391
                {
392
                    int i;
393
                    cmsUInt32Number al = inpackedsamplesize == 1 ? alpha*0x101 : alpha;
394
                    cmsUInt32Number inva = 0xffff0000U / al;
395
                    for (i = 0; i < numinchannels; i++)
396
                        currIn[i] = ((currIn[i] * inva)>>16);
397
                }
398
  #endif
399
 #endif
400
#endif
401
80.8k
#ifdef CACHED
402
80.8k
                if (COMPARE(currIn, prevIn))
403
61.1k
#endif /* CACHED */
404
61.1k
                {
405
#ifdef GAMUTCHECK
406
 #ifdef XFORM_FLOAT
407
                    cmsFloat32Number OutOfGamut;
408
409
                    // Evaluate gamut marker.
410
                    cmsPipelineEvalFloat(currIn, &OutOfGamut, core->GamutCheck);
411
412
                    // Is current color out of gamut?
413
                    if (OutOfGamut > 0.0)
414
                        // Certainly, out of gamut
415
                        for (j=0; j < cmsMAXCHANNELS; j++)
416
                            fOut[j] = -1.0;
417
                    else
418
 #else
419
                    cmsUInt16Number wOutOfGamut;
420
421
                    evalGamut(ContextID, currIn, &wOutOfGamut, core->GamutCheck->Data);
422
                    if (wOutOfGamut >= 1)
423
                        /* RJW: Could be faster? copy once to a local buffer? */
424
                        cmsGetAlarmCodes(ContextID, wOut);
425
                    else
426
 #endif /* FLOAT_XFORM */
427
#endif /* GAMUTCHECK */
428
61.1k
                        eval(ContextID, currIn, wOut, data);
429
#ifdef NO_UNPACK
430
 #ifdef CACHED
431
                    prevIn = currIn;
432
 #endif
433
                    currIn = (XFORM_TYPE *)(((char *)currIn) + totalinbytes);
434
#else
435
61.1k
 #ifdef CACHED
436
61.1k
                    {XFORM_TYPE *tmp = currIn; currIn = prevIn; prevIn = tmp;} // SWAP
437
61.1k
 #endif /* CACHED */
438
61.1k
#endif /* NO_UNPACK */
439
61.1k
                }
440
#ifdef NO_PACK
441
                else
442
                    COPY_MATCHED(prevOut,wOut);
443
                prevOut = wOut;
444
#endif
445
#ifdef PREALPHA
446
 #ifndef PACKINCLUDESPREALPHA
447
  #ifdef XFORM_FLOAT
448
                {
449
                    int i;
450
                    for (i = 0; i < numoutchannels; i++)
451
                        wScaled = wOut[i] * alpha;
452
                }
453
  #else
454
                {
455
                    int i;
456
                    cmsUInt32Number al = inpackedsamplesize == 1 ? alpha*0x101 : alpha;
457
                    for (i = 0; i < numoutchannels; i++)
458
                        wScaled[i] = mul65535(wOut[i],al);
459
                }
460
  #endif
461
                PACK(ContextID,p,wScaled,output,bppo,alpha);
462
 #else
463
                PACK(ContextID,p,wOut,output,bppo,alpha);
464
 #endif
465
#else
466
80.8k
                PACK(ContextID,p,wOut,output,bppo,alpha);
467
80.8k
#endif
468
80.8k
                COPY_EXTRAS(p,accum,output);
469
#ifdef PREALPHA
470
            }
471
#endif
472
80.8k
        } /* End x loop */
473
80.8k
        in = (void *)((cmsUInt8Number *)in + Stride->BytesPerLineIn);
474
80.8k
        out = (void *)((cmsUInt8Number *)out + Stride->BytesPerLineOut);
475
80.8k
    } /* End y loop */
476
    /* The following code is only safe if we know that a given transform is
477
     * called on one thread a time. */
478
#if 0
479
#ifdef CACHED
480
#ifdef NO_UNPACK
481
    memcpy(p->Cache.CacheIn,prevIn, CMPBYTES);
482
#else
483
    memcpy(p->Cache.CacheIn, prevIn, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
484
#endif
485
#ifdef NO_PACK
486
    COPY_MATCHED(prevOut,p->Cache.CacheOut);
487
#else
488
    memcpy(p->Cache.CacheOut, wOut, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
489
#endif /* NO_PACK */
490
#endif /* CACHED */
491
#endif
492
80.8k
}
Unexecuted instantiation: cmsxform.c:CachedXFORM1to3
cmsxform.c:CachedXFORM1x2to3x2
Line
Count
Source
255
22.6M
{
256
22.6M
    _cmsTRANSFORMCORE *core = p->core;
257
22.6M
#ifndef NO_UNPACK
258
 #ifdef XFORM_FLOAT
259
    cmsFloat32Number wIn[cmsMAXCHANNELS*2];
260
 #else
261
22.6M
    cmsUInt16Number wIn[cmsMAXCHANNELS*2];
262
22.6M
 #endif
263
22.6M
 #define wIn0 (&wIn[0])
264
22.6M
 #define wIn1 (&wIn[cmsMAXCHANNELS])
265
22.6M
#endif
266
22.6M
    XFORM_TYPE *currIn;
267
22.6M
#ifdef CACHED
268
22.6M
    XFORM_TYPE *prevIn;
269
22.6M
#endif /* CACHED */
270
#ifdef NO_PACK
271
    XFORM_TYPE *wOut = (XFORM_TYPE *)out;
272
    XFORM_TYPE *prevOut = (XFORM_TYPE *)p->Cache.CacheOut;
273
#else
274
22.6M
    XFORM_TYPE wOut[cmsMAXCHANNELS];
275
22.6M
#endif
276
#if defined(PREALPHA) && !defined(PACKINCLUDESPREALPHA)
277
    XFORM_TYPE wScaled[cmsMAXCHANNELS];
278
#endif
279
#ifdef GAMUTCHECK
280
    _cmsPipelineEval16Fn evalGamut = core->GamutCheck->Eval16Fn;
281
#endif /* GAMUTCHECK */
282
#ifdef XFORM_FLOAT
283
    _cmsPipelineEvalFloatFn eval = core->Lut->EvalFloatFn;
284
    const cmsPipeline *data = core->Lut;
285
#else
286
22.6M
    _cmsPipelineEval16Fn eval = core->Lut->Eval16Fn;
287
22.6M
    void *data = core->Lut->Data;
288
22.6M
#endif
289
22.6M
    cmsUInt32Number bppi = Stride->BytesPerPlaneIn;
290
22.6M
    cmsUInt32Number bppo = Stride->BytesPerPlaneOut;
291
22.6M
#ifdef NUMINCHANNELS
292
22.6M
    int numinchannels = NUMINCHANNELS;
293
#else
294
    int numinchannels = T_CHANNELS(p->InputFormat);
295
#endif
296
22.6M
#ifdef NUMOUTCHANNELS
297
22.6M
    int numoutchannels = NUMOUTCHANNELS;
298
#else
299
    int numoutchannels = T_CHANNELS(p->OutputFormat);
300
#endif
301
22.6M
#ifdef NUMEXTRAS
302
22.6M
    int numextras = NUMEXTRAS;
303
#else
304
    int numextras = T_EXTRA(p->InputFormat);
305
#endif
306
22.6M
#ifdef INPACKEDSAMPLESIZE
307
22.6M
    int inpackedsamplesize = INPACKEDSAMPLESIZE;
308
#else
309
    int inpackedsamplesize = T_BYTES(p->InputFormat);
310
#endif
311
22.6M
#ifdef OUTPACKEDSAMPLESIZE
312
22.6M
    int outpackedsamplesize = OUTPACKEDSAMPLESIZE;
313
#else
314
    int outpackedsamplesize = T_BYTES(p->OutputFormat);
315
#endif
316
22.6M
    int prealphaindexin = numinchannels + numextras - 1;
317
22.6M
    int prealphaindexout = numoutchannels + numextras - 1;
318
22.6M
    int totalinbytes = (numinchannels + numextras)*inpackedsamplesize;
319
22.6M
    int totaloutbytes = (numoutchannels + numextras)*outpackedsamplesize;
320
321
    /* Silence some warnings */
322
22.6M
    (void)bppi;
323
22.6M
    (void)bppo;
324
22.6M
    (void)prealphaindexin;
325
22.6M
    (void)numextras;
326
22.6M
    (void)prealphaindexout;
327
22.6M
    (void)inpackedsamplesize;
328
22.6M
    (void)outpackedsamplesize;
329
22.6M
    (void)totalinbytes;
330
22.6M
    (void)totaloutbytes;
331
332
#ifdef BULK_COPY_EXTRAS
333
    if (core->dwOriginalFlags & cmsFLAGS_COPY_ALPHA)
334
        _cmsHandleExtraChannels(ContextID, p, in, out, PixelsPerLine, LineCount, Stride);
335
#endif
336
337
22.6M
    if (PixelsPerLine == 0)
338
0
        return;
339
340
#ifdef NO_UNPACK
341
    prevIn = (XFORM_TYPE *)p->Cache.CacheIn;
342
#else
343
22.6M
 #ifdef CACHED
344
    // Empty buffers for quick memcmp
345
22.6M
    memset(wIn1, 0, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
346
347
    // Get copy of zero cache
348
22.6M
    memcpy(wIn0, p->Cache.CacheIn,  sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
349
22.6M
    memcpy(wOut, p->Cache.CacheOut, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
350
351
    // The caller guarantees us that the cache is always valid on entry; if
352
    // the representation is changed, the cache is reset.
353
22.6M
    prevIn = wIn0;
354
22.6M
 #endif /* CACHED */
355
22.6M
    currIn = wIn1;
356
22.6M
#endif
357
358
45.3M
    while (LineCount-- > 0)
359
22.6M
    {
360
22.6M
        cmsUInt32Number n = PixelsPerLine;
361
22.6M
        cmsUInt8Number* accum  = (cmsUInt8Number*) in;
362
22.6M
        cmsUInt8Number* output = (cmsUInt8Number*) out;
363
#ifdef NO_UNPACK
364
        currIn = (XFORM_TYPE *)accum;
365
#endif
366
45.3M
        while (n-- > 0) { // prevIn == CacheIn, wOut = CacheOut
367
#ifdef PREALPHA
368
 #ifdef XFORM_FLOAT
369
            cmsFloat32Number alpha = ((cmsFloat32Number *)accum)[prealphaindexin];
370
 #else
371
            cmsUInt32Number alpha = inpackedsamplesize == 2 ?
372
                                     ((cmsUInt16Number *)accum)[prealphaindexin] :
373
                                     (accum[prealphaindexin]);
374
 #endif
375
            if (alpha == 0) {
376
                ZEROPACK(ContextID,p,output,accum);
377
                accum += inpackedsamplesize*(prealphaindexin+1);
378
            } else {
379
#endif
380
22.6M
                UNPACK(ContextID,p,currIn,accum,bppi,alpha);
381
#ifdef PREALPHA
382
 #ifndef UNPACKINCLUDESPREALPHA
383
  #ifdef XFORM_FLOAT
384
                {
385
                    int i;
386
                    cmsFloat32Number inva = 1.0f / alpha;
387
                    for (i = 0; i < numinchannels; i++)
388
                        currIn[i] *= inva;
389
                }
390
  #else
391
                {
392
                    int i;
393
                    cmsUInt32Number al = inpackedsamplesize == 1 ? alpha*0x101 : alpha;
394
                    cmsUInt32Number inva = 0xffff0000U / al;
395
                    for (i = 0; i < numinchannels; i++)
396
                        currIn[i] = ((currIn[i] * inva)>>16);
397
                }
398
  #endif
399
 #endif
400
#endif
401
22.6M
#ifdef CACHED
402
22.6M
                if (COMPARE(currIn, prevIn))
403
18.7M
#endif /* CACHED */
404
18.7M
                {
405
#ifdef GAMUTCHECK
406
 #ifdef XFORM_FLOAT
407
                    cmsFloat32Number OutOfGamut;
408
409
                    // Evaluate gamut marker.
410
                    cmsPipelineEvalFloat(currIn, &OutOfGamut, core->GamutCheck);
411
412
                    // Is current color out of gamut?
413
                    if (OutOfGamut > 0.0)
414
                        // Certainly, out of gamut
415
                        for (j=0; j < cmsMAXCHANNELS; j++)
416
                            fOut[j] = -1.0;
417
                    else
418
 #else
419
                    cmsUInt16Number wOutOfGamut;
420
421
                    evalGamut(ContextID, currIn, &wOutOfGamut, core->GamutCheck->Data);
422
                    if (wOutOfGamut >= 1)
423
                        /* RJW: Could be faster? copy once to a local buffer? */
424
                        cmsGetAlarmCodes(ContextID, wOut);
425
                    else
426
 #endif /* FLOAT_XFORM */
427
#endif /* GAMUTCHECK */
428
18.7M
                        eval(ContextID, currIn, wOut, data);
429
#ifdef NO_UNPACK
430
 #ifdef CACHED
431
                    prevIn = currIn;
432
 #endif
433
                    currIn = (XFORM_TYPE *)(((char *)currIn) + totalinbytes);
434
#else
435
18.7M
 #ifdef CACHED
436
18.7M
                    {XFORM_TYPE *tmp = currIn; currIn = prevIn; prevIn = tmp;} // SWAP
437
18.7M
 #endif /* CACHED */
438
18.7M
#endif /* NO_UNPACK */
439
18.7M
                }
440
#ifdef NO_PACK
441
                else
442
                    COPY_MATCHED(prevOut,wOut);
443
                prevOut = wOut;
444
#endif
445
#ifdef PREALPHA
446
 #ifndef PACKINCLUDESPREALPHA
447
  #ifdef XFORM_FLOAT
448
                {
449
                    int i;
450
                    for (i = 0; i < numoutchannels; i++)
451
                        wScaled = wOut[i] * alpha;
452
                }
453
  #else
454
                {
455
                    int i;
456
                    cmsUInt32Number al = inpackedsamplesize == 1 ? alpha*0x101 : alpha;
457
                    for (i = 0; i < numoutchannels; i++)
458
                        wScaled[i] = mul65535(wOut[i],al);
459
                }
460
  #endif
461
                PACK(ContextID,p,wScaled,output,bppo,alpha);
462
 #else
463
                PACK(ContextID,p,wOut,output,bppo,alpha);
464
 #endif
465
#else
466
22.6M
                PACK(ContextID,p,wOut,output,bppo,alpha);
467
22.6M
#endif
468
22.6M
                COPY_EXTRAS(p,accum,output);
469
#ifdef PREALPHA
470
            }
471
#endif
472
22.6M
        } /* End x loop */
473
22.6M
        in = (void *)((cmsUInt8Number *)in + Stride->BytesPerLineIn);
474
22.6M
        out = (void *)((cmsUInt8Number *)out + Stride->BytesPerLineOut);
475
22.6M
    } /* End y loop */
476
    /* The following code is only safe if we know that a given transform is
477
     * called on one thread a time. */
478
#if 0
479
#ifdef CACHED
480
#ifdef NO_UNPACK
481
    memcpy(p->Cache.CacheIn,prevIn, CMPBYTES);
482
#else
483
    memcpy(p->Cache.CacheIn, prevIn, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
484
#endif
485
#ifdef NO_PACK
486
    COPY_MATCHED(prevOut,p->Cache.CacheOut);
487
#else
488
    memcpy(p->Cache.CacheOut, wOut, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
489
#endif /* NO_PACK */
490
#endif /* CACHED */
491
#endif
492
22.6M
}
cmsxform.c:CachedXFORM1to4
Line
Count
Source
255
207
{
256
207
    _cmsTRANSFORMCORE *core = p->core;
257
207
#ifndef NO_UNPACK
258
 #ifdef XFORM_FLOAT
259
    cmsFloat32Number wIn[cmsMAXCHANNELS*2];
260
 #else
261
207
    cmsUInt16Number wIn[cmsMAXCHANNELS*2];
262
207
 #endif
263
207
 #define wIn0 (&wIn[0])
264
207
 #define wIn1 (&wIn[cmsMAXCHANNELS])
265
207
#endif
266
207
    XFORM_TYPE *currIn;
267
207
#ifdef CACHED
268
207
    XFORM_TYPE *prevIn;
269
207
#endif /* CACHED */
270
#ifdef NO_PACK
271
    XFORM_TYPE *wOut = (XFORM_TYPE *)out;
272
    XFORM_TYPE *prevOut = (XFORM_TYPE *)p->Cache.CacheOut;
273
#else
274
207
    XFORM_TYPE wOut[cmsMAXCHANNELS];
275
207
#endif
276
#if defined(PREALPHA) && !defined(PACKINCLUDESPREALPHA)
277
    XFORM_TYPE wScaled[cmsMAXCHANNELS];
278
#endif
279
#ifdef GAMUTCHECK
280
    _cmsPipelineEval16Fn evalGamut = core->GamutCheck->Eval16Fn;
281
#endif /* GAMUTCHECK */
282
#ifdef XFORM_FLOAT
283
    _cmsPipelineEvalFloatFn eval = core->Lut->EvalFloatFn;
284
    const cmsPipeline *data = core->Lut;
285
#else
286
207
    _cmsPipelineEval16Fn eval = core->Lut->Eval16Fn;
287
207
    void *data = core->Lut->Data;
288
207
#endif
289
207
    cmsUInt32Number bppi = Stride->BytesPerPlaneIn;
290
207
    cmsUInt32Number bppo = Stride->BytesPerPlaneOut;
291
207
#ifdef NUMINCHANNELS
292
207
    int numinchannels = NUMINCHANNELS;
293
#else
294
    int numinchannels = T_CHANNELS(p->InputFormat);
295
#endif
296
207
#ifdef NUMOUTCHANNELS
297
207
    int numoutchannels = NUMOUTCHANNELS;
298
#else
299
    int numoutchannels = T_CHANNELS(p->OutputFormat);
300
#endif
301
207
#ifdef NUMEXTRAS
302
207
    int numextras = NUMEXTRAS;
303
#else
304
    int numextras = T_EXTRA(p->InputFormat);
305
#endif
306
207
#ifdef INPACKEDSAMPLESIZE
307
207
    int inpackedsamplesize = INPACKEDSAMPLESIZE;
308
#else
309
    int inpackedsamplesize = T_BYTES(p->InputFormat);
310
#endif
311
207
#ifdef OUTPACKEDSAMPLESIZE
312
207
    int outpackedsamplesize = OUTPACKEDSAMPLESIZE;
313
#else
314
    int outpackedsamplesize = T_BYTES(p->OutputFormat);
315
#endif
316
207
    int prealphaindexin = numinchannels + numextras - 1;
317
207
    int prealphaindexout = numoutchannels + numextras - 1;
318
207
    int totalinbytes = (numinchannels + numextras)*inpackedsamplesize;
319
207
    int totaloutbytes = (numoutchannels + numextras)*outpackedsamplesize;
320
321
    /* Silence some warnings */
322
207
    (void)bppi;
323
207
    (void)bppo;
324
207
    (void)prealphaindexin;
325
207
    (void)numextras;
326
207
    (void)prealphaindexout;
327
207
    (void)inpackedsamplesize;
328
207
    (void)outpackedsamplesize;
329
207
    (void)totalinbytes;
330
207
    (void)totaloutbytes;
331
332
#ifdef BULK_COPY_EXTRAS
333
    if (core->dwOriginalFlags & cmsFLAGS_COPY_ALPHA)
334
        _cmsHandleExtraChannels(ContextID, p, in, out, PixelsPerLine, LineCount, Stride);
335
#endif
336
337
207
    if (PixelsPerLine == 0)
338
0
        return;
339
340
#ifdef NO_UNPACK
341
    prevIn = (XFORM_TYPE *)p->Cache.CacheIn;
342
#else
343
207
 #ifdef CACHED
344
    // Empty buffers for quick memcmp
345
207
    memset(wIn1, 0, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
346
347
    // Get copy of zero cache
348
207
    memcpy(wIn0, p->Cache.CacheIn,  sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
349
207
    memcpy(wOut, p->Cache.CacheOut, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
350
351
    // The caller guarantees us that the cache is always valid on entry; if
352
    // the representation is changed, the cache is reset.
353
207
    prevIn = wIn0;
354
207
 #endif /* CACHED */
355
207
    currIn = wIn1;
356
207
#endif
357
358
414
    while (LineCount-- > 0)
359
207
    {
360
207
        cmsUInt32Number n = PixelsPerLine;
361
207
        cmsUInt8Number* accum  = (cmsUInt8Number*) in;
362
207
        cmsUInt8Number* output = (cmsUInt8Number*) out;
363
#ifdef NO_UNPACK
364
        currIn = (XFORM_TYPE *)accum;
365
#endif
366
53.1k
        while (n-- > 0) { // prevIn == CacheIn, wOut = CacheOut
367
#ifdef PREALPHA
368
 #ifdef XFORM_FLOAT
369
            cmsFloat32Number alpha = ((cmsFloat32Number *)accum)[prealphaindexin];
370
 #else
371
            cmsUInt32Number alpha = inpackedsamplesize == 2 ?
372
                                     ((cmsUInt16Number *)accum)[prealphaindexin] :
373
                                     (accum[prealphaindexin]);
374
 #endif
375
            if (alpha == 0) {
376
                ZEROPACK(ContextID,p,output,accum);
377
                accum += inpackedsamplesize*(prealphaindexin+1);
378
            } else {
379
#endif
380
52.9k
                UNPACK(ContextID,p,currIn,accum,bppi,alpha);
381
#ifdef PREALPHA
382
 #ifndef UNPACKINCLUDESPREALPHA
383
  #ifdef XFORM_FLOAT
384
                {
385
                    int i;
386
                    cmsFloat32Number inva = 1.0f / alpha;
387
                    for (i = 0; i < numinchannels; i++)
388
                        currIn[i] *= inva;
389
                }
390
  #else
391
                {
392
                    int i;
393
                    cmsUInt32Number al = inpackedsamplesize == 1 ? alpha*0x101 : alpha;
394
                    cmsUInt32Number inva = 0xffff0000U / al;
395
                    for (i = 0; i < numinchannels; i++)
396
                        currIn[i] = ((currIn[i] * inva)>>16);
397
                }
398
  #endif
399
 #endif
400
#endif
401
52.9k
#ifdef CACHED
402
52.9k
                if (COMPARE(currIn, prevIn))
403
52.7k
#endif /* CACHED */
404
52.7k
                {
405
#ifdef GAMUTCHECK
406
 #ifdef XFORM_FLOAT
407
                    cmsFloat32Number OutOfGamut;
408
409
                    // Evaluate gamut marker.
410
                    cmsPipelineEvalFloat(currIn, &OutOfGamut, core->GamutCheck);
411
412
                    // Is current color out of gamut?
413
                    if (OutOfGamut > 0.0)
414
                        // Certainly, out of gamut
415
                        for (j=0; j < cmsMAXCHANNELS; j++)
416
                            fOut[j] = -1.0;
417
                    else
418
 #else
419
                    cmsUInt16Number wOutOfGamut;
420
421
                    evalGamut(ContextID, currIn, &wOutOfGamut, core->GamutCheck->Data);
422
                    if (wOutOfGamut >= 1)
423
                        /* RJW: Could be faster? copy once to a local buffer? */
424
                        cmsGetAlarmCodes(ContextID, wOut);
425
                    else
426
 #endif /* FLOAT_XFORM */
427
#endif /* GAMUTCHECK */
428
52.7k
                        eval(ContextID, currIn, wOut, data);
429
#ifdef NO_UNPACK
430
 #ifdef CACHED
431
                    prevIn = currIn;
432
 #endif
433
                    currIn = (XFORM_TYPE *)(((char *)currIn) + totalinbytes);
434
#else
435
52.7k
 #ifdef CACHED
436
52.7k
                    {XFORM_TYPE *tmp = currIn; currIn = prevIn; prevIn = tmp;} // SWAP
437
52.7k
 #endif /* CACHED */
438
52.7k
#endif /* NO_UNPACK */
439
52.7k
                }
440
#ifdef NO_PACK
441
                else
442
                    COPY_MATCHED(prevOut,wOut);
443
                prevOut = wOut;
444
#endif
445
#ifdef PREALPHA
446
 #ifndef PACKINCLUDESPREALPHA
447
  #ifdef XFORM_FLOAT
448
                {
449
                    int i;
450
                    for (i = 0; i < numoutchannels; i++)
451
                        wScaled = wOut[i] * alpha;
452
                }
453
  #else
454
                {
455
                    int i;
456
                    cmsUInt32Number al = inpackedsamplesize == 1 ? alpha*0x101 : alpha;
457
                    for (i = 0; i < numoutchannels; i++)
458
                        wScaled[i] = mul65535(wOut[i],al);
459
                }
460
  #endif
461
                PACK(ContextID,p,wScaled,output,bppo,alpha);
462
 #else
463
                PACK(ContextID,p,wOut,output,bppo,alpha);
464
 #endif
465
#else
466
52.9k
                PACK(ContextID,p,wOut,output,bppo,alpha);
467
52.9k
#endif
468
52.9k
                COPY_EXTRAS(p,accum,output);
469
#ifdef PREALPHA
470
            }
471
#endif
472
52.9k
        } /* End x loop */
473
207
        in = (void *)((cmsUInt8Number *)in + Stride->BytesPerLineIn);
474
207
        out = (void *)((cmsUInt8Number *)out + Stride->BytesPerLineOut);
475
207
    } /* End y loop */
476
    /* The following code is only safe if we know that a given transform is
477
     * called on one thread a time. */
478
#if 0
479
#ifdef CACHED
480
#ifdef NO_UNPACK
481
    memcpy(p->Cache.CacheIn,prevIn, CMPBYTES);
482
#else
483
    memcpy(p->Cache.CacheIn, prevIn, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
484
#endif
485
#ifdef NO_PACK
486
    COPY_MATCHED(prevOut,p->Cache.CacheOut);
487
#else
488
    memcpy(p->Cache.CacheOut, wOut, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
489
#endif /* NO_PACK */
490
#endif /* CACHED */
491
#endif
492
207
}
cmsxform.c:CachedXFORM1x2to4x2
Line
Count
Source
255
790k
{
256
790k
    _cmsTRANSFORMCORE *core = p->core;
257
790k
#ifndef NO_UNPACK
258
 #ifdef XFORM_FLOAT
259
    cmsFloat32Number wIn[cmsMAXCHANNELS*2];
260
 #else
261
790k
    cmsUInt16Number wIn[cmsMAXCHANNELS*2];
262
790k
 #endif
263
790k
 #define wIn0 (&wIn[0])
264
790k
 #define wIn1 (&wIn[cmsMAXCHANNELS])
265
790k
#endif
266
790k
    XFORM_TYPE *currIn;
267
790k
#ifdef CACHED
268
790k
    XFORM_TYPE *prevIn;
269
790k
#endif /* CACHED */
270
#ifdef NO_PACK
271
    XFORM_TYPE *wOut = (XFORM_TYPE *)out;
272
    XFORM_TYPE *prevOut = (XFORM_TYPE *)p->Cache.CacheOut;
273
#else
274
790k
    XFORM_TYPE wOut[cmsMAXCHANNELS];
275
790k
#endif
276
#if defined(PREALPHA) && !defined(PACKINCLUDESPREALPHA)
277
    XFORM_TYPE wScaled[cmsMAXCHANNELS];
278
#endif
279
#ifdef GAMUTCHECK
280
    _cmsPipelineEval16Fn evalGamut = core->GamutCheck->Eval16Fn;
281
#endif /* GAMUTCHECK */
282
#ifdef XFORM_FLOAT
283
    _cmsPipelineEvalFloatFn eval = core->Lut->EvalFloatFn;
284
    const cmsPipeline *data = core->Lut;
285
#else
286
790k
    _cmsPipelineEval16Fn eval = core->Lut->Eval16Fn;
287
790k
    void *data = core->Lut->Data;
288
790k
#endif
289
790k
    cmsUInt32Number bppi = Stride->BytesPerPlaneIn;
290
790k
    cmsUInt32Number bppo = Stride->BytesPerPlaneOut;
291
790k
#ifdef NUMINCHANNELS
292
790k
    int numinchannels = NUMINCHANNELS;
293
#else
294
    int numinchannels = T_CHANNELS(p->InputFormat);
295
#endif
296
790k
#ifdef NUMOUTCHANNELS
297
790k
    int numoutchannels = NUMOUTCHANNELS;
298
#else
299
    int numoutchannels = T_CHANNELS(p->OutputFormat);
300
#endif
301
790k
#ifdef NUMEXTRAS
302
790k
    int numextras = NUMEXTRAS;
303
#else
304
    int numextras = T_EXTRA(p->InputFormat);
305
#endif
306
790k
#ifdef INPACKEDSAMPLESIZE
307
790k
    int inpackedsamplesize = INPACKEDSAMPLESIZE;
308
#else
309
    int inpackedsamplesize = T_BYTES(p->InputFormat);
310
#endif
311
790k
#ifdef OUTPACKEDSAMPLESIZE
312
790k
    int outpackedsamplesize = OUTPACKEDSAMPLESIZE;
313
#else
314
    int outpackedsamplesize = T_BYTES(p->OutputFormat);
315
#endif
316
790k
    int prealphaindexin = numinchannels + numextras - 1;
317
790k
    int prealphaindexout = numoutchannels + numextras - 1;
318
790k
    int totalinbytes = (numinchannels + numextras)*inpackedsamplesize;
319
790k
    int totaloutbytes = (numoutchannels + numextras)*outpackedsamplesize;
320
321
    /* Silence some warnings */
322
790k
    (void)bppi;
323
790k
    (void)bppo;
324
790k
    (void)prealphaindexin;
325
790k
    (void)numextras;
326
790k
    (void)prealphaindexout;
327
790k
    (void)inpackedsamplesize;
328
790k
    (void)outpackedsamplesize;
329
790k
    (void)totalinbytes;
330
790k
    (void)totaloutbytes;
331
332
#ifdef BULK_COPY_EXTRAS
333
    if (core->dwOriginalFlags & cmsFLAGS_COPY_ALPHA)
334
        _cmsHandleExtraChannels(ContextID, p, in, out, PixelsPerLine, LineCount, Stride);
335
#endif
336
337
790k
    if (PixelsPerLine == 0)
338
0
        return;
339
340
#ifdef NO_UNPACK
341
    prevIn = (XFORM_TYPE *)p->Cache.CacheIn;
342
#else
343
790k
 #ifdef CACHED
344
    // Empty buffers for quick memcmp
345
790k
    memset(wIn1, 0, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
346
347
    // Get copy of zero cache
348
790k
    memcpy(wIn0, p->Cache.CacheIn,  sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
349
790k
    memcpy(wOut, p->Cache.CacheOut, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
350
351
    // The caller guarantees us that the cache is always valid on entry; if
352
    // the representation is changed, the cache is reset.
353
790k
    prevIn = wIn0;
354
790k
 #endif /* CACHED */
355
790k
    currIn = wIn1;
356
790k
#endif
357
358
1.58M
    while (LineCount-- > 0)
359
790k
    {
360
790k
        cmsUInt32Number n = PixelsPerLine;
361
790k
        cmsUInt8Number* accum  = (cmsUInt8Number*) in;
362
790k
        cmsUInt8Number* output = (cmsUInt8Number*) out;
363
#ifdef NO_UNPACK
364
        currIn = (XFORM_TYPE *)accum;
365
#endif
366
1.58M
        while (n-- > 0) { // prevIn == CacheIn, wOut = CacheOut
367
#ifdef PREALPHA
368
 #ifdef XFORM_FLOAT
369
            cmsFloat32Number alpha = ((cmsFloat32Number *)accum)[prealphaindexin];
370
 #else
371
            cmsUInt32Number alpha = inpackedsamplesize == 2 ?
372
                                     ((cmsUInt16Number *)accum)[prealphaindexin] :
373
                                     (accum[prealphaindexin]);
374
 #endif
375
            if (alpha == 0) {
376
                ZEROPACK(ContextID,p,output,accum);
377
                accum += inpackedsamplesize*(prealphaindexin+1);
378
            } else {
379
#endif
380
790k
                UNPACK(ContextID,p,currIn,accum,bppi,alpha);
381
#ifdef PREALPHA
382
 #ifndef UNPACKINCLUDESPREALPHA
383
  #ifdef XFORM_FLOAT
384
                {
385
                    int i;
386
                    cmsFloat32Number inva = 1.0f / alpha;
387
                    for (i = 0; i < numinchannels; i++)
388
                        currIn[i] *= inva;
389
                }
390
  #else
391
                {
392
                    int i;
393
                    cmsUInt32Number al = inpackedsamplesize == 1 ? alpha*0x101 : alpha;
394
                    cmsUInt32Number inva = 0xffff0000U / al;
395
                    for (i = 0; i < numinchannels; i++)
396
                        currIn[i] = ((currIn[i] * inva)>>16);
397
                }
398
  #endif
399
 #endif
400
#endif
401
790k
#ifdef CACHED
402
790k
                if (COMPARE(currIn, prevIn))
403
192k
#endif /* CACHED */
404
192k
                {
405
#ifdef GAMUTCHECK
406
 #ifdef XFORM_FLOAT
407
                    cmsFloat32Number OutOfGamut;
408
409
                    // Evaluate gamut marker.
410
                    cmsPipelineEvalFloat(currIn, &OutOfGamut, core->GamutCheck);
411
412
                    // Is current color out of gamut?
413
                    if (OutOfGamut > 0.0)
414
                        // Certainly, out of gamut
415
                        for (j=0; j < cmsMAXCHANNELS; j++)
416
                            fOut[j] = -1.0;
417
                    else
418
 #else
419
                    cmsUInt16Number wOutOfGamut;
420
421
                    evalGamut(ContextID, currIn, &wOutOfGamut, core->GamutCheck->Data);
422
                    if (wOutOfGamut >= 1)
423
                        /* RJW: Could be faster? copy once to a local buffer? */
424
                        cmsGetAlarmCodes(ContextID, wOut);
425
                    else
426
 #endif /* FLOAT_XFORM */
427
#endif /* GAMUTCHECK */
428
192k
                        eval(ContextID, currIn, wOut, data);
429
#ifdef NO_UNPACK
430
 #ifdef CACHED
431
                    prevIn = currIn;
432
 #endif
433
                    currIn = (XFORM_TYPE *)(((char *)currIn) + totalinbytes);
434
#else
435
192k
 #ifdef CACHED
436
192k
                    {XFORM_TYPE *tmp = currIn; currIn = prevIn; prevIn = tmp;} // SWAP
437
192k
 #endif /* CACHED */
438
192k
#endif /* NO_UNPACK */
439
192k
                }
440
#ifdef NO_PACK
441
                else
442
                    COPY_MATCHED(prevOut,wOut);
443
                prevOut = wOut;
444
#endif
445
#ifdef PREALPHA
446
 #ifndef PACKINCLUDESPREALPHA
447
  #ifdef XFORM_FLOAT
448
                {
449
                    int i;
450
                    for (i = 0; i < numoutchannels; i++)
451
                        wScaled = wOut[i] * alpha;
452
                }
453
  #else
454
                {
455
                    int i;
456
                    cmsUInt32Number al = inpackedsamplesize == 1 ? alpha*0x101 : alpha;
457
                    for (i = 0; i < numoutchannels; i++)
458
                        wScaled[i] = mul65535(wOut[i],al);
459
                }
460
  #endif
461
                PACK(ContextID,p,wScaled,output,bppo,alpha);
462
 #else
463
                PACK(ContextID,p,wOut,output,bppo,alpha);
464
 #endif
465
#else
466
790k
                PACK(ContextID,p,wOut,output,bppo,alpha);
467
790k
#endif
468
790k
                COPY_EXTRAS(p,accum,output);
469
#ifdef PREALPHA
470
            }
471
#endif
472
790k
        } /* End x loop */
473
790k
        in = (void *)((cmsUInt8Number *)in + Stride->BytesPerLineIn);
474
790k
        out = (void *)((cmsUInt8Number *)out + Stride->BytesPerLineOut);
475
790k
    } /* End y loop */
476
    /* The following code is only safe if we know that a given transform is
477
     * called on one thread a time. */
478
#if 0
479
#ifdef CACHED
480
#ifdef NO_UNPACK
481
    memcpy(p->Cache.CacheIn,prevIn, CMPBYTES);
482
#else
483
    memcpy(p->Cache.CacheIn, prevIn, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
484
#endif
485
#ifdef NO_PACK
486
    COPY_MATCHED(prevOut,p->Cache.CacheOut);
487
#else
488
    memcpy(p->Cache.CacheOut, wOut, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
489
#endif /* NO_PACK */
490
#endif /* CACHED */
491
#endif
492
790k
}
cmsxform.c:CachedXFORM3to1
Line
Count
Source
255
1.53M
{
256
1.53M
    _cmsTRANSFORMCORE *core = p->core;
257
1.53M
#ifndef NO_UNPACK
258
 #ifdef XFORM_FLOAT
259
    cmsFloat32Number wIn[cmsMAXCHANNELS*2];
260
 #else
261
1.53M
    cmsUInt16Number wIn[cmsMAXCHANNELS*2];
262
1.53M
 #endif
263
1.53M
 #define wIn0 (&wIn[0])
264
1.53M
 #define wIn1 (&wIn[cmsMAXCHANNELS])
265
1.53M
#endif
266
1.53M
    XFORM_TYPE *currIn;
267
1.53M
#ifdef CACHED
268
1.53M
    XFORM_TYPE *prevIn;
269
1.53M
#endif /* CACHED */
270
#ifdef NO_PACK
271
    XFORM_TYPE *wOut = (XFORM_TYPE *)out;
272
    XFORM_TYPE *prevOut = (XFORM_TYPE *)p->Cache.CacheOut;
273
#else
274
1.53M
    XFORM_TYPE wOut[cmsMAXCHANNELS];
275
1.53M
#endif
276
#if defined(PREALPHA) && !defined(PACKINCLUDESPREALPHA)
277
    XFORM_TYPE wScaled[cmsMAXCHANNELS];
278
#endif
279
#ifdef GAMUTCHECK
280
    _cmsPipelineEval16Fn evalGamut = core->GamutCheck->Eval16Fn;
281
#endif /* GAMUTCHECK */
282
#ifdef XFORM_FLOAT
283
    _cmsPipelineEvalFloatFn eval = core->Lut->EvalFloatFn;
284
    const cmsPipeline *data = core->Lut;
285
#else
286
1.53M
    _cmsPipelineEval16Fn eval = core->Lut->Eval16Fn;
287
1.53M
    void *data = core->Lut->Data;
288
1.53M
#endif
289
1.53M
    cmsUInt32Number bppi = Stride->BytesPerPlaneIn;
290
1.53M
    cmsUInt32Number bppo = Stride->BytesPerPlaneOut;
291
1.53M
#ifdef NUMINCHANNELS
292
1.53M
    int numinchannels = NUMINCHANNELS;
293
#else
294
    int numinchannels = T_CHANNELS(p->InputFormat);
295
#endif
296
1.53M
#ifdef NUMOUTCHANNELS
297
1.53M
    int numoutchannels = NUMOUTCHANNELS;
298
#else
299
    int numoutchannels = T_CHANNELS(p->OutputFormat);
300
#endif
301
1.53M
#ifdef NUMEXTRAS
302
1.53M
    int numextras = NUMEXTRAS;
303
#else
304
    int numextras = T_EXTRA(p->InputFormat);
305
#endif
306
1.53M
#ifdef INPACKEDSAMPLESIZE
307
1.53M
    int inpackedsamplesize = INPACKEDSAMPLESIZE;
308
#else
309
    int inpackedsamplesize = T_BYTES(p->InputFormat);
310
#endif
311
1.53M
#ifdef OUTPACKEDSAMPLESIZE
312
1.53M
    int outpackedsamplesize = OUTPACKEDSAMPLESIZE;
313
#else
314
    int outpackedsamplesize = T_BYTES(p->OutputFormat);
315
#endif
316
1.53M
    int prealphaindexin = numinchannels + numextras - 1;
317
1.53M
    int prealphaindexout = numoutchannels + numextras - 1;
318
1.53M
    int totalinbytes = (numinchannels + numextras)*inpackedsamplesize;
319
1.53M
    int totaloutbytes = (numoutchannels + numextras)*outpackedsamplesize;
320
321
    /* Silence some warnings */
322
1.53M
    (void)bppi;
323
1.53M
    (void)bppo;
324
1.53M
    (void)prealphaindexin;
325
1.53M
    (void)numextras;
326
1.53M
    (void)prealphaindexout;
327
1.53M
    (void)inpackedsamplesize;
328
1.53M
    (void)outpackedsamplesize;
329
1.53M
    (void)totalinbytes;
330
1.53M
    (void)totaloutbytes;
331
332
#ifdef BULK_COPY_EXTRAS
333
    if (core->dwOriginalFlags & cmsFLAGS_COPY_ALPHA)
334
        _cmsHandleExtraChannels(ContextID, p, in, out, PixelsPerLine, LineCount, Stride);
335
#endif
336
337
1.53M
    if (PixelsPerLine == 0)
338
0
        return;
339
340
#ifdef NO_UNPACK
341
    prevIn = (XFORM_TYPE *)p->Cache.CacheIn;
342
#else
343
1.53M
 #ifdef CACHED
344
    // Empty buffers for quick memcmp
345
1.53M
    memset(wIn1, 0, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
346
347
    // Get copy of zero cache
348
1.53M
    memcpy(wIn0, p->Cache.CacheIn,  sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
349
1.53M
    memcpy(wOut, p->Cache.CacheOut, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
350
351
    // The caller guarantees us that the cache is always valid on entry; if
352
    // the representation is changed, the cache is reset.
353
1.53M
    prevIn = wIn0;
354
1.53M
 #endif /* CACHED */
355
1.53M
    currIn = wIn1;
356
1.53M
#endif
357
358
3.06M
    while (LineCount-- > 0)
359
1.53M
    {
360
1.53M
        cmsUInt32Number n = PixelsPerLine;
361
1.53M
        cmsUInt8Number* accum  = (cmsUInt8Number*) in;
362
1.53M
        cmsUInt8Number* output = (cmsUInt8Number*) out;
363
#ifdef NO_UNPACK
364
        currIn = (XFORM_TYPE *)accum;
365
#endif
366
1.28G
        while (n-- > 0) { // prevIn == CacheIn, wOut = CacheOut
367
#ifdef PREALPHA
368
 #ifdef XFORM_FLOAT
369
            cmsFloat32Number alpha = ((cmsFloat32Number *)accum)[prealphaindexin];
370
 #else
371
            cmsUInt32Number alpha = inpackedsamplesize == 2 ?
372
                                     ((cmsUInt16Number *)accum)[prealphaindexin] :
373
                                     (accum[prealphaindexin]);
374
 #endif
375
            if (alpha == 0) {
376
                ZEROPACK(ContextID,p,output,accum);
377
                accum += inpackedsamplesize*(prealphaindexin+1);
378
            } else {
379
#endif
380
1.28G
                UNPACK(ContextID,p,currIn,accum,bppi,alpha);
381
#ifdef PREALPHA
382
 #ifndef UNPACKINCLUDESPREALPHA
383
  #ifdef XFORM_FLOAT
384
                {
385
                    int i;
386
                    cmsFloat32Number inva = 1.0f / alpha;
387
                    for (i = 0; i < numinchannels; i++)
388
                        currIn[i] *= inva;
389
                }
390
  #else
391
                {
392
                    int i;
393
                    cmsUInt32Number al = inpackedsamplesize == 1 ? alpha*0x101 : alpha;
394
                    cmsUInt32Number inva = 0xffff0000U / al;
395
                    for (i = 0; i < numinchannels; i++)
396
                        currIn[i] = ((currIn[i] * inva)>>16);
397
                }
398
  #endif
399
 #endif
400
#endif
401
1.28G
#ifdef CACHED
402
1.28G
                if (COMPARE(currIn, prevIn))
403
150M
#endif /* CACHED */
404
150M
                {
405
#ifdef GAMUTCHECK
406
 #ifdef XFORM_FLOAT
407
                    cmsFloat32Number OutOfGamut;
408
409
                    // Evaluate gamut marker.
410
                    cmsPipelineEvalFloat(currIn, &OutOfGamut, core->GamutCheck);
411
412
                    // Is current color out of gamut?
413
                    if (OutOfGamut > 0.0)
414
                        // Certainly, out of gamut
415
                        for (j=0; j < cmsMAXCHANNELS; j++)
416
                            fOut[j] = -1.0;
417
                    else
418
 #else
419
                    cmsUInt16Number wOutOfGamut;
420
421
                    evalGamut(ContextID, currIn, &wOutOfGamut, core->GamutCheck->Data);
422
                    if (wOutOfGamut >= 1)
423
                        /* RJW: Could be faster? copy once to a local buffer? */
424
                        cmsGetAlarmCodes(ContextID, wOut);
425
                    else
426
 #endif /* FLOAT_XFORM */
427
#endif /* GAMUTCHECK */
428
150M
                        eval(ContextID, currIn, wOut, data);
429
#ifdef NO_UNPACK
430
 #ifdef CACHED
431
                    prevIn = currIn;
432
 #endif
433
                    currIn = (XFORM_TYPE *)(((char *)currIn) + totalinbytes);
434
#else
435
150M
 #ifdef CACHED
436
150M
                    {XFORM_TYPE *tmp = currIn; currIn = prevIn; prevIn = tmp;} // SWAP
437
150M
 #endif /* CACHED */
438
150M
#endif /* NO_UNPACK */
439
150M
                }
440
#ifdef NO_PACK
441
                else
442
                    COPY_MATCHED(prevOut,wOut);
443
                prevOut = wOut;
444
#endif
445
#ifdef PREALPHA
446
 #ifndef PACKINCLUDESPREALPHA
447
  #ifdef XFORM_FLOAT
448
                {
449
                    int i;
450
                    for (i = 0; i < numoutchannels; i++)
451
                        wScaled = wOut[i] * alpha;
452
                }
453
  #else
454
                {
455
                    int i;
456
                    cmsUInt32Number al = inpackedsamplesize == 1 ? alpha*0x101 : alpha;
457
                    for (i = 0; i < numoutchannels; i++)
458
                        wScaled[i] = mul65535(wOut[i],al);
459
                }
460
  #endif
461
                PACK(ContextID,p,wScaled,output,bppo,alpha);
462
 #else
463
                PACK(ContextID,p,wOut,output,bppo,alpha);
464
 #endif
465
#else
466
1.28G
                PACK(ContextID,p,wOut,output,bppo,alpha);
467
1.28G
#endif
468
1.28G
                COPY_EXTRAS(p,accum,output);
469
#ifdef PREALPHA
470
            }
471
#endif
472
1.28G
        } /* End x loop */
473
1.53M
        in = (void *)((cmsUInt8Number *)in + Stride->BytesPerLineIn);
474
1.53M
        out = (void *)((cmsUInt8Number *)out + Stride->BytesPerLineOut);
475
1.53M
    } /* End y loop */
476
    /* The following code is only safe if we know that a given transform is
477
     * called on one thread a time. */
478
#if 0
479
#ifdef CACHED
480
#ifdef NO_UNPACK
481
    memcpy(p->Cache.CacheIn,prevIn, CMPBYTES);
482
#else
483
    memcpy(p->Cache.CacheIn, prevIn, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
484
#endif
485
#ifdef NO_PACK
486
    COPY_MATCHED(prevOut,p->Cache.CacheOut);
487
#else
488
    memcpy(p->Cache.CacheOut, wOut, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
489
#endif /* NO_PACK */
490
#endif /* CACHED */
491
#endif
492
1.53M
}
cmsxform.c:CachedXFORM3x2to1x2
Line
Count
Source
255
12.8M
{
256
12.8M
    _cmsTRANSFORMCORE *core = p->core;
257
12.8M
#ifndef NO_UNPACK
258
 #ifdef XFORM_FLOAT
259
    cmsFloat32Number wIn[cmsMAXCHANNELS*2];
260
 #else
261
12.8M
    cmsUInt16Number wIn[cmsMAXCHANNELS*2];
262
12.8M
 #endif
263
12.8M
 #define wIn0 (&wIn[0])
264
12.8M
 #define wIn1 (&wIn[cmsMAXCHANNELS])
265
12.8M
#endif
266
12.8M
    XFORM_TYPE *currIn;
267
12.8M
#ifdef CACHED
268
12.8M
    XFORM_TYPE *prevIn;
269
12.8M
#endif /* CACHED */
270
#ifdef NO_PACK
271
    XFORM_TYPE *wOut = (XFORM_TYPE *)out;
272
    XFORM_TYPE *prevOut = (XFORM_TYPE *)p->Cache.CacheOut;
273
#else
274
12.8M
    XFORM_TYPE wOut[cmsMAXCHANNELS];
275
12.8M
#endif
276
#if defined(PREALPHA) && !defined(PACKINCLUDESPREALPHA)
277
    XFORM_TYPE wScaled[cmsMAXCHANNELS];
278
#endif
279
#ifdef GAMUTCHECK
280
    _cmsPipelineEval16Fn evalGamut = core->GamutCheck->Eval16Fn;
281
#endif /* GAMUTCHECK */
282
#ifdef XFORM_FLOAT
283
    _cmsPipelineEvalFloatFn eval = core->Lut->EvalFloatFn;
284
    const cmsPipeline *data = core->Lut;
285
#else
286
12.8M
    _cmsPipelineEval16Fn eval = core->Lut->Eval16Fn;
287
12.8M
    void *data = core->Lut->Data;
288
12.8M
#endif
289
12.8M
    cmsUInt32Number bppi = Stride->BytesPerPlaneIn;
290
12.8M
    cmsUInt32Number bppo = Stride->BytesPerPlaneOut;
291
12.8M
#ifdef NUMINCHANNELS
292
12.8M
    int numinchannels = NUMINCHANNELS;
293
#else
294
    int numinchannels = T_CHANNELS(p->InputFormat);
295
#endif
296
12.8M
#ifdef NUMOUTCHANNELS
297
12.8M
    int numoutchannels = NUMOUTCHANNELS;
298
#else
299
    int numoutchannels = T_CHANNELS(p->OutputFormat);
300
#endif
301
12.8M
#ifdef NUMEXTRAS
302
12.8M
    int numextras = NUMEXTRAS;
303
#else
304
    int numextras = T_EXTRA(p->InputFormat);
305
#endif
306
12.8M
#ifdef INPACKEDSAMPLESIZE
307
12.8M
    int inpackedsamplesize = INPACKEDSAMPLESIZE;
308
#else
309
    int inpackedsamplesize = T_BYTES(p->InputFormat);
310
#endif
311
12.8M
#ifdef OUTPACKEDSAMPLESIZE
312
12.8M
    int outpackedsamplesize = OUTPACKEDSAMPLESIZE;
313
#else
314
    int outpackedsamplesize = T_BYTES(p->OutputFormat);
315
#endif
316
12.8M
    int prealphaindexin = numinchannels + numextras - 1;
317
12.8M
    int prealphaindexout = numoutchannels + numextras - 1;
318
12.8M
    int totalinbytes = (numinchannels + numextras)*inpackedsamplesize;
319
12.8M
    int totaloutbytes = (numoutchannels + numextras)*outpackedsamplesize;
320
321
    /* Silence some warnings */
322
12.8M
    (void)bppi;
323
12.8M
    (void)bppo;
324
12.8M
    (void)prealphaindexin;
325
12.8M
    (void)numextras;
326
12.8M
    (void)prealphaindexout;
327
12.8M
    (void)inpackedsamplesize;
328
12.8M
    (void)outpackedsamplesize;
329
12.8M
    (void)totalinbytes;
330
12.8M
    (void)totaloutbytes;
331
332
#ifdef BULK_COPY_EXTRAS
333
    if (core->dwOriginalFlags & cmsFLAGS_COPY_ALPHA)
334
        _cmsHandleExtraChannels(ContextID, p, in, out, PixelsPerLine, LineCount, Stride);
335
#endif
336
337
12.8M
    if (PixelsPerLine == 0)
338
0
        return;
339
340
#ifdef NO_UNPACK
341
    prevIn = (XFORM_TYPE *)p->Cache.CacheIn;
342
#else
343
12.8M
 #ifdef CACHED
344
    // Empty buffers for quick memcmp
345
12.8M
    memset(wIn1, 0, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
346
347
    // Get copy of zero cache
348
12.8M
    memcpy(wIn0, p->Cache.CacheIn,  sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
349
12.8M
    memcpy(wOut, p->Cache.CacheOut, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
350
351
    // The caller guarantees us that the cache is always valid on entry; if
352
    // the representation is changed, the cache is reset.
353
12.8M
    prevIn = wIn0;
354
12.8M
 #endif /* CACHED */
355
12.8M
    currIn = wIn1;
356
12.8M
#endif
357
358
25.6M
    while (LineCount-- > 0)
359
12.8M
    {
360
12.8M
        cmsUInt32Number n = PixelsPerLine;
361
12.8M
        cmsUInt8Number* accum  = (cmsUInt8Number*) in;
362
12.8M
        cmsUInt8Number* output = (cmsUInt8Number*) out;
363
#ifdef NO_UNPACK
364
        currIn = (XFORM_TYPE *)accum;
365
#endif
366
25.6M
        while (n-- > 0) { // prevIn == CacheIn, wOut = CacheOut
367
#ifdef PREALPHA
368
 #ifdef XFORM_FLOAT
369
            cmsFloat32Number alpha = ((cmsFloat32Number *)accum)[prealphaindexin];
370
 #else
371
            cmsUInt32Number alpha = inpackedsamplesize == 2 ?
372
                                     ((cmsUInt16Number *)accum)[prealphaindexin] :
373
                                     (accum[prealphaindexin]);
374
 #endif
375
            if (alpha == 0) {
376
                ZEROPACK(ContextID,p,output,accum);
377
                accum += inpackedsamplesize*(prealphaindexin+1);
378
            } else {
379
#endif
380
12.8M
                UNPACK(ContextID,p,currIn,accum,bppi,alpha);
381
#ifdef PREALPHA
382
 #ifndef UNPACKINCLUDESPREALPHA
383
  #ifdef XFORM_FLOAT
384
                {
385
                    int i;
386
                    cmsFloat32Number inva = 1.0f / alpha;
387
                    for (i = 0; i < numinchannels; i++)
388
                        currIn[i] *= inva;
389
                }
390
  #else
391
                {
392
                    int i;
393
                    cmsUInt32Number al = inpackedsamplesize == 1 ? alpha*0x101 : alpha;
394
                    cmsUInt32Number inva = 0xffff0000U / al;
395
                    for (i = 0; i < numinchannels; i++)
396
                        currIn[i] = ((currIn[i] * inva)>>16);
397
                }
398
  #endif
399
 #endif
400
#endif
401
12.8M
#ifdef CACHED
402
12.8M
                if (COMPARE(currIn, prevIn))
403
12.1M
#endif /* CACHED */
404
12.1M
                {
405
#ifdef GAMUTCHECK
406
 #ifdef XFORM_FLOAT
407
                    cmsFloat32Number OutOfGamut;
408
409
                    // Evaluate gamut marker.
410
                    cmsPipelineEvalFloat(currIn, &OutOfGamut, core->GamutCheck);
411
412
                    // Is current color out of gamut?
413
                    if (OutOfGamut > 0.0)
414
                        // Certainly, out of gamut
415
                        for (j=0; j < cmsMAXCHANNELS; j++)
416
                            fOut[j] = -1.0;
417
                    else
418
 #else
419
                    cmsUInt16Number wOutOfGamut;
420
421
                    evalGamut(ContextID, currIn, &wOutOfGamut, core->GamutCheck->Data);
422
                    if (wOutOfGamut >= 1)
423
                        /* RJW: Could be faster? copy once to a local buffer? */
424
                        cmsGetAlarmCodes(ContextID, wOut);
425
                    else
426
 #endif /* FLOAT_XFORM */
427
#endif /* GAMUTCHECK */
428
12.1M
                        eval(ContextID, currIn, wOut, data);
429
#ifdef NO_UNPACK
430
 #ifdef CACHED
431
                    prevIn = currIn;
432
 #endif
433
                    currIn = (XFORM_TYPE *)(((char *)currIn) + totalinbytes);
434
#else
435
12.1M
 #ifdef CACHED
436
12.1M
                    {XFORM_TYPE *tmp = currIn; currIn = prevIn; prevIn = tmp;} // SWAP
437
12.1M
 #endif /* CACHED */
438
12.1M
#endif /* NO_UNPACK */
439
12.1M
                }
440
#ifdef NO_PACK
441
                else
442
                    COPY_MATCHED(prevOut,wOut);
443
                prevOut = wOut;
444
#endif
445
#ifdef PREALPHA
446
 #ifndef PACKINCLUDESPREALPHA
447
  #ifdef XFORM_FLOAT
448
                {
449
                    int i;
450
                    for (i = 0; i < numoutchannels; i++)
451
                        wScaled = wOut[i] * alpha;
452
                }
453
  #else
454
                {
455
                    int i;
456
                    cmsUInt32Number al = inpackedsamplesize == 1 ? alpha*0x101 : alpha;
457
                    for (i = 0; i < numoutchannels; i++)
458
                        wScaled[i] = mul65535(wOut[i],al);
459
                }
460
  #endif
461
                PACK(ContextID,p,wScaled,output,bppo,alpha);
462
 #else
463
                PACK(ContextID,p,wOut,output,bppo,alpha);
464
 #endif
465
#else
466
12.8M
                PACK(ContextID,p,wOut,output,bppo,alpha);
467
12.8M
#endif
468
12.8M
                COPY_EXTRAS(p,accum,output);
469
#ifdef PREALPHA
470
            }
471
#endif
472
12.8M
        } /* End x loop */
473
12.8M
        in = (void *)((cmsUInt8Number *)in + Stride->BytesPerLineIn);
474
12.8M
        out = (void *)((cmsUInt8Number *)out + Stride->BytesPerLineOut);
475
12.8M
    } /* End y loop */
476
    /* The following code is only safe if we know that a given transform is
477
     * called on one thread a time. */
478
#if 0
479
#ifdef CACHED
480
#ifdef NO_UNPACK
481
    memcpy(p->Cache.CacheIn,prevIn, CMPBYTES);
482
#else
483
    memcpy(p->Cache.CacheIn, prevIn, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
484
#endif
485
#ifdef NO_PACK
486
    COPY_MATCHED(prevOut,p->Cache.CacheOut);
487
#else
488
    memcpy(p->Cache.CacheOut, wOut, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
489
#endif /* NO_PACK */
490
#endif /* CACHED */
491
#endif
492
12.8M
}
cmsxform.c:CachedXFORM3to3
Line
Count
Source
255
150k
{
256
150k
    _cmsTRANSFORMCORE *core = p->core;
257
150k
#ifndef NO_UNPACK
258
 #ifdef XFORM_FLOAT
259
    cmsFloat32Number wIn[cmsMAXCHANNELS*2];
260
 #else
261
150k
    cmsUInt16Number wIn[cmsMAXCHANNELS*2];
262
150k
 #endif
263
150k
 #define wIn0 (&wIn[0])
264
150k
 #define wIn1 (&wIn[cmsMAXCHANNELS])
265
150k
#endif
266
150k
    XFORM_TYPE *currIn;
267
150k
#ifdef CACHED
268
150k
    XFORM_TYPE *prevIn;
269
150k
#endif /* CACHED */
270
#ifdef NO_PACK
271
    XFORM_TYPE *wOut = (XFORM_TYPE *)out;
272
    XFORM_TYPE *prevOut = (XFORM_TYPE *)p->Cache.CacheOut;
273
#else
274
150k
    XFORM_TYPE wOut[cmsMAXCHANNELS];
275
150k
#endif
276
#if defined(PREALPHA) && !defined(PACKINCLUDESPREALPHA)
277
    XFORM_TYPE wScaled[cmsMAXCHANNELS];
278
#endif
279
#ifdef GAMUTCHECK
280
    _cmsPipelineEval16Fn evalGamut = core->GamutCheck->Eval16Fn;
281
#endif /* GAMUTCHECK */
282
#ifdef XFORM_FLOAT
283
    _cmsPipelineEvalFloatFn eval = core->Lut->EvalFloatFn;
284
    const cmsPipeline *data = core->Lut;
285
#else
286
150k
    _cmsPipelineEval16Fn eval = core->Lut->Eval16Fn;
287
150k
    void *data = core->Lut->Data;
288
150k
#endif
289
150k
    cmsUInt32Number bppi = Stride->BytesPerPlaneIn;
290
150k
    cmsUInt32Number bppo = Stride->BytesPerPlaneOut;
291
150k
#ifdef NUMINCHANNELS
292
150k
    int numinchannels = NUMINCHANNELS;
293
#else
294
    int numinchannels = T_CHANNELS(p->InputFormat);
295
#endif
296
150k
#ifdef NUMOUTCHANNELS
297
150k
    int numoutchannels = NUMOUTCHANNELS;
298
#else
299
    int numoutchannels = T_CHANNELS(p->OutputFormat);
300
#endif
301
150k
#ifdef NUMEXTRAS
302
150k
    int numextras = NUMEXTRAS;
303
#else
304
    int numextras = T_EXTRA(p->InputFormat);
305
#endif
306
150k
#ifdef INPACKEDSAMPLESIZE
307
150k
    int inpackedsamplesize = INPACKEDSAMPLESIZE;
308
#else
309
    int inpackedsamplesize = T_BYTES(p->InputFormat);
310
#endif
311
150k
#ifdef OUTPACKEDSAMPLESIZE
312
150k
    int outpackedsamplesize = OUTPACKEDSAMPLESIZE;
313
#else
314
    int outpackedsamplesize = T_BYTES(p->OutputFormat);
315
#endif
316
150k
    int prealphaindexin = numinchannels + numextras - 1;
317
150k
    int prealphaindexout = numoutchannels + numextras - 1;
318
150k
    int totalinbytes = (numinchannels + numextras)*inpackedsamplesize;
319
150k
    int totaloutbytes = (numoutchannels + numextras)*outpackedsamplesize;
320
321
    /* Silence some warnings */
322
150k
    (void)bppi;
323
150k
    (void)bppo;
324
150k
    (void)prealphaindexin;
325
150k
    (void)numextras;
326
150k
    (void)prealphaindexout;
327
150k
    (void)inpackedsamplesize;
328
150k
    (void)outpackedsamplesize;
329
150k
    (void)totalinbytes;
330
150k
    (void)totaloutbytes;
331
332
#ifdef BULK_COPY_EXTRAS
333
    if (core->dwOriginalFlags & cmsFLAGS_COPY_ALPHA)
334
        _cmsHandleExtraChannels(ContextID, p, in, out, PixelsPerLine, LineCount, Stride);
335
#endif
336
337
150k
    if (PixelsPerLine == 0)
338
0
        return;
339
340
#ifdef NO_UNPACK
341
    prevIn = (XFORM_TYPE *)p->Cache.CacheIn;
342
#else
343
150k
 #ifdef CACHED
344
    // Empty buffers for quick memcmp
345
150k
    memset(wIn1, 0, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
346
347
    // Get copy of zero cache
348
150k
    memcpy(wIn0, p->Cache.CacheIn,  sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
349
150k
    memcpy(wOut, p->Cache.CacheOut, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
350
351
    // The caller guarantees us that the cache is always valid on entry; if
352
    // the representation is changed, the cache is reset.
353
150k
    prevIn = wIn0;
354
150k
 #endif /* CACHED */
355
150k
    currIn = wIn1;
356
150k
#endif
357
358
300k
    while (LineCount-- > 0)
359
150k
    {
360
150k
        cmsUInt32Number n = PixelsPerLine;
361
150k
        cmsUInt8Number* accum  = (cmsUInt8Number*) in;
362
150k
        cmsUInt8Number* output = (cmsUInt8Number*) out;
363
#ifdef NO_UNPACK
364
        currIn = (XFORM_TYPE *)accum;
365
#endif
366
100M
        while (n-- > 0) { // prevIn == CacheIn, wOut = CacheOut
367
#ifdef PREALPHA
368
 #ifdef XFORM_FLOAT
369
            cmsFloat32Number alpha = ((cmsFloat32Number *)accum)[prealphaindexin];
370
 #else
371
            cmsUInt32Number alpha = inpackedsamplesize == 2 ?
372
                                     ((cmsUInt16Number *)accum)[prealphaindexin] :
373
                                     (accum[prealphaindexin]);
374
 #endif
375
            if (alpha == 0) {
376
                ZEROPACK(ContextID,p,output,accum);
377
                accum += inpackedsamplesize*(prealphaindexin+1);
378
            } else {
379
#endif
380
100M
                UNPACK(ContextID,p,currIn,accum,bppi,alpha);
381
#ifdef PREALPHA
382
 #ifndef UNPACKINCLUDESPREALPHA
383
  #ifdef XFORM_FLOAT
384
                {
385
                    int i;
386
                    cmsFloat32Number inva = 1.0f / alpha;
387
                    for (i = 0; i < numinchannels; i++)
388
                        currIn[i] *= inva;
389
                }
390
  #else
391
                {
392
                    int i;
393
                    cmsUInt32Number al = inpackedsamplesize == 1 ? alpha*0x101 : alpha;
394
                    cmsUInt32Number inva = 0xffff0000U / al;
395
                    for (i = 0; i < numinchannels; i++)
396
                        currIn[i] = ((currIn[i] * inva)>>16);
397
                }
398
  #endif
399
 #endif
400
#endif
401
100M
#ifdef CACHED
402
100M
                if (COMPARE(currIn, prevIn))
403
14.8M
#endif /* CACHED */
404
14.8M
                {
405
#ifdef GAMUTCHECK
406
 #ifdef XFORM_FLOAT
407
                    cmsFloat32Number OutOfGamut;
408
409
                    // Evaluate gamut marker.
410
                    cmsPipelineEvalFloat(currIn, &OutOfGamut, core->GamutCheck);
411
412
                    // Is current color out of gamut?
413
                    if (OutOfGamut > 0.0)
414
                        // Certainly, out of gamut
415
                        for (j=0; j < cmsMAXCHANNELS; j++)
416
                            fOut[j] = -1.0;
417
                    else
418
 #else
419
                    cmsUInt16Number wOutOfGamut;
420
421
                    evalGamut(ContextID, currIn, &wOutOfGamut, core->GamutCheck->Data);
422
                    if (wOutOfGamut >= 1)
423
                        /* RJW: Could be faster? copy once to a local buffer? */
424
                        cmsGetAlarmCodes(ContextID, wOut);
425
                    else
426
 #endif /* FLOAT_XFORM */
427
#endif /* GAMUTCHECK */
428
14.8M
                        eval(ContextID, currIn, wOut, data);
429
#ifdef NO_UNPACK
430
 #ifdef CACHED
431
                    prevIn = currIn;
432
 #endif
433
                    currIn = (XFORM_TYPE *)(((char *)currIn) + totalinbytes);
434
#else
435
14.8M
 #ifdef CACHED
436
14.8M
                    {XFORM_TYPE *tmp = currIn; currIn = prevIn; prevIn = tmp;} // SWAP
437
14.8M
 #endif /* CACHED */
438
14.8M
#endif /* NO_UNPACK */
439
14.8M
                }
440
#ifdef NO_PACK
441
                else
442
                    COPY_MATCHED(prevOut,wOut);
443
                prevOut = wOut;
444
#endif
445
#ifdef PREALPHA
446
 #ifndef PACKINCLUDESPREALPHA
447
  #ifdef XFORM_FLOAT
448
                {
449
                    int i;
450
                    for (i = 0; i < numoutchannels; i++)
451
                        wScaled = wOut[i] * alpha;
452
                }
453
  #else
454
                {
455
                    int i;
456
                    cmsUInt32Number al = inpackedsamplesize == 1 ? alpha*0x101 : alpha;
457
                    for (i = 0; i < numoutchannels; i++)
458
                        wScaled[i] = mul65535(wOut[i],al);
459
                }
460
  #endif
461
                PACK(ContextID,p,wScaled,output,bppo,alpha);
462
 #else
463
                PACK(ContextID,p,wOut,output,bppo,alpha);
464
 #endif
465
#else
466
100M
                PACK(ContextID,p,wOut,output,bppo,alpha);
467
100M
#endif
468
100M
                COPY_EXTRAS(p,accum,output);
469
#ifdef PREALPHA
470
            }
471
#endif
472
100M
        } /* End x loop */
473
150k
        in = (void *)((cmsUInt8Number *)in + Stride->BytesPerLineIn);
474
150k
        out = (void *)((cmsUInt8Number *)out + Stride->BytesPerLineOut);
475
150k
    } /* End y loop */
476
    /* The following code is only safe if we know that a given transform is
477
     * called on one thread a time. */
478
#if 0
479
#ifdef CACHED
480
#ifdef NO_UNPACK
481
    memcpy(p->Cache.CacheIn,prevIn, CMPBYTES);
482
#else
483
    memcpy(p->Cache.CacheIn, prevIn, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
484
#endif
485
#ifdef NO_PACK
486
    COPY_MATCHED(prevOut,p->Cache.CacheOut);
487
#else
488
    memcpy(p->Cache.CacheOut, wOut, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
489
#endif /* NO_PACK */
490
#endif /* CACHED */
491
#endif
492
150k
}
cmsxform.c:CachedXFORM3x2to3x2
Line
Count
Source
255
6.64M
{
256
6.64M
    _cmsTRANSFORMCORE *core = p->core;
257
6.64M
#ifndef NO_UNPACK
258
 #ifdef XFORM_FLOAT
259
    cmsFloat32Number wIn[cmsMAXCHANNELS*2];
260
 #else
261
6.64M
    cmsUInt16Number wIn[cmsMAXCHANNELS*2];
262
6.64M
 #endif
263
6.64M
 #define wIn0 (&wIn[0])
264
6.64M
 #define wIn1 (&wIn[cmsMAXCHANNELS])
265
6.64M
#endif
266
6.64M
    XFORM_TYPE *currIn;
267
6.64M
#ifdef CACHED
268
6.64M
    XFORM_TYPE *prevIn;
269
6.64M
#endif /* CACHED */
270
#ifdef NO_PACK
271
    XFORM_TYPE *wOut = (XFORM_TYPE *)out;
272
    XFORM_TYPE *prevOut = (XFORM_TYPE *)p->Cache.CacheOut;
273
#else
274
6.64M
    XFORM_TYPE wOut[cmsMAXCHANNELS];
275
6.64M
#endif
276
#if defined(PREALPHA) && !defined(PACKINCLUDESPREALPHA)
277
    XFORM_TYPE wScaled[cmsMAXCHANNELS];
278
#endif
279
#ifdef GAMUTCHECK
280
    _cmsPipelineEval16Fn evalGamut = core->GamutCheck->Eval16Fn;
281
#endif /* GAMUTCHECK */
282
#ifdef XFORM_FLOAT
283
    _cmsPipelineEvalFloatFn eval = core->Lut->EvalFloatFn;
284
    const cmsPipeline *data = core->Lut;
285
#else
286
6.64M
    _cmsPipelineEval16Fn eval = core->Lut->Eval16Fn;
287
6.64M
    void *data = core->Lut->Data;
288
6.64M
#endif
289
6.64M
    cmsUInt32Number bppi = Stride->BytesPerPlaneIn;
290
6.64M
    cmsUInt32Number bppo = Stride->BytesPerPlaneOut;
291
6.64M
#ifdef NUMINCHANNELS
292
6.64M
    int numinchannels = NUMINCHANNELS;
293
#else
294
    int numinchannels = T_CHANNELS(p->InputFormat);
295
#endif
296
6.64M
#ifdef NUMOUTCHANNELS
297
6.64M
    int numoutchannels = NUMOUTCHANNELS;
298
#else
299
    int numoutchannels = T_CHANNELS(p->OutputFormat);
300
#endif
301
6.64M
#ifdef NUMEXTRAS
302
6.64M
    int numextras = NUMEXTRAS;
303
#else
304
    int numextras = T_EXTRA(p->InputFormat);
305
#endif
306
6.64M
#ifdef INPACKEDSAMPLESIZE
307
6.64M
    int inpackedsamplesize = INPACKEDSAMPLESIZE;
308
#else
309
    int inpackedsamplesize = T_BYTES(p->InputFormat);
310
#endif
311
6.64M
#ifdef OUTPACKEDSAMPLESIZE
312
6.64M
    int outpackedsamplesize = OUTPACKEDSAMPLESIZE;
313
#else
314
    int outpackedsamplesize = T_BYTES(p->OutputFormat);
315
#endif
316
6.64M
    int prealphaindexin = numinchannels + numextras - 1;
317
6.64M
    int prealphaindexout = numoutchannels + numextras - 1;
318
6.64M
    int totalinbytes = (numinchannels + numextras)*inpackedsamplesize;
319
6.64M
    int totaloutbytes = (numoutchannels + numextras)*outpackedsamplesize;
320
321
    /* Silence some warnings */
322
6.64M
    (void)bppi;
323
6.64M
    (void)bppo;
324
6.64M
    (void)prealphaindexin;
325
6.64M
    (void)numextras;
326
6.64M
    (void)prealphaindexout;
327
6.64M
    (void)inpackedsamplesize;
328
6.64M
    (void)outpackedsamplesize;
329
6.64M
    (void)totalinbytes;
330
6.64M
    (void)totaloutbytes;
331
332
#ifdef BULK_COPY_EXTRAS
333
    if (core->dwOriginalFlags & cmsFLAGS_COPY_ALPHA)
334
        _cmsHandleExtraChannels(ContextID, p, in, out, PixelsPerLine, LineCount, Stride);
335
#endif
336
337
6.64M
    if (PixelsPerLine == 0)
338
0
        return;
339
340
#ifdef NO_UNPACK
341
    prevIn = (XFORM_TYPE *)p->Cache.CacheIn;
342
#else
343
6.64M
 #ifdef CACHED
344
    // Empty buffers for quick memcmp
345
6.64M
    memset(wIn1, 0, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
346
347
    // Get copy of zero cache
348
6.64M
    memcpy(wIn0, p->Cache.CacheIn,  sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
349
6.64M
    memcpy(wOut, p->Cache.CacheOut, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
350
351
    // The caller guarantees us that the cache is always valid on entry; if
352
    // the representation is changed, the cache is reset.
353
6.64M
    prevIn = wIn0;
354
6.64M
 #endif /* CACHED */
355
6.64M
    currIn = wIn1;
356
6.64M
#endif
357
358
13.2M
    while (LineCount-- > 0)
359
6.64M
    {
360
6.64M
        cmsUInt32Number n = PixelsPerLine;
361
6.64M
        cmsUInt8Number* accum  = (cmsUInt8Number*) in;
362
6.64M
        cmsUInt8Number* output = (cmsUInt8Number*) out;
363
#ifdef NO_UNPACK
364
        currIn = (XFORM_TYPE *)accum;
365
#endif
366
13.2M
        while (n-- > 0) { // prevIn == CacheIn, wOut = CacheOut
367
#ifdef PREALPHA
368
 #ifdef XFORM_FLOAT
369
            cmsFloat32Number alpha = ((cmsFloat32Number *)accum)[prealphaindexin];
370
 #else
371
            cmsUInt32Number alpha = inpackedsamplesize == 2 ?
372
                                     ((cmsUInt16Number *)accum)[prealphaindexin] :
373
                                     (accum[prealphaindexin]);
374
 #endif
375
            if (alpha == 0) {
376
                ZEROPACK(ContextID,p,output,accum);
377
                accum += inpackedsamplesize*(prealphaindexin+1);
378
            } else {
379
#endif
380
6.64M
                UNPACK(ContextID,p,currIn,accum,bppi,alpha);
381
#ifdef PREALPHA
382
 #ifndef UNPACKINCLUDESPREALPHA
383
  #ifdef XFORM_FLOAT
384
                {
385
                    int i;
386
                    cmsFloat32Number inva = 1.0f / alpha;
387
                    for (i = 0; i < numinchannels; i++)
388
                        currIn[i] *= inva;
389
                }
390
  #else
391
                {
392
                    int i;
393
                    cmsUInt32Number al = inpackedsamplesize == 1 ? alpha*0x101 : alpha;
394
                    cmsUInt32Number inva = 0xffff0000U / al;
395
                    for (i = 0; i < numinchannels; i++)
396
                        currIn[i] = ((currIn[i] * inva)>>16);
397
                }
398
  #endif
399
 #endif
400
#endif
401
6.64M
#ifdef CACHED
402
6.64M
                if (COMPARE(currIn, prevIn))
403
6.38M
#endif /* CACHED */
404
6.38M
                {
405
#ifdef GAMUTCHECK
406
 #ifdef XFORM_FLOAT
407
                    cmsFloat32Number OutOfGamut;
408
409
                    // Evaluate gamut marker.
410
                    cmsPipelineEvalFloat(currIn, &OutOfGamut, core->GamutCheck);
411
412
                    // Is current color out of gamut?
413
                    if (OutOfGamut > 0.0)
414
                        // Certainly, out of gamut
415
                        for (j=0; j < cmsMAXCHANNELS; j++)
416
                            fOut[j] = -1.0;
417
                    else
418
 #else
419
                    cmsUInt16Number wOutOfGamut;
420
421
                    evalGamut(ContextID, currIn, &wOutOfGamut, core->GamutCheck->Data);
422
                    if (wOutOfGamut >= 1)
423
                        /* RJW: Could be faster? copy once to a local buffer? */
424
                        cmsGetAlarmCodes(ContextID, wOut);
425
                    else
426
 #endif /* FLOAT_XFORM */
427
#endif /* GAMUTCHECK */
428
6.38M
                        eval(ContextID, currIn, wOut, data);
429
#ifdef NO_UNPACK
430
 #ifdef CACHED
431
                    prevIn = currIn;
432
 #endif
433
                    currIn = (XFORM_TYPE *)(((char *)currIn) + totalinbytes);
434
#else
435
6.38M
 #ifdef CACHED
436
6.38M
                    {XFORM_TYPE *tmp = currIn; currIn = prevIn; prevIn = tmp;} // SWAP
437
6.38M
 #endif /* CACHED */
438
6.38M
#endif /* NO_UNPACK */
439
6.38M
                }
440
#ifdef NO_PACK
441
                else
442
                    COPY_MATCHED(prevOut,wOut);
443
                prevOut = wOut;
444
#endif
445
#ifdef PREALPHA
446
 #ifndef PACKINCLUDESPREALPHA
447
  #ifdef XFORM_FLOAT
448
                {
449
                    int i;
450
                    for (i = 0; i < numoutchannels; i++)
451
                        wScaled = wOut[i] * alpha;
452
                }
453
  #else
454
                {
455
                    int i;
456
                    cmsUInt32Number al = inpackedsamplesize == 1 ? alpha*0x101 : alpha;
457
                    for (i = 0; i < numoutchannels; i++)
458
                        wScaled[i] = mul65535(wOut[i],al);
459
                }
460
  #endif
461
                PACK(ContextID,p,wScaled,output,bppo,alpha);
462
 #else
463
                PACK(ContextID,p,wOut,output,bppo,alpha);
464
 #endif
465
#else
466
6.64M
                PACK(ContextID,p,wOut,output,bppo,alpha);
467
6.64M
#endif
468
6.64M
                COPY_EXTRAS(p,accum,output);
469
#ifdef PREALPHA
470
            }
471
#endif
472
6.64M
        } /* End x loop */
473
6.64M
        in = (void *)((cmsUInt8Number *)in + Stride->BytesPerLineIn);
474
6.64M
        out = (void *)((cmsUInt8Number *)out + Stride->BytesPerLineOut);
475
6.64M
    } /* End y loop */
476
    /* The following code is only safe if we know that a given transform is
477
     * called on one thread a time. */
478
#if 0
479
#ifdef CACHED
480
#ifdef NO_UNPACK
481
    memcpy(p->Cache.CacheIn,prevIn, CMPBYTES);
482
#else
483
    memcpy(p->Cache.CacheIn, prevIn, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
484
#endif
485
#ifdef NO_PACK
486
    COPY_MATCHED(prevOut,p->Cache.CacheOut);
487
#else
488
    memcpy(p->Cache.CacheOut, wOut, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
489
#endif /* NO_PACK */
490
#endif /* CACHED */
491
#endif
492
6.64M
}
cmsxform.c:CachedXFORM3to4
Line
Count
Source
255
104
{
256
104
    _cmsTRANSFORMCORE *core = p->core;
257
104
#ifndef NO_UNPACK
258
 #ifdef XFORM_FLOAT
259
    cmsFloat32Number wIn[cmsMAXCHANNELS*2];
260
 #else
261
104
    cmsUInt16Number wIn[cmsMAXCHANNELS*2];
262
104
 #endif
263
104
 #define wIn0 (&wIn[0])
264
104
 #define wIn1 (&wIn[cmsMAXCHANNELS])
265
104
#endif
266
104
    XFORM_TYPE *currIn;
267
104
#ifdef CACHED
268
104
    XFORM_TYPE *prevIn;
269
104
#endif /* CACHED */
270
#ifdef NO_PACK
271
    XFORM_TYPE *wOut = (XFORM_TYPE *)out;
272
    XFORM_TYPE *prevOut = (XFORM_TYPE *)p->Cache.CacheOut;
273
#else
274
104
    XFORM_TYPE wOut[cmsMAXCHANNELS];
275
104
#endif
276
#if defined(PREALPHA) && !defined(PACKINCLUDESPREALPHA)
277
    XFORM_TYPE wScaled[cmsMAXCHANNELS];
278
#endif
279
#ifdef GAMUTCHECK
280
    _cmsPipelineEval16Fn evalGamut = core->GamutCheck->Eval16Fn;
281
#endif /* GAMUTCHECK */
282
#ifdef XFORM_FLOAT
283
    _cmsPipelineEvalFloatFn eval = core->Lut->EvalFloatFn;
284
    const cmsPipeline *data = core->Lut;
285
#else
286
104
    _cmsPipelineEval16Fn eval = core->Lut->Eval16Fn;
287
104
    void *data = core->Lut->Data;
288
104
#endif
289
104
    cmsUInt32Number bppi = Stride->BytesPerPlaneIn;
290
104
    cmsUInt32Number bppo = Stride->BytesPerPlaneOut;
291
104
#ifdef NUMINCHANNELS
292
104
    int numinchannels = NUMINCHANNELS;
293
#else
294
    int numinchannels = T_CHANNELS(p->InputFormat);
295
#endif
296
104
#ifdef NUMOUTCHANNELS
297
104
    int numoutchannels = NUMOUTCHANNELS;
298
#else
299
    int numoutchannels = T_CHANNELS(p->OutputFormat);
300
#endif
301
104
#ifdef NUMEXTRAS
302
104
    int numextras = NUMEXTRAS;
303
#else
304
    int numextras = T_EXTRA(p->InputFormat);
305
#endif
306
104
#ifdef INPACKEDSAMPLESIZE
307
104
    int inpackedsamplesize = INPACKEDSAMPLESIZE;
308
#else
309
    int inpackedsamplesize = T_BYTES(p->InputFormat);
310
#endif
311
104
#ifdef OUTPACKEDSAMPLESIZE
312
104
    int outpackedsamplesize = OUTPACKEDSAMPLESIZE;
313
#else
314
    int outpackedsamplesize = T_BYTES(p->OutputFormat);
315
#endif
316
104
    int prealphaindexin = numinchannels + numextras - 1;
317
104
    int prealphaindexout = numoutchannels + numextras - 1;
318
104
    int totalinbytes = (numinchannels + numextras)*inpackedsamplesize;
319
104
    int totaloutbytes = (numoutchannels + numextras)*outpackedsamplesize;
320
321
    /* Silence some warnings */
322
104
    (void)bppi;
323
104
    (void)bppo;
324
104
    (void)prealphaindexin;
325
104
    (void)numextras;
326
104
    (void)prealphaindexout;
327
104
    (void)inpackedsamplesize;
328
104
    (void)outpackedsamplesize;
329
104
    (void)totalinbytes;
330
104
    (void)totaloutbytes;
331
332
#ifdef BULK_COPY_EXTRAS
333
    if (core->dwOriginalFlags & cmsFLAGS_COPY_ALPHA)
334
        _cmsHandleExtraChannels(ContextID, p, in, out, PixelsPerLine, LineCount, Stride);
335
#endif
336
337
104
    if (PixelsPerLine == 0)
338
0
        return;
339
340
#ifdef NO_UNPACK
341
    prevIn = (XFORM_TYPE *)p->Cache.CacheIn;
342
#else
343
104
 #ifdef CACHED
344
    // Empty buffers for quick memcmp
345
104
    memset(wIn1, 0, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
346
347
    // Get copy of zero cache
348
104
    memcpy(wIn0, p->Cache.CacheIn,  sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
349
104
    memcpy(wOut, p->Cache.CacheOut, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
350
351
    // The caller guarantees us that the cache is always valid on entry; if
352
    // the representation is changed, the cache is reset.
353
104
    prevIn = wIn0;
354
104
 #endif /* CACHED */
355
104
    currIn = wIn1;
356
104
#endif
357
358
208
    while (LineCount-- > 0)
359
104
    {
360
104
        cmsUInt32Number n = PixelsPerLine;
361
104
        cmsUInt8Number* accum  = (cmsUInt8Number*) in;
362
104
        cmsUInt8Number* output = (cmsUInt8Number*) out;
363
#ifdef NO_UNPACK
364
        currIn = (XFORM_TYPE *)accum;
365
#endif
366
26.7k
        while (n-- > 0) { // prevIn == CacheIn, wOut = CacheOut
367
#ifdef PREALPHA
368
 #ifdef XFORM_FLOAT
369
            cmsFloat32Number alpha = ((cmsFloat32Number *)accum)[prealphaindexin];
370
 #else
371
            cmsUInt32Number alpha = inpackedsamplesize == 2 ?
372
                                     ((cmsUInt16Number *)accum)[prealphaindexin] :
373
                                     (accum[prealphaindexin]);
374
 #endif
375
            if (alpha == 0) {
376
                ZEROPACK(ContextID,p,output,accum);
377
                accum += inpackedsamplesize*(prealphaindexin+1);
378
            } else {
379
#endif
380
26.6k
                UNPACK(ContextID,p,currIn,accum,bppi,alpha);
381
#ifdef PREALPHA
382
 #ifndef UNPACKINCLUDESPREALPHA
383
  #ifdef XFORM_FLOAT
384
                {
385
                    int i;
386
                    cmsFloat32Number inva = 1.0f / alpha;
387
                    for (i = 0; i < numinchannels; i++)
388
                        currIn[i] *= inva;
389
                }
390
  #else
391
                {
392
                    int i;
393
                    cmsUInt32Number al = inpackedsamplesize == 1 ? alpha*0x101 : alpha;
394
                    cmsUInt32Number inva = 0xffff0000U / al;
395
                    for (i = 0; i < numinchannels; i++)
396
                        currIn[i] = ((currIn[i] * inva)>>16);
397
                }
398
  #endif
399
 #endif
400
#endif
401
26.6k
#ifdef CACHED
402
26.6k
                if (COMPARE(currIn, prevIn))
403
13.3k
#endif /* CACHED */
404
13.3k
                {
405
#ifdef GAMUTCHECK
406
 #ifdef XFORM_FLOAT
407
                    cmsFloat32Number OutOfGamut;
408
409
                    // Evaluate gamut marker.
410
                    cmsPipelineEvalFloat(currIn, &OutOfGamut, core->GamutCheck);
411
412
                    // Is current color out of gamut?
413
                    if (OutOfGamut > 0.0)
414
                        // Certainly, out of gamut
415
                        for (j=0; j < cmsMAXCHANNELS; j++)
416
                            fOut[j] = -1.0;
417
                    else
418
 #else
419
                    cmsUInt16Number wOutOfGamut;
420
421
                    evalGamut(ContextID, currIn, &wOutOfGamut, core->GamutCheck->Data);
422
                    if (wOutOfGamut >= 1)
423
                        /* RJW: Could be faster? copy once to a local buffer? */
424
                        cmsGetAlarmCodes(ContextID, wOut);
425
                    else
426
 #endif /* FLOAT_XFORM */
427
#endif /* GAMUTCHECK */
428
13.3k
                        eval(ContextID, currIn, wOut, data);
429
#ifdef NO_UNPACK
430
 #ifdef CACHED
431
                    prevIn = currIn;
432
 #endif
433
                    currIn = (XFORM_TYPE *)(((char *)currIn) + totalinbytes);
434
#else
435
13.3k
 #ifdef CACHED
436
13.3k
                    {XFORM_TYPE *tmp = currIn; currIn = prevIn; prevIn = tmp;} // SWAP
437
13.3k
 #endif /* CACHED */
438
13.3k
#endif /* NO_UNPACK */
439
13.3k
                }
440
#ifdef NO_PACK
441
                else
442
                    COPY_MATCHED(prevOut,wOut);
443
                prevOut = wOut;
444
#endif
445
#ifdef PREALPHA
446
 #ifndef PACKINCLUDESPREALPHA
447
  #ifdef XFORM_FLOAT
448
                {
449
                    int i;
450
                    for (i = 0; i < numoutchannels; i++)
451
                        wScaled = wOut[i] * alpha;
452
                }
453
  #else
454
                {
455
                    int i;
456
                    cmsUInt32Number al = inpackedsamplesize == 1 ? alpha*0x101 : alpha;
457
                    for (i = 0; i < numoutchannels; i++)
458
                        wScaled[i] = mul65535(wOut[i],al);
459
                }
460
  #endif
461
                PACK(ContextID,p,wScaled,output,bppo,alpha);
462
 #else
463
                PACK(ContextID,p,wOut,output,bppo,alpha);
464
 #endif
465
#else
466
26.6k
                PACK(ContextID,p,wOut,output,bppo,alpha);
467
26.6k
#endif
468
26.6k
                COPY_EXTRAS(p,accum,output);
469
#ifdef PREALPHA
470
            }
471
#endif
472
26.6k
        } /* End x loop */
473
104
        in = (void *)((cmsUInt8Number *)in + Stride->BytesPerLineIn);
474
104
        out = (void *)((cmsUInt8Number *)out + Stride->BytesPerLineOut);
475
104
    } /* End y loop */
476
    /* The following code is only safe if we know that a given transform is
477
     * called on one thread a time. */
478
#if 0
479
#ifdef CACHED
480
#ifdef NO_UNPACK
481
    memcpy(p->Cache.CacheIn,prevIn, CMPBYTES);
482
#else
483
    memcpy(p->Cache.CacheIn, prevIn, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
484
#endif
485
#ifdef NO_PACK
486
    COPY_MATCHED(prevOut,p->Cache.CacheOut);
487
#else
488
    memcpy(p->Cache.CacheOut, wOut, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
489
#endif /* NO_PACK */
490
#endif /* CACHED */
491
#endif
492
104
}
cmsxform.c:CachedXFORM3x2to4x2
Line
Count
Source
255
54.5M
{
256
54.5M
    _cmsTRANSFORMCORE *core = p->core;
257
54.5M
#ifndef NO_UNPACK
258
 #ifdef XFORM_FLOAT
259
    cmsFloat32Number wIn[cmsMAXCHANNELS*2];
260
 #else
261
54.5M
    cmsUInt16Number wIn[cmsMAXCHANNELS*2];
262
54.5M
 #endif
263
54.5M
 #define wIn0 (&wIn[0])
264
54.5M
 #define wIn1 (&wIn[cmsMAXCHANNELS])
265
54.5M
#endif
266
54.5M
    XFORM_TYPE *currIn;
267
54.5M
#ifdef CACHED
268
54.5M
    XFORM_TYPE *prevIn;
269
54.5M
#endif /* CACHED */
270
#ifdef NO_PACK
271
    XFORM_TYPE *wOut = (XFORM_TYPE *)out;
272
    XFORM_TYPE *prevOut = (XFORM_TYPE *)p->Cache.CacheOut;
273
#else
274
54.5M
    XFORM_TYPE wOut[cmsMAXCHANNELS];
275
54.5M
#endif
276
#if defined(PREALPHA) && !defined(PACKINCLUDESPREALPHA)
277
    XFORM_TYPE wScaled[cmsMAXCHANNELS];
278
#endif
279
#ifdef GAMUTCHECK
280
    _cmsPipelineEval16Fn evalGamut = core->GamutCheck->Eval16Fn;
281
#endif /* GAMUTCHECK */
282
#ifdef XFORM_FLOAT
283
    _cmsPipelineEvalFloatFn eval = core->Lut->EvalFloatFn;
284
    const cmsPipeline *data = core->Lut;
285
#else
286
54.5M
    _cmsPipelineEval16Fn eval = core->Lut->Eval16Fn;
287
54.5M
    void *data = core->Lut->Data;
288
54.5M
#endif
289
54.5M
    cmsUInt32Number bppi = Stride->BytesPerPlaneIn;
290
54.5M
    cmsUInt32Number bppo = Stride->BytesPerPlaneOut;
291
54.5M
#ifdef NUMINCHANNELS
292
54.5M
    int numinchannels = NUMINCHANNELS;
293
#else
294
    int numinchannels = T_CHANNELS(p->InputFormat);
295
#endif
296
54.5M
#ifdef NUMOUTCHANNELS
297
54.5M
    int numoutchannels = NUMOUTCHANNELS;
298
#else
299
    int numoutchannels = T_CHANNELS(p->OutputFormat);
300
#endif
301
54.5M
#ifdef NUMEXTRAS
302
54.5M
    int numextras = NUMEXTRAS;
303
#else
304
    int numextras = T_EXTRA(p->InputFormat);
305
#endif
306
54.5M
#ifdef INPACKEDSAMPLESIZE
307
54.5M
    int inpackedsamplesize = INPACKEDSAMPLESIZE;
308
#else
309
    int inpackedsamplesize = T_BYTES(p->InputFormat);
310
#endif
311
54.5M
#ifdef OUTPACKEDSAMPLESIZE
312
54.5M
    int outpackedsamplesize = OUTPACKEDSAMPLESIZE;
313
#else
314
    int outpackedsamplesize = T_BYTES(p->OutputFormat);
315
#endif
316
54.5M
    int prealphaindexin = numinchannels + numextras - 1;
317
54.5M
    int prealphaindexout = numoutchannels + numextras - 1;
318
54.5M
    int totalinbytes = (numinchannels + numextras)*inpackedsamplesize;
319
54.5M
    int totaloutbytes = (numoutchannels + numextras)*outpackedsamplesize;
320
321
    /* Silence some warnings */
322
54.5M
    (void)bppi;
323
54.5M
    (void)bppo;
324
54.5M
    (void)prealphaindexin;
325
54.5M
    (void)numextras;
326
54.5M
    (void)prealphaindexout;
327
54.5M
    (void)inpackedsamplesize;
328
54.5M
    (void)outpackedsamplesize;
329
54.5M
    (void)totalinbytes;
330
54.5M
    (void)totaloutbytes;
331
332
#ifdef BULK_COPY_EXTRAS
333
    if (core->dwOriginalFlags & cmsFLAGS_COPY_ALPHA)
334
        _cmsHandleExtraChannels(ContextID, p, in, out, PixelsPerLine, LineCount, Stride);
335
#endif
336
337
54.5M
    if (PixelsPerLine == 0)
338
0
        return;
339
340
#ifdef NO_UNPACK
341
    prevIn = (XFORM_TYPE *)p->Cache.CacheIn;
342
#else
343
54.5M
 #ifdef CACHED
344
    // Empty buffers for quick memcmp
345
54.5M
    memset(wIn1, 0, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
346
347
    // Get copy of zero cache
348
54.5M
    memcpy(wIn0, p->Cache.CacheIn,  sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
349
54.5M
    memcpy(wOut, p->Cache.CacheOut, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
350
351
    // The caller guarantees us that the cache is always valid on entry; if
352
    // the representation is changed, the cache is reset.
353
54.5M
    prevIn = wIn0;
354
54.5M
 #endif /* CACHED */
355
54.5M
    currIn = wIn1;
356
54.5M
#endif
357
358
109M
    while (LineCount-- > 0)
359
54.5M
    {
360
54.5M
        cmsUInt32Number n = PixelsPerLine;
361
54.5M
        cmsUInt8Number* accum  = (cmsUInt8Number*) in;
362
54.5M
        cmsUInt8Number* output = (cmsUInt8Number*) out;
363
#ifdef NO_UNPACK
364
        currIn = (XFORM_TYPE *)accum;
365
#endif
366
109M
        while (n-- > 0) { // prevIn == CacheIn, wOut = CacheOut
367
#ifdef PREALPHA
368
 #ifdef XFORM_FLOAT
369
            cmsFloat32Number alpha = ((cmsFloat32Number *)accum)[prealphaindexin];
370
 #else
371
            cmsUInt32Number alpha = inpackedsamplesize == 2 ?
372
                                     ((cmsUInt16Number *)accum)[prealphaindexin] :
373
                                     (accum[prealphaindexin]);
374
 #endif
375
            if (alpha == 0) {
376
                ZEROPACK(ContextID,p,output,accum);
377
                accum += inpackedsamplesize*(prealphaindexin+1);
378
            } else {
379
#endif
380
54.5M
                UNPACK(ContextID,p,currIn,accum,bppi,alpha);
381
#ifdef PREALPHA
382
 #ifndef UNPACKINCLUDESPREALPHA
383
  #ifdef XFORM_FLOAT
384
                {
385
                    int i;
386
                    cmsFloat32Number inva = 1.0f / alpha;
387
                    for (i = 0; i < numinchannels; i++)
388
                        currIn[i] *= inva;
389
                }
390
  #else
391
                {
392
                    int i;
393
                    cmsUInt32Number al = inpackedsamplesize == 1 ? alpha*0x101 : alpha;
394
                    cmsUInt32Number inva = 0xffff0000U / al;
395
                    for (i = 0; i < numinchannels; i++)
396
                        currIn[i] = ((currIn[i] * inva)>>16);
397
                }
398
  #endif
399
 #endif
400
#endif
401
54.5M
#ifdef CACHED
402
54.5M
                if (COMPARE(currIn, prevIn))
403
54.2M
#endif /* CACHED */
404
54.2M
                {
405
#ifdef GAMUTCHECK
406
 #ifdef XFORM_FLOAT
407
                    cmsFloat32Number OutOfGamut;
408
409
                    // Evaluate gamut marker.
410
                    cmsPipelineEvalFloat(currIn, &OutOfGamut, core->GamutCheck);
411
412
                    // Is current color out of gamut?
413
                    if (OutOfGamut > 0.0)
414
                        // Certainly, out of gamut
415
                        for (j=0; j < cmsMAXCHANNELS; j++)
416
                            fOut[j] = -1.0;
417
                    else
418
 #else
419
                    cmsUInt16Number wOutOfGamut;
420
421
                    evalGamut(ContextID, currIn, &wOutOfGamut, core->GamutCheck->Data);
422
                    if (wOutOfGamut >= 1)
423
                        /* RJW: Could be faster? copy once to a local buffer? */
424
                        cmsGetAlarmCodes(ContextID, wOut);
425
                    else
426
 #endif /* FLOAT_XFORM */
427
#endif /* GAMUTCHECK */
428
54.2M
                        eval(ContextID, currIn, wOut, data);
429
#ifdef NO_UNPACK
430
 #ifdef CACHED
431
                    prevIn = currIn;
432
 #endif
433
                    currIn = (XFORM_TYPE *)(((char *)currIn) + totalinbytes);
434
#else
435
54.2M
 #ifdef CACHED
436
54.2M
                    {XFORM_TYPE *tmp = currIn; currIn = prevIn; prevIn = tmp;} // SWAP
437
54.2M
 #endif /* CACHED */
438
54.2M
#endif /* NO_UNPACK */
439
54.2M
                }
440
#ifdef NO_PACK
441
                else
442
                    COPY_MATCHED(prevOut,wOut);
443
                prevOut = wOut;
444
#endif
445
#ifdef PREALPHA
446
 #ifndef PACKINCLUDESPREALPHA
447
  #ifdef XFORM_FLOAT
448
                {
449
                    int i;
450
                    for (i = 0; i < numoutchannels; i++)
451
                        wScaled = wOut[i] * alpha;
452
                }
453
  #else
454
                {
455
                    int i;
456
                    cmsUInt32Number al = inpackedsamplesize == 1 ? alpha*0x101 : alpha;
457
                    for (i = 0; i < numoutchannels; i++)
458
                        wScaled[i] = mul65535(wOut[i],al);
459
                }
460
  #endif
461
                PACK(ContextID,p,wScaled,output,bppo,alpha);
462
 #else
463
                PACK(ContextID,p,wOut,output,bppo,alpha);
464
 #endif
465
#else
466
54.5M
                PACK(ContextID,p,wOut,output,bppo,alpha);
467
54.5M
#endif
468
54.5M
                COPY_EXTRAS(p,accum,output);
469
#ifdef PREALPHA
470
            }
471
#endif
472
54.5M
        } /* End x loop */
473
54.5M
        in = (void *)((cmsUInt8Number *)in + Stride->BytesPerLineIn);
474
54.5M
        out = (void *)((cmsUInt8Number *)out + Stride->BytesPerLineOut);
475
54.5M
    } /* End y loop */
476
    /* The following code is only safe if we know that a given transform is
477
     * called on one thread a time. */
478
#if 0
479
#ifdef CACHED
480
#ifdef NO_UNPACK
481
    memcpy(p->Cache.CacheIn,prevIn, CMPBYTES);
482
#else
483
    memcpy(p->Cache.CacheIn, prevIn, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
484
#endif
485
#ifdef NO_PACK
486
    COPY_MATCHED(prevOut,p->Cache.CacheOut);
487
#else
488
    memcpy(p->Cache.CacheOut, wOut, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
489
#endif /* NO_PACK */
490
#endif /* CACHED */
491
#endif
492
54.5M
}
cmsxform.c:CachedXFORM4to1
Line
Count
Source
255
109k
{
256
109k
    _cmsTRANSFORMCORE *core = p->core;
257
109k
#ifndef NO_UNPACK
258
 #ifdef XFORM_FLOAT
259
    cmsFloat32Number wIn[cmsMAXCHANNELS*2];
260
 #else
261
109k
    cmsUInt16Number wIn[cmsMAXCHANNELS*2];
262
109k
 #endif
263
109k
 #define wIn0 (&wIn[0])
264
109k
 #define wIn1 (&wIn[cmsMAXCHANNELS])
265
109k
#endif
266
109k
    XFORM_TYPE *currIn;
267
109k
#ifdef CACHED
268
109k
    XFORM_TYPE *prevIn;
269
109k
#endif /* CACHED */
270
#ifdef NO_PACK
271
    XFORM_TYPE *wOut = (XFORM_TYPE *)out;
272
    XFORM_TYPE *prevOut = (XFORM_TYPE *)p->Cache.CacheOut;
273
#else
274
109k
    XFORM_TYPE wOut[cmsMAXCHANNELS];
275
109k
#endif
276
#if defined(PREALPHA) && !defined(PACKINCLUDESPREALPHA)
277
    XFORM_TYPE wScaled[cmsMAXCHANNELS];
278
#endif
279
#ifdef GAMUTCHECK
280
    _cmsPipelineEval16Fn evalGamut = core->GamutCheck->Eval16Fn;
281
#endif /* GAMUTCHECK */
282
#ifdef XFORM_FLOAT
283
    _cmsPipelineEvalFloatFn eval = core->Lut->EvalFloatFn;
284
    const cmsPipeline *data = core->Lut;
285
#else
286
109k
    _cmsPipelineEval16Fn eval = core->Lut->Eval16Fn;
287
109k
    void *data = core->Lut->Data;
288
109k
#endif
289
109k
    cmsUInt32Number bppi = Stride->BytesPerPlaneIn;
290
109k
    cmsUInt32Number bppo = Stride->BytesPerPlaneOut;
291
109k
#ifdef NUMINCHANNELS
292
109k
    int numinchannels = NUMINCHANNELS;
293
#else
294
    int numinchannels = T_CHANNELS(p->InputFormat);
295
#endif
296
109k
#ifdef NUMOUTCHANNELS
297
109k
    int numoutchannels = NUMOUTCHANNELS;
298
#else
299
    int numoutchannels = T_CHANNELS(p->OutputFormat);
300
#endif
301
109k
#ifdef NUMEXTRAS
302
109k
    int numextras = NUMEXTRAS;
303
#else
304
    int numextras = T_EXTRA(p->InputFormat);
305
#endif
306
109k
#ifdef INPACKEDSAMPLESIZE
307
109k
    int inpackedsamplesize = INPACKEDSAMPLESIZE;
308
#else
309
    int inpackedsamplesize = T_BYTES(p->InputFormat);
310
#endif
311
109k
#ifdef OUTPACKEDSAMPLESIZE
312
109k
    int outpackedsamplesize = OUTPACKEDSAMPLESIZE;
313
#else
314
    int outpackedsamplesize = T_BYTES(p->OutputFormat);
315
#endif
316
109k
    int prealphaindexin = numinchannels + numextras - 1;
317
109k
    int prealphaindexout = numoutchannels + numextras - 1;
318
109k
    int totalinbytes = (numinchannels + numextras)*inpackedsamplesize;
319
109k
    int totaloutbytes = (numoutchannels + numextras)*outpackedsamplesize;
320
321
    /* Silence some warnings */
322
109k
    (void)bppi;
323
109k
    (void)bppo;
324
109k
    (void)prealphaindexin;
325
109k
    (void)numextras;
326
109k
    (void)prealphaindexout;
327
109k
    (void)inpackedsamplesize;
328
109k
    (void)outpackedsamplesize;
329
109k
    (void)totalinbytes;
330
109k
    (void)totaloutbytes;
331
332
#ifdef BULK_COPY_EXTRAS
333
    if (core->dwOriginalFlags & cmsFLAGS_COPY_ALPHA)
334
        _cmsHandleExtraChannels(ContextID, p, in, out, PixelsPerLine, LineCount, Stride);
335
#endif
336
337
109k
    if (PixelsPerLine == 0)
338
0
        return;
339
340
#ifdef NO_UNPACK
341
    prevIn = (XFORM_TYPE *)p->Cache.CacheIn;
342
#else
343
109k
 #ifdef CACHED
344
    // Empty buffers for quick memcmp
345
109k
    memset(wIn1, 0, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
346
347
    // Get copy of zero cache
348
109k
    memcpy(wIn0, p->Cache.CacheIn,  sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
349
109k
    memcpy(wOut, p->Cache.CacheOut, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
350
351
    // The caller guarantees us that the cache is always valid on entry; if
352
    // the representation is changed, the cache is reset.
353
109k
    prevIn = wIn0;
354
109k
 #endif /* CACHED */
355
109k
    currIn = wIn1;
356
109k
#endif
357
358
218k
    while (LineCount-- > 0)
359
109k
    {
360
109k
        cmsUInt32Number n = PixelsPerLine;
361
109k
        cmsUInt8Number* accum  = (cmsUInt8Number*) in;
362
109k
        cmsUInt8Number* output = (cmsUInt8Number*) out;
363
#ifdef NO_UNPACK
364
        currIn = (XFORM_TYPE *)accum;
365
#endif
366
52.5M
        while (n-- > 0) { // prevIn == CacheIn, wOut = CacheOut
367
#ifdef PREALPHA
368
 #ifdef XFORM_FLOAT
369
            cmsFloat32Number alpha = ((cmsFloat32Number *)accum)[prealphaindexin];
370
 #else
371
            cmsUInt32Number alpha = inpackedsamplesize == 2 ?
372
                                     ((cmsUInt16Number *)accum)[prealphaindexin] :
373
                                     (accum[prealphaindexin]);
374
 #endif
375
            if (alpha == 0) {
376
                ZEROPACK(ContextID,p,output,accum);
377
                accum += inpackedsamplesize*(prealphaindexin+1);
378
            } else {
379
#endif
380
52.4M
                UNPACK(ContextID,p,currIn,accum,bppi,alpha);
381
#ifdef PREALPHA
382
 #ifndef UNPACKINCLUDESPREALPHA
383
  #ifdef XFORM_FLOAT
384
                {
385
                    int i;
386
                    cmsFloat32Number inva = 1.0f / alpha;
387
                    for (i = 0; i < numinchannels; i++)
388
                        currIn[i] *= inva;
389
                }
390
  #else
391
                {
392
                    int i;
393
                    cmsUInt32Number al = inpackedsamplesize == 1 ? alpha*0x101 : alpha;
394
                    cmsUInt32Number inva = 0xffff0000U / al;
395
                    for (i = 0; i < numinchannels; i++)
396
                        currIn[i] = ((currIn[i] * inva)>>16);
397
                }
398
  #endif
399
 #endif
400
#endif
401
52.4M
#ifdef CACHED
402
52.4M
                if (COMPARE(currIn, prevIn))
403
19.5M
#endif /* CACHED */
404
19.5M
                {
405
#ifdef GAMUTCHECK
406
 #ifdef XFORM_FLOAT
407
                    cmsFloat32Number OutOfGamut;
408
409
                    // Evaluate gamut marker.
410
                    cmsPipelineEvalFloat(currIn, &OutOfGamut, core->GamutCheck);
411
412
                    // Is current color out of gamut?
413
                    if (OutOfGamut > 0.0)
414
                        // Certainly, out of gamut
415
                        for (j=0; j < cmsMAXCHANNELS; j++)
416
                            fOut[j] = -1.0;
417
                    else
418
 #else
419
                    cmsUInt16Number wOutOfGamut;
420
421
                    evalGamut(ContextID, currIn, &wOutOfGamut, core->GamutCheck->Data);
422
                    if (wOutOfGamut >= 1)
423
                        /* RJW: Could be faster? copy once to a local buffer? */
424
                        cmsGetAlarmCodes(ContextID, wOut);
425
                    else
426
 #endif /* FLOAT_XFORM */
427
#endif /* GAMUTCHECK */
428
19.5M
                        eval(ContextID, currIn, wOut, data);
429
#ifdef NO_UNPACK
430
 #ifdef CACHED
431
                    prevIn = currIn;
432
 #endif
433
                    currIn = (XFORM_TYPE *)(((char *)currIn) + totalinbytes);
434
#else
435
19.5M
 #ifdef CACHED
436
19.5M
                    {XFORM_TYPE *tmp = currIn; currIn = prevIn; prevIn = tmp;} // SWAP
437
19.5M
 #endif /* CACHED */
438
19.5M
#endif /* NO_UNPACK */
439
19.5M
                }
440
#ifdef NO_PACK
441
                else
442
                    COPY_MATCHED(prevOut,wOut);
443
                prevOut = wOut;
444
#endif
445
#ifdef PREALPHA
446
 #ifndef PACKINCLUDESPREALPHA
447
  #ifdef XFORM_FLOAT
448
                {
449
                    int i;
450
                    for (i = 0; i < numoutchannels; i++)
451
                        wScaled = wOut[i] * alpha;
452
                }
453
  #else
454
                {
455
                    int i;
456
                    cmsUInt32Number al = inpackedsamplesize == 1 ? alpha*0x101 : alpha;
457
                    for (i = 0; i < numoutchannels; i++)
458
                        wScaled[i] = mul65535(wOut[i],al);
459
                }
460
  #endif
461
                PACK(ContextID,p,wScaled,output,bppo,alpha);
462
 #else
463
                PACK(ContextID,p,wOut,output,bppo,alpha);
464
 #endif
465
#else
466
52.4M
                PACK(ContextID,p,wOut,output,bppo,alpha);
467
52.4M
#endif
468
52.4M
                COPY_EXTRAS(p,accum,output);
469
#ifdef PREALPHA
470
            }
471
#endif
472
52.4M
        } /* End x loop */
473
109k
        in = (void *)((cmsUInt8Number *)in + Stride->BytesPerLineIn);
474
109k
        out = (void *)((cmsUInt8Number *)out + Stride->BytesPerLineOut);
475
109k
    } /* End y loop */
476
    /* The following code is only safe if we know that a given transform is
477
     * called on one thread a time. */
478
#if 0
479
#ifdef CACHED
480
#ifdef NO_UNPACK
481
    memcpy(p->Cache.CacheIn,prevIn, CMPBYTES);
482
#else
483
    memcpy(p->Cache.CacheIn, prevIn, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
484
#endif
485
#ifdef NO_PACK
486
    COPY_MATCHED(prevOut,p->Cache.CacheOut);
487
#else
488
    memcpy(p->Cache.CacheOut, wOut, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
489
#endif /* NO_PACK */
490
#endif /* CACHED */
491
#endif
492
109k
}
cmsxform.c:CachedXFORM4x2to1x2
Line
Count
Source
255
57.6M
{
256
57.6M
    _cmsTRANSFORMCORE *core = p->core;
257
57.6M
#ifndef NO_UNPACK
258
 #ifdef XFORM_FLOAT
259
    cmsFloat32Number wIn[cmsMAXCHANNELS*2];
260
 #else
261
57.6M
    cmsUInt16Number wIn[cmsMAXCHANNELS*2];
262
57.6M
 #endif
263
57.6M
 #define wIn0 (&wIn[0])
264
57.6M
 #define wIn1 (&wIn[cmsMAXCHANNELS])
265
57.6M
#endif
266
57.6M
    XFORM_TYPE *currIn;
267
57.6M
#ifdef CACHED
268
57.6M
    XFORM_TYPE *prevIn;
269
57.6M
#endif /* CACHED */
270
#ifdef NO_PACK
271
    XFORM_TYPE *wOut = (XFORM_TYPE *)out;
272
    XFORM_TYPE *prevOut = (XFORM_TYPE *)p->Cache.CacheOut;
273
#else
274
57.6M
    XFORM_TYPE wOut[cmsMAXCHANNELS];
275
57.6M
#endif
276
#if defined(PREALPHA) && !defined(PACKINCLUDESPREALPHA)
277
    XFORM_TYPE wScaled[cmsMAXCHANNELS];
278
#endif
279
#ifdef GAMUTCHECK
280
    _cmsPipelineEval16Fn evalGamut = core->GamutCheck->Eval16Fn;
281
#endif /* GAMUTCHECK */
282
#ifdef XFORM_FLOAT
283
    _cmsPipelineEvalFloatFn eval = core->Lut->EvalFloatFn;
284
    const cmsPipeline *data = core->Lut;
285
#else
286
57.6M
    _cmsPipelineEval16Fn eval = core->Lut->Eval16Fn;
287
57.6M
    void *data = core->Lut->Data;
288
57.6M
#endif
289
57.6M
    cmsUInt32Number bppi = Stride->BytesPerPlaneIn;
290
57.6M
    cmsUInt32Number bppo = Stride->BytesPerPlaneOut;
291
57.6M
#ifdef NUMINCHANNELS
292
57.6M
    int numinchannels = NUMINCHANNELS;
293
#else
294
    int numinchannels = T_CHANNELS(p->InputFormat);
295
#endif
296
57.6M
#ifdef NUMOUTCHANNELS
297
57.6M
    int numoutchannels = NUMOUTCHANNELS;
298
#else
299
    int numoutchannels = T_CHANNELS(p->OutputFormat);
300
#endif
301
57.6M
#ifdef NUMEXTRAS
302
57.6M
    int numextras = NUMEXTRAS;
303
#else
304
    int numextras = T_EXTRA(p->InputFormat);
305
#endif
306
57.6M
#ifdef INPACKEDSAMPLESIZE
307
57.6M
    int inpackedsamplesize = INPACKEDSAMPLESIZE;
308
#else
309
    int inpackedsamplesize = T_BYTES(p->InputFormat);
310
#endif
311
57.6M
#ifdef OUTPACKEDSAMPLESIZE
312
57.6M
    int outpackedsamplesize = OUTPACKEDSAMPLESIZE;
313
#else
314
    int outpackedsamplesize = T_BYTES(p->OutputFormat);
315
#endif
316
57.6M
    int prealphaindexin = numinchannels + numextras - 1;
317
57.6M
    int prealphaindexout = numoutchannels + numextras - 1;
318
57.6M
    int totalinbytes = (numinchannels + numextras)*inpackedsamplesize;
319
57.6M
    int totaloutbytes = (numoutchannels + numextras)*outpackedsamplesize;
320
321
    /* Silence some warnings */
322
57.6M
    (void)bppi;
323
57.6M
    (void)bppo;
324
57.6M
    (void)prealphaindexin;
325
57.6M
    (void)numextras;
326
57.6M
    (void)prealphaindexout;
327
57.6M
    (void)inpackedsamplesize;
328
57.6M
    (void)outpackedsamplesize;
329
57.6M
    (void)totalinbytes;
330
57.6M
    (void)totaloutbytes;
331
332
#ifdef BULK_COPY_EXTRAS
333
    if (core->dwOriginalFlags & cmsFLAGS_COPY_ALPHA)
334
        _cmsHandleExtraChannels(ContextID, p, in, out, PixelsPerLine, LineCount, Stride);
335
#endif
336
337
57.6M
    if (PixelsPerLine == 0)
338
0
        return;
339
340
#ifdef NO_UNPACK
341
    prevIn = (XFORM_TYPE *)p->Cache.CacheIn;
342
#else
343
57.6M
 #ifdef CACHED
344
    // Empty buffers for quick memcmp
345
57.6M
    memset(wIn1, 0, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
346
347
    // Get copy of zero cache
348
57.6M
    memcpy(wIn0, p->Cache.CacheIn,  sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
349
57.6M
    memcpy(wOut, p->Cache.CacheOut, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
350
351
    // The caller guarantees us that the cache is always valid on entry; if
352
    // the representation is changed, the cache is reset.
353
57.6M
    prevIn = wIn0;
354
57.6M
 #endif /* CACHED */
355
57.6M
    currIn = wIn1;
356
57.6M
#endif
357
358
115M
    while (LineCount-- > 0)
359
57.6M
    {
360
57.6M
        cmsUInt32Number n = PixelsPerLine;
361
57.6M
        cmsUInt8Number* accum  = (cmsUInt8Number*) in;
362
57.6M
        cmsUInt8Number* output = (cmsUInt8Number*) out;
363
#ifdef NO_UNPACK
364
        currIn = (XFORM_TYPE *)accum;
365
#endif
366
115M
        while (n-- > 0) { // prevIn == CacheIn, wOut = CacheOut
367
#ifdef PREALPHA
368
 #ifdef XFORM_FLOAT
369
            cmsFloat32Number alpha = ((cmsFloat32Number *)accum)[prealphaindexin];
370
 #else
371
            cmsUInt32Number alpha = inpackedsamplesize == 2 ?
372
                                     ((cmsUInt16Number *)accum)[prealphaindexin] :
373
                                     (accum[prealphaindexin]);
374
 #endif
375
            if (alpha == 0) {
376
                ZEROPACK(ContextID,p,output,accum);
377
                accum += inpackedsamplesize*(prealphaindexin+1);
378
            } else {
379
#endif
380
57.6M
                UNPACK(ContextID,p,currIn,accum,bppi,alpha);
381
#ifdef PREALPHA
382
 #ifndef UNPACKINCLUDESPREALPHA
383
  #ifdef XFORM_FLOAT
384
                {
385
                    int i;
386
                    cmsFloat32Number inva = 1.0f / alpha;
387
                    for (i = 0; i < numinchannels; i++)
388
                        currIn[i] *= inva;
389
                }
390
  #else
391
                {
392
                    int i;
393
                    cmsUInt32Number al = inpackedsamplesize == 1 ? alpha*0x101 : alpha;
394
                    cmsUInt32Number inva = 0xffff0000U / al;
395
                    for (i = 0; i < numinchannels; i++)
396
                        currIn[i] = ((currIn[i] * inva)>>16);
397
                }
398
  #endif
399
 #endif
400
#endif
401
57.6M
#ifdef CACHED
402
57.6M
                if (COMPARE(currIn, prevIn))
403
57.6M
#endif /* CACHED */
404
57.6M
                {
405
#ifdef GAMUTCHECK
406
 #ifdef XFORM_FLOAT
407
                    cmsFloat32Number OutOfGamut;
408
409
                    // Evaluate gamut marker.
410
                    cmsPipelineEvalFloat(currIn, &OutOfGamut, core->GamutCheck);
411
412
                    // Is current color out of gamut?
413
                    if (OutOfGamut > 0.0)
414
                        // Certainly, out of gamut
415
                        for (j=0; j < cmsMAXCHANNELS; j++)
416
                            fOut[j] = -1.0;
417
                    else
418
 #else
419
                    cmsUInt16Number wOutOfGamut;
420
421
                    evalGamut(ContextID, currIn, &wOutOfGamut, core->GamutCheck->Data);
422
                    if (wOutOfGamut >= 1)
423
                        /* RJW: Could be faster? copy once to a local buffer? */
424
                        cmsGetAlarmCodes(ContextID, wOut);
425
                    else
426
 #endif /* FLOAT_XFORM */
427
#endif /* GAMUTCHECK */
428
57.6M
                        eval(ContextID, currIn, wOut, data);
429
#ifdef NO_UNPACK
430
 #ifdef CACHED
431
                    prevIn = currIn;
432
 #endif
433
                    currIn = (XFORM_TYPE *)(((char *)currIn) + totalinbytes);
434
#else
435
57.6M
 #ifdef CACHED
436
57.6M
                    {XFORM_TYPE *tmp = currIn; currIn = prevIn; prevIn = tmp;} // SWAP
437
57.6M
 #endif /* CACHED */
438
57.6M
#endif /* NO_UNPACK */
439
57.6M
                }
440
#ifdef NO_PACK
441
                else
442
                    COPY_MATCHED(prevOut,wOut);
443
                prevOut = wOut;
444
#endif
445
#ifdef PREALPHA
446
 #ifndef PACKINCLUDESPREALPHA
447
  #ifdef XFORM_FLOAT
448
                {
449
                    int i;
450
                    for (i = 0; i < numoutchannels; i++)
451
                        wScaled = wOut[i] * alpha;
452
                }
453
  #else
454
                {
455
                    int i;
456
                    cmsUInt32Number al = inpackedsamplesize == 1 ? alpha*0x101 : alpha;
457
                    for (i = 0; i < numoutchannels; i++)
458
                        wScaled[i] = mul65535(wOut[i],al);
459
                }
460
  #endif
461
                PACK(ContextID,p,wScaled,output,bppo,alpha);
462
 #else
463
                PACK(ContextID,p,wOut,output,bppo,alpha);
464
 #endif
465
#else
466
57.6M
                PACK(ContextID,p,wOut,output,bppo,alpha);
467
57.6M
#endif
468
57.6M
                COPY_EXTRAS(p,accum,output);
469
#ifdef PREALPHA
470
            }
471
#endif
472
57.6M
        } /* End x loop */
473
57.6M
        in = (void *)((cmsUInt8Number *)in + Stride->BytesPerLineIn);
474
57.6M
        out = (void *)((cmsUInt8Number *)out + Stride->BytesPerLineOut);
475
57.6M
    } /* End y loop */
476
    /* The following code is only safe if we know that a given transform is
477
     * called on one thread a time. */
478
#if 0
479
#ifdef CACHED
480
#ifdef NO_UNPACK
481
    memcpy(p->Cache.CacheIn,prevIn, CMPBYTES);
482
#else
483
    memcpy(p->Cache.CacheIn, prevIn, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
484
#endif
485
#ifdef NO_PACK
486
    COPY_MATCHED(prevOut,p->Cache.CacheOut);
487
#else
488
    memcpy(p->Cache.CacheOut, wOut, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
489
#endif /* NO_PACK */
490
#endif /* CACHED */
491
#endif
492
57.6M
}
cmsxform.c:CachedXFORM4to3
Line
Count
Source
255
59.4k
{
256
59.4k
    _cmsTRANSFORMCORE *core = p->core;
257
59.4k
#ifndef NO_UNPACK
258
 #ifdef XFORM_FLOAT
259
    cmsFloat32Number wIn[cmsMAXCHANNELS*2];
260
 #else
261
59.4k
    cmsUInt16Number wIn[cmsMAXCHANNELS*2];
262
59.4k
 #endif
263
59.4k
 #define wIn0 (&wIn[0])
264
59.4k
 #define wIn1 (&wIn[cmsMAXCHANNELS])
265
59.4k
#endif
266
59.4k
    XFORM_TYPE *currIn;
267
59.4k
#ifdef CACHED
268
59.4k
    XFORM_TYPE *prevIn;
269
59.4k
#endif /* CACHED */
270
#ifdef NO_PACK
271
    XFORM_TYPE *wOut = (XFORM_TYPE *)out;
272
    XFORM_TYPE *prevOut = (XFORM_TYPE *)p->Cache.CacheOut;
273
#else
274
59.4k
    XFORM_TYPE wOut[cmsMAXCHANNELS];
275
59.4k
#endif
276
#if defined(PREALPHA) && !defined(PACKINCLUDESPREALPHA)
277
    XFORM_TYPE wScaled[cmsMAXCHANNELS];
278
#endif
279
#ifdef GAMUTCHECK
280
    _cmsPipelineEval16Fn evalGamut = core->GamutCheck->Eval16Fn;
281
#endif /* GAMUTCHECK */
282
#ifdef XFORM_FLOAT
283
    _cmsPipelineEvalFloatFn eval = core->Lut->EvalFloatFn;
284
    const cmsPipeline *data = core->Lut;
285
#else
286
59.4k
    _cmsPipelineEval16Fn eval = core->Lut->Eval16Fn;
287
59.4k
    void *data = core->Lut->Data;
288
59.4k
#endif
289
59.4k
    cmsUInt32Number bppi = Stride->BytesPerPlaneIn;
290
59.4k
    cmsUInt32Number bppo = Stride->BytesPerPlaneOut;
291
59.4k
#ifdef NUMINCHANNELS
292
59.4k
    int numinchannels = NUMINCHANNELS;
293
#else
294
    int numinchannels = T_CHANNELS(p->InputFormat);
295
#endif
296
59.4k
#ifdef NUMOUTCHANNELS
297
59.4k
    int numoutchannels = NUMOUTCHANNELS;
298
#else
299
    int numoutchannels = T_CHANNELS(p->OutputFormat);
300
#endif
301
59.4k
#ifdef NUMEXTRAS
302
59.4k
    int numextras = NUMEXTRAS;
303
#else
304
    int numextras = T_EXTRA(p->InputFormat);
305
#endif
306
59.4k
#ifdef INPACKEDSAMPLESIZE
307
59.4k
    int inpackedsamplesize = INPACKEDSAMPLESIZE;
308
#else
309
    int inpackedsamplesize = T_BYTES(p->InputFormat);
310
#endif
311
59.4k
#ifdef OUTPACKEDSAMPLESIZE
312
59.4k
    int outpackedsamplesize = OUTPACKEDSAMPLESIZE;
313
#else
314
    int outpackedsamplesize = T_BYTES(p->OutputFormat);
315
#endif
316
59.4k
    int prealphaindexin = numinchannels + numextras - 1;
317
59.4k
    int prealphaindexout = numoutchannels + numextras - 1;
318
59.4k
    int totalinbytes = (numinchannels + numextras)*inpackedsamplesize;
319
59.4k
    int totaloutbytes = (numoutchannels + numextras)*outpackedsamplesize;
320
321
    /* Silence some warnings */
322
59.4k
    (void)bppi;
323
59.4k
    (void)bppo;
324
59.4k
    (void)prealphaindexin;
325
59.4k
    (void)numextras;
326
59.4k
    (void)prealphaindexout;
327
59.4k
    (void)inpackedsamplesize;
328
59.4k
    (void)outpackedsamplesize;
329
59.4k
    (void)totalinbytes;
330
59.4k
    (void)totaloutbytes;
331
332
#ifdef BULK_COPY_EXTRAS
333
    if (core->dwOriginalFlags & cmsFLAGS_COPY_ALPHA)
334
        _cmsHandleExtraChannels(ContextID, p, in, out, PixelsPerLine, LineCount, Stride);
335
#endif
336
337
59.4k
    if (PixelsPerLine == 0)
338
0
        return;
339
340
#ifdef NO_UNPACK
341
    prevIn = (XFORM_TYPE *)p->Cache.CacheIn;
342
#else
343
59.4k
 #ifdef CACHED
344
    // Empty buffers for quick memcmp
345
59.4k
    memset(wIn1, 0, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
346
347
    // Get copy of zero cache
348
59.4k
    memcpy(wIn0, p->Cache.CacheIn,  sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
349
59.4k
    memcpy(wOut, p->Cache.CacheOut, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
350
351
    // The caller guarantees us that the cache is always valid on entry; if
352
    // the representation is changed, the cache is reset.
353
59.4k
    prevIn = wIn0;
354
59.4k
 #endif /* CACHED */
355
59.4k
    currIn = wIn1;
356
59.4k
#endif
357
358
118k
    while (LineCount-- > 0)
359
59.4k
    {
360
59.4k
        cmsUInt32Number n = PixelsPerLine;
361
59.4k
        cmsUInt8Number* accum  = (cmsUInt8Number*) in;
362
59.4k
        cmsUInt8Number* output = (cmsUInt8Number*) out;
363
#ifdef NO_UNPACK
364
        currIn = (XFORM_TYPE *)accum;
365
#endif
366
30.8M
        while (n-- > 0) { // prevIn == CacheIn, wOut = CacheOut
367
#ifdef PREALPHA
368
 #ifdef XFORM_FLOAT
369
            cmsFloat32Number alpha = ((cmsFloat32Number *)accum)[prealphaindexin];
370
 #else
371
            cmsUInt32Number alpha = inpackedsamplesize == 2 ?
372
                                     ((cmsUInt16Number *)accum)[prealphaindexin] :
373
                                     (accum[prealphaindexin]);
374
 #endif
375
            if (alpha == 0) {
376
                ZEROPACK(ContextID,p,output,accum);
377
                accum += inpackedsamplesize*(prealphaindexin+1);
378
            } else {
379
#endif
380
30.7M
                UNPACK(ContextID,p,currIn,accum,bppi,alpha);
381
#ifdef PREALPHA
382
 #ifndef UNPACKINCLUDESPREALPHA
383
  #ifdef XFORM_FLOAT
384
                {
385
                    int i;
386
                    cmsFloat32Number inva = 1.0f / alpha;
387
                    for (i = 0; i < numinchannels; i++)
388
                        currIn[i] *= inva;
389
                }
390
  #else
391
                {
392
                    int i;
393
                    cmsUInt32Number al = inpackedsamplesize == 1 ? alpha*0x101 : alpha;
394
                    cmsUInt32Number inva = 0xffff0000U / al;
395
                    for (i = 0; i < numinchannels; i++)
396
                        currIn[i] = ((currIn[i] * inva)>>16);
397
                }
398
  #endif
399
 #endif
400
#endif
401
30.7M
#ifdef CACHED
402
30.7M
                if (COMPARE(currIn, prevIn))
403
9.58M
#endif /* CACHED */
404
9.58M
                {
405
#ifdef GAMUTCHECK
406
 #ifdef XFORM_FLOAT
407
                    cmsFloat32Number OutOfGamut;
408
409
                    // Evaluate gamut marker.
410
                    cmsPipelineEvalFloat(currIn, &OutOfGamut, core->GamutCheck);
411
412
                    // Is current color out of gamut?
413
                    if (OutOfGamut > 0.0)
414
                        // Certainly, out of gamut
415
                        for (j=0; j < cmsMAXCHANNELS; j++)
416
                            fOut[j] = -1.0;
417
                    else
418
 #else
419
                    cmsUInt16Number wOutOfGamut;
420
421
                    evalGamut(ContextID, currIn, &wOutOfGamut, core->GamutCheck->Data);
422
                    if (wOutOfGamut >= 1)
423
                        /* RJW: Could be faster? copy once to a local buffer? */
424
                        cmsGetAlarmCodes(ContextID, wOut);
425
                    else
426
 #endif /* FLOAT_XFORM */
427
#endif /* GAMUTCHECK */
428
9.58M
                        eval(ContextID, currIn, wOut, data);
429
#ifdef NO_UNPACK
430
 #ifdef CACHED
431
                    prevIn = currIn;
432
 #endif
433
                    currIn = (XFORM_TYPE *)(((char *)currIn) + totalinbytes);
434
#else
435
9.58M
 #ifdef CACHED
436
9.58M
                    {XFORM_TYPE *tmp = currIn; currIn = prevIn; prevIn = tmp;} // SWAP
437
9.58M
 #endif /* CACHED */
438
9.58M
#endif /* NO_UNPACK */
439
9.58M
                }
440
#ifdef NO_PACK
441
                else
442
                    COPY_MATCHED(prevOut,wOut);
443
                prevOut = wOut;
444
#endif
445
#ifdef PREALPHA
446
 #ifndef PACKINCLUDESPREALPHA
447
  #ifdef XFORM_FLOAT
448
                {
449
                    int i;
450
                    for (i = 0; i < numoutchannels; i++)
451
                        wScaled = wOut[i] * alpha;
452
                }
453
  #else
454
                {
455
                    int i;
456
                    cmsUInt32Number al = inpackedsamplesize == 1 ? alpha*0x101 : alpha;
457
                    for (i = 0; i < numoutchannels; i++)
458
                        wScaled[i] = mul65535(wOut[i],al);
459
                }
460
  #endif
461
                PACK(ContextID,p,wScaled,output,bppo,alpha);
462
 #else
463
                PACK(ContextID,p,wOut,output,bppo,alpha);
464
 #endif
465
#else
466
30.7M
                PACK(ContextID,p,wOut,output,bppo,alpha);
467
30.7M
#endif
468
30.7M
                COPY_EXTRAS(p,accum,output);
469
#ifdef PREALPHA
470
            }
471
#endif
472
30.7M
        } /* End x loop */
473
59.4k
        in = (void *)((cmsUInt8Number *)in + Stride->BytesPerLineIn);
474
59.4k
        out = (void *)((cmsUInt8Number *)out + Stride->BytesPerLineOut);
475
59.4k
    } /* End y loop */
476
    /* The following code is only safe if we know that a given transform is
477
     * called on one thread a time. */
478
#if 0
479
#ifdef CACHED
480
#ifdef NO_UNPACK
481
    memcpy(p->Cache.CacheIn,prevIn, CMPBYTES);
482
#else
483
    memcpy(p->Cache.CacheIn, prevIn, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
484
#endif
485
#ifdef NO_PACK
486
    COPY_MATCHED(prevOut,p->Cache.CacheOut);
487
#else
488
    memcpy(p->Cache.CacheOut, wOut, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
489
#endif /* NO_PACK */
490
#endif /* CACHED */
491
#endif
492
59.4k
}
cmsxform.c:CachedXFORM4x2to3x2
Line
Count
Source
255
32.4M
{
256
32.4M
    _cmsTRANSFORMCORE *core = p->core;
257
32.4M
#ifndef NO_UNPACK
258
 #ifdef XFORM_FLOAT
259
    cmsFloat32Number wIn[cmsMAXCHANNELS*2];
260
 #else
261
32.4M
    cmsUInt16Number wIn[cmsMAXCHANNELS*2];
262
32.4M
 #endif
263
32.4M
 #define wIn0 (&wIn[0])
264
32.4M
 #define wIn1 (&wIn[cmsMAXCHANNELS])
265
32.4M
#endif
266
32.4M
    XFORM_TYPE *currIn;
267
32.4M
#ifdef CACHED
268
32.4M
    XFORM_TYPE *prevIn;
269
32.4M
#endif /* CACHED */
270
#ifdef NO_PACK
271
    XFORM_TYPE *wOut = (XFORM_TYPE *)out;
272
    XFORM_TYPE *prevOut = (XFORM_TYPE *)p->Cache.CacheOut;
273
#else
274
32.4M
    XFORM_TYPE wOut[cmsMAXCHANNELS];
275
32.4M
#endif
276
#if defined(PREALPHA) && !defined(PACKINCLUDESPREALPHA)
277
    XFORM_TYPE wScaled[cmsMAXCHANNELS];
278
#endif
279
#ifdef GAMUTCHECK
280
    _cmsPipelineEval16Fn evalGamut = core->GamutCheck->Eval16Fn;
281
#endif /* GAMUTCHECK */
282
#ifdef XFORM_FLOAT
283
    _cmsPipelineEvalFloatFn eval = core->Lut->EvalFloatFn;
284
    const cmsPipeline *data = core->Lut;
285
#else
286
32.4M
    _cmsPipelineEval16Fn eval = core->Lut->Eval16Fn;
287
32.4M
    void *data = core->Lut->Data;
288
32.4M
#endif
289
32.4M
    cmsUInt32Number bppi = Stride->BytesPerPlaneIn;
290
32.4M
    cmsUInt32Number bppo = Stride->BytesPerPlaneOut;
291
32.4M
#ifdef NUMINCHANNELS
292
32.4M
    int numinchannels = NUMINCHANNELS;
293
#else
294
    int numinchannels = T_CHANNELS(p->InputFormat);
295
#endif
296
32.4M
#ifdef NUMOUTCHANNELS
297
32.4M
    int numoutchannels = NUMOUTCHANNELS;
298
#else
299
    int numoutchannels = T_CHANNELS(p->OutputFormat);
300
#endif
301
32.4M
#ifdef NUMEXTRAS
302
32.4M
    int numextras = NUMEXTRAS;
303
#else
304
    int numextras = T_EXTRA(p->InputFormat);
305
#endif
306
32.4M
#ifdef INPACKEDSAMPLESIZE
307
32.4M
    int inpackedsamplesize = INPACKEDSAMPLESIZE;
308
#else
309
    int inpackedsamplesize = T_BYTES(p->InputFormat);
310
#endif
311
32.4M
#ifdef OUTPACKEDSAMPLESIZE
312
32.4M
    int outpackedsamplesize = OUTPACKEDSAMPLESIZE;
313
#else
314
    int outpackedsamplesize = T_BYTES(p->OutputFormat);
315
#endif
316
32.4M
    int prealphaindexin = numinchannels + numextras - 1;
317
32.4M
    int prealphaindexout = numoutchannels + numextras - 1;
318
32.4M
    int totalinbytes = (numinchannels + numextras)*inpackedsamplesize;
319
32.4M
    int totaloutbytes = (numoutchannels + numextras)*outpackedsamplesize;
320
321
    /* Silence some warnings */
322
32.4M
    (void)bppi;
323
32.4M
    (void)bppo;
324
32.4M
    (void)prealphaindexin;
325
32.4M
    (void)numextras;
326
32.4M
    (void)prealphaindexout;
327
32.4M
    (void)inpackedsamplesize;
328
32.4M
    (void)outpackedsamplesize;
329
32.4M
    (void)totalinbytes;
330
32.4M
    (void)totaloutbytes;
331
332
#ifdef BULK_COPY_EXTRAS
333
    if (core->dwOriginalFlags & cmsFLAGS_COPY_ALPHA)
334
        _cmsHandleExtraChannels(ContextID, p, in, out, PixelsPerLine, LineCount, Stride);
335
#endif
336
337
32.4M
    if (PixelsPerLine == 0)
338
0
        return;
339
340
#ifdef NO_UNPACK
341
    prevIn = (XFORM_TYPE *)p->Cache.CacheIn;
342
#else
343
32.4M
 #ifdef CACHED
344
    // Empty buffers for quick memcmp
345
32.4M
    memset(wIn1, 0, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
346
347
    // Get copy of zero cache
348
32.4M
    memcpy(wIn0, p->Cache.CacheIn,  sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
349
32.4M
    memcpy(wOut, p->Cache.CacheOut, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
350
351
    // The caller guarantees us that the cache is always valid on entry; if
352
    // the representation is changed, the cache is reset.
353
32.4M
    prevIn = wIn0;
354
32.4M
 #endif /* CACHED */
355
32.4M
    currIn = wIn1;
356
32.4M
#endif
357
358
64.8M
    while (LineCount-- > 0)
359
32.4M
    {
360
32.4M
        cmsUInt32Number n = PixelsPerLine;
361
32.4M
        cmsUInt8Number* accum  = (cmsUInt8Number*) in;
362
32.4M
        cmsUInt8Number* output = (cmsUInt8Number*) out;
363
#ifdef NO_UNPACK
364
        currIn = (XFORM_TYPE *)accum;
365
#endif
366
64.8M
        while (n-- > 0) { // prevIn == CacheIn, wOut = CacheOut
367
#ifdef PREALPHA
368
 #ifdef XFORM_FLOAT
369
            cmsFloat32Number alpha = ((cmsFloat32Number *)accum)[prealphaindexin];
370
 #else
371
            cmsUInt32Number alpha = inpackedsamplesize == 2 ?
372
                                     ((cmsUInt16Number *)accum)[prealphaindexin] :
373
                                     (accum[prealphaindexin]);
374
 #endif
375
            if (alpha == 0) {
376
                ZEROPACK(ContextID,p,output,accum);
377
                accum += inpackedsamplesize*(prealphaindexin+1);
378
            } else {
379
#endif
380
32.4M
                UNPACK(ContextID,p,currIn,accum,bppi,alpha);
381
#ifdef PREALPHA
382
 #ifndef UNPACKINCLUDESPREALPHA
383
  #ifdef XFORM_FLOAT
384
                {
385
                    int i;
386
                    cmsFloat32Number inva = 1.0f / alpha;
387
                    for (i = 0; i < numinchannels; i++)
388
                        currIn[i] *= inva;
389
                }
390
  #else
391
                {
392
                    int i;
393
                    cmsUInt32Number al = inpackedsamplesize == 1 ? alpha*0x101 : alpha;
394
                    cmsUInt32Number inva = 0xffff0000U / al;
395
                    for (i = 0; i < numinchannels; i++)
396
                        currIn[i] = ((currIn[i] * inva)>>16);
397
                }
398
  #endif
399
 #endif
400
#endif
401
32.4M
#ifdef CACHED
402
32.4M
                if (COMPARE(currIn, prevIn))
403
32.4M
#endif /* CACHED */
404
32.4M
                {
405
#ifdef GAMUTCHECK
406
 #ifdef XFORM_FLOAT
407
                    cmsFloat32Number OutOfGamut;
408
409
                    // Evaluate gamut marker.
410
                    cmsPipelineEvalFloat(currIn, &OutOfGamut, core->GamutCheck);
411
412
                    // Is current color out of gamut?
413
                    if (OutOfGamut > 0.0)
414
                        // Certainly, out of gamut
415
                        for (j=0; j < cmsMAXCHANNELS; j++)
416
                            fOut[j] = -1.0;
417
                    else
418
 #else
419
                    cmsUInt16Number wOutOfGamut;
420
421
                    evalGamut(ContextID, currIn, &wOutOfGamut, core->GamutCheck->Data);
422
                    if (wOutOfGamut >= 1)
423
                        /* RJW: Could be faster? copy once to a local buffer? */
424
                        cmsGetAlarmCodes(ContextID, wOut);
425
                    else
426
 #endif /* FLOAT_XFORM */
427
#endif /* GAMUTCHECK */
428
32.4M
                        eval(ContextID, currIn, wOut, data);
429
#ifdef NO_UNPACK
430
 #ifdef CACHED
431
                    prevIn = currIn;
432
 #endif
433
                    currIn = (XFORM_TYPE *)(((char *)currIn) + totalinbytes);
434
#else
435
32.4M
 #ifdef CACHED
436
32.4M
                    {XFORM_TYPE *tmp = currIn; currIn = prevIn; prevIn = tmp;} // SWAP
437
32.4M
 #endif /* CACHED */
438
32.4M
#endif /* NO_UNPACK */
439
32.4M
                }
440
#ifdef NO_PACK
441
                else
442
                    COPY_MATCHED(prevOut,wOut);
443
                prevOut = wOut;
444
#endif
445
#ifdef PREALPHA
446
 #ifndef PACKINCLUDESPREALPHA
447
  #ifdef XFORM_FLOAT
448
                {
449
                    int i;
450
                    for (i = 0; i < numoutchannels; i++)
451
                        wScaled = wOut[i] * alpha;
452
                }
453
  #else
454
                {
455
                    int i;
456
                    cmsUInt32Number al = inpackedsamplesize == 1 ? alpha*0x101 : alpha;
457
                    for (i = 0; i < numoutchannels; i++)
458
                        wScaled[i] = mul65535(wOut[i],al);
459
                }
460
  #endif
461
                PACK(ContextID,p,wScaled,output,bppo,alpha);
462
 #else
463
                PACK(ContextID,p,wOut,output,bppo,alpha);
464
 #endif
465
#else
466
32.4M
                PACK(ContextID,p,wOut,output,bppo,alpha);
467
32.4M
#endif
468
32.4M
                COPY_EXTRAS(p,accum,output);
469
#ifdef PREALPHA
470
            }
471
#endif
472
32.4M
        } /* End x loop */
473
32.4M
        in = (void *)((cmsUInt8Number *)in + Stride->BytesPerLineIn);
474
32.4M
        out = (void *)((cmsUInt8Number *)out + Stride->BytesPerLineOut);
475
32.4M
    } /* End y loop */
476
    /* The following code is only safe if we know that a given transform is
477
     * called on one thread a time. */
478
#if 0
479
#ifdef CACHED
480
#ifdef NO_UNPACK
481
    memcpy(p->Cache.CacheIn,prevIn, CMPBYTES);
482
#else
483
    memcpy(p->Cache.CacheIn, prevIn, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
484
#endif
485
#ifdef NO_PACK
486
    COPY_MATCHED(prevOut,p->Cache.CacheOut);
487
#else
488
    memcpy(p->Cache.CacheOut, wOut, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
489
#endif /* NO_PACK */
490
#endif /* CACHED */
491
#endif
492
32.4M
}
Unexecuted instantiation: cmsxform.c:CachedXFORM4to4
Unexecuted instantiation: cmsxform.c:CachedXFORM4x2to4x2
Unexecuted instantiation: cmsxform.c:CachedXFORM4
cmsxform.c:CachedXFORM8
Line
Count
Source
255
11.8k
{
256
11.8k
    _cmsTRANSFORMCORE *core = p->core;
257
11.8k
#ifndef NO_UNPACK
258
 #ifdef XFORM_FLOAT
259
    cmsFloat32Number wIn[cmsMAXCHANNELS*2];
260
 #else
261
11.8k
    cmsUInt16Number wIn[cmsMAXCHANNELS*2];
262
11.8k
 #endif
263
11.8k
 #define wIn0 (&wIn[0])
264
11.8k
 #define wIn1 (&wIn[cmsMAXCHANNELS])
265
11.8k
#endif
266
11.8k
    XFORM_TYPE *currIn;
267
11.8k
#ifdef CACHED
268
11.8k
    XFORM_TYPE *prevIn;
269
11.8k
#endif /* CACHED */
270
#ifdef NO_PACK
271
    XFORM_TYPE *wOut = (XFORM_TYPE *)out;
272
    XFORM_TYPE *prevOut = (XFORM_TYPE *)p->Cache.CacheOut;
273
#else
274
11.8k
    XFORM_TYPE wOut[cmsMAXCHANNELS];
275
11.8k
#endif
276
#if defined(PREALPHA) && !defined(PACKINCLUDESPREALPHA)
277
    XFORM_TYPE wScaled[cmsMAXCHANNELS];
278
#endif
279
#ifdef GAMUTCHECK
280
    _cmsPipelineEval16Fn evalGamut = core->GamutCheck->Eval16Fn;
281
#endif /* GAMUTCHECK */
282
#ifdef XFORM_FLOAT
283
    _cmsPipelineEvalFloatFn eval = core->Lut->EvalFloatFn;
284
    const cmsPipeline *data = core->Lut;
285
#else
286
11.8k
    _cmsPipelineEval16Fn eval = core->Lut->Eval16Fn;
287
11.8k
    void *data = core->Lut->Data;
288
11.8k
#endif
289
11.8k
    cmsUInt32Number bppi = Stride->BytesPerPlaneIn;
290
11.8k
    cmsUInt32Number bppo = Stride->BytesPerPlaneOut;
291
#ifdef NUMINCHANNELS
292
    int numinchannels = NUMINCHANNELS;
293
#else
294
11.8k
    int numinchannels = T_CHANNELS(p->InputFormat);
295
11.8k
#endif
296
#ifdef NUMOUTCHANNELS
297
    int numoutchannels = NUMOUTCHANNELS;
298
#else
299
11.8k
    int numoutchannels = T_CHANNELS(p->OutputFormat);
300
11.8k
#endif
301
11.8k
#ifdef NUMEXTRAS
302
11.8k
    int numextras = NUMEXTRAS;
303
#else
304
    int numextras = T_EXTRA(p->InputFormat);
305
#endif
306
#ifdef INPACKEDSAMPLESIZE
307
    int inpackedsamplesize = INPACKEDSAMPLESIZE;
308
#else
309
11.8k
    int inpackedsamplesize = T_BYTES(p->InputFormat);
310
11.8k
#endif
311
#ifdef OUTPACKEDSAMPLESIZE
312
    int outpackedsamplesize = OUTPACKEDSAMPLESIZE;
313
#else
314
11.8k
    int outpackedsamplesize = T_BYTES(p->OutputFormat);
315
11.8k
#endif
316
11.8k
    int prealphaindexin = numinchannels + numextras - 1;
317
11.8k
    int prealphaindexout = numoutchannels + numextras - 1;
318
11.8k
    int totalinbytes = (numinchannels + numextras)*inpackedsamplesize;
319
11.8k
    int totaloutbytes = (numoutchannels + numextras)*outpackedsamplesize;
320
321
    /* Silence some warnings */
322
11.8k
    (void)bppi;
323
11.8k
    (void)bppo;
324
11.8k
    (void)prealphaindexin;
325
11.8k
    (void)numextras;
326
11.8k
    (void)prealphaindexout;
327
11.8k
    (void)inpackedsamplesize;
328
11.8k
    (void)outpackedsamplesize;
329
11.8k
    (void)totalinbytes;
330
11.8k
    (void)totaloutbytes;
331
332
#ifdef BULK_COPY_EXTRAS
333
    if (core->dwOriginalFlags & cmsFLAGS_COPY_ALPHA)
334
        _cmsHandleExtraChannels(ContextID, p, in, out, PixelsPerLine, LineCount, Stride);
335
#endif
336
337
11.8k
    if (PixelsPerLine == 0)
338
0
        return;
339
340
#ifdef NO_UNPACK
341
    prevIn = (XFORM_TYPE *)p->Cache.CacheIn;
342
#else
343
11.8k
 #ifdef CACHED
344
    // Empty buffers for quick memcmp
345
11.8k
    memset(wIn1, 0, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
346
347
    // Get copy of zero cache
348
11.8k
    memcpy(wIn0, p->Cache.CacheIn,  sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
349
11.8k
    memcpy(wOut, p->Cache.CacheOut, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
350
351
    // The caller guarantees us that the cache is always valid on entry; if
352
    // the representation is changed, the cache is reset.
353
11.8k
    prevIn = wIn0;
354
11.8k
 #endif /* CACHED */
355
11.8k
    currIn = wIn1;
356
11.8k
#endif
357
358
128k
    while (LineCount-- > 0)
359
116k
    {
360
116k
        cmsUInt32Number n = PixelsPerLine;
361
116k
        cmsUInt8Number* accum  = (cmsUInt8Number*) in;
362
116k
        cmsUInt8Number* output = (cmsUInt8Number*) out;
363
#ifdef NO_UNPACK
364
        currIn = (XFORM_TYPE *)accum;
365
#endif
366
112M
        while (n-- > 0) { // prevIn == CacheIn, wOut = CacheOut
367
#ifdef PREALPHA
368
 #ifdef XFORM_FLOAT
369
            cmsFloat32Number alpha = ((cmsFloat32Number *)accum)[prealphaindexin];
370
 #else
371
            cmsUInt32Number alpha = inpackedsamplesize == 2 ?
372
                                     ((cmsUInt16Number *)accum)[prealphaindexin] :
373
                                     (accum[prealphaindexin]);
374
 #endif
375
            if (alpha == 0) {
376
                ZEROPACK(ContextID,p,output,accum);
377
                accum += inpackedsamplesize*(prealphaindexin+1);
378
            } else {
379
#endif
380
112M
                UNPACK(ContextID,p,currIn,accum,bppi,alpha);
381
#ifdef PREALPHA
382
 #ifndef UNPACKINCLUDESPREALPHA
383
  #ifdef XFORM_FLOAT
384
                {
385
                    int i;
386
                    cmsFloat32Number inva = 1.0f / alpha;
387
                    for (i = 0; i < numinchannels; i++)
388
                        currIn[i] *= inva;
389
                }
390
  #else
391
                {
392
                    int i;
393
                    cmsUInt32Number al = inpackedsamplesize == 1 ? alpha*0x101 : alpha;
394
                    cmsUInt32Number inva = 0xffff0000U / al;
395
                    for (i = 0; i < numinchannels; i++)
396
                        currIn[i] = ((currIn[i] * inva)>>16);
397
                }
398
  #endif
399
 #endif
400
#endif
401
112M
#ifdef CACHED
402
112M
                if (COMPARE(currIn, prevIn))
403
4.10M
#endif /* CACHED */
404
4.10M
                {
405
#ifdef GAMUTCHECK
406
 #ifdef XFORM_FLOAT
407
                    cmsFloat32Number OutOfGamut;
408
409
                    // Evaluate gamut marker.
410
                    cmsPipelineEvalFloat(currIn, &OutOfGamut, core->GamutCheck);
411
412
                    // Is current color out of gamut?
413
                    if (OutOfGamut > 0.0)
414
                        // Certainly, out of gamut
415
                        for (j=0; j < cmsMAXCHANNELS; j++)
416
                            fOut[j] = -1.0;
417
                    else
418
 #else
419
                    cmsUInt16Number wOutOfGamut;
420
421
                    evalGamut(ContextID, currIn, &wOutOfGamut, core->GamutCheck->Data);
422
                    if (wOutOfGamut >= 1)
423
                        /* RJW: Could be faster? copy once to a local buffer? */
424
                        cmsGetAlarmCodes(ContextID, wOut);
425
                    else
426
 #endif /* FLOAT_XFORM */
427
#endif /* GAMUTCHECK */
428
4.10M
                        eval(ContextID, currIn, wOut, data);
429
#ifdef NO_UNPACK
430
 #ifdef CACHED
431
                    prevIn = currIn;
432
 #endif
433
                    currIn = (XFORM_TYPE *)(((char *)currIn) + totalinbytes);
434
#else
435
4.10M
 #ifdef CACHED
436
4.10M
                    {XFORM_TYPE *tmp = currIn; currIn = prevIn; prevIn = tmp;} // SWAP
437
4.10M
 #endif /* CACHED */
438
4.10M
#endif /* NO_UNPACK */
439
4.10M
                }
440
#ifdef NO_PACK
441
                else
442
                    COPY_MATCHED(prevOut,wOut);
443
                prevOut = wOut;
444
#endif
445
#ifdef PREALPHA
446
 #ifndef PACKINCLUDESPREALPHA
447
  #ifdef XFORM_FLOAT
448
                {
449
                    int i;
450
                    for (i = 0; i < numoutchannels; i++)
451
                        wScaled = wOut[i] * alpha;
452
                }
453
  #else
454
                {
455
                    int i;
456
                    cmsUInt32Number al = inpackedsamplesize == 1 ? alpha*0x101 : alpha;
457
                    for (i = 0; i < numoutchannels; i++)
458
                        wScaled[i] = mul65535(wOut[i],al);
459
                }
460
  #endif
461
                PACK(ContextID,p,wScaled,output,bppo,alpha);
462
 #else
463
                PACK(ContextID,p,wOut,output,bppo,alpha);
464
 #endif
465
#else
466
112M
                PACK(ContextID,p,wOut,output,bppo,alpha);
467
112M
#endif
468
112M
                COPY_EXTRAS(p,accum,output);
469
#ifdef PREALPHA
470
            }
471
#endif
472
112M
        } /* End x loop */
473
116k
        in = (void *)((cmsUInt8Number *)in + Stride->BytesPerLineIn);
474
116k
        out = (void *)((cmsUInt8Number *)out + Stride->BytesPerLineOut);
475
116k
    } /* End y loop */
476
    /* The following code is only safe if we know that a given transform is
477
     * called on one thread a time. */
478
#if 0
479
#ifdef CACHED
480
#ifdef NO_UNPACK
481
    memcpy(p->Cache.CacheIn,prevIn, CMPBYTES);
482
#else
483
    memcpy(p->Cache.CacheIn, prevIn, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
484
#endif
485
#ifdef NO_PACK
486
    COPY_MATCHED(prevOut,p->Cache.CacheOut);
487
#else
488
    memcpy(p->Cache.CacheOut, wOut, sizeof(XFORM_TYPE) * cmsMAXCHANNELS);
489
#endif /* NO_PACK */
490
#endif /* CACHED */
491
#endif
492
11.8k
}
493
494
#undef wIn0
495
#undef wIn1
496
#undef XFORM_TYPE
497
#undef XFORM_FLOAT
498
499
#undef FUNCTION_NAME
500
#undef COMPARE
501
#undef CMPBYTES
502
#undef OUTBYTES
503
#undef UNPACK
504
#undef NO_UNPACK
505
#undef PACK
506
#undef NO_PACK
507
#undef UNPACKFN
508
#undef PACKFN
509
#undef GAMUTCHECK
510
#undef CACHED
511
#undef COPY_MATCHED
512
#undef EXTRABYTES
513
#undef COPY_EXTRAS
514
#undef BULK_COPY_EXTRAS
515
#undef PREALPHA
516
#undef ZEROPACK
517
#undef XFORMVARS
518
#undef UNPRE
519
#undef REPRE
520
#undef INPACKEDSAMPLESIZE
521
#undef OUTPACKEDSAMPLESIZE
522
#undef NUMINCHANNELS
523
#undef NUMOUTCHANNELS
524
#undef NUMEXTRAS