2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libjava / java / awt / image / ImageFilter.java
blobf58e5381df63abd779ffab661904fa6cad088cc5
1 /* ImageFilter.java -- Java class for filtering images
2 Copyright (C) 1999 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA.
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.
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. */
39 package java.awt.image;
41 import java.util.Hashtable;
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.
48 * @author C. Brian Jones (cbj@gnu.org)
50 public class ImageFilter implements ImageConsumer, Cloneable
52 /**
53 * The consumer this filter is filtering an image data stream for.
54 * It is initialized in the method <code>getFilterInstance</code>.
56 protected ImageConsumer consumer = null;
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>
73 public void resendTopDownLeftRight(ImageProducer ip)
75 ip.requestTopDownLeftRightResend(this);
78 /**
79 * By default, returns a shallow copy of the object created by
80 * <code>Object.clone()</code>
82 * @see java.lang.Object#clone ()
84 public Object clone()
86 try
88 return super.clone();
90 catch (CloneNotSupportedException e)
92 // This should never happen as this class implements the
93 // Cloneable interface.
94 throw new InternalError ();
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.
103 * @see #clone ()
105 public ImageFilter getFilterInstance(ImageConsumer ic)
107 if ( ic == null )
108 throw new IllegalArgumentException("null argument for ImageFilter.getFilterInstance(ImageConsumer)");
110 consumer = ic;
111 ImageFilter f = (ImageFilter)clone();
112 consumer = null;
113 return f;
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.
123 * @param width the width of the image
124 * @param height the height of the image
126 public void setDimensions(int width, int height)
128 consumer.setDimensions(width, height);
132 * An <code>ImageProducer</code> can set a list of properties
133 * associated with this image by using this method.
135 * @param props the list of properties associated with this image
137 public void setProperties(Hashtable props)
139 props.put("filters", "ImageFilter");
140 consumer.setProperties(props);
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>.
148 * @param model the color model to be used most often by setPixels
149 * @see ColorModel */
150 public void setColorModel(ColorModel model)
152 consumer.setColorModel(model);
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.
162 * @param flags a bit mask of hints
163 * @see ImageConsumer
165 public void setHints(int flags)
167 consumer.setHints(flags);
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).
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
184 public void setPixels(int x, int y, int w, int h,
185 ColorModel model, byte[] pixels, int offset, int scansize)
187 consumer.setPixels(x, y, w, h, model, pixels, offset, scansize);
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).
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
204 public void setPixels(int x, int y, int w, int h,
205 ColorModel model, int[] pixels, int offset, int scansize)
207 consumer.setPixels(x, y, w, h, model, pixels, offset, scansize);
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.
216 public void imageComplete(int status)
218 consumer.imageComplete(status);