]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Added in support for subtractive mode in 1-bit images. This should further reduce...
authorJeremias Maerki <jeremias@apache.org>
Thu, 15 Jan 2009 16:54:45 +0000 (16:54 +0000)
committerJeremias Maerki <jeremias@apache.org>
Thu, 15 Jan 2009 16:54:45 +0000 (16:54 +0000)
We need to change the way the AFP library works in the long term. Adding one boolean flag causes changes in 5 different classes. That can't be it.

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@734754 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/afp/AFPDataObjectFactory.java
src/java/org/apache/fop/afp/AFPImageObjectInfo.java
src/java/org/apache/fop/afp/ioca/ImageContent.java
src/java/org/apache/fop/afp/ioca/ImageSegment.java
src/java/org/apache/fop/afp/modca/ImageObject.java
src/java/org/apache/fop/render/afp/AFPImageHandlerRenderedImage.java

index 80cb40713242062e6ca5e11948cfb824e120046c..f6de7b5b44bbbeb7d144399edd541be417ff4b34 100644 (file)
@@ -21,6 +21,9 @@ package org.apache.fop.afp;
 
 import java.awt.geom.Rectangle2D;
 
+import org.apache.xmlgraphics.image.codec.tiff.TIFFImage;
+import org.apache.xmlgraphics.java2d.Graphics2DImagePainter;
+
 import org.apache.fop.afp.ioca.ImageContent;
 import org.apache.fop.afp.modca.AbstractDataObject;
 import org.apache.fop.afp.modca.AbstractNamedAFPObject;
@@ -35,8 +38,6 @@ import org.apache.fop.afp.modca.Registry;
 import org.apache.fop.afp.modca.ResourceObject;
 import org.apache.fop.afp.modca.triplets.MappingOptionTriplet;
 import org.apache.fop.afp.modca.triplets.ObjectClassificationTriplet;
-import org.apache.xmlgraphics.image.codec.tiff.TIFFImage;
-import org.apache.xmlgraphics.java2d.Graphics2DImagePainter;
 
 /**
  * Factory for high level data objects (Image/Graphics etc)
@@ -117,6 +118,7 @@ public class AFPDataObjectFactory {
         } else {
             imageObj.setIDESize((byte) imageObjectInfo.getBitsPerPixel());
         }
+        imageObj.setSubtractive(imageObjectInfo.isSubtractive());
 
         imageObj.setData(imageObjectInfo.getData());
 
index f3677534f494a8921ae542882b60fb872569024b..45ea5fc1fc4e6ba2f87e8cdd1b9da0e79eaae9b3 100644 (file)
@@ -34,6 +34,8 @@ public class AFPImageObjectInfo extends AFPDataObjectInfo {
     /** compression type if any */
     private int compression = -1;
 
+    private boolean subtractive;
+
     /**
      * Default constructor
      */
@@ -104,12 +106,29 @@ public class AFPImageObjectInfo extends AFPDataObjectInfo {
         this.compression = compression;
     }
 
+    /**
+     * 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;
+    }
+
+    /**
+     * Indicates whether additive or subtractive mode is set.
+     * @return true for subtractive mode, false for additive mode
+     */
+    public boolean isSubtractive() {
+        return subtractive;
+    }
+
     /** {@inheritDoc} */
     public String toString() {
         return "AFPImageObjectInfo{" + super.toString()
             + ", compression=" + compression
             + ", color=" + color
             + ", bitsPerPixel=" + bitsPerPixel
+            + ", " + (isSubtractive() ? "subtractive" : "additive")
             + "}";
     }
 }
\ No newline at end of file
index 40e51578b3d944495d51d231bb0c4fedbe1c2a10..bdb2455d901ae2b7cb85bd1cec7737bb6817ff0a 100644 (file)
@@ -68,6 +68,9 @@ public class ImageContent extends AbstractStructuredObject {
     /** the image color model */
     private byte colorModel = (byte)0x01;
 
+    /** additive/subtractive setting for ASFLAG */
+    private boolean subtractive = false;
+
     /** the image data */
     private byte[] data;
 
@@ -122,6 +125,14 @@ public class ImageContent extends AbstractStructuredObject {
         this.colorModel = color;
     }
 
+    /**
+     * 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;
+    }
+
     /**
      * Set the image data (can be byte array or inputstream)
      *
@@ -243,12 +254,16 @@ public class ImageContent extends AbstractStructuredObject {
      * @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
-                0x00, // FLAGS
+                flags, // FLAGS
                 0x00, // Reserved
                 colorModel, // COLOR MODEL
                 0x00, // Reserved
@@ -260,6 +275,20 @@ public class ImageContent extends AbstractStructuredObject {
             };
             ideStructData[1] = (byte)(ideStructData.length - 2);
             return ideStructData;
+        } else if (size == 1) {
+            final byte[] ideStructData = new byte[] {
+                    (byte)0x9B, // ID
+                    0x00, // Length
+                    flags, // FLAGS
+                    0x00, // Reserved
+                    colorModel, // COLOR MODEL
+                    0x00, // Reserved
+                    0x00, // Reserved
+                    0x00, // Reserved
+                    1
+                };
+                ideStructData[1] = (byte)(ideStructData.length - 2);
+                return ideStructData;
         }
         return new byte[0];
     }
index 9fb5447197786550a184e1f3781c6d524ed2b6e6..5ecbc63bb6d6399f66e2711546700af005d60f58 100644 (file)
@@ -113,6 +113,14 @@ public class ImageSegment extends AbstractNamedAFPObject {
         getImageContent().setImageIDEColorModel(colorModel);
     }
 
+    /**
+     * Set either additive or subtractive mode (used for ASFLAG).
+     * @param subtractive true for subtractive mode, false for additive mode
+     */
+    public void setSubtractive(boolean subtractive) {
+        getImageContent().setSubtractive(subtractive);
+    }
+
     /**
      * Set the data image data.
      *
index 24ac0cb22b47b391219b7737c3458dabc47cb01a..b11d478cc65c4e16560ce692cf9453bfbce0c3d5 100644 (file)
@@ -23,6 +23,7 @@ import java.io.IOException;
 import java.io.OutputStream;
 
 import org.apache.commons.io.output.ByteArrayOutputStream;
+
 import org.apache.fop.afp.AFPDataObjectInfo;
 import org.apache.fop.afp.AFPImageObjectInfo;
 import org.apache.fop.afp.Factory;
@@ -113,10 +114,18 @@ public class ImageObject extends AbstractDataObject {
         getImageSegment().setIDEColorModel(colorModel);
     }
 
+    /**
+     * Set either additive or subtractive mode (used for ASFLAG).
+     * @param subtractive true for subtractive mode, false for additive mode
+     */
+    public void setSubtractive(boolean subtractive) {
+        getImageSegment().setSubtractive(subtractive);
+    }
+
     /**
      * Set the data of the image.
      *
-     * @param data the image data
+     * @param imageData the image data
      */
     public void setData(byte[] imageData) {
         getImageSegment().setData(imageData);
index b956d826428bfd4313f44bc8c97e0b65c18c2bd8..66915ec2d6d81911bd56690ba0b8f770c489e6c1 100644 (file)
@@ -105,13 +105,15 @@ public class AFPImageHandlerRenderedImage extends AFPImageHandler {
             if (BitmapImageUtil.getColorIndexSize(renderedImage) > 2) {
                 directEncode = false; //Lookup tables are not implemented, yet
             }
-            if (BitmapImageUtil.isMonochromeImage(renderedImage)
-                    && BitmapImageUtil.isZeroBlack(renderedImage)) {
-                directEncode = false; //Passing additive/subtractive info not implemented, yet
-            }
             if (directEncode) {
                 log.debug("Encoding image directly...");
                 imageObjectInfo.setBitsPerPixel(encodedColorModel.getPixelSize());
+                if (BitmapImageUtil.isMonochromeImage(renderedImage)
+                        && !BitmapImageUtil.isZeroBlack(renderedImage)) {
+                    log.trace("set subtractive mode");
+                    imageObjectInfo.setSubtractive(true);
+                }
+
                 helper.encode(baos);
                 imageData = baos.toByteArray();
             }