Rate This Document
Findability
Accuracy
Completeness
Readability

ResizeNearest

Adjusts the image size using the nearest-neighbor interpolation algorithm.

Before calling the ResizeNearest 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 function interface is declared as follows:

  • Initialization function:

    HmppResult HMPPI_ResizeNearestInit_32f(HmppiSize srcSize, HmppiSize dstSize, HmppiResizePolicy_32f **pSpec);

  • Main function:

    HmppResult HMPPI_ResizeNearest_32f_C1R(const float *pSrc, int srcStep, float *pDst, int dstStep, HmppiPoint dstOffset, HmppiSize dstSize, const HmppiResizePolicy_32f *pSpec);

  • Release function:

    HmppResult HMPPI_ResizeNearestRelease_32f(HmppiResizePolicy_32f *policy);

Parameters

Parameter

Description

Value Range

Input/Output

pSrc

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

pDst

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

pSpec

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 an alarm and no operation is 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 pSpec initialization.

HMPP_STS_SIZE_ERR

The width or height in srcSize and dstSize is a negative value.

HMPP_STS_STEP_ERR

  • srcStep or dstStep is not an integer multiple of the float byte length.
  • srcStep or dstStep is less than the product of the float byte length and srcwidth or dstwidth.

HMPP_STS_BORDER_ERR

The specified border algorithm type is not supported.

HMPP_STS_OUT_OF_RANGE_ERR

The offset 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

void ResizeNearestExample()
{
    HmppiSize srcSize = {3, 3};
    HmppiSize dstSize = {6, 6};
    HmppiPoint dstOffset = {0, 0};
    int srcStep = srcSize.width * sizeof(float);
    int dstStep = dstSize.width * sizeof(float);
    HmppiResizePolicy_32f *pSpec; 
    float pSrc[] = {0.0, 255.0, 3.0, 6.0, 255.0, 0.0, 2.0, 1.0, 3.0};
    int dstLen = dstSize.width * dstSize.height;
    float *pDst = HMPPS_Malloc_32f(dstLen);
    HMPPI_ResizeNearestInit_32f(srcSize, dstSize, &pSpec);
    HmppResult result = HMPPI_ResizeNearest_32f_C1R (
        pSrc, srcStep, pDst, dstStep, dstOffset, dstSize, &pSpec);
    printf("result = %d\n", result);
    if (result != HMPP_STS_NO_ERR) {
        return;
    } 
    for (int i = 0; i < dstLen; i++){
        printf("%f ", pDst[i]);
    }
    printf("\n");
    HMPPI_ResizeNearestRelease_32f(pSpec);
}

Output:

result = 0
0.000000 255.000000 255.000000 3.000000 3.000000 0.000000 6.000000 255.000000 255.000000 0.000000 0.000000 0.000000 6.000000 255.000000 255.000000 0.000000 0.000000 0.000000 2.000000 1.000000 1.000000 3.000000 3.000000 0.000000 2.000000 1.000000 1.000000 3.000000 3.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000