FloodFill
Performs a flood fill operation on an image.
The function interface is declared as follows:
HmppResult HMPPI_FloodFill_4Con_8u_C1IR(uint8_t *srcDst, int srcDstStep, HmppiSize roiSize, HmppiPoint seed, uint8_t newVal, HmppiConnectedComp *pRegion);
HmppResult HMPPI_FloodFill_8Con_32f_C1IR(float *srcDst, int srcDstStep, HmppiSize roiSize, HmppiPoint seed, float newVal, HmppiConnectedComp *pRegion);
HmppResult HMPPI_FloodFill_8Con_8u_C1IR(uint8_t *srcDst, int srcDstStep, HmppiSize roiSize, HmppiPoint seed, uint8_t newVal, HmppiConnectedComp *pRegion);
Parameters
Parameter |
Description |
Value Range |
Input/Output |
|---|---|---|---|
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 |
seed |
Start point (seed) for the flood fill operation within the source image |
seed.x ∈ (0, INT_MAX], seed.y ∈ (0, INT_MAX] |
Input |
newVal |
New value for the flood fill operation |
Range of the input data type |
Input |
pRegion |
Pointer to the connected component structure |
The value cannot be NULL. |
Output |
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 srcDst or pRegion is NULL. |
HMPP_STS_SIZE_ERR |
The value of roiSize is 0 or negative. |
HMPP_STS_STEP_ERR |
The value of srcDstStep 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 srcDstStep cannot be exactly divided by the byte length of the data type to which srcDst belongs. |
Example
#include <stdio.h>
#include "hmppi.h"
#include "hmpp_type.h"
void FloodFillExample()
{
HmppiSize roi = {7, 7};
uint8_t srcDst[50] = { 1, 1, 1, 1, 1, 1, 1,
0, 0, 1, 0, 0, 0, 1,
0, 1, 1, 1, 0, 1, 1,
0, 0, 0, 0, 1, 1, 1,
0, 0, 1, 0, 0, 1, 1,
0, 0, 0, 0, 1, 0, 1,
1, 1, 1, 1, 1, 1, 1
};
int32_t srcDstStep = 7 * sizeof(uint8_t);
HmppiPoint seed = {3, 3};
uint8_t newVal = 2;
HmppiConnectedComp pRegion;
HmppResult res = HMPPI_FloodFill_4Con_8u_C1IR(srcDst, srcDstStep, roi, seed, newVal, &pRegion);
printf("result: %d\n", (int)res);
for (int i = 0; i < 7; i++) {
for (int j = 0; j < 7; j++) {
printf("%d ", srcDst[i * 7 + j]);
}
printf("\n");
}
}
int main()
{
FloodFillExample();
return 0;
}
Output:
result: 0 1 1 1 1 1 1 1 2 2 1 0 0 0 1 2 1 1 1 0 1 1 2 2 2 2 1 1 1 2 2 1 2 2 1 1 2 2 2 2 1 0 1 1 1 1 1 1 1 1