ImageManager { public static Color[] createColorPalette(ImageInfo imageInfo) { Debug.assertNotNull(imageInfo); final boolean logScaled = imageInfo.isLogScaled(); final ColorPaletteDef cpd = imageInfo.getColorPaletteDef(); Debug.assertNotNull(cpd); Debug.assertTrue(cpd.getNumPoints() >= 2); final double minSample; final double maxSample; if (logScaled) { minSample = getSampleLog(cpd.getFirstPoint()); maxSample = getSampleLog(cpd.getLastPoint()); } else { minSample = getSample(cpd.getFirstPoint()); maxSample = getSample(cpd.getLastPoint()); } final int numColors = cpd.getNumColors(); final double scalingFactor = 1 / (numColors - 1.0); final Color[] colorPalette = new Color[numColors]; int pointIndex = 0; final int maxPointIndex = cpd.getNumPoints() - 2; BorderSamplesAndColors boSaCo = getBorderSamplesAndColors(imageInfo, pointIndex, null); for (int i = 0; i < numColors - 1; i++) { final double w = i * scalingFactor; final double sample = minSample + w * (maxSample - minSample); if (sample >= boSaCo.sample2) { pointIndex++; pointIndex = Math.min(pointIndex, maxPointIndex); boSaCo = getBorderSamplesAndColors(imageInfo, pointIndex, boSaCo); } if (cpd.isDiscrete()) { colorPalette[i] = boSaCo.color1; } else { colorPalette[i] = computeColor(sample, boSaCo); } } colorPalette[numColors - 1] = boSaCo.color2; return colorPalette; } ImageManager(); static ImageManager getInstance(); synchronized void dispose(); static MultiLevelModel getMultiLevelModel(RasterDataNode rasterDataNode); static AffineTransform getImageToModelTransform(GeoCoding geoCoding); static CoordinateReferenceSystem getModelCrs(GeoCoding geoCoding); PlanarImage getSourceImage(RasterDataNode rasterDataNode, int level); PlanarImage getValidMaskImage(final RasterDataNode rasterDataNode, int level); PlanarImage getGeophysicalImage(RasterDataNode rasterDataNode, int level); static ImageLayout createSingleBandedImageLayout(RasterDataNode rasterDataNode); static ImageLayout createSingleBandedImageLayout(RasterDataNode rasterDataNode, int dataBufferType); static ImageLayout createSingleBandedImageLayout(int dataBufferType,
                                                            int width,
                                                            int height,
                                                            int tileWidth,
                                                            int tileHeight); static ImageLayout createSingleBandedImageLayout(int dataBufferType,
                                                            int sourceWidth,
                                                            int sourceHeight,
                                                            Dimension tileSize,
                                                            ResolutionLevel level); static ImageLayout createSingleBandedImageLayout(int dataBufferType,
                                                            Point sourcePos,
                                                            int sourceWidth,
                                                            int sourceHeight,
                                                            Dimension tileSize,
                                                            ResolutionLevel level); static int getDataBufferType(int productDataType); static int getProductDataType(int dataBufferType); static Dimension getPreferredTileSize(Product product); RenderedImage createColoredBandImage(RasterDataNode[] rasterDataNodes,
                                                ImageInfo imageInfo,
                                                int level); static MultiLevelModel createMultiLevelModel(ProductNode productNode); RenderedImage getMaskImage(final Product product, final String expression, int level); MultiLevelImage getMaskImage(final String expression, final Product product); void clearMaskImageCache(Product product); ImageInfo getImageInfo(RasterDataNode[] rasters); void prepareImageInfos(RasterDataNode[] rasterDataNodes, ProgressMonitor pm); int getStatisticsLevel(RasterDataNode raster, int levelCount); PlanarImage createColoredMaskImage(Product product, String expression, Color color, boolean invertMask,
                                              int level); static PlanarImage createColoredMaskImage(Color color, RenderedImage alphaImage, boolean invertAlpha); static PlanarImage createColoredMaskImage(RenderedImage maskImage, Color color, double opacity); static PlanarImage createColoredMaskImage(Color color, RenderedImage alphaImage, RenderingHints hints); static MultiLevelImage createMaskedGeophysicalImage(final RasterDataNode node, Number maskValue); static RenderedImage createFormatOp(RenderedImage image, int dataType); static Color[] createColorPalette(ImageInfo imageInfo); static Color computeColor(ImageInfo imageInfo, Double rasterValue); static final ImageCRS DEFAULT_IMAGE_CRS; }
@Test public void testCreateLinearColorPalette() { final ColorPaletteDef cpd = new ColorPaletteDef(new ColorPaletteDef.Point[]{ new ColorPaletteDef.Point(100, Color.WHITE), new ColorPaletteDef.Point(200, Color.BLUE), new ColorPaletteDef.Point(300, Color.RED), new ColorPaletteDef.Point(400, Color.GREEN), }, 7); final ImageInfo imageInfo = new ImageInfo(cpd); imageInfo.setLogScaled(false); final Color[] palette = ImageManager.createColorPalette(imageInfo); assertNotNull(palette); assertEquals(7, palette.length); assertEquals(new Color(255, 255, 255), palette[0]); assertEquals(new Color(128, 128, 255), palette[1]); assertEquals(new Color(0, 0, 255), palette[2]); assertEquals(new Color(128, 0, 128), palette[3]); assertEquals(new Color(255, 0, 0), palette[4]); assertEquals(new Color(128, 128, 0), palette[5]); assertEquals(new Color(0, 255, 0), palette[6]); }
@Test public void testCreateLog10ColorPalette() { final ColorPaletteDef cpd = new ColorPaletteDef(new ColorPaletteDef.Point[]{ new ColorPaletteDef.Point(1, Color.WHITE), new ColorPaletteDef.Point(10, Color.BLUE), new ColorPaletteDef.Point(100, Color.RED), new ColorPaletteDef.Point(1000, Color.GREEN), }, 7); final ImageInfo imageInfo = new ImageInfo(cpd); imageInfo.setLogScaled(true); final Color[] palette = ImageManager.createColorPalette(imageInfo); assertNotNull(palette); assertEquals(7, palette.length); assertEquals(new Color(255, 255, 255), palette[0]); assertEquals(new Color(128, 128, 255), palette[1]); assertEquals(new Color(0, 0, 255), palette[2]); assertEquals(new Color(128, 0, 128), palette[3]); assertEquals(new Color(255, 0, 0), palette[4]); assertEquals(new Color(128, 128, 0), palette[5]); assertEquals(new Color(0, 255, 0), palette[6]); }
@Test public void testCreateLinearColorPalette_Discrete() { final ColorPaletteDef cpd = new ColorPaletteDef(new ColorPaletteDef.Point[]{ new ColorPaletteDef.Point(100, Color.WHITE), new ColorPaletteDef.Point(200, Color.BLUE), new ColorPaletteDef.Point(300, Color.RED), new ColorPaletteDef.Point(400, Color.GREEN), }, 7); cpd.setDiscrete(true); final ImageInfo imageInfo = new ImageInfo(cpd); imageInfo.setLogScaled(false); final Color[] palette = ImageManager.createColorPalette(imageInfo); assertNotNull(palette); assertEquals(7, palette.length); assertEquals(new Color(255, 255, 255), palette[0]); assertEquals(new Color(255, 255, 255), palette[1]); assertEquals(new Color(0, 0, 255), palette[2]); assertEquals(new Color(0, 0, 255), palette[3]); assertEquals(new Color(255, 0, 0), palette[4]); assertEquals(new Color(255, 0, 0), palette[4]); assertEquals(new Color(0, 255, 0), palette[6]); }
@Test public void testCreateLog10ColorPalette_Discrete() { final ColorPaletteDef cpd = new ColorPaletteDef(new ColorPaletteDef.Point[]{ new ColorPaletteDef.Point(1, Color.WHITE), new ColorPaletteDef.Point(10, Color.BLUE), new ColorPaletteDef.Point(100, Color.RED), new ColorPaletteDef.Point(1000, Color.GREEN), }, 7); cpd.setDiscrete(true); final ImageInfo imageInfo = new ImageInfo(cpd); imageInfo.setLogScaled(true); final Color[] palette = ImageManager.createColorPalette(imageInfo); assertNotNull(palette); assertEquals(7, palette.length); assertEquals(new Color(255, 255, 255), palette[0]); assertEquals(new Color(255, 255, 255), palette[1]); assertEquals(new Color(0, 0, 255), palette[2]); assertEquals(new Color(0, 0, 255), palette[3]); assertEquals(new Color(255, 0, 0), palette[4]); assertEquals(new Color(255, 0, 0), palette[5]); assertEquals(new Color(0, 255, 0), palette[6]); }