use of java.awt.image.DataBufferFloat in project javacv by bytedeco.
the class GLCanvasFrame method showImage.
public void showImage(BufferedImage image) {
if (image == null) {
return;
}
this.color = null;
this.width = image.getWidth();
this.height = image.getHeight();
DataBuffer buffer = image.getRaster().getDataBuffer();
if (buffer instanceof DataBufferByte) {
this.buffer = ByteBuffer.wrap(((DataBufferByte) buffer).getData());
this.type = GL2.GL_UNSIGNED_BYTE;
} else if (buffer instanceof DataBufferDouble) {
this.buffer = DoubleBuffer.wrap(((DataBufferDouble) buffer).getData());
this.type = GL2.GL_DOUBLE;
} else if (buffer instanceof DataBufferFloat) {
this.buffer = FloatBuffer.wrap(((DataBufferFloat) buffer).getData());
this.type = GL2.GL_FLOAT;
} else if (buffer instanceof DataBufferInt) {
this.buffer = IntBuffer.wrap(((DataBufferInt) buffer).getData());
this.type = GL2.GL_INT;
} else if (buffer instanceof DataBufferShort) {
this.buffer = ShortBuffer.wrap(((DataBufferShort) buffer).getData());
this.type = GL2.GL_SHORT;
} else if (buffer instanceof DataBufferUShort) {
this.buffer = ShortBuffer.wrap(((DataBufferUShort) buffer).getData());
this.type = GL2.GL_UNSIGNED_SHORT;
} else {
assert false;
}
switch(image.getSampleModel().getNumBands()) {
case 1:
this.format = GL2.GL_LUMINANCE;
break;
case 2:
this.format = GL2.GL_RG;
break;
case 3:
this.format = GL2.GL_RGB;
break;
case 4:
this.format = GL2.GL_RGBA;
break;
default:
assert false;
}
getGLCanvas().display();
}
use of java.awt.image.DataBufferFloat in project imageio-ext by geosolutions-it.
the class TIFFDecompressor method decode.
/**
* Decodes the input bit stream (located in the
* <code>ImageInputStream</code> <code>stream</code>, at offset
* <code>offset</code>, and continuing for <code>byteCount</code>
* bytes) into the output <code>BufferedImage</code>
* <code>image</code>.
*
* <p> The default implementation analyzes the destination image
* to determine if it is suitable as the destination for the
* <code>decodeRaw</code> method. If not, a suitable image is
* created. Next, <code>decodeRaw</code> is called to perform the
* actual decoding, and the results are copied into the
* destination image if necessary. Subsampling and offsetting are
* performed automatically.
*
* <p> The precise responsibilities of this routine are as
* follows. The input bit stream is defined by the instance
* variables <code>stream</code>, <code>offset</code>, and
* <code>byteCount</code>. These bits contain the data for the
* region of the source image defined by <code>srcMinX</code>,
* <code>srcMinY</code>, <code>srcWidth</code>, and
* <code>srcHeight</code>.
*
* <p> The source data is required to be subsampling, starting at
* the <code>sourceXOffset</code>th column and including
* every <code>subsampleX</code>th pixel thereafter (and similarly
* for <code>sourceYOffset</code> and
* <code>subsampleY</code>).
*
* <p> Pixels are copied into the destination with an addition shift of
* (<code>dstXOffset</code>, <code>dstYOffset</code>). The complete
* set of formulas relating the source and destination coordinate spaces
* are:
*
* <pre>
* dx = (sx - sourceXOffset)/subsampleX + dstXOffset;
* dy = (sy - sourceYOffset)/subsampleY + dstYOffset;
* </pre>
*
* Only source pixels such that <code>(sx - sourceXOffset) %
* subsampleX == 0</code> and <code>(sy - sourceYOffset) %
* subsampleY == 0</code> are copied.
*
* <p> The inverse mapping, from destination to source coordinates,
* is one-to-one:
*
* <pre>
* sx = (dx - dstXOffset)*subsampleX + sourceXOffset;
* sy = (dy - dstYOffset)*subsampleY + sourceYOffset;
* </pre>
*
* <p> The region of the destination image to be updated is given
* by the instance variables <code>dstMinX</code>,
* <code>dstMinY</code>, <code>dstWidth</code>, and
* <code>dstHeight</code>.
*
* <p> It is possible that not all of the source data being read
* will contribute to the destination image. For example, the
* destination offsets could be set such that some of the source
* pixels land outside of the bounds of the image. As a
* convenience, the bounds of the active source region (that is,
* the region of the strip or tile being read that actually
* contributes to the destination image, taking clipping into
* account) are available as <code>activeSrcMinX</code>,
* <code>activeSrcMinY</code>, <code>activeSrcWidth</code> and
* <code>activeSrcHeight</code>. Thus, the source pixel at
* (<code>activeSrcMinX</code>, <code>activeSrcMinY</code>) will
* map to the destination pixel (<code>dstMinX</code>,
* <code>dstMinY</code>).
*
* <p> The sequence of source bands given by
* <code>sourceBands</code> are to be copied into the sequence of
* bands in the destination given by
* <code>destinationBands</code>.
*
* <p> Some standard tag information is provided the instance
* variables <code>photometricInterpretation</code>,
* <code>compression</code>, <code>samplesPerPixel</code>,
* <code>bitsPerSample</code>, <code>sampleFormat</code>,
* <code>extraSamples</code>, and <code>colorMap</code>.
*
* <p> In practice, unless there is a significant performance
* advantage to be gained by overriding this routine, most users
* will prefer to use the default implementation of this routine,
* and instead override the <code>decodeRaw</code> and/or
* <code>getRawImageType</code> methods.
*
* @exception IOException if an error occurs in
* <code>decodeRaw</code>.
*/
public void decode() throws IOException {
byte[] byteData = null;
short[] shortData = null;
int[] intData = null;
float[] floatData = null;
double[] doubleData = null;
int dstOffset = 0;
int pixelBitStride = 1;
int scanlineStride = 0;
if (useTurbo) {
decodeRaw(byteData, dstOffset, pixelBitStride, scanlineStride);
} else {
// Analyze raw image
this.rawImage = null;
if (isImageSimple) {
if (isBilevel) {
rawImage = this.image;
} else if (isContiguous) {
rawImage = image.getSubimage(dstMinX, dstMinY, dstWidth, dstHeight);
}
}
boolean isDirectCopy = rawImage != null;
if (rawImage == null) {
rawImage = createRawImage();
if (rawImage == null) {
throw new IIOException("Couldn't create image buffer!");
}
}
WritableRaster ras = rawImage.getRaster();
if (isBilevel) {
Rectangle rect = isImageSimple ? new Rectangle(dstMinX, dstMinY, dstWidth, dstHeight) : ras.getBounds();
byteData = ImageUtil.getPackedBinaryData(ras, rect);
dstOffset = 0;
pixelBitStride = 1;
scanlineStride = (rect.width + 7) / 8;
} else {
SampleModel sm = ras.getSampleModel();
DataBuffer db = ras.getDataBuffer();
boolean isSupportedType = false;
if (sm instanceof ComponentSampleModel) {
ComponentSampleModel csm = (ComponentSampleModel) sm;
dstOffset = csm.getOffset(-ras.getSampleModelTranslateX(), -ras.getSampleModelTranslateY());
scanlineStride = csm.getScanlineStride();
if (db instanceof DataBufferByte) {
DataBufferByte dbb = (DataBufferByte) db;
byteData = dbb.getData();
pixelBitStride = csm.getPixelStride() * 8;
isSupportedType = true;
} else if (db instanceof DataBufferUShort) {
DataBufferUShort dbus = (DataBufferUShort) db;
shortData = dbus.getData();
pixelBitStride = csm.getPixelStride() * 16;
isSupportedType = true;
} else if (db instanceof DataBufferShort) {
DataBufferShort dbs = (DataBufferShort) db;
shortData = dbs.getData();
pixelBitStride = csm.getPixelStride() * 16;
isSupportedType = true;
} else if (db instanceof DataBufferInt) {
DataBufferInt dbi = (DataBufferInt) db;
intData = dbi.getData();
pixelBitStride = csm.getPixelStride() * 32;
isSupportedType = true;
} else if (db instanceof DataBufferFloat) {
DataBufferFloat dbf = (DataBufferFloat) db;
floatData = dbf.getData();
pixelBitStride = csm.getPixelStride() * 32;
isSupportedType = true;
} else if (db instanceof DataBufferDouble) {
DataBufferDouble dbf = (DataBufferDouble) db;
doubleData = dbf.getData();
pixelBitStride = csm.getPixelStride() * 64;
isSupportedType = true;
}
} else if (sm instanceof MultiPixelPackedSampleModel) {
MultiPixelPackedSampleModel mppsm = (MultiPixelPackedSampleModel) sm;
dstOffset = mppsm.getOffset(-ras.getSampleModelTranslateX(), -ras.getSampleModelTranslateY());
pixelBitStride = mppsm.getPixelBitStride();
scanlineStride = mppsm.getScanlineStride();
if (db instanceof DataBufferByte) {
DataBufferByte dbb = (DataBufferByte) db;
byteData = dbb.getData();
isSupportedType = true;
} else if (db instanceof DataBufferUShort) {
DataBufferUShort dbus = (DataBufferUShort) db;
shortData = dbus.getData();
isSupportedType = true;
} else if (db instanceof DataBufferInt) {
DataBufferInt dbi = (DataBufferInt) db;
intData = dbi.getData();
isSupportedType = true;
}
} else if (sm instanceof SinglePixelPackedSampleModel) {
SinglePixelPackedSampleModel sppsm = (SinglePixelPackedSampleModel) sm;
dstOffset = sppsm.getOffset(-ras.getSampleModelTranslateX(), -ras.getSampleModelTranslateY());
scanlineStride = sppsm.getScanlineStride();
if (db instanceof DataBufferByte) {
DataBufferByte dbb = (DataBufferByte) db;
byteData = dbb.getData();
pixelBitStride = 8;
isSupportedType = true;
} else if (db instanceof DataBufferUShort) {
DataBufferUShort dbus = (DataBufferUShort) db;
shortData = dbus.getData();
pixelBitStride = 16;
isSupportedType = true;
} else if (db instanceof DataBufferInt) {
DataBufferInt dbi = (DataBufferInt) db;
intData = dbi.getData();
pixelBitStride = 32;
isSupportedType = true;
}
}
if (!isSupportedType) {
throw new IIOException("Unsupported raw image type: SampleModel = " + sm + "; DataBuffer = " + db);
}
}
if (isBilevel) {
// Bilevel data are always in a contiguous byte buffer.
decodeRaw(byteData, dstOffset, pixelBitStride, scanlineStride);
} else {
SampleModel sm = ras.getSampleModel();
// bits except at the end of a row.
if (isDataBufferBitContiguous(sm)) {
// Use byte or float data directly.
if (byteData != null) {
if (DEBUG) {
System.out.println("Decoding bytes directly");
}
if (offset == 0 && byteCount == 0 && noData != null) {
setEmptyTile(byteData, dstOffset, pixelBitStride, scanlineStride, noData.byteValue());
} else {
decodeRaw(byteData, dstOffset, pixelBitStride, scanlineStride);
}
} else if (floatData != null) {
if (DEBUG) {
System.out.println("Decoding floats directly");
}
if (offset == 0 && byteCount == 0 && noData != null) {
setEmptyTile(floatData, dstOffset, pixelBitStride, scanlineStride, noData.floatValue());
} else {
decodeRaw(floatData, dstOffset, pixelBitStride, scanlineStride);
}
} else if (doubleData != null) {
if (DEBUG) {
System.out.println("Decoding doubles directly");
}
if (offset == 0 && byteCount == 0 && noData != null) {
setEmptyTile(doubleData, dstOffset, pixelBitStride, scanlineStride, noData.doubleValue());
} else {
decodeRaw(doubleData, dstOffset, pixelBitStride, scanlineStride);
}
} else {
if (shortData != null) {
if (offset == 0 && byteCount == 0 && noData != null) {
setEmptyTile(shortData, dstOffset, pixelBitStride, scanlineStride, noData.shortValue());
} else if (areSampleSizesEqual(sm) && sm.getSampleSize(0) == 16) {
if (DEBUG) {
System.out.println("Decoding shorts directly");
}
// Decode directly into short data.
decodeRaw(shortData, dstOffset, pixelBitStride, scanlineStride);
} else {
if (DEBUG) {
System.out.println("Decoding bytes->shorts");
}
// Decode into bytes and reformat into shorts.
int bpp = getBitsPerPixel(sm);
int bytesPerRow = (bpp * srcWidth + 7) / 8;
byte[] buf = new byte[bytesPerRow * srcHeight];
decodeRaw(buf, 0, bpp, bytesPerRow);
reformatData(buf, bytesPerRow, srcHeight, shortData, null, dstOffset, scanlineStride);
}
} else if (intData != null) {
if (offset == 0 && byteCount == 0 && noData != null) {
setEmptyTile(intData, dstOffset, pixelBitStride, scanlineStride, noData.intValue());
} else if (areSampleSizesEqual(sm) && sm.getSampleSize(0) == 32) {
if (DEBUG) {
System.out.println("Decoding ints directly");
}
// Decode directly into int data.
decodeRaw(intData, dstOffset, pixelBitStride, scanlineStride);
} else {
if (DEBUG) {
System.out.println("Decoding bytes->ints");
}
// Decode into bytes and reformat into ints.
int bpp = getBitsPerPixel(sm);
int bytesPerRow = (bpp * srcWidth + 7) / 8;
byte[] buf = new byte[bytesPerRow * srcHeight];
decodeRaw(buf, 0, bpp, bytesPerRow);
reformatData(buf, bytesPerRow, srcHeight, null, intData, dstOffset, scanlineStride);
}
}
}
} else {
if (DEBUG) {
System.out.println("Decoding discontiguous data");
}
// Read discontiguous data into bytes and set the samples
// into the Raster.
int bpp = getBitsPerPixel(sm);
int bytesPerRow = (bpp * srcWidth + 7) / 8;
byte[] buf = new byte[bytesPerRow * srcHeight];
decodeRaw(buf, 0, bpp, bytesPerRow);
reformatDiscontiguousData(buf, bytesPerRow, srcWidth, srcHeight, ras);
}
}
if (colorConverter != null) {
float[] rgb = new float[3];
if (byteData != null) {
for (int j = 0; j < dstHeight; j++) {
int idx = dstOffset;
for (int i = 0; i < dstWidth; i++) {
float x0 = (float) (byteData[idx] & 0xff);
float x1 = (float) (byteData[idx + 1] & 0xff);
float x2 = (float) (byteData[idx + 2] & 0xff);
colorConverter.toRGB(x0, x1, x2, rgb);
byteData[idx] = (byte) (rgb[0]);
byteData[idx + 1] = (byte) (rgb[1]);
byteData[idx + 2] = (byte) (rgb[2]);
idx += 3;
}
dstOffset += scanlineStride;
}
} else if (shortData != null) {
if (sampleFormat[0] == BaselineTIFFTagSet.SAMPLE_FORMAT_SIGNED_INTEGER) {
for (int j = 0; j < dstHeight; j++) {
int idx = dstOffset;
for (int i = 0; i < dstWidth; i++) {
float x0 = (float) shortData[idx];
float x1 = (float) shortData[idx + 1];
float x2 = (float) shortData[idx + 2];
colorConverter.toRGB(x0, x1, x2, rgb);
shortData[idx] = (short) (rgb[0]);
shortData[idx + 1] = (short) (rgb[1]);
shortData[idx + 2] = (short) (rgb[2]);
idx += 3;
}
dstOffset += scanlineStride;
}
} else {
for (int j = 0; j < dstHeight; j++) {
int idx = dstOffset;
for (int i = 0; i < dstWidth; i++) {
float x0 = (float) (shortData[idx] & 0xffff);
float x1 = (float) (shortData[idx + 1] & 0xffff);
float x2 = (float) (shortData[idx + 2] & 0xffff);
colorConverter.toRGB(x0, x1, x2, rgb);
shortData[idx] = (short) (rgb[0]);
shortData[idx + 1] = (short) (rgb[1]);
shortData[idx + 2] = (short) (rgb[2]);
idx += 3;
}
dstOffset += scanlineStride;
}
}
} else if (intData != null) {
for (int j = 0; j < dstHeight; j++) {
int idx = dstOffset;
for (int i = 0; i < dstWidth; i++) {
float x0 = (float) intData[idx];
float x1 = (float) intData[idx + 1];
float x2 = (float) intData[idx + 2];
colorConverter.toRGB(x0, x1, x2, rgb);
intData[idx] = (int) (rgb[0]);
intData[idx + 1] = (int) (rgb[1]);
intData[idx + 2] = (int) (rgb[2]);
idx += 3;
}
dstOffset += scanlineStride;
}
} else if (floatData != null) {
for (int j = 0; j < dstHeight; j++) {
int idx = dstOffset;
for (int i = 0; i < dstWidth; i++) {
float x0 = floatData[idx];
float x1 = floatData[idx + 1];
float x2 = floatData[idx + 2];
colorConverter.toRGB(x0, x1, x2, rgb);
floatData[idx] = rgb[0];
floatData[idx + 1] = rgb[1];
floatData[idx + 2] = rgb[2];
idx += 3;
}
dstOffset += scanlineStride;
}
}
// int[] p = new int[3];
// ras.getPixel(0, 0, p);
// System.out.println("p00 = " +
// p[0] + " " + p[1] + " " + p[2]);
// ras.getPixel(1, 0, p);
// System.out.println("p10 = " +
// p[0] + " " + p[1] + " " + p[2]);
// ras.getPixel(2, 0, p);
// System.out.println("p20 = " +
// p[0] + " " + p[1] + " " + p[2]);
// ras.getPixel(3, 0, p);
// System.out.println("p30 = " +
// p[0] + " " + p[1] + " " + p[2]);
// ColorSpace rgb = ColorSpace.getInstance(ColorSpace.CS_sRGB);
// ColorConvertOp op = new ColorConvertOp(colorSpace, rgb, null);
// WritableRaster dest = op.createCompatibleDestRaster(ras);
// op.filter(ras, dest);
// ras = dest;
}
if (photometricInterpretation == BaselineTIFFTagSet.PHOTOMETRIC_INTERPRETATION_WHITE_IS_ZERO) {
if (byteData != null) {
int bytesPerRow = (srcWidth * pixelBitStride + 7) / 8;
for (int y = 0; y < srcHeight; y++) {
int offset = dstOffset + y * scanlineStride;
for (int i = 0; i < bytesPerRow; i++) {
byteData[offset + i] ^= 0xff;
}
}
} else if (shortData != null) {
int shortsPerRow = (srcWidth * pixelBitStride + 15) / 16;
if (sampleFormat[0] == BaselineTIFFTagSet.SAMPLE_FORMAT_SIGNED_INTEGER) {
for (int y = 0; y < srcHeight; y++) {
int offset = dstOffset + y * scanlineStride;
for (int i = 0; i < shortsPerRow; i++) {
int shortOffset = offset + i;
// XXX Does this make any sense?
shortData[shortOffset] = (short) (Short.MAX_VALUE - shortData[shortOffset]);
}
}
} else {
for (int y = 0; y < srcHeight; y++) {
int offset = dstOffset + y * scanlineStride;
for (int i = 0; i < shortsPerRow; i++) {
shortData[offset + i] ^= 0xffff;
}
}
}
} else if (intData != null) {
int intsPerRow = (srcWidth * pixelBitStride + 15) / 16;
for (int y = 0; y < srcHeight; y++) {
int offset = dstOffset + y * scanlineStride;
for (int i = 0; i < intsPerRow; i++) {
int intOffset = offset + i;
// XXX Does this make any sense?
intData[intOffset] = Integer.MAX_VALUE - intData[intOffset];
}
}
} else if (floatData != null) {
int floatsPerRow = (srcWidth * pixelBitStride + 15) / 16;
for (int y = 0; y < srcHeight; y++) {
int offset = dstOffset + y * scanlineStride;
for (int i = 0; i < floatsPerRow; i++) {
int floatOffset = offset + i;
// XXX Does this make any sense?
floatData[floatOffset] = 1.0F - floatData[floatOffset];
}
}
}
}
if (isBilevel) {
Rectangle rect = isImageSimple ? new Rectangle(dstMinX, dstMinY, dstWidth, dstHeight) : ras.getBounds();
ImageUtil.setPackedBinaryData(byteData, ras, rect);
}
// equals the raster of 'image' or is a child thereof.
if (isDirectCopy) {
// rawImage == image) {
return;
}
}
// Copy the raw image data into the true destination image
Raster src = rawImage.getRaster();
// Create band child of source
Raster srcChild = src.createChild(0, 0, srcWidth, srcHeight, srcMinX, srcMinY, planar ? null : sourceBands);
WritableRaster dst = image.getRaster();
// Create dst child covering area and bands to be written
WritableRaster dstChild = dst.createWritableChild(dstMinX, dstMinY, dstWidth, dstHeight, dstMinX, dstMinY, destinationBands);
if (subsampleX == 1 && subsampleY == 1 && !adjustBitDepths) {
srcChild = srcChild.createChild(activeSrcMinX, activeSrcMinY, activeSrcWidth, activeSrcHeight, dstMinX, dstMinY, null);
dstChild.setRect(srcChild);
} else if (subsampleX == 1 && !adjustBitDepths) {
int sy = activeSrcMinY;
int dy = dstMinY;
while (sy < srcMinY + srcHeight) {
Raster srcRow = srcChild.createChild(activeSrcMinX, sy, activeSrcWidth, 1, dstMinX, dy, null);
dstChild.setRect(srcRow);
sy += subsampleY;
++dy;
}
} else {
// /init vars
int numBands = srcChild.getNumBands();
int sy = activeSrcMinY;
int dy = dstMinY;
// get the databuffer type
final int type = srcChild.getDataBuffer().getDataType();
switch(type) {
case DataBuffer.TYPE_BYTE:
case DataBuffer.TYPE_INT:
case DataBuffer.TYPE_SHORT:
case DataBuffer.TYPE_USHORT:
int[] p = srcChild.getPixel(srcMinX, srcMinY, (int[]) null);
while (sy < activeSrcMinY + activeSrcHeight) {
int sx = activeSrcMinX;
int dx = dstMinX;
while (sx < activeSrcMinX + activeSrcWidth) {
srcChild.getPixel(sx, sy, p);
if (adjustBitDepths) {
for (int band = 0; band < numBands; band++) {
p[band] = bitDepthScale[band][p[band]];
}
}
dstChild.setPixel(dx, dy, p);
sx += subsampleX;
++dx;
}
sy += subsampleY;
++dy;
}
break;
case DataBuffer.TYPE_DOUBLE:
double[] d = srcChild.getPixel(srcMinX, srcMinY, (double[]) null);
while (sy < activeSrcMinY + activeSrcHeight) {
int sx = activeSrcMinX;
int dx = dstMinX;
while (sx < activeSrcMinX + activeSrcWidth) {
srcChild.getPixel(sx, sy, d);
// if (adjustBitDepths) {
// for (int band = 0; band < numBands; band++) {
// d[band] = bitDepthScale[band][d[band]];
// }
// }
dstChild.setPixel(dx, dy, d);
sx += subsampleX;
++dx;
}
sy += subsampleY;
++dy;
}
break;
case DataBuffer.TYPE_FLOAT:
float[] f = srcChild.getPixel(srcMinX, srcMinY, (float[]) null);
while (sy < activeSrcMinY + activeSrcHeight) {
int sx = activeSrcMinX;
int dx = dstMinX;
while (sx < activeSrcMinX + activeSrcWidth) {
srcChild.getPixel(sx, sy, f);
// if (adjustBitDepths) {
// for (int band = 0; band < numBands; band++) {
// d[band] = bitDepthScale[band][d[band]];
// }
// }
dstChild.setPixel(dx, dy, f);
sx += subsampleX;
++dx;
}
sy += subsampleY;
++dy;
}
break;
default:
break;
}
}
}
use of java.awt.image.DataBufferFloat in project javacv by bytedeco.
the class Java2DFrameConverter method copy.
public static void copy(Frame frame, BufferedImage bufferedImage, double gamma, boolean flipChannels, Rectangle roi) {
Buffer in = frame.image[0];
int bufferIndex = roi == null ? 0 : roi.y * frame.imageStride + roi.x * frame.imageChannels;
SampleModel sm = bufferedImage.getSampleModel();
Raster r = bufferedImage.getRaster();
DataBuffer out = r.getDataBuffer();
int x = -r.getSampleModelTranslateX();
int y = -r.getSampleModelTranslateY();
int step = sm.getWidth() * sm.getNumBands();
int channels = sm.getNumBands();
if (sm instanceof ComponentSampleModel) {
step = ((ComponentSampleModel) sm).getScanlineStride();
channels = ((ComponentSampleModel) sm).getPixelStride();
} else if (sm instanceof SinglePixelPackedSampleModel) {
step = ((SinglePixelPackedSampleModel) sm).getScanlineStride();
channels = 1;
} else if (sm instanceof MultiPixelPackedSampleModel) {
step = ((MultiPixelPackedSampleModel) sm).getScanlineStride();
// ??
channels = ((MultiPixelPackedSampleModel) sm).getPixelBitStride() / 8;
}
int start = y * step + x * channels;
if (out instanceof DataBufferByte) {
byte[] a = ((DataBufferByte) out).getData();
flipCopyWithGamma((ByteBuffer) in, bufferIndex, frame.imageStride, ByteBuffer.wrap(a), start, step, false, gamma, false, flipChannels ? channels : 0);
} else if (out instanceof DataBufferDouble) {
double[] a = ((DataBufferDouble) out).getData();
flipCopyWithGamma((DoubleBuffer) in, bufferIndex, frame.imageStride, DoubleBuffer.wrap(a), start, step, gamma, false, flipChannels ? channels : 0);
} else if (out instanceof DataBufferFloat) {
float[] a = ((DataBufferFloat) out).getData();
flipCopyWithGamma((FloatBuffer) in, bufferIndex, frame.imageStride, FloatBuffer.wrap(a), start, step, gamma, false, flipChannels ? channels : 0);
} else if (out instanceof DataBufferInt) {
int[] a = ((DataBufferInt) out).getData();
int stride = frame.imageStride;
if (in instanceof ByteBuffer) {
in = ((ByteBuffer) in).order(flipChannels ? ByteOrder.LITTLE_ENDIAN : ByteOrder.BIG_ENDIAN).asIntBuffer();
stride /= 4;
}
flipCopyWithGamma((IntBuffer) in, bufferIndex, stride, IntBuffer.wrap(a), start, step, gamma, false, flipChannels ? channels : 0);
} else if (out instanceof DataBufferShort) {
short[] a = ((DataBufferShort) out).getData();
flipCopyWithGamma((ShortBuffer) in, bufferIndex, frame.imageStride, ShortBuffer.wrap(a), start, step, true, gamma, false, flipChannels ? channels : 0);
} else if (out instanceof DataBufferUShort) {
short[] a = ((DataBufferUShort) out).getData();
flipCopyWithGamma((ShortBuffer) in, bufferIndex, frame.imageStride, ShortBuffer.wrap(a), start, step, false, gamma, false, flipChannels ? channels : 0);
} else {
assert false;
}
}
Aggregations