001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2006, Geotools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or (at your option) any later version.
010: *
011: * This library 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 GNU
014: * Lesser General Public License for more details.
015: */
016: package org.geotools.coverage.processing.operation;
017:
018: // J2SE and JAI dependencies
019: import java.awt.Color;
020: import java.util.Collections;
021: import java.util.Map;
022: import javax.media.jai.util.Range;
023:
024: // OpenGIS dependencies
025: import org.opengis.coverage.Coverage;
026: import org.opengis.coverage.grid.GridCoverage;
027: import org.opengis.parameter.ParameterDescriptor;
028: import org.opengis.parameter.ParameterValueGroup;
029: import org.opengis.util.InternationalString;
030:
031: // Geotools dependencies
032: import org.geotools.coverage.Category;
033: import org.geotools.coverage.GridSampleDimension;
034: import org.geotools.coverage.processing.ColorMap;
035: import org.geotools.coverage.processing.AbstractProcessor;
036: import org.geotools.factory.Hints;
037: import org.geotools.metadata.iso.citation.Citations;
038: import org.geotools.parameter.DefaultParameterDescriptor;
039: import org.geotools.parameter.DefaultParameterDescriptorGroup;
040: import org.geotools.resources.image.ColorUtilities;
041:
042: /**
043: * Operation replacing the colors of a {@link GridCoverage}. This operation accepts
044: * one argument, {@code ColorMaps}, which must be an instance of {@link ColorMap}.
045: *
046: * @since 2.3
047: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/coverage/src/main/java/org/geotools/coverage/processing/operation/Recolor.java $
048: * @version $Id: Recolor.java 26601 2007-08-19 23:16:35Z desruisseaux $
049: * @author Martin Desruisseaux
050: *
051: * @todo For compatibility with Geotools 2.3, this operator temporarily accepts an array of
052: * {@link Map} objects, where keys are category names as {@link String} and values are
053: * colors as {@code Color[]}. The {@code null} key is a special value meaning "any
054: * quantitative category". A future Geotools version may not accept {@link Map} anymore.
055: */
056: public final class Recolor extends IndexColorOperation {
057: /**
058: * The parameter descriptor for the color map.
059: */
060: public static final ParameterDescriptor COLOR_MAPS = new DefaultParameterDescriptor(
061: Citations.GEOTOOLS, "ColorMaps", Object[].class, // Value class (mandatory): TODO: change to ColorMap[]
062: null, // Array of valid values
063: new ColorMap[] { // Default value - a gray scale
064: new ColorMap(new Color[] { new Color(16, 16, 16),
065: new Color(240, 240, 240) }) }, null, // Minimal value
066: null, // Maximal value
067: null, // Unit of measure
068: true); // Parameter is mandatory
069:
070: /**
071: * Constructs a new "Recolor" operation.
072: */
073: public Recolor() {
074: super (new DefaultParameterDescriptorGroup(Citations.GEOTOOLS,
075: "Recolor", new ParameterDescriptor[] { SOURCE_0,
076: COLOR_MAPS }));
077: }
078:
079: /**
080: * Transforms the supplied RGB colors.
081: *
082: * @see ColorMap#recolor
083: */
084: protected GridSampleDimension transformColormap(final int[] ARGB,
085: final int band, final GridSampleDimension sampleDimension,
086: final ParameterValueGroup parameters) {
087: final Object[] colorMaps = (Object[]) parameters.parameter(
088: "ColorMaps").getValue();
089: if (colorMaps == null || colorMaps.length == 0) {
090: return sampleDimension;
091: }
092: Object colorMap = colorMaps[Math
093: .min(band, colorMaps.length - 1)];
094: if (colorMap instanceof Map) {
095: AbstractProcessor.LOGGER
096: .warning("\"ColorMaps\" parameter of type java.util.Map[] is deprecated. "
097: + "Please use the org.geotools.coverage.processing.ColorMap type instead.");
098: colorMap = new ColorMap((Map) colorMap);
099: }
100: return ((ColorMap) colorMap).recolor(sampleDimension, ARGB);
101: }
102: }
|