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;
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)
} else {
imageObj.setIDESize((byte) imageObjectInfo.getBitsPerPixel());
}
+ imageObj.setSubtractive(imageObjectInfo.isSubtractive());
imageObj.setData(imageObjectInfo.getData());
/** compression type if any */
private int compression = -1;
+ private boolean subtractive;
+
/**
* Default constructor
*/
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
/** the image color model */
private byte colorModel = (byte)0x01;
+ /** additive/subtractive setting for ASFLAG */
+ private boolean subtractive = false;
+
/** the image data */
private byte[] data;
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)
*
* @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
};
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];
}
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.
*
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;
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);
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();
}