RGB/RGBA to NV12 Color Conversion#

Converts an image from RGB or RGBA format to NV12 format.

Description

This function can operate with ROI (see Image Regions of Interest).

This function performs conversion from gamma-corrected RGB or RGBA image to NV12 image using formulas:

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

Conversion also performs 4:2:0 downsampling for the converted image with Cb and Cr channels interleaved. Two plane Y’Cb’Cr’ image with 4:2:0 sampling and interleaved Cb and Cr components in respected order is also known as NV12 format. In case of RGBA source image format, alpha channel is ignored and its values are lost. Source and destination image width and height must be even.

Headers

oneapi/ipl/convert.hpp

Syntax

template<typename ComputeT = float, typename SrcImageT, typename DstImageT>
sycl::event oneapi::ipl::rgb_to_nv12(sycl::queue &queue, SrcImageT &src, DstImageT &dst, const color_conversion_spec<typename DstImageT::data_t> &spec = {}, const std::vector<sycl::event> &dependencies = {})#

Function for RGB or RGBA to NV12 color conversion.

Template Parameters:
  • ComputeT – The type in which all calculations will be performed

  • SrcImageT – Source image type

  • DstImageT – Destination image type

Parameters:
  • queue – SYCL queue object

  • src – Source image object

  • dst – Destination image object

  • spec – Specification for convert function

  • dependencies – SYCL event dependencies

Returns:

SYCL event

Supported values for ComputeT:

float

double

Supported values for source layout:

channel3

channel4

Parameters

See Parameters of Color Conversion (spec).

Errors

compile-time memory layout check

Indicates an error when image memory layout is not supported.

compile-time data type check

Indicates an error when image data type is not supported.

compile-time compute data type check

Indicates an error when compute data type is not supported.

invalid_argument exception

Indicates an error when ROI sizes of the source image and the destination image are not equal.

invalid_argument exception

Indicates an error when one of the pitch values is not divisible by size of component data type in bytes.

The code example below demonstrates how oneapi::ipl::rgb_to_nv12 shall be called for RGBA to NV12 conversion:

using namespace oneapi;

sycl::queue                 queue;
ipl::shared_usm_allocator_t allocator{ queue };
const sycl::range<2>        image_size{ height, width };

// Source image for RGBA data
ipl::image<ipl::layouts::channel4, std::uint8_t> src_image{ queue, p_image_data, image_size, allocator };
// Destination image for NV12 data
ipl::image<ipl::layouts::sub420i, std::uint8_t> dst_image{ image_size, allocator };

// Convert RGBA to NV12
auto event = ipl::rgb_to_nv12(queue, src_image, dst_image);