YUV420ToRGB
Converts a YUV image in 4:2:0 sampling format into an RGB color model.
This function converts a Y'U'V' image src to a gamma-corrected R'G'B' image dst according to the following formulas:
R' = Y' + 1.140*V'
G' = Y' - 0.394*U' - 0.581*V'
B' = Y' + 2.032*U'
The function interface declaration is as follows:
HmppResult HMPPI_YUV420ToRGB_8u_P3C3R(const uint8_t* src[3], int srcStep[3], uint8_t *dst, int dstStep,HmppiSize roiSize);
HmppResult HMPPI_YUV420ToRGB_8u_P3AC4R(const uint8_t * src[3], int srcStep[3], uint8_t *dst, int dstStep,HmppiSize roiSize);
HmppResult HMPPI_YUV420ToRGB_8u_P3R(const uint8_t * src[3], int srcStep[3], uint8_t *dst[3], int dstStep,HmppiSize roiSize);
HmppResult HMPPI_YUV420ToRGB_8u_P3C3(const uint8_t * src[3], uint8_t * dst, HmppiSize imgSize);
HmppResult HMPPI_YUV420ToRGB_8u_P3(const uint8_t * src[3], uint8_t * dst[3], HmppiSize imgSize);
Parameters
Parameter |
Description |
Value Range |
Input/Output |
|---|---|---|---|
src |
Pointer to the source image. This array stores pointers pointing to the color planes of the source planar image. |
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 image ROI. This array stores pointers pointing to the color planes of the destination planar image. |
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 image and target image for the operation without ROI |
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 is NULL. |
HMPP_STS_SIZE_ERR |
The value of roiSize is 0 or negative. |
HMPP_STS_STEP_ERR |
The value of srcStep is 0 or negative. |
HMPP_STS_ROI_ERR |
The product of the width of roiSize and the number of channels is greater than the step srcStep. |
Example
#define SRC_BUFFER_SIZE_T 90
#define DST_BUFFER_SIZE_T 90
void TestExample_YUV420ToRGB()
{
HmppiSize roi = { 4, 4 };
const uint8_t src1[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
};
const uint8_t src2[SRC_BUFFER_SIZE_T] = {
11, 22, 33, 44, 55, 66, 77, 88, 22, 88, 77, 66, 55, 44, 33,
21, 23, 33, 44, 55, 66, 77, 88, 22, 88, 77, 66, 55, 44, 33,
31, 24, 33, 44, 55, 66, 77, 88, 22, 88, 77, 66, 55, 44, 33,
41, 25, 33, 44, 55, 66, 77, 88, 22, 88, 77, 66, 55, 44, 33,
51, 26, 33, 44, 55, 66, 77, 88, 22, 88, 77, 66, 55, 44, 33,
61, 27, 33, 44, 55, 66, 77, 88, 22, 88, 77, 66, 55, 44, 33
};
const uint8_t src3[SRC_BUFFER_SIZE_T] = {
11, 12, 33, 44, 55, 66, 77, 88, 22, 88, 77, 66, 55, 44, 33,
12, 22, 33, 44, 55, 66, 77, 88, 22, 88, 77, 66, 55, 44, 33,
13, 32, 33, 44, 55, 66, 77, 88, 22, 88, 77, 66, 55, 44, 33,
14, 42, 33, 44, 55, 66, 77, 88, 22, 88, 77, 66, 55, 44, 33,
15, 52, 33, 44, 55, 66, 77, 88, 22, 88, 77, 66, 55, 44, 33,
16, 62, 33, 44, 55, 66, 77, 88, 22, 88, 77, 66, 55, 44, 33
};
const uint8_t *src[3] = {src1, src2, src3};
int32_t srcStep[3] = {20 * sizeof(uint8_t), 20 * sizeof(uint8_t), 20 * sizeof(uint8_t)};
int32_t dstStep = 20 * sizeof(uint8_t);;
uint8_t dst[DST_BUFFER_SIZE_T] = {0};
HmppResult result = HMPPI_YUV420ToRGB_8u_P3C3R(src, srcStep, dst, dstStep, roi);
printf("result = %d \ndst = ", result);
if (result != HMPP_STS_NO_ERR) {
printf("result error: %d\n", result);
}
int32_t dstWidth = dstStep / sizeof(uint8_t);
for(int32_t i = 0; i < DST_BUFFER_SIZE_T; i++){
if (i % dstWidth == 0) {
printf("\n");
}
printf("%3d ",dst[i]);
}
printf("\n");
}
int main()
{
TestExample_YUV420ToRGB();
return 0;
}
Output:
result = 0 dst = 0 124 0 0 135 0 0 141 0 0 152 0 0 0 0 0 0 0 0 0 0 179 0 0 190 0 0 196 0 0 130 0 0 0 0 0 0 0 0 0 6 137 0 0 126 0 0 104 0 0 93 0 0 0 0 0 0 0 0 0 0 71 0 0 82 0 0 82 0 0 93 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0