public class YUVImage
extends java.lang.Object
YUVImage
instance
serves as the destination image for YUV encode and decompress-to-YUV
operations and as the source image for compress-from-YUV and YUV decode
operations.
Technically, the JPEG format uses the YCbCr colorspace (which technically is not a "colorspace" but rather a "color transform"), but per the convention of the digital video community, the TurboJPEG API uses "YUV" to refer to an image format consisting of Y, Cb, and Cr image planes.
Each plane is simply a 2D array of bytes, each byte representing the value of one of the components at a particular location in the image. The "component width" and "component height" of each plane are determined by the image width, height, and level of chrominance subsampling. For the luminance plane, the component width is the image width padded to the nearest multiple of the horizontal subsampling factor (2 in the case of 4:2:0 and 4:2:2, 4 in the case of 4:1:1, 1 in the case of 4:4:4 or grayscale.) Similarly, the component height of the luminance plane is the image height padded to the nearest multiple of the vertical subsampling factor (2 in the case of 4:2:0 or 4:4:0, 1 in the case of 4:4:4 or grayscale.) The component width of the chrominance planes is equal to the component width of the luminance plane divided by the horizontal subsampling factor, and the component height of the chrominance planes is equal to the component height of the luminance plane divided by the vertical subsampling factor.
For example, if the source image is 35 x 35 pixels and 4:2:2 subsampling is used, then the luminance plane would be 36 x 35 bytes, and each of the chrominance planes would be 18 x 35 bytes. If you specify a line padding of 4 bytes on top of this, then the luminance plane would be 36 x 35 bytes, and each of the chrominance planes would be 20 x 35 bytes.
Modifier and Type | Field and Description |
---|---|
protected long |
handle |
protected byte[] |
yuvBuf |
protected int |
yuvHeight |
protected int |
yuvPad |
protected int |
yuvSubsamp |
protected int |
yuvWidth |
Constructor and Description |
---|
YUVImage(byte[] yuvImage,
int width,
int pad,
int height,
int subsamp)
Create a
YUVImage instance from an existing YUV planar image
buffer. |
YUVImage(int width,
int pad,
int height,
int subsamp)
Create a
YUVImage instance with a new image buffer. |
Modifier and Type | Method and Description |
---|---|
byte[] |
getBuf()
Returns the YUV image buffer
|
int |
getHeight()
Returns the height of the YUV image.
|
int |
getPad()
Returns the line padding used in the YUV image buffer.
|
int |
getSize()
Returns the size (in bytes) of the YUV image buffer
|
int |
getSubsamp()
Returns the level of chrominance subsampling used in the YUV image.
|
int |
getWidth()
Returns the width of the YUV image.
|
void |
setBuf(byte[] yuvImage,
int width,
int pad,
int height,
int subsamp)
Assign an existing YUV planar image buffer to this
YUVImage
instance. |
protected long handle
protected byte[] yuvBuf
protected int yuvPad
protected int yuvWidth
protected int yuvHeight
protected int yuvSubsamp
public YUVImage(int width, int pad, int height, int subsamp) throws java.lang.Exception
YUVImage
instance with a new image buffer.width
- width (in pixels) of the YUV imagepad
- Each line of each plane in the YUV image buffer will be padded
to this number of bytes (must be a power of 2.)height
- height (in pixels) of the YUV imagesubsamp
- the level of chrominance subsampling to be used in the YUV
image (one of TJ.SAMP_*
)java.lang.Exception
public YUVImage(byte[] yuvImage, int width, int pad, int height, int subsamp) throws java.lang.Exception
YUVImage
instance from an existing YUV planar image
buffer.yuvImage
- image buffer that contains or will contain YUV planar
image data. Use TJ.bufSizeYUV(int, int, int, int)
to determine the minimum size for
this buffer. The Y, U (Cb), and V (Cr) image planes are stored
sequentially in the buffer (see above
for a description
of the image format.)width
- width (in pixels) of the YUV imagepad
- the line padding used in the YUV image buffer. For
instance, if each line in each plane of the buffer is padded to the
nearest multiple of 4 bytes, then pad
should be set to 4.height
- height (in pixels) of the YUV imagesubsamp
- the level of chrominance subsampling used in the YUV
image (one of TJ.SAMP_*
)java.lang.Exception
public void setBuf(byte[] yuvImage, int width, int pad, int height, int subsamp) throws java.lang.Exception
YUVImage
instance.yuvImage
- image buffer that contains or will contain YUV planar
image data. Use TJ.bufSizeYUV(int, int, int, int)
to determine the minimum size for
this buffer. The Y, U (Cb), and V (Cr) image planes are stored
sequentially in the buffer (see above
for a description
of the image format.)width
- width (in pixels) of the YUV imagepad
- the line padding used in the YUV image buffer. For
instance, if each line in each plane of the buffer is padded to the
nearest multiple of 4 bytes, then pad
should be set to 4.height
- height (in pixels) of the YUV imagesubsamp
- the level of chrominance subsampling used in the YUV
image (one of TJ.SAMP_*
)java.lang.Exception
public int getWidth() throws java.lang.Exception
java.lang.Exception
public int getHeight() throws java.lang.Exception
java.lang.Exception
public int getPad() throws java.lang.Exception
java.lang.Exception
public int getSubsamp() throws java.lang.Exception
TJ.SAMP_*
.java.lang.Exception
public byte[] getBuf() throws java.lang.Exception
java.lang.Exception
public int getSize() throws java.lang.Exception
java.lang.Exception