public abstract class PixelFormat<T extends Buffer> extends Object
PixelFormat
object defines the layout of data for a pixel of
a given format.Modifier and Type | Class and Description |
---|---|
static class |
PixelFormat.Type
An enum describing the in-array storage format of a single pixel
managed by a
PixelFormat . |
Modifier and Type | Method and Description |
---|---|
static PixelFormat<ByteBuffer> |
createByteIndexedInstance(int[] colors)
Creates a
PixelFormat instance describing a pixel layout
with the pixels stored as single bytes representing an index
into the specified lookup table of non-premultiplied color
values in the INT_ARGB format. |
static PixelFormat<ByteBuffer> |
createByteIndexedPremultipliedInstance(int[] colors)
Creates a
PixelFormat instance describing a pixel layout
with the pixels stored as single bytes representing an index
into the specified lookup table of premultiplied color
values in the INT_ARGB_PRE format. |
abstract int |
getArgb(T buf,
int x,
int y,
int scanlineStride)
Reads pixel data from the buffer at the specified coordinates and
converts it to a 32-bit integer representation of the color in the
INT_ARGB format. |
static WritablePixelFormat<ByteBuffer> |
getByteBgraInstance()
Returns a
WritablePixelFormat instance describing a pixel
layout with the pixels stored in adjacent bytes with the
non-premultiplied components stored in order of increasing index:
blue, green, red, alpha. |
static WritablePixelFormat<ByteBuffer> |
getByteBgraPreInstance()
Returns a
WritablePixelFormat instance describing a pixel
layout with the pixels stored in adjacent bytes with the
premultiplied components stored in order of increasing index:
blue, green, red, alpha. |
static PixelFormat<ByteBuffer> |
getByteRgbInstance()
Returns a
PixelFormat instance describing a pixel
layout with the pixels stored in adjacent bytes with the
color components stored in order of increasing index:
red, green, blue. |
static WritablePixelFormat<IntBuffer> |
getIntArgbInstance()
Returns a
WritablePixelFormat instance describing a pixel
layout with the pixels stored in 32-bit integers with the
non-premultiplied components stored in order, from MSb to LSb:
alpha, red, green, blue. |
static WritablePixelFormat<IntBuffer> |
getIntArgbPreInstance()
Returns a
WritablePixelFormat instance describing a pixel
layout with the pixels stored in 32-bit integers with the
premultiplied components stored in order, from MSb to LSb:
alpha, red, green, blue. |
PixelFormat.Type |
getType()
Returns the enum representing the storage format of the pixels
managed by this
PixelFormat object. |
abstract boolean |
isPremultiplied()
Returns true iff the color components decoded (or encoded) by this
format are pre-multiplied by the alpha component for more efficient
blending calculations.
|
abstract boolean |
isWritable()
Returns true iff this
PixelFormat object can convert
color information into a pixel representation. |
public static WritablePixelFormat<IntBuffer> getIntArgbInstance()
WritablePixelFormat
instance describing a pixel
layout with the pixels stored in 32-bit integers with the
non-premultiplied components stored in order, from MSb to LSb:
alpha, red, green, blue.
Pixels in this format can be decoded using the following sample code:
int pixel = array[rowstart + x]; int alpha = ((pixel >> 24) & 0xff); int red = ((pixel >> 16) & 0xff); int green = ((pixel >> 8) & 0xff); int blue = ((pixel ) & 0xff);
WritabelPixelFormat<IntBuffer>
describing the
indicated pixel formatpublic static WritablePixelFormat<IntBuffer> getIntArgbPreInstance()
WritablePixelFormat
instance describing a pixel
layout with the pixels stored in 32-bit integers with the
premultiplied components stored in order, from MSb to LSb:
alpha, red, green, blue.
Pixels in this format can be decoded using the following sample code:
int pixel = array[rowstart + x]; int alpha = ((pixel >> 24) & 0xff); int red = ((pixel >> 16) & 0xff); int green = ((pixel >> 8) & 0xff); int blue = ((pixel ) & 0xff);
WritabelPixelFormat<IntBuffer>
describing the
indicated pixel formatpublic static WritablePixelFormat<ByteBuffer> getByteBgraInstance()
WritablePixelFormat
instance describing a pixel
layout with the pixels stored in adjacent bytes with the
non-premultiplied components stored in order of increasing index:
blue, green, red, alpha.
Pixels in this format can be decoded using the following sample code:
int i = rowstart + x * 4; int blue = (array[i+0] & 0xff); int green = (array[i+1] & 0xff); int red = (array[i+2] & 0xff); int alpha = (array[i+3] & 0xff);
WritablePixelFormat<ByteBuffer>
describing the
indicated pixel formatpublic static WritablePixelFormat<ByteBuffer> getByteBgraPreInstance()
WritablePixelFormat
instance describing a pixel
layout with the pixels stored in adjacent bytes with the
premultiplied components stored in order of increasing index:
blue, green, red, alpha.
Pixels in this format can be decoded using the following sample code:
int i = rowstart + x * 4; int blue = (array[i+0] & 0xff); int green = (array[i+1] & 0xff); int red = (array[i+2] & 0xff); int alpha = (array[i+3] & 0xff);
WritablePixelFormat<ByteBuffer>
describing the
indicated pixel formatpublic static PixelFormat<ByteBuffer> getByteRgbInstance()
PixelFormat
instance describing a pixel
layout with the pixels stored in adjacent bytes with the
color components stored in order of increasing index:
red, green, blue.
Pixels in this format can be decoded using the following sample code:
int i = rowstart + x * 3; int red = (array[i+0] & 0xff); int green = (array[i+1] & 0xff); int blue = (array[i+2] & 0xff);
PixelFormat<ByteBuffer>
describing the
indicated pixel formatpublic static PixelFormat<ByteBuffer> createByteIndexedPremultipliedInstance(int[] colors)
PixelFormat
instance describing a pixel layout
with the pixels stored as single bytes representing an index
into the specified lookup table of premultiplied color
values in the INT_ARGB_PRE
format.
Pixels in this format can be decoded using the following sample code:
int pixel = array[rowstart + x] & 0xff; int argb = colors[pixel]; int alpha = ((argb >> 24) & 0xff); int red = ((argb >> 16) & 0xff); int green = ((argb >> 8) & 0xff); int blue = ((argb ) & 0xff);
colors
- an int[]
array of 32-bit color values in
the INT_ARGB_PRE
formatPixelFormat<ByteBuffer>
describing the indicated
pixel format with the specified list of premultiplied colorspublic static PixelFormat<ByteBuffer> createByteIndexedInstance(int[] colors)
PixelFormat
instance describing a pixel layout
with the pixels stored as single bytes representing an index
into the specified lookup table of non-premultiplied color
values in the INT_ARGB
format.
Pixels in this format can be decoded using the following sample code:
int pixel = array[rowstart + x] & 0xff; int argb = colors[pixel]; int alpha = ((argb >> 24) & 0xff); int red = ((argb >> 16) & 0xff); int green = ((argb >> 8) & 0xff); int blue = ((argb ) & 0xff);
colors
- an int[]
array of 32-bit color values in
the INT_ARGB
formatPixelFormat<ByteBuffer>
describing the indicated
pixel format with the specified list of non-premultiplied colorspublic PixelFormat.Type getType()
PixelFormat
object.Type
enum of the pixelspublic abstract boolean isWritable()
PixelFormat
object can convert
color information into a pixel representation.PixelFormat
can convert colors to
pixel datapublic abstract boolean isPremultiplied()
public abstract int getArgb(T buf, int x, int y, int scanlineStride)
INT_ARGB
format.
The 32-bit integer will contain the 4 color components in separate
8-bit fields in ARGB order from the most significant byte to the least
significant byte.
The buffer should be positioned to the start of the pixel data such
that buf.get(0)
would return the pixel information for the
pixel at coordinates (0, 0)
.
The scanlineStride
parameter defines the distance from the pixel
data at the start of one row to the pixel data at the start of the
immediately following row at the next higher Y coordinate. Usually,
scanlineStride
is the same as the width of the image multiplied
by the number of data elements per pixel (1 for the case of the
integer and indexed formats, or 3 or 4 in the case of the byte
formats), but some images may have further padding between rows for
alignment or other purposes.
The color components can be extracted from the returned integer using the following sample code:
int alpha = ((retval >> 24) & 0xff); int red = ((retval >> 16) & 0xff); int green = ((retval >> 8) & 0xff); int blue = ((retval ) & 0xff);
buf
- the buffer of pixel datax
- the X coordinate of the pixel to be ready
- the Y coordinate of the pixel to be readscanlineStride
- the number of buffer elements between the
start of adjacent pixel rows in the bufferINT_ARGB
pixel formatCopyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.