Scale
Scales pixel values of an image and converts them to another bit depth.
The function interface is declared as follows:
- Scaling for single-channel data:
HmppResult HMPPI_Scale_8u16u_C1R(const uint8_t *src, int32_t srcStep, uint16_t *dst, int32_t dstStep, HmppiSize roiSize);
HmppResult HMPPI_Scale_8u16s_C1R(const uint8_t *src, int32_t srcStep, int16_t *dst, int32_t dstStep, HmppiSize roiSize);
HmppResult HMPPI_Scale_8u32s_C1R(const uint8_t *src, int32_t srcStep, int32_t *dst, int32_t dstStep, HmppiSize roiSize);
HmppResult HMPPI_Scale_8u32f_C1R(const uint8_t *src, int32_t srcStep, float *dst, int32_t dstStep, HmppiSize roiSize, float vMin, float vMax);
HmppResult HMPPI_Scale_16u8u_C1R(const uint16_t *src, int32_t srcStep, uint8_t *dst, int32_t dstStep, HmppiSize roiSize, HmppHintAlgorithm hint);
HmppResult HMPPI_Scale_16s8u_C1R(const int16_t *src, int32_t srcStep, uint8_t *dst, int32_t dstStep, HmppiSize roiSize, HmppHintAlgorithm hint);
HmppResult HMPPI_Scale_32s8u_C1R(const int32_t *src, int32_t srcStep, uint8_t *dst, int32_t dstStep, HmppiSize roiSize, HmppHintAlgorithm hint);
HmppResult HMPPI_Scale_32f8u_C1R(const float *src, int32_t srcStep, uint8_t *dst, int32_t dstStep, HmppiSize roiSize, float vMin, float vMax);
- Scaling for multi-channel data:
HmppResult HMPPI_Scale_8u16u_C3R(const uint8_t *src, int32_t srcStep, uint16_t *dst, int32_t dstStep, HmppiSize roiSize);
HmppResult HMPPI_Scale_8u16s_C3R(const uint8_t *src, int32_t srcStep, int16_t *dst, int32_t dstStep, HmppiSize roiSize);
HmppResult HMPPI_Scale_8u32s_C3R(const uint8_t *src, int32_t srcStep, int32_t *dst, int32_t dstStep, HmppiSize roiSize);
HmppResult HMPPI_Scale_8u32f_C3R(const uint8_t *src, int32_t srcStep, float *dst, int32_t dstStep, HmppiSize roiSize, float vMin, float vMax);
HmppResult HMPPI_Scale_16u8u_C3R(const uint16_t *src, int32_t srcStep, uint8_t *dst, int32_t dstStep, HmppiSize roiSize, HmppHintAlgorithm hint);
HmppResult HMPPI_Scale_16s8u_C3R(const int16_t *src, int32_t srcStep, uint8_t *dst, int32_t dstStep, HmppiSize roiSize, HmppHintAlgorithm hint);
HmppResult HMPPI_Scale_32s8u_C3R(const int32_t *src, int32_t srcStep, uint8_t *dst, int32_t dstStep, HmppiSize roiSize, HmppHintAlgorithm hint);
HmppResult HMPPI_Scale_32f8u_C3R(const float *src, int32_t srcStep, uint8_t *dst, int32_t dstStep, HmppiSize roiSize, float vMin, float vMax);
HmppResult HMPPI_Scale_8u16u_C4R(const uint8_t *src, int32_t srcStep, uint16_t *dst, int32_t dstStep, HmppiSize roiSize);
HmppResult HMPPI_Scale_8u16s_C4R(const uint8_t *src, int32_t srcStep, int16_t *dst, int32_t dstStep, HmppiSize roiSize);
HmppResult HMPPI_Scale_8u32s_C4R(const uint8_t *src, int32_t srcStep, int32_t *dst, int32_t dstStep, HmppiSize roiSize);
HmppResult HMPPI_Scale_8u32f_C4R(const uint8_t *src, int32_t srcStep, float *dst, int32_t dstStep, HmppiSize roiSize, float vMin, float vMax);
HmppResult HMPPI_Scale_16u8u_C4R(const uint16_t *src, int32_t srcStep, uint8_t *dst, int32_t dstStep, HmppiSize roiSize, HmppHintAlgorithm hint);
HmppResult HMPPI_Scale_16s8u_C4R(const int16_t *src, int32_t srcStep, uint8_t *dst, int32_t dstStep, HmppiSize roiSize, HmppHintAlgorithm hint);
HmppResult HMPPI_Scale_32s8u_C4R(const int32_t *src, int32_t srcStep, uint8_t *dst, int32_t dstStep, HmppiSize roiSize, HmppHintAlgorithm hint);
HmppResult HMPPI_Scale_32f8u_C4R(const float *src, int32_t srcStep, uint8_t *dst, int32_t dstStep, HmppiSize roiSize, float vMin, float vMax);
HmppResult HMPPI_Scale_8u16u_AC4R(const uint8_t *src, int32_t srcStep, uint16_t *dst, int32_t dstStep, HmppiSize roiSize);
HmppResult HMPPI_Scale_8u16s_AC4R(const uint8_t *src, int32_t srcStep, int16_t *dst, int32_t dstStep, HmppiSize roiSize);
HmppResult HMPPI_Scale_8u32s_AC4R(const uint8_t *src, int32_t srcStep, int32_t *dst, int32_t dstStep, HmppiSize roiSize);
HmppResult HMPPI_Scale_16u8u_AC4R(const uint16_t *src, int32_t srcStep, uint8_t *dst, int32_t dstStep, HmppiSize roiSize, HmppHintAlgorithm hint);
HmppResult HMPPI_Scale_16s8u_AC4R(const int16_t *src, int32_t srcStep, uint8_t *dst, int32_t dstStep, HmppiSize roiSize, HmppHintAlgorithm hint);
HmppResult HMPPI_Scale_32s8u_AC4R(const int32_t *src, int32_t srcStep, uint8_t *dst, int32_t dstStep, HmppiSize roiSize, HmppHintAlgorithm hint);
Parameters
Parameter |
Description |
Value Range |
Input/Output |
|---|---|---|---|
src |
Pointer to the source image ROI |
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 |
The value cannot be NULL. |
Input/Output |
dstStep |
Distance between starts of consecutive lines in the destination image, in bytes |
The value must be zero or a positive integer. |
Input |
vMin |
Minimum value in the input data |
You can obtain this value by calling HMPPI_Min_* APIs. |
Input |
vMax |
Maximum value in the input data |
You can obtain this value by calling HMPPI_Max_* APIs. |
Input |
hint |
Algorithmic implementation mode of the function |
Any of the enumerated values of HmppHintAlgorithm |
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 |
cmpOp |
Operation used to compare pixel values and the threshold. Comparison for "greater than" or "less than" can be used. |
HMPP_CMP_LT, HMPP_CMP_GT |
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 result of roiSize.width x Number of channels x Number of bytes occupied by the data type is greater than the step. |
HMPP_STS_NOT_EVEN_STEP_ERR |
The value of srcStep cannot be exactly divided by the byte length of the data type to which src belongs. |
HMPP_STS_SCALE_RANGE_ERR |
The value of vMin is greater than that of vMax. |
HMPP_STS_NOT_SUPPORTED_MODE_ERR |
The comparison mode is not supported. |
HMPP_STS_NO_ERR |
No error occurs. |
Example
void ScaleExample()
{
HmppiSize roi = {5,4};
uint8_t src[60] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
};
int16_t dst[72] = {0};
int32_t srcStep=15*sizeof(uint8_t);
int32_t dstStep=18*sizeof(int16_t);
HMPPI_Scale_8u16s_C3R(src, srcStep, dst, dstStep, roi);
for(int i=0; i< 4; ++i){
for(int j=0;j<18;++j){
printf( "%d ", dst[i*18 + j]);
}
printf("\n");
}
}
int main(){
ScaleExample();
return 0;
}
Output:
-32511 -32254 -31997 -31740 -31483 -31226 -30969 -30712 -30455 -30198 -29941 -29684 -29427 -29170 -28913 0 0 0 -32511 -32254 -31997 -31740 -31483 -31226 -30969 -30712 -30455 -30198 -29941 -29684 -29427 -29170 -28913 0 0 0 -32511 -32254 -31997 -31740 -31483 -31226 -30969 -30712 -30455 -30198 -29941 -29684 -29427 -29170 -28913 0 0 0 -32511 -32254 -31997 -31740 -31483 -31226 -30969 -30712 -30455 -30198 -29941 -29684 -29427 -29170 -28913 0 0 0