[−][src]Function dcv_color_primitives::convert_image
pub fn convert_image(
width: u32,
height: u32,
src_format: &ImageFormat,
src_strides: Option<&[usize]>,
src_buffers: &[&[u8]],
dst_format: &ImageFormat,
dst_strides: Option<&[usize]>,
dst_buffers: &mut [&mut [u8]]
) -> Result<(), ErrorKind>
Converts from a color space to another one, applying downsampling/upsampling to match destination image format.
Arguments
width
- Width of the image to convert in pixelsheight
- Height of the image to convert in pixelssrc_format
- Source image formatsrc_strides
- An array of distances in bytes between starts of consecutive lines in each source image planessrc_buffers
- An array of image buffers in each source color planedst_format
- Destination image formatdst_strides
- An array of distances in bytes between starts of consecutive lines in each destination image planesdst_buffers
- An array of image buffers in each destination color plane
Errors
-
NotInitialized
if the library was not initialized before -
InvalidValue
ifwidth
orheight
violate thesize constraints
that might by imposed by the source and destination image pixel formats -
InvalidValue
if source or destination image formats have a number of planes which is not compatible with their pixel formats -
InvalidOperation
if there is no available method to convert the image with the source pixel format to the image with the destination pixel format.The list of available conversions is specified here:
Source image pixel format Supported destination image pixel formats PixelFormat::Argb PixelFormat::Nv12 1
PixelFormat::Bgra PixelFormat::Nv12 1
PixelFormat::Bgr PixelFormat::Nv12 1
PixelFormat::Nv12 PixelFormat::Bgra 2
-
NotEnoughData
if the source stride array is notNone
and its length is less than the source image format number of planes -
NotEnoughData
if the destination stride array is notNone
and its length is less than the destination image format number of planes -
NotEnoughData
if one or more source/destination buffers does not provide enough data.The minimum number of bytes to provide for each buffer depends from the image format, dimensions, and strides (if they are not
None
).You can compute the buffers' size using
get_buffers_size
Algorithm 1
Conversion from linear RGB model to YCbCr color model, with 4:2:0 downsampling
If the destination image color space is Bt601, the following formula is applied:
y = 0.257 * r + 0.504 * g + 0.098 * b + 16
cb = -0.148 * r - 0.291 * g + 0.439 * b + 128
cr = 0.439 * r - 0.368 * g - 0.071 * b + 128
If the destination image color space is Bt709, the following formula is applied:
y = 0.213 * r + 0.715 * g + 0.072 * b + 16
cb = -0.117 * r - 0.394 * g + 0.511 * b + 128
cr = 0.511 * r - 0.464 * g - 0.047 * b + 128
Algorithm 2
Conversion from YCbCr model to linear RGB model, with 4:4:4 upsampling
If the destination image contains an alpha channel, each component will be set to 255
If the source image color space is Bt601, the following formula is applied:
r = 1.164 * (y - 16) + 1.596 * (cr - 128)
g = 1.164 * (y - 16) - 0.813 * (cr - 128) - 0.392 * (cb - 128)
b = 1.164 * (y - 16) + 2.017 * (cb - 128)
If the source image color space is Bt709, the following formula is applied:
r = 1.164 * (y - 16) + 1.793 * (cr - 128)
g = 1.164 * (y - 16) - 0.534 * (cr - 128) - 0.213 * (cb - 128)
b = 1.164 * (y - 16) + 2.115 * (cb - 128)