aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremias Maerki <jeremias@apache.org>2009-01-15 16:54:45 +0000
committerJeremias Maerki <jeremias@apache.org>2009-01-15 16:54:45 +0000
commit6ecef8a3e6b919c0a544d0f4c28e15a5928445a8 (patch)
treec0014fa13097243fade22bdaaeb2467468bf9268
parent3ba2a9633b964923cd2a00bf36af130255beed47 (diff)
downloadxmlgraphics-fop-6ecef8a3e6b919c0a544d0f4c28e15a5928445a8.tar.gz
xmlgraphics-fop-6ecef8a3e6b919c0a544d0f4c28e15a5928445a8.zip
Added in support for subtractive mode in 1-bit images. This should further reduce AFP file sizes for certain images.
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
-rw-r--r--src/java/org/apache/fop/afp/AFPDataObjectFactory.java6
-rw-r--r--src/java/org/apache/fop/afp/AFPImageObjectInfo.java19
-rw-r--r--src/java/org/apache/fop/afp/ioca/ImageContent.java31
-rw-r--r--src/java/org/apache/fop/afp/ioca/ImageSegment.java8
-rw-r--r--src/java/org/apache/fop/afp/modca/ImageObject.java11
-rw-r--r--src/java/org/apache/fop/render/afp/AFPImageHandlerRenderedImage.java10
6 files changed, 77 insertions, 8 deletions
diff --git a/src/java/org/apache/fop/afp/AFPDataObjectFactory.java b/src/java/org/apache/fop/afp/AFPDataObjectFactory.java
index 80cb40713..f6de7b5b4 100644
--- a/src/java/org/apache/fop/afp/AFPDataObjectFactory.java
+++ b/src/java/org/apache/fop/afp/AFPDataObjectFactory.java
@@ -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());
diff --git a/src/java/org/apache/fop/afp/AFPImageObjectInfo.java b/src/java/org/apache/fop/afp/AFPImageObjectInfo.java
index f3677534f..45ea5fc1f 100644
--- a/src/java/org/apache/fop/afp/AFPImageObjectInfo.java
+++ b/src/java/org/apache/fop/afp/AFPImageObjectInfo.java
@@ -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
diff --git a/src/java/org/apache/fop/afp/ioca/ImageContent.java b/src/java/org/apache/fop/afp/ioca/ImageContent.java
index 40e51578b..bdb2455d9 100644
--- a/src/java/org/apache/fop/afp/ioca/ImageContent.java
+++ b/src/java/org/apache/fop/afp/ioca/ImageContent.java
@@ -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;
@@ -123,6 +126,14 @@ public class ImageContent extends AbstractStructuredObject {
}
/**
+ * 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)
*
* @param imageData the image data
@@ -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];
}
diff --git a/src/java/org/apache/fop/afp/ioca/ImageSegment.java b/src/java/org/apache/fop/afp/ioca/ImageSegment.java
index 9fb544719..5ecbc63bb 100644
--- a/src/java/org/apache/fop/afp/ioca/ImageSegment.java
+++ b/src/java/org/apache/fop/afp/ioca/ImageSegment.java
@@ -114,6 +114,14 @@ public class ImageSegment extends AbstractNamedAFPObject {
}
/**
+ * 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.
*
* @param data the image data
diff --git a/src/java/org/apache/fop/afp/modca/ImageObject.java b/src/java/org/apache/fop/afp/modca/ImageObject.java
index 24ac0cb22..b11d478cc 100644
--- a/src/java/org/apache/fop/afp/modca/ImageObject.java
+++ b/src/java/org/apache/fop/afp/modca/ImageObject.java
@@ -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;
@@ -114,9 +115,17 @@ public class ImageObject extends AbstractDataObject {
}
/**
+ * 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);
diff --git a/src/java/org/apache/fop/render/afp/AFPImageHandlerRenderedImage.java b/src/java/org/apache/fop/render/afp/AFPImageHandlerRenderedImage.java
index b956d8264..66915ec2d 100644
--- a/src/java/org/apache/fop/render/afp/AFPImageHandlerRenderedImage.java
+++ b/src/java/org/apache/fop/render/afp/AFPImageHandlerRenderedImage.java
@@ -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();
}