001: /*
002: * @(#) $Header: /cvs/jai-operators/src/main/ca/forklabs/media/jai/opimage/UnaryFunctionCRIF.java,v 1.3 2007/08/16 21:24:56 forklabs Exp $
003: *
004: * Copyright (C) 2007 Forklabs Daniel Léonard
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License
008: * as published by the Free Software Foundation; either version 2
009: * of the License, or (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
019: */
020:
021: package ca.forklabs.media.jai.opimage;
022:
023: import java.awt.RenderingHints;
024: import java.awt.image.RenderedImage;
025: import java.awt.image.renderable.ContextualRenderedImageFactory;
026: import java.awt.image.renderable.ParameterBlock;
027: import javax.media.jai.ImageLayout;
028: import ca.forklabs.baselib.util.UnaryFunction;
029: import ca.forklabs.media.jai.operator.UnaryFunctionDescriptor;
030:
031: /**
032: * Class {@code UnaryFunctionCRIF} is a {@link ContextualRenderedImageFactory}
033: * supporting the <em>unaryfunction</em> operation in the rendered and
034: * renderable image layers.
035: *
036: * @author <a href="mailto:forklabs at dev.java.net?subject=ca.forklabs.media.jai.opimage.UnaryFunctionCRIF">Daniel Léonard</a>
037: * @version $Revision: 1.3 $
038: * @see UnaryFunctionOpImage
039: */
040: public class UnaryFunctionCRIF extends AbstractCRIF {
041:
042: //---------------------------
043: // Constructor
044: //---------------------------
045:
046: /**
047: * Constructor.
048: */
049: public UnaryFunctionCRIF() {
050: super (UnaryFunctionDescriptor.NAME);
051: }
052:
053: //---------------------------
054: // Instance methods
055: //---------------------------
056:
057: /**
058: * Gets the function.
059: * @param pb the parameter block.
060: * @return the function.
061: */
062: @SuppressWarnings("unchecked")
063: protected UnaryFunction<Double, Double> getFunction(
064: ParameterBlock pb) {
065: int index = UnaryFunctionDescriptor.FUNCTION_PARAMETER_INDEX;
066: UnaryFunction<Double, Double> function = (UnaryFunction<Double, Double>) pb
067: .getObjectParameter(index);
068: return function;
069: }
070:
071: //---------------------------
072: // Implemented methods from javax.media.jai.CRIFImpl
073: //---------------------------
074:
075: /**
076: * Creates a new instance of {@link UnaryFunctionOpImage} in the rendered
077: * layer.
078: * @param pb the parameter block.
079: * @param hints optional rendering hints.
080: */
081: @Override
082: @SuppressWarnings("unchecked")
083: public RenderedImage create(ParameterBlock pb, RenderingHints hints) {
084: RenderedImage source = pb.getRenderedSource(0);
085: UnaryFunction<Double, Double> function = this .getFunction(pb);
086: ImageLayout layout = this .getImageLayout(hints);
087: RenderedImage sink = new UnaryFunctionOpImage(source, function,
088: layout, hints);
089: return sink;
090: }
091: // TODO : is the create method for renderable necessary ?
092:
093: }
094:
095: /*
096: * $Log: UnaryFunctionCRIF.java,v $
097: * Revision 1.3 2007/08/16 21:24:56 forklabs
098: * Added a getter for a parameter in the ParameterBlock.
099: *
100: * Revision 1.2 2007/07/05 18:26:21 forklabs
101: * Added a note about the necessity of a method.
102: *
103: * Revision 1.1 2007/05/03 18:32:28 forklabs
104: * Initial commit for the unaryfunction operator.
105: *
106: */
|