0N/A/*
2362N/A * Copyright (c) 1995, 2004, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage java.awt.image;
0N/A
0N/Aimport java.util.Hashtable;
0N/A
0N/A/**
0N/A * This class implements a filter for the set of interface methods that
0N/A * are used to deliver data from an ImageProducer to an ImageConsumer.
0N/A * It is meant to be used in conjunction with a FilteredImageSource
0N/A * object to produce filtered versions of existing images. It is a
0N/A * base class that provides the calls needed to implement a "Null filter"
0N/A * which has no effect on the data being passed through. Filters should
0N/A * subclass this class and override the methods which deal with the
0N/A * data that needs to be filtered and modify it as necessary.
0N/A *
0N/A * @see FilteredImageSource
0N/A * @see ImageConsumer
0N/A *
0N/A * @author Jim Graham
0N/A */
0N/Apublic class ImageFilter implements ImageConsumer, Cloneable {
0N/A /**
0N/A * The consumer of the particular image data stream for which this
0N/A * instance of the ImageFilter is filtering data. It is not
0N/A * initialized during the constructor, but rather during the
0N/A * getFilterInstance() method call when the FilteredImageSource
0N/A * is creating a unique instance of this object for a particular
0N/A * image data stream.
0N/A * @see #getFilterInstance
0N/A * @see ImageConsumer
0N/A */
0N/A protected ImageConsumer consumer;
0N/A
0N/A /**
0N/A * Returns a unique instance of an ImageFilter object which will
0N/A * actually perform the filtering for the specified ImageConsumer.
0N/A * The default implementation just clones this object.
0N/A * <p>
0N/A * Note: This method is intended to be called by the ImageProducer
0N/A * of the Image whose pixels are being filtered. Developers using
0N/A * this class to filter pixels from an image should avoid calling
0N/A * this method directly since that operation could interfere
0N/A * with the filtering operation.
0N/A * @param ic the specified <code>ImageConsumer</code>
0N/A * @return an <code>ImageFilter</code> used to perform the
0N/A * filtering for the specified <code>ImageConsumer</code>.
0N/A */
0N/A public ImageFilter getFilterInstance(ImageConsumer ic) {
0N/A ImageFilter instance = (ImageFilter) clone();
0N/A instance.consumer = ic;
0N/A return instance;
0N/A }
0N/A
0N/A /**
0N/A * Filters the information provided in the setDimensions method
0N/A * of the ImageConsumer interface.
0N/A * <p>
0N/A * Note: This method is intended to be called by the ImageProducer
0N/A * of the Image whose pixels are being filtered. Developers using
0N/A * this class to filter pixels from an image should avoid calling
0N/A * this method directly since that operation could interfere
0N/A * with the filtering operation.
0N/A * @see ImageConsumer#setDimensions
0N/A */
0N/A public void setDimensions(int width, int height) {
0N/A consumer.setDimensions(width, height);
0N/A }
0N/A
0N/A /**
0N/A * Passes the properties from the source object along after adding a
0N/A * property indicating the stream of filters it has been run through.
0N/A * <p>
0N/A * Note: This method is intended to be called by the ImageProducer
0N/A * of the Image whose pixels are being filtered. Developers using
0N/A * this class to filter pixels from an image should avoid calling
0N/A * this method directly since that operation could interfere
0N/A * with the filtering operation.
0N/A *
0N/A * @param props the properties from the source object
0N/A * @exception NullPointerException if <code>props</code> is null
0N/A */
0N/A public void setProperties(Hashtable<?,?> props) {
0N/A Hashtable<Object,Object> p = (Hashtable<Object,Object>)props.clone();
0N/A Object o = p.get("filters");
0N/A if (o == null) {
0N/A p.put("filters", toString());
0N/A } else if (o instanceof String) {
0N/A p.put("filters", ((String) o)+toString());
0N/A }
0N/A consumer.setProperties(p);
0N/A }
0N/A
0N/A /**
0N/A * Filter the information provided in the setColorModel method
0N/A * of the ImageConsumer interface.
0N/A * <p>
0N/A * Note: This method is intended to be called by the ImageProducer
0N/A * of the Image whose pixels are being filtered. Developers using
0N/A * this class to filter pixels from an image should avoid calling
0N/A * this method directly since that operation could interfere
0N/A * with the filtering operation.
0N/A * @see ImageConsumer#setColorModel
0N/A */
0N/A public void setColorModel(ColorModel model) {
0N/A consumer.setColorModel(model);
0N/A }
0N/A
0N/A /**
0N/A * Filters the information provided in the setHints method
0N/A * of the ImageConsumer interface.
0N/A * <p>
0N/A * Note: This method is intended to be called by the ImageProducer
0N/A * of the Image whose pixels are being filtered. Developers using
0N/A * this class to filter pixels from an image should avoid calling
0N/A * this method directly since that operation could interfere
0N/A * with the filtering operation.
0N/A * @see ImageConsumer#setHints
0N/A */
0N/A public void setHints(int hints) {
0N/A consumer.setHints(hints);
0N/A }
0N/A
0N/A /**
0N/A * Filters the information provided in the setPixels method of the
0N/A * ImageConsumer interface which takes an array of bytes.
0N/A * <p>
0N/A * Note: This method is intended to be called by the ImageProducer
0N/A * of the Image whose pixels are being filtered. Developers using
0N/A * this class to filter pixels from an image should avoid calling
0N/A * this method directly since that operation could interfere
0N/A * with the filtering operation.
0N/A * @see ImageConsumer#setPixels
0N/A */
0N/A public void setPixels(int x, int y, int w, int h,
0N/A ColorModel model, byte pixels[], int off,
0N/A int scansize) {
0N/A consumer.setPixels(x, y, w, h, model, pixels, off, scansize);
0N/A }
0N/A
0N/A /**
0N/A * Filters the information provided in the setPixels method of the
0N/A * ImageConsumer interface which takes an array of integers.
0N/A * <p>
0N/A * Note: This method is intended to be called by the ImageProducer
0N/A * of the Image whose pixels are being filtered. Developers using
0N/A * this class to filter pixels from an image should avoid calling
0N/A * this method directly since that operation could interfere
0N/A * with the filtering operation.
0N/A * @see ImageConsumer#setPixels
0N/A */
0N/A public void setPixels(int x, int y, int w, int h,
0N/A ColorModel model, int pixels[], int off,
0N/A int scansize) {
0N/A consumer.setPixels(x, y, w, h, model, pixels, off, scansize);
0N/A }
0N/A
0N/A /**
0N/A * Filters the information provided in the imageComplete method of
0N/A * the ImageConsumer interface.
0N/A * <p>
0N/A * Note: This method is intended to be called by the ImageProducer
0N/A * of the Image whose pixels are being filtered. Developers using
0N/A * this class to filter pixels from an image should avoid calling
0N/A * this method directly since that operation could interfere
0N/A * with the filtering operation.
0N/A * @see ImageConsumer#imageComplete
0N/A */
0N/A public void imageComplete(int status) {
0N/A consumer.imageComplete(status);
0N/A }
0N/A
0N/A /**
0N/A * Responds to a request for a TopDownLeftRight (TDLR) ordered resend
0N/A * of the pixel data from an <code>ImageConsumer</code>.
0N/A * When an <code>ImageConsumer</code> being fed
0N/A * by an instance of this <code>ImageFilter</code>
0N/A * requests a resend of the data in TDLR order,
0N/A * the <code>FilteredImageSource</code>
0N/A * invokes this method of the <code>ImageFilter</code>.
0N/A *
0N/A * <p>
0N/A *
0N/A * An <code>ImageFilter</code> subclass might override this method or not,
0N/A * depending on if and how it can send data in TDLR order.
0N/A * Three possibilities exist:
0N/A *
0N/A * <ul>
0N/A * <li>
0N/A * Do not override this method.
0N/A * This makes the subclass use the default implementation,
0N/A * which is to
0N/A * forward the request
0N/A * to the indicated <code>ImageProducer</code>
0N/A * using this filter as the requesting <code>ImageConsumer</code>.
0N/A * This behavior
0N/A * is appropriate if the filter can determine
0N/A * that it will forward the pixels
0N/A * in TDLR order if its upstream producer object
0N/A * sends them in TDLR order.
0N/A *
0N/A * <li>
0N/A * Override the method to simply send the data.
0N/A * This is appropriate if the filter can handle the request itself &#151;
0N/A * for example,
0N/A * if the generated pixels have been saved in some sort of buffer.
0N/A *
0N/A * <li>
0N/A * Override the method to do nothing.
0N/A * This is appropriate
0N/A * if the filter cannot produce filtered data in TDLR order.
0N/A * </ul>
0N/A *
0N/A * @see ImageProducer#requestTopDownLeftRightResend
0N/A * @param ip the ImageProducer that is feeding this instance of
0N/A * the filter - also the ImageProducer that the request should be
0N/A * forwarded to if necessary
0N/A * @exception NullPointerException if <code>ip</code> is null
0N/A */
0N/A public void resendTopDownLeftRight(ImageProducer ip) {
0N/A ip.requestTopDownLeftRightResend(this);
0N/A }
0N/A
0N/A /**
0N/A * Clones this object.
0N/A */
0N/A public Object clone() {
0N/A try {
0N/A return super.clone();
0N/A } catch (CloneNotSupportedException e) {
0N/A // this shouldn't happen, since we are Cloneable
0N/A throw new InternalError();
0N/A }
0N/A }
0N/A}