You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlgraphics.apache.org by ga...@apache.org on 2012/06/23 21:18:20 UTC

svn commit: r1353185 - in /xmlgraphics/commons/branches/commons-1_5rc1: src/java/org/apache/xmlgraphics/image/loader/impl/imageio/ test/java/org/apache/xmlgraphics/image/loader/impl/

Author: gadams
Date: Sat Jun 23 19:18:19 2012
New Revision: 1353185

URL: http://svn.apache.org/viewvc?rev=1353185&view=rev
Log:
Bugzilla #53423:
Fix IllegalArgumentException loading a grayscale PNG with a CMYK color profile.

Added:
    xmlgraphics/commons/branches/commons-1_5rc1/test/java/org/apache/xmlgraphics/image/loader/impl/ImageLoaderImageIOTestCase.java
    xmlgraphics/commons/branches/commons-1_5rc1/test/java/org/apache/xmlgraphics/image/loader/impl/gray-vs-cmyk-profile.png
Modified:
    xmlgraphics/commons/branches/commons-1_5rc1/src/java/org/apache/xmlgraphics/image/loader/impl/imageio/ImageLoaderImageIO.java

Modified: xmlgraphics/commons/branches/commons-1_5rc1/src/java/org/apache/xmlgraphics/image/loader/impl/imageio/ImageLoaderImageIO.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/commons-1_5rc1/src/java/org/apache/xmlgraphics/image/loader/impl/imageio/ImageLoaderImageIO.java?rev=1353185&r1=1353184&r2=1353185&view=diff
==============================================================================
--- xmlgraphics/commons/branches/commons-1_5rc1/src/java/org/apache/xmlgraphics/image/loader/impl/imageio/ImageLoaderImageIO.java (original)
+++ xmlgraphics/commons/branches/commons-1_5rc1/src/java/org/apache/xmlgraphics/image/loader/impl/imageio/ImageLoaderImageIO.java Sat Jun 23 19:18:19 2012
@@ -65,7 +65,6 @@ import org.apache.xmlgraphics.image.load
 import org.apache.xmlgraphics.image.loader.impl.ImageBuffered;
 import org.apache.xmlgraphics.image.loader.impl.ImageRendered;
 import org.apache.xmlgraphics.image.loader.util.ImageUtil;
-
 import org.apache.xmlgraphics.java2d.color.profile.ColorProfileUtil;
 
 /**
@@ -197,12 +196,21 @@ public class ImageLoaderImageIO extends 
                     WritableRaster wr = Raster.createWritableRaster(imageData
                             .getSampleModel(), null);
                     imageData.copyData(wr);
-                    BufferedImage bi = new BufferedImage(cm2, wr, cm2
-                            .isAlphaPremultiplied(), null);
-                    imageData = bi;
-                    cm = cm2;
+                    try {
+                        BufferedImage bi = new BufferedImage(cm2, wr, cm2
+                                .isAlphaPremultiplied(), null);
+                        imageData = bi;
+                        cm = cm2;
+                    } catch (IllegalArgumentException iae) {
+                        log.warn("Image " + info.getOriginalURI()
+                                + " has an incompatible color profile."
+                                + " The color profile will be ignored."
+                                + "\nColor model of loaded bitmap: " + cm
+                                + "\nColor model of color profile: " + cm2);
+                    }
                 }
             }
+
             // ImageIOUtil.dumpMetadataToSystemOut(iiometa);
             // Retrieve the transparent color from the metadata
             if (iiometa != null && iiometa.isStandardMetadataFormatSupported()) {

Added: xmlgraphics/commons/branches/commons-1_5rc1/test/java/org/apache/xmlgraphics/image/loader/impl/ImageLoaderImageIOTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/commons-1_5rc1/test/java/org/apache/xmlgraphics/image/loader/impl/ImageLoaderImageIOTestCase.java?rev=1353185&view=auto
==============================================================================
--- xmlgraphics/commons/branches/commons-1_5rc1/test/java/org/apache/xmlgraphics/image/loader/impl/ImageLoaderImageIOTestCase.java (added)
+++ xmlgraphics/commons/branches/commons-1_5rc1/test/java/org/apache/xmlgraphics/image/loader/impl/ImageLoaderImageIOTestCase.java Sat Jun 23 19:18:19 2012
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.xmlgraphics.image.loader.impl;
+
+import static org.junit.Assert.assertTrue;
+
+import java.net.URL;
+
+import junit.framework.Assert;
+
+import org.junit.Test;
+
+import org.apache.xmlgraphics.image.loader.Image;
+import org.apache.xmlgraphics.image.loader.ImageContext;
+import org.apache.xmlgraphics.image.loader.ImageFlavor;
+import org.apache.xmlgraphics.image.loader.ImageInfo;
+import org.apache.xmlgraphics.image.loader.ImageSessionContext;
+import org.apache.xmlgraphics.image.loader.MockImageContext;
+import org.apache.xmlgraphics.image.loader.MockImageSessionContext;
+import org.apache.xmlgraphics.image.loader.impl.imageio.ImageLoaderImageIO;
+import org.apache.xmlgraphics.util.MimeConstants;
+
+/**
+ * Tests for {@link ImageLoaderImageIO}.
+ */
+public class ImageLoaderImageIOTestCase {
+
+    /**
+     * Tests a grayscale PNG that has a CMYK color profile. ImageLoaderImageIO used
+     * to fail on that with an IllegalArgumentException.
+     * @throws Exception if an error occurs
+     */
+    @Test
+    public void testGrayPNGWithCMYKProfile() throws Exception {
+        URL imageURL = getClass().getResource("gray-vs-cmyk-profile.png");
+        Assert.assertNotNull(imageURL);
+        String uri = imageURL.toURI().toASCIIString();
+
+        ImageLoaderImageIO loader = new ImageLoaderImageIO(ImageFlavor.RENDERED_IMAGE);
+        ImageContext context = MockImageContext.newSafeInstance();
+        ImageSessionContext session = new MockImageSessionContext(context);
+        ImageInfo info = new ImageInfo(uri, MimeConstants.MIME_PNG);
+        Image im = loader.loadImage(info, null, session);
+        assertTrue(im instanceof ImageRendered);
+    }
+
+}

Added: xmlgraphics/commons/branches/commons-1_5rc1/test/java/org/apache/xmlgraphics/image/loader/impl/gray-vs-cmyk-profile.png
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/branches/commons-1_5rc1/test/java/org/apache/xmlgraphics/image/loader/impl/gray-vs-cmyk-profile.png?rev=1353185&view=auto
==============================================================================
Files xmlgraphics/commons/branches/commons-1_5rc1/test/java/org/apache/xmlgraphics/image/loader/impl/gray-vs-cmyk-profile.png (added) and xmlgraphics/commons/branches/commons-1_5rc1/test/java/org/apache/xmlgraphics/image/loader/impl/gray-vs-cmyk-profile.png Sat Jun 23 19:18:19 2012 differ



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: commits-help@xmlgraphics.apache.org