28package com.jogamp.opengl.util.awt;
30import java.awt.image.BufferedImage;
31import java.awt.image.ColorModel;
32import java.awt.image.DataBuffer;
33import java.awt.image.DataBufferInt;
34import java.awt.image.Raster;
35import java.awt.image.SinglePixelPackedSampleModel;
36import java.awt.image.WritableRaster;
37import java.nio.Buffer;
38import java.nio.IntBuffer;
39import java.util.Iterator;
41import com.jogamp.nativewindow.util.PixelFormat;
42import com.jogamp.opengl.GL;
43import com.jogamp.opengl.GLProfile;
45import com.jogamp.common.nio.Buffers;
46import com.jogamp.common.util.IntObjectHashMap;
47import com.jogamp.opengl.util.GLPixelBuffer;
78 public final BufferedImage
image;
80 private final PixelFormat.Composition hostPixelComp;
81 private final int awtFormat;
104 this.hostPixelComp = hostPixelComp;
105 this.awtFormat = awtFormat;
126 throw new IllegalArgumentException(
"Requested size exceeds image size: "+
width+
"x"+
height+
" > "+
image.getWidth()+
"x"+
image.getHeight());
131 final ColorModel cm =
image.getColorModel();
132 final WritableRaster raster0 =
image.getRaster();
133 final DataBuffer dataBuffer = raster0.getDataBuffer();
134 final SinglePixelPackedSampleModel sppsm0 = (SinglePixelPackedSampleModel) raster0.getSampleModel();
135 final SinglePixelPackedSampleModel sppsm1 =
new SinglePixelPackedSampleModel(dataBuffer.getDataType(),
137 final WritableRaster raster1 = Raster.createWritableRaster(sppsm1, dataBuffer,
null);
138 return new BufferedImage (cm, raster1, cm.isAlphaPremultiplied(),
null);
143 final DataBuffer dataBuffer0 =
image.getRaster().getDataBuffer();
144 final DataBuffer dataBufferU = imageU.getRaster().getDataBuffer();
145 return dataBufferU == dataBuffer0;
150 sb = super.toString(sb);
151 sb.append(
", allowRowStride ").append(
allowRowStride).append(
", image [").append(
image.getWidth()).append(
"x").append(
image.getHeight()).append(
", ").append(
image.toString()).append(
"]");
156 return "AWTGLPixelBuffer["+
toString(
null).toString()+
"]";
163 private final boolean allowRowStride;
171 this.allowRowStride = allowRowStride;
179 return gl.
isGLES() ? awtPixelAttributesIntRGBA : awtPixelAttributesIntBGRA;
183 return glp.
isGLES() ? awtPixelAttributesIntRGBA : awtPixelAttributesIntBGRA;
210 if( 4 == componentCount ) {
212 return glp.
isGLES() ? BufferedImage.TYPE_INT_BGR : BufferedImage.TYPE_INT_ARGB;
214 return glp.
isGLES() ? BufferedImage.TYPE_INT_BGR : BufferedImage.TYPE_INT_RGB;
219 if( 4 == componentCount ) {
234 final int width,
final int height,
final int depth,
final int minByteSize) {
235 if(
null == hostPixComp ) {
236 throw new IllegalArgumentException(
"Null hostPixComp");
240 final int[] readBackIntBuffer = ((DataBufferInt)
image.getRaster().getDataBuffer()).getData();
241 final Buffer ibuffer = IntBuffer.wrap( readBackIntBuffer );
258 private final IntObjectHashMap bufferMap =
new IntObjectHashMap(8);
262 int hash = hostPixelComp.hashCode();
272 super(allowRowStride);
283 final boolean pack,
final int width,
final int height,
final int depth,
final int minByteSize) {
284 if(
null == hostPixComp ) {
295 bufferMap.put(bufferKey, r);
304 final int minByteSize) {
306 final int[] readBackIntBuffer = ((DataBufferInt)
image.getRaster().getDataBuffer()).getData();
307 final Buffer ibuffer = IntBuffer.wrap( readBackIntBuffer );
330 final int awtFormat =
getAWTFormat(glp, componentCount);
337 bufferMap.put(bufferKey, r);
343 for(
final Iterator<IntObjectHashMap.Entry> i=bufferMap.iterator(); i.hasNext(); ) {
Specifies the the OpenGL profile.
final boolean isGLES()
Indicates whether this profile is capable of GLES.
final PixelFormat pfmt
PixelFormat describing the component layout
OpenGL pixel data buffer, allowing user to provide buffers via their GLPixelBufferProvider implementa...
final int width
Width in pixels, representing buffer's byteSize.
final boolean allowRowStride
Allow GL2ES3#GL_PACK_ROW_LENGTH, or GL2ES2#GL_UNPACK_ROW_LENGTH.
final int depth
Depth in pixels.
final int height
Height in pixels, representing buffer's byteSize.
final GLPixelAttributes pixelAttributes
The GLPixelAttributes.
boolean requiresNewBuffer(final GL gl, final int newWidth, final int newHeight, int newByteSize)
Returns true, if invalid or implementation requires a new buffer based on the new size due to pixel a...
final boolean pack
Data packing direction.
final Buffer buffer
Buffer holding the pixel data.
Provider for AWTGLPixelBuffer instances.
AWTGLPixelBuffer allocate(final GL gl, final PixelFormat.Composition hostPixComp, final GLPixelAttributes pixelAttributes, final boolean pack, final int width, final int height, final int depth, final int minByteSize)
Allocates a new GLPixelBuffer object.The minimum required remaining byte size equals to minByteSize,...
GLPixelAttributes getAttributes(final GLProfile glp, final int componentCount)
AWTGLPixelBufferProvider(final boolean allowRowStride)
GLPixelAttributes getAttributes(final GL gl, final int componentCount, final boolean pack)
Returns RGB[A] GLPixelAttributes matching GL, componentCount and pack.
int getAWTFormat(final GLProfile glp, final int componentCount)
Returns one of.
PixelFormat.Composition getHostPixelComp(final GLProfile glp, final int componentCount)
Returns the host PixelFormat.Composition matching GL and componentCount if required by implementation...
PixelFormat getAWTPixelFormat(final GLProfile glp, final int componentCount)
boolean getAllowRowStride()
Allow GL2ES3#GL_PACK_ROW_LENGTH, or GL2ES2#GL_UNPACK_ROW_LENGTH.
Provider for singleton AWTGLPixelBuffer instances.
AWTGLPixelBuffer allocate(final GL gl, PixelFormat.Composition hostPixComp, final GLPixelAttributes pixelAttributes, final boolean pack, final int width, final int height, final int depth, final int minByteSize)
Allocates a new GLPixelBuffer object.The minimum required remaining byte size equals to minByteSize,...
AWTGLPixelBuffer initSingleton(final GLProfile glp, final int componentCount, final boolean pack, final int width, final int height, final int depth)
Initializes the single AWTGLPixelBuffer w/ a given size, if not yet allocated.
SingleAWTGLPixelBufferProvider(final boolean allowRowStride)
AWTGLPixelBuffer getSingleBuffer(final PixelFormat.Composition hostPixelComp, final GLPixelAttributes pixelAttributes, final boolean pack)
Return the last allocated AWTGLPixelBuffer, if compatible w/ the given PixelFormat....
void dispose()
Dispose all resources.
AWT GLPixelBuffer backed by an BufferedImage of type BufferedImage#TYPE_INT_ARGB or BufferedImage#TYP...
final BufferedImage image
The underlying BufferedImage.
BufferedImage getAlignedImage(final int width, final int height)
Returns a width- and height-aligned image representation sharing data w/ image.
void dispose()
Dispose resources.
StringBuilder toString(StringBuilder sb)
final PixelFormat.Composition getHostPixelComp()
AWTGLPixelBuffer(final PixelFormat.Composition hostPixelComp, final GLPixelAttributes pixelAttributes, final boolean pack, final int awtFormat, final int width, final int height, final int depth, final BufferedImage image, final Buffer buffer, final boolean allowRowStride)
final boolean isDataBufferSource(final BufferedImage imageU)
boolean isGLES()
Indicates whether this GL object conforms to one of the OpenGL ES profiles, see isGLES1(),...
GLProfile getGLProfile()
Returns the GLProfile associated with this GL object.
static final int GL_BGRA
GL_VERSION_1_2, GL_IMG_read_format, GL_APPLE_texture_format_BGRA8888, GL_EXT_texture_format_BGRA8888,...
static final int GL_RGBA
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_RGBA" with expression...
static final int GL_UNSIGNED_BYTE
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_UNSIGNED_BYTE" with e...
Allows user to interface with another toolkit to define GLPixelAttributes and memory buffer to produc...
Single GLPixelBuffer provider.