28package com.jogamp.nativewindow.awt;
31import java.awt.color.ColorSpace;
32import java.awt.image.BufferedImage;
33import java.awt.image.ColorModel;
34import java.awt.image.DataBuffer;
35import java.awt.image.DirectColorModel;
36import java.awt.image.SampleModel;
37import java.awt.image.SinglePixelPackedSampleModel;
38import java.awt.image.WritableRaster;
39import java.nio.ByteBuffer;
40import java.nio.IntBuffer;
41import java.util.Hashtable;
43import com.jogamp.common.nio.Buffers;
52 super(sampleModel, dataBuffer, origin);
57 final int customImageType;
60 final DirectDataBufferInt dataBuffer,
final WritableRaster raster,
final Hashtable<?,?> properties) {
61 super(cm, raster,
false , properties);
62 this.customImageType = customImageType;
63 this.dataBuffer = dataBuffer;
72 return customImageType;
82 return "BufferedImageInt@"+Integer.toHexString(hashCode())
83 +
": custom/internal type = "+customImageType+
"/"+getType()
84 +
" "+getColorModel()+
" "+getRaster();
110 final ColorSpace colorSpace = ColorSpace.getInstance(ColorSpace.CS_sRGB);
111 final int transferType = DataBuffer.TYPE_INT;
112 final int bpp, rmask, gmask, bmask, amask;
113 final boolean alphaPreMul;
114 switch( imageType ) {
115 case BufferedImage.TYPE_INT_ARGB:
123 case BufferedImage.TYPE_INT_ARGB_PRE:
131 case BufferedImage.TYPE_INT_RGB:
139 case BufferedImage.TYPE_INT_BGR:
148 throw new IllegalArgumentException(
"Unsupported imageType, must be [INT_ARGB, INT_ARGB_PRE, INT_RGB, INT_BGR], has "+imageType);
150 final ColorModel colorModel =
new DirectColorModel(colorSpace, bpp, rmask, gmask, bmask, amask, alphaPreMul, transferType);
151 final int[] bandMasks;
153 bandMasks =
new int[4];
154 bandMasks[3] = amask;
157 bandMasks =
new int[3];
159 bandMasks[0] = rmask;
160 bandMasks[1] = gmask;
161 bandMasks[2] = bmask;
164 if(
null == location ) {
165 location =
new Point(0,0);
167 final SinglePixelPackedSampleModel sppsm =
new SinglePixelPackedSampleModel(dataBuffer.getDataType(),
168 width, height, width , bandMasks);
175 return new BufferedImageInt(imageType, colorModel, dataBuffer, raster, properties);
179 private final ByteBuffer dataBytes;
181 private final IntBuffer dataInts;
184 private final ByteBuffer bankdataBytes[];
186 private final IntBuffer bankdataInts[];
195 super(TYPE_INT, size);
196 dataBytes = Buffers.newDirectByteBuffer(size * Buffers.SIZEOF_INT);
197 dataInts = dataBytes.asIntBuffer();
198 bankdataBytes =
new ByteBuffer[1];
199 bankdataInts =
new IntBuffer[1];
200 bankdataBytes[0] = dataBytes;
201 bankdataInts[0] = dataInts;
212 super(TYPE_INT,size,numBanks);
213 bankdataBytes =
new ByteBuffer[numBanks];
214 bankdataInts =
new IntBuffer[numBanks];
215 for (
int i= 0; i < numBanks; i++) {
216 bankdataBytes[i] = Buffers.newDirectByteBuffer(size * Buffers.SIZEOF_INT);
217 bankdataInts[i] = bankdataBytes[i].asIntBuffer();
219 dataBytes = bankdataBytes[0];
220 dataInts = bankdataInts[0];
236 super(TYPE_INT,size);
237 dataBytes = Buffers.nativeOrder(dataArray);
238 dataInts = dataBytes.asIntBuffer();
239 bankdataBytes =
new ByteBuffer[1];
240 bankdataInts =
new IntBuffer[1];
241 bankdataBytes[0] = dataBytes;
242 bankdataInts[0] = dataInts;
272 return bankdataInts[bank];
282 return bankdataBytes[bank];
295 return dataInts.get(i+offset);
308 public int getElem(
final int bank,
final int i) {
309 return bankdataInts[bank].get(i+offsets[bank]);
322 public void setElem(
final int i,
final int val) {
323 dataInts.put(i+offset, val);
336 public void setElem(
final int bank,
final int i,
final int val) {
337 bankdataInts[bank].put(i+offsets[bank], val);
BufferedImageInt(final int customImageType, final ColorModel cm, final DirectDataBufferInt dataBuffer, final WritableRaster raster, final Hashtable<?,?> properties)
DirectDataBufferInt getDataBuffer()
Returns the underlying DirectDataBufferInt associated with this instance via Raster instance.
DirectWritableRaster(final SampleModel sampleModel, final DirectDataBufferInt dataBuffer, final Point origin)
DataBuffer specialization using NIO direct buffer of type DataBuffer#TYPE_INT as storage.
DirectDataBufferInt(final int size)
Constructs an nio integer-based DataBuffer with a single bank and the specified size.
int getElem(final int bank, final int i)
Returns the requested data array element from the specified bank.
int getElem(final int i)
Returns the requested data array element from the first (default) bank.
IntBuffer getData()
Returns the default (first) int data array in DataBuffer as an IntBuffer representation.
IntBuffer getData(final int bank)
Returns the data array for the specified bank as an IntBuffer representation.
static BufferedImageInt createBufferedImage(final int width, final int height, final int imageType, Point location, final Hashtable<?,?> properties)
Creates a BufferedImageInt using a direct color model in sRGB color space.
ByteBuffer getDataBytes()
Returns the default (first) int data array in DataBuffer as a ByteBuffer representation.
DirectDataBufferInt(final ByteBuffer dataArray, final int size)
Constructs an nio integer-based DataBuffer with a single bank using the specified array.
void setElem(final int bank, final int i, final int val)
Sets the requested data array element in the specified bank to the integer value i.
DirectDataBufferInt(final int size, final int numBanks)
Constructs an nio integer-based DataBuffer with the specified number of banks, all of which are the s...
ByteBuffer getDataBytes(final int bank)
Returns the data array for the specified bank as a ByteBuffer representation.
void setElem(final int i, final int val)
Sets the requested data array element in the first (default) bank to the specified value.