SwapChannels
Copies the channel data of a specified region in the source image to a specified region in the destination image in a certain order.
The function interface declaration is as follows:
HmppResult HMPPI_SwapChannels_8u_C3R(const uint8_t *src, int32_t src_step, uint8_t *dst, int32_t dst_step, HmppiSize roi_size, const int32_t dst_order[3]);
HmppResult HMPPI_SwapChannels_16u_C3R(const uint16_t *src, int32_t src_step, uint16_t *dst, int32_t dst_step, HmppiSize roi_size, const int32_t dst_order[3]);
HmppResult HMPPI_SwapChannels_16s_C3R(const int16_t *src, int32_t src_step, int16_t *dst, int32_t dst_step, HmppiSize roi_size, const int32_t dst_order[3]);
HmppResult HMPPI_SwapChannels_32s_C3R(const int32_t *src, int32_t src_step, int32_t *dst, int32_t dst_step, HmppiSize roi_size, const int32_t dst_order[3]);
HmppResult HMPPI_SwapChannels_32f_C3R(const float *src, int32_t src_step, float *dst, int32_t dst_step, HmppiSize roi_size, const int32_t dst_order[3]);
HmppResult HMPPI_SwapChannels_8u_AC4R(const uint8_t *src, int32_t src_step, uint8_t *dst, int32_t dst_step, HmppiSize roi_size, const int32_t dst_order[3]);
HmppResult HMPPI_SwapChannels_16u_AC4R(const uint16_t *src, int32_t src_step, uint16_t *dst, int32_t dst_step, HmppiSize roi_size, const int32_t dst_order[3]);
HmppResult HMPPI_SwapChannels_16s_AC4R(const int16_t *src, int32_t src_step, int16_t *dst, int32_t dst_step, HmppiSize roi_size, const int32_t dst_order[3]);
HmppResult HMPPI_SwapChannels_32s_AC4R(const int32_t *src, int32_t src_step, int32_t *dst, int32_t dst_step, HmppiSize roi_size, const int32_t dst_order[3]);
HmppResult HMPPI_SwapChannels_32f_AC4R(const float *src, int32_t src_step, float *dst, int32_t dst_step, HmppiSize roi_size, const int32_t dst_order[3]);
HmppResult HMPPI_SwapChannels_8u_C4R(const uint8_t *src, int32_t src_step, uint8_t *dst, int32_t dst_step, HmppiSize roi_size, const int32_t dst_order[4]);
HmppResult HMPPI_SwapChannels_16u_C4R(const uint16_t *src, int32_t src_step, uint16_t *dst, int32_t dst_step, HmppiSize roi_size, const int32_t dst_order[4]);
HmppResult HMPPI_SwapChannels_16s_C4R(const int16_t *src, int32_t src_step, int16_t *dst, int32_t dst_step, HmppiSize roi_size, const int32_t dst_order[4]);
HmppResult HMPPI_SwapChannels_32s_C4R(const int32_t *src, int32_t src_step, int32_t *dst, int32_t dst_step, HmppiSize roi_size, const int32_t dst_order[4]);
HmppResult HMPPI_SwapChannels_32f_C4R(const float *src, int32_t src_step, float *dst, int32_t dst_step, HmppiSize roi_size, const int32_t dst_order[4]);
HmppResult HMPPI_SwapChannels_8u_C3IR(uint8_t *srcdst, int32_t srcdst_step, HmppiSize roi_size, const int32_t dst_order[3]);
HmppResult HMPPI_SwapChannels_8u_C4IR(uint8_t *srcdst, int32_t srcdst_step, HmppiSize roi_size, const int32_t dst_order[4]);
HmppResult HMPPI_SwapChannels_8u_C3C4R(const uint8_t *src, int32_t src_step, uint8_t *dst, int32_t dst_step, HmppiSize roi_size, const int32_t dst_order[4], uint8_t val);
HmppResult HMPPI_SwapChannels_16u_C3C4R(const uint16_t *src, int32_t src_step, uint16_t *dst, int32_t dst_step, HmppiSize roi_size, const int32_t dst_order[4], uint16_t val);
HmppResult HMPPI_SwapChannels_16s_C3C4R(const int16_t *src, int32_t src_step, int16_t *dst, int32_t dst_step, HmppiSize roi_size, const int32_t dst_order[4], int16_t val);
HmppResult HMPPI_SwapChannels_32s_C3C4R(const int32_t *src, int32_t src_step, int32_t *dst, int32_t dst_step, HmppiSize roi_size, const int32_t dst_order[4], int32_t val);
HmppResult HMPPI_SwapChannels_32f_C3C4R(const float *src, int32_t src_step, float *dst, int32_t dst_step, HmppiSize roi_size, const int32_t dst_order[4], float val);
HmppResult HMPPI_SwapChannels_8u_C4C3R(const uint8_t *src, int32_t src_step, uint8_t *dst, int32_t dst_step, HmppiSize roi_size, const int32_t dst_order[3]);
HmppResult HMPPI_SwapChannels_16u_C4C3R(const uint16_t *src, int32_t src_step, uint16_t *dst, int32_t dst_step, HmppiSize roi_size, const int32_t dst_order[3]);
HmppResult HMPPI_SwapChannels_16s_C4C3R(const int16_t *src, int32_t src_step, int16_t *dst, int32_t dst_step, HmppiSize roi_size, const int32_t dst_order[3]);
HmppResult HMPPI_SwapChannels_32s_C4C3R(const int32_t *src, int32_t src_step, int32_t *dst, int32_t dst_step, HmppiSize roi_size, const int32_t dst_order[3]);
HmppResult HMPPI_SwapChannels_32f_C4C3R(const float *src, int32_t src_step, float *dst, int32_t dst_step, HmppiSize roi_size, const int32_t dst_order[3]);
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 |
srcDst |
Pointer to the source and destination buffers |
The value cannot be NULL. |
Input/Output |
srcDstStep |
Distance between the starts of consecutive lines in the source image and the destination image |
The value must be zero or a positive integer. |
Input |
roiSize |
Size of the ROI of the source and destination images, in pixels |
The value must be zero or a positive integer. |
Input |
dstOrder |
Order of channels in the destination image |
Random combination of 0, 1, and 2 or random combination of 0, 1, 2, and 3 |
Input |
val |
Constant value |
Any constant value |
Input |
Return Value
- Success: HMPP_STS_NO_ERR
- Failure: An error code is returned.
Error Codes
Error Code |
Description |
|---|---|
HMPP_STS_NULL_PTR_ERR |
A null pointer exists in src or dst, or the value of dstorder 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 zero 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 value of srcStep or dstStep cannot be exactly divided by the byte length of the data type to which src or dst belongs. |
HMPP_STS_NO_ERR |
No error occurs. |
Example
#define SRC_BUFFER_SIZE_T 36
#define DST_BUFFER_SIZE_T 40
void PrintResult(HmppResult result, uint8_t *dst, int32_t dstStep)
{
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\n");
}
void TestExample()
{
HmppiSize roi = { 2, 4 };
const uint8_t src[SRC_BUFFER_SIZE_T] = {
53, 111, 2, 61, 6, 12,
77, 184, 5, 99, 3, 4,
41, 233, 1, 27, 5, 6,
62, 157, 6, 80, 7, 8
};
int32_t srcStep = 6 * sizeof(uint8_t);
uint8_t dst[DST_BUFFER_SIZE_T] = { 0 };
int32_t dstStep = 8 * sizeof(uint8_t);
const int32_t dst_order[3] = {2, 0, 1};
HmppResult result = HMPPI_SwapChannels_8u_C3R(src, srcStep, dst, dstStep, roi, dst_order);
PrintResult(result, dst, dstStep);
}
int main()
{
TestExample();
return 0;
}
Output:
result = 0 dst = 2 53 111 12 61 6 0 0 5 77 184 4 99 3 0 0 1 41 233 6 27 5 0 0 6 62 157 8 80 7 0 0 0 0 0 0 0 0 0 0