You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2018/02/19 17:49:16 UTC
svn commit: r1824794 -
/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDICCBased.java
Author: tilman
Date: Mon Feb 19 17:49:15 2018
New Revision: 1824794
URL: http://svn.apache.org/viewvc?rev=1824794&view=rev
Log:
PDFBOX-2917, PDFBOX-4114: fix icc profile that has the wrong display class as done in twelvemonkeys and suggested by Michael Vakulich
Modified:
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDICCBased.java
Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDICCBased.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDICCBased.java?rev=1824794&r1=1824793&r2=1824794&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDICCBased.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDICCBased.java Mon Feb 19 17:49:15 2018
@@ -137,6 +137,7 @@ public final class PDICCBased extends PD
}
else
{
+ profile = ensureDisplayProfile(profile);
awtColorSpace = new ICC_ColorSpace(profile);
iccProfile = profile;
}
@@ -200,6 +201,32 @@ public final class PDICCBased extends PD
return deviceModel.equals("sRGB");
}
+ // PDFBOX-4114: fix profile that has the wrong display class,
+ // as done by Harald Kuhr in twelvemonkeys JPEGImageReader.ensureDisplayProfile()
+ private static ICC_Profile ensureDisplayProfile(ICC_Profile profile)
+ {
+ if (profile.getProfileClass() != ICC_Profile.CLASS_DISPLAY)
+ {
+ byte[] profileData = profile.getData(); // Need to clone entire profile, due to a OpenJDK bug
+
+ if (profileData[ICC_Profile.icHdrRenderingIntent] == ICC_Profile.icPerceptual)
+ {
+ LOG.warn("ICC profile is Perceptual, ignoring, treating as Display class");
+ intToBigEndian(ICC_Profile.icSigDisplayClass, profileData, ICC_Profile.icHdrDeviceClass);
+ return ICC_Profile.getInstance(profileData);
+ }
+ }
+ return profile;
+ }
+
+ private static void intToBigEndian(int value, byte[] array, int index)
+ {
+ array[index] = (byte) (value >> 24);
+ array[index + 1] = (byte) (value >> 16);
+ array[index + 2] = (byte) (value >> 8);
+ array[index + 3] = (byte) (value);
+ }
+
@Override
public float[] toRGB(float[] value) throws IOException
{