summaryrefslogtreecommitdiff
path: root/libjava/classpath/gnu/java/awt/image
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/classpath/gnu/java/awt/image')
-rw-r--r--libjava/classpath/gnu/java/awt/image/AsyncImage.java300
-rw-r--r--libjava/classpath/gnu/java/awt/image/ImageConverter.java528
-rw-r--r--libjava/classpath/gnu/java/awt/image/ImageDecoder.java188
-rw-r--r--libjava/classpath/gnu/java/awt/image/XBMDecoder.java155
-rw-r--r--libjava/classpath/gnu/java/awt/image/package.html46
5 files changed, 1217 insertions, 0 deletions
diff --git a/libjava/classpath/gnu/java/awt/image/AsyncImage.java b/libjava/classpath/gnu/java/awt/image/AsyncImage.java
new file mode 100644
index 000000000..4fa33740e
--- /dev/null
+++ b/libjava/classpath/gnu/java/awt/image/AsyncImage.java
@@ -0,0 +1,300 @@
+/* AsyncImage.java -- Loads images asynchronously
+ Copyright (C) 2008 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.awt.image;
+
+
+import java.awt.Graphics;
+import java.awt.Image;
+import java.awt.image.ImageConsumer;
+import java.awt.image.ImageObserver;
+import java.awt.image.ImageProducer;
+import java.util.HashSet;
+import java.util.Iterator;
+
+/**
+ * Supports asynchronous loading of images.
+ */
+public class AsyncImage
+ extends Image
+{
+
+ /**
+ * The image source for AsyncImages.
+ */
+ private class AsyncImageSource
+ implements ImageProducer
+ {
+ /**
+ * The real image source, if already present, or <code>null</code>
+ * otherwise.
+ */
+ private ImageProducer realSource;
+
+ public void addConsumer(ImageConsumer ic)
+ {
+ startProduction(ic);
+ }
+
+ public boolean isConsumer(ImageConsumer ic)
+ {
+ return false;
+ }
+
+ public void removeConsumer(ImageConsumer ic)
+ {
+ // Nothing to do here.
+ }
+
+ public void requestTopDownLeftRightResend(ImageConsumer ic)
+ {
+ startProduction(ic);
+ }
+
+ public void startProduction(ImageConsumer ic)
+ {
+ ImageProducer ip = getRealSource();
+ if (ip == null)
+ {
+ ic.setDimensions(1, 1);
+ ic.imageComplete(ImageConsumer.SINGLEFRAMEDONE);
+ }
+ else
+ {
+ ip.startProduction(ic);
+ }
+ }
+
+ /**
+ * Returns the real image source, if already present. Otherwise, this
+ * returns <code>null</code>.
+ *
+ * @return the real image source, or <code>null</code> if not present
+ */
+ private ImageProducer getRealSource()
+ {
+ synchronized (AsyncImage.this)
+ {
+ ImageProducer source = realSource;
+ if (source == null)
+ {
+ Image ri = realImage;
+ if (ri != null)
+ {
+ realSource = source = ri.getSource();
+ }
+ }
+ return source;
+ }
+ }
+ }
+
+ /**
+ * The real image. This is null as long as the image is not complete.
+ */
+ private volatile Image realImage;
+
+ /**
+ * The image observers.
+ *
+ * This is package private to avoid accessor methods.
+ */
+ HashSet<ImageObserver> observers;
+
+ private volatile boolean complete = false;
+
+ /**
+ * Creates a new AsyncImage.
+ */
+ AsyncImage()
+ {
+ observers = new HashSet<ImageObserver>();
+ }
+
+ public void flush()
+ {
+ // Nothing to do here.
+ }
+
+ public Graphics getGraphics()
+ {
+ Image r = realImage;
+ Graphics g = null;
+ if (r != null)
+ g = r.getGraphics(); // Should we return some dummy graphics instead?
+ return g;
+ }
+
+ public boolean isComplete() {
+ return complete;
+ }
+
+ public int getHeight(ImageObserver observer)
+ {
+ addObserver(observer);
+ int height = -1;
+ waitForImage(observer);
+ Image r = realImage;
+ if (r != null)
+ height = r.getHeight(observer);
+ return height;
+ }
+
+ public Object getProperty(String name, ImageObserver observer)
+ {
+ addObserver(observer);
+ Image r = realImage;
+ Object prop = null;
+ if (r != null)
+ prop = r.getProperty(name, observer);
+ return prop;
+ }
+
+ public ImageProducer getSource()
+ {
+ return new AsyncImageSource();
+ }
+
+ public int getWidth(ImageObserver observer)
+ {
+ addObserver(observer);
+ int width = -1;
+ waitForImage(observer);
+ Image r = realImage;
+ if (r != null)
+ width = r.getWidth(observer);
+ return width;
+ }
+
+ public void addObserver(ImageObserver obs)
+ {
+ if (obs != null)
+ {
+ synchronized (this)
+ {
+ // This field gets null when image loading is complete and we don't
+ // need to store any more observers.
+ HashSet<ImageObserver> observs = observers;
+ if (observs != null)
+ {
+ observs.add(obs);
+ }
+ }
+ }
+ }
+
+ public boolean prepareImage(int w, int h, ImageObserver obs)
+ {
+ addObserver(obs);
+ return realImage != null;
+ }
+
+ public int checkImage(int w, int h, ImageObserver obs)
+ {
+ addObserver(obs);
+ int flags = 0;
+ if (realImage != null)
+ flags = ImageObserver.ALLBITS | ImageObserver.WIDTH
+ | ImageObserver.HEIGHT | ImageObserver.PROPERTIES;
+ return flags;
+ }
+
+ public Image getRealImage()
+ {
+ return realImage;
+ }
+
+ public void setRealImage(Image im)
+ {
+ realImage = im;
+ int status = ImageObserver.HEIGHT | ImageObserver.WIDTH;
+ notifyObservers(status, 0, 0, im.getWidth(null), im.getHeight(null));
+ }
+
+ public void notifyObservers(int status, int x, int y, int w, int h)
+ {
+ synchronized (this)
+ {
+ HashSet observs = observers;
+ if (observs != null)
+ {
+ Iterator i = observs.iterator();
+ while (i.hasNext())
+ {
+ ImageObserver obs = (ImageObserver) i.next();
+ boolean complete = obs.imageUpdate(this, status, x, y, realImage.getWidth(obs), realImage.getHeight(obs));
+ if (complete) // Remove completed observers.
+ i.remove();
+ }
+ }
+ if ((status & ImageObserver.ALLBITS) != 0)
+ {
+ complete = true;
+ notifyAll();
+ }
+ }
+ }
+
+ /**
+ * Waits for the image to be loaded completely, if the image observer
+ * is <code>null</code>. Otherwise this is not necessary, because the
+ * image observer can be notified about later completion.
+ *
+ * @param observer the image observer
+ */
+ public void waitForImage(ImageObserver observer)
+ {
+ if (!complete && observer == null)
+ {
+ synchronized (this)
+ {
+ while (! complete)
+ {
+ try
+ {
+ wait();
+ }
+ catch (InterruptedException ex)
+ {
+ Thread.currentThread().interrupt();
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/libjava/classpath/gnu/java/awt/image/ImageConverter.java b/libjava/classpath/gnu/java/awt/image/ImageConverter.java
new file mode 100644
index 000000000..f9c6268c3
--- /dev/null
+++ b/libjava/classpath/gnu/java/awt/image/ImageConverter.java
@@ -0,0 +1,528 @@
+/* ImageConverter.java -- Loads images asynchronously
+ Copyright (C) 2008 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.awt.image;
+
+import gnu.java.awt.image.AsyncImage;
+
+import java.awt.GraphicsEnvironment;
+import java.awt.Image;
+import java.awt.Transparency;
+import java.awt.image.BufferedImage;
+import java.awt.image.ColorModel;
+import java.awt.image.DataBuffer;
+import java.awt.image.ImageConsumer;
+import java.awt.image.IndexColorModel;
+import java.awt.image.ImageObserver;
+import java.awt.image.SinglePixelPackedSampleModel;
+import java.awt.image.WritableRaster;
+import java.util.Hashtable;
+
+/**
+ * Convert an Image to a BufferedImage.
+ *
+ * @author Roman Kennke (kennke@aicas.com)
+ */
+public class ImageConverter implements ImageConsumer
+{
+
+ public static final String IMAGE_TRANSPARENCY_PROPERTY =
+ "gnu.awt.image.transparency";
+
+ public static final String IMAGE_PROPERTIES_PROPERTY =
+ "gnu.awt.image.properties";
+
+ private AsyncImage image;
+ private BufferedImage bImage;
+ private Hashtable imageProperties;
+ private int width, height;
+ private ColorModel colorModel;
+ private ColorModel targetColorModel;
+
+ public ImageConverter()
+ {
+ width = 0;
+ height = 0;
+ image = new AsyncImage();
+ }
+
+ public void setDimensions(int w, int h)
+ {
+ width = w;
+ height = h;
+ }
+
+ public void setProperties(Hashtable props)
+ {
+ // Ignore for now.
+ }
+
+ public void setColorModel(ColorModel model)
+ {
+ colorModel = model;
+ }
+
+ public void setHints(int flags)
+ {
+ // Ignore for now.
+ }
+
+ public void setPixels(int x, int y, int w, int h, ColorModel model,
+ byte[] pixels, int offset, int scansize)
+ {
+ model = setupColorModel(model);
+
+ if (bImage == null)
+ {
+ createImage();
+ }
+
+ Integer t = (Integer) imageProperties.get("gnu.awt.image.transparency");
+ int transparency = t.intValue();
+
+ if(targetColorModel.equals(model))
+ {
+ transparency = transferPixels(x, y, w, h, model, pixels, offset,
+ scansize, transparency);
+ }
+ else if (model instanceof IndexColorModel
+ && targetColorModel.equals(ColorModel.getRGBdefault()))
+ {
+ transparency = convertIndexColorModelToSRGB(x, y, w, h,
+ (IndexColorModel) model,
+ pixels, offset, scansize,
+ transparency);
+ }
+ else
+ {
+ transparency = convertPixels(x, y, w, h, model, pixels, offset,
+ scansize, transparency);
+ }
+
+ imageProperties.put("gnu.awt.image.transparency",
+ Integer.valueOf(transparency));
+ }
+
+ public void setPixels(int x, int y, int w, int h, ColorModel model,
+ int[] pixels, int offset, int scansize)
+ {
+ model = setupColorModel(model);
+ if (bImage == null)
+ {
+ createImage();
+ }
+
+ Integer t = (Integer) imageProperties.get(IMAGE_TRANSPARENCY_PROPERTY);
+ int transparency= t.intValue();
+
+ if (targetColorModel.equals(model))
+ {
+ transparency = transferPixels(x, y, w, h, model, pixels, offset,
+ scansize, transparency);
+ }
+ else if (model instanceof IndexColorModel
+ && targetColorModel.equals(ColorModel.getRGBdefault()))
+ {
+ transparency = convertIndexColorModelToSRGB(x, y, w, h,
+ (IndexColorModel) model,
+ pixels, offset, scansize,
+ transparency);
+ }
+ else
+ {
+ transparency = convertPixels(x, y, w, h, model, pixels, offset,
+ scansize, transparency);
+ }
+
+ imageProperties.put(IMAGE_TRANSPARENCY_PROPERTY,
+ Integer.valueOf(transparency));
+
+ }
+
+ /**
+ * Initialize the color model for this setPixels run: <br/>
+ * 1. if no color model was given use the hinted color model <br/>
+ * 2. if no color model was given and non was hinted use the default sRGB color model. <br/>
+ * Also:<br/>
+ * If no target color model was set use the color model of the given pixels.
+ * @param model
+ * @return
+ */
+ private ColorModel setupColorModel(ColorModel model)
+ {
+ // If the given color model is null use the previously hinted color model.
+ if (model == null)
+ model = colorModel;
+
+ // If no color model was given or hinted use default sRGB.
+ if (model == null)
+ model = ColorModel.getRGBdefault();
+
+ // If no specific color model was requested for the target use the current
+ // pixels model.
+ if (targetColorModel == null)
+ targetColorModel = model;
+ targetColorModel = ColorModel.getRGBdefault();
+ return model;
+ }
+
+ /**
+ * Creates the image instance into which the pixel data is converted.
+ */
+ private void createImage()
+ {
+ if (imageProperties == null)
+ {
+ imageProperties = new Hashtable();
+ }
+
+ imageProperties.put(IMAGE_TRANSPARENCY_PROPERTY,
+ Integer.valueOf(Transparency.OPAQUE));
+ imageProperties.put(IMAGE_PROPERTIES_PROPERTY, imageProperties);
+
+ // For the sRGB case let the GraphicsEnvironment create an image for us.
+ if (ColorModel.getRGBdefault().equals(targetColorModel))
+ {
+ bImage = GraphicsEnvironment.getLocalGraphicsEnvironment()
+ .getDefaultScreenDevice()
+ .getDefaultConfiguration()
+ .createCompatibleImage(width, height, Transparency.TRANSLUCENT);
+ }
+ else
+ {
+ WritableRaster raster =
+ targetColorModel.createCompatibleWritableRaster(width, height);
+ bImage = new BufferedImage(targetColorModel, raster, false,
+ imageProperties);
+ }
+ image.setRealImage(bImage);
+ return;
+ }
+
+ /**
+ * Transfers pixels into a raster of the same color model.
+ *
+ * @param x the X coordinate of the source pixel rectangle
+ * @param y the Y coordinate of the source pixel rectangle
+ * @param w the width of the source pixel rectangle
+ * @param h the height of the source pixel rectangle
+ * @param model the color model of the source pixels
+ * @param pixels the pixel data
+ * @param offset the offset in the pixel array
+ * @param scansize the scanline size
+ * @param transparency the assumed transparency
+ *
+ * @return the determined transparency
+ */
+ private int transferPixels(int x, int y, int w, int h, ColorModel model,
+ byte[] pixels, int offset, int scansize,
+ int transparency)
+ {
+ // If we have the same color model, then we can simply drop
+ // the pixel value into the target raster.
+ bImage.getRaster().setDataElements(x, y, w, h, pixels);
+
+ for (int yy = 0; yy < h; yy++)
+ {
+ for (int xx = 0; xx < w; xx++)
+ {
+ int pixel = 0xFF & pixels[yy * scansize + xx + offset];
+ int alpha = model.getAlpha(pixel);
+ transparency = updateTransparency(alpha, transparency);
+ }
+ }
+ return transparency;
+ }
+
+ /**
+ * Transfers pixels into a raster of the same color model.
+ *
+ * @param x the X coordinate of the source pixel rectangle
+ * @param y the Y coordinate of the source pixel rectangle
+ * @param w the width of the source pixel rectangle
+ * @param h the height of the source pixel rectangle
+ * @param model the color model of the source pixels
+ * @param pixels the pixel data
+ * @param offset the offset in the pixel array
+ * @param scansize the scanline size
+ * @param transparency the assumed transparency
+ *
+ * @return the determined transparency
+ */
+ private int transferPixels(int x, int y, int w, int h, ColorModel model,
+ int[] pixels, int offset, int scansize,
+ int transparency)
+ {
+ // If we have the same color model, then we can simply drop
+ // the pixel value into the target raster.
+ bImage.getRaster().setDataElements(x, y, w, h, pixels);
+
+ for (int yy = 0; yy < h; yy++)
+ {
+ for (int xx = 0; xx < w; xx++)
+ {
+ int pixel = pixels[yy * scansize + xx + offset];
+ int alpha = model.getAlpha(pixel);
+ transparency = updateTransparency(alpha, transparency);
+ }
+ }
+ return transparency;
+ }
+
+ /**
+ * Converts pixel from one color model to another, and stores them in the
+ * target image.
+ *
+ * @param x the X coordinate of the source pixel rectangle
+ * @param y the Y coordinate of the source pixel rectangle
+ * @param w the width of the source pixel rectangle
+ * @param h the height of the source pixel rectangle
+ * @param model the color model of the source pixels
+ * @param pixels the pixel data
+ * @param offset the offset in the pixel array
+ * @param scansize the scanline size
+ * @param transparency the assumed transparency
+ *
+ * @return the determined transparency
+ */
+ private int convertPixels(int x, int y, int w, int h, ColorModel model,
+ byte[] pixels, int offset, int scansize,
+ int transparency)
+ {
+ // If the color models are not the same, we must convert the
+ // pixel values from one model to the other.
+ Object dataEl = null;
+ // Convert pixels to the destination color model.
+ for (int yy = 0; yy < h; yy++)
+ {
+ for (int xx = 0; xx < w; xx++)
+ {
+ int pixel = 0xFF & pixels[yy * scansize + xx + offset];
+ int rgb = model.getRGB(pixel);
+ int alpha = model.getAlpha(pixel);
+ transparency = updateTransparency(alpha, transparency);
+ dataEl = targetColorModel.getDataElements(rgb, dataEl);
+ bImage.getRaster().setDataElements(x + xx, y + yy, dataEl);
+ }
+ }
+ return transparency;
+ }
+
+ /**
+ * Converts pixel from one color model to another, and stores them in the
+ * target image.
+ *
+ * @param x the X coordinate of the source pixel rectangle
+ * @param y the Y coordinate of the source pixel rectangle
+ * @param w the width of the source pixel rectangle
+ * @param h the height of the source pixel rectangle
+ * @param model the color model of the source pixels
+ * @param pixels the pixel data
+ * @param offset the offset in the pixel array
+ * @param scansize the scanline size
+ * @param transparency the assumed transparency
+ *
+ * @return the determined transparency
+ */
+ private int convertPixels(int x, int y, int w, int h, ColorModel model,
+ int[] pixels, int offset, int scansize,
+ int transparency)
+ {
+ // If the color models are not the same, we must convert the
+ // pixel values from one model to the other.
+ Object dataEl = null;
+ // Convert pixels to the destination color model.
+ for (int yy = 0; yy < h; yy++)
+ {
+ for (int xx = 0; xx < w; xx++)
+ {
+ int pixel = pixels[yy * scansize + xx + offset];
+ int rgb = model.getRGB(pixel);
+ int alpha = model.getAlpha(pixel);
+ transparency = updateTransparency(alpha, transparency);
+ dataEl = targetColorModel.getDataElements(rgb, dataEl);
+ bImage.getRaster().setDataElements(x + xx, y + yy, dataEl);
+ }
+ }
+ return transparency;
+ }
+
+ /**
+ * Converts pixels from an index color model to the target image.
+ *
+ * @param x the X coordinate of the source pixel rectangle
+ * @param y the Y coordinate of the source pixel rectangle
+ * @param w the width of the source pixel rectangle
+ * @param h the height of the source pixel rectangle
+ * @param model the color model of the source pixels
+ * @param pixels the pixel data
+ * @param offset the offset in the pixel array
+ * @param scansize the scanline size
+ * @param transparency the assumed transparency
+ *
+ * @return the determined transparency
+ */
+ private int convertIndexColorModelToSRGB(int x, int y, int w, int h,
+ IndexColorModel model,
+ byte[] pixels, int offset,
+ int scansize, int transparency)
+ {
+
+ int mapSize = model.getMapSize();
+ int[] colorMap = new int[mapSize];
+ for(int i=0; i < mapSize; i++)
+ {
+ colorMap[i] = model.getRGB(i);
+ }
+
+ WritableRaster raster = bImage.getRaster();
+ SinglePixelPackedSampleModel sampleMode =
+ (SinglePixelPackedSampleModel) raster.getSampleModel();
+ DataBuffer dataBuffer = (DataBuffer) raster.getDataBuffer();
+
+ int rasterOffset = sampleMode.getOffset(x,y)+dataBuffer.getOffset();
+ int rasterScanline = sampleMode.getScanlineStride();
+
+ for (int yy = 0; yy < h; yy++)
+ {
+ int xoffset = offset;
+ for (int xx = 0; xx < w; xx++)
+ {
+ int argb = colorMap[(pixels[xoffset++] & 0xFF)];
+ dataBuffer.setElem(rasterOffset+xx, argb);
+ int alpha = (argb >>> 24);
+ transparency = updateTransparency(alpha, transparency);
+ }
+ offset += scansize;
+ rasterOffset += rasterScanline;
+ }
+
+ return transparency;
+ }
+
+ /**
+ * Converts pixels from an index color model to the target image.
+ *
+ * @param x the X coordinate of the source pixel rectangle
+ * @param y the Y coordinate of the source pixel rectangle
+ * @param w the width of the source pixel rectangle
+ * @param h the height of the source pixel rectangle
+ * @param model the color model of the source pixels
+ * @param pixels the pixel data
+ * @param offset the offset in the pixel array
+ * @param scansize the scanline size
+ * @param transparency the assumed transparency
+ *
+ * @return the determined transparency
+ */
+ private int convertIndexColorModelToSRGB(int x, int y, int w, int h,
+ IndexColorModel model, int[] pixels,
+ int offset, int scansize,
+ int transparency)
+ {
+ int mapSize = model.getMapSize();
+ int[] colorMap = new int[mapSize];
+ for(int i=0; i < mapSize; i++)
+ {
+ colorMap[i] = model.getRGB(i);
+ }
+
+ WritableRaster raster = bImage.getRaster();
+ SinglePixelPackedSampleModel sampleMode =
+ (SinglePixelPackedSampleModel) raster.getSampleModel();
+ DataBuffer dataBuffer = (DataBuffer)raster.getDataBuffer();
+
+ int rasterOffset = sampleMode.getOffset(x, y) + dataBuffer.getOffset();
+ int rasterScanline = sampleMode.getScanlineStride();
+
+ for (int yy = 0; yy < h; yy++)
+ {
+ int xoffset = offset;
+ for (int xx = 0; xx < w; xx++)
+ {
+ int argb = colorMap[pixels[xoffset++]];
+ dataBuffer.setElem(rasterOffset + xx, argb);
+ int alpha = (argb >>> 24);
+ transparency = updateTransparency(alpha, transparency);
+ }
+ offset += scansize;
+ rasterOffset += rasterScanline;
+ }
+
+ return transparency;
+ }
+
+ /**
+ * Updates the transparency information according to the alpha pixel value.
+ *
+ * @param alpha the alpha pixel value
+ * @param transparency the old transparency
+ *
+ * @return the updated transparency
+ */
+ private int updateTransparency(int alpha, int transparency)
+ {
+ if (alpha != 0xFF)
+ {
+ if (alpha == 0x00 && transparency <= Transparency.BITMASK)
+ {
+ transparency = Transparency.BITMASK;
+ }
+ else if (transparency < Transparency.TRANSLUCENT)
+ {
+ transparency = Transparency.TRANSLUCENT;
+ }
+ }
+ return transparency;
+ }
+
+ public void imageComplete(int status)
+ {
+ image.notifyObservers(ImageObserver.ALLBITS, 0, 0, width, height);
+ }
+
+ public void setTargetColorModel(ColorModel model)
+ {
+ targetColorModel = model;
+ }
+
+ public Image getImage()
+ {
+ return image;
+ }
+}
diff --git a/libjava/classpath/gnu/java/awt/image/ImageDecoder.java b/libjava/classpath/gnu/java/awt/image/ImageDecoder.java
new file mode 100644
index 000000000..a572ea33b
--- /dev/null
+++ b/libjava/classpath/gnu/java/awt/image/ImageDecoder.java
@@ -0,0 +1,188 @@
+/* ImageDecoder.java --
+ Copyright (C) 1999, 2000, 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.java.awt.image;
+
+import java.awt.image.ImageConsumer;
+import java.awt.image.ImageProducer;
+import java.io.ByteArrayInputStream;
+import java.io.DataInput;
+import java.io.EOFException;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Vector;
+
+public abstract class ImageDecoder implements ImageProducer
+{
+ Vector consumers = new Vector ();
+ String filename;
+ URL url;
+ byte[] data;
+ int offset;
+ int length;
+ InputStream input;
+ DataInput datainput;
+
+ static
+ {
+ // FIXME: there was some broken code here that looked like
+ // it wanted to rely on this property. I don't have any idea
+ // what it was intended to do.
+ // String endian = System.getProperties ().getProperty ("gnu.cpu.endian");
+ }
+
+ public ImageDecoder (String filename)
+ {
+ this.filename = filename;
+ }
+
+ public ImageDecoder (URL url)
+ {
+ this.url = url;
+ }
+
+ public ImageDecoder (InputStream is)
+ {
+ this.input = is;
+ }
+
+ public ImageDecoder (DataInput datainput)
+ {
+ this.datainput = datainput;
+ }
+
+ public ImageDecoder (byte[] imagedata, int imageoffset, int imagelength)
+ {
+ data = imagedata;
+ offset = imageoffset;
+ length = imagelength;
+ }
+
+ public void addConsumer (ImageConsumer ic)
+ {
+ consumers.addElement (ic);
+ }
+
+ public boolean isConsumer (ImageConsumer ic)
+ {
+ return consumers.contains (ic);
+ }
+
+ public void removeConsumer (ImageConsumer ic)
+ {
+ consumers.removeElement (ic);
+ }
+
+ public void startProduction (ImageConsumer ic)
+ {
+ if (!isConsumer(ic))
+ addConsumer(ic);
+
+ Vector list = (Vector) consumers.clone ();
+ try
+ {
+ // Create the input stream here rather than in the
+ // ImageDecoder constructors so that exceptions cause
+ // imageComplete to be called with an appropriate error
+ // status.
+ if (input == null)
+ {
+ try
+ {
+ if (url != null)
+ input = url.openStream();
+ else if (datainput != null)
+ input = new DataInputStreamWrapper(datainput);
+ else
+ {
+ if (filename != null)
+ input = new FileInputStream (filename);
+ else
+ input = new ByteArrayInputStream (data, offset, length);
+ }
+ produce (list, input);
+ }
+ finally
+ {
+ input = null;
+ }
+ }
+ else
+ {
+ produce (list, input);
+ }
+ }
+ catch (Exception e)
+ {
+ for (int i = 0; i < list.size (); i++)
+ {
+ ImageConsumer ic2 = (ImageConsumer) list.elementAt (i);
+ ic2.imageComplete (ImageConsumer.IMAGEERROR);
+ }
+ }
+ }
+
+ public void requestTopDownLeftRightResend (ImageConsumer ic)
+ {
+ }
+
+ public abstract void produce (Vector v, InputStream is) throws IOException;
+
+ private static class DataInputStreamWrapper extends InputStream
+ {
+ private final DataInput datainput;
+
+ DataInputStreamWrapper(DataInput datainput)
+ {
+ this.datainput = datainput;
+ }
+
+ public int read() throws IOException
+ {
+ try
+ {
+ return datainput.readByte() & 0xFF;
+ }
+ catch (EOFException eofe)
+ {
+ return -1;
+ }
+ }
+ }
+}
diff --git a/libjava/classpath/gnu/java/awt/image/XBMDecoder.java b/libjava/classpath/gnu/java/awt/image/XBMDecoder.java
new file mode 100644
index 000000000..35a3568b8
--- /dev/null
+++ b/libjava/classpath/gnu/java/awt/image/XBMDecoder.java
@@ -0,0 +1,155 @@
+/* XBMDecoder.java -- Decodes X-bitmaps
+ Copyright (C) 1999, 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.awt.image;
+
+import java.awt.image.ColorModel;
+import java.awt.image.ImageConsumer;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.net.URL;
+import java.util.StringTokenizer;
+import java.util.Vector;
+
+public class XBMDecoder extends ImageDecoder
+{
+ BufferedReader reader;
+ static final ColorModel cm = ColorModel.getRGBdefault ();
+ static final int black = 0xff000000;
+ static final int transparent = 0x00000000;
+ static final int masktable[] = { 0x01, 0x02, 0x04, 0x08,
+ 0x10, 0x20, 0x40, 0x80 };
+
+ public XBMDecoder (String filename)
+ {
+ super (filename);
+ }
+
+ public XBMDecoder (URL url)
+ {
+ super (url);
+ }
+
+ public void produce (Vector v, InputStream is) throws IOException
+ {
+ reader = new BufferedReader (new InputStreamReader (is));
+ int width = -1, height = -1;
+
+ for (int i = 0; i < 2; i++)
+ {
+ String line = reader.readLine ();
+ StringTokenizer st = new StringTokenizer (line);
+
+ st.nextToken (); // #define
+ st.nextToken (); // name_[width|height]
+ if (i == 0)
+ width = Integer.parseInt (st.nextToken (), 10);
+ else
+ height = Integer.parseInt (st.nextToken (), 10);
+ }
+
+ for (int i = 0; i < v.size (); i++)
+ {
+ ImageConsumer ic = (ImageConsumer) v.elementAt (i);
+
+ ic.setDimensions (width, height);
+ ic.setColorModel (cm);
+ ic.setHints (ImageConsumer.COMPLETESCANLINES
+ | ImageConsumer.SINGLEFRAME
+ | ImageConsumer.SINGLEPASS
+ | ImageConsumer.TOPDOWNLEFTRIGHT);
+ }
+
+ /* skip to the byte array */
+ while (reader.read () != '{') { }
+
+ /* loop through each scanline */
+ for (int line = 0; line < height; line++)
+ {
+ int scanline[] = getScanline (reader, width);
+
+ for (int i = 0; i < v.size (); i++)
+ {
+ ImageConsumer ic = (ImageConsumer) v.elementAt (i);
+ ic.setPixels (0, 0 + line, width, 1, cm, scanline, 0, width);
+ }
+ }
+
+ /* tell each ImageConsumer that we're finished */
+ for (int i = 0; i < v.size (); i++)
+ {
+ ImageConsumer ic = (ImageConsumer) v.elementAt (i);
+ ic.imageComplete (ImageConsumer.STATICIMAGEDONE);
+ }
+ }
+
+ public static int[] getScanline (Reader in, int len) throws IOException
+ {
+ char byteStr[] = new char[2];
+ int scanline[] = new int[len];
+ int x = 0;
+
+ while (x < len)
+ {
+ int ch = in.read ();
+ if (ch == '0')
+ {
+ in.read (); // 'x'
+
+ byteStr[0] = (char) in.read ();
+ byteStr[1] = (char) in.read ();
+
+ int byteVal = Integer.parseInt (new String (byteStr), 16);
+
+ for (int i = 0; i < 8; i++, x++)
+ {
+ if (x == len) // condition occurs if bitmap is padded
+ return scanline;
+
+ scanline[x] = ((byteVal & masktable[i]) != 0) ?
+ black : transparent;
+ }
+ }
+ }
+
+ return scanline;
+ }
+}
diff --git a/libjava/classpath/gnu/java/awt/image/package.html b/libjava/classpath/gnu/java/awt/image/package.html
new file mode 100644
index 000000000..8823367ea
--- /dev/null
+++ b/libjava/classpath/gnu/java/awt/image/package.html
@@ -0,0 +1,46 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<!-- package.html - describes classes in gnu.java.awt.image package.
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. -->
+
+<html>
+<head><title>GNU Classpath - gnu.java.awt.image</title></head>
+
+<body>
+<p></p>
+
+</body>
+</html>