BGRToYCbCr420
Converts a BGR image to a YCbCr image using the 4:2:0 sampling format. According to the sampling mode, the width and height of roiSize must be multiples of 2. If not, the system corrects their values to the nearest multiples of 2, performs operation, and returns an error code.
The formula is as follows:
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
The function interface declaration is as follows:
HmppResult HMPPI_BGRToYCbCr420_8u_C3P3R(const uint8_t* src, int32_t srcStep, uint8_t* dst[3], int32_t dstStep[3], HmppiSize roiSize);
HmppResult HMPPI_BGRToYCbCr420_8u_AC4P3R(const uint8_t* src, int32_t srcStep, uint8_t* dst[3], int32_t dstStep[3], HmppiSize roiSize);
Parameters
Parameter |
Description |
Value Range |
Input/Output |
|---|---|---|---|
src |
Pointer to the source vector |
The value cannot be NULL. |
Input |
srcStep |
Distance between starts of consecutive lines in the source image, in bytes |
(0, INT_MAX] |
Input |
dst |
Pointer to the destination vector |
The value cannot be NULL. |
Output |
dstStep |
Distance between starts of consecutive lines in the destination image, in bytes |
(0, INT_MAX] |
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 |
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.width or roiSize.height is less than 2. |
HMPP_STS_STEP_ERR |
The value of srcStep or dstStep is less than or equal to 0. |
HMPP_STS_ROI_ERR |
roiSize.width > Step |
HMPP_STS_DOUBLE_SIZE |
The value of roiSize.width or roiSize.height is not a multiple of 2. |
Example
#define SRC_BUFFER_SIZE_T 90
#define DST_BUFFER_SIZE_T 12
int CopyExample()
{
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
};
uint8_t a[DST_BUFFER_SIZE_T], b[DST_BUFFER_SIZE_T], c[DST_BUFFER_SIZE_T];
uint8_t *dst[3] = {a, b, c};
int32_t srcStep = 15 * sizeof(uint8_t);
int32_t dstStep[3] = {12 * sizeof(uint8_t),12 * sizeof(uint8_t),12 * sizeof(uint8_t)};
HmppResult result = HMPPI_BGRToYCbCr420_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");
return 0;
}
Output:
result = 0 dst = 37 65 74 80 0 0 0 0 0 0 0 0 121 133 0 0 0 0 0 0 0 0 0 0 133 111 0 0 0 0 0 0 0 0 0 0