RGBToGray
Converts an RGB image to a grayscale image. This function converts the color according to the following formula:

The function interface declaration is as follows:
Operation on pixel-order data:
HmppResult HMPPI_RGBToGray_8u_C3C1R(const uint8_t* src, int32_t srcStep, uint8_t* dst, int32_t dstStep, HmppiSize roiSize)
HmppResult HMPPI_RGBToGray_8u_AC4C1R(const uint8_t* src, int32_t srcStep, uint8_t* dst, int32_t dstStep, HmppiSize roiSize)
HmppResult HMPPI_RGBToGray_16u_C3C1R(const uint16_t* src, int32_t srcStep, uint16_t* dst, int32_t dstStep, HmppiSize roiSize)
HmppResult HMPPI_RGBToGray_16u_AC4C1R(const uint16_t* src, int32_t srcStep, uint16_t* dst, int32_t dstStep, HmppiSize roiSize)
HmppResult HMPPI_RGBToGray_16s_C3C1R(const int16_t* src, int32_t srcStep, int16_t* dst, int32_t dstStep, HmppiSize roiSize)
HmppResult HMPPI_RGBToGray_16s_AC4C1R(const int16_t* src, int32_t srcStep, int16_t* dst, int32_t dstStep, HmppiSize roiSize)
HmppResult HMPPI_RGBToGray_32f_C3C1R(const float* src, int32_t srcStep, float* dst, int32_t dstStep, HmppiSize roiSize)
HmppResult HMPPI_RGBToGray_32f_AC4C1R(const float* src, int32_t srcStep, float* dst, int32_t dstStep, HmppiSize roiSize)
Parameters
Parameter |
Description |
Value Range |
Input/Output |
|---|---|---|---|
src |
Pointer to the source image. This array stores the color data 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 the color data 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 |
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 is 0 or negative. |
HMPP_STS_STEP_ERR |
The value of srcStep or dstStep is 0 or negative. |
HMPP_STS_ROI_ERR |
roiSize.width x Number of channels x Number of bytes occupied by the data type > Step |
HMPP_STS_NOT_EVEN_STEP_ERR |
The step is an odd number when the data type is not uint8_t. |
HMPP_STS_NO_ERR |
No error occurs. |
Example
#define SRC_BUFFER_SIZE_T 64
#define DST_BUFFER_SIZE_T 32
void TestExample()
{
HmppiSize roi = { 3, 5 };
const int16_t src[SRC_BUFFER_SIZE_T] = {
121, 212, 131, 255, 11, 22, 33, 44, 55, 66, 42, 10,
156, 93, 243, 200, 55, 44, 33, 11, 22, 33, 30, 99,
4, 233, 109, 27, 88, 77, 66, 55, 44, 33, 5, 22,
6, 7, 8, 0, 77, 88, 22, 88, 77, 66, 1, 0,
44, 33, 22, 11, 55, 66, 77, 88, 99, 10, 59, 32
};
int32_t srcStep = 12 * sizeof(int16_t);
int16_t dst[DST_BUFFER_SIZE_T] = { 0 };
int32_t dstStep = 6 * sizeof(int16_t);
HmppResult result = HMPPI_RGBToGray_16s_C3C1R(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(int16_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();
return 0;
}
Output:
result = 0 dst = 176 85 42 0 0 0 129 97 19 0 0 0 150 69 57 0 0 0 7 55 67 0 0 0 35 43 86 0 0 0 0 0