YuvImage
public
class
YuvImage
extends Object
YuvImage contains YUV data and provides a method that compresses a region of
the YUV data to a Jpeg. The YUV data should be provided as a single byte
array irrespective of the number of image planes in it.
Currently only ImageFormat.NV21 and ImageFormat.YUY2 are supported.
To compress a rectangle region in the YUV data, users have to specify the
region by left, top, width and height.
Summary
Public constructors |
YuvImage(byte[] yuv, int format, int width, int height, int[] strides)
Construct an YuvImage.
|
YuvImage(byte[] yuv, int format, int width, int height, int[] strides, ColorSpace colorSpace)
Construct an YuvImage.
|
Inherited methods |
From class
java.lang.Object
Object
|
clone()
Creates and returns a copy of this object.
|
boolean
|
equals(Object obj)
Indicates whether some other object is "equal to" this one.
|
void
|
finalize()
Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.
|
final
Class<?>
|
getClass()
Returns the runtime class of this Object .
|
int
|
hashCode()
Returns a hash code value for the object.
|
final
void
|
notify()
Wakes up a single thread that is waiting on this object's
monitor.
|
final
void
|
notifyAll()
Wakes up all threads that are waiting on this object's monitor.
|
String
|
toString()
Returns a string representation of the object.
|
final
void
|
wait(long timeoutMillis, int nanos)
Causes the current thread to wait until it is awakened, typically
by being notified or interrupted, or until a
certain amount of real time has elapsed.
|
final
void
|
wait(long timeoutMillis)
Causes the current thread to wait until it is awakened, typically
by being notified or interrupted, or until a
certain amount of real time has elapsed.
|
final
void
|
wait()
Causes the current thread to wait until it is awakened, typically
by being notified or interrupted.
|
|
Public constructors
YuvImage
public YuvImage (byte[] yuv,
int format,
int width,
int height,
int[] strides)
Construct an YuvImage. Use SRGB for as default ColorSpace
.
Parameters |
yuv |
byte : The YUV data. In the case of more than one image plane, all the planes must be
concatenated into a single byte array. |
format |
int : The YUV data format as defined in ImageFormat . |
width |
int : The width of the YuvImage. |
height |
int : The height of the YuvImage. |
strides |
int : (Optional) Row bytes of each image plane. If yuv contains padding, the stride
of each image must be provided. If strides is null, the method assumes no
padding and derives the row bytes by format and width itself. |
YuvImage
public YuvImage (byte[] yuv,
int format,
int width,
int height,
int[] strides,
ColorSpace colorSpace)
Construct an YuvImage.
Parameters |
yuv |
byte : The YUV data. In the case of more than one image plane, all the planes
must be concatenated into a single byte array.
This value cannot be null . |
format |
int : The YUV data format as defined in ImageFormat . |
width |
int : The width of the YuvImage. |
height |
int : The height of the YuvImage. |
strides |
int : (Optional) Row bytes of each image plane. If yuv contains padding, the
stride of each image must be provided. If strides is null, the method
assumes no padding and derives the row bytes by format and width itself. |
colorSpace |
ColorSpace : The YUV image color space as defined in ColorSpace .
If the parameter is null, SRGB will be set as the default value. |
Public methods
compressToJpeg
public boolean compressToJpeg (Rect rectangle,
int quality,
OutputStream stream)
Compress a rectangle region in the YuvImage to a jpeg.
For image format, only ImageFormat.NV21 and ImageFormat.YUY2 are supported.
For color space, only SRGB is supported.
Parameters |
rectangle |
Rect : The rectangle region to be compressed. The medthod checks if rectangle is
inside the image. Also, the method modifies rectangle if the chroma pixels
in it are not matched with the luma pixels in it. |
quality |
int : Hint to the compressor, 0-100. 0 meaning compress for
small size, 100 meaning compress for max quality. |
stream |
OutputStream : OutputStream to write the compressed data. |
Returns |
boolean |
True if the compression is successful. |
Throws |
IllegalArgumentException |
if rectangle is invalid; color space or image format
is not supported; quality is not within [0, 100]; or stream is null. |
compressToJpegR
public boolean compressToJpegR (YuvImage sdr,
int quality,
OutputStream stream)
Compress the HDR image into JPEG/R format.
Sample usage:
hdr_image.compressToJpegR(sdr_image, 90, stream);
For the SDR image, only YUV_420_888 image format is supported, and the following
color spaces are supported:
ColorSpace.Named.SRGB,
ColorSpace.Named.DISPLAY_P3
For the HDR image, only YCBCR_P010 image format is supported, and the following
color spaces are supported:
ColorSpace.Named.BT2020_HLG,
ColorSpace.Named.BT2020_PQ
Parameters |
sdr |
YuvImage : The SDR image, only ImageFormat.YUV_420_888 is supported.
This value cannot be null . |
quality |
int : Hint to the compressor, 0-100. 0 meaning compress for
small size, 100 meaning compress for max quality. |
stream |
OutputStream : OutputStream to write the compressed data.
This value cannot be null . |
Returns |
boolean |
True if the compression is successful. |
compressToJpegR
public boolean compressToJpegR (YuvImage sdr,
int quality,
OutputStream stream,
byte[] exif)
Compress the HDR image into JPEG/R format.
Sample usage:
hdr_image.compressToJpegR(sdr_image, 90, stream);
For the SDR image, only YUV_420_888 image format is supported, and the following
color spaces are supported:
ColorSpace.Named.SRGB,
ColorSpace.Named.DISPLAY_P3
For the HDR image, only YCBCR_P010 image format is supported, and the following
color spaces are supported:
ColorSpace.Named.BT2020_HLG,
ColorSpace.Named.BT2020_PQ
Parameters |
sdr |
YuvImage : The SDR image, only ImageFormat.YUV_420_888 is supported.
This value cannot be null . |
quality |
int : Hint to the compressor, 0-100. 0 meaning compress for
small size, 100 meaning compress for max quality. |
stream |
OutputStream : OutputStream to write the compressed data.
This value cannot be null . |
exif |
byte : Exchangeable image file format.
This value cannot be null . |
Returns |
boolean |
True if the compression is successful. |
getColorSpace
public ColorSpace getColorSpace ()
Returns |
ColorSpace |
the color space of the image.
This value cannot be null . |
getHeight
public int getHeight ()
Returns |
int |
the height of the image. |
getStrides
public int[] getStrides ()
Returns |
int[] |
the number of row bytes in each image plane. |
getWidth
public int getWidth ()
Returns |
int |
the width of the image. |
getYuvData
public byte[] getYuvData ()
Returns |
byte[] |
the YUV data. |
public int getYuvFormat ()