< prev index next >
src/java.desktop/share/native/liblcms/cmsopt.c
Print this page
*** 25,39 ****
// 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
//
// 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,
--- 25,38 ----
// 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-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,270 ****
// 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);
// Recover the chain
- if (Multmat != NULL) {
Multmat->Next = chain;
- }
*pt1 = Multmat;
}
AnyOpt = TRUE;
}
--- 255,268 ----
// 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
Multmat->Next = chain;
*pt1 = Multmat;
}
AnyOpt = TRUE;
}
*** 558,576 ****
Grid -> Tab.T[index + i] = Value[i];
return TRUE;
}
! // Auxiliar, 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 (White1[i] != White2[i]) return FALSE;
}
return TRUE;
}
--- 556,574 ----
Grid -> Tab.T[index + i] = Value[i];
return TRUE;
}
! // 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 extremely different that the fixup should be avoided
if (White1[i] != White2[i]) return FALSE;
}
return TRUE;
}
*** 704,714 ****
// Get a pointer to the prelinearization element
cmsStage* PreLin = cmsPipelineGetPtrToFirstStage(Src);
// Check if suitable
! if (PreLin ->Type == cmsSigCurveSetElemType) {
// Maybe this is a linear tram, so we can avoid the whole stuff
if (!AllCurvesAreLinear(PreLin)) {
// All seems ok, proceed.
--- 702,712 ----
// Get a pointer to the prelinearization element
cmsStage* PreLin = cmsPipelineGetPtrToFirstStage(Src);
// Check if suitable
! 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,747 ****
// Get a pointer to the postlinearization if present
cmsStage* PostLin = cmsPipelineGetPtrToLastStage(Src);
// Check if suitable
! if (cmsStageType(PostLin) == cmsSigCurveSetElemType) {
// Maybe this is a linear tram, so we can avoid the whole stuff
if (!AllCurvesAreLinear(PostLin)) {
// All seems ok, proceed.
--- 735,745 ----
// Get a pointer to the postlinearization if present
cmsStage* PostLin = cmsPipelineGetPtrToLastStage(Src);
// Check if suitable
! 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,1050 ****
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
return FALSE;
}
// --------------------------------------------------------------------------------------------------------------
--- 1037,1048 ----
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 / 20)) return TRUE; // Degenerated, many zeros
! if (Poles > (nEntries / 20)) return TRUE; // Degenerated, many poles
return FALSE;
}
// --------------------------------------------------------------------------------------------------------------
*** 1069,1082 ****
// This is a loosy optimization! does not apply in floating-point cases
if (_cmsFormatterIsFloat(*InputFormat) || _cmsFormatterIsFloat(*OutputFormat)) return FALSE;
! // Only on RGB
if (T_COLORSPACE(*InputFormat) != PT_RGB) return FALSE;
! if (T_COLORSPACE(*OutputFormat) != PT_RGB) return FALSE;
// On 16 bits, user has to specify the feature
if (!_cmsFormatterIs8bit(*InputFormat)) {
if (!(*dwFlags & cmsFLAGS_CLUT_PRE_LINEARIZATION)) return FALSE;
}
--- 1067,1082 ----
// This is a loosy optimization! does not apply in floating-point cases
if (_cmsFormatterIsFloat(*InputFormat) || _cmsFormatterIsFloat(*OutputFormat)) return FALSE;
! // Only on chunky RGB
if (T_COLORSPACE(*InputFormat) != 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,1105 ****
--- 1096,1121 ----
// 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,1439 ****
for (i=0; i < Src ->InputChannels; i++) {
cmsFreeToneCurve(GammaTables[i]);
GammaTables[i] = NULL;
}
! if (GammaTables != NULL) _cmsFree(Src ->ContextID, GammaTables);
// Maybe the curves are linear at the end
if (!AllCurvesAreLinear(ObtainedCurves)) {
if (!cmsPipelineInsertStage(Dest, cmsAT_BEGIN, ObtainedCurves))
--- 1445,1458 ----
for (i=0; i < Src ->InputChannels; i++) {
cmsFreeToneCurve(GammaTables[i]);
GammaTables[i] = NULL;
}
! 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 >