/[classpath]/classpath/java/awt/image/MemoryImageSource.java
ViewVC logotype

Diff of /classpath/java/awt/image/MemoryImageSource.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.11 by mkoch, Wed Dec 1 16:22:44 2004 UTC revision 1.12 by mkoch, Thu Dec 23 08:54:59 2004 UTC
# Line 1  Line 1 
1  /* MemoryImageSource.java -- Java class for providing image data  /* MemoryImageSource.java -- Java class for providing image data
2     Copyright (C) 1999, 2004  Free Software Foundation, Inc.     Copyright (C) 1999, 2004  Free Software Foundation, Inc.
3    
4  This file is part of GNU Classpath.  This file is part of GNU Classpath.
# Line 41  package java.awt.image; Line 41  package java.awt.image;
41  import java.util.Hashtable;  import java.util.Hashtable;
42  import java.util.Vector;  import java.util.Vector;
43    
44  public class MemoryImageSource implements ImageProducer  public class MemoryImageSource implements ImageProducer
45  {  {
46      private boolean animated = false;    private boolean animated = false;
47      private boolean fullbuffers = false;    private boolean fullbuffers = false;
48      private int pixeli[], width, height, offset, scansize;    private int[] pixeli;
49      private byte pixelb[];    private int width;
50      private ColorModel cm;    private int height;
51      private Hashtable props = new Hashtable();    private int offset;
52      private Vector consumers = new Vector();    private int scansize;
53      private byte[] pixelb;
54      /**    private ColorModel cm;
55       * Construct an image producer that reads image data from a byte    private Hashtable props = new Hashtable();
56       * array.    private Vector consumers = new Vector();
57       *  
58       * @param w width of image    /**
59       * @param h height of image     * Construct an image producer that reads image data from a byte
60       * @param cm the color model used to represent pixel values     * array.
61       * @param pix a byte array of pixel values     *
62       * @param off the offset into the array at which the first pixel is stored     * @param w width of image
63       * @param scan the number of array elements that represents a single pixel row     * @param h height of image
64       */     * @param cm the color model used to represent pixel values
65      public MemoryImageSource(int w, int h, ColorModel cm,     * @param pix a byte array of pixel values
66                               byte pix[], int off, int scan)     * @param off the offset into the array at which the first pixel is stored
67      {     * @param scan the number of array elements that represents a single pixel row
68          this ( w, h, cm, pix, off, scan, null );     */
69      }    public MemoryImageSource(int w, int h, ColorModel cm, byte[] pix, int off,
70      /**                             int scan)
71         Constructs an ImageProducer from memory    {
72      */      this(w, h, cm, pix, off, scan, null);
73      public MemoryImageSource( int w, int h, ColorModel cm,    }
74                                byte pix[], int off, int scan,  
75                                Hashtable props)    /**
76      {     * Constructs an ImageProducer from memory
77          width = w;     */
78          height = h;    public MemoryImageSource(int w, int h, ColorModel cm, byte[] pix, int off,
79          this.cm = cm;                             int scan, Hashtable props)
80          offset = off;    {
81          scansize = scan;      width = w;
82          this.props = props;      height = h;
83          int max = (( scansize > width ) ? scansize : width );      this.cm = cm;
84          pixelb = pix;      offset = off;
85      }      scansize = scan;
86      /**      this.props = props;
87       * Construct an image producer that reads image data from an      int max = ((scansize > width) ? scansize : width);
88       * integer array.      pixelb = pix;
89       *    }
90       * @param w width of image  
91       * @param h height of image    /**
92       * @param cm the color model used to represent pixel values     * Construct an image producer that reads image data from an
93       * @param pix an integer array of pixel values     * integer array.
94       * @param off the offset into the array at which the first pixel is stored     *
95       * @param scan the number of array elements that represents a single pixel row     * @param w width of image
96       */     * @param h height of image
97      public MemoryImageSource(int w, int h, ColorModel cm,     * @param cm the color model used to represent pixel values
98                               int pix[], int off, int scan)     * @param pix an integer array of pixel values
99      {     * @param off the offset into the array at which the first pixel is stored
100          this ( w, h, cm, pix, off, scan, null );     * @param scan the number of array elements that represents a single pixel row
101      }     */
102      public MemoryImageSource(int w, int h, ColorModel cm, int[] pix, int off,
103      /**                             int scan)
104         Constructs an ImageProducer from memory    {
105      */      this(w, h, cm, pix, off, scan, null);
106      public MemoryImageSource(int w, int h, ColorModel cm,    }
107                               int pix[], int off, int scan,  
108                               Hashtable props)    /**
109      {       Constructs an ImageProducer from memory
110          width = w;    */
111          height = h;    public MemoryImageSource(int w, int h, ColorModel cm, int[] pix, int off,
112          this.cm = cm;                             int scan, Hashtable props)
113          offset = off;    {
114          scansize = scan;      width = w;
115          this.props = props;      height = h;
116          int max = (( scansize > width ) ? scansize : width );      this.cm = cm;
117          pixeli = pix;      offset = off;
118      }      scansize = scan;
119      /**      this.props = props;
120         Constructs an ImageProducer from memory using the default RGB ColorModel      int max = ((scansize > width) ? scansize : width);
121      */      pixeli = pix;
122      public MemoryImageSource(int w, int h,    }
123                               int pix[], int off, int scan,  
124                               Hashtable props)    /**
125      {     * Constructs an ImageProducer from memory using the default RGB ColorModel
126          this ( w, h, ColorModel.getRGBdefault(), pix, off, scan, props);     */
127      }    public MemoryImageSource(int w, int h, int[] pix, int off, int scan,
128                               Hashtable props)
129      /**    {
130         Constructs an ImageProducer from memory using the default RGB ColorModel      this(w, h, ColorModel.getRGBdefault(), pix, off, scan, props);
131      */    }
132      public MemoryImageSource(int w, int h,  
133                               int pix[], int off, int scan)    /**
134      {     * Constructs an ImageProducer from memory using the default RGB ColorModel
135          this ( w, h, ColorModel.getRGBdefault(), pix, off, scan, null);     */
136      }    public MemoryImageSource(int w, int h, int[] pix, int off, int scan)
137      {
138      /**      this(w, h, ColorModel.getRGBdefault(), pix, off, scan, null);
139       * Used to register an <code>ImageConsumer</code> with this    }
140       * <code>ImageProducer</code>.    
141       */    /**
142      public synchronized void addConsumer(ImageConsumer ic) {     * Used to register an <code>ImageConsumer</code> with this
143          if (consumers.contains(ic))     * <code>ImageProducer</code>.
144              return;     */
145      public synchronized void addConsumer(ImageConsumer ic)
146          consumers.addElement(ic);    {
147      }      if (consumers.contains(ic))
148          return;
149      /**  
150       * Used to determine if the given <code>ImageConsumer</code> is      consumers.addElement(ic);
151       * already registered with this <code>ImageProducer</code>.      }
152       */  
153      public synchronized boolean isConsumer(ImageConsumer ic) {    /**
154          if (consumers.contains(ic))     * Used to determine if the given <code>ImageConsumer</code> is
155              return true;     * already registered with this <code>ImageProducer</code>.
156          return false;     */
157      }    public synchronized boolean isConsumer(ImageConsumer ic)
158      {
159      /**      if (consumers.contains(ic))
160       * Used to remove an <code>ImageConsumer</code> from the list of        return true;
161       * registered consumers for this <code>ImageProducer</code>.        return false;
162       */    }
163      public synchronized void removeConsumer(ImageConsumer ic) {  
164          consumers.removeElement(ic);    /**
165      }     * Used to remove an <code>ImageConsumer</code> from the list of
166       * registered consumers for this <code>ImageProducer</code>.
167      /**     */
168       * Used to register an <code>ImageConsumer</code> with this    public synchronized void removeConsumer(ImageConsumer ic)
169       * <code>ImageProducer</code> and then immediately start    {
170       * reconstruction of the image data to be delivered to all      consumers.removeElement(ic);
171       * registered consumers.      }
172       */  
173      public void startProduction(ImageConsumer ic) {    /**
174          if (!(consumers.contains(ic))) {     * Used to register an <code>ImageConsumer</code> with this
175              consumers.addElement(ic);     * <code>ImageProducer</code> and then immediately start
176          }             * reconstruction of the image data to be delivered to all
177       * registered consumers.
178       */
179      public void startProduction(ImageConsumer ic)
180      {
181        if (! (consumers.contains(ic)))
182          consumers.addElement(ic);
183    
184        Vector list = (Vector) consumers.clone();
185        for (int i = 0; i < list.size(); i++)
186          {
187            ic = (ImageConsumer) list.elementAt(i);
188            sendPicture(ic);
189            if (animated)
190              ic.imageComplete(ImageConsumer.SINGLEFRAME);
191            else
192              ic.imageComplete(ImageConsumer.STATICIMAGEDONE);
193          }
194      }
195    
196      /**
197       * Used to register an <code>ImageConsumer</code> with this
198       * <code>ImageProducer</code> and then request that this producer
199       * resend the image data in the order top-down, left-right.
200       */
201      public void requestTopDownLeftRightResend(ImageConsumer ic)
202      {
203        startProduction(ic);
204      }
205    
206      /**
207       * Changes a flag to indicate whether this MemoryImageSource supports
208       * animations.
209       *
210       * @param animated A flag indicating whether this class supports animations
211       */
212      public synchronized void setAnimated(boolean animated)
213      {
214        this.animated = animated;
215      }
216    
217      /**
218       * A flag to indicate whether or not to send full buffer updates when
219       * sending animation. If this flag is set then full buffers are sent
220       * in the newPixels methods instead of just regions.
221       *
222       * @param fullbuffers - a flag indicating whether to send the full buffers
223       */
224      public synchronized void setFullBufferUpdates(boolean fullbuffers)
225      {
226        this.fullbuffers = fullbuffers;
227      }
228    
229      /**
230       * Send an animation frame to the image consumers.
231       */
232      public void newPixels()
233      {
234        if (animated == true)
235          {
236            ImageConsumer ic;
237          Vector list = (Vector) consumers.clone();          Vector list = (Vector) consumers.clone();
238          for(int i = 0; i < list.size(); i++) {          for (int i = 0; i < list.size(); i++)
239              {
240              ic = (ImageConsumer) list.elementAt(i);              ic = (ImageConsumer) list.elementAt(i);
241              sendPicture( ic );              sendPicture(ic);
242              if (animated)              ic.imageComplete(ImageConsumer.SINGLEFRAME);
243                ic.imageComplete( ImageConsumer.SINGLEFRAME );            }
244              else        }
245                ic.imageComplete( ImageConsumer.STATICIMAGEDONE );    }
246          }        
247      }    private void sendPicture(ImageConsumer ic)
248      {
249      /**      ic.setHints(ImageConsumer.TOPDOWNLEFTRIGHT);
250       * Used to register an <code>ImageConsumer</code> with this      if (props != null)
251       * <code>ImageProducer</code> and then request that this producer        ic.setProperties(props);
252       * resend the image data in the order top-down, left-right.        ic.setDimensions(width, height);
253       */      ic.setColorModel(cm);
254      public void requestTopDownLeftRightResend(ImageConsumer ic) {      if (pixeli != null)
255          startProduction ( ic );        ic.setPixels(0, 0, width, height, cm, pixeli, offset, scansize);
256      }      else
257          ic.setPixels(0, 0, width, height, cm, pixelb, offset, scansize);
258      }
259      /**  
260         Changes a flag to indicate whether this MemoryImageSource supports    /**
261         animations.     * Send an animation frame to the image consumers containing the specified
262       * pixels unless setFullBufferUpdates is set.
263         @param animated A flag indicating whether this class supports animations     */
264       */        public synchronized void newPixels(int x, int y, int w, int h)
265      public synchronized void setAnimated(boolean animated)    {
266      {      if (animated == true)
267          this.animated = animated;        {
268      }          if (fullbuffers)
269              newPixels();
270            else
271      /**            {
272         A flag to indicate whether or not to send full buffer updates when              ImageConsumer ic;
273         sending animation. If this flag is set then full buffers are sent              Vector list = (Vector) consumers.clone();
274         in the newPixels methods instead of just regions.              for (int i = 0; i < list.size(); i++)
275                  {
276         @param fullbuffers - a flag indicating whether to send the full buffers                  ic = (ImageConsumer) list.elementAt(i);
277       */                  ic.setHints(ImageConsumer.TOPDOWNLEFTRIGHT);
278      public synchronized void setFullBufferUpdates(boolean fullbuffers)                  if (props != null)
279      {                    ic.setProperties(props);
280          this.fullbuffers = fullbuffers;                  if (pixeli != null)
281      }                    {
282                        int[] pixelbuf = new int[w * h];
283      /**                      for (int row = y; row < y + h; row++)
284         Send an animation frame to the image consumers.                        System.arraycopy(pixeli, row * scansize + x + offset,
285       */                                         pixelbuf, 0, w * h);
286      public void newPixels()                      ic.setPixels(x, y, w, h, cm, pixelbuf, 0, w);
287      {                    }
288          if( animated == true ) {                  else
289                  ImageConsumer ic;                    {
290                  Vector list = (Vector) consumers.clone();                      byte[] pixelbuf = new byte[w * h];
291                  for(int i = 0; i < list.size(); i++) {                      for (int row = y; row < y + h; row++)
292                          ic = (ImageConsumer) list.elementAt(i);                        System.arraycopy(pixelb, row * scansize + x + offset,
293                          sendPicture( ic );                                         pixelbuf, 0, w * h);
294                          ic.imageComplete( ImageConsumer.SINGLEFRAME );  
295                      }                        ic.setPixels(x, y, w, h, cm, pixelbuf, 0, w);
296              }                    }
297      }                  ic.imageComplete(ImageConsumer.SINGLEFRAME);
298                  }
299                  }
300      private void sendPicture ( ImageConsumer ic )        }
301      {    }
302          ic.setHints( ImageConsumer.TOPDOWNLEFTRIGHT );  
303          if( props != null ) {    /**
304              ic.setProperties( props );     * Send an animation frame to the image consumers containing the specified
305          }     * pixels unless setFullBufferUpdates is set.
306          ic.setDimensions(width, height);     *
307          ic.setColorModel(cm);     * If framenotify is set then a notification is sent when the frame
308          if( pixeli != null ) {     * is sent otherwise no status is sent.
309              ic.setPixels( 0, 0, width, height, cm, pixeli, offset, scansize );     */
310          } else {    public synchronized void newPixels(int x, int y, int w, int h,
311              ic.setPixels( 0, 0, width, height, cm, pixelb, offset, scansize );                                       boolean framenotify)
312          }    {
313      }      if (animated == true)
314          {
315      /**          if (fullbuffers)
316         Send an animation frame to the image consumers containing the specified            newPixels();
317         pixels unless setFullBufferUpdates is set.          else
318       */            {
319      public synchronized void newPixels(int x,              ImageConsumer ic;
320                                         int y,              Vector list = (Vector) consumers.clone();
321                                         int w,              for (int i = 0; i < list.size(); i++)
322                                         int h)                {
323      {                  ic = (ImageConsumer) list.elementAt(i);
324          if( animated == true )                  ic.setHints(ImageConsumer.TOPDOWNLEFTRIGHT);
325              {                  if (props != null)
326                  if( fullbuffers ) {                    ic.setProperties(props);
327                      newPixels();                  if (pixeli != null)
328                  } else {                    {
329                      ImageConsumer ic;                      int[] pixelbuf = new int[w * h];
330                      Vector list = (Vector) consumers.clone();                      for (int row = y; row < y + h; row++)
331                      for(int i = 0; i < list.size(); i++) {                        System.arraycopy(pixeli, row * scansize + x + offset,
332                              ic = (ImageConsumer) list.elementAt(i);                                         pixelbuf, 0, w * h);
333                              ic.setHints( ImageConsumer.TOPDOWNLEFTRIGHT );                      ic.setPixels(x, y, w, h, cm, pixelbuf, 0, w);
334                              if( props != null ) {                    }
335                                  ic.setProperties( props );                  else
336                              }                    {
337                              if( pixeli != null ) {                      byte[] pixelbuf = new byte[w * h];
338                                  int[] pixelbuf = new int[w * h];                      for (int row = y; row < y + h; row++)
339                                  for (int row = y; row < y + h; row++)                        System.arraycopy(pixelb, row * scansize + x + offset,
340                                      System.arraycopy(pixeli, row * scansize + x + offset, pixelbuf, 0, w * h);                                         pixelbuf, 0, w * h);
341                                  ic.setPixels( x, y, w, h, cm, pixelbuf, 0, w );                      ic.setPixels(x, y, w, h, cm, pixelbuf, 0, w);
342                              } else {                    }
343                                  byte[] pixelbuf = new byte[w * h];                  if (framenotify == true)
344                                  for (int row = y; row < y + h; row++)                    ic.imageComplete(ImageConsumer.SINGLEFRAME);
345                                    System.arraycopy(pixelb, row * scansize + x + offset, pixelbuf, 0, w * h);                }
346              }
347                                  ic.setPixels( x, y, w, h, cm, pixelbuf, 0, w );        }
348                              }    }
349                              ic.imageComplete( ImageConsumer.SINGLEFRAME );  
350                      }    public synchronized void newPixels(byte[] newpix, ColorModel newmodel,
351                  }                                           int offset, int scansize)
352              }    {
353      }      pixeli = null;
354        pixelb = newpix;
355        cm = newmodel;
356        this.offset = offset;
357      /**      this.scansize = scansize;
358         Send an animation frame to the image consumers containing the specified      if (animated == true)
359         pixels unless setFullBufferUpdates is set.        newPixels();
360      }
361         If framenotify is set then a notification is sent when the frame  
362         is sent otherwise no status is sent.    public synchronized void newPixels(int[] newpix, ColorModel newmodel,
363       */                                       int offset, int scansize)
364      public synchronized void newPixels(int x,    {
365                                         int y,      pixelb = null;
366                                         int w,      pixeli = newpix;
367                                         int h,      cm = newmodel;
368                                         boolean framenotify)      this.offset = offset;
369      {      this.scansize = scansize;
370          if( animated == true )      if (animated == true)
371              {        newPixels();
372                  if( fullbuffers ) {    }
                     newPixels();  
                 } else {  
                     ImageConsumer ic;  
                     Vector list = (Vector) consumers.clone();  
                     for(int i = 0; i < list.size(); i++) {  
                             ic = (ImageConsumer) list.elementAt(i);  
                             ic.setHints( ImageConsumer.TOPDOWNLEFTRIGHT );  
                             if( props != null ) {  
                                 ic.setProperties( props );  
                             }  
                             if( pixeli != null ) {  
                                 int[] pixelbuf = new int[w * h];  
                                 for (int row = y; row < y + h; row++)  
                                     System.arraycopy(pixeli, row * scansize + x + offset, pixelbuf, 0, w * h);  
                                 ic.setPixels( x, y, w, h, cm, pixelbuf, 0, w );  
                             } else {  
                                 byte[] pixelbuf = new byte[w * h];  
                                 for (int row = y; row < y + h; row++)  
                                     System.arraycopy(pixelb, row * scansize + x + offset, pixelbuf, 0, w * h);  
                                 ic.setPixels( x, y, w, h, cm, pixelbuf, 0, w );  
                             }  
                             if( framenotify == true )  
                                 ic.imageComplete( ImageConsumer.SINGLEFRAME );  
                     }  
                 }      
             }  
     }  
   
     public synchronized void newPixels(byte newpix[],  
                                        ColorModel newmodel,  
                                        int offset,  
                                        int scansize)  
   
     {  
         pixeli = null;  
         pixelb = newpix;  
         cm = newmodel;  
         this.offset = offset;  
         this.scansize = scansize;  
         if( animated == true )  
             {  
                 newPixels();  
             }  
     }  
   
     public synchronized void newPixels(int newpix[],  
                                        ColorModel newmodel,  
                                        int offset,  
                                        int scansize)  
   
     {  
         pixelb = null;  
         pixeli = newpix;  
         cm = newmodel;  
         this.offset = offset;  
         this.scansize = scansize;  
         if( animated == true )  
             {  
                 newPixels();  
             }  
     }  
   
373  }  }

Legend:
Removed from v.1.11  
changed lines
  Added in v.1.12

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26