/* * GeoTools - The Open Source Java GIS Toolkit * http://geotools.org * * (C) 2006-2008, Open Source Geospatial Foundation (OSGeo) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. */ package org.geotools.coverage.processing.operation; import java.awt.image.ColorModel; import java.awt.image.IndexColorModel; import java.awt.image.RenderedImage; import javax.media.jai.ImageLayout; import javax.media.jai.NullOpImage; import javax.media.jai.OpImage; import org.opengis.coverage.Coverage; import org.opengis.coverage.SampleDimension; import org.opengis.coverage.grid.GridCoverage; import org.opengis.parameter.ParameterValueGroup; import org.geotools.factory.Hints; import org.geotools.coverage.CoverageFactoryFinder; import org.geotools.coverage.GridSampleDimension; import org.geotools.coverage.grid.GridCoverage2D; import org.geotools.coverage.grid.ViewType; import org.geotools.coverage.processing.Operation2D; import org.geotools.parameter.DefaultParameterDescriptorGroup; import org.geotools.resources.coverage.CoverageUtilities; import org.geotools.resources.image.ColorUtilities; import org.geotools.resources.Classes; import org.geotools.resources.i18n.ErrorKeys; import org.geotools.resources.i18n.Errors; /** * Operation applied only on image's colors. This operation work only for source * image using an {@link IndexColorModel}. * * @source $URL$ * @version $Id$ * @author Martin Desruisseaux * * @todo Consider moving this class to the {@link org.geotools.coverage.processing} package. */ abstract class IndexColorOperation extends Operation2D { /** * Constructs an operation. */ public IndexColorOperation(final DefaultParameterDescriptorGroup descriptor) { super(descriptor); } /** * Performs the color transformation. This method invokes the * {@link #transformColormap transformColormap(...)} method with current RGB * colormap, the source {@link SampleDimension} and the supplied parameters. * * @param parameters The parameters. * @param hints Rendering hints (ignored in this implementation). * * @throws IllegalArgumentException if the candidate image do not use an * {@link IndexColorModel}. */ public Coverage doOperation(final ParameterValueGroup parameters, final Hints hints) { final GridCoverage2D source = (GridCoverage2D) parameters.parameter("Source").getValue(); final GridCoverage2D visual = source.view(ViewType.RENDERED); final RenderedImage image = visual.getRenderedImage(); final GridSampleDimension[] bands = visual.getSampleDimensions(); final int visibleBand = CoverageUtilities.getVisibleBand(image); ColorModel model = image.getColorModel(); boolean colorChanged = false; for (int i=0; i