aboutsummaryrefslogtreecommitdiff
path: root/lib/algo/flood_fill.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/algo/flood_fill.c')
-rw-r--r--lib/algo/flood_fill.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/lib/algo/flood_fill.c b/lib/algo/flood_fill.c
index d11b5aa..e2ee870 100644
--- a/lib/algo/flood_fill.c
+++ b/lib/algo/flood_fill.c
@@ -5,29 +5,30 @@
// 1. Check that the (x,y) is within the picture
// 2. Check if the (x,y) coordinate in the mask is unused
// 3. Check if the (x,y) coordinate in the image is non-background
-// 4. Check if the (x,y) coordinate in the image is the same color as the fill color
+// 4. Check if the (x,y) coordinate in the image is the same color as the fill
+// color
// 5. If all hold, set the label for the pixel, and check each neighbor
// Otherwise, stop flooding
-bool_t flood(ImageData_t* image, MaskData_t* mask, size_t width, size_t height, size_t channels, size_t x, size_t y, ImageData_t* fill_color, MaskData_t label)
-{
+bool_t flood(ImageData_t *image, MaskData_t *mask, size_t width, size_t height,
+ size_t channels, size_t x, size_t y, ImageData_t *fill_color,
+ MaskData_t label) {
if ((x >= width) | (y >= height)) {
return FALSE;
}
- size_t coord = x + y*width;
+ size_t coord = x + y * width;
if (mask[coord] != 0) {
return FALSE;
}
- if (color_zero(&(image[coord*channels]), channels)) {
+ if (color_zero(&(image[coord * channels]), channels)) {
return FALSE;
}
- if (color_equal(&(image[coord*channels]), fill_color, channels)) {
+ if (color_equal(&(image[coord * channels]), fill_color, channels)) {
mask[coord] = label;
- flood(image, mask, width, height, channels, x, y+1, fill_color, label);
- flood(image, mask, width, height, channels, x, y-1, fill_color, label);
- flood(image, mask, width, height, channels, x+1, y, fill_color, label);
- flood(image, mask, width, height, channels, x-1, y, fill_color, label);
+ flood(image, mask, width, height, channels, x, y + 1, fill_color, label);
+ flood(image, mask, width, height, channels, x, y - 1, fill_color, label);
+ flood(image, mask, width, height, channels, x + 1, y, fill_color, label);
+ flood(image, mask, width, height, channels, x - 1, y, fill_color, label);
return TRUE;
}
return FALSE;
}
-