final double normalizedSample = normalizeSample(slider.getSample()); double sliderPos = normalizedSample * (palettePos2 - palettePos1);
private TiffShort[] createColorMap(Product product) { final ImageInfo imageInfo = product.getBandAt(0).getImageInfo(null, ProgressMonitor.NULL); final ColorPaletteDef paletteDef = imageInfo.getColorPaletteDef(); final TiffShort[] redColor = new TiffShort[TIFF_COLORMAP_SIZE]; Arrays.fill(redColor, new TiffShort(0)); final TiffShort[] greenColor = new TiffShort[TIFF_COLORMAP_SIZE]; Arrays.fill(greenColor, new TiffShort(0)); final TiffShort[] blueColor = new TiffShort[TIFF_COLORMAP_SIZE]; Arrays.fill(blueColor, new TiffShort(0)); final float factor = 65535.0f / 255.0f; for (ColorPaletteDef.Point point : paletteDef.getPoints()) { final Color color = point.getColor(); final int red = (int) (color.getRed() * factor); final int green = (int) (color.getGreen() * factor); final int blue = (int) (color.getBlue() * factor); int mapIndex = (int) Math.floor(point.getSample()); redColor[mapIndex] = new TiffShort(red); greenColor[mapIndex] = new TiffShort(green); blueColor[mapIndex] = new TiffShort(blue); } final TiffShort[] colorMap = new TiffShort[TIFF_COLORMAP_SIZE * 3]; System.arraycopy(redColor, 0, colorMap, 0, redColor.length); System.arraycopy(greenColor, 0, colorMap, TIFF_COLORMAP_SIZE, greenColor.length); System.arraycopy(blueColor, 0, colorMap, TIFF_COLORMAP_SIZE *2 , blueColor.length); return colorMap; }
private TiffShort[] createColorMap(Product product) { final ImageInfo imageInfo = product.getBandAt(0).getImageInfo(null, ProgressMonitor.NULL); final ColorPaletteDef paletteDef = imageInfo.getColorPaletteDef(); final TiffShort[] redColor = new TiffShort[TIFF_COLORMAP_SIZE]; Arrays.fill(redColor, new TiffShort(0)); final TiffShort[] greenColor = new TiffShort[TIFF_COLORMAP_SIZE]; Arrays.fill(greenColor, new TiffShort(0)); final TiffShort[] blueColor = new TiffShort[TIFF_COLORMAP_SIZE]; Arrays.fill(blueColor, new TiffShort(0)); final float factor = 65535.0f / 255.0f; for (ColorPaletteDef.Point point : paletteDef.getPoints()) { final Color color = point.getColor(); final int red = (int) (color.getRed() * factor); final int green = (int) (color.getGreen() * factor); final int blue = (int) (color.getBlue() * factor); int mapIndex = (int) Math.floor(point.getSample()); redColor[mapIndex] = new TiffShort(red); greenColor[mapIndex] = new TiffShort(green); blueColor[mapIndex] = new TiffShort(blue); } final TiffShort[] colorMap = new TiffShort[TIFF_COLORMAP_SIZE * 3]; System.arraycopy(redColor, 0, colorMap, 0, redColor.length); System.arraycopy(greenColor, 0, colorMap, TIFF_COLORMAP_SIZE, greenColor.length); System.arraycopy(blueColor, 0, colorMap, TIFF_COLORMAP_SIZE * 2, blueColor.length); return colorMap; }
final ColorPaletteDef.Point[] points = imageInfo.getColorPaletteDef().getPoints(); for (int colorIndex = 0; colorIndex < points.length; colorIndex++) { sampleColorIndexMap.putValue((int) points[colorIndex].getSample(), colorIndex);
for (int i = 0; i < n; i++) { ColorPaletteDef.Point slider = getGradationCurvePointAt(i); labels[i] = String.valueOf(MathUtils.round(slider.getSample(), roundFactor)); labelWidths[i] = fontMetrics.stringWidth(labels[i]);
Element colorPalettePointElem = new Element(DimapProductConstants.TAG_COLOR_PALETTE_POINT); bandStatisticsElem.addContent(colorPalettePointElem); JDomHelper.addElement(DimapProductConstants.TAG_SAMPLE, point.getSample(), colorPalettePointElem); colorPalettePointElem.addContent(createColorElement(point.getColor()));
final String[] cppTags = createTags(indent + 2, DimapProductConstants.TAG_COLOR_PALETTE_POINT); sXmlW.println(cppTags[0]); sXmlW.printLine(indent + 3, DimapProductConstants.TAG_SAMPLE, point.getSample()); if (StringUtils.isNotNullAndNotEmpty(point.getLabel())) { sXmlW.printLine(indent + 3, DimapProductConstants.TAG_LABEL, point.getLabel());
assertEquals(256, cpd.getNumColors()); assertEquals(3, cpd.getNumPoints()); assertEquals(-1.0, cpd.getPointAt(0).getSample(), 1e-10); assertEquals(+0.0, cpd.getPointAt(1).getSample(), 1e-10); assertEquals(+1.0, cpd.getPointAt(2).getSample(), 1e-10); assertEquals(Color.BLACK, cpd.getPointAt(0).getColor()); assertEquals(Color.GRAY, cpd.getPointAt(1).getColor()); assertEquals(256, cpd.getNumColors()); assertEquals(3, cpd.getNumPoints()); assertEquals(-1.0, cpd.getPointAt(0).getSample(), 1e-10); assertEquals(+0.5, cpd.getPointAt(1).getSample(), 1e-10); assertEquals(+1.0, cpd.getPointAt(2).getSample(), 1e-10); assertEquals(Color.BLACK, cpd.getPointAt(0).getColor()); assertEquals(Color.GRAY, cpd.getPointAt(1).getColor());
/** * creates a new point between the point at the given index * * @param index the index * @param scaling the scaling * * @return true, if a point has been inserted */ public boolean createPointAfter(int index, Scaling scaling) { Point point1 = getPointAt(index); Point point2 = null; if (index < points.indexOf(points.lastElement())) { point2 = getPointAt(index + 1); } final Point newPoint; if (point2 != null) { final double max = Math.max(point1.getSample(), point2.getSample()); final double min = Math.min(point1.getSample(), point2.getSample()); final double middle; middle = scaling.scale(0.5 * (scaling.scaleInverse(min) + scaling.scaleInverse(max))); newPoint = new Point(middle, getCenterColor(point1.getColor(), point2.getColor())); insertPointAfter(index, newPoint); return true; } return false; }
private static void transferPoints(ColorPaletteDef sourceCPD, double minSample, double maxSample, boolean autoDistribute, ColorPaletteDef targetCPD) { if (autoDistribute || sourceCPD.isAutoDistribute()) { alignNumPoints(sourceCPD, targetCPD); double minDisplaySample = sourceCPD.getMinDisplaySample(); double maxDisplaySample = sourceCPD.getMaxDisplaySample(); double delta1 = (maxSample > minSample) ? maxSample - minSample : 1.0; double delta2 = (maxDisplaySample > minDisplaySample) ? maxDisplaySample - minDisplaySample : 1.0; double b = delta1 / delta2; double a = minSample - minDisplaySample * b; for (int i = 0; i < sourceCPD.getNumPoints(); i++) { targetCPD.getPointAt(i).setSample(a + b * sourceCPD.getPointAt(i).getSample()); targetCPD.getPointAt(i).setColor(sourceCPD.getPointAt(i).getColor()); targetCPD.getPointAt(i).setLabel(sourceCPD.getPointAt(i).getLabel()); } } else { targetCPD.setPoints(sourceCPD.getPoints().clone()); } }
/** * Stores this color palette definition in the given file * * @param colorPaletteDef thje color palette definition * @param file the file * * @throws IOException if an I/O error occurs */ public static void storeColorPaletteDef(ColorPaletteDef colorPaletteDef, File file) throws IOException { final ColorPaletteDef.Point[] points = colorPaletteDef.getPoints(); final PropertyMap propertyMap = new PropertyMap(); final int numPoints = points.length; propertyMap.setPropertyInt(_PROPERTY_KEY_NUM_POINTS, numPoints); propertyMap.setPropertyBool(_PROPERTY_KEY_AUTODISTRIBUTE, colorPaletteDef.isAutoDistribute()); for (int i = 0; i < numPoints; i++) { propertyMap.setPropertyColor(_PROPERTY_KEY_COLOR + i, points[i].getColor()); propertyMap.setPropertyDouble(_PROPERTY_KEY_SAMPLE + i, points[i].getSample()); } propertyMap.store(file, "BEAM Colour Palette Definition File"); /*I18N*/ }
private static void writeImageInfo(ColorPaletteDef.Point[] points, NVariable variable) throws IOException { final double[] sampleValues = new double[points.length]; final int[] redValues = new int[points.length]; final int[] greenValues = new int[points.length]; final int[] blueValues = new int[points.length]; for (int i = 0; i < points.length; i++) { ColorPaletteDef.Point point = points[i]; sampleValues[i] = point.getSample(); redValues[i] = point.getColor().getRed(); greenValues[i] = point.getColor().getGreen(); blueValues[i] = point.getColor().getBlue(); } variable.addAttribute(COLOR_TABLE_SAMPLE_VALUES, Array.factory(sampleValues)); variable.addAttribute(COLOR_TABLE_RED_VALUES, Array.factory(redValues)); variable.addAttribute(COLOR_TABLE_GREEN_VALUES, Array.factory(greenValues)); variable.addAttribute(COLOR_TABLE_BLUE_VALUES, Array.factory(blueValues)); }
private Color computeColor(final double sample) { for (int i = 0; i < getNumPoints() - 1; i++) { final Point p1 = getPointAt(i); final Point p2 = getPointAt(i + 1); final double sample1 = p1.getSample(); final double sample2 = p2.getSample(); final Color color1 = p1.getColor(); final Color color2 = p2.getColor(); if (sample >= sample1 && sample <= sample2) { if (discrete) { return color1; } else { return computeColor(sample, sample1, sample2, color1, color2); } } } return Color.BLACK; }
private static double getSample(ColorPaletteDef.Point point) { return point.getSample(); }
public double getMinDisplaySample() { return getFirstPoint().getSample(); }
public double getMaxDisplaySample() { return getLastPoint().getSample(); }
@Override public double getSliderSample(int index) { return getImageInfo().getColorPaletteDef().getPointAt(index).getSample(); }
@Override public Object getValueAt(int rowIndex, int columnIndex) { final ColorPaletteDef.Point point = getImageInfo().getColorPaletteDef().getPointAt(rowIndex); if (columnIndex == 0) { final Color color = point.getColor(); return color.equals(ImageInfo.NO_COLOR) ? null : color; } else if (columnIndex == 1) { return point.getSample(); } return null; }
static boolean checkApplicability(ColorPaletteDef cpd) { final ColorPaletteDef.Point[] points = cpd.getPoints(); for (ColorPaletteDef.Point point : points) { if (point.getSample() <= 0.0) { return false; } } return true; } }