13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 */
24
25 // This file is available under and governed by the GNU General Public
26 // License version 2 only, as published by the Free Software Foundation.
27 // However, the following notice accompanied the original version of this
28 // file:
29 //
30 //---------------------------------------------------------------------------------
31 //
32 // Little Color Management System
33 // Copyright (c) 1998-2017 Marti Maria Saguer
34 //
35 // Permission is hereby granted, free of charge, to any person obtaining
36 // a copy of this software and associated documentation files (the "Software"),
37 // to deal in the Software without restriction, including without limitation
38 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
39 // and/or sell copies of the Software, and to permit persons to whom the Software
40 // is furnished to do so, subject to the following conditions:
41 //
42 // The above copyright notice and this permission notice shall be included in
43 // all copies or substantial portions of the Software.
44 //
45 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
46 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
47 // THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
48 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
49 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
50 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
51 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
52 //
53 //---------------------------------------------------------------------------------
223 // Gamut LUT Creation -----------------------------------------------------------------------------------------
224
225 // Used by gamut & softproofing
226
227 typedef struct {
228
229 cmsHTRANSFORM hInput; // From whatever input color space. 16 bits to DBL
230 cmsHTRANSFORM hForward, hReverse; // Transforms going from Lab to colorant and back
231 cmsFloat64Number Thereshold; // The thereshold after which is considered out of gamut
232
233 } GAMUTCHAIN;
234
235 // This sampler does compute gamut boundaries by comparing original
236 // values with a transform going back and forth. Values above ERR_THERESHOLD
237 // of maximum are considered out of gamut.
238
239 #define ERR_THERESHOLD 5
240
241
242 static
243 int GamutSampler(register const cmsUInt16Number In[], register cmsUInt16Number Out[], register void* Cargo)
244 {
245 GAMUTCHAIN* t = (GAMUTCHAIN* ) Cargo;
246 cmsCIELab LabIn1, LabOut1;
247 cmsCIELab LabIn2, LabOut2;
248 cmsUInt16Number Proof[cmsMAXCHANNELS], Proof2[cmsMAXCHANNELS];
249 cmsFloat64Number dE1, dE2, ErrorRatio;
250
251 // Assume in-gamut by default.
252 ErrorRatio = 1.0;
253
254 // Convert input to Lab
255 cmsDoTransform(t -> hInput, In, &LabIn1, 1);
256
257 // converts from PCS to colorant. This always
258 // does return in-gamut values,
259 cmsDoTransform(t -> hForward, &LabIn1, Proof, 1);
260
261 // Now, do the inverse, from colorant to PCS.
262 cmsDoTransform(t -> hReverse, Proof, &LabOut1, 1);
263
436 if (hLab) cmsCloseProfile(hLab);
437
438 // And return computed hull
439 return Gamut;
440 }
441
442 // Total Area Coverage estimation ----------------------------------------------------------------
443
444 typedef struct {
445 cmsUInt32Number nOutputChans;
446 cmsHTRANSFORM hRoundTrip;
447 cmsFloat32Number MaxTAC;
448 cmsFloat32Number MaxInput[cmsMAXCHANNELS];
449
450 } cmsTACestimator;
451
452
453 // This callback just accounts the maximum ink dropped in the given node. It does not populate any
454 // memory, as the destination table is NULL. Its only purpose it to know the global maximum.
455 static
456 int EstimateTAC(register const cmsUInt16Number In[], register cmsUInt16Number Out[], register void * Cargo)
457 {
458 cmsTACestimator* bp = (cmsTACestimator*) Cargo;
459 cmsFloat32Number RoundTrip[cmsMAXCHANNELS];
460 cmsUInt32Number i;
461 cmsFloat32Number Sum;
462
463
464 // Evaluate the xform
465 cmsDoTransform(bp->hRoundTrip, In, RoundTrip, 1);
466
467 // All all amounts of ink
468 for (Sum=0, i=0; i < bp ->nOutputChans; i++)
469 Sum += RoundTrip[i];
470
471 // If above maximum, keep track of input values
472 if (Sum > bp ->MaxTAC) {
473
474 bp ->MaxTAC = Sum;
475
476 for (i=0; i < bp ->nOutputChans; i++) {
|
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 */
24
25 // This file is available under and governed by the GNU General Public
26 // License version 2 only, as published by the Free Software Foundation.
27 // However, the following notice accompanied the original version of this
28 // file:
29 //
30 //---------------------------------------------------------------------------------
31 //
32 // Little Color Management System
33 // Copyright (c) 1998-2020 Marti Maria Saguer
34 //
35 // Permission is hereby granted, free of charge, to any person obtaining
36 // a copy of this software and associated documentation files (the "Software"),
37 // to deal in the Software without restriction, including without limitation
38 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
39 // and/or sell copies of the Software, and to permit persons to whom the Software
40 // is furnished to do so, subject to the following conditions:
41 //
42 // The above copyright notice and this permission notice shall be included in
43 // all copies or substantial portions of the Software.
44 //
45 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
46 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
47 // THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
48 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
49 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
50 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
51 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
52 //
53 //---------------------------------------------------------------------------------
223 // Gamut LUT Creation -----------------------------------------------------------------------------------------
224
225 // Used by gamut & softproofing
226
227 typedef struct {
228
229 cmsHTRANSFORM hInput; // From whatever input color space. 16 bits to DBL
230 cmsHTRANSFORM hForward, hReverse; // Transforms going from Lab to colorant and back
231 cmsFloat64Number Thereshold; // The thereshold after which is considered out of gamut
232
233 } GAMUTCHAIN;
234
235 // This sampler does compute gamut boundaries by comparing original
236 // values with a transform going back and forth. Values above ERR_THERESHOLD
237 // of maximum are considered out of gamut.
238
239 #define ERR_THERESHOLD 5
240
241
242 static
243 int GamutSampler(CMSREGISTER const cmsUInt16Number In[], CMSREGISTER cmsUInt16Number Out[], CMSREGISTER void* Cargo)
244 {
245 GAMUTCHAIN* t = (GAMUTCHAIN* ) Cargo;
246 cmsCIELab LabIn1, LabOut1;
247 cmsCIELab LabIn2, LabOut2;
248 cmsUInt16Number Proof[cmsMAXCHANNELS], Proof2[cmsMAXCHANNELS];
249 cmsFloat64Number dE1, dE2, ErrorRatio;
250
251 // Assume in-gamut by default.
252 ErrorRatio = 1.0;
253
254 // Convert input to Lab
255 cmsDoTransform(t -> hInput, In, &LabIn1, 1);
256
257 // converts from PCS to colorant. This always
258 // does return in-gamut values,
259 cmsDoTransform(t -> hForward, &LabIn1, Proof, 1);
260
261 // Now, do the inverse, from colorant to PCS.
262 cmsDoTransform(t -> hReverse, Proof, &LabOut1, 1);
263
436 if (hLab) cmsCloseProfile(hLab);
437
438 // And return computed hull
439 return Gamut;
440 }
441
442 // Total Area Coverage estimation ----------------------------------------------------------------
443
444 typedef struct {
445 cmsUInt32Number nOutputChans;
446 cmsHTRANSFORM hRoundTrip;
447 cmsFloat32Number MaxTAC;
448 cmsFloat32Number MaxInput[cmsMAXCHANNELS];
449
450 } cmsTACestimator;
451
452
453 // This callback just accounts the maximum ink dropped in the given node. It does not populate any
454 // memory, as the destination table is NULL. Its only purpose it to know the global maximum.
455 static
456 int EstimateTAC(CMSREGISTER const cmsUInt16Number In[], CMSREGISTER cmsUInt16Number Out[], CMSREGISTER void * Cargo)
457 {
458 cmsTACestimator* bp = (cmsTACestimator*) Cargo;
459 cmsFloat32Number RoundTrip[cmsMAXCHANNELS];
460 cmsUInt32Number i;
461 cmsFloat32Number Sum;
462
463
464 // Evaluate the xform
465 cmsDoTransform(bp->hRoundTrip, In, RoundTrip, 1);
466
467 // All all amounts of ink
468 for (Sum=0, i=0; i < bp ->nOutputChans; i++)
469 Sum += RoundTrip[i];
470
471 // If above maximum, keep track of input values
472 if (Sum > bp ->MaxTAC) {
473
474 bp ->MaxTAC = Sum;
475
476 for (i=0; i < bp ->nOutputChans; i++) {
|