diff --git a/src/helma/image/imageio/gif/GIFImageWriteParam.java b/src/helma/image/imageio/gif/GIFImageWriteParam.java new file mode 100644 index 00000000..0ed54b1d --- /dev/null +++ b/src/helma/image/imageio/gif/GIFImageWriteParam.java @@ -0,0 +1,40 @@ +/* + * Helma License Notice + * + * The contents of this file are subject to the Helma License + * Version 2.0 (the "License"). You may not use this file except in + * compliance with the License. A copy of the License is available at + * http://adele.helma.org/download/helma/license.txt + * + * Copyright 1998-2003 Helma Software. All Rights Reserved. + * + * $RCSfile$ + * $Author$ + * $Revision$ + * $Date$ + */ + +/* + * The imageio integration is inspired by the package org.freehep.graphicsio.gif + */ + +package helma.image.imageio.gif; + +import java.util.*; +import javax.imageio.*; + +public class GIFImageWriteParam extends ImageWriteParam { + + private boolean quantizeColors; + private String quantizeMode; + + public GIFImageWriteParam(Locale locale) { + super(locale); + canWriteProgressive = true; + progressiveMode = MODE_DEFAULT; + } + + public ImageWriteParam getWriteParam(Properties properties) { + return this; + } +} \ No newline at end of file diff --git a/src/helma/image/imageio/gif/GIFImageWriter.java b/src/helma/image/imageio/gif/GIFImageWriter.java new file mode 100644 index 00000000..94a99c2c --- /dev/null +++ b/src/helma/image/imageio/gif/GIFImageWriter.java @@ -0,0 +1,84 @@ +/* + * Helma License Notice + * + * The contents of this file are subject to the Helma License + * Version 2.0 (the "License"). You may not use this file except in + * compliance with the License. A copy of the License is available at + * http://adele.helma.org/download/helma/license.txt + * + * Copyright 1998-2003 Helma Software. All Rights Reserved. + * + * $RCSfile$ + * $Author$ + * $Revision$ + * $Date$ + */ + +/* + * The imageio integration is inspired by the package org.freehep.graphicsio.gif + */ + +package helma.image.imageio.gif; + +import java.awt.image.*; +import java.io.*; +import javax.imageio.*; +import javax.imageio.metadata.*; + +import helma.image.*; + +public class GIFImageWriter extends ImageWriter { + GIFEncoder encoder; + + public GIFImageWriter(GIFImageWriterSpi originatingProvider) { + super(originatingProvider); + encoder = new GIFEncoder(); + } + + public void write(IIOMetadata streamMetadata, IIOImage image, + ImageWriteParam param) throws IOException { + if (image == null) + throw new IllegalArgumentException("image == null"); + + if (image.hasRaster()) + throw new UnsupportedOperationException("Cannot write rasters"); + + Object output = getOutput(); + if (output == null) + throw new IllegalStateException("output was not set"); + + if (param == null) + param = getDefaultWriteParam(); + + RenderedImage ri = image.getRenderedImage(); + if (!(ri instanceof BufferedImage)) + throw new IOException("RenderedImage is not a BufferedImage"); + if (!(output instanceof DataOutput)) + throw new IOException("output is not a DataOutput"); + encoder.encode((BufferedImage) ri, (DataOutput) output, + param.getProgressiveMode() != ImageWriteParam.MODE_DISABLED, null); + } + + public IIOMetadata convertStreamMetadata(IIOMetadata inData, + ImageWriteParam param) { + return null; + } + + public IIOMetadata convertImageMetadata(IIOMetadata inData, + ImageTypeSpecifier imageType, ImageWriteParam param) { + return null; + } + + public IIOMetadata getDefaultImageMetadata(ImageTypeSpecifier imageType, + ImageWriteParam param) { + return null; + } + + public IIOMetadata getDefaultStreamMetadata(ImageWriteParam param) { + return null; + } + + public ImageWriteParam getDefaultWriteParam() { + return new GIFImageWriteParam(getLocale()); + } +} \ No newline at end of file diff --git a/src/helma/image/imageio/gif/GIFImageWriterSpi.java b/src/helma/image/imageio/gif/GIFImageWriterSpi.java new file mode 100644 index 00000000..778b7ce7 --- /dev/null +++ b/src/helma/image/imageio/gif/GIFImageWriterSpi.java @@ -0,0 +1,58 @@ +/* + * Helma License Notice + * + * The contents of this file are subject to the Helma License + * Version 2.0 (the "License"). You may not use this file except in + * compliance with the License. A copy of the License is available at + * http://adele.helma.org/download/helma/license.txt + * + * Copyright 1998-2003 Helma Software. All Rights Reserved. + * + * $RCSfile$ + * $Author$ + * $Revision$ + * $Date$ + */ + +/* + * The imageio integration is inspired by the package org.freehep.graphicsio.gif + */ + +package helma.image.imageio.gif; + +import java.io.*; +import java.util.*; +import javax.imageio.*; +import javax.imageio.spi.*; + +public class GIFImageWriterSpi extends ImageWriterSpi { + + public GIFImageWriterSpi() { + super( + "Helma Object Publisher, http://helma.org/", + "1.0", + new String[] {"gif", "GIF"}, + new String[] {"gif", "GIF"}, + new String[] {"image/gif", "image/x-gif"}, + "helma.image.imageio.gif.GIFImageWriter", + STANDARD_OUTPUT_TYPE, + null, + false, null, null, null, null, + false, null, null, null, null + ); + } + + public String getDescription(Locale locale) { + return "Graphics Interchange Format"; + } + + public ImageWriter createWriterInstance(Object extension) + throws IOException { + return new GIFImageWriter(this); + } + + public boolean canEncodeImage(ImageTypeSpecifier type) { + // FIXME handle # colors + return true; + } +} \ No newline at end of file