private static ByteInterleavedRaster normalizeRaster(ByteInterleavedRaster raster) { boolean reallocBuffer = false; int scanLineStride = raster.getScanlineStride(); int dataOffsets[] = raster.getDataOffsets(); for (int i = 0; i < dataOffsets.length; i++) if (dataOffsets[i] != i) { reallocBuffer = true; break; } int bands = raster.getNumBands(); if (!reallocBuffer && (raster.getPixelStride() != bands || scanLineStride != raster.getWidth() * bands)) reallocBuffer = true; if (reallocBuffer) { PixelInterleavedSampleModel sm = (PixelInterleavedSampleModel) raster.getSampleModel(); PixelInterleavedSampleModel newSM = new PixelInterleavedSampleModel( sm.getDataType(), raster.getWidth(), raster.getHeight(), bands, bands * raster.getWidth(), bands == 1 ? new int[] {0} : new int[] {0, 1, 2}); ByteInterleavedRaster newRaster = new ByteInterleavedRaster(newSM, new Point(raster.getMinX(), raster.getMinY())); Functions.copyData(newRaster, raster); raster = newRaster; } return raster; }
public Byte(ByteInterleavedRaster srcRas, ColorModel cm, AffineTransform xform, int maxw) { super(cm, xform, srcRas.getWidth(), srcRas.getHeight(), maxw); this.srcRas = srcRas; this.inData = srcRas.getDataStorage(); this.inSpan = srcRas.getScanlineStride(); this.inOff = srcRas.getDataOffset(0); }
public void doTransform(ByteInterleavedRaster input, ByteInterleavedRaster output) { if (cmsTransform != null) { ByteInterleavedRaster ri = normalizeRaster(input); ByteInterleavedRaster ro; int outBands = output.getNumBands(); if (!input.getBounds().equals(output.getBounds())) { int[] offsets = outBands == 1 ? new int[] {0} : new int[] {0, 1, 2}; SampleModel sm = new PixelInterleavedSampleModel( DataBuffer.TYPE_BYTE, ri.getWidth(), ri.getHeight(), outBands, outBands * ri.getWidth(), offsets); ro = new ByteInterleavedRaster(sm, new Point(ri.getMinX(), ri.getMinY())); } else ro = normalizeRaster(output); int pixels = outBands == 1 ? ro.getDataStorage().length : ro.getDataStorage().length / outBands; cmsDoTransform(cmsTransform.handle, ri.getDataStorage(), ro.getDataStorage(), pixels); if (ro != output) Functions.copyData(output, ro); } }
public ByteFilter( ByteInterleavedRaster srcRas, ColorModel cm, AffineTransform xform, int maxw) { super( (cm.getTransparency() == Transparency.OPAQUE ? xrgbmodel : argbmodel), xform, srcRas.getWidth(), srcRas.getHeight(), maxw); this.inPalette = new int[256]; ((IndexColorModel) cm).getRGBs(this.inPalette); this.srcRas = srcRas; this.inData = srcRas.getDataStorage(); this.inSpan = srcRas.getScanlineStride(); this.inOff = srcRas.getDataOffset(0); }