From c61bb864c026d26a393f2a09c82de9bbc5043c6f Mon Sep 17 00:00:00 2001 From: Christian C Date: Tue, 4 Mar 2025 19:10:07 -0800 Subject: Modularization --- include/lib/algo/flood_fill.h | 20 ++++++++++++++++++++ include/lib/bool.h | 8 ++++++++ include/lib/color.h | 22 ++++++++++++++++++++++ include/lib/dir.h | 15 +++++++++++++++ include/lib/lib.h | 4 ++-- include/lib/time.h | 15 +++++++++++++++ 6 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 include/lib/algo/flood_fill.h create mode 100644 include/lib/bool.h create mode 100644 include/lib/color.h create mode 100644 include/lib/dir.h create mode 100644 include/lib/time.h (limited to 'include') diff --git a/include/lib/algo/flood_fill.h b/include/lib/algo/flood_fill.h new file mode 100644 index 0000000..a48f4a1 --- /dev/null +++ b/include/lib/algo/flood_fill.h @@ -0,0 +1,20 @@ +#ifndef INC_LIB_ALGO_FLOOD_FILL_H +#define INC_LIB_ALGO_FLOOD_FILL_H + +#include +#include +#include +#include + +//----------------------------------------------- +// Flood +// Floods a mask from a given set of image to determine the contiguous regions +// 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 +// 5. If all hold, set the label for the pixel, and check each neighbor +// Otherwise, stop flooding +bool_t flood(uint8_t* image, uint16_t* mask, size_t width, size_t height, size_t channels, size_t x, size_t y, uint8_t* fill_color, uint16_t label); + +#endif diff --git a/include/lib/bool.h b/include/lib/bool.h new file mode 100644 index 0000000..6bf4c40 --- /dev/null +++ b/include/lib/bool.h @@ -0,0 +1,8 @@ +#ifndef INC_LIB_BOOL_H +#define INC_LIB_BOOL_H + +#define bool_t uint8_t +#define FALSE 0 +#define TRUE 1 + +#endif diff --git a/include/lib/color.h b/include/lib/color.h new file mode 100644 index 0000000..b999510 --- /dev/null +++ b/include/lib/color.h @@ -0,0 +1,22 @@ +#ifndef INC_LIB_COLOR_H +#define INC_LIB_COLOR_H + +#include +#include +#include + +//----------------------------------------------- +// Color Equal to Background +// Background: zeros in RGB, alpha can be whatever +bool_t color_zero(uint8_t* color1, size_t channels); + +//----------------------------------------------- +// Color Equality +// Determine if two colors are identical +bool_t color_equal(uint8_t* color1, uint8_t* color2, size_t channels); + +//----------------------------------------------- +// Print out the `channels` length color vector +void print_color(uint8_t* color, size_t channels); + +#endif diff --git a/include/lib/dir.h b/include/lib/dir.h new file mode 100644 index 0000000..6177735 --- /dev/null +++ b/include/lib/dir.h @@ -0,0 +1,15 @@ +#ifndef INC_LIB_DIR_H +#define INC_LIB_DIR_H + +#include +#include + +//----------------------------------------------- +// Is directory +bool_t is_directory(char* dirname); + +//----------------------------------------------- +// List directory +char** lsdir(char* dirname); + +#endif diff --git a/include/lib/lib.h b/include/lib/lib.h index b8db686..8ca17f8 100644 --- a/include/lib/lib.h +++ b/include/lib/lib.h @@ -1,8 +1,8 @@ -#include - #ifndef INC_LIB_LIB_H #define INC_LIB_LIB_H +#include + extern const uint32_t SCREEN_WIDTH; extern const uint32_t SCREEN_HEIGHT; diff --git a/include/lib/time.h b/include/lib/time.h new file mode 100644 index 0000000..aebc6ed --- /dev/null +++ b/include/lib/time.h @@ -0,0 +1,15 @@ +#ifndef INC_LIB_TIME_H +#define INC_LIB_TIME_H + +#include + +//----------------------------------------------- +// Difference in Time +// Compute the difference between timespec structs +double diff_time(struct timespec *time1, struct timespec *time0); + +//----------------------------------------------- +// Get Current Time +void get_time(struct timespec *ts); + +#endif -- cgit v1.2.1