Rate This Document
Findability
Accuracy
Completeness
Readability

CompareC

Compares each pixel value of an image with a fixed value using a specific comparison method.

The function interface is declared as follows:

HmppResult HMPPI_CompareC_8u_C1R(const uint8_t* pSrc, int srcStep, uint8_t value, uint8_t* pDst, int dstStep, HmppiSize roiSize, HmppCmpOp cmpOp);

Parameters

Parameter

Description

Value Range

Input/Output

pSrc

Pointer to the source vector

The value cannot be NULL.

Input

srcStep

Distance between starts of consecutive lines in the source image, in bytes

(0, INT_MAX]

Input

value

Fixed value used for comparison

[-UINT8_MAX, UINT8_MAX]

Input

pDst

Pointer to the destination vector

The value cannot be NULL.

Output

dstStep

Distance between starts of consecutive lines in the destination image, in bytes

(0, INT_MAX]

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

Enumeration, specifying the comparison method

  • HMPP_CMP_EQ: Compares whether a pixel is equal to the fixed value.
  • HMPP_CMP_GE: Compares whether a pixel is greater than or equal to the fixed value.
  • HMPP_CMP_LE: Compares whether a pixel is less than or equal to the fixed value.
  • HMPP_CMP_GT: Compares whether a pixel is greater than the fixed value.
  • HMPP_CMP_LT: Compares whether a pixel is less than the fixed 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

The value of src or max is NULL.

HMPP_STS_STEP_ERR

The value of srcStep is less than or equal to 0.

HMPP_STS_SIZE_ERR

The value of roiSize.width or roiSize.height is less than or equal to 0.

HMPP_STS_ROI_ERR

The value of roiSize.width is greater than the step.

Example

#include <stdio.h>
#include "hmppi.h"
#include "hmpp_type.h"
void CompareCExample()
{
    HmppiSize roi = {5, 7};
    uint8_t src[45] = {1, 2, 3, 4, 5,
                       1, 2, 3, 4, 5,
                       1, 2, 3, 4, 5,
                       1, 2, 3, 4, 5,
                       1, 2, 3, 4, 5,
                       1, 2, 3, 4, 5,
                       1, 2, 3, 4, 5,
                       1, 2, 3, 4, 5,
                       1, 2, 3, 4, 5
                      };
    uint8_t dst[49] = {0};
    int32_t srcStep = 5 * sizeof(uint8_t);
    int32_t dstStep = 7 * sizeof(uint8_t);
    int32_t value = 3;
    HmppCmpOp cmpop = HMPP_CMP_GE;
    (void)HMPPI_CompareC_8u_C1R(src, srcStep, value, dst, dstStep, roi, cmpop);
    for (int i = 0; i < 7; i++) {
        for (int j = 0; j < 7; j++) {
            printf("%d ", dst[i * 7 + j]);
        }
        printf("\n");
    }
}
int main()
{
    CompareCExample();
    return 0;
}

Output:

0 0 255 255 255 0 0 
0 0 255 255 255 0 0 
0 0 255 255 255 0 0 
0 0 255 255 255 0 0 
0 0 255 255 255 0 0 
0 0 255 255 255 0 0 
0 0 255 255 255 0 0