< prev index next >
src/share/native/sun/java2d/cmm/lcms/cmsopt.c
Print this page
@@ -25,15 +25,14 @@
// This file is available under and governed by the GNU General Public
// License version 2 only, as published by the Free Software Foundation.
// However, the following notice accompanied the original version of this
// file:
//
-
//---------------------------------------------------------------------------------
//
// Little Color Management System
-// Copyright (c) 1998-2011 Marti Maria Saguer
+// Copyright (c) 1998-2016 Marti Maria Saguer
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
@@ -256,15 +255,14 @@
// Now what if the result is a plain identity?
if (!isFloatMatrixIdentity(&res)) {
// We can not get rid of full matrix
cmsStage* Multmat = cmsStageAllocMatrix(Lut->ContextID, 3, 3, (const cmsFloat64Number*) &res, NULL);
+ if (Multmat == NULL) return FALSE; // Should never happen
// Recover the chain
- if (Multmat != NULL) {
Multmat->Next = chain;
- }
*pt1 = Multmat;
}
AnyOpt = TRUE;
}
@@ -558,19 +556,19 @@
Grid -> Tab.T[index + i] = Value[i];
return TRUE;
}
-// Auxiliar, to see if two values are equal or very different
+// Auxiliary, to see if two values are equal or very different
static
cmsBool WhitesAreEqual(int n, cmsUInt16Number White1[], cmsUInt16Number White2[] )
{
int i;
for (i=0; i < n; i++) {
- if (abs(White1[i] - White2[i]) > 0xf000) return TRUE; // Values are so extremly different that the fixup should be avoided
+ if (abs(White1[i] - White2[i]) > 0xf000) return TRUE; // Values are so extremely different that the fixup should be avoided
if (White1[i] != White2[i]) return FALSE;
}
return TRUE;
}
@@ -704,11 +702,11 @@
// Get a pointer to the prelinearization element
cmsStage* PreLin = cmsPipelineGetPtrToFirstStage(Src);
// Check if suitable
- if (PreLin ->Type == cmsSigCurveSetElemType) {
+ if (PreLin && PreLin ->Type == cmsSigCurveSetElemType) {
// Maybe this is a linear tram, so we can avoid the whole stuff
if (!AllCurvesAreLinear(PreLin)) {
// All seems ok, proceed.
@@ -737,11 +735,11 @@
// Get a pointer to the postlinearization if present
cmsStage* PostLin = cmsPipelineGetPtrToLastStage(Src);
// Check if suitable
- if (cmsStageType(PostLin) == cmsSigCurveSetElemType) {
+ if (PostLin && cmsStageType(PostLin) == cmsSigCurveSetElemType) {
// Maybe this is a linear tram, so we can avoid the whole stuff
if (!AllCurvesAreLinear(PostLin)) {
// All seems ok, proceed.
@@ -1039,12 +1037,12 @@
if (g ->Table16[i] == 0x0000) Zeros++;
if (g ->Table16[i] == 0xffff) Poles++;
}
if (Zeros == 1 && Poles == 1) return FALSE; // For linear tables
- if (Zeros > (nEntries / 4)) return TRUE; // Degenerated, mostly zeros
- if (Poles > (nEntries / 4)) return TRUE; // Degenerated, mostly poles
+ if (Zeros > (nEntries / 20)) return TRUE; // Degenerated, many zeros
+ if (Poles > (nEntries / 20)) return TRUE; // Degenerated, many poles
return FALSE;
}
// --------------------------------------------------------------------------------------------------------------
@@ -1069,14 +1067,16 @@
// This is a loosy optimization! does not apply in floating-point cases
if (_cmsFormatterIsFloat(*InputFormat) || _cmsFormatterIsFloat(*OutputFormat)) return FALSE;
- // Only on RGB
+ // Only on chunky RGB
if (T_COLORSPACE(*InputFormat) != PT_RGB) return FALSE;
- if (T_COLORSPACE(*OutputFormat) != PT_RGB) return FALSE;
+ if (T_PLANAR(*InputFormat)) return FALSE;
+ if (T_COLORSPACE(*OutputFormat) != PT_RGB) return FALSE;
+ if (T_PLANAR(*OutputFormat)) return FALSE;
// On 16 bits, user has to specify the feature
if (!_cmsFormatterIs8bit(*InputFormat)) {
if (!(*dwFlags & cmsFLAGS_CLUT_PRE_LINEARIZATION)) return FALSE;
}
@@ -1096,10 +1096,26 @@
// Empty gamma containers
memset(Trans, 0, sizeof(Trans));
memset(TransReverse, 0, sizeof(TransReverse));
+ // If the last stage of the original lut are curves, and those curves are
+ // degenerated, it is likely the transform is squeezing and clipping
+ // the output from previous CLUT. We cannot optimize this case
+ {
+ cmsStage* last = cmsPipelineGetPtrToLastStage(OriginalLut);
+
+ if (cmsStageType(last) == cmsSigCurveSetElemType) {
+
+ _cmsStageToneCurvesData* Data = (_cmsStageToneCurvesData*)cmsStageData(last);
+ for (i = 0; i < Data->nCurves; i++) {
+ if (IsDegenerated(Data->TheCurves[i]))
+ goto Error;
+ }
+ }
+ }
+
for (t = 0; t < OriginalLut ->InputChannels; t++) {
Trans[t] = cmsBuildTabulatedToneCurve16(OriginalLut ->ContextID, PRELINEARIZATION_POINTS, NULL);
if (Trans[t] == NULL) goto Error;
}
@@ -1429,11 +1445,14 @@
for (i=0; i < Src ->InputChannels; i++) {
cmsFreeToneCurve(GammaTables[i]);
GammaTables[i] = NULL;
}
- if (GammaTables != NULL) _cmsFree(Src ->ContextID, GammaTables);
+ if (GammaTables != NULL) {
+ _cmsFree(Src->ContextID, GammaTables);
+ GammaTables = NULL;
+ }
// Maybe the curves are linear at the end
if (!AllCurvesAreLinear(ObtainedCurves)) {
if (!cmsPipelineInsertStage(Dest, cmsAT_BEGIN, ObtainedCurves))
< prev index next >