< prev index next >

src/java.desktop/share/classes/com/sun/imageio/plugins/tiff/TIFFImageReader.java

Print this page

        

@@ -728,21 +728,50 @@
 
             // If an ICCProfile field is present change the ImageTypeSpecifier
             // to use it if the data layout is component type.
             if (iccProfileField != null
                     && itsRaw.getColorModel() instanceof ComponentColorModel) {
+                // 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);
-                ICC_ColorSpace iccColorSpace
-                        = new ICC_ColorSpace(iccProfile);
+                    iccColorSpace = new ICC_ColorSpace(iccProfile);
 
-                // Get the raw sample and color information.
-                ColorModel cmRaw = itsRaw.getColorModel();
-                ColorSpace csRaw = cmRaw.getColorSpace();
-                SampleModel smRaw = itsRaw.getSampleModel();
+                    // 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.
                 int numBands = smRaw.getNumBands();
                 int numComponents = iccColorSpace.getNumComponents();
< prev index next >