Coverage Report - uk.co.javagear.FastImage
 
Classes in this File Line Coverage Branch Coverage Complexity
FastImage
0% 
0% 
1.111
 
 1  
 /*
 2  
  * FastImage.java
 3  
  *
 4  
  * This file is part of JavaGear.
 5  
  *
 6  
  * JavaGear 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 of the License, or
 9  
  * (at your option) any later version.
 10  
  *
 11  
  * JavaGear is distributed in the hope that it will be useful,
 12  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 13  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 14  
  * GNU General Public License for more details.
 15  
  *
 16  
  * You should have received a copy of the GNU General Public License
 17  
  * along with JavaGear; if not, write to the Free Software
 18  
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 19  
  */
 20  
 
 21  
 package uk.co.javagear;
 22  
 
 23  
 import java.awt.Image;
 24  
 import java.awt.Toolkit;
 25  
 import java.awt.Graphics;
 26  
 import java.awt.image.DirectColorModel;
 27  
 import java.awt.image.ImageConsumer;
 28  
 import java.awt.image.ImageProducer;
 29  
 
 30  
 
 31  
 /**
 32  
  * FastImage implements <code>ImageProducer</code> and is used to reconstruct the image
 33  
  * whenever it is needed.
 34  
  *
 35  
  * @author Copyright (C) 2003 Chris White
 36  
  * @version 18th January 2003
 37  
  */
 38  
 public class FastImage implements ImageProducer {
 39  
     
 40  
     /**
 41  
      * Image width.
 42  
      */
 43  
     private int width;
 44  
     
 45  
     /**
 46  
      * Image height.
 47  
      */
 48  
     private int height;
 49  
     
 50  
     /**
 51  
      * Image data.
 52  
      */
 53  
     private Image image;
 54  
     
 55  
     /**
 56  
      * Image consumer.
 57  
      */
 58  
     private ImageConsumer consumer;
 59  
     
 60  
     /**
 61  
      * Direct color model (32 bits).
 62  
      */
 63  
     private DirectColorModel model;
 64  
     
 65  
     /**
 66  
      * Construct a <code>FastImage</code>.
 67  
      *
 68  
      * @param w Width of Image
 69  
      * @param h Height of Image
 70  
      */
 71  0
     public FastImage(int w, int h) {
 72  0
         width = w;
 73  0
         height = h;
 74  
         
 75  0
         model = new DirectColorModel(32, 0x00FF0000, 0x000FF00, 0x000000FF, 0);
 76  
         
 77  0
         image = Toolkit.getDefaultToolkit().createImage(this);
 78  0
     }
 79  
     
 80  
     
 81  
     /**
 82  
      * Update the FastImage with new pixel data.
 83  
      *
 84  
      * @param pixels pixel array.
 85  
      * @param offset offset into pixel array.
 86  
      */
 87  
     public void update(int[] pixels, int offset) {
 88  0
         if (consumer != null) {
 89  
             // Copy Integer Pixel Data to ImageComsumer
 90  0
             consumer.setPixels(0, 0, width, height, model, pixels, offset, width);
 91  
             
 92  
             // Notify Image Consumer When Single Frame is Done
 93  0
             consumer.imageComplete(ImageConsumer.SINGLEFRAMEDONE);
 94  
         }
 95  0
     }
 96  
     
 97  
     
 98  
     /**
 99  
      * Paint the <code>FastImage</code>.
 100  
      *
 101  
      * @param g graphics context
 102  
      * @param xOffset X Offset at which to paint image at
 103  
      * @param yOffset Y Offset at which to paint image at
 104  
      * @param xScale X Scale Factor
 105  
      * @param yScale Y Scale Factor
 106  
      */
 107  
     public void paint(Graphics g, int xOffset, int yOffset, int xScale, int yScale) {
 108  0
         g.drawImage(image, xOffset, yOffset, xScale, yScale, null);
 109  0
     }
 110  
     
 111  
     /**
 112  
      * Paint the <code>FastImage</code>.
 113  
      *
 114  
      * @param g Graphics context
 115  
      * @param x1 Destination top left corner
 116  
      * @param y1 Destination top left corner
 117  
      * @param x2 Destination bottom right corner
 118  
      * @param y2 Destination bottom right corner
 119  
      * @param x3 Source top left corner
 120  
      * @param y3 Source top left corner
 121  
      * @param x4 Source bottom right corner
 122  
      * @param y4 Source bottom right corner
 123  
      */
 124  
     public void paint(Graphics g
 125  
             , int x1, int y1
 126  
             , int x2, int y2
 127  
             , int x3, int y3
 128  
             , int x4, int y4) {
 129  0
         g.drawImage(image, x1, y1, x2, y2, x3, y3, x4, y4, null);
 130  0
     }
 131  
     
 132  
     
 133  
     /**
 134  
      * Registers an ImageConsumer with the ImageProducer for access to the image data
 135  
      *  during a later reconstruction of the Image.
 136  
      *
 137  
      * @param ic the specified ImageConsumer
 138  
      */
 139  
     public void addConsumer(ImageConsumer ic) {
 140  
         // Register Image Consumer
 141  0
         consumer = ic;
 142  
         
 143  
         // Set Image Dimensions
 144  0
         consumer.setDimensions(width, height);
 145  
         
 146  
         // Set Image Consumer Hints for speed
 147  0
         consumer.setHints(ImageConsumer.TOPDOWNLEFTRIGHT | ImageConsumer.COMPLETESCANLINES
 148  
                 | ImageConsumer.SINGLEPASS | ImageConsumer.SINGLEFRAME);
 149  
         
 150  
         // Set Image Colour Model
 151  0
         consumer.setColorModel(model);
 152  0
     }
 153  
     
 154  
     /**
 155  
      * Check if consumer is already registered.
 156  
      *
 157  
      * @return always returns true
 158  
      * @param ic an instance of <code>ImageConsumer</code>.
 159  
      */
 160  
     public boolean isConsumer(ImageConsumer ic) {
 161  0
         return true;
 162  
     }
 163  
     
 164  
     /**
 165  
      * Registers the specified ImageConsumer object as a consumer and starts an immediate
 166  
      * reconstruction of the image data which will then be delivered to this consumer and
 167  
      * any other consumer which might have already been registered with the producer.
 168  
      *
 169  
      * @param ic the specified ImageConsumer
 170  
      */
 171  
     public void startProduction(ImageConsumer ic) {
 172  0
         addConsumer(ic);
 173  0
     }
 174  
     
 175  
     /**
 176  
      * Does nothing.
 177  
      *
 178  
      * @param ic an instance of <code>ImageConsumer</code>.
 179  
      */
 180  
     public void removeConsumer(ImageConsumer ic) {
 181  0
     }
 182  
     
 183  
     /**
 184  
      * Does nothing.
 185  
      *
 186  
      * @param ic an instance of <code>ImageConsumer</code>.
 187  
      */
 188  
     public void requestTopDownLeftRightResend(ImageConsumer ic) {
 189  0
     }
 190  
     
 191  
 }