/*
* $Id$
- * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
+ * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/
package org.apache.fop.image;
// Java
-import java.net.URL;
import java.awt.color.ColorSpace;
import java.awt.color.ICC_Profile;
import java.io.InputStream;
// FOP
import org.apache.fop.pdf.PDFColor;
-import org.apache.fop.image.analyser.ImageReaderFactory;
-import org.apache.fop.image.analyser.ImageReader;
import org.apache.fop.fo.FOUserAgent;
/**
* @see FopImage
*/
public abstract class AbstractFopImage implements FopImage {
+ /**
+ * Keeps track of what has been loaded.
+ */
protected int loaded = 0;
/**
* Image width (in pixel).
*/
- protected int m_width = 0;
+ protected int width = 0;
/**
* Image height (in pixel).
*/
- protected int m_height = 0;
+ protected int height = 0;
/**
* Image input stream.
/**
* Image color space (java.awt.color.ColorSpace).
*/
- protected ColorSpace m_colorSpace = null;
+ protected ColorSpace colorSpace = null;
/**
* Bits per pixel.
*/
- protected int m_bitsPerPixel = 0;
+ protected int bitsPerPixel = 0;
/**
* Image data (uncompressed).
*/
- protected byte[] m_bitmaps = null;
+ protected byte[] bitmaps = null;
/**
* Image data size.
*/
- protected int m_bitmapsSize = 0;
+ protected int bitmapsSize = 0;
/**
* Image transparency.
*/
- protected boolean m_isTransparent = false;
+ protected boolean isTransparent = false;
/**
* Transparent color (org.apache.fop.pdf.PDFColor).
*/
- protected PDFColor m_transparentColor = null;
+ protected PDFColor transparentColor = null;
/**
* Constructor.
* <LI>image height
* </UL>
* The image data isn't kept in memory.
- * @param input input stream
- * imgReader ImageReader object
- * @return a new FopImage object
+ * @param info image information
*/
public AbstractFopImage(FopImage.ImageInfo info) {
this.inputStream = info.inputStream;
this.imageInfo = info;
- if(this.imageInfo.width != -1) {
- m_width = imageInfo.width;
- m_height = imageInfo.height;
+ if (this.imageInfo.width != -1) {
+ width = imageInfo.width;
+ height = imageInfo.height;
loaded = loaded | DIMENSIONS;
}
}
+ /**
+ * Get the mime type for this image.
+ *
+ * @return the mime type for the image
+ */
public String getMimeType() {
return imageInfo.mimeType;
}
/**
* Load image data and initialize its properties.
+ *
+ * @param type the type of loading to do
+ * @param ua the user agent for handling logging etc.
+ * @return true if the loading was successful
*/
public synchronized boolean load(int type, FOUserAgent ua) {
- if((loaded & type) != 0) {
+ if ((loaded & type) != 0) {
return true;
}
boolean success = true;
- if(((type & DIMENSIONS) != 0) && ((loaded & DIMENSIONS) == 0)) {
+ if (((type & DIMENSIONS) != 0) && ((loaded & DIMENSIONS) == 0)) {
success = success && loadDimensions(ua);
- if(!success) {
+ if (!success) {
return false;
}
loaded = loaded | DIMENSIONS;
}
- if(((type & BITMAP) != 0) && ((loaded & BITMAP) == 0)) {
+ if (((type & BITMAP) != 0) && ((loaded & BITMAP) == 0)) {
success = success && loadBitmap(ua);
- if(success) {
+ if (success) {
loaded = loaded | BITMAP;
}
}
- if(((type & ORIGINAL_DATA) != 0) && ((loaded & ORIGINAL_DATA) == 0)) {
+ if (((type & ORIGINAL_DATA) != 0) && ((loaded & ORIGINAL_DATA) == 0)) {
success = success && loadOriginalData(ua);
- if(success) {
+ if (success) {
loaded = loaded | ORIGINAL_DATA;
}
}
return success;
}
+ /**
+ * Load the dimensions of the image.
+ * All implementations should override this to get and
+ * return the dimensions.
+ *
+ * @param ua the user agent
+ * @return true if the loading was successful
+ */
protected boolean loadDimensions(FOUserAgent ua) {
return false;
}
+ /**
+ * Load a bitmap array of the image.
+ * If the renderer requires a bitmap image then the
+ * implementations should override this to load the bitmap.
+ *
+ * @param ua the user agent
+ * @return true if the loading was successful
+ */
protected boolean loadBitmap(FOUserAgent ua) {
return false;
}
+ /**
+ * Load the original image data.
+ * In some cases the original data can be used by the renderer.
+ * This should load the data and any other associated information.
+ *
+ * @param ua the user agent
+ * @return true if the loading was successful
+ */
protected boolean loadOriginalData(FOUserAgent ua) {
return false;
}
* @return the image width
*/
public int getWidth() {
- return this.m_width;
+ return this.width;
}
/**
* @return the image height
*/
public int getHeight() {
- return this.m_height;
+ return this.height;
}
/**
* @return the image color space (java.awt.color.ColorSpace)
*/
public ColorSpace getColorSpace() {
- return this.m_colorSpace;
+ return this.colorSpace;
}
/**
* Get ICC profile for this image.
+ * @return the icc profile or null if not applicable
*/
public ICC_Profile getICCProfile() {
return null;
* @return number of bits per pixel
*/
public int getBitsPerPixel() {
- return this.m_bitsPerPixel;
+ return this.bitsPerPixel;
}
/**
* @return true if the image is transparent
*/
public boolean isTransparent() {
- return this.m_isTransparent;
+ return this.isTransparent;
}
+ /**
+ * Check if this image has a soft mask.
+ *
+ * @return true if the image also has a soft transparency mask
+ */
public boolean hasSoftMask() {
return false;
}
+ /**
+ * Get the soft mask.
+ * The soft mask should have the same bitdepth as the image data.
+ *
+ * @return the data array of soft mask values
+ */
public byte[] getSoftMask() {
return null;
}
* @return the transparent color (org.apache.fop.pdf.PDFColor)
*/
public PDFColor getTransparentColor() {
- return this.m_transparentColor;
+ return this.transparentColor;
}
/**
* @return the image data
*/
public byte[] getBitmaps() {
- return this.m_bitmaps;
+ return this.bitmaps;
}
/**
* @return the image data size
*/
public int getBitmapsSize() {
- return this.m_bitmapsSize;
+ return this.bitmapsSize;
}
/**
/*
* $Id$
- * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
+ * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/
-/**
- * FopImage object for BMP images.
- * @author Art WELCH
- * @see AbstractFopImage
- * @see FopImage
- */
-
package org.apache.fop.image;
// Java
-import java.net.URL;
-import java.io.InputStream;
import java.io.IOException;
import java.awt.color.ColorSpace;
// FOP
-import org.apache.fop.image.analyser.ImageReader;
import org.apache.fop.fo.FOUserAgent;
+/**
+ * Bitmap image.
+ * This supports loading a bitmap image into bitmap data.
+ *
+ * @author Art WELCH
+ * @see AbstractFopImage
+ * @see FopImage
+ */
public class BmpImage extends AbstractFopImage {
- public BmpImage(FopImage.ImageInfo imgReader) {
- super(imgReader);
+ /**
+ * Create a bitmap image with the image data.
+ *
+ * @param imgInfo the image information
+ */
+ public BmpImage(FopImage.ImageInfo imgInfo) {
+ super(imgInfo);
}
+ /**
+ * Load the bitmap.
+ * This laods the bitmap data from the bitmap image.
+ *
+ * @param ua the user agent
+ * @return true if it was loaded successfully
+ */
protected boolean loadBitmap(FOUserAgent ua) {
int wpos = 18;
int hpos = 22; // offset positioning for w and height in bmp files
boolean eof = false;
while ((!eof) && (filepos < 54)) {
int input = inputStream.read();
- if (input == -1)
+ if (input == -1) {
eof = true;
- else
+ } else {
headermap[filepos++] = input;
+ }
}
if (headermap[28] == 4 || headermap[28] == 8) {
int count2 = 2;
while (!eof && count2 >= -1) {
int input = inputStream.read();
- if (input == -1)
+ if (input == -1) {
eof = true;
- else if (count2 >= 0) {
+ } else if (count2 >= 0) {
palette[countr * 3 + count2] =
(byte)(input & 0xFF);
}
return false;
}
// gets h & w from headermap
- this.m_width = headermap[wpos] + headermap[wpos + 1] * 256 +
+ this.width = headermap[wpos] + headermap[wpos + 1] * 256 +
headermap[wpos + 2] * 256 * 256 +
headermap[wpos + 3] * 256 * 256 * 256;
- this.m_height = headermap[hpos] + headermap[hpos + 1] * 256 +
+ this.height = headermap[hpos] + headermap[hpos + 1] * 256 +
headermap[hpos + 2] * 256 * 256 +
headermap[hpos + 3] * 256 * 256 * 256;
int imagestart = headermap[10] + headermap[11] * 256 +
headermap[12] * 256 * 256 + headermap[13] * 256 * 256 * 256;
- this.m_bitsPerPixel = headermap[28];
- this.m_colorSpace = ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB);
+ this.bitsPerPixel = headermap[28];
+ this.colorSpace = ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB);
int bytes = 0;
- if (this.m_bitsPerPixel == 1)
- bytes = (this.m_width + 7) / 8;
- else if (this.m_bitsPerPixel == 24)
- bytes = this.m_width * 3;
- else if (this.m_bitsPerPixel == 4 || this.m_bitsPerPixel == 8)
- bytes = this.m_width / (8 / this.m_bitsPerPixel);
+ if (this.bitsPerPixel == 1)
+ bytes = (this.width + 7) / 8;
+ else if (this.bitsPerPixel == 24)
+ bytes = this.width * 3;
+ else if (this.bitsPerPixel == 4 || this.bitsPerPixel == 8)
+ bytes = this.width / (8 / this.bitsPerPixel);
else {
ua.getLogger().error("Image (" + ""
- + ") has " + this.m_bitsPerPixel
+ + ") has " + this.bitsPerPixel
+ " which is not a supported BMP format.");
return false;
}
}
// Should take care of the ColorSpace and bitsPerPixel
- this.m_bitmapsSize = this.m_width * this.m_height * 3;
- this.m_bitmaps = new byte[this.m_bitmapsSize];
+ this.bitmapsSize = this.width * this.height * 3;
+ this.bitmaps = new byte[this.bitmapsSize];
- int[] temp = new int[bytes * this.m_height];
+ int[] temp = new int[bytes * this.height];
try {
int input;
int count = 0;
return false;
}
- for (int i = 0; i < this.m_height; i++) {
+ for (int i = 0; i < this.height; i++) {
int x = 0;
int j = 0;
while (j < bytes) {
- int p = temp[(this.m_height - i - 1) * bytes + j];
+ int p = temp[(this.height - i - 1) * bytes + j];
- if (this.m_bitsPerPixel == 24 && x < this.m_width) {
+ if (this.bitsPerPixel == 24 && x < this.width) {
int countr = 2;
do {
- this.m_bitmaps[3 * (i * this.m_width + x) +
+ this.bitmaps[3 * (i * this.width + x) +
countr] =
- (byte)(temp[(this.m_height - i - 1) *
+ (byte)(temp[(this.height - i - 1) *
bytes + j] & 0xFF);
j++;
} while (--countr >= 0)
;
x++;
- } else if (this.m_bitsPerPixel == 1) {
+ } else if (this.bitsPerPixel == 1) {
for (int countr = 0;
- countr < 8 && x < this.m_width; countr++) {
+ countr < 8 && x < this.width; countr++) {
if ((p & 0x80) != 0) {
- this.m_bitmaps[3 *
- (i * this.m_width + x)] = (byte) 0xFF;
- this.m_bitmaps[3 * (i * this.m_width + x) +
+ this.bitmaps[3 *
+ (i * this.width + x)] = (byte) 0xFF;
+ this.bitmaps[3 * (i * this.width + x) +
1] = (byte) 0xFF;
- this.m_bitmaps[3 * (i * this.m_width + x) +
+ this.bitmaps[3 * (i * this.width + x) +
2] = (byte) 0xFF;
} else {
- this.m_bitmaps[3 *
- (i * this.m_width + x)] = (byte) 0;
- this.m_bitmaps[3 * (i * this.m_width + x) +
+ this.bitmaps[3 *
+ (i * this.width + x)] = (byte) 0;
+ this.bitmaps[3 * (i * this.width + x) +
1] = (byte) 0;
- this.m_bitmaps[3 * (i * this.m_width + x) +
+ this.bitmaps[3 * (i * this.width + x) +
2] = (byte) 0;
}
p <<= 1;
x++;
}
j++;
- } else if (this.m_bitsPerPixel == 4) {
+ } else if (this.bitsPerPixel == 4) {
for (int countr = 0;
- countr < 2 && x < this.m_width; countr++) {
+ countr < 2 && x < this.width; countr++) {
int pal = ((p & 0xF0) >> 4) * 3;
- this.m_bitmaps[3 * (i * this.m_width + x)] =
+ this.bitmaps[3 * (i * this.width + x)] =
palette[pal];
- this.m_bitmaps[3 * (i * this.m_width + x) +
+ this.bitmaps[3 * (i * this.width + x) +
1] = palette[pal + 1];
- this.m_bitmaps[3 * (i * this.m_width + x) +
+ this.bitmaps[3 * (i * this.width + x) +
2] = palette[pal + 2];
p <<= 4;
x++;
}
j++;
- } else if (this.m_bitsPerPixel == 8) {
- if (x < this.m_width) {
+ } else if (this.bitsPerPixel == 8) {
+ if (x < this.width) {
p *= 3;
- this.m_bitmaps[3 * (i * this.m_width + x)] =
+ this.bitmaps[3 * (i * this.width + x)] =
palette[p];
- this.m_bitmaps[3 * (i * this.m_width + x) +
+ this.bitmaps[3 * (i * this.width + x) +
1] = palette[p + 1];
- this.m_bitmaps[3 * (i * this.m_width + x) +
+ this.bitmaps[3 * (i * this.width + x) +
2] = palette[p + 2];
j++;
x++;
}
}
- // This seems really strange to me, but I noticed that JimiImage hardcodes
- // m_bitsPerPixel to 8. If I do not do this Acrobat is unable to read the resultant PDF,
+ // This seems really strange to me, but I noticed that
+ // JimiImage hardcodes bitsPerPixel to 8. If I do not
+ // do this Acrobat is unable to read the resultant PDF,
// so we will hardcode this...
- this.m_bitsPerPixel = 8;
+ this.bitsPerPixel = 8;
return true;
}
}
+
/*
* $Id$
- * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
+ * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/
package org.apache.fop.image;
-// Java
-import java.net.URL;
-import java.net.URLConnection;
-import java.io.InputStream;
-import java.io.IOException;
-
-// FOP
-import org.apache.fop.apps.Driver;
-import org.apache.fop.image.analyser.ImageReader;
-import org.apache.fop.image.analyser.EPSReader;
-
-import org.xml.sax.InputSource;
-import org.xml.sax.XMLReader;
-
/**
+ * EPS image handler.
+ * This handles the Encapulated PostScript images.
+ * It gets the dimensions and original data from the analyser.
+ *
* @see AbstractFopImage
* @see FopImage
*/
private EPSData epsData = null;
/**
- * Initialize docName and bounding box
+ * Create an EPS image with the image information.
+ *
+ * @param imgInfo the information containing the data and bounding box
+ */
+ public EPSImage(FopImage.ImageInfo imgInfo) {
+ super(imgInfo);
+ init("");
+ if (imgInfo.data instanceof EPSData) {
+ epsData = (EPSData) imgInfo.data;
+ bbox = new int[4];
+ bbox[0] = (int) epsData.bbox[0];
+ bbox[1] = (int) epsData.bbox[1];
+ bbox[2] = (int) epsData.bbox[2];
+ bbox[3] = (int) epsData.bbox[3];
+
+ loaded = loaded | ORIGINAL_DATA;
+ }
+ }
+
+ /**
+ * Initialize docName and bounding box.
+ * @param name the document name
*/
private void init(String name) {
bbox = new int[4];
/**
* Return the name of the eps
+ * @return the name of the eps
*/
public String getDocName() {
return docName;
/**
* Return the bounding box
+ * @return an int array containing the bounding box
*/
public int[] getBBox() {
return bbox;
}
- public EPSImage(FopImage.ImageInfo imgInfo) {
- super(imgInfo);
- init("");
- if (imgInfo.data instanceof EPSData) {
- epsData = (EPSData) imgInfo.data;
- bbox = new int[4];
- bbox[0] = (int) epsData.bbox[0];
- bbox[1] = (int) epsData.bbox[1];
- bbox[2] = (int) epsData.bbox[2];
- bbox[3] = (int) epsData.bbox[3];
-
- loaded = loaded | ORIGINAL_DATA;
- }
- }
-
+ /**
+ * Get the eps image.
+ *
+ * @return the original eps image data
+ */
public byte[] getEPSImage() {
if (epsData.epsFile == null) {
//log.error("ERROR LOADING EXTERNAL EPS");
return epsData.epsFile;
}
+ /**
+ * Data for EPS image.
+ */
public static class EPSData {
public long[] bbox;
public boolean isAscii; // True if plain ascii eps file
/*
* $Id$
- * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
+ * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/
-// Author: Eric SCHAEFFER
-// Description: represent an image object
-
package org.apache.fop.image;
import java.io.InputStream;
import org.apache.fop.pdf.PDFColor;
import org.apache.fop.fo.FOUserAgent;
+/**
+ * Fop image interface for loading images.
+ *
+ * @author Eric SCHAEFFER
+ */
public interface FopImage {
+ /**
+ * Flag for loading dimensions.
+ */
public static final int DIMENSIONS = 1;
+
+ /**
+ * Flag for loading original data.
+ */
public static final int ORIGINAL_DATA = 2;
+
+ /**
+ * Flag for loading bitmap data.
+ */
public static final int BITMAP = 4;
+ /**
+ * Get the mime type of this image.
+ * This is used so that when reading from the image it knows
+ * what type of image it is.
+ *
+ * @return the mime type string
+ */
public String getMimeType();
/**
* Load particular inforamtion for this image
* This must be called before attempting to get
* the information.
+ *
+ * @param type the type of loading required
+ * @param ua the user agent
* @return boolean true if the information could be loaded
*/
public boolean load(int type, FOUserAgent ua);
public byte[] getRessourceBytes();
public int getRessourceBytesSize();
+ /**
+ * Image info class.
+ * Information loaded from analyser and passed to image object.
+ */
public static class ImageInfo {
public InputStream inputStream;
public int width;
/*
* $Id$
- * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
+ * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/
package org.apache.fop.image;
// Java
-import java.net.URL;
import java.awt.image.ImageProducer;
import java.awt.image.ColorModel;
import java.awt.image.IndexColorModel;
import java.awt.color.ColorSpace;
-import java.io.InputStream;
// FOP
import org.apache.fop.pdf.PDFColor;
//ip = (ImageProducer) inputStream.getContent();
inputStream.close();
inputStream = null;
+ if (ip == null) {
+ return false;
+ }
FopImageConsumer consumer = new FopImageConsumer(ip);
ip.startProduction(consumer);
Thread.sleep(500);
}
- this.m_height = consumer.getHeight();
- this.m_width = consumer.getWidth();
+ this.height = consumer.getHeight();
+ this.width = consumer.getWidth();
try {
tmpMap = consumer.getImage();
}
ColorModel cm = consumer.getColorModel();
- this.m_bitsPerPixel = 8;
- // this.m_bitsPerPixel = cm.getPixelSize();
- this.m_colorSpace = ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB);
+ this.bitsPerPixel = 8;
+ // this.bitsPerPixel = cm.getPixelSize();
+ this.colorSpace = ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB);
if (cm.hasAlpha()) {
int transparencyType = cm.getTransparency(); // java.awt.Transparency. BITMASK or OPAQUE or TRANSLUCENT
if (transparencyType == java.awt.Transparency.OPAQUE) {
- this.m_isTransparent = false;
+ this.isTransparent = false;
} else if (transparencyType ==
java.awt.Transparency.BITMASK) {
if (cm instanceof IndexColorModel) {
IndexColorModel indexcm = (IndexColorModel) cm;
- this.m_isTransparent = false;
+ this.isTransparent = false;
byte[] alphas = new byte[indexcm.getMapSize()];
byte[] reds = new byte[indexcm.getMapSize()];
byte[] greens = new byte[indexcm.getMapSize()];
i < indexcm.getMapSize();
i++) {
if ((alphas[i] & 0xFF) == 0) {
- this.m_isTransparent = true;
- this.m_transparentColor = new PDFColor(
+ this.isTransparent = true;
+ this.transparentColor = new PDFColor(
(int)(reds[i] & 0xFF),
(int)(greens[i] & 0xFF),
(int)(blues[i] & 0xFF));
} else {
// TRANSLUCENT
/*
- * this.m_isTransparent = false;
- * for (int i = 0; i < this.m_width * this.m_height; i++) {
+ * this.isTransparent = false;
+ * for (int i = 0; i < this.width * this.height; i++) {
* if (cm.getAlpha(tmpMap[i]) == 0) {
- * this.m_isTransparent = true;
- * this.m_transparentColor = new PDFColor(cm.getRed(tmpMap[i]), cm.getGreen(tmpMap[i]), cm.getBlue(tmpMap[i]));
+ * this.isTransparent = true;
+ * this.transparentColor = new PDFColor(cm.getRed(tmpMap[i]), cm.getGreen(tmpMap[i]), cm.getBlue(tmpMap[i]));
* break;
* }
* }
*/
// use special API...
- this.m_isTransparent = false;
+ this.isTransparent = false;
}
} else {
- this.m_isTransparent = false;
+ this.isTransparent = false;
}
} else {
- this.m_isTransparent = false;
+ this.isTransparent = false;
}
} catch (Exception ex) {
ua.getLogger().error("Error while loading image "
}
// Should take care of the ColorSpace and bitsPerPixel
- this.m_bitmapsSize = this.m_width * this.m_height * 3;
- this.m_bitmaps = new byte[this.m_bitmapsSize];
- for (int i = 0; i < this.m_height; i++) {
- for (int j = 0; j < this.m_width; j++) {
- int p = tmpMap[i * this.m_width + j];
+ this.bitmapsSize = this.width * this.height * 3;
+ this.bitmaps = new byte[this.bitmapsSize];
+ for (int i = 0; i < this.height; i++) {
+ for (int j = 0; j < this.width; j++) {
+ int p = tmpMap[i * this.width + j];
int r = (p >> 16) & 0xFF;
int g = (p >> 8) & 0xFF;
int b = (p) & 0xFF;
- this.m_bitmaps[3 * (i * this.m_width + j)] =
+ this.bitmaps[3 * (i * this.width + j)] =
(byte)(r & 0xFF);
- this.m_bitmaps[3 * (i * this.m_width + j) + 1] =
+ this.bitmaps[3 * (i * this.width + j) + 1] =
(byte)(g & 0xFF);
- this.m_bitmaps[3 * (i * this.m_width + j) + 2] =
+ this.bitmaps[3 * (i * this.width + j) + 2] =
(byte)(b & 0xFF);
}
}
/*
* $Id$
- * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
+ * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/
// FOP
import org.apache.fop.fo.FOUserAgent;
+/**
+ * Image cache holder.
+ * This interface is used for caching images.
+ */
public interface ImageCache {
+ /**
+ * Get an image from the cache.
+ *
+ * @param url the url and key for the image
+ * @param context the user agent context
+ */
public FopImage getImage(String url, FOUserAgent context);
+
+ /**
+ * Release an image in the current context.
+ *
+ * @param url the url and key for the image
+ * @param context the user agent context
+ */
public void releaseImage(String url, FOUserAgent context);
+
+ /**
+ * Invalidate image.
+ * If during loading this image is found to be invalid
+ * it will be invalidated to prevent further attempts at
+ * loading the image.
+ *
+ * @param url the url and key for the image
+ * @param context the user agent context
+ */
public void invalidateImage(String url, FOUserAgent context);
+
+ /**
+ * Remove a context and handle all images in the context.
+ *
+ * @param context the user agent context
+ */
public void removeContext(FOUserAgent context);
}
// Avalon
import org.apache.avalon.framework.logger.Logger;
-/*
-handle context: base dir, logger, caching
-
- */
-
/**
* create FopImage objects (with a configuration file - not yet implemented).
* @author Eric SCHAEFFER
private ImageFactory() {}
+ /**
+ * Get static image factory instance.
+ *
+ * @return the image factory instance
+ */
public static ImageFactory getInstance() {
return factory;
}
+ /**
+ * Get the url string from a wrapped url.
+ *
+ * @href the input wrapped url
+ * @return the raw url
+ */
public static String getURL(String href) {
/*
* According to section 5.11 a <uri-specification> is:
* If this returns null then the image could not be loaded
* due to an error. Messages should be logged.
* Before calling this the getURL(url) must be used.
+ *
+ * @param url the url for the image
+ * @param context the user agent context
+ * @return the fop image instance
*/
public FopImage getImage(String url, FOUserAgent context) {
return cache.getImage(url, context);
* This can be used if the renderer has its own cache of
* the image.
* The image should then be put into the weak cache.
+ *
+ * @param url the url for the image
+ * @param context the user agent context
*/
public void releaseImage(String url, FOUserAgent context) {
cache.releaseImage(url, context);
* create an FopImage objects.
* @param href image URL as a String
* @return a new FopImage object
+ *
+ * @param href the url for the image
+ * @param baseURL the base url
+ * @param ua the user agent context
+ * @return the fop image instance
*/
protected static FopImage loadImage(String href, String baseURL,
FOUserAgent ua) {
InputStream imgIS = openStream(href, baseURL, ua);
+ if (imgIS == null) {
+ return null;
+ }
+
// If not, check image type
FopImage.ImageInfo imgInfo = null;
try {
}
}
+/**
+ * Basic image cache.
+ * This keeps track of invalid images.
+ */
class BasicImageCache implements ImageCache {
Set invalid = Collections.synchronizedSet(new HashSet());
Map contextStore = Collections.synchronizedMap(new HashMap());
package org.apache.fop.image;
-// Java
-import java.net.URL;
-import java.io.InputStream;
-import java.io.InputStream;
-
// AWT
import java.awt.image.ColorModel;
import java.awt.image.IndexColorModel;
inputStream.close();
inputStream = null;
- this.m_height = imageOp.getHeight();
- this.m_width = imageOp.getWidth();
+ this.height = imageOp.getHeight();
+ this.width = imageOp.getWidth();
ColorModel cm = imageOp.getColorModel();
- this.m_bitsPerPixel = 8;
- // this.m_bitsPerPixel = cm.getPixelSize();
- this.m_colorSpace = ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB);
+ this.bitsPerPixel = 8;
+ // this.bitsPerPixel = cm.getPixelSize();
+ this.colorSpace = ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB);
BufferedImage imageData = imageOp.getAsBufferedImage();
- int[] tmpMap = imageData.getRGB(0, 0, this.m_width,
- this.m_height, null, 0, this.m_width);
+ int[] tmpMap = imageData.getRGB(0, 0, this.width,
+ this.height, null, 0, this.width);
if (cm.hasAlpha()) {
int transparencyType = cm.getTransparency(); // java.awt.Transparency. BITMASK or OPAQUE or TRANSLUCENT
if (transparencyType == java.awt.Transparency.OPAQUE) {
- this.m_isTransparent = false;
+ this.isTransparent = false;
} else if (transparencyType ==
java.awt.Transparency.BITMASK) {
if (cm instanceof IndexColorModel) {
- this.m_isTransparent = false;
+ this.isTransparent = false;
byte[] alphas = new byte[
((IndexColorModel) cm).getMapSize()];
byte[] reds = new byte[
i < ((IndexColorModel) cm).getMapSize();
i++) {
if ((alphas[i] & 0xFF) == 0) {
- this.m_isTransparent = true;
- this.m_transparentColor = new PDFColor(
+ this.isTransparent = true;
+ this.transparentColor = new PDFColor(
(int)(reds[i] & 0xFF),
(int)(greens[i] & 0xFF),
(int)(blues[i] & 0xFF));
} else {
// TRANSLUCENT
/*
- * this.m_isTransparent = false;
- * for (int i = 0; i < this.m_width * this.m_height; i++) {
+ * this.isTransparent = false;
+ * for (int i = 0; i < this.width * this.height; i++) {
* if (cm.getAlpha(tmpMap[i]) == 0) {
- * this.m_isTransparent = true;
- * this.m_transparentColor = new PDFColor(cm.getRed(tmpMap[i]), cm.getGreen(tmpMap[i]), cm.getBlue(tmpMap[i]));
+ * this.isTransparent = true;
+ * this.transparentColor = new PDFColor(cm.getRed(tmpMap[i]), cm.getGreen(tmpMap[i]), cm.getBlue(tmpMap[i]));
* break;
* }
* }
* // or use special API...
*/
- this.m_isTransparent = false;
+ this.isTransparent = false;
}
} else {
- this.m_isTransparent = false;
+ this.isTransparent = false;
}
} else {
- this.m_isTransparent = false;
+ this.isTransparent = false;
}
// Should take care of the ColorSpace and bitsPerPixel
- this.m_bitmapsSize = this.m_width * this.m_height * 3;
- this.m_bitmaps = new byte[this.m_bitmapsSize];
- for (int i = 0; i < this.m_height; i++) {
- for (int j = 0; j < this.m_width; j++) {
- int p = tmpMap[i * this.m_width + j];
+ this.bitmapsSize = this.width * this.height * 3;
+ this.bitmaps = new byte[this.bitmapsSize];
+ for (int i = 0; i < this.height; i++) {
+ for (int j = 0; j < this.width; j++) {
+ int p = tmpMap[i * this.width + j];
int r = (p >> 16) & 0xFF;
int g = (p >> 8) & 0xFF;
int b = (p) & 0xFF;
- this.m_bitmaps[3 * (i * this.m_width + j)] =
+ this.bitmaps[3 * (i * this.width + j)] =
(byte)(r & 0xFF);
- this.m_bitmaps[3 * (i * this.m_width + j) + 1] =
+ this.bitmaps[3 * (i * this.width + j) + 1] =
(byte)(g & 0xFF);
- this.m_bitmaps[3 * (i * this.m_width + j) + 2] =
+ this.bitmaps[3 * (i * this.width + j) + 2] =
(byte)(b & 0xFF);
}
}
}
protected boolean loadDimensions(FOUserAgent ua) {
- if(this.m_bitmaps == null) {
+ if(this.bitmaps == null) {
loadImage(ua.getLogger());
}
- return this.m_bitmaps != null;
+ return this.bitmaps != null;
}
protected boolean loadBitmap(FOUserAgent ua) {
- if(this.m_bitmaps == null) {
+ if(this.bitmaps == null) {
loadImage(ua.getLogger());
}
- return this.m_bitmaps != null;
+ return this.bitmaps != null;
}
protected void loadImage(Logger log) {
while (!consumer.isImageReady()) {
Thread.sleep(500);
}
- this.m_height = consumer.getHeight();
- this.m_width = consumer.getWidth();
+ this.height = consumer.getHeight();
+ this.width = consumer.getWidth();
inputStream.close();
inputStream = null;
}
ColorModel cm = consumer.getColorModel();
- this.m_bitsPerPixel = 8;
- // this.m_bitsPerPixel = cm.getPixelSize();
- this.m_colorSpace = ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB);
+ this.bitsPerPixel = 8;
+ // this.bitsPerPixel = cm.getPixelSize();
+ this.colorSpace = ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB);
if (cm.hasAlpha()) {
// java.awt.Transparency. BITMASK or OPAQUE or TRANSLUCENT
int transparencyType = cm.getTransparency();
if (transparencyType == java.awt.Transparency.OPAQUE) {
- this.m_isTransparent = false;
+ this.isTransparent = false;
} else if (transparencyType ==
java.awt.Transparency.BITMASK) {
if (cm instanceof IndexColorModel) {
- this.m_isTransparent = false;
+ this.isTransparent = false;
byte[] alphas = new byte[
((IndexColorModel) cm).getMapSize()];
byte[] reds = new byte[
i < ((IndexColorModel) cm).getMapSize();
i++) {
if ((alphas[i] & 0xFF) == 0) {
- this.m_isTransparent = true;
- this.m_transparentColor = new PDFColor(
+ this.isTransparent = true;
+ this.transparentColor = new PDFColor(
(int)(reds[i] & 0xFF),
(int)(greens[i] & 0xFF),
(int)(blues[i] & 0xFF));
} else {
// TRANSLUCENT
/*
- * this.m_isTransparent = false;
- * for (int i = 0; i < this.m_width * this.m_height; i++) {
+ * this.isTransparent = false;
+ * for (int i = 0; i < this.width * this.height; i++) {
* if (cm.getAlpha(tmpMap[i]) == 0) {
- * this.m_isTransparent = true;
- * this.m_transparentColor = new PDFColor(cm.getRed(tmpMap[i]), cm.getGreen(tmpMap[i]), cm.getBlue(tmpMap[i]));
+ * this.isTransparent = true;
+ * this.transparentColor = new PDFColor(cm.getRed(tmpMap[i]), cm.getGreen(tmpMap[i]), cm.getBlue(tmpMap[i]));
* break;
* }
* }
*/
// use special API...
- this.m_isTransparent = false;
+ this.isTransparent = false;
}
} else {
- this.m_isTransparent = false;
+ this.isTransparent = false;
}
} else {
- this.m_isTransparent = false;
+ this.isTransparent = false;
}
} catch (Throwable ex) {
log.error("Error while loading image "
// Should take care of the ColorSpace and bitsPerPixel
- this.m_bitmapsSize = this.m_width * this.m_height * 3;
- this.m_bitmaps = new byte[this.m_bitmapsSize];
- for (int i = 0; i < this.m_height; i++) {
- for (int j = 0; j < this.m_width; j++) {
- int p = tmpMap[i * this.m_width + j];
+ this.bitmapsSize = this.width * this.height * 3;
+ this.bitmaps = new byte[this.bitmapsSize];
+ for (int i = 0; i < this.height; i++) {
+ for (int j = 0; j < this.width; j++) {
+ int p = tmpMap[i * this.width + j];
int r = (p >> 16) & 0xFF;
int g = (p >> 8) & 0xFF;
int b = (p) & 0xFF;
- this.m_bitmaps[3 * (i * this.m_width + j)] =
+ this.bitmaps[3 * (i * this.width + j)] =
(byte)(r & 0xFF);
- this.m_bitmaps[3 * (i * this.m_width + j) + 1] =
+ this.bitmaps[3 * (i * this.width + j) + 1] =
(byte)(g & 0xFF);
- this.m_bitmaps[3 * (i * this.m_width + j) + 2] =
+ this.bitmaps[3 * (i * this.width + j) + 2] =
(byte)(b & 0xFF);
}
}
/*
* $Id$
- * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
+ * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/
package org.apache.fop.image;
// Java
-import java.net.URL;
-import java.awt.image.ImageProducer;
-import java.awt.image.ColorModel;
-import java.awt.image.IndexColorModel;
import java.io.ByteArrayOutputStream;
-import java.io.InputStream;
import java.awt.color.ColorSpace;
import java.awt.color.ICC_Profile;
-import java.awt.color.ICC_ColorSpace;
// FOP
-import org.apache.fop.image.analyser.ImageReader;
import org.apache.fop.fo.FOUserAgent;
/**
*/
public class JpegImage extends AbstractFopImage {
private ICC_Profile iccProfile = null;
- private boolean found_icc_profile = false;
- private boolean found_dimensions = false;
+ private boolean foundICCProfile = false;
+ private boolean foundDimensions = false;
/**
* Create a jpeg image with the info.
protected boolean loadOriginalData(FOUserAgent ua) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ByteArrayOutputStream iccStream = new ByteArrayOutputStream();
- InputStream inStream;
- byte[] readBuf = new byte[4096];
- int bytes_read;
int index = 0;
boolean cont = true;
try {
- inStream = inputStream;
-
- while ((bytes_read = inStream.read(readBuf)) != -1) {
- baos.write(readBuf, 0, bytes_read);
+ byte[] readBuf = new byte[4096];
+ int bytesRead;
+ while ((bytesRead = inputStream.read(readBuf)) != -1) {
+ baos.write(readBuf, 0, bytesRead);
}
inputStream.close();
inputStream = null;
} catch (java.io.IOException ex) {
- ua.getLogger().error("Error while loading image " +
- "" + " : " + ex.getClass() +
- " - " + ex.getMessage(), ex);
+ ua.getLogger().error("Error while loading image "
+ + " : " + ex.getClass()
+ + " - " + ex.getMessage(), ex);
return false;
}
- this.m_bitmaps = baos.toByteArray();
- this.m_bitsPerPixel = 8;
- this.m_isTransparent = false;
+ this.bitmaps = baos.toByteArray();
+ this.bitsPerPixel = 8;
+ this.isTransparent = false;
- if (this.m_bitmaps.length > (index + 2) &&
- uByte(this.m_bitmaps[index]) == 255 &&
- uByte(this.m_bitmaps[index + 1]) == 216) {
+ if (this.bitmaps.length > (index + 2)
+ && uByte(this.bitmaps[index]) == 255
+ && uByte(this.bitmaps[index + 1]) == 216) {
index += 2;
- while (index < this.m_bitmaps.length && cont) {
+ while (index < this.bitmaps.length && cont) {
//check to be sure this is the begining of a header
- if (this.m_bitmaps.length > (index + 2) &&
- uByte(this.m_bitmaps[index]) == 255) {
+ if (this.bitmaps.length > (index + 2)
+ && uByte(this.bitmaps[index]) == 255) {
- //192 or 194 are the header bytes that contain the jpeg width height and color depth.
- if (uByte(this.m_bitmaps[index + 1]) == 192 ||
- uByte(this.m_bitmaps[index + 1]) == 194) {
+ //192 or 194 are the header bytes that contain
+ // the jpeg width height and color depth.
+ if (uByte(this.bitmaps[index + 1]) == 192
+ || uByte(this.bitmaps[index + 1]) == 194) {
- this.m_height = calcBytes(this.m_bitmaps[index + 5],
- this.m_bitmaps[index + 6]);
- this.m_width = calcBytes(this.m_bitmaps[index + 7],
- this.m_bitmaps[index + 8]);
+ this.height = calcBytes(this.bitmaps[index + 5],
+ this.bitmaps[index + 6]);
+ this.width = calcBytes(this.bitmaps[index + 7],
+ this.bitmaps[index + 8]);
- if (this.m_bitmaps[index + 9] == 1) {
- this.m_colorSpace = ColorSpace.getInstance(
+ if (this.bitmaps[index + 9] == 1) {
+ this.colorSpace = ColorSpace.getInstance(
ColorSpace.CS_GRAY);
- } else if (this.m_bitmaps[index + 9] == 3) {
- this.m_colorSpace = ColorSpace.getInstance(
+ } else if (this.bitmaps[index + 9] == 3) {
+ this.colorSpace = ColorSpace.getInstance(
ColorSpace.CS_LINEAR_RGB);
- } else if (this.m_bitmaps[index + 9] == 4) {
+ } else if (this.bitmaps[index + 9] == 4) {
// howto create CMYK color space
- this.m_colorSpace = ColorSpace.getInstance(
+ this.colorSpace = ColorSpace.getInstance(
ColorSpace.CS_CIEXYZ);
} else {
ua.getLogger().error("Unknown ColorSpace for image: "
return false;
}
- found_dimensions = true;
- if (found_icc_profile) {
+ foundDimensions = true;
+ if (foundICCProfile) {
cont = false;
break;
}
- index += calcBytes(this.m_bitmaps[index + 2],
- this.m_bitmaps[index + 3]) + 2;
+ index += calcBytes(this.bitmaps[index + 2],
+ this.bitmaps[index + 3]) + 2;
- } else if (uByte(this.m_bitmaps[index + 1]) ==
- 226 && this.m_bitmaps.length > (index + 60)) {
+ } else if (uByte(this.bitmaps[index + 1]) == 226
+ && this.bitmaps.length > (index + 60)) {
// Check if ICC profile
- byte[] icc_string = new byte[11];
- System.arraycopy(this.m_bitmaps, index + 4,
- icc_string, 0, 11);
+ byte[] iccString = new byte[11];
+ System.arraycopy(this.bitmaps, index + 4,
+ iccString, 0, 11);
- if ("ICC_PROFILE".equals(new String(icc_string))) {
+ if ("ICC_PROFILE".equals(new String(iccString))) {
int chunkSize = calcBytes(
- this.m_bitmaps[index + 2],
- this.m_bitmaps[index + 3]) + 2;
+ this.bitmaps[index + 2],
+ this.bitmaps[index + 3]) + 2;
- iccStream.write(this.m_bitmaps,
+ iccStream.write(this.bitmaps,
index + 18, chunkSize - 18);
}
- index += calcBytes(this.m_bitmaps[index + 2],
- this.m_bitmaps[index + 3]) + 2;
+ index += calcBytes(this.bitmaps[index + 2],
+ this.bitmaps[index + 3]) + 2;
} else {
- index += calcBytes(this.m_bitmaps[index + 2],
- this.m_bitmaps[index + 3]) + 2;
+ index += calcBytes(this.bitmaps[index + 2],
+ this.bitmaps[index + 3]) + 2;
}
} else {
ua.getLogger().error("Invalid ICC profile: " + e, e);
return false;
}
- } else if(this.m_colorSpace == null) {
+ } else if (this.colorSpace == null) {
ua.getLogger().error("ColorSpace not specified for JPEG image");
return false;
}
fis.mark(length + 1);
SAXSVGDocumentFactory factory = new SAXSVGDocumentFactory(
XMLImage.getParserName());
- SVGDocument doc = (SVGDocument) factory.createDocument(uri, fis);
+ SVGDocument doc = (SVGDocument) factory.createSVGDocument(uri, fis);
info.data = doc;
Element e = doc.getRootElement();