break; case 1: x = linearSegment(in[i++], out, x, n); break; case 2: { break; case 1: x = linearSegment(in[i2++], out, x, n); break; default: illegalOpcode(op, i2-2); illegalOpcode(op, i-2); exceedsLutLength(out.length); else endOfSegmentedLut(); lutLengthMismatch(x, out.length);
@Override public boolean isCompatibleRaster(Raster raster) { return isCompatibleSampleModel(raster.getSampleModel()); }
public BufferedImage convertToIntDiscrete(Raster raster) { if (!isCompatibleRaster(raster)) throw new IllegalArgumentException( "This raster is not compatible with this PaletteColorModel."); ColorModel cm = new DirectColorModel(getColorSpace(), 24, 0xff0000, 0x00ff00, 0x0000ff, 0, false, DataBuffer.TYPE_INT); int w = raster.getWidth(); int h = raster.getHeight(); WritableRaster discreteRaster = cm.createCompatibleWritableRaster(w, h); int[] discretData = ((DataBufferInt) discreteRaster.getDataBuffer()).getData(); DataBuffer data = raster.getDataBuffer(); if (data instanceof DataBufferByte) { byte[] pixels = ((DataBufferByte) data).getData(); for (int i = 0; i < pixels.length; i++) discretData[i] = getRGB(pixels[i]); } else { short[] pixels = ((DataBufferUShort) data).getData(); for (int i = 0; i < pixels.length; i++) discretData[i] = getRGB(pixels[i]); } return new BufferedImage(cm, discreteRaster, false, null); }
private byte[] lutData(Attributes ds, int[] desc, int dataTag, int segmTag) { int len = desc[0] == 0 ? 0x10000 : desc[0]; int bits = desc[2]; byte[] data = ds.getSafeBytes(dataTag); if (data == null) { int[] segm = ds.getInts(segmTag); if (segm == null) { throw new IllegalArgumentException("Missing LUT Data!"); } if (bits == 8) { throw new IllegalArgumentException( "Segmented LUT Data with LUT Descriptor: bits=8"); } data = new byte[len]; inflateSegmentedLut(segm, data); } else if (bits == 16 || data.length != len) { if (data.length != len << 1) lutLengthMismatch(data.length, len); int hilo = ds.bigEndian() ? 0 : 1; if (bits == 8) hilo = 1 - hilo; // padded high bits -> use low bits data = LookupTableFactory.halfLength(data, hilo); } return data; }
private static int linearSegment(int y1, byte[] out, int x, int n) { if (x == 0) throw new IllegalArgumentException( "Linear segment cannot be the first segment"); try { int y0 = out[x-1]; int dy = y1-y0; for (int j = 1; j <= n; j++) out[x++] = (byte)((y0 + dy*j/n)>>8); } catch (IndexOutOfBoundsException e) { exceedsLutLength(out.length); } return x; }
public static ColorModel createPaletteColorModel(int bits, int dataType, Attributes ds) { return new PaletteColorModel(bits, dataType, createRGBColorSpace(ds), ds); }
public static BufferedImage convertToIntRGB(BufferedImage bi) { ColorModel cm = bi.getColorModel(); if (cm instanceof DirectColorModel) return bi; if (cm.getNumComponents() != 3) throw new IllegalArgumentException("ColorModel: " + cm); WritableRaster raster = bi.getRaster(); if (cm instanceof PaletteColorModel) return ((PaletteColorModel) cm).convertToIntDiscrete(raster); BufferedImage intRGB = new BufferedImage(bi.getWidth(), bi.getHeight(), BufferedImage.TYPE_INT_RGB); Graphics graphics = intRGB.getGraphics(); try { graphics.drawImage(bi, 0, 0, null); } finally { graphics.dispose(); } return intRGB; }
public BufferedImage convertToIntDiscrete(Raster raster) { if (!isCompatibleRaster(raster)) throw new IllegalArgumentException( "This raster is not compatible with this PaletteColorModel."); ColorModel cm = new DirectColorModel(getColorSpace(), 24, 0xff0000, 0x00ff00, 0x0000ff, 0, false, DataBuffer.TYPE_INT); int w = raster.getWidth(); int h = raster.getHeight(); WritableRaster discreteRaster = cm.createCompatibleWritableRaster(w, h); int[] discretData = ((DataBufferInt) discreteRaster.getDataBuffer()).getData(); DataBuffer data = raster.getDataBuffer(); if (data instanceof DataBufferByte) { byte[] pixels = ((DataBufferByte) data).getData(); for (int i = 0; i < pixels.length; i++) discretData[i] = getRGB(pixels[i]); } else { short[] pixels = ((DataBufferUShort) data).getData(); for (int i = 0; i < pixels.length; i++) discretData[i] = getRGB(pixels[i]); } return new BufferedImage(cm, discreteRaster, false, null); }
private byte[] lutData(Attributes ds, int[] desc, int dataTag, int segmTag) { int len = desc[0] == 0 ? 0x10000 : desc[0]; int bits = desc[2]; byte[] data = ds.getSafeBytes(dataTag); if (data == null) { int[] segm = ds.getInts(segmTag); if (segm == null) { throw new IllegalArgumentException("Missing LUT Data!"); } if (bits == 8) { throw new IllegalArgumentException( "Segmented LUT Data with LUT Descriptor: bits=8"); } data = new byte[len]; inflateSegmentedLut(segm, data); } else if (bits == 16 || data.length != len) { if (data.length != len << 1) lutLengthMismatch(data.length, len); int hilo = ds.bigEndian() ? 0 : 1; if (bits == 8) hilo = 1 - hilo; // padded high bits -> use low bits data = LookupTableFactory.halfLength(data, hilo); } return data; }
private static int linearSegment(int y1, byte[] out, int x, int n) { if (x == 0) throw new IllegalArgumentException( "Linear segment cannot be the first segment"); try { int y0 = out[x-1]; int dy = y1-y0; for (int j = 1; j <= n; j++) out[x++] = (byte)((y0 + dy*j/n)>>8); } catch (IndexOutOfBoundsException e) { exceedsLutLength(out.length); } return x; }
public static ColorModel createPaletteColorModel(int bits, int dataType, Attributes ds) { return new PaletteColorModel(bits, dataType, createRGBColorSpace(ds), ds); }
public static BufferedImage convertToIntRGB(BufferedImage bi) { ColorModel cm = bi.getColorModel(); if (cm instanceof DirectColorModel) return bi; if (cm.getNumComponents() != 3) throw new IllegalArgumentException("ColorModel: " + cm); WritableRaster raster = bi.getRaster(); if (cm instanceof PaletteColorModel) return ((PaletteColorModel) cm).convertToIntDiscrete(raster); BufferedImage intRGB = new BufferedImage(bi.getWidth(), bi.getHeight(), BufferedImage.TYPE_INT_RGB); Graphics graphics = intRGB.getGraphics(); try { graphics.drawImage(bi, 0, 0, null); } finally { graphics.dispose(); } return intRGB; }
break; case 1: x = linearSegment(in[i++], out, x, n); break; case 2: { break; case 1: x = linearSegment(in[i2++], out, x, n); break; default: illegalOpcode(op, i2-2); illegalOpcode(op, i-2); exceedsLutLength(out.length); else endOfSegmentedLut(); lutLengthMismatch(x, out.length);
@Override public boolean isCompatibleRaster(Raster raster) { return isCompatibleSampleModel(raster.getSampleModel()); }