ResizeLinear
Adjusts the size of an image.
Before calling the ResizeLinear function, you need to call Init for initialization, call the main function of the ResizeLinear function, and then call Release to release the related space. The image size can be adjusted in the following three ways:
- After the initialization, adjust the size of the entire image, and then release the space.
- After the initialization, adjust the size of each image block, and then release the space.
- Initialize each image block, adjust their size by using the Resize main function, and then release the space.
Currently, only the bilinear interpolation algorithm can be used to adjust the image size.
The function interface declaration is as follows:
- Initialization:
HmppResult HMPPI_ResizeLinearInit_8u(HmppiSize srcSize, HmppiSize dstSize, HmppiResizePolicy_32f** policy);
- Main functions:
HmppResult HMPPI_ResizeLinear_8u_C3R(const uint8_t *src, int32_t srcStep, uint8_t *dst, int32_t dstStep, HmppiPoint dstOffset, HmppiSize dstSize, HmppiBorderType border, const uint8_t *borderValue, const HmppResizePolicy_32f *policy);
HmppResult HMPPI_ResizeLinear_8u_C4R(const uint8_t *src, int32_t srcStep, uint8_t *dst, int32_t dstStep, HmppiPoint dstOffset, HmppiSize dstSize, HmppiBorderType border, const uint8_t *borderValue, const HmppResizePolicy_32f *policy);
- Release:
HmppResult HMPPI_ResizeLinearRelease_8u(HmppResizePolicy_32f *policy);
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 |
srcSize |
Size of the source image block |
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 |
dstOffset |
Offset of the destination image block |
The value must be zero or a positive integer. |
Input |
dstSize |
Size of the destination image block |
Positive integer |
Input |
border |
Algorithm for obtaining the border value |
The following algorithms are supported: HMPPI_BORDER_REPL HMPPI_BORDER_IN_MEM HMPPI_BORDER_REPL | HMPPI_BORDER_IN_MEM_BOTTOM HMPPI_BORDER_REPL | HMPPI_BORDER_IN_MEM_TOP HMPPI_BORDER_REPL | HMPPI_BORDER_IN_MEM_LEFT HMPPI_BORDER_REPL | HMPPI_BORDER_IN_MEM_RIGHT HMPPI_BORDER_REPL | HMPPI_BORDER_IN_MEM_RIGHT | HMPPI_BORDER_IN_MEM_BOTTOM HMPPI_BORDER_REPL | HMPPI_BORDER_IN_MEM_RIGHT | HMPPI_BORDER_IN_MEM_TOP HMPPI_BORDER_REPL | HMPPI_BORDER_IN_MEM_LEFT | HMPPI_BORDER_IN_MEM_BOTTOM HMPPI_BORDER_REPL | HMPPI_BORDER_IN_MEM_LEFT | HMPPI_BORDER_IN_MEM_TOP HMPPI_BORDER_REPL | HMPPI_BORDER_IN_MEM_RIGHT | HMPPI_BORDER_IN_MEM_BOTTOM | HMPPI_BORDER_IN_MEM_LEFT HMPPI_BORDER_REPL | HMPPI_BORDER_IN_MEM_RIGHT | HMPPI_BORDER_IN_MEM_TOP | HMPPI_BORDER_IN_MEM_BOTTOM HMPPI_BORDER_REPL | HMPPI_BORDER_IN_MEM_LEFT | HMPPI_BORDER_IN_MEM_BOTTOM | HMPPI_BORDER_IN_MEM_TOP HMPPI_BORDER_REPL | HMPPI_BORDER_IN_MEM_LEFT | HMPPI_BORDER_IN_MEM_TOP | HMPPI_BORDER_IN_MEM_RIGHT ER_REPL | HMPPI_BORDER_IN_MEM |
Input |
borderValue |
Border value |
Border value when border is set to HMPPI_BORDER_CONST |
Input |
policy |
Pointer to the special structure |
The value cannot be NULL. |
Input/Output |
Return Value
- Success: HMPP_STS_NO_ERR
- Failure: An error code is returned.
Error Codes
Error Code |
Description |
|---|---|
HMPP_STS_NO_OPERATION |
This is only an alarm and no operation needs to be performed. The width or height in srcSize and dstSize is 0. |
HMPP_STS_NULL_PTR_ERR |
A null pointer exists. |
HMPP_STS_MALLOC_FAILED |
Failed to allocate memory during policy initialization. |
HMPP_STS_SIZE_ERR |
The width or height in srcSize and dstSize is a negative value. Alternatively, the value of srcSize is less than 2 x 2. |
HMPP_STS_BORDER_ERR |
The algorithm type for obtaining the border value is not supported. |
HMPP_STS_OUT_OF_RANGE_ERR |
The offset value of the destination image block is greater than the width or height of the destination image block input by the Init function. |
HMPP_STS_SIZE_WRN |
The width or height of the destination image block is greater than the width or height of the destination image block input by the Init function. |
Example
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include "hmppi.h"
#include "hmpps.h"
int main ()
{
HmppiResizePolicy_32f *policy = NULL;
HmppiSize srcSize = {2, 2};
HmppiSize dstSize = {4, 4};
int32_t numChannels = 3;
HmppiBorderType borderType = HMPPI_BORDER_REPL;
const uint8_t borderValue = 0;
HmppResult result = 0;
HmppiPoint dstOffset = {0, 0};
uint8_t src[12] = {0, 255, 3, 6, 255, 0,
2, 1, 3, 4, 134, 23};
int32_t dstLen = dstSize.width * dstSize.height * numChannels;
uint8_t *dst = HMPPS_Malloc_8u(dstLen);
result = HMPPI_ResizeLinearInit_8u(srcSize, dstSize, &policy);
printf("result = %d\n", result);
int32_t srcStep = srcSize.width * numChannels * sizeof(uint8_t);
int32_t dstStep = dstSize.width * numChannels * sizeof(uint8_t);
result = HMPPI_ResizeLinear_8u_C3R(src, srcStep, dst, dstStep, dstOffset, dstSize, borderType, &borderValue, policy);
printf("result = %d\n", result);
HMPPI_ResizeLinearRelease_8u(policy);
printf("free policy end\n");
for (int32_t i = 0; i < dstLen; i++) {
printf("%d ", dst[i]);
}
printf("\n");
HMPPS_Free(dst);
}
Output:
result = 0 result = 0 free policy end 0 255 3 2 255 2 5 255 1 6 255 0 1 192 3 2 200 4 4 216 5 6 225 6 2 65 3 2 89 7 4 139 14 5 164 17 2 1 3 3 34 8 4 101 18 4 134 23