[Helma-dev] New Imaging code, based on imageio

Jürg Lehni juerg at vectorama.org
Wed Nov 12 19:10:40 CET 2003


This is the current state of the new imaging code for helma.

It consists of two things:

- a new quantizier which should be faster and handles transparent 
images correctly (and hopefully doesn't throw exceptions). I ported 
this class from the c++ class found here: 
http://www.xdp.it/cquantizer.htm and added these extensions (from the 
source comments):
   - Conversion of the input image to a BufferedImage with a 
IndexColorModel
   - Dithering of images through the java2d's internal dithering 
algorithms,
     by setting the dither parameter to true.
   - Support for a transparent color, which is correctly rendered by
     GIFImageWriter. All pixels with alpha < 0x80 are converted to this
     color when the parameter alphaToBitmask is set to true.

- a new GIFImageWriter which is a modification of the acme writer. I 
optimized quite a few things here. As the quantizier now produces 
BufferedImages with IndexColorModel, all the palette optimization code 
can be skipped. This results in a much fuster code as it's not 
necessary any more to walk through all the pixels of the image and 
collect and count equal colors... These are the extensions here (from 
the source comments):
   - encode now directly works on BufferedImage objects, the ImageEncoder
     and ImageConsumer oriented frameworks has been removed.
   - Only BufferedImages with IndexColorModel are taken, so no more
     palette optimization with IntHashtable objects are necessary. If the
     BufferedImage is in wrong format, helma.image.Quantizier is used to
     convert it into a index based image.
   - This version is much less space consuming as it only takes one 
sample
     row of the rastered image at a time into memory during compression.
   - The overall time for color reduction and gif compression should
     therefore be greatly reduced

GIFImageWriter is right now an extension of javax.imageio.ImageWriter, 
so it only works on Java 1.4. But It wouldn't be too much work to 
convert it to a JAI codec or something similar.

Jimi and Acme are not used any longer, so the attached archive is all 
that is needed for the complete imaging functionality (this results in 
a much smaller helma download file). And as imageio is a flexible 
framework with plugins, new file formats can easily be added.

SaveAs in the SunImageWrapper now looks like this:

	public void saveAs(String filename) {
         try {
			int pos = filename.lastIndexOf('.');
			if (pos != -1) {
				String extension = filename.substring(pos + 1, 
filename.length()).toLowerCase();
				javax.imageio.ImageIO.write(getBufferedImage(), extension, new 
File(filename));
             }
         } catch (Exception x) {
             throw new RuntimeException(x.getMessage());
         }
     }

One more thing: the file 
META-INF/services/javax.imageio.spi.ImageWriterSpi in helma.jar is 
necerssary for the IIORegistry in order to register the added 
ImageWriters (right now only helma.image.imageio.gif.GIFImageWriterSpi)

I hope you like it

Jürg

-------------- next part --------------
A non-text attachment was scrubbed...
Name: imaging.0.1.tar.gz
Type: application/x-gzip
Size: 20103 bytes
Desc: not available
Url : http://grazia.helma.at/pipermail/helma-dev/attachments/20031112/84ba119c/imaging.0.1.tar-0001.gz


More information about the Helma-dev mailing list