Skip to content

Commit

Permalink
Bugzilla #53423:
Browse files Browse the repository at this point in the history
Fix IllegalArgumentException loading a grayscale PNG with a CMYK color profile.

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/commons/trunk@1350697 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
jmaerki committed Jun 15, 2012
1 parent 5c26f5c commit b50c605
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 5 deletions.
Expand Up @@ -65,7 +65,6 @@
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;

/**
Expand Down Expand Up @@ -197,12 +196,21 @@ public Image loadImage(ImageInfo info, Map hints, ImageSessionContext session)
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()) {
Expand Down
@@ -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);
}

}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b50c605

Please sign in to comment.