@Override public ColorModel getColorModel(int visibleBand, int numBands) { return sampleDim.getColorModel(visibleBand, numBands); }
@Override public ColorModel getColorModel(int visibleBand, int numBands, int type) { return sampleDim.getColorModel(visibleBand, numBands, type); }
@Override public ColorModel getColorModel() { return sampleDim.getColorModel(); }
/** * Returns a color model for this sample dimension. The default implementation create a color * model with 1 band using each category's colors as returned by {@link Category#getColors}. * * <p>Note that {@link org.geotools.coverage.grid.GridCoverage2D#getSampleDimension} returns * special implementations of {@code GridSampleDimension}. In this particular case, the color * model created by this {@code getColorModel()} method will have the same number of bands than * the grid coverage's {@link java.awt.image.RenderedImage}. * * @return The requested color model, suitable for {@link java.awt.image.RenderedImage} objects * with values in the <code>{@link #getRange}</code> range. May be {@code null} if this * sample dimension has no category. */ public ColorModel getColorModel() { // The 'Grid2DSampleDimension' class overrides this method // with better values for 'band' and 'numBands' constants. final int band = 0; final int numBands = 1; return getColorModel(band, numBands); }
/** * Returns the color interpretation of the sample dimension. A sample dimension can be an index * into a color palette or be a color model component. If the sample dimension is not assigned a * color interpretation the value is {@link ColorInterpretation#UNDEFINED}. */ public ColorInterpretation getColorInterpretation() { // The 'Grid2DSampleDimension' class overrides this method // with better values for 'band' and 'numBands' constants. final int band = 0; final int numBands = 1; return TypeMap.getColorInterpretation(getColorModel(band, numBands), band); }
/** * Returns the buffered image to be wrapped by {@link GridCoverage2D}. If no image has been * {@linkplain #setBufferedImage explicitly defined}, a new one is created the first time this * method is invoked. Users can write in this image before to create the grid coverage. */ public BufferedImage getBufferedImage() { if (image == null) { final int numBands = variables.size(); if (numBands == 0) { image = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY); } else { final GridSampleDimension sd = variables.get(0).getSampleDimension(); final ColorModel cm; if (numBands == 1) { cm = sd.getColorModel(); } else { cm = sd.getColorModel(0, numBands); } final WritableRaster raster = cm.createCompatibleWritableRaster(width, height); image = new BufferedImage(cm, raster, false, null); } } return image; }
/** * Constructs a grid coverage from the specified {@linkplain WritableRaster raster} and * "{@linkplain GridGeometry2D#getGridToCoordinateSystem grid to CRS}" transform. * * @param name The grid coverage name. * @param raster The raster. * @param crs The coordinate reference system. This specifies the CRS used when accessing a grid * coverage with the {@code evaluate} methods. The number of dimensions must matches the * number of target dimensions of {@code gridToCRS}. * @param gridToCRS The math transform from grid to coordinate reference system. * @param bands Sample dimensions for each image band, or {@code null} for default sample * dimensions. If non-null, then this array's length must matches the number of bands in * {@code image}. * @return The new grid coverage. * @since 2.2 */ public GridCoverage2D create( final CharSequence name, final WritableRaster raster, final CoordinateReferenceSystem crs, final MathTransform gridToCRS, GridSampleDimension[] bands) { if (bands == null) { bands = RenderedSampleDimension.create(name, raster, null, null, null, null, null); } final ColorModel model = bands[0].getColorModel(0, bands.length, raster.getDataBuffer().getDataType()); final RenderedImage image = new BufferedImage(model, raster, false, null); return create(name, image, crs, gridToCRS, bands, null, null); }
bands[0].getColorModel(0, bands.length, raster.getDataBuffer().getDataType()); final RenderedImage image = new BufferedImage(model, raster, false, null); return create(name, image, envelope, bands, null, null);
/** * Color palette associated with the sample dimension. A color palette can have any number of * colors. See palette interpretation for meaning of the palette entries. If the grid coverage * has no color palette, {@code null} will be returned. * * @return The color palette associated with the sample dimension. * @see #getPaletteInterpretation * @see #getColorInterpretation * @see IndexColorModel * @deprecated No replacement. */ public int[][] getPalette() { final ColorModel color = getColorModel(); if (color instanceof IndexColorModel) { final IndexColorModel cm = (IndexColorModel) color; final int[][] colors = new int[cm.getMapSize()][]; for (int i = 0; i < colors.length; i++) { colors[i] = new int[] {cm.getRed(i), cm.getGreen(i), cm.getBlue(i)}; } return colors; } return null; }
/** * Returns a color model for this sample dimension. The default implementation create a color * model with 1 band using each category's colors as returned by {@link Category#getColors}. * The returned color model will typically use data type {@link DataBuffer#TYPE_FLOAT} if this * {@code GridSampleDimension} instance is "geophysics", or an integer data type otherwise. * <p> * Note that {@link org.geotools.coverage.grid.GridCoverage2D#getSampleDimension} returns * special implementations of {@code GridSampleDimension}. In this particular case, * the color model created by this {@code getColorModel()} method will have the same number of * bands than the grid coverage's {@link RenderedImage}. * * @return The requested color model, suitable for {@link RenderedImage} objects with values * in the <code>{@link #getRange}</code> range. May be {@code null} if this * sample dimension has no category. */ public ColorModel getColorModel() { // The 'Grid2DSampleDimension' class overrides this method // with better values for 'band' and 'numBands' constants. final int band = 0; final int numBands = 1; return getColorModel(band, numBands); }
/** * Returns a color model for this sample dimension. The default implementation create a color * model with 1 band using each category's colors as returned by {@link Category#getColors}. * The returned color model will typically use {@link DataBuffer#TYPE_FLOAT} if this sample * dimension is {@linkplain org.geotools.coverage.grid.ViewType#GEOPHYSICS geophysics}, or * an integer data type otherwise. * <p> * Note that {@link org.geotools.coverage.grid.GridCoverage2D#getSampleDimension} returns * special implementations of {@code GridSampleDimension}. In this particular case, * the color model created by this {@code getColorModel()} method will have the same number of * bands than the grid coverage's {@link java.awt.image.RenderedImage}. * * @return The requested color model, suitable for {@link java.awt.image.RenderedImage} objects * with values in the <code>{@link #getRange}</code> range. May be {@code null} if this * sample dimension has no category. */ public ColorModel getColorModel() { // The 'Grid2DSampleDimension' class overrides this method // with better values for 'band' and 'numBands' constants. final int band = 0; final int numBands = 1; return getColorModel(band, numBands); }
name, raster, minValues, maxValues, units, colors, hints); final ColorModel model = bands[0].getColorModel(0, bands.length, raster.getSampleModel().getDataType()); final RenderedImage image = new BufferedImage(model, raster, false, null); return create(name, image, envelope, bands, null, null); name, raster, minValues, maxValues, units, colors, hints); final ColorModel model = bands[0].getColorModel(0, bands.length, raster.getDataBuffer().getDataType()); final RenderedImage image = new BufferedImage(model, raster, false, null); return create(name, image, crs, gridToCRS, bands, null, null);
GridSampleDimension.wrap(getSampleDimension(VISIBLE_BAND)); final ColorModel colorModel = band.getColorModel(VISIBLE_BAND, getNumSampleDimensions()); final SampleModel sampleModel = colorModel.createCompatibleSampleModel(tileSize.width, tileSize.height);
colors = sampleDims[visibleBand].getColorModel(visibleBand, sampleDims.length); if (colors != null) { if (layout == null) {
/** * Returns the color interpretation of the sample dimension. * A sample dimension can be an index into a color palette or be a color model * component. If the sample dimension is not assigned a color interpretation * the value is {@link ColorInterpretation#UNDEFINED}. * */ public ColorInterpretation getColorInterpretation() { // The 'Grid2DSampleDimension' class overrides this method // with better values for 'band' and 'numBands' constants. final int band = 0; final int numBands = 1; return TypeMap.getColorInterpretation(getColorModel(band, numBands), band); }
/** * Returns the color interpretation of the sample dimension. * A sample dimension can be an index into a color palette or be a color model * component. If the sample dimension is not assigned a color interpretation * the value is {@link ColorInterpretation#UNDEFINED}. * * @deprecated No replacement. */ public ColorInterpretation getColorInterpretation() { // The 'Grid2DSampleDimension' class overrides this method // with better values for 'band' and 'numBands' constants. final int band = 0; final int numBands = 1; return TypeMap.getColorInterpretation(getColorModel(band, numBands), band); }
/** * Returns the buffered image to be wrapped by {@link GridCoverage2D}. If no image has been * {@linkplain #setBufferedImage explicitly defined}, a new one is created the first time * this method is invoked. Users can write in this image before to create the grid coverage. */ public BufferedImage getBufferedImage() { if (image == null) { final int numBands = variables.size(); if (numBands == 0) { image = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY); } else { final GridSampleDimension sd = variables.get(0).getSampleDimension(); final ColorModel cm; if (numBands == 1) { cm = sd.getColorModel(); } else { cm = sd.getColorModel(0, numBands); } final WritableRaster raster = cm.createCompatibleWritableRaster(width, height); image = new BufferedImage(cm, raster, false, null); } } return image; }
(i == visibleBand) ? image.getColorModel() : band.getColorModel(); if (!(candidate instanceof IndexColorModel)) {
} else { colors = targetBands[visibleTargetBand].getColorModel( visibleTargetBand, targetBands.length);
/** * Color palette associated with the sample dimension. A color palette can have any number of * colors. See palette interpretation for meaning of the palette entries. If the grid coverage * has no color palette, {@code null} will be returned. * * @return The color palette associated with the sample dimension. * * @see #getPaletteInterpretation * @see #getColorInterpretation * @see IndexColorModel * * @deprecated No replacement. */ public int[][] getPalette() { final ColorModel color = getColorModel(); if (color instanceof IndexColorModel) { final IndexColorModel cm = (IndexColorModel) color; final int[][] colors = new int[cm.getMapSize()][]; for (int i=0; i<colors.length; i++) { colors[i] = new int[] {cm.getRed(i), cm.getGreen(i), cm.getBlue(i)}; } return colors; } return null; }