Permalink
Browse files

XGC-105: AFP rounded corners not in CMYK

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/commons/trunk@1754511 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
1 parent 4425248 commit 1b144ec7a016d35d3d395e7f3c52f197c189baed Simon Steiner committed Jul 29, 2016
@@ -30,6 +30,7 @@
import java.awt.image.ColorModel;
import java.awt.image.ComponentColorModel;
import java.awt.image.DataBuffer;
+import java.awt.image.PixelInterleavedSampleModel;
import java.awt.image.Raster;
import java.awt.image.WritableRaster;
import java.util.Map;
@@ -39,6 +40,7 @@
import org.apache.xmlgraphics.image.loader.ImageFlavor;
import org.apache.xmlgraphics.image.loader.ImageProcessingHints;
import org.apache.xmlgraphics.image.loader.ImageSize;
+import org.apache.xmlgraphics.java2d.color.DeviceCMYKColorSpace;
import org.apache.xmlgraphics.util.UnitConv;
/**
@@ -71,8 +73,9 @@ public Image convert(Image src, Map hints) {
if (res != null) {
resolution = res.intValue();
}
+ boolean cmyk = Boolean.TRUE.equals(hints.get("CMYK"));
- BufferedImage bi = paintToBufferedImage(g2dImage, bitsPerPixel, withAlpha, resolution);
+ BufferedImage bi = paintToBufferedImage(g2dImage, bitsPerPixel, withAlpha, resolution, cmyk);
ImageBuffered bufImage = new ImageBuffered(src.getInfo(), bi, null);
return bufImage;
@@ -87,7 +90,7 @@ public Image convert(Image src, Map hints) {
* @return the newly created BufferedImage
*/
protected BufferedImage paintToBufferedImage(ImageGraphics2D g2dImage,
- int bitsPerPixel, boolean withAlpha, int resolution) {
+ int bitsPerPixel, boolean withAlpha, int resolution, boolean cmyk) {
ImageSize size = g2dImage.getSize();
RenderingHints additionalHints = null;
@@ -115,7 +118,17 @@ protected BufferedImage paintToBufferedImage(ImageGraphics2D g2dImage,
if (withAlpha) {
bi = new BufferedImage(bmw, bmh, BufferedImage.TYPE_INT_ARGB);
} else {
- bi = new BufferedImage(bmw, bmh, BufferedImage.TYPE_INT_RGB);
+ if (cmyk) {
+ ComponentColorModel ccm = new ComponentColorModel(
+ new DeviceCMYKColorSpace(), false, false, 1, DataBuffer.TYPE_BYTE);
+ int[] bands = {0, 1, 2, 3};
+ PixelInterleavedSampleModel sm = new PixelInterleavedSampleModel(
+ DataBuffer.TYPE_BYTE, bmw, bmh, 4, bmw * 4, bands);
+ WritableRaster raster = WritableRaster.createWritableRaster(sm, new Point(0, 0));
+ bi = new BufferedImage(ccm, raster, false, null);
+ } else {
+ bi = new BufferedImage(bmw, bmh, BufferedImage.TYPE_INT_RGB);
+ }
}
}
@@ -0,0 +1,59 @@
+/*
+ * 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 java.awt.Dimension;
+import java.awt.Graphics2D;
+import java.awt.geom.Rectangle2D;
+import java.util.HashMap;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.apache.xmlgraphics.image.loader.ImageInfo;
+import org.apache.xmlgraphics.image.loader.ImageProcessingHints;
+import org.apache.xmlgraphics.image.loader.ImageSize;
+import org.apache.xmlgraphics.java2d.Graphics2DImagePainter;
+import org.apache.xmlgraphics.java2d.color.DeviceCMYKColorSpace;
+
+public class ImageConverterG2D2BitmapTestCase {
+ @Test
+ public void testConvert() {
+ ImageInfo info = new ImageInfo(null, null);
+ ImageSize imageSize = new ImageSize(100, 100, 72);
+ imageSize.calcSizeFromPixels();
+ info.setSize(imageSize);
+ HashMap hints = new HashMap();
+ hints.put(ImageProcessingHints.TRANSPARENCY_INTENT, ImageProcessingHints.TRANSPARENCY_INTENT_IGNORE);
+ hints.put("CMYK", true);
+ ImageBuffered image = (ImageBuffered) new ImageConverterG2D2Bitmap().convert(
+ new ImageGraphics2D(info, new EmptyGraphics2DImagePainter()), hints);
+ Assert.assertEquals(image.getBufferedImage().getColorModel().getNumColorComponents(), 4);
+ Assert.assertEquals(image.getColorSpace().getClass(), DeviceCMYKColorSpace.class);
+ }
+
+ private static class EmptyGraphics2DImagePainter implements Graphics2DImagePainter {
+ public void paint(Graphics2D g2d, Rectangle2D area) {
+ }
+
+ public Dimension getImageSize() {
+ return null;
+ }
+ }
+}

0 comments on commit 1b144ec

Please sign in to comment.