RGBToYUV422
Converts an RGB image to a YUV422 color model using 4:2:2 sampling. A YUV422 image uses 4:2:2 sampling, that is, Y is sampled twice, and U and V are sampled once for every two pixel blocks.
The function interface declaration is as follows:
- Operation on pixel-order data:
HmppResult HMPPI_RGBToYUV422_8u_C3C2R(const uint8_t *src, int32_t srcStep, uint8_t *dst, int32_t dstStep, HmppiSize roiSize);
- Operation on planar data:
HmppResult HMPPI_RGBToYUV422_8u_P3R(const uint8_t *src[3], int32_t srcStep, uint8_t *dst[3], int32_t dstStep[3], HmppiSize roiSize);
HmppResult HMPPI_RGBToYUV422_8u_C3P3R(const uint8_t *src, int32_t srcStep, uint8_t *dst[3], int32_t dstStep[3], HmppiSize roiSize);
- Operation on planar data (without ROI):
HmppResult HMPPI_RGBToYUV422_8u_P3(const uint8_t *src[3], uint8_t *dst[3], HmppiSize imgSize);
- Conversion from pixel-order to planar data (without ROI):
HmppResult HMPPI_RGBToYUV422_8u_C3P3(const uint8_t *src, uint8_t *dst[3], HmppiSize imgSize);
Parameters
Parameter |
Description |
Value Range |
Input/Output |
|---|---|---|---|
src |
Pointer to the source buffer of pixel-order data. If the input is planar data, this parameter indicates an array of pointers to separate source color planes. |
The value cannot be NULL. |
Input |
srcStep |
Distance between starts of consecutive lines in the source image, in bytes |
The value must be zero or a positive integer. |
Input |
dst |
Pointer to the destination buffer of pixel-order data. If the input is planar data, this parameter indicates an array of pointers to separate destination color planes. |
The value cannot be NULL. |
Output |
dstStep |
Distance between starts of consecutive lines in the destination image, in bytes |
The value must be zero or a positive integer. |
Input |
roiSize |
Size of the ROI of the source and destination images, in pixels |
roiSize.width ∈ (0, INT_MAX], roiSize.height ∈ (0, INT_MAX] |
Input |
imgSize |
Size of the source and destination images, in pixels |
The value must be zero or a positive integer. |
Input |
Return Value
- Success: HMPP_STS_NO_ERR
- Failure: An error code is returned.
Error Codes
Error Code |
Description |
|---|---|
HMPP_STS_NULL_PTR_ERR |
The value of src or dst is NULL. |
HMPP_STS_SIZE_ERR |
The value of roiSize or imgSize is 0 or a negative value. |
HMPP_STS_STEP_ERR |
The value of srcStep or dstStep is zero or negative. |
HMPP_STS_ROI_ERR |
The product of the width of roiSize and the number of channels is greater than the step. |
HMPP_STS_NO_ERR |
No error occurs. |
Example
#define SRC_BUFFER_SIZE_T 180
#define DST_BUFFER_SIZE_T 120
void TestExample()
{
HmppiSize roi = { 4, 4 };
const uint8_t src[SRC_BUFFER_SIZE_T] = {
11, 22, 33, 44, 55, 66, 77, 88, 22, 88, 77, 66, 55, 44, 33,
11, 22, 33, 44, 55, 66, 77, 88, 22, 88, 77, 66, 55, 44, 33,
11, 22, 33, 44, 55, 66, 77, 88, 22, 88, 77, 66, 55, 44, 33,
11, 22, 33, 44, 55, 66, 77, 88, 22, 88, 77, 66, 55, 44, 33,
11, 22, 33, 44, 55, 66, 77, 88, 22, 88, 77, 66, 55, 44, 33,
11, 22, 33, 44, 55, 66, 77, 88, 22, 88, 77, 66, 55, 44, 33,
11, 22, 33, 44, 55, 66, 77, 88, 22, 88, 77, 66, 55, 44, 33,
11, 22, 33, 44, 55, 66, 77, 88, 22, 88, 77, 66, 55, 44, 33,
11, 22, 33, 44, 55, 66, 77, 88, 22, 88, 77, 66, 55, 44, 33,
11, 22, 33, 44, 55, 66, 77, 88, 22, 88, 77, 66, 55, 44, 33,
11, 22, 33, 44, 55, 66, 77, 88, 22, 88, 77, 66, 55, 44, 33,
11, 22, 33, 44, 55, 66, 77, 88, 22, 88, 77, 66, 55, 44, 33
};
uint8_t a[DST_BUFFER_SIZE_T] = { 0 };
uint8_t b[DST_BUFFER_SIZE_T] = { 0 };
uint8_t c[DST_BUFFER_SIZE_T] = { 0 };
uint8_t *dst[3] = {a, b, c};
int32_t srcStep = 12 * sizeof(uint8_t);
int32_t dstStep[3] = {20 * sizeof(uint8_t), 20 * sizeof(uint8_t), 20 * sizeof(uint8_t)};
HmppResult result = HMPPI_RGBToYUV422_8u_C3P3R(src, srcStep, dst, dstStep, roi);
printf("result = %d \ndst = ", result);
if (result != HMPP_STS_NO_ERR) {
printf("result error: %d\n", result);
}
for(int32_t i = 0; i < 3; i++){
int32_t dstWidth = dstStep[i] / sizeof(uint8_t);
for (int32_t j = 0; j < DST_BUFFER_SIZE_T; j++) {
if( j % dstWidth == 0 ){
printf("\n");
}
printf("%3d ",dst[i][j]);
}
}
printf("\n");
}
int main()
{
TestExample();
return 0;
}
Output:
result = 0 dst = 19 52 77 79 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 46 19 52 77 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 79 46 19 52 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 77 79 46 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 134 111 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 128 117 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 121 134 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 111 128 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 120 131 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 128 124 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 135 120 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 131 128 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0