/* * Geotools 2 - OpenSource mapping toolkit * (C) 2003, Geotools Project Management Committee (PMC) * (C) 2003, Institut de Recherche pour le Développement * * 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; either * version 2.1 of the License, or (at your option) any later version. * * 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. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * * Contacts: * UNITED KINGDOM: James Macgill * mailto:j.macgill@geog.leeds.ac.uk * * FRANCE: Surveillance de l'Environnement Assistée par Satellite * Institut de Recherche pour le Développement / US-Espace * mailto:seasnet@teledetection.fr * * CANADA: Observatoire du Saint-Laurent * Institut Maurice-Lamontagne * mailto:osl@osl.gc.ca */ package org.geotools.gp; // J2SE dependencies import java.awt.RenderingHints; import java.awt.image.ColorModel; import java.awt.image.IndexColorModel; import java.awt.image.RenderedImage; import java.awt.image.renderable.ParameterBlock; import javax.media.jai.ImageLayout; import javax.media.jai.JAI; import javax.media.jai.ParameterList; import javax.media.jai.ParameterListDescriptor; import javax.media.jai.ParameterListDescriptorImpl; import javax.media.jai.WritablePropertySource; import org.geotools.cv.SampleDimension; import org.geotools.gc.GridCoverage; import org.geotools.resources.LegacyGCSUtilities; import org.geotools.resources.image.ColorUtilities; /** * A grid coverage containing a subset of an other GridCoverage's sample dimensions, * and/or a different {@link ColorModel}. A common reason why we want to change the * color model is to select a different visible band. Consequently, the "SelectSampleDimension" * name still appropriate in this context. * * @source $URL$ * @version $Id$ * @author Martin Desruisseaux * * @deprecated Replaced by {@link org.geotools.coverage.operation.BandSelector2D}. */ final class SelectSampleDimension extends GridCoverage { /** * The mapping to bands in the source grid coverage. * May be null if all bands were keeped. */ private final int[] bandIndices; /** * Construct a new SelectSampleDimension grid coverage. This grid coverage will * use the same coordinate system and the same geometry than the source grid coverage. * * @param source The source coverage. * @param image The image to use. * @param bands The sample dimensions to use. * @param bandIndices The mapping to bands in source. Not used * by this constructor, but keeped for futur reference. * * @task HACK: It would be nice if we could use always the "BandSelect" operation * without the "Null" one. But as of JAI-1.1.1, "BandSelect" is not * wise enough to detect the case were no copy is required. */ private SelectSampleDimension(final GridCoverage source, final RenderedImage image, final SampleDimension[] bands, final int[] bandIndices) { super(source.getName(null), // The grid source name image, // The underlying data source.getCoordinateSystem(), // The coordinate system. source.getGridGeometry().getGridToCoordinateSystem(), bands, // The sample dimensions new GridCoverage[]{source}, // The source grid coverages. null); // Properties this.bandIndices = bandIndices; assert bandIndices==null || bandIndices.length==bands.length; } /** * Apply the band select operation to a grid coverage. * * @param parameters List of name value pairs for the parameters. * @param A set of rendering hints, or null if none. * @return The result as a grid coverage. */ static GridCoverage create(final ParameterList parameters, RenderingHints hints) { RenderedImage image; GridCoverage source = (GridCoverage)parameters.getObjectParameter("Source"); int[] bandIndices = (int[]) parameters.getObjectParameter("SampleDimensions"); Integer visibleBand = (Integer) parameters.getObjectParameter("VisibleSampleDimension"); int visibleSourceBand; int visibleTargetBand; SampleDimension[] sourceBands; SampleDimension[] targetBands; if (bandIndices != null) { bandIndices = (int[]) bandIndices.clone(); } do { sourceBands = source.getSampleDimensions(); targetBands = sourceBands; /* * Construct an array of target bands. If the 'bandIndices' parameter contains * only "identity" indices (0, 1, 2...), then we will work as if no band indices * were provided. It will allow us to use the "Null" operation rather than * "BandSelect", which make it possible to avoid to copy raster data. */ if (bandIndices != null) { if (bandIndices.length!=sourceBands.length || !isIdentity(bandIndices)) { targetBands = new SampleDimension[bandIndices.length]; for (int i=0; itrue if the specified array contains increasing values 0, 1, 2... */ private static boolean isIdentity(final int[] bands) { for (int i=0; inull if none. * @return The result as a grid coverage. */ protected GridCoverage doOperation(final ParameterList parameters, RenderingHints hints) { return SelectSampleDimension.create(parameters, hints); } } }