You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-dev@xmlgraphics.apache.org by Eric SCHAEFFER <es...@posterconseil.com> on 2000/04/21 10:02:04 UTC

Image support - Proposal

Hie,

After a discussion with Pankaj Narula, here is a proposal for image support.
Tell us what you think about it (specially for the viewer).
I can implement the factory (using a configuration file) and the abstract base
class. Pankaj will implement the changes in other classes (PDFXObject,
PDFDocument, etc...).
We can have wrappers for JAI (Java 2) and Jimi (Java 1, but licence pb and no
more support by SUN).

1 - FOPImage interface

Constants can also be strings, I don't know what is better.
For compression constants, the name can be changed to the corresponding PDF
filter name (ie PNG => DEFLAT, JPEG => ?).

Image data is loaded during the object construction. We currently need to do
this to know the real image size.
Image data is kept in the object, but compressed. I suggest to use Deflat
(ZLib) algo, because there's no loss of quality.
I think it would be better to use a configuration file to specify the algo.

public interface FOPImage {
  // contants
  public static int DEVICE_GRAY = 1;
  public static int DEVICE_RGB = 2;
  public static int DEVICE_CMYK = 3;
  public static int FILTER_JPEG = 4;
  public static int FILTER_PNG = 5;

  // init and load the image data
  // Exception if can't load image
  public FOPImage(URL href) throws FOPImageException;

  // get image general properties
  public int getWidth();
  public int getHeight();
  public String getURL();

  // get the image bytes, and bytes properties
  public byte[] getImageBytes();
  public int getImageSize();
  public int getBitsPerPixel();
  public int getColorSpace(); // DeviceGray, DeviceRGB, or DeviceCMYK
  public boolean isCompressed(); // are returned bytes compressed
  public int getCompressionFilter(); // what compression algo is used (JPEG,
PNG, ...)

  // release memory
  public void close();
}

2 - base abstract image class (AbstractFOPImage) :

All implementing classes should extend this one. The extending class just have
to implement a private method that load the image data. All other methods
(FOPImage interface) can already be implemented.

public abstract AbstractFOPImage implements FOPImage {
    ...
  // subclasses should implement this method, that return the image data
(uncompressed)
  private byte[] decodeURL() throws FOPImageException;
    ...
  }
}

3 - A utility class to handle compression algo

compress, uncompress, from one compression type to another one, etc...

4 - An image factory (FOPImageFactory)

This factory return an FOPImage object, according to the image mime-type (or
extension) and to a configuration file.
The AbstractFOPImage subclasses implement the decodeURL method using the algo
they want: JAI, Jimi, etc...
The configuration file associates mime-types to one of these subclasses.


Eric.