private static ImageInfo createIndexedImageInfo( Product product, TIFFRenderedImage baseImage, Band band) { final IndexColorModel colorModel = (IndexColorModel) baseImage.getColorModel(); final IndexCoding indexCoding = new IndexCoding("color_map"); final int colorCount = colorModel.getMapSize(); final ColorPaletteDef.Point[] points = new ColorPaletteDef.Point[colorCount]; for (int j = 0; j < colorCount; j++) { final String name = String.format("I%3d", j); indexCoding.addIndex(name, j, ""); points[j] = new ColorPaletteDef.Point(j, new Color(colorModel.getRGB(j)), name); } product.getIndexCodingGroup().add(indexCoding); band.setSampleCoding(indexCoding); return new ImageInfo(new ColorPaletteDef(points, points.length)); }
private void writeIndexCoding(IndexCoding indexCoding, NVariable variable) throws IOException { CfIndexCodingPart.writeIndexCoding(indexCoding, variable); final String[] indexNames = indexCoding.getIndexNames(); final StringBuilder descriptions = new StringBuilder(); for (String indexName : indexNames) { final MetadataAttribute index = indexCoding.getIndex(indexName); if (index != null) { final String description = index.getDescription(); if (description != null) { descriptions.append(description); } } descriptions.append(DESCRIPTION_SEPARATOR); } variable.addAttribute(INDEX_DESCRIPTIONS, descriptions.toString().trim()); variable.addAttribute(INDEX_CODING_NAME, indexCoding.getName()); }
private static IndexCoding readIndexCoding(Variable variable, String indexCodingName) throws ProductIOException { final IndexCoding indexCoding = CfIndexCodingPart.readIndexCoding(variable, indexCodingName); if (indexCoding != null) { final Attribute descriptionsAtt = variable.findAttributeIgnoreCase(INDEX_DESCRIPTIONS); if (descriptionsAtt != null) { final String[] descriptions = descriptionsAtt.getStringValue().split(DESCRIPTION_SEPARATOR); if (indexCoding.getNumAttributes() == descriptions.length) { for (int i = 0; i < descriptions.length; i++) { indexCoding.getAttributeAt(i).setDescription(descriptions[i]); } } } final Attribute nameAtt = variable.findAttributeIgnoreCase(INDEX_CODING_NAME); if (nameAtt != null) { indexCoding.setName(nameAtt.getStringValue()); } } return indexCoding; }