Image.YUV (image v0.62.0)
View SourceFunctions to convert from/to YUV (YCbCr) encoding and BT.601/BT.709 colorspaces and sRGB images.
The following YUV (YCbCr) binary formats are supported:
- Planar frame types only (not packed frames). 
- 4:4:4,- 4:2:2and- 4:2:0encodings.
Performance profiling indicates this implementation is not suitable for real time frame processing of YUV images.
Summary
Functions
Deocdes a raw YUV binary into [y, u, v] planes
where each plane is a binary.
Encodes an image that is in a YUV colorspace to raw YUV data that is a list of the three planes, each a binary.
Converts raw YUV data into an RGB image.
Converts the raw YUV data in a .yuv file
into an RGB image.
Convert an image in an YUV colorspace and convert it to RGB colorspace.
Takes the [y, u, v] planes and converts them to
an RGB image.
Converts an image to raw YUV data as a binary.
Writes an image to a YUV raw binary.
Writes an image to a YUV file as raw YUV data.
Types
@type yuv_colorspace() :: :bt601 | :bt709
      YUV colorspace
@type yuv_encoding() :: :C444 | :C422 | :C420
      YUV encoding
@type yuv_list() :: [binary()]
YUV data as a three-element list of binaries
Functions
Deocdes a raw YUV binary into [y, u, v] planes
where each plane is a binary.
Arguments
- binaryis a binary representation of a YUV image.
- widthis the width of the image encoded in- yuv.
- heightis the height of the image encoded in- yuv.
- encodingis one of- :C444,- :C422or- :C420representing how- yuvis encoded.
Returns
- {:ok, [y, u, v]}or
- {:error, reason}.
@spec encode(image :: Vix.Vips.Image.t(), encoding :: yuv_encoding()) :: {:ok, yuv_list()} | {:errpr, Image.error_message()}
Encodes an image that is in a YUV colorspace to raw YUV data that is a list of the three planes, each a binary.
The data is always written in a planar format.
Arguments
- imageis any- t:Vimage.t/0that is in a YUV colorspace such as that returned from- Image.YUV.new_from_file/5or- Image.YUV.new_from_binary/5.
- encodingis one of- :C444,- :C422or- :C420representing how- yuvis to be encoded.
Returns
- {:ok, [y, u, v]}or
- {:error, Image.error_message()}.
@spec new_from_binary( binary :: binary(), width :: pos_integer(), height :: pos_integer(), encoding :: yuv_encoding(), colorspace :: yuv_colorspace() ) :: {:ok, Vix.Vips.Image.t()} | {:error, Image.error_message()}
Converts raw YUV data into an RGB image.
The data is assumed, and required to be in:
- Planar format
- 8-bit color depth
Arguments
- binaryis raw YUV data as a binary.
- widthis the width of the image encoded in the YUV data.
- heightis the height of the image encoded in the YUV data.
- encodingis one of- :C444,- :C422or- :C420.
- colorspaceis one of- :bt601(the default) or- :bt709.
Returns
- {:ok, rgb_image}or
- {:error, reason}.
@spec new_from_file( path :: Path.t(), width :: pos_integer(), height :: pos_integer(), encoding :: yuv_encoding(), colorspace :: yuv_colorspace() ) :: {:ok, Vix.Vips.Image.t()} | {:error, Image.error_message()}
Converts the raw YUV data in a .yuv file
into an RGB image.
The data is assumed, and required to be in:
- Planar format
- 8-bit color depth
Arguments
- pathis any accessible file system path.
- widthis the width of the image encoded in the YUV data.
- heightis the height of the image encoded in the YUV data.
- encodingis one of- :C444,- :C422or- :C420.
- colorspaceis one of- :bt601(the default) or- :bt709.
Returns
- {:ok, rgb_image}or
- {:error, reason}.
@spec to_rgb(image :: Vix.Vips.Image.t(), colorspace :: yuv_colorspace()) :: {:ok, Vix.Vips.Image.t()} | {:error, Image.error_message()}
Convert an image in an YUV colorspace and convert it to RGB colorspace.
Arguments
- imageis any- t:Vimage.t/0that is in a YUV colorspace such as that returned from- Image.YUV.new_from_file/5or- Image.YUV.new_from_binary/5.
- colorspaceis one of- :bt601(the default) or- :bt709that represents the colorspace of- imagebefore conversion.
@spec to_rgb( yuv :: yuv_list(), width :: pos_integer(), height :: pos_integer(), encoding :: yuv_encoding(), colorspace :: yuv_colorspace() ) :: {:ok, Vix.Vips.Image.t()} | {:error, Image.error_message()}
Takes the [y, u, v] planes and converts them to
an RGB image.
Arguments
- yuvis a list of three binaries representing the- Y,- Uand- Vplanes. Such a list is returned from- Image.YUV.to_yuv/3and from- Image.YUV.encode/2.
- widthis the width of the image encoded in- yuv.
- heightis the height of the image encoded in- yuv.
- encodingis one of- :C444,- :C422or- :C420representing how- yuvis encoded.
- colorspaceis one of- :bt601(the default) or- :bt709that represents the colorspace of- imagebefore conversion.
Returns
- {:ok, image}or
- {:error, reason}.
@spec to_yuv( image :: Vix.Vips.Image.t(), encoding :: yuv_encoding(), colorspace :: yuv_colorspace() ) :: {:ok, yuv_list()} | {:error, Image.error_message()}
Converts an image to raw YUV data as a binary.
Arguments
- imageis any- t:Vimage.t/0.
- encodingis one of- :C444,- :C422or- :C420.
- colorspaceis one of- :bt601(the default) or- :bt709.
Returns
- {:ok, [y, u, v]}or
- {:error, reason}.
@spec write_to_binary( image :: Vix.Vips.Image.t(), encoding :: yuv_encoding(), colorspace :: yuv_colorspace() ) :: {:ok, binary()} | {:error, Image.error_message()}
Writes an image to a YUV raw binary.
Arguments
- imageis any- t:Vimage.t/0.
- encodingis one of- :C444,- :C422or- :C420.
- colorspaceis one of- :bt601(the default) or- :bt709.
Returns
- {:ok, yuv_binary}or
- {:error, reason}.
@spec write_to_file( image :: Vix.Vips.Image.t(), path :: Path.t(), encoding :: yuv_encoding(), colorspace :: yuv_colorspace() ) :: :ok | {:error, Image.error_message()}
Writes an image to a YUV file as raw YUV data.
It is recommeneded, but not required, that the path
name use a .yuv suffix.
Arguments
- pathis any accessible file system path.
- encodingis one of- :C444,- :C422or- :C420.
- colorspaceis one of- :bt601(the default) or- :bt709.
Returns
- :okor
- {:error, reason}.