View Source Image.YUV (image v0.55.2)
Functions 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:2
and4:2:0
encodings.
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
binary
is a binary representation of a YUV image.width
is the width of the image encoded inyuv
.height
is the height of the image encoded inyuv
.encoding
is one of:C444
,:C422
or:C420
representing howyuv
is 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
image
is anyt:Vimage.t/0
that is in a YUV colorspace such as that returned fromImage.YUV.new_from_file/5
orImage.YUV.new_from_binary/5
.encoding
is one of:C444
,:C422
or:C420
representing howyuv
is to be encoded.
Returns
{:ok, [y, u, v]}
or{:error, Image.error_message()}
.
new_from_binary(binary, width, height, encoding, colorspace \\ :bt601)
View Source (since 0.41.0)@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
binary
is raw YUV data as a binary.width
is the width of the image encoded in the YUV data.height
is the height of the image encoded in the YUV data.encoding
is one of:C444
,:C422
or:C420
.colorspace
is one of:bt601
(the default) or:bt709
.
Returns
{:ok, rgb_image}
or{:error, reason}
.
new_from_file(path, width, height, encoding, colorspace \\ :bt601)
View Source (since 0.41.0)@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
path
is any accessible file system path.width
is the width of the image encoded in the YUV data.height
is the height of the image encoded in the YUV data.encoding
is one of:C444
,:C422
or:C420
.colorspace
is 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
image
is anyt:Vimage.t/0
that is in a YUV colorspace such as that returned fromImage.YUV.new_from_file/5
orImage.YUV.new_from_binary/5
.colorspace
is one of:bt601
(the default) or:bt709
that represents the colorspace ofimage
before 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
yuv
is a list of three binaries representing theY
,U
andV
planes. Such a list is returned fromImage.YUV.to_yuv/3
and fromImage.YUV.encode/2
.width
is the width of the image encoded inyuv
.height
is the height of the image encoded inyuv
.encoding
is one of:C444
,:C422
or:C420
representing howyuv
is encoded.colorspace
is one of:bt601
(the default) or:bt709
that represents the colorspace ofimage
before 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
image
is anyt:Vimage.t/0
.encoding
is one of:C444
,:C422
or:C420
.colorspace
is one of:bt601
(the default) or:bt709
.
Returns
{:ok, [y, u, v]}
or{:error, reason}
.
write_to_binary(image, encoding, colorspace \\ :bt601)
View Source (since 0.41.0)@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
image
is anyt:Vimage.t/0
.encoding
is one of:C444
,:C422
or:C420
.colorspace
is one of:bt601
(the default) or:bt709
.
Returns
{:ok, yuv_binary}
or{:error, reason}
.
write_to_file(image, path, encoding, colorspace \\ :bt601)
View Source (since 0.41.0)@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
path
is any accessible file system path.encoding
is one of:C444
,:C422
or:C420
.colorspace
is one of:bt601
(the default) or:bt709
.
Returns
:ok
or{:error, reason}
.