Function libwebp::WebPDecodeYUV
source · pub fn WebPDecodeYUV(
data: &[u8]
) -> Result<(u32, u32, u32, u32, WebpYuvBox), WebPSimpleError>
Expand description
Decodes WebP images pointed to by data
to Y’UV format1.
1 Also named Y’CbCr. See: http://en.wikipedia.org/wiki/YCbCr
Return value
It retuns a tuple with the following data in this order:
- width
- height
- stride
- uv_stride
- a
WebpYuvBox
which contains the pointers to the Y, U and V planes.
The dimension of the U and V planes are both (width + 1) / 2
and (height + 1)/ 2
.
The Y buffer has a stride returned as stride
, while U and V
have a common stride returned as uv_stride
.
Errors
Returns Err
if data
doesn’t contain a valid WebP image.
Examples
use libwebp::WebPDecodeYUV;
let data: &[u8];
let (width, height, stride, uv_stride, buf) =
WebPDecodeYUV(data).expect("Invalid WebP data");
assert!(width <= stride);
assert!((width + 1) / 2 <= uv_stride);
assert_eq!(buf.y().len(), stride as usize * height as usize);
assert_eq!(buf.u().len(), uv_stride as usize * ((height as usize + 1) / 2));
assert_eq!(buf.v().len(), uv_stride as usize * ((height as usize + 1) / 2));
eprintln!(
"top-left pixel: yuv({}, {}, {})",
buf.y()[0],
buf.u()[0],
buf.v()[0],
)