001: /*
002: * @(#) $Header: /cvs/jai-operators/src/main/ca/forklabs/media/jai/opimage/SpectralHomomorphicCRIF.java,v 1.2 2007/07/17 16:42:46 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.CollectionImage;
028: import ca.forklabs.media.jai.operator.PipelineDescriptor;
029: import ca.forklabs.media.jai.operator.SpectralFilterDescriptor;
030: import ca.forklabs.media.jai.FormatDataType;
031: import ca.forklabs.media.jai.ParameterBlockUtil;
032: import ca.forklabs.media.jai.SpectralFilter2D;
033: import ca.forklabs.media.jai.operator.SpectralHomomorphicDescriptor;
034:
035: /**
036: * Class {@code SpectralHomomorphicCRIF} is a
037: * {@link ContextualRenderedImageFactory} supporting the
038: * <em>spectralhomomorphic</em> operation in the rendered and renderable image
039: * layers.
040: *
041: * @author <a href="mailto:forklabs at dev.java.net?subject=ca.forklabs.media.jai.operator.SpectralHomomorphicCRIF">Daniel Léonard</a>
042: * @version $Revision: 1.2 $
043: */
044: public class SpectralHomomorphicCRIF extends AbstractCRIF {
045:
046: //---------------------------
047: // Constructor
048: //---------------------------
049:
050: /**
051: * Constructor.
052: */
053: public SpectralHomomorphicCRIF() {
054: super (SpectralHomomorphicDescriptor.NAME);
055: }
056:
057: //---------------------------
058: // Instance methods
059: //---------------------------
060:
061: /**
062: * Gets the spectral filter.
063: * @param pb the parameter block.
064: * @return the spectral filter.
065: */
066: protected SpectralFilter2D getFilter(ParameterBlock pb) {
067: int index = SpectralHomomorphicDescriptor.FILTER_PARAMETER_INDEX;
068: SpectralFilter2D filter = (SpectralFilter2D) pb
069: .getObjectParameter(index);
070: return filter;
071: }
072:
073: /**
074: * Gets the type for the format operation.
075: * @param pb the parameter block.
076: * @return type for the format operation.
077: */
078: protected FormatDataType getDataType(ParameterBlock pb) {
079: int index = SpectralHomomorphicDescriptor.TYPE_PARAMETER_INDEX;
080: FormatDataType type = (FormatDataType) pb
081: .getObjectParameter(index);
082: return type;
083: }
084:
085: //---------------------------
086: // Implemented methods from javax.media.jai.CRIFImpl
087: //---------------------------
088:
089: /**
090: * Enhance the image.
091: * @param pb the parameter block.
092: * @param hints optional rendering hints.
093: */
094: @Override
095: @SuppressWarnings("nls")
096: public RenderedImage create(ParameterBlock pb, RenderingHints hints) {
097: CollectionImage sources = (CollectionImage) pb.getSource(0);
098: RenderedImage source = (RenderedImage) sources.get(0);
099:
100: SpectralFilter2D filter = this .getFilter(pb);
101: FormatDataType type = this .getDataType(pb);
102:
103: String[] operations = new String[] { "format", "addconst",
104: "log", SpectralFilterDescriptor.NAME, "exp",
105: "subtractconst", };
106:
107: ParameterBlock[] pbs = new ParameterBlock[] {
108: ParameterBlockUtil.createFormatParameterBlock(null,
109: type),
110: ParameterBlockUtil.createAddConstParameterBlock(null,
111: new double[] { 1.0, }),
112: ParameterBlockUtil.createLogParameterBlock(null),
113: new ParameterBlock().add(filter).add(type),
114: ParameterBlockUtil.createExpParameterBlock(null),
115: ParameterBlockUtil.createSubtractConstParameterBlock(
116: null, new double[] { 1.0, }), };
117: RenderedImage sink = PipelineDescriptor.create(source,
118: operations, pbs, hints);
119: return sink;
120: }
121:
122: // TODO : is the create method for renderable necessary ?
123:
124: }
125:
126: /*
127: * $Log: SpectralHomomorphicCRIF.java,v $
128: * Revision 1.2 2007/07/17 16:42:46 forklabs
129: * Now uses operator spectralfilter.
130: *
131: * Revision 1.1 2007/07/05 18:31:30 forklabs
132: * Operator spectralhomomorphic.
133: *
134: */
|