Skip to content

Commit cb95a72

Browse files
committed
8260380: Upgrade to LittleCMS 2.12
Reviewed-by: phh, andrew Backport-of: 4caeb39f01b13b5472d8dacb268262fd418fd0c4
1 parent 503ae0b commit cb95a72

File tree

20 files changed

+431
-468
lines changed

20 files changed

+431
-468
lines changed

THIRD_PARTY_README

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1725,7 +1725,7 @@ THE SOFTWARE.
17251725

17261726
-------------------------------------------------------------------------------
17271727

1728-
%% This notice is provided with respect to Little CMS 2.11, which may be
1728+
%% This notice is provided with respect to Little CMS 2.12, which may be
17291729
included with JRE 8, JDK 8, and OpenJDK 8.
17301730

17311731
--- begin of LICENSE ---

jdk/src/share/native/sun/java2d/cmm/lcms/cmsalpha.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ static
104104
void from8to16(void* dst, const void* src)
105105
{
106106
cmsUInt8Number n = *(cmsUInt8Number*)src;
107-
*(cmsUInt16Number*) dst = FROM_8_TO_16(n);
107+
*(cmsUInt16Number*) dst = (cmsUInt16Number) FROM_8_TO_16(n);
108108
}
109109

110110
static
@@ -117,13 +117,13 @@ void from8to16SE(void* dst, const void* src)
117117
static
118118
void from8toFLT(void* dst, const void* src)
119119
{
120-
*(cmsFloat32Number*)dst = (*(cmsUInt8Number*)src) / 255.0f;
120+
*(cmsFloat32Number*)dst = (cmsFloat32Number) (*(cmsUInt8Number*)src) / 255.0f;
121121
}
122122

123123
static
124124
void from8toDBL(void* dst, const void* src)
125125
{
126-
*(cmsFloat64Number*)dst = (*(cmsUInt8Number*)src) / 255.0;
126+
*(cmsFloat64Number*)dst = (cmsFloat64Number) (*(cmsUInt8Number*)src) / 255.0;
127127
}
128128

129129
static
@@ -182,13 +182,13 @@ void from16SEtoFLT(void* dst, const void* src)
182182
static
183183
void from16toDBL(void* dst, const void* src)
184184
{
185-
*(cmsFloat64Number*)dst = (*(cmsUInt16Number*)src) / 65535.0f;
185+
*(cmsFloat64Number*)dst = (cmsFloat64Number) (*(cmsUInt16Number*)src) / 65535.0;
186186
}
187187

188188
static
189189
void from16SEtoDBL(void* dst, const void* src)
190190
{
191-
*(cmsFloat64Number*)dst = (CHANGE_ENDIAN(*(cmsUInt16Number*)src)) / 65535.0f;
191+
*(cmsFloat64Number*)dst = (cmsFloat64Number) (CHANGE_ENDIAN(*(cmsUInt16Number*)src)) / 65535.0;
192192
}
193193

194194
static

jdk/src/share/native/sun/java2d/cmm/lcms/cmscgats.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,21 +1525,30 @@ cmsBool CMSEXPORT cmsIT8SetDataFormat(cmsHANDLE h, int n, const char *Sample)
15251525
return SetDataFormat(it8, n, Sample);
15261526
}
15271527

1528+
// A safe atoi that returns 0 when NULL input is given
1529+
static
1530+
cmsInt32Number satoi(const char* b)
1531+
{
1532+
if (b == NULL) return 0;
1533+
return atoi(b);
1534+
}
1535+
15281536
static
15291537
void AllocateDataSet(cmsIT8* it8)
15301538
{
15311539
TABLE* t = GetTable(it8);
15321540

15331541
if (t -> Data) return; // Already allocated
15341542

1535-
t-> nSamples = atoi(cmsIT8GetProperty(it8, "NUMBER_OF_FIELDS"));
1536-
t-> nPatches = atoi(cmsIT8GetProperty(it8, "NUMBER_OF_SETS"));
1543+
t-> nSamples = satoi(cmsIT8GetProperty(it8, "NUMBER_OF_FIELDS"));
1544+
t-> nPatches = satoi(cmsIT8GetProperty(it8, "NUMBER_OF_SETS"));
15371545

15381546
if (t -> nSamples < 0 || t->nSamples > 0x7ffe || t->nPatches < 0 || t->nPatches > 0x7ffe)
15391547
{
15401548
SynError(it8, "AllocateDataSet: too much data");
15411549
}
15421550
else {
1551+
// Some dumb analizers warns of possible overflow here, just take a look couple of lines above.
15431552
t->Data = (char**)AllocChunk(it8, ((cmsUInt32Number)t->nSamples + 1) * ((cmsUInt32Number)t->nPatches + 1) * sizeof(char*));
15441553
if (t->Data == NULL) {
15451554

@@ -1705,11 +1714,11 @@ void WriteHeader(cmsIT8* it8, SAVESTREAM* fp)
17051714
break;
17061715

17071716
case WRITE_HEXADECIMAL:
1708-
Writef(fp, "\t0x%X", atoi(p ->Value));
1717+
Writef(fp, "\t0x%X", satoi(p ->Value));
17091718
break;
17101719

17111720
case WRITE_BINARY:
1712-
Writef(fp, "\t0x%B", atoi(p ->Value));
1721+
Writef(fp, "\t0x%B", satoi(p ->Value));
17131722
break;
17141723

17151724
case WRITE_PAIR:
@@ -1738,7 +1747,7 @@ void WriteDataFormat(SAVESTREAM* fp, cmsIT8* it8)
17381747

17391748
WriteStr(fp, "BEGIN_DATA_FORMAT\n");
17401749
WriteStr(fp, " ");
1741-
nSamples = atoi(cmsIT8GetProperty(it8, "NUMBER_OF_FIELDS"));
1750+
nSamples = satoi(cmsIT8GetProperty(it8, "NUMBER_OF_FIELDS"));
17421751

17431752
for (i = 0; i < nSamples; i++) {
17441753

@@ -1761,7 +1770,7 @@ void WriteData(SAVESTREAM* fp, cmsIT8* it8)
17611770

17621771
WriteStr (fp, "BEGIN_DATA\n");
17631772

1764-
t->nPatches = atoi(cmsIT8GetProperty(it8, "NUMBER_OF_SETS"));
1773+
t->nPatches = satoi(cmsIT8GetProperty(it8, "NUMBER_OF_SETS"));
17651774

17661775
for (i = 0; i < t-> nPatches; i++) {
17671776

jdk/src/share/native/sun/java2d/cmm/lcms/cmscnvrt.c

Lines changed: 79 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,9 @@ cmsPipeline* BlackPreservingKOnlyIntents(cmsContext ContextID,
759759
cmsUInt32Number ICCIntents[256];
760760
cmsStage* CLUT;
761761
cmsUInt32Number i, nGridPoints;
762+
cmsUInt32Number lastProfilePos;
763+
cmsUInt32Number preservationProfilesCount;
764+
cmsHPROFILE hLastProfile;
762765

763766

764767
// Sanity check
@@ -768,20 +771,36 @@ cmsPipeline* BlackPreservingKOnlyIntents(cmsContext ContextID,
768771
for (i=0; i < nProfiles; i++)
769772
ICCIntents[i] = TranslateNonICCIntents(TheIntents[i]);
770773

774+
775+
// Trim all CMYK devicelinks at the end
776+
lastProfilePos = nProfiles - 1;
777+
hLastProfile = hProfiles[lastProfilePos];
778+
779+
while (lastProfilePos > 1)
780+
{
781+
hLastProfile = hProfiles[--lastProfilePos];
782+
if (cmsGetColorSpace(hLastProfile) != cmsSigCmykData ||
783+
cmsGetDeviceClass(hLastProfile) != cmsSigLinkClass)
784+
break;
785+
}
786+
787+
preservationProfilesCount = lastProfilePos + 1;
788+
771789
// Check for non-cmyk profiles
772790
if (cmsGetColorSpace(hProfiles[0]) != cmsSigCmykData ||
773-
cmsGetColorSpace(hProfiles[nProfiles-1]) != cmsSigCmykData)
791+
!(cmsGetColorSpace(hLastProfile) == cmsSigCmykData ||
792+
cmsGetDeviceClass(hLastProfile) == cmsSigOutputClass))
774793
return DefaultICCintents(ContextID, nProfiles, ICCIntents, hProfiles, BPC, AdaptationStates, dwFlags);
775794

776-
memset(&bp, 0, sizeof(bp));
777-
778795
// Allocate an empty LUT for holding the result
779796
Result = cmsPipelineAlloc(ContextID, 4, 4);
780797
if (Result == NULL) return NULL;
781798

799+
memset(&bp, 0, sizeof(bp));
800+
782801
// Create a LUT holding normal ICC transform
783802
bp.cmyk2cmyk = DefaultICCintents(ContextID,
784-
nProfiles,
803+
preservationProfilesCount,
785804
ICCIntents,
786805
hProfiles,
787806
BPC,
@@ -793,7 +812,7 @@ cmsPipeline* BlackPreservingKOnlyIntents(cmsContext ContextID,
793812
// Now, compute the tone curve
794813
bp.KTone = _cmsBuildKToneCurve(ContextID,
795814
4096,
796-
nProfiles,
815+
preservationProfilesCount,
797816
ICCIntents,
798817
hProfiles,
799818
BPC,
@@ -818,6 +837,19 @@ cmsPipeline* BlackPreservingKOnlyIntents(cmsContext ContextID,
818837
if (!cmsStageSampleCLut16bit(CLUT, BlackPreservingGrayOnlySampler, (void*) &bp, 0))
819838
goto Error;
820839

840+
841+
// Insert possible devicelinks at the end
842+
for (i = lastProfilePos + 1; i < nProfiles; i++)
843+
{
844+
cmsPipeline* devlink = _cmsReadDevicelinkLUT(hProfiles[i], ICCIntents[i]);
845+
if (devlink == NULL)
846+
goto Error;
847+
848+
if (!cmsPipelineCat(Result, devlink))
849+
goto Error;
850+
}
851+
852+
821853
// Get rid of xform and tone curve
822854
cmsPipelineFree(bp.cmyk2cmyk);
823855
cmsFreeToneCurve(bp.KTone);
@@ -936,6 +968,8 @@ int BlackPreservingSampler(CMSREGISTER const cmsUInt16Number In[], CMSREGISTER c
936968
return TRUE;
937969
}
938970

971+
972+
939973
// This is the entry for black-plane preserving, which are non-ICC
940974
static
941975
cmsPipeline* BlackPreservingKPlaneIntents(cmsContext ContextID,
@@ -947,10 +981,14 @@ cmsPipeline* BlackPreservingKPlaneIntents(cmsContext ContextID,
947981
cmsUInt32Number dwFlags)
948982
{
949983
PreserveKPlaneParams bp;
984+
950985
cmsPipeline* Result = NULL;
951986
cmsUInt32Number ICCIntents[256];
952987
cmsStage* CLUT;
953988
cmsUInt32Number i, nGridPoints;
989+
cmsUInt32Number lastProfilePos;
990+
cmsUInt32Number preservationProfilesCount;
991+
cmsHPROFILE hLastProfile;
954992
cmsHPROFILE hLab;
955993

956994
// Sanity check
@@ -960,32 +998,45 @@ cmsPipeline* BlackPreservingKPlaneIntents(cmsContext ContextID,
960998
for (i=0; i < nProfiles; i++)
961999
ICCIntents[i] = TranslateNonICCIntents(TheIntents[i]);
9621000

1001+
// Trim all CMYK devicelinks at the end
1002+
lastProfilePos = nProfiles - 1;
1003+
hLastProfile = hProfiles[lastProfilePos];
1004+
1005+
while (lastProfilePos > 1)
1006+
{
1007+
hLastProfile = hProfiles[--lastProfilePos];
1008+
if (cmsGetColorSpace(hLastProfile) != cmsSigCmykData ||
1009+
cmsGetDeviceClass(hLastProfile) != cmsSigLinkClass)
1010+
break;
1011+
}
1012+
1013+
preservationProfilesCount = lastProfilePos + 1;
1014+
9631015
// Check for non-cmyk profiles
9641016
if (cmsGetColorSpace(hProfiles[0]) != cmsSigCmykData ||
965-
!(cmsGetColorSpace(hProfiles[nProfiles-1]) == cmsSigCmykData ||
966-
cmsGetDeviceClass(hProfiles[nProfiles-1]) == cmsSigOutputClass))
1017+
!(cmsGetColorSpace(hLastProfile) == cmsSigCmykData ||
1018+
cmsGetDeviceClass(hLastProfile) == cmsSigOutputClass))
9671019
return DefaultICCintents(ContextID, nProfiles, ICCIntents, hProfiles, BPC, AdaptationStates, dwFlags);
9681020

9691021
// Allocate an empty LUT for holding the result
9701022
Result = cmsPipelineAlloc(ContextID, 4, 4);
9711023
if (Result == NULL) return NULL;
9721024

973-
9741025
memset(&bp, 0, sizeof(bp));
9751026

9761027
// We need the input LUT of the last profile, assuming this one is responsible of
9771028
// black generation. This LUT will be searched in inverse order.
978-
bp.LabK2cmyk = _cmsReadInputLUT(hProfiles[nProfiles-1], INTENT_RELATIVE_COLORIMETRIC);
1029+
bp.LabK2cmyk = _cmsReadInputLUT(hLastProfile, INTENT_RELATIVE_COLORIMETRIC);
9791030
if (bp.LabK2cmyk == NULL) goto Cleanup;
9801031

9811032
// Get total area coverage (in 0..1 domain)
982-
bp.MaxTAC = cmsDetectTAC(hProfiles[nProfiles-1]) / 100.0;
1033+
bp.MaxTAC = cmsDetectTAC(hLastProfile) / 100.0;
9831034
if (bp.MaxTAC <= 0) goto Cleanup;
9841035

9851036

9861037
// Create a LUT holding normal ICC transform
9871038
bp.cmyk2cmyk = DefaultICCintents(ContextID,
988-
nProfiles,
1039+
preservationProfilesCount,
9891040
ICCIntents,
9901041
hProfiles,
9911042
BPC,
@@ -994,7 +1045,7 @@ cmsPipeline* BlackPreservingKPlaneIntents(cmsContext ContextID,
9941045
if (bp.cmyk2cmyk == NULL) goto Cleanup;
9951046

9961047
// Now the tone curve
997-
bp.KTone = _cmsBuildKToneCurve(ContextID, 4096, nProfiles,
1048+
bp.KTone = _cmsBuildKToneCurve(ContextID, 4096, preservationProfilesCount,
9981049
ICCIntents,
9991050
hProfiles,
10001051
BPC,
@@ -1004,14 +1055,14 @@ cmsPipeline* BlackPreservingKPlaneIntents(cmsContext ContextID,
10041055

10051056
// To measure the output, Last profile to Lab
10061057
hLab = cmsCreateLab4ProfileTHR(ContextID, NULL);
1007-
bp.hProofOutput = cmsCreateTransformTHR(ContextID, hProfiles[nProfiles-1],
1058+
bp.hProofOutput = cmsCreateTransformTHR(ContextID, hLastProfile,
10081059
CHANNELS_SH(4)|BYTES_SH(2), hLab, TYPE_Lab_DBL,
10091060
INTENT_RELATIVE_COLORIMETRIC,
10101061
cmsFLAGS_NOCACHE|cmsFLAGS_NOOPTIMIZE);
10111062
if ( bp.hProofOutput == NULL) goto Cleanup;
10121063

10131064
// Same as anterior, but lab in the 0..1 range
1014-
bp.cmyk2Lab = cmsCreateTransformTHR(ContextID, hProfiles[nProfiles-1],
1065+
bp.cmyk2Lab = cmsCreateTransformTHR(ContextID, hLastProfile,
10151066
FLOAT_SH(1)|CHANNELS_SH(4)|BYTES_SH(4), hLab,
10161067
FLOAT_SH(1)|CHANNELS_SH(3)|BYTES_SH(4),
10171068
INTENT_RELATIVE_COLORIMETRIC,
@@ -1034,6 +1085,18 @@ cmsPipeline* BlackPreservingKPlaneIntents(cmsContext ContextID,
10341085

10351086
cmsStageSampleCLut16bit(CLUT, BlackPreservingSampler, (void*) &bp, 0);
10361087

1088+
// Insert possible devicelinks at the end
1089+
for (i = lastProfilePos + 1; i < nProfiles; i++)
1090+
{
1091+
cmsPipeline* devlink = _cmsReadDevicelinkLUT(hProfiles[i], ICCIntents[i]);
1092+
if (devlink == NULL)
1093+
goto Cleanup;
1094+
1095+
if (!cmsPipelineCat(Result, devlink))
1096+
goto Cleanup;
1097+
}
1098+
1099+
10371100
Cleanup:
10381101

10391102
if (bp.cmyk2cmyk) cmsPipelineFree(bp.cmyk2cmyk);
@@ -1046,6 +1109,8 @@ cmsPipeline* BlackPreservingKPlaneIntents(cmsContext ContextID,
10461109
return Result;
10471110
}
10481111

1112+
1113+
10491114
// Link routines ------------------------------------------------------------------------------------------------------
10501115

10511116
// Chain several profiles into a single LUT. It just checks the parameters and then calls the handler

0 commit comments

Comments
 (0)