Author: jeremias
Date: Fri Oct 23 13:33:18 2009
New Revision: 829057

URL: http://svn.apache.org/viewvc?rev=829057&view=rev
Log:
Added support for encoding CMYK bitmap images (IOCA FS45) and TIFF images as 
embedded objects.

Added:
    
xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/ioca/IDEStructureParameter.java
   (with props)
Modified:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/AFPDataObjectFactory.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/AFPPaintingState.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/ioca/ImageContent.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/ioca/ImageSegment.java
    
xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/modca/ContainerDataDescriptor.java
    
xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/modca/ImageDataDescriptor.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/modca/ImageObject.java
    
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPCustomizable.java
    
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java
    
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPImageHandlerRawStream.java
    
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPImageHandlerRenderedImage.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPRenderer.java
    
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java
    xmlgraphics/fop/trunk/status.xml

Modified: 
xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/AFPDataObjectFactory.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/AFPDataObjectFactory.java?rev=829057&r1=829056&r2=829057&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/AFPDataObjectFactory.java 
(original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/AFPDataObjectFactory.java 
Fri Oct 23 13:33:18 2009
@@ -24,6 +24,7 @@
 import org.apache.xmlgraphics.image.codec.tiff.TIFFImage;
 import org.apache.xmlgraphics.java2d.Graphics2DImagePainter;
 
+import org.apache.fop.afp.ioca.IDEStructureParameter;
 import org.apache.fop.afp.ioca.ImageContent;
 import org.apache.fop.afp.modca.AbstractDataObject;
 import org.apache.fop.afp.modca.AbstractNamedAFPObject;
@@ -113,12 +114,35 @@
             }
         }
 
-        if (imageObjectInfo.isColor()) {
-            imageObj.setIDESize((byte) 24);
-        } else {
-            imageObj.setIDESize((byte) imageObjectInfo.getBitsPerPixel());
+        ImageContent content = imageObj.getImageSegment().getImageContent();
+        int bitsPerPixel = imageObjectInfo.getBitsPerPixel();
+        imageObj.setIDESize((byte) bitsPerPixel);
+        IDEStructureParameter ideStruct;
+        switch (bitsPerPixel) {
+        case 1:
+            //Skip IDE Structure Parameter
+            break;
+        case 4:
+        case 8:
+            ideStruct = content.needIDEStructureParameter();
+            ideStruct.setBitsPerComponent(new int[] {bitsPerPixel});
+            break;
+        case 24:
+            ideStruct = content.needIDEStructureParameter();
+            ideStruct.setDefaultRGBColorModel();
+            break;
+        case 32:
+            ideStruct = content.needIDEStructureParameter();
+            ideStruct.setDefaultCMYKColorModel();
+            break;
+        default:
+            throw new IllegalArgumentException("Unsupported number of bits per 
pixel: "
+                    + bitsPerPixel);
+        }
+        if (imageObjectInfo.isSubtractive()) {
+            ideStruct = content.needIDEStructureParameter();
+            ideStruct.setSubtractive(imageObjectInfo.isSubtractive());
         }
-        imageObj.setSubtractive(imageObjectInfo.isSubtractive());
 
         imageObj.setData(imageObjectInfo.getData());
 

Modified: 
xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/AFPPaintingState.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/AFPPaintingState.java?rev=829057&r1=829056&r2=829057&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/AFPPaintingState.java 
(original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/AFPPaintingState.java Fri 
Oct 23 13:33:18 2009
@@ -46,8 +46,10 @@
     /** color image support */
     private boolean colorImages = false;
 
-    /** images are supported in this AFP environment */
+    /** true if certain image formats may be embedded unchanged in their 
native format. */
     private boolean nativeImagesSupported = false;
+    /** true if CMYK images (requires IOCA FS45 suppport on the target 
platform) may be generated */
+    private boolean cmykImagesSupported;
 
     /** default value for image depth */
     private int bitsPerPixel = 8;
@@ -64,6 +66,7 @@
     /** a unit converter */
     private final transient AFPUnitConverter unitConv = new 
AFPUnitConverter(this);
 
+
     /**
      * Sets the rotation to be used for portrait pages, valid values are 0
      * (default), 90, 180, 270.
@@ -186,6 +189,24 @@
     }
 
     /**
+     * Controls whether CMYK images (IOCA FS45) are enabled. By default, 
support is disabled
+     * for wider compatibility. When disabled, any CMYK image is converted to 
the selected
+     * color format.
+     * @param value true to enabled CMYK images
+     */
+    public void setCMYKImagesSupported(boolean value) {
+        this.cmykImagesSupported = value;
+    }
+
+    /**
+     * Indicates whether CMYK images (IOCA FS45) are enabled.
+     * @return true if IOCA FS45 is enabled
+     */
+    public boolean isCMYKImagesSupported() {
+        return this.cmykImagesSupported;
+    }
+
+    /**
      * Sets the output/device resolution
      *
      * @param resolution

Added: 
xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/ioca/IDEStructureParameter.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/ioca/IDEStructureParameter.java?rev=829057&view=auto
==============================================================================
--- 
xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/ioca/IDEStructureParameter.java
 (added)
+++ 
xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/ioca/IDEStructureParameter.java
 Fri Oct 23 13:33:18 2009
@@ -0,0 +1,151 @@
+/*
+ * 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.fop.afp.ioca;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.fop.afp.Streamable;
+
+/**
+ * This class represents the IOCA IDE Structure parameter (X'9B').
+ */
+public class IDEStructureParameter implements Streamable {
+
+    /** The RGB color model used by the IDE Structure parameter */
+    public static final byte COLOR_MODEL_RGB = (byte)0x01;
+    /** The YCrCb color model used by the IDE Structure parameter */
+    public static final byte COLOR_MODEL_YCRCB = (byte)0x02;
+    /** The CMYK color model used by the IDE Structure parameter */
+    public static final byte COLOR_MODEL_CMYK = (byte)0x04;
+    /** The YCbCr color model used by the IDE Structure parameter */
+    public static final byte COLOR_MODEL_YCBCR = (byte)0x12;
+
+    /** additive/subtractive setting for ASFLAG */
+    private boolean subtractive = false;
+
+    /** setting for GRAYCODE flag */
+    private boolean grayCoding = false;
+
+    /** the image color model */
+    private byte colorModel = COLOR_MODEL_RGB;
+
+    /** the array with the number of bits/IDE for each component */
+    private byte[] bitsPerIDE = new byte[] {(byte)1}; //1-bit by default
+
+    /**
+     * Creates a new IDE Structure parameter. The values are initialized for a 
bi-level image
+     * using the RGB color model.
+     */
+    public IDEStructureParameter() {
+        //nop
+    }
+
+    /**
+     * Sets the image IDE color model.
+     *
+     * @param color    the IDE color model.
+     */
+    public void setColorModel(byte color) {
+        this.colorModel = color;
+    }
+
+    /**
+     * Establishes the parameter values for the normal RGB 24bit color model.
+     */
+    public void setDefaultRGBColorModel() {
+        this.colorModel = COLOR_MODEL_RGB;
+        setUniformBitsPerComponent(3, 8);
+    }
+
+    /**
+     * Establishes the parameter values for the normal CMYK 32bit color model.
+     */
+    public void setDefaultCMYKColorModel() {
+        this.colorModel = COLOR_MODEL_CMYK;
+        setUniformBitsPerComponent(4, 8);
+    }
+
+    /**
+     * Sets
+     * @param numComponents
+     * @param bitsPerComponent
+     */
+    public void setUniformBitsPerComponent(int numComponents, int 
bitsPerComponent) {
+        if (bitsPerComponent < 0 || bitsPerComponent >= 256) {
+            throw new IllegalArgumentException(
+                    "The number of bits per component must be between 0 and 
255");
+        }
+        this.bitsPerIDE = new byte[numComponents];
+        for (int i = 0; i < numComponents; i++) {
+            this.bitsPerIDE[i] = (byte)bitsPerComponent;
+        }
+    }
+
+    /**
+     * Sets the array for the bits/IDE, one entry per component.
+     * @param bitsPerComponent the
+     */
+    public void setBitsPerComponent(int[] bitsPerComponent) {
+        int numComponents = bitsPerComponent.length;
+        this.bitsPerIDE = new byte[numComponents];
+        for (int i = 0; i < numComponents; i++) {
+            int bits = bitsPerComponent[i];
+            if (bits < 0 || bits >= 256) {
+                throw new IllegalArgumentException(
+                        "The number of bits per component must be between 0 
and 255");
+            }
+            this.bitsPerIDE[i] = (byte)bits;
+        }
+    }
+
+    /**
+     * Set either additive or subtractive mode (used for ASFLAG).
+     * @param subtractive true for subtractive mode, false for additive mode
+     */
+    public void setSubtractive(boolean subtractive) {
+        this.subtractive = subtractive;
+    }
+
+    /** {...@inheritdoc} */
+    public void writeToStream(OutputStream os) throws IOException {
+        int length = 7 + bitsPerIDE.length;
+
+        byte flags = 0x00;
+        if (subtractive) {
+            flags |= 1 << 7;
+        }
+        if (grayCoding) {
+            flags |= 1 << 6;
+        }
+
+        DataOutputStream dout = new DataOutputStream(os);
+        dout.writeByte(0x9B); //ID
+        dout.writeByte(length - 2); //LENGTH
+        dout.writeByte(flags); //FLAGS
+        dout.writeByte(this.colorModel); //FORMAT
+        for (int i = 0; i < 3; i++) {
+            dout.writeByte(0); //RESERVED
+        }
+        dout.write(this.bitsPerIDE); //component sizes
+    }
+
+}

Propchange: 
xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/ioca/IDEStructureParameter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/ioca/IDEStructureParameter.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: 
xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/ioca/ImageContent.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/ioca/ImageContent.java?rev=829057&r1=829056&r2=829057&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/ioca/ImageContent.java 
(original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/ioca/ImageContent.java 
Fri Oct 23 13:33:18 2009
@@ -56,21 +56,18 @@
     /** the image size parameter */
     private ImageSizeParameter imageSizeParameter = null;
 
+    /** the IDE Structure parameter */
+    private IDEStructureParameter ideStructureParameter = null;
+
     /** the image encoding */
     private byte encoding = (byte)0x03;
 
-    /** the image ide size */
-    private byte size = 1;
+    /** the image IDE (Image Data Element, Sample) size */
+    private byte ideSize = 1;
 
     /** the image compression */
     private byte compression = (byte)0xC0;
 
-    /** the image color model */
-    private byte colorModel = (byte)0x01;
-
-    /** additive/subtractive setting for ASFLAG */
-    private boolean subtractive = false;
-
     /** the image data */
     private byte[] data;
 
@@ -90,6 +87,34 @@
     }
 
     /**
+     * Sets the IDE Structure parameter.
+     * @param parameter the IDE Structure parameter
+     */
+    public void setIDEStructureParameter(IDEStructureParameter parameter) {
+        this.ideStructureParameter = parameter;
+    }
+
+    /**
+     * Returns the (optional) IDE Structure parameter
+     * @return the IDE Structure parameter or null if none is set
+     */
+    public IDEStructureParameter getIDEStructureParameter() {
+        return this.ideStructureParameter;
+    }
+
+    /**
+     * Returns the (optional) IDE Structure parameter. If none is set an 
instance is prepared
+     * with defaults for a bi-level image.
+     * @return the IDE Structure parameter
+     */
+    public IDEStructureParameter needIDEStructureParameter() {
+        if (this.ideStructureParameter == null) {
+            setIDEStructureParameter(new IDEStructureParameter());
+        }
+        return getIDEStructureParameter();
+    }
+
+    /**
      * Sets the image encoding.
      *
      * @param enc The image encoding.
@@ -113,24 +138,26 @@
      * @param s The IDE size.
      */
     public void setImageIDESize(byte s) {
-        this.size = s;
+        this.ideSize = s;
     }
 
     /**
      * Sets the image IDE color model.
      *
      * @param color    the IDE color model.
+     * @deprecated use {...@link 
#setIDEStructureParameter(IDEStructureParameter)} instead
      */
     public void setImageIDEColorModel(byte color) {
-        this.colorModel = color;
+        needIDEStructureParameter().setColorModel(color);
     }
 
     /**
      * Set either additive or subtractive mode (used for ASFLAG).
      * @param subtractive true for subtractive mode, false for additive mode
+     * @deprecated use {...@link 
#setIDEStructureParameter(IDEStructureParameter)} instead
      */
     public void setSubtractive(boolean subtractive) {
-        this.subtractive = subtractive;
+        needIDEStructureParameter().setSubtractive(subtractive);
     }
 
     /**
@@ -155,10 +182,12 @@
 
         os.write(getImageIDESizeParameter());
 
-        boolean useFS10 = (this.size == 1);
-        if (!useFS10) {
-            os.write(getIDEStructureParameter());
+        if (getIDEStructureParameter() != null) {
+            getIDEStructureParameter().writeToStream(os);
+        }
 
+        boolean useFS10 = (this.ideSize == 1);
+        if (!useFS10) {
             os.write(getExternalAlgorithmParameter());
         }
 
@@ -243,58 +272,15 @@
      * @return byte[] The data stream.
      */
     private byte[] getImageIDESizeParameter() {
-        if (size != 1) {
+        if (ideSize != 1) {
             final byte[] ideSizeData = new byte[] {
                     (byte)0x96, // ID
                     0x01, // Length
-                    size};
+                    ideSize};
             return ideSizeData;
         } else {
             return new byte[0];
         }
     }
 
-    /**
-     * Helper method to return the external algorithm parameter.
-     *
-     * @return byte[] The data stream.
-     */
-    private byte[] getIDEStructureParameter() {
-        byte flags = 0x00;
-        if (subtractive) {
-            flags |= 1 << 7;
-        }
-        if (colorModel != 0 && size == 24) {
-            final byte bits = (byte)(size / 3);
-            final byte[] ideStructData = new byte[] {
-                (byte)0x9B, // ID
-                0x00, // Length
-                flags, // FLAGS
-                colorModel, // COLOR MODEL
-                0x00, // Reserved
-                0x00, // Reserved
-                0x00, // Reserved
-                bits,
-                bits,
-                bits,
-            };
-            ideStructData[1] = (byte)(ideStructData.length - 2);
-            return ideStructData;
-        } else if (size == 1) {
-            final byte[] ideStructData = new byte[] {
-                    (byte)0x9B, // ID
-                    0x00, // Length
-                    flags, // FLAGS
-                    colorModel, // COLOR MODEL
-                    0x00, // Reserved
-                    0x00, // Reserved
-                    0x00, // Reserved
-                    0x01
-                };
-                ideStructData[1] = (byte)(ideStructData.length - 2);
-                return ideStructData;
-        }
-        return new byte[0];
-    }
-
 }

Modified: 
xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/ioca/ImageSegment.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/ioca/ImageSegment.java?rev=829057&r1=829056&r2=829057&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/ioca/ImageSegment.java 
(original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/ioca/ImageSegment.java 
Fri Oct 23 13:33:18 2009
@@ -56,7 +56,11 @@
         this.factory = factory;
     }
 
-    private ImageContent getImageContent() {
+    /**
+     * Returns the image content object associated with this image segment.
+     * @return the image content
+     */
+    public ImageContent getImageContent() {
         if (imageContent == null) {
             this.imageContent = factory.createImageContent();
         }
@@ -108,6 +112,7 @@
      * Sets the image IDE color model.
      *
      * @param colorModel the IDE color model.
+     * @deprecated Use {...@link IDEStructureParameter#setColorModel(byte)} 
instead.
      */
     public void setIDEColorModel(byte colorModel) {
         getImageContent().setImageIDEColorModel(colorModel);
@@ -116,6 +121,7 @@
     /**
      * Set either additive or subtractive mode (used for ASFLAG).
      * @param subtractive true for subtractive mode, false for additive mode
+     * @deprecated Use {...@link 
IDEStructureParameter#setSubtractive(boolean)} instead.
      */
     public void setSubtractive(boolean subtractive) {
         getImageContent().setSubtractive(subtractive);
@@ -124,7 +130,7 @@
     /**
      * Set the data image data.
      *
-     * @param data the image data
+     * @param imageData the image data
      */
     public void setData(byte[] imageData) {
         getImageContent().setImageData(imageData);

Modified: 
xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/modca/ContainerDataDescriptor.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/modca/ContainerDataDescriptor.java?rev=829057&r1=829056&r2=829057&view=diff
==============================================================================
--- 
xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/modca/ContainerDataDescriptor.java
 (original)
+++ 
xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/modca/ContainerDataDescriptor.java
 Fri Oct 23 13:33:18 2009
@@ -79,6 +79,8 @@
         data[18] = ysize[0];
         data[19] = ysize[1];
         data[20] = ysize[2];
+
+        os.write(data);
     }
 
 }

Modified: 
xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/modca/ImageDataDescriptor.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/modca/ImageDataDescriptor.java?rev=829057&r1=829056&r2=829057&view=diff
==============================================================================
--- 
xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/modca/ImageDataDescriptor.java
 (original)
+++ 
xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/modca/ImageDataDescriptor.java
 Fri Oct 23 13:33:18 2009
@@ -31,6 +31,7 @@
 
     public static final byte FUNCTION_SET_FS10 = 0x0A;
     public static final byte FUNCTION_SET_FS11 = 0x0B;
+    public static final byte FUNCTION_SET_FS45 = 45;
 
     private byte functionSet = FUNCTION_SET_FS11; // FCNSET = IOCA FS 11
 

Modified: 
xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/modca/ImageObject.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/modca/ImageObject.java?rev=829057&r1=829056&r2=829057&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/modca/ImageObject.java 
(original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/afp/modca/ImageObject.java 
Fri Oct 23 13:33:18 2009
@@ -24,9 +24,12 @@
 
 import org.apache.commons.io.output.ByteArrayOutputStream;
 
+import org.apache.xmlgraphics.util.MimeConstants;
+
 import org.apache.fop.afp.AFPDataObjectInfo;
 import org.apache.fop.afp.AFPImageObjectInfo;
 import org.apache.fop.afp.Factory;
+import org.apache.fop.afp.ioca.IDEStructureParameter;
 import org.apache.fop.afp.ioca.ImageSegment;
 
 /**
@@ -50,7 +53,11 @@
         super(factory, name);
     }
 
-    private ImageSegment getImageSegment() {
+    /**
+     * Returns the image segment object associated with this image object.
+     * @return the image segment
+     */
+    public ImageSegment getImageSegment() {
         if (imageSegment == null) {
             this.imageSegment = factory.createImageSegment();
         }
@@ -71,6 +78,8 @@
             = factory.createImageDataDescriptor(dataWidth, dataHeight, 
dataWidthRes, dataHeightRes);
         if (imageObjectInfo.getBitsPerPixel() == 1) {
             
imageDataDescriptor.setFunctionSet(ImageDataDescriptor.FUNCTION_SET_FS10);
+        } else if 
(MimeConstants.MIME_AFP_IOCA_FS45.equals(imageObjectInfo.getMimeType())) {
+            
imageDataDescriptor.setFunctionSet(ImageDataDescriptor.FUNCTION_SET_FS45);
         }
         getObjectEnvironmentGroup().setDataDescriptor(imageDataDescriptor);
         getObjectEnvironmentGroup().setMapImageObject(
@@ -110,6 +119,7 @@
      * Sets the image IDE color model.
      *
      * @param colorModel    the IDE color model.
+     * @deprecated Use {...@link IDEStructureParameter#setColorModel(byte)} 
instead.
      */
     public void setIDEColorModel(byte colorModel) {
         getImageSegment().setIDEColorModel(colorModel);
@@ -118,6 +128,7 @@
     /**
      * Set either additive or subtractive mode (used for ASFLAG).
      * @param subtractive true for subtractive mode, false for additive mode
+     * @deprecated Use {...@link 
IDEStructureParameter#setSubtractive(boolean)} instead.
      */
     public void setSubtractive(boolean subtractive) {
         getImageSegment().setSubtractive(subtractive);

Modified: 
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPCustomizable.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPCustomizable.java?rev=829057&r1=829056&r2=829057&view=diff
==============================================================================
--- 
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPCustomizable.java 
(original)
+++ 
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPCustomizable.java 
Fri Oct 23 13:33:18 2009
@@ -51,6 +51,14 @@
     void setNativeImagesSupported(boolean nativeImages);
 
     /**
+     * Controls whether CMYK images (IOCA FS45) are enabled. By default, 
support is disabled
+     * for wider compatibility. When disabled, any CMYK image is converted to 
the selected
+     * color format.
+     * @param value true to enabled CMYK images
+     */
+    void setCMYKImagesSupported(boolean value);
+
+    /**
      * Sets the shading mode for painting filled rectangles.
      * @param shadingMode the shading mode
      */

Modified: 
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java?rev=829057&r1=829056&r2=829057&view=diff
==============================================================================
--- 
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java
 (original)
+++ 
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPDocumentHandler.java
 Fri Oct 23 13:33:18 2009
@@ -357,6 +357,11 @@
     }
 
     /** {...@inheritdoc} */
+    public void setCMYKImagesSupported(boolean value) {
+        paintingState.setCMYKImagesSupported(value);
+    }
+
+    /** {...@inheritdoc} */
     public void setShadingMode(AFPShadingMode shadingMode) {
         this.shadingMode = shadingMode;
     }

Modified: 
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPImageHandlerRawStream.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPImageHandlerRawStream.java?rev=829057&r1=829056&r2=829057&view=diff
==============================================================================
--- 
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPImageHandlerRawStream.java
 (original)
+++ 
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPImageHandlerRawStream.java
 Fri Oct 23 13:33:18 2009
@@ -24,6 +24,7 @@
 import org.apache.xmlgraphics.image.loader.impl.ImageRawEPS;
 import org.apache.xmlgraphics.image.loader.impl.ImageRawJPEG;
 import org.apache.xmlgraphics.image.loader.impl.ImageRawStream;
+import org.apache.xmlgraphics.util.MimeConstants;
 
 import org.apache.fop.afp.AFPDataObjectInfo;
 import org.apache.fop.render.RenderingContext;
@@ -35,6 +36,7 @@
 
     private static final ImageFlavor[] FLAVORS = new ImageFlavor[] {
         ImageFlavor.RAW_JPEG,
+        ImageFlavor.RAW_TIFF,
         ImageFlavor.RAW_EPS,
     };
 
@@ -63,7 +65,12 @@
         if (targetContext instanceof AFPRenderingContext) {
             AFPRenderingContext afpContext = 
(AFPRenderingContext)targetContext;
             return (afpContext.getPaintingState().isNativeImagesSupported())
-                && (image == null || image instanceof ImageRawJPEG || image 
instanceof ImageRawEPS);
+                && (image == null
+                        || image instanceof ImageRawJPEG
+                        || image instanceof ImageRawEPS
+                        || ((image instanceof ImageRawStream)
+                                && (MimeConstants.MIME_TIFF.equals(
+                                        
((ImageRawStream)image).getMimeType()))));
         }
         return false;
     }

Modified: 
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPImageHandlerRenderedImage.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPImageHandlerRenderedImage.java?rev=829057&r1=829056&r2=829057&view=diff
==============================================================================
--- 
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPImageHandlerRenderedImage.java
 (original)
+++ 
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPImageHandlerRenderedImage.java
 Fri Oct 23 13:33:18 2009
@@ -89,7 +89,11 @@
         int resolution = paintingState.getResolution();
         int maxPixelSize = paintingState.getBitsPerPixel();
         if (paintingState.isColorImages()) {
-            maxPixelSize *= 3; //RGB only at the moment
+            if (paintingState.isCMYKImagesSupported()) {
+                maxPixelSize *= 4; //CMYK is maximum
+            } else {
+                maxPixelSize *= 3; //RGB is maximum
+            }
         }
         RenderedImage renderedImage = imageRendered.getRenderedImage();
 
@@ -97,6 +101,7 @@
         ImageSize intrinsicSize = imageInfo.getSize();
 
         boolean useFS10 = (maxPixelSize == 1) || 
BitmapImageUtil.isMonochromeImage(renderedImage);
+        int functionSet = useFS10 ? 10 : 11;
         boolean usePageSegments = useFS10
                     && 
!imageObjectInfo.getResourceInfo().getLevel().isInline();
 
@@ -124,11 +129,6 @@
                         resampledDim.width, resampledDim.height, resolution);
             }
         }
-        if (useFS10) {
-            imageObjectInfo.setMimeType(MimeConstants.MIME_AFP_IOCA_FS10);
-        } else {
-            imageObjectInfo.setMimeType(MimeConstants.MIME_AFP_IOCA_FS11);
-        }
 
         imageObjectInfo.setDataHeightRes((int)Math.round(
                 effIntrinsicSize.getDpiHorizontal() * 10));
@@ -156,9 +156,9 @@
         byte[] imageData = null;
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         boolean allowDirectEncoding = true;
-        if (allowDirectEncoding && pixelSize <= maxPixelSize) {
+        if (allowDirectEncoding && (pixelSize <= maxPixelSize)) {
             //Attempt to encode without resampling the image
-            ImageEncodingHelper helper = new 
ImageEncodingHelper(renderedImage);
+            ImageEncodingHelper helper = new 
ImageEncodingHelper(renderedImage, pixelSize == 32);
             ColorModel encodedColorModel = helper.getEncodedColorModel();
             boolean directEncode = true;
             if (helper.getEncodedColorModel().getPixelSize() > maxPixelSize) {
@@ -180,6 +180,9 @@
                     log.trace("set subtractive mode");
                     imageObjectInfo.setSubtractive(true);
                 }
+                if (pixelSize == 32) {
+                    functionSet = 45; //IOCA FS45 required for CMYK
+                }
 
                 helper.encode(baos);
                 imageData = baos.toByteArray();
@@ -191,6 +194,7 @@
             //Convert image to 24bit RGB
             ImageEncodingHelper.encodeRenderedImageAsRGB(renderedImage, baos);
             imageData = baos.toByteArray();
+            imageObjectInfo.setBitsPerPixel(24);
 
             boolean colorImages = paintingState.isColorImages();
             imageObjectInfo.setColor(colorImages);
@@ -212,6 +216,20 @@
             }
         }
 
+        switch (functionSet) {
+        case 10:
+            imageObjectInfo.setMimeType(MimeConstants.MIME_AFP_IOCA_FS10);
+            break;
+        case 11:
+            imageObjectInfo.setMimeType(MimeConstants.MIME_AFP_IOCA_FS11);
+            break;
+        case 45:
+            imageObjectInfo.setMimeType(MimeConstants.MIME_AFP_IOCA_FS45);
+            break;
+        default:
+            throw new IllegalStateException("Invalid IOCA function set: " + 
functionSet);
+        }
+
         imageObjectInfo.setData(imageData);
 
         // set object area info

Modified: 
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPRenderer.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPRenderer.java?rev=829057&r1=829056&r2=829057&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPRenderer.java 
(original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPRenderer.java 
Fri Oct 23 13:33:18 2009
@@ -90,8 +90,8 @@
 import org.apache.fop.render.afp.extensions.AFPExtensionAttachment;
 import org.apache.fop.render.afp.extensions.AFPIncludeFormMap;
 import org.apache.fop.render.afp.extensions.AFPInvokeMediumMap;
-import org.apache.fop.render.afp.extensions.AFPPageSetup;
 import org.apache.fop.render.afp.extensions.AFPPageOverlay;
+import org.apache.fop.render.afp.extensions.AFPPageSetup;
 
 /**
  * This is an implementation of a FOP Renderer that renders areas to AFP.
@@ -444,6 +444,7 @@
         ImageFlavor.XML_DOM,
         /*ImageFlavor.RAW_PNG, */ // PNG not natively supported in AFP
         ImageFlavor.RAW_JPEG, ImageFlavor.RAW_CCITTFAX, ImageFlavor.RAW_EPS,
+        ImageFlavor.RAW_TIFF,
         ImageFlavor.GRAPHICS2D, ImageFlavor.BUFFERED_IMAGE, 
ImageFlavor.RENDERED_IMAGE };
 
     private static final ImageFlavor[] FLAVORS = new ImageFlavor[] {
@@ -831,6 +832,11 @@
     }
 
     /** {...@inheritdoc} */
+    public void setCMYKImagesSupported(boolean value) {
+        paintingState.setCMYKImagesSupported(value);
+    }
+
+    /** {...@inheritdoc} */
     public void setShadingMode(AFPShadingMode shadingMode) {
         this.shadingMode = shadingMode;
     }

Modified: 
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java?rev=829057&r1=829056&r2=829057&view=diff
==============================================================================
--- 
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java
 (original)
+++ 
xmlgraphics/fop/trunk/src/java/org/apache/fop/render/afp/AFPRendererConfigurator.java
 Fri Oct 23 13:33:18 2009
@@ -318,6 +318,9 @@
         String imagesMode = imagesCfg.getAttribute("mode", 
IMAGES_MODE_GRAYSCALE);
         if (IMAGES_MODE_COLOR.equals(imagesMode)) {
             customizable.setColorImages(true);
+
+            boolean cmyk = imagesCfg.getAttributeAsBoolean("cmyk", false);
+            customizable.setCMYKImagesSupported(cmyk);
         } else {
             customizable.setColorImages(false);
             // default to 8 bits per pixel

Modified: xmlgraphics/fop/trunk/status.xml
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/status.xml?rev=829057&r1=829056&r2=829057&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/status.xml (original)
+++ xmlgraphics/fop/trunk/status.xml Fri Oct 23 13:33:18 2009
@@ -58,6 +58,9 @@
       documents. Example: the fix of marks layering will be such a case when 
it's done.
     -->
     <release version="FOP Trunk" date="TBD">
+      <action context="Code" dev="JM" type="add">
+        Added support for encoding CMYK bitmap images (IOCA FS45) and TIFF 
images as embedded objects.
+      </action>
       <action context="Code" dev="AC" type="add">
         Added support for xmlfile and xsltfile parameters in FOP's Ant Task.
       </action>



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to