source: branches/libc-0.6/src/gcc/libjava/java/awt/image/MemoryImageSource.java

Last change on this file was 1392, checked in by bird, 22 years ago

This commit was generated by cvs2svn to compensate for changes in r1391,
which included commits to RCS files with non-trunk default branches.

  • Property cvs2svn:cvs-rev set to 1.1.1.2
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 9.2 KB
Line 
1/* MemoryImageSource.java -- Java class for providing image data
2 Copyright (C) 1999 Free Software Foundation, Inc.
3
4This file is part of GNU Classpath.
5
6GNU Classpath is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GNU Classpath is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Classpath; see the file COPYING. If not, write to the
18Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
1902111-1307 USA.
20
21Linking this library statically or dynamically with other modules is
22making a combined work based on this library. Thus, the terms and
23conditions of the GNU General Public License cover the whole
24combination.
25
26As a special exception, the copyright holders of this library give you
27permission to link this library with independent modules to produce an
28executable, regardless of the license terms of these independent
29modules, and to copy and distribute the resulting executable under
30terms of your choice, provided that you also meet, for each linked
31independent module, the terms and conditions of the license of that
32module. An independent module is a module which is not derived from
33or based on this library. If you modify this library, you may extend
34this exception to your version of the library, but you are not
35obligated to do so. If you do not wish to do so, delete this
36exception statement from your version. */
37
38
39package java.awt.image;
40
41import java.awt.Image;
42import java.util.Enumeration;
43import java.util.Hashtable;
44
45public class MemoryImageSource implements ImageProducer
46{
47 private boolean animated = false;
48 private boolean fullbuffers = false;
49 private int pixeli[], width, height, offset, scansize;
50 private byte pixelb[];
51 private ColorModel cm;
52 private Hashtable props, consumers = new Hashtable();
53
54 /**
55 Constructs an ImageProducer from memory
56 */
57 public MemoryImageSource(int w, int h, ColorModel cm,
58 byte pix[], int off, int scan)
59 {
60 this ( w, h, cm, pix, off, scan, null );
61 }
62 /**
63 Constructs an ImageProducer from memory
64 */
65 public MemoryImageSource( int w, int h, ColorModel cm,
66 byte pix[], int off, int scan,
67 Hashtable props)
68 {
69 width = w;
70 height = h;
71 this.cm = cm;
72 offset = off;
73 scansize = scan;
74 this.props = props;
75 int max = (( scansize > width ) ? scansize : width );
76 pixelb = new byte[ max * height ];
77 System.arraycopy( pix, 0, pixelb, 0, max );
78 }
79 /**
80 Constructs an ImageProducer from memory
81 */
82 public MemoryImageSource(int w, int h, ColorModel cm,
83 int pix[], int off, int scan)
84 {
85 this ( w, h, cm, pix, off, scan, null );
86 }
87
88 /**
89 Constructs an ImageProducer from memory
90 */
91 public MemoryImageSource(int w, int h, ColorModel cm,
92 int pix[], int off, int scan,
93 Hashtable props)
94 {
95 width = w;
96 height = h;
97 this.cm = cm;
98 offset = off;
99 scansize = scan;
100 this.props = props;
101 int max = (( scansize > width ) ? scansize : width );
102 pixeli = new int[ max * height ];
103 System.arraycopy( pix, 0, pixeli, 0, max );
104 }
105 /**
106 Constructs an ImageProducer from memory using the default RGB ColorModel
107 */
108 public MemoryImageSource(int w, int h,
109 int pix[], int off, int scan,
110 Hashtable props)
111 {
112 this ( w, h, ColorModel.getRGBdefault(), pix, off, scan, props);
113 }
114
115 /**
116 Constructs an ImageProducer from memory using the default RGB ColorModel
117 */
118 public MemoryImageSource(int w, int h,
119 int pix[], int off, int scan)
120 {
121 this ( w, h, ColorModel.getRGBdefault(), pix, off, scan, null);
122 }
123
124 /**
125 * Used to register an <code>ImageConsumer</code> with this
126 * <code>ImageProducer</code>.
127 */
128 public synchronized void addConsumer(ImageConsumer ic) {
129 if (consumers.containsKey(ic))
130 return;
131
132 consumers.put(ic, ic);
133 }
134
135 /**
136 * Used to determine if the given <code>ImageConsumer</code> is
137 * already registered with this <code>ImageProducer</code>.
138 */
139 public synchronized boolean isConsumer(ImageConsumer ic) {
140 if (consumers.containsKey(ic))
141 return true;
142 return false;
143 }
144
145 /**
146 * Used to remove an <code>ImageConsumer</code> from the list of
147 * registered consumers for this <code>ImageProducer</code>.
148 */
149 public synchronized void removeConsumer(ImageConsumer ic) {
150 consumers.remove(ic);
151 }
152
153 /**
154 * Used to register an <code>ImageConsumer</code> with this
155 * <code>ImageProducer</code> and then immediately start
156 * reconstruction of the image data to be delivered to all
157 * registered consumers.
158 */
159 public void startProduction(ImageConsumer ic) {
160 if (!(consumers.containsKey(ic))) {
161 consumers.put(ic, ic);
162 }
163 Enumeration e = consumers.elements();
164 for( ; e.hasMoreElements(); ) {
165 ic = (ImageConsumer)e.nextElement();
166 sendPicture( ic );
167 ic.imageComplete( ImageConsumer.SINGLEFRAME );
168 }
169
170 }
171
172 /**
173 * Used to register an <code>ImageConsumer</code> with this
174 * <code>ImageProducer</code> and then request that this producer
175 * resend the image data in the order top-down, left-right.
176 */
177 public void requestTopDownLeftRightResend(ImageConsumer ic) {
178 startProduction ( ic );
179 }
180
181
182 /**
183 Changes a flag to indicate whether this MemoryImageSource supports
184 animations.
185
186 @param animated A flag indicating whether this class supports animations
187 */
188 public synchronized void setAnimated(boolean animated)
189 {
190 this.animated = animated;
191 }
192
193
194 /**
195 A flag to indicate whether or not to send full buffer updates when
196 sending animation. If this flag is set then full buffers are sent
197 in the newPixels methods instead of just regions.
198
199 @param fullbuffers - a flag indicating whether to send the full buffers
200 */
201 public synchronized void setFullBufferUpdates(boolean fullbuffers)
202 {
203 this.fullbuffers = fullbuffers;
204 }
205
206 /**
207 Send an animation frame to the image consumers.
208 */
209 public void newPixels()
210 {
211 if( animated == true ) {
212 ImageConsumer ic;
213 Enumeration e = consumers.elements();
214 for( ; e.hasMoreElements(); ) {
215 ic = (ImageConsumer)e.nextElement();
216 sendPicture( ic );
217 ic.imageComplete( ImageConsumer.SINGLEFRAME );
218 }
219 }
220 }
221
222
223 private void sendPicture ( ImageConsumer ic )
224 {
225 ic.setHints( ImageConsumer.TOPDOWNLEFTRIGHT );
226 if( props != null ) {
227 ic.setProperties( props );
228 }
229 if( pixeli != null ) {
230 ic.setPixels( 0, 0, width, height, cm, pixeli, offset, scansize );
231 } else {
232 ic.setPixels( 0, 0, width, height, cm, pixelb, offset, scansize );
233 }
234 }
235
236 /**
237 Send an animation frame to the image consumers containing the specified
238 pixels unless setFullBufferUpdates is set.
239 */
240 public synchronized void newPixels(int x,
241 int y,
242 int w,
243 int h)
244 {
245 if( animated == true )
246 {
247 if( fullbuffers ) {
248 newPixels();
249 } else {
250 ImageConsumer ic;
251 Enumeration e = consumers.elements();
252 for( ; e.hasMoreElements(); ) {
253 ic = (ImageConsumer)e.nextElement();
254 ic.setHints( ImageConsumer.TOPDOWNLEFTRIGHT );
255 if( props != null ) {
256 ic.setProperties( props );
257 }
258 if( pixeli != null ) {
259 ic.setPixels( 0, 0, width, height, cm, pixeli, offset, scansize );
260 } else {
261 ic.setPixels( 0, 0, width, height, cm, pixelb, offset, scansize );
262 }
263 ic.imageComplete( ImageConsumer.SINGLEFRAME );
264 }
265 }
266 }
267 }
268
269
270
271 /**
272 Send an animation frame to the image consumers containing the specified
273 pixels unless setFullBufferUpdates is set.
274
275 If framenotify is set then a notification is sent when the frame
276 is sent otherwise no status is sent.
277 */
278 public synchronized void newPixels(int x,
279 int y,
280 int w,
281 int h,
282 boolean framenotify)
283 {
284 if( animated == true )
285 {
286 if( fullbuffers ) {
287 newPixels();
288 } else {
289 ImageConsumer ic;
290 Enumeration e = consumers.elements();
291 for( ; e.hasMoreElements(); ) {
292 ic = (ImageConsumer)e.nextElement();
293 ic.setHints( ImageConsumer.TOPDOWNLEFTRIGHT );
294 if( props != null ) {
295 ic.setProperties( props );
296 }
297 if( pixeli != null ) {
298 ic.setPixels( 0, 0, width, height, cm, pixeli, offset, scansize );
299 } else {
300 ic.setPixels( 0, 0, width, height, cm, pixelb, offset, scansize );
301 }
302 if( framenotify == true )
303 ic.imageComplete( ImageConsumer.SINGLEFRAME );
304 }
305 }
306 }
307 }
308
309 public synchronized void newPixels(byte newpix[],
310 ColorModel newmodel,
311 int offset,
312 int scansize)
313
314 {
315 if( animated == true )
316 {
317 //FIXME
318 }
319 }
320
321 public synchronized void newPixels(int newpix[],
322 ColorModel newmodel,
323 int offset,
324 int scansize)
325
326 {
327 if( animated == true )
328 {
329 //FIXME
330 }
331 }
332
333}
Note: See TracBrowser for help on using the repository browser.