Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / libjava / classpath / gnu / java / awt / peer / gtk / GtkImageConsumer.java
blob299f01dcaa6bb7160d7fc63c5adf93c0194e9e52
1 /* GtkImageConsumer.java
2 Copyright (C) 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package gnu.java.awt.peer.gtk;
41 import java.awt.Graphics;
42 import java.awt.Image;
43 import java.awt.image.ColorModel;
44 import java.awt.image.DirectColorModel;
45 import java.awt.image.ImageConsumer;
46 import java.awt.image.ImageObserver;
47 import java.awt.image.ImageProducer;
48 import java.awt.image.MemoryImageSource;
49 import java.util.Hashtable;
50 import java.util.Vector;
52 /**
53 * Helper class to GtkImage. Sits and gathers pixels for a GtkImage and then
54 * calls GtkImage.setImage().
56 * @author Sven de Marothy
58 public class GtkImageConsumer implements ImageConsumer
60 private GtkImage target;
61 private int width, height;
62 private Hashtable properties;
63 private int[] pixelCache = null;
64 private ImageProducer source;
66 public GtkImageConsumer(GtkImage target, ImageProducer source)
68 this.target = target;
69 this.source = source;
72 public synchronized void imageComplete (int status)
74 // we need to reuse the pixel cache for memory image sources since
75 // a memory image's backing array can be updated "live".
76 if (!(source instanceof MemoryImageSource))
77 source.removeConsumer(this);
78 target.setImage(width, height, pixelCache, properties);
81 public synchronized void setColorModel (ColorModel model)
83 // This method is to inform on what the most used color model
84 // in the image is, for optimization reasons. We ignore this
85 // information.
88 public synchronized void setDimensions (int width, int height)
90 pixelCache = new int[width*height];
92 this.width = width;
93 this.height = height;
96 public synchronized void setHints (int flags)
98 // This method informs us in which order the pixels are
99 // delivered, for progressive-loading support, etc.
100 // Since we wait until it's all loaded, we can ignore the hints.
103 public synchronized void setPixels (int x, int y, int width, int height,
104 ColorModel cm, byte[] pixels,
105 int offset, int scansize)
107 setPixels (x, y, width, height, cm, convertPixels (pixels), offset,
108 scansize);
111 public synchronized void setPixels (int x, int y, int width, int height,
112 ColorModel cm, int[] pixels,
113 int offset, int scansize)
115 if (pixelCache == null)
116 return; // Not sure this should ever happen.
118 if (cm.equals(GtkImage.nativeModel))
119 for (int i = 0; i < height; i++)
120 System.arraycopy (pixels, offset + (i * scansize),
121 pixelCache, (y + i) * this.width + x,
122 width);
123 else
125 for (int i = 0; i < height; i++)
126 for (int j = 0; j < width; j++)
128 // get in AARRGGBB and convert to AABBGGRR
129 int pix = cm.getRGB(pixels[offset + (i * scansize) + x + j]);
130 byte b = (byte)(pix & 0xFF);
131 byte r = (byte)(((pix & 0x00FF0000) >> 16) & 0xFF);
132 pix &= 0xFF00FF00;
133 pix |= ((b & 0xFF) << 16);
134 pix |= (r & 0xFF);
135 pixelCache[(y + i) * this.width + x + j] = pix;
141 * This is an old method, no idea if it's correct.
143 private int[] convertPixels (byte[] pixels)
145 int ret[] = new int[pixels.length];
147 for (int i = 0; i < pixels.length; i++)
148 ret[i] = pixels[i] & 0xFF;
150 return ret;
153 public synchronized void setProperties (Hashtable props)
155 this.properties = props;