# HG changeset patch # User bpb # Date 1483128925 28800 # Fri Dec 30 12:15:25 2016 -0800 # Node ID 57869afbc1e241038ee9c0ce0e4cbe8e69fc5b70 # Parent 9adbdbedae4f90947e072a44e8c9f78258d550a1 8172153: Create workaround for failure to use ICC profile contained in a TIFF field Summary: Work errors due to using an embedded ICC profile from the metadata Reviewed-by: XXX diff --git a/src/java.desktop/share/classes/com/sun/imageio/plugins/tiff/TIFFImageReader.java b/src/java.desktop/share/classes/com/sun/imageio/plugins/tiff/TIFFImageReader.java --- a/src/java.desktop/share/classes/com/sun/imageio/plugins/tiff/TIFFImageReader.java +++ b/src/java.desktop/share/classes/com/sun/imageio/plugins/tiff/TIFFImageReader.java @@ -730,17 +730,46 @@ // to use it if the data layout is component type. if (iccProfileField != null && itsRaw.getColorModel() instanceof ComponentColorModel) { - // Create a ColorSpace from the profile. - byte[] iccProfileValue = iccProfileField.getAsBytes(); - ICC_Profile iccProfile - = ICC_Profile.getInstance(iccProfileValue); - ICC_ColorSpace iccColorSpace - = new ICC_ColorSpace(iccProfile); - // Get the raw sample and color information. ColorModel cmRaw = itsRaw.getColorModel(); ColorSpace csRaw = cmRaw.getColorSpace(); SampleModel smRaw = itsRaw.getSampleModel(); + + ColorSpace iccColorSpace = null; + try { + // Create a ColorSpace from the profile. + byte[] iccProfileValue = iccProfileField.getAsBytes(); + ICC_Profile iccProfile + = ICC_Profile.getInstance(iccProfileValue); + iccColorSpace = new ICC_ColorSpace(iccProfile); + + // Workaround for JDK-8145241: test a conversion and fall + // back to a standard ColorSpace if it fails. This + // workaround could be removed if JDK-8145241 is fixed. + float[] rgb = + iccColorSpace.toRGB(new float[] {1.0F, 1.0F, 1.0F}); + } catch (Exception iccProfileException) { + processWarningOccurred("Superseding bad ICC profile: " + + iccProfileException.getMessage()); + + if (iccColorSpace != null) { + switch (iccColorSpace.getType()) { + case ColorSpace.TYPE_GRAY: + iccColorSpace = + ColorSpace.getInstance(ColorSpace.CS_GRAY); + break; + case ColorSpace.TYPE_RGB: + iccColorSpace = + ColorSpace.getInstance(ColorSpace.CS_sRGB); + break; + default: + iccColorSpace = csRaw; + break; + } + } else { + iccColorSpace = csRaw; + } + } // Get the number of samples per pixel and the number // of color components.