RGBImageProfile implements ConfigurableExtension { public static void storeRgbaExpressions(final Product product, final String[] rgbaExpressions) { for (int i = 0; i < RGBImageProfile.RGBA_BAND_NAMES.length; i++) { final String rgbBandName = RGBImageProfile.RGBA_BAND_NAMES[i]; final String rgbaExpression = rgbaExpressions[i]; final Band rgbBand = product.getBand(rgbBandName); final boolean expressionIsEmpty = rgbaExpression.equals(""); final boolean alphaChannel = i == 3; if (rgbBand != null) { if (rgbBand instanceof VirtualBand) { VirtualBand virtualBand = (VirtualBand) rgbBand; virtualBand.setExpression(rgbaExpression); } else { product.removeBand(rgbBand); product.addBand(new VirtualBand(rgbBandName, ProductData.TYPE_FLOAT32, product.getSceneRasterWidth(), product.getSceneRasterHeight(), expressionIsEmpty ? "0" : rgbaExpression)); } } else { if (!alphaChannel || !expressionIsEmpty) { product.addBand(new VirtualBand(rgbBandName, ProductData.TYPE_FLOAT32, product.getSceneRasterWidth(), product.getSceneRasterHeight(), expressionIsEmpty ? "0" : rgbaExpression)); } } } } RGBImageProfile();  RGBImageProfile(final String name);  RGBImageProfile(final String name, String[] rgbaExpressions);  RGBImageProfile(final String name, String[] rgbaExpressions, String pattern[]); String getName(); void setName(String name); boolean isInternal(); void setInternal(final boolean internal); boolean equalExpressions(RGBImageProfile profile); boolean equalExpressions(String[] rgbaExpressions); boolean isValid(); String[] getRgbExpressions(); void setRgbExpressions(String[] rgbExpressions); String[] getRgbaExpressions(); void setRgbaExpressions(String[] rgbaExpressions); String getRedExpression(); void setRedExpression(String expression); String getGreenExpression(); void setGreenExpression(String expression); String getBlueExpression(); void setBlueExpression(String expression); String getAlphaExpression(); void setAlphaExpression(String expression); boolean hasAlpha(); String[] getPattern(); void setPattern(String[] pattern); boolean isApplicableTo(final Product product); static RGBImageProfile getCurrentProfile(final Product product); static RGBImageProfile loadProfile(final File file); static RGBImageProfile loadProfile(final URL url); void store(final File file); void getProperties(final Properties properties); @SuppressWarnings("LocalVariableHidesMemberVariable") void setProperties(Properties properties); static void storeRgbaExpressions(final Product product, final String[] rgbaExpressions); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString(); void configure(ConfigurationElement config); static final String RED_BAND_NAME; static final String GREEN_BAND_NAME; static final String BLUE_BAND_NAME; static final String ALPHA_BAND_NAME; static final String[] RGB_BAND_NAMES; static final String[] RGBA_BAND_NAMES; static final String FILENAME_EXTENSION; static final String PROPERTY_KEY_NAME; static final String PROPERTY_KEY_RED; static final String PROPERTY_KEY_GREEN; static final String PROPERTY_KEY_BLUE; static final String PROPERTY_KEY_ALPHA; static final String PROPERTY_KEY_INTERNAL; final static String PROPERTY_KEY_PREFIX_RGB_PROFILE; }
@Test public void testStoreRgbaExpressions() { final Product p1 = createTestProduct(); RGBImageProfile.storeRgbaExpressions(p1, new String[]{"U", "V", "W", "X"}); assertNotNull(p1.getBand(RGBImageProfile.RED_BAND_NAME)); assertNotNull(p1.getBand(RGBImageProfile.GREEN_BAND_NAME)); assertNotNull(p1.getBand(RGBImageProfile.BLUE_BAND_NAME)); assertNotNull(p1.getBand(RGBImageProfile.ALPHA_BAND_NAME)); }
@Test public void testStoreRgbaExpressionsWithoutAlpha() { final Product p1 = createTestProduct(); RGBImageProfile.storeRgbaExpressions(p1, new String[]{"U", "V", "W", ""}); assertNotNull(p1.getBand(RGBImageProfile.RED_BAND_NAME)); assertNotNull(p1.getBand(RGBImageProfile.GREEN_BAND_NAME)); assertNotNull(p1.getBand(RGBImageProfile.BLUE_BAND_NAME)); assertNull(p1.getBand(RGBImageProfile.ALPHA_BAND_NAME)); }
@Test public void testStoreRgbaExpressionsWithoutGreen() { final Product p1 = createTestProduct(); RGBImageProfile.storeRgbaExpressions(p1, new String[]{"U", "", "W", ""}); assertNotNull(p1.getBand(RGBImageProfile.RED_BAND_NAME)); assertNotNull(p1.getBand(RGBImageProfile.GREEN_BAND_NAME)); assertNotNull(p1.getBand(RGBImageProfile.BLUE_BAND_NAME)); assertNull(p1.getBand(RGBImageProfile.ALPHA_BAND_NAME)); assertEquals("0", ((VirtualBand) p1.getBand(RGBImageProfile.GREEN_BAND_NAME)).getExpression()); }
@Test public void testStoreRgbaExpressionsOverwrite() { final Product p1 = createTestProduct(); RGBImageProfile.storeRgbaExpressions(p1, new String[]{"U", "V", "W", "X"}); assertNotNull(p1.getBand(RGBImageProfile.RED_BAND_NAME)); assertNotNull(p1.getBand(RGBImageProfile.GREEN_BAND_NAME)); assertNotNull(p1.getBand(RGBImageProfile.BLUE_BAND_NAME)); assertNotNull(p1.getBand(RGBImageProfile.ALPHA_BAND_NAME)); RGBImageProfile.storeRgbaExpressions(p1, new String[]{"0.3", "2.0", "6.7", ""}); assertNotNull(p1.getBand(RGBImageProfile.RED_BAND_NAME)); assertNotNull(p1.getBand(RGBImageProfile.GREEN_BAND_NAME)); assertNotNull(p1.getBand(RGBImageProfile.BLUE_BAND_NAME)); assertNotNull(p1.getBand(RGBImageProfile.ALPHA_BAND_NAME)); assertEquals("0.3", ((VirtualBand) p1.getBand(RGBImageProfile.RED_BAND_NAME)).getExpression()); assertEquals("2.0", ((VirtualBand) p1.getBand(RGBImageProfile.GREEN_BAND_NAME)).getExpression()); assertEquals("6.7", ((VirtualBand) p1.getBand(RGBImageProfile.BLUE_BAND_NAME)).getExpression()); assertEquals("", ((VirtualBand) p1.getBand(RGBImageProfile.ALPHA_BAND_NAME)).getExpression()); }