GrayToRGB
Converts a grayscale image to an RGB 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_GrayToRGB_8u_C1C3R(const uint8_t* src, int32_t srcStep, uint8_t* dst, int32_t dstStep, HmppiSize roiSize)
HmppResult HMPPI_GrayToRGB_8u_C1C4R(const uint8_t* src, int32_t srcStep, uint8_t* dst, int32_t dstStep, HmppiSize roiSize, uint8_t aVal)
HmppResult HMPPI_GrayToRGB_16u_C1C3R(const uint16_t* src, int32_t srcStep, uint16_t* dst, int32_t dstStep, HmppiSize roiSize)
HmppResult HMPPI_GrayToRGB_16u_C1C4R(const uint16_t* src, int32_t srcStep, uint16_t* dst, int32_t dstStep, HmppiSize roiSize, uint16_t aVal)
HmppResult HMPPI_GrayToRGB_32f_C1C3R(const float* src, int32_t srcStep, float* dst, int32_t dstStep, HmppiSize roiSize)
HmppResult HMPPI_GrayToRGB_32f_C1C4R(const float* src, int32_t srcStep, float* dst, int32_t dstStep, HmppiSize roiSize, float aVal)
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 |
aVal |
Constant value used to fill the fourth channel |
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 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 32
#define DST_BUFFER_SIZE_T 84
void TestExample()
{
HmppiSize roi = { 3, 4 };
const uint16_t src[SRC_BUFFER_SIZE_T] = {
12123, 21243, 13165, 255, 1, 2,
10256, 11193, 30243, 200, 3, 4,
4, 233, 109, 27, 5, 6,
6, 7, 8, 0, 7, 8
};
int32_t srcStep = 6 * sizeof(uint16_t);
uint16_t dst[DST_BUFFER_SIZE_T] = { 0 };
int32_t dstStep = 14 * sizeof(uint16_t);
uint16_t aVal = 0x8000;
HmppResult result = HMPPI_GrayToRGB_16u_C1C4R(src, srcStep, dst, dstStep, roi, aVal);
printf("result = %d \ndst = ", result);
if (result != HMPP_STS_NO_ERR) {
printf("result error: %d\n", result);
}
int32_t dstWidth = dstStep / sizeof(uint16_t);
for (int32_t i = 0; i < DST_BUFFER_SIZE_T; i++) {
if( i % dstWidth == 0 ){
printf("\n");
}
printf("%5d ",dst[i]);
}
printf("\n");
}
int main()
{
TestExample();
return 0;
}
Output:
result = 0
dst =
12123 12123 12123 32768 21243 21243 21243 32768 13165 13165 13165 32768 0 0
10256 10256 10256 32768 11193 11193 11193 32768 30243 30243 30243 32768 0 0
4 4 4 32768 233 233 233 32768 109 109 109 32768 0 0
6 6 6 32768 7 7 7 32768 8 8 8 32768 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