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-ffa450edef68pull/37/head
@@ -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()); | |||
@@ -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") | |||
+ "}"; | |||
} | |||
} |
@@ -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]; | |||
} |
@@ -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. | |||
* |
@@ -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); |
@@ -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(); | |||
} |