001/*
002 * $Id: AbstractFilter.java 3863 2010-10-26 02:53:32Z kschaefe $
003 *
004 * Dual-licensed under LGPL (Sun and Romain Guy) and BSD (Romain Guy).
005 *
006 * Copyright 2005 Sun Microsystems, Inc., 4150 Network Circle,
007 * Santa Clara, California 95054, U.S.A. All rights reserved.
008 *
009 * Copyright (c) 2006 Romain Guy <romain.guy@mac.com>
010 * All rights reserved.
011 *
012 * Redistribution and use in source and binary forms, with or without
013 * modification, are permitted provided that the following conditions
014 * are met:
015 * 1. Redistributions of source code must retain the above copyright
016 *    notice, this list of conditions and the following disclaimer.
017 * 2. Redistributions in binary form must reproduce the above copyright
018 *    notice, this list of conditions and the following disclaimer in the
019 *    documentation and/or other materials provided with the distribution.
020 * 3. The name of the author may not be used to endorse or promote products
021 *    derived from this software without specific prior written permission.
022 *
023 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
024 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
025 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
026 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
027 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
028 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
029 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
030 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
031 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
032 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
033 */
034
035package org.jdesktop.swingx.image;
036
037import java.awt.Rectangle;
038import java.awt.RenderingHints;
039import java.awt.geom.Point2D;
040import java.awt.geom.Rectangle2D;
041import java.awt.image.BufferedImage;
042import java.awt.image.BufferedImageOp;
043import java.awt.image.ColorModel;
044
045import org.jdesktop.beans.AbstractBean;
046
047/**
048 * <p>Provides an abstract implementation of the <code>BufferedImageOp</code>
049 * interface. This class can be used to created new image filters based
050 * on <code>BufferedImageOp</code>.</p>
051 *
052 * @author Romain Guy <romain.guy@mac.com>
053 */
054
055public abstract class AbstractFilter extends AbstractBean implements BufferedImageOp {
056    @Override
057    public abstract BufferedImage filter(BufferedImage src, BufferedImage dest);
058
059    /**
060     * {@inheritDoc}
061     */
062    @Override
063    public Rectangle2D getBounds2D(BufferedImage src) {
064        return new Rectangle(0, 0, src.getWidth(), src.getHeight());
065    }
066
067    /**
068     * {@inheritDoc}
069     */
070    @Override
071    public BufferedImage createCompatibleDestImage(BufferedImage src,
072                                                   ColorModel destCM) {
073        if (destCM == null) {
074            destCM = src.getColorModel();
075        }
076
077        return new BufferedImage(destCM,
078                                 destCM.createCompatibleWritableRaster(
079                                         src.getWidth(), src.getHeight()),
080                                 destCM.isAlphaPremultiplied(), null);
081    }
082
083    /**
084     * {@inheritDoc}
085     */
086    @Override
087    public Point2D getPoint2D(Point2D srcPt, Point2D dstPt) {
088        return (Point2D) srcPt.clone();
089    }
090
091    /**
092     * {@inheritDoc}
093     */
094    @Override
095    public RenderingHints getRenderingHints() {
096        return null;
097    }
098}