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