< prev index next >

src/java.desktop/share/native/liblcms/cmsgmt.c

Print this page

231     cmsFloat64Number Threshold;         // The threshold 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_THRESHOLD
237 // of maximum are considered out of gamut.
238 
239 #define ERR_THRESHOLD      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 
264     memmove(&LabIn2, &LabOut1, sizeof(cmsCIELab));
265 
266     // Try again, but this time taking Check as input
267     cmsDoTransform(t -> hForward, &LabOut1, Proof2, 1);
268     cmsDoTransform(t -> hReverse, Proof2, &LabOut2, 1);
269 
270     // Take difference of direct value
271     dE1 = cmsDeltaE(&LabIn1, &LabOut1);

608                     else
609                         if (h >= 225. && h < 315.) {
610                             // clip by bmin
611                             Lab -> b = bmin;
612                             Lab -> a = bmin / slope;
613                         }
614                         else  {
615                             cmsSignalError(0, cmsERROR_RANGE, "Invalid angle");
616                             return FALSE;
617                         }
618 
619     }
620 
621     return TRUE;
622 }
623 
624 // Detect whatever a given ICC profile works in linear (gamma 1.0) space
625 // Actually, doing that "well" is quite hard, since every component may behave completely different.
626 // Since the true point of this function is to detect suitable optimizations, I am imposing some requirements
627 // that simplifies things: only RGB, and only profiles that can got in both directions.
628 // The algorithm obtains Y from a syntetical gray R=G=B. Then least squares fitting is used to estimate gamma.
629 // For gamma close to 1.0, RGB is linear. On profiles not supported, -1 is returned.
630 
631 cmsFloat64Number CMSEXPORT cmsDetectRGBProfileGamma(cmsHPROFILE hProfile, cmsFloat64Number threshold)
632 {
633     cmsContext ContextID;
634     cmsHPROFILE hXYZ;
635     cmsHTRANSFORM xform;
636     cmsToneCurve* Y_curve;
637     cmsUInt16Number rgb[256][3];
638     cmsCIEXYZ XYZ[256];
639     cmsFloat32Number Y_normalized[256];
640     cmsFloat64Number gamma;
641     cmsProfileClassSignature cl;
642     int i;
643 
644     if (cmsGetColorSpace(hProfile) != cmsSigRgbData)
645         return -1;
646 
647     cl = cmsGetDeviceClass(hProfile);
648     if (cl != cmsSigInputClass && cl != cmsSigDisplayClass &&

231     cmsFloat64Number Threshold;         // The threshold 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_THRESHOLD
237 // of maximum are considered out of gamut.
238 
239 #define ERR_THRESHOLD      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. NEVER READ, USED FOR DEBUG PURPOSES.
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 
264     memmove(&LabIn2, &LabOut1, sizeof(cmsCIELab));
265 
266     // Try again, but this time taking Check as input
267     cmsDoTransform(t -> hForward, &LabOut1, Proof2, 1);
268     cmsDoTransform(t -> hReverse, Proof2, &LabOut2, 1);
269 
270     // Take difference of direct value
271     dE1 = cmsDeltaE(&LabIn1, &LabOut1);

608                     else
609                         if (h >= 225. && h < 315.) {
610                             // clip by bmin
611                             Lab -> b = bmin;
612                             Lab -> a = bmin / slope;
613                         }
614                         else  {
615                             cmsSignalError(0, cmsERROR_RANGE, "Invalid angle");
616                             return FALSE;
617                         }
618 
619     }
620 
621     return TRUE;
622 }
623 
624 // Detect whatever a given ICC profile works in linear (gamma 1.0) space
625 // Actually, doing that "well" is quite hard, since every component may behave completely different.
626 // Since the true point of this function is to detect suitable optimizations, I am imposing some requirements
627 // that simplifies things: only RGB, and only profiles that can got in both directions.
628 // The algorithm obtains Y from a synthetical gray R=G=B. Then least squares fitting is used to estimate gamma.
629 // For gamma close to 1.0, RGB is linear. On profiles not supported, -1 is returned.
630 
631 cmsFloat64Number CMSEXPORT cmsDetectRGBProfileGamma(cmsHPROFILE hProfile, cmsFloat64Number threshold)
632 {
633     cmsContext ContextID;
634     cmsHPROFILE hXYZ;
635     cmsHTRANSFORM xform;
636     cmsToneCurve* Y_curve;
637     cmsUInt16Number rgb[256][3];
638     cmsCIEXYZ XYZ[256];
639     cmsFloat32Number Y_normalized[256];
640     cmsFloat64Number gamma;
641     cmsProfileClassSignature cl;
642     int i;
643 
644     if (cmsGetColorSpace(hProfile) != cmsSigRgbData)
645         return -1;
646 
647     cl = cmsGetDeviceClass(hProfile);
648     if (cl != cmsSigInputClass && cl != cmsSigDisplayClass &&
< prev index next >