You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlgraphics.apache.org by ss...@apache.org on 2016/07/29 13:09:37 UTC

svn commit: r1754511 - in /xmlgraphics/commons/trunk/src: main/java/org/apache/xmlgraphics/image/loader/impl/ImageConverterG2D2Bitmap.java test/java/org/apache/xmlgraphics/image/loader/impl/ImageConverterG2D2BitmapTestCase.java

Author: ssteiner
Date: Fri Jul 29 13:09:37 2016
New Revision: 1754511

URL: http://svn.apache.org/viewvc?rev=1754511&view=rev
Log:
XGC-105: AFP rounded corners not in CMYK

Added:
    xmlgraphics/commons/trunk/src/test/java/org/apache/xmlgraphics/image/loader/impl/ImageConverterG2D2BitmapTestCase.java   (with props)
Modified:
    xmlgraphics/commons/trunk/src/main/java/org/apache/xmlgraphics/image/loader/impl/ImageConverterG2D2Bitmap.java

Modified: xmlgraphics/commons/trunk/src/main/java/org/apache/xmlgraphics/image/loader/impl/ImageConverterG2D2Bitmap.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/main/java/org/apache/xmlgraphics/image/loader/impl/ImageConverterG2D2Bitmap.java?rev=1754511&r1=1754510&r2=1754511&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/src/main/java/org/apache/xmlgraphics/image/loader/impl/ImageConverterG2D2Bitmap.java (original)
+++ xmlgraphics/commons/trunk/src/main/java/org/apache/xmlgraphics/image/loader/impl/ImageConverterG2D2Bitmap.java Fri Jul 29 13:09:37 2016
@@ -30,6 +30,7 @@ import java.awt.image.BufferedImage;
 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.load
 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 class ImageConverterG2D2Bitmap ex
         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 class ImageConverterG2D2Bitmap ex
      * @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 @@ public class ImageConverterG2D2Bitmap ex
             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);
+                }
             }
         }
 

Added: xmlgraphics/commons/trunk/src/test/java/org/apache/xmlgraphics/image/loader/impl/ImageConverterG2D2BitmapTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/test/java/org/apache/xmlgraphics/image/loader/impl/ImageConverterG2D2BitmapTestCase.java?rev=1754511&view=auto
==============================================================================
--- xmlgraphics/commons/trunk/src/test/java/org/apache/xmlgraphics/image/loader/impl/ImageConverterG2D2BitmapTestCase.java (added)
+++ xmlgraphics/commons/trunk/src/test/java/org/apache/xmlgraphics/image/loader/impl/ImageConverterG2D2BitmapTestCase.java Fri Jul 29 13:09:37 2016
@@ -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;
+        }
+    }
+}

Propchange: xmlgraphics/commons/trunk/src/test/java/org/apache/xmlgraphics/image/loader/impl/ImageConverterG2D2BitmapTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native



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