GNU Classpath (0.17) | ||
Frames | No Frames |
1: /* ImageFilter.java -- Java class for filtering images 2: Copyright (C) 1999 Free Software Foundation, Inc. 3: 4: This file is part of GNU Classpath. 5: 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. 10: 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. 15: 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. 20: 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. 25: 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. */ 37: 38: 39: package java.awt.image; 40: 41: import java.util.Hashtable; 42: 43: /** 44: * The <code>ImageFilter</code> class is a base class which can be 45: * extended to provide different types of filters for an image. By 46: * default this class does nothing to an image passing through it. 47: * 48: * @author C. Brian Jones (cbj@gnu.org) 49: */ 50: public class ImageFilter implements ImageConsumer, Cloneable 51: { 52: /** 53: * The consumer this filter is filtering an image data stream for. 54: * It is initialized in the method <code>getFilterInstance</code>. 55: */ 56: protected ImageConsumer consumer = null; 57: 58: /** 59: * The <code>ImageConsumer</code> can use this method to request 60: * the pixels be delivered in top-down, left-right order. 61: * <br> 62: * The filter can respond in three different ways. 63: * <ul> 64: * <li>The default behavior is to forward the request to the 65: * <code>ImageProducer</code> 66: * using the method <code>requestTopDownLeftRightResend</code> 67: * and using the filter as the consumer.</li> 68: * <li>The filter has the pixels and can retransmit them in the 69: * top-down, left-right order.</li> 70: * <li>The filter can do nothing when this method is called.</li> 71: * </ul> 72: */ 73: public void resendTopDownLeftRight(ImageProducer ip) 74: { 75: ip.requestTopDownLeftRightResend(this); 76: } 77: 78: /** 79: * By default, returns a shallow copy of the object created by 80: * <code>Object.clone()</code> 81: * 82: * @see java.lang.Object#clone () 83: */ 84: public Object clone() 85: { 86: try 87: { 88: return super.clone(); 89: } 90: catch (CloneNotSupportedException e) 91: { 92: // This should never happen as this class implements the 93: // Cloneable interface. 94: throw new InternalError (); 95: } 96: } 97: 98: /** 99: * This is the only method which can set the 100: * <code>ImageConsumer</code> for this filter. By default a clone 101: * of this filter with the appropriate consumer set is returned. 102: * 103: * @see #clone () 104: */ 105: public ImageFilter getFilterInstance(ImageConsumer ic) 106: { 107: if ( ic == null ) 108: throw new IllegalArgumentException("null argument for ImageFilter.getFilterInstance(ImageConsumer)"); 109: 110: consumer = ic; 111: ImageFilter f = (ImageFilter)clone(); 112: consumer = null; 113: return f; 114: } 115: 116: /** 117: * An <code>ImageProducer</code> indicates the size of the image 118: * being produced using this method. A filter can override this 119: * method to intercept these calls from the producer in order to 120: * change either the width or the height before in turn calling 121: * the consumer's <code>setDimensions</code> method. 122: * 123: * @param width the width of the image 124: * @param height the height of the image 125: */ 126: public void setDimensions(int width, int height) 127: { 128: consumer.setDimensions(width, height); 129: } 130: 131: /** 132: * An <code>ImageProducer</code> can set a list of properties 133: * associated with this image by using this method. 134: * 135: * @param props the list of properties associated with this image 136: */ 137: public void setProperties(Hashtable props) 138: { 139: props.put("filters", "ImageFilter"); 140: consumer.setProperties(props); 141: } 142: 143: /** 144: * Override this method to process calls to this method from the 145: * <code>ImageProducer</code>. By default the <code>setColorModel</code> 146: * method of the consumer is called with the specified <code>model</code>. 147: * 148: * @param model the color model to be used most often by setPixels 149: * @see ColorModel */ 150: public void setColorModel(ColorModel model) 151: { 152: consumer.setColorModel(model); 153: } 154: 155: /** 156: * The <code>ImageProducer</code> should call this method with a 157: * bit mask of hints from any of <code>RANDOMPIXELORDER</code>, 158: * <code>TOPDOWNLEFTRIGHT</code>, <code>COMPLETESCANLINES</code>, 159: * <code>SINGLEPASS</code>, <code>SINGLEFRAME</code> from the 160: * <code>ImageConsumer</code> interface. 161: * 162: * @param flags a bit mask of hints 163: * @see ImageConsumer 164: */ 165: public void setHints(int flags) 166: { 167: consumer.setHints(flags); 168: } 169: 170: /** 171: * This function delivers a rectangle of pixels where any 172: * pixel(m,n) is stored in the array as a <code>byte</code> at 173: * index (n * scansize + m + offset). 174: * 175: * @param x the x coordinate of the rectangle 176: * @param y the y coordinate of the rectangle 177: * @param w the width of the rectangle 178: * @param h the height of the rectangle 179: * @param model the <code>ColorModel</code> used to translate the pixels 180: * @param pixels the array of pixel values 181: * @param offset the index of the first pixels in the <code>pixels</code> array 182: * @param scansize the width to use in extracting pixels from the <code>pixels</code> array 183: */ 184: public void setPixels(int x, int y, int w, int h, 185: ColorModel model, byte[] pixels, int offset, int scansize) 186: { 187: consumer.setPixels(x, y, w, h, model, pixels, offset, scansize); 188: } 189: 190: /** 191: * This function delivers a rectangle of pixels where any 192: * pixel(m,n) is stored in the array as an <code>int</code> at 193: * index (n * scansize + m + offset). 194: * 195: * @param x the x coordinate of the rectangle 196: * @param y the y coordinate of the rectangle 197: * @param w the width of the rectangle 198: * @param h the height of the rectangle 199: * @param model the <code>ColorModel</code> used to translate the pixels 200: * @param pixels the array of pixel values 201: * @param offset the index of the first pixels in the <code>pixels</code> array 202: * @param scansize the width to use in extracting pixels from the <code>pixels</code> array 203: */ 204: public void setPixels(int x, int y, int w, int h, 205: ColorModel model, int[] pixels, int offset, int scansize) 206: { 207: consumer.setPixels(x, y, w, h, model, pixels, offset, scansize); 208: } 209: 210: /** 211: * The <code>ImageProducer</code> calls this method to indicate a 212: * single frame or the entire image is complete. The method is 213: * also used to indicate an error in loading or producing the 214: * image. 215: */ 216: public void imageComplete(int status) 217: { 218: consumer.imageComplete(status); 219: } 220: }
GNU Classpath (0.17) |