Java Code Examples for java.awt.image.DataBufferInt#getElem()
The following examples show how to use
java.awt.image.DataBufferInt#getElem() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebP.java From webp-imageio with Apache License 2.0 | 5 votes |
private static byte[] extractComponentRGBInt( int aWidth, int aHeight, ComponentSampleModel aSampleModel, DataBufferInt aDataBuffer ) { byte[] out = new byte[ aWidth * aHeight * 3 ]; int[] bankIndices = aSampleModel.getBankIndices(); int[] bankOffsets = aSampleModel.getBandOffsets(); int rScanIx = bankOffsets[ 0 ]; int gScanIx = bankOffsets[ 1 ]; int bScanIx = bankOffsets[ 2 ]; int pixelStride = aSampleModel.getPixelStride(); int scanlineStride = aSampleModel.getScanlineStride(); for ( int b = 0, y = 0; y < aHeight; y++ ) { int rPixIx = rScanIx; int gPixIx = gScanIx; int bPixIx = bScanIx; for ( int x = 0; x < aWidth; x++, b += 3 ) { out[b] = (byte) aDataBuffer.getElem(bankIndices[0], rPixIx); rPixIx += pixelStride; out[b + 1] = (byte) aDataBuffer.getElem(bankIndices[1], gPixIx); gPixIx += pixelStride; out[b + 2] = (byte) aDataBuffer.getElem(bankIndices[2], bPixIx); bPixIx += pixelStride; } rScanIx += scanlineStride; gScanIx += scanlineStride; bScanIx += scanlineStride; } return out; }
Example 2
Source File: WebP.java From webp-imageio with Apache License 2.0 | 5 votes |
private static byte[] extractComponentRGBAInt( int aWidth, int aHeight, ComponentSampleModel aSampleModel, DataBufferInt aDataBuffer ) { byte[] out = new byte[ aWidth * aHeight * 4 ]; int[] bankIndices = aSampleModel.getBankIndices(); int[] bankOffsets = aSampleModel.getBandOffsets(); int rScanIx = bankOffsets[ 0 ]; int gScanIx = bankOffsets[ 1 ]; int bScanIx = bankOffsets[ 2 ]; int aScanIx = bankOffsets[ 3 ]; int pixelStride = aSampleModel.getPixelStride(); int scanlineStride = aSampleModel.getScanlineStride(); for ( int b = 0, y = 0; y < aHeight; y++ ) { int rPixIx = rScanIx; int gPixIx = gScanIx; int bPixIx = bScanIx; int aPixIx = aScanIx; for ( int x = 0; x < aWidth; x++, b += 4 ) { out[b] = (byte) aDataBuffer.getElem(bankIndices[0], rPixIx); rPixIx += pixelStride; out[b + 1] = (byte) aDataBuffer.getElem(bankIndices[1], gPixIx); gPixIx += pixelStride; out[b + 2] = (byte) aDataBuffer.getElem(bankIndices[2], bPixIx); bPixIx += pixelStride; out[b + 3] = (byte) aDataBuffer.getElem(bankIndices[3], aPixIx); aPixIx += pixelStride; } rScanIx += scanlineStride; gScanIx += scanlineStride; bScanIx += scanlineStride; aScanIx += scanlineStride; } return out; }