/** Simple utility method generating a Byte Based lookup table */ private static LookupTable generateLookupTableByte(byte[] lut) { return LookupTableFactory.create(lut, DataBuffer.TYPE_BYTE); }
/** * Builds a lookup table that is the identity on all bands but the alpha one, where the opacity * is applied * * @param opacity * @param bands * @param alphaBand * @return */ LookupTable buildOpacityLookupTable( float opacity, final int bands, int alphaBand, int dataType) { byte[][] matrix = new byte[bands][256]; for (int band = 0; band < matrix.length; band++) { if (band == alphaBand) { for (int i = 0; i < 256; i++) { matrix[band][i] = (byte) Math.round(i * opacity); } } else { for (int i = 0; i < 256; i++) { matrix[band][i] = (byte) i; } } } LookupTable table = LookupTableFactory.create(matrix, dataType); return table; }
private LookupTable createLookupTableByte(List<Range<Integer>> exclusionValues, int dataType) { final byte[] b = new byte[256]; Arrays.fill(b, (byte) 0); for (Range<Integer> exclusionValue : exclusionValues) { final int minValue = exclusionValue.getMinValue(); final int maxValue = exclusionValue.getMaxValue(); for (int i = minValue; i <= maxValue; i++) { b[i] = (byte) INVALID_PIXEL_I; } } return LookupTableFactory.create(b, dataType); }
private LookupTable createLookupTableUShort( List<Range<Integer>> exclusionValues, int dataType) { final byte[] bUShort = new byte[65536]; Arrays.fill(bUShort, (byte) 0); for (Range<Integer> exclusionValue : exclusionValues) { final int minValue = exclusionValue.getMinValue(); final int maxValue = exclusionValue.getMaxValue(); for (int i = minValue; i <= maxValue; i++) { bUShort[i] = (byte) INVALID_PIXEL_I; } } return LookupTableFactory.create(bUShort, dataType); } }
if (max < 256) { table = LookupTableFactory.create( new byte[] {(byte) value0, (byte) value1}, DataBuffer.TYPE_BYTE); } else if (max < 65536) { table = LookupTableFactory.create( new short[] {(short) value0, (short) value1}, true); } else { table = LookupTableFactory.create(new int[] {value0, value1}); table = LookupTableFactory.create(new int[] {value0, value1}, DataBuffer.TYPE_BYTE);
LookupTable table = LookupTableFactory.create(lut, dataType); worker.lookup(table); } else {
LookupTableFactory.create(tableData, image.getSampleModel().getDataType());
private LookupTable buildNoDataLookupTable(int dataType, Range noDataRange) { byte[] table; switch (dataType) { case DataBuffer.TYPE_BYTE: table = new byte[256]; for (int i = 0; i < table.length; i++) { if (noDataRange.contains(i)) { table[i] = 0; } else { table[i] = 1; } } break; case DataBuffer.TYPE_USHORT: table = new byte[65536]; for (int i = 0; i < table.length; i++) { if (noDataRange.contains(i)) { table[i] = 0; } else { table[i] = 1; } } break; default: throw new IllegalArgumentException( "Unable to handle a index color model based on data type " + dataType); } return LookupTableFactory.create(table); }
LookupTableFactory.create(lutData, mask.getSampleModel().getDataType());
.rangeLookup(lookupTable) .bandCombine(matrix) .lookup(LookupTableFactory.create(ALPHA_LUT)) .getRenderedImage();
/** * This takes an image with an indexed color model that uses less than 256 colors and has a 8bit * sample model, and transforms it to one that has the optimal sample model (for example, 1bit * if the palette only has 2 colors) * * @param source */ private static RenderedImage optimizeSampleModel(RenderedImage source) { int w = source.getWidth(); int h = source.getHeight(); ImageLayout layout = new ImageLayout(); layout.setColorModel(source.getColorModel()); layout.setSampleModel(source.getColorModel().createCompatibleSampleModel(w, h)); // if I don't force tiling off with this setting an exception is thrown // when writing the image out... layout.setTileWidth(w); layout.setTileHeight(h); RenderingHints hints = new RenderingHints(JAI.KEY_IMAGE_LAYOUT, layout); LookupTable table = LookupTableFactory.create(IDENTITY_TABLE); // TODO SIMONE why not format? ImageWorker worker = new ImageWorker(source); worker.setRenderingHints(hints); worker.lookup(table); return worker.getRenderedImage(); }