}
// Should take care of the ColorSpace and bitsPerPixel
- this.bitmapsSize = this.width * this.height * 3;
- this.bitmaps = new byte[this.bitmapsSize];
+ this.bitmaps = new byte[this.width * this.height * 3];
for (int i = 0; i < this.height; i++) {
for (int j = 0; j < this.width; j++) {
int p = tmpMap[i * this.width + j];
protected int bitsPerPixel = 0;
/**
- * Image data (uncompressed).
+ * Image data (pixels, uncompressed).
*/
protected byte[] bitmaps = null;
/**
- * Image data size.
+ * Image data (undecoded, compressed, for image formats that can be embedded without decoding.
*/
- protected int bitmapsSize = 0;
+ protected byte[] raw = null;
/**
* Image transparency.
}
/**
- * Return the image data (uncompressed).
+ * Return the image data (pixels, uncompressed).
* @return the image data
*/
public byte[] getBitmaps() {
}
/**
- * Return the image data size (uncompressed).
+ * Return the image data size (number of bytes taken up by the uncompressed pixels).
* @return the image data size
*/
public int getBitmapsSize() {
- return this.bitmapsSize;
+ return (bitmaps != null ? bitmaps.length : 0);
}
/**
* @return the original image data
*/
public byte[] getRessourceBytes() {
- return null;
+ return raw;
}
/**
* @return the original image data size
*/
public int getRessourceBytesSize() {
- return 0;
+ return (raw != null ? raw.length : 0);
}
}
* @see org.apache.fop.image.FopImage#hasSoftMask()
*/
public boolean hasSoftMask() {
- if (this.bitmaps == null) {
+ if (this.bitmaps == null && this.raw == null) {
loadImage();
}
protected void loadImage() {
if (loadDimensions()) {
try {
+ if (cr == null) {
+ throw new IllegalStateException(
+ "Can't load the bitmaps data without the CachableRed instance");
+ }
+
// Get our current ColorModel
ColorModel cm = cr.getColorModel();
// It has an alpha channel so generate a soft mask.
- if (!this.isTransparent && cm.hasAlpha())
+ if (!this.isTransparent && cm.hasAlpha()) {
this.softMask = new byte[this.width * this.height];
+ }
- this.bitmapsSize = this.width * this.height * 3;
- this.bitmaps = new byte[this.bitmapsSize];
+ this.bitmaps = new byte[this.width * this.height * 3];
WritableRaster wr = (WritableRaster)cr.getData();
BufferedImage bi = new BufferedImage
}
// Should take care of the ColorSpace and bitsPerPixel
- this.bitmapsSize = this.width * this.height * 3;
- this.bitmaps = new byte[this.bitmapsSize];
+ this.bitmaps = new byte[this.width * this.height * 3];
int[] temp = new int[bytes * this.height];
try {
}
// Should take care of the ColorSpace and bitsPerPixel
- this.bitmapsSize = this.width * this.height * 3;
- this.bitmaps = new byte[this.bitmapsSize];
+ this.bitmaps = new byte[this.width * this.height * 3];
for (int i = 0; i < this.height; i++) {
for (int j = 0; j < this.width; j++) {
int p = tmpMap[i * this.width + j];
import java.awt.image.ColorModel;
import java.awt.image.IndexColorModel;
import java.awt.image.BufferedImage;
-import java.awt.color.ColorSpace;
import java.awt.Color;
// JAI
}
// Should take care of the ColorSpace and bitsPerPixel
- this.bitmapsSize = this.width * this.height * 3;
- this.bitmaps = new byte[this.bitmapsSize];
+ this.bitmaps = new byte[this.width * this.height * 3];
for (int i = 0; i < this.height; i++) {
for (int j = 0; j < this.width; j++) {
int p = tmpMap[i * this.width + j];
protected void loadImage() {
int[] tmpMap = null;
try {
- ImageProducer ip =
- Jimi.getImageProducer(inputStream,
+ ImageProducer ip = Jimi.getImageProducer(inputStream,
Jimi.SYNCHRONOUS | Jimi.IN_MEMORY);
FopImageConsumer consumer = new FopImageConsumer(ip);
ip.startProduction(consumer);
// Should take care of the ColorSpace and bitsPerPixel
- this.bitmapsSize = this.width * this.height * 3;
- this.bitmaps = new byte[this.bitmapsSize];
+ this.bitmaps = new byte[this.width * this.height * 3];
for (int i = 0; i < this.height; i++) {
for (int j = 0; j < this.width; j++) {
int p = tmpMap[i * this.width + j];
public class JpegImage extends AbstractFopImage {
private ICC_Profile iccProfile = null;
private boolean foundICCProfile = false;
- private boolean foundDimensions = false;
/**
* Create a jpeg image with the info.
inputStream = null;
}
- this.bitmaps = baos.toByteArray();
+ this.raw = baos.toByteArray();
this.bitsPerPixel = 8;
this.isTransparent = false;
//Check for SOI (Start of image) marker (FFD8)
- if (this.bitmaps.length > (index + 2)
- && uByte(this.bitmaps[index]) == 255 /*0xFF*/
- && uByte(this.bitmaps[index + 1]) == 216 /*0xD8*/) {
+ if (this.raw.length > (index + 2)
+ && uByte(this.raw[index]) == 255 /*0xFF*/
+ && uByte(this.raw[index + 1]) == 216 /*0xD8*/) {
index += 2;
- while (index < this.bitmaps.length && cont) {
+ while (index < this.raw.length && cont) {
//check to be sure this is the begining of a header
- if (this.bitmaps.length > (index + 2)
- && uByte(this.bitmaps[index]) == 255 /*0xFF*/) {
+ if (this.raw.length > (index + 2)
+ && uByte(this.raw[index]) == 255 /*0xFF*/) {
//192 or 194 are the header bytes that contain
// the jpeg width height and color depth.
- if (uByte(this.bitmaps[index + 1]) == 192 /*0xC0*/
- || uByte(this.bitmaps[index + 1]) == 194 /*0xC2*/) {
+ if (uByte(this.raw[index + 1]) == 192 /*0xC0*/
+ || uByte(this.raw[index + 1]) == 194 /*0xC2*/) {
- this.height = calcBytes(this.bitmaps[index + 5],
- this.bitmaps[index + 6]);
- this.width = calcBytes(this.bitmaps[index + 7],
- this.bitmaps[index + 8]);
+ this.height = calcBytes(this.raw[index + 5],
+ this.raw[index + 6]);
+ this.width = calcBytes(this.raw[index + 7],
+ this.raw[index + 8]);
- if (this.bitmaps[index + 9] == 1) {
+ if (this.raw[index + 9] == 1) {
this.colorSpace = ColorSpace.getInstance(
ColorSpace.CS_GRAY);
- } else if (this.bitmaps[index + 9] == 3) {
+ } else if (this.raw[index + 9] == 3) {
this.colorSpace = ColorSpace.getInstance(
ColorSpace.CS_LINEAR_RGB);
- } else if (this.bitmaps[index + 9] == 4) {
+ } else if (this.raw[index + 9] == 4) {
// howto create CMYK color space
/*
this.colorSpace = ColorSpace.getInstance(
return false;
}
- foundDimensions = true;
if (foundICCProfile) {
cont = false;
break;
}
- index += calcBytes(this.bitmaps[index + 2],
- this.bitmaps[index + 3]) + 2;
+ index += calcBytes(this.raw[index + 2],
+ this.raw[index + 3]) + 2;
- } else if (uByte(this.bitmaps[index + 1]) == 226 /*0xE2*/
- && this.bitmaps.length > (index + 60)) {
+ } else if (uByte(this.raw[index + 1]) == 226 /*0xE2*/
+ && this.raw.length > (index + 60)) {
// Check if ICC profile
byte[] iccString = new byte[11];
- System.arraycopy(this.bitmaps, index + 4,
+ System.arraycopy(this.raw, index + 4,
iccString, 0, 11);
if ("ICC_PROFILE".equals(new String(iccString))) {
int chunkSize = calcBytes(
- this.bitmaps[index + 2],
- this.bitmaps[index + 3]) + 2;
+ this.raw[index + 2],
+ this.raw[index + 3]) + 2;
- iccStream.write(this.bitmaps,
+ iccStream.write(this.raw,
index + 18, chunkSize - 18);
}
- index += calcBytes(this.bitmaps[index + 2],
- this.bitmaps[index + 3]) + 2;
+ index += calcBytes(this.raw[index + 2],
+ this.raw[index + 3]) + 2;
} else {
- index += calcBytes(this.bitmaps[index + 2],
- this.bitmaps[index + 3]) + 2;
+ index += calcBytes(this.raw[index + 2],
+ this.raw[index + 3]) + 2;
}
} else {
return stripCount;
}
- /**
- * @see org.apache.fop.image.BatikImage#decodeImage(org.apache.batik.ext.awt.image.codec.SeekableStream)
- */
+ /** @see org.apache.fop.image.BatikImage */
protected CachableRed decodeImage(SeekableStream stream) throws IOException {
org.apache.batik.ext.awt.image.codec.tiff.TIFFImage img
= new org.apache.batik.ext.awt.image.codec.tiff.TIFFImage
return false;
}
- this.bitmaps = readBuf;
+ this.raw = readBuf;
return true;
} catch (IOException ioe) {
log.error("Error while loading image strip 1 (TIFF): ", ioe);
if (isPS) {
outputPostScriptContents(out);
} else {
- out.write(fopImage.getBitmaps());
+ if (fopImage.getBitmapsSize() > 0) {
+ out.write(fopImage.getBitmaps());
+ } else {
+ out.write(fopImage.getRessourceBytes());
+ }
}
}
}
boolean iscolor = img.getColorSpace().getType()
!= ColorSpace.CS_GRAY;
- byte[] imgmap = img.getBitmaps();
+ byte[] imgmap;
+ if (img.getBitmapsSize() > 0) {
+ imgmap = img.getBitmaps();
+ } else {
+ imgmap = img.getRessourceBytes();
+ }
gen.saveGraphicsState();
gen.writeln(x + " " + y + " translate");