aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorChristian C <cc@localhost>2025-03-22 22:27:40 -0700
committerChristian C <cc@localhost>2025-03-22 22:27:40 -0700
commit16422831ed49c573c1b8a43ba907bceb00fd5eea (patch)
tree1c2d86d5eecf6d1b7b4951f0b20f8c86e6939ac2 /include
parent123464e36f2a151d820e08db7b4b426ca2b3657a (diff)
Named Types
Diffstat (limited to 'include')
-rw-r--r--include/lib/algo/avl_tree.h8
-rw-r--r--include/lib/algo/flood_fill.h3
-rw-r--r--include/lib/color.h7
-rw-r--r--include/lib/data/image_types.h11
-rw-r--r--include/lib/png.h10
-rw-r--r--include/lib/seg/mask_data.h29
-rw-r--r--include/lib/seg/util.h17
-rw-r--r--include/test/__meta__.h3
-rw-r--r--include/test/lib/color.h5
9 files changed, 55 insertions, 38 deletions
diff --git a/include/lib/algo/avl_tree.h b/include/lib/algo/avl_tree.h
index f77ce5b..4467fd1 100644
--- a/include/lib/algo/avl_tree.h
+++ b/include/lib/algo/avl_tree.h
@@ -6,19 +6,21 @@
#include <stdlib.h>
#include <sys/types.h>
+#define AvlHeight_t uint8_t
+
struct AVLNode {
void* data;
bool_t (*compare)(void*, void*);
struct AVLNode* left;
struct AVLNode* right;
- uint8_t height;
+ AvlHeight_t height;
};
// Get the height of an AVL node
-uint8_t get_height(struct AVLNode* node);
+AvlHeight_t get_height(struct AVLNode* node);
// Get the Maximum Height between two
-uint8_t max_height(uint8_t a, uint8_t b);
+AvlHeight_t max_height(AvlHeight_t a, AvlHeight_t b);
// Get the balance factor of a node
ssize_t get_balance_factor(struct AVLNode* node);
diff --git a/include/lib/algo/flood_fill.h b/include/lib/algo/flood_fill.h
index 81ed6fd..e9872eb 100644
--- a/include/lib/algo/flood_fill.h
+++ b/include/lib/algo/flood_fill.h
@@ -3,6 +3,7 @@
#include <lib/bool.h>
#include <lib/color.h>
+#include <lib/data/image_types.h>
#include <stddef.h>
#include <stdint.h>
@@ -14,6 +15,6 @@
// 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);
+bool_t flood(ImageData_t* image, ImageMaskData_t* mask, size_t width, size_t height, size_t channels, size_t x, size_t y, ImageData_t* fill_color, ImageMaskData_t label);
#endif
diff --git a/include/lib/color.h b/include/lib/color.h
index 1bc9393..ceaecbd 100644
--- a/include/lib/color.h
+++ b/include/lib/color.h
@@ -4,16 +4,17 @@
#include <stdint.h>
#include <stddef.h>
#include <lib/bool.h>
+#include <lib/data/image_types.h>
// Color Equal to Background
// Background: zeros in RGB, alpha can be whatever
-bool_t color_zero(const uint8_t* color1, size_t channels);
+bool_t color_zero(const ImageData_t* color1, size_t channels);
// Color Equality
// Determine if two colors are identical
-bool_t color_equal(const uint8_t* color1, const uint8_t* color2, size_t channels);
+bool_t color_equal(const ImageData_t* color1, const ImageData_t* color2, size_t channels);
// Print out the `channels` length color vector
-void print_color(uint8_t* color, size_t channels);
+void print_color(ImageData_t* color, size_t channels);
#endif
diff --git a/include/lib/data/image_types.h b/include/lib/data/image_types.h
index 0360d89..76b1472 100644
--- a/include/lib/data/image_types.h
+++ b/include/lib/data/image_types.h
@@ -1,19 +1,22 @@
#ifndef INC_LIB_DATA_IMAGE_TYPES_H
#define INC_LIB_DATA_IMAGE_TYPES_H
+#include <stdint.h>
+#include <stddef.h>
+
#define ImageData_t uint8_t
-#define MaskData_t uint16_t
+#define ImageMaskData_t uint16_t
-struct ImageData {
+struct Image {
size_t width;
size_t height;
ImageData_t** image;
};
-struct ImageData {
+struct ImageMask {
size_t width;
size_t height;
- MaskData_t** image;
+ ImageMaskData_t** mask;
};
#endif
diff --git a/include/lib/png.h b/include/lib/png.h
index e7943c2..ddc1db3 100644
--- a/include/lib/png.h
+++ b/include/lib/png.h
@@ -4,10 +4,14 @@
#include <stdint.h>
#include <sys/types.h>
+#define PixelChannel_t uint8_t
+#define PixelSize_t uint8_t
+#define PixelDepth_t uint8_t
+
struct pixel_t {
- uint8_t red;
- uint8_t green;
- uint8_t blue;
+ PixelChannel_t red;
+ PixelChannel_t green;
+ PixelChannel_t blue;
};
struct bitmap_t {
diff --git a/include/lib/seg/mask_data.h b/include/lib/seg/mask_data.h
index 8e2ae3a..bbaf38c 100644
--- a/include/lib/seg/mask_data.h
+++ b/include/lib/seg/mask_data.h
@@ -2,16 +2,17 @@
#define INC_LIB_SEG_MASK_DATA_H
#include <lib/algo/avl_tree.h>
+#include <lib/data/image_types.h>
#include <lib/monad.h>
struct MaskData {
- uint16_t label;
+ ImageMaskData_t label;
size_t area;
size_t perimeter;
};
// Allocate Mask Data for Label
-struct MaskData* create_mask_data(uint16_t label);
+struct MaskData* create_mask_data(ImageMaskData_t label);
// Compare mask data labels
bool_t compare_labels(struct MaskData* left, struct MaskData* right);
@@ -24,42 +25,42 @@ struct Result insert_mask(struct AVLNode* node, struct MaskData* data);
// Allocate a label's Mask data in a tree
// If it already exists, skip the allocation
-struct AVLNode* insert_mask_alloc(struct AVLNode* node, uint16_t label);
+struct AVLNode* insert_mask_alloc(struct AVLNode* node, ImageMaskData_t label);
// Print AVL Node Mask Data Label
void print_label(struct AVLNode* root);
// Increase the label's area
-bool_t increase_label_area(struct AVLNode* root, uint16_t label);
+bool_t increase_label_area(struct AVLNode* root, ImageMaskData_t label);
// Increase the label's perimeter
-bool_t increase_label_perimeter(struct AVLNode* root, uint16_t label);
+bool_t increase_label_perimeter(struct AVLNode* root, ImageMaskData_t label);
// Increase the label's area
// Create an AVL node if it doesn't exist
-struct AVLNode* increase_label_area_alloc(struct AVLNode* root, uint16_t label);
+struct AVLNode* increase_label_area_alloc(struct AVLNode* root, ImageMaskData_t label);
// Increase the label's perimeter
// Create an AVL node if it doesn't exist
-struct AVLNode* increase_label_perimeter_alloc(struct AVLNode* root, uint16_t label);
+struct AVLNode* increase_label_perimeter_alloc(struct AVLNode* root, ImageMaskData_t label);
-// Comparison of uint16_ts
-bool_t compare_uint16_t(uint16_t* s1, uint16_t* s2);
+// Comparison of ImageMaskData_ts
+bool_t compare_image_mask_data_t(ImageMaskData_t* s1, ImageMaskData_t* s2);
// In-order traversal print pointer
-void print_in_order_uint16_t(struct AVLNode* root);
+void print_in_order_image_mask_data_t(struct AVLNode* root);
-// Check if uint16_t in AVLTree with uint16_t* data
-bool_t in_uint16_t_tree(struct AVLNode* root, uint16_t value);
+// Check if ImageMaskData_t in AVLTree with ImageMaskData_t* data
+bool_t in_image_mask_data_t_tree(struct AVLNode* root, ImageMaskData_t value);
// Filter out small masks
// Assumption: Contiguous labeling
struct AVLNode* get_small_labels(struct AVLNode* removal_tree, struct AVLNode* label_tree, size_t min_area, size_t min_perimeter);
// Get mask label data
-struct AVLNode* get_mask_data(uint16_t* masks, uint32_t width, uint32_t height);
+struct AVLNode* get_mask_data(ImageMaskData_t* masks, uint32_t width, uint32_t height);
// Filter out small masks in mask
-void filter_small_masks(uint16_t* masks, uint32_t width, uint32_t height, size_t min_area, size_t min_perimeter);
+void filter_small_masks(ImageMaskData_t* masks, uint32_t width, uint32_t height, size_t min_area, size_t min_perimeter);
#endif
diff --git a/include/lib/seg/util.h b/include/lib/seg/util.h
index c54b0e0..ef85c2c 100644
--- a/include/lib/seg/util.h
+++ b/include/lib/seg/util.h
@@ -2,6 +2,7 @@
#define INC_LIB_SEG_UTIL_H
#include <lib/bool.h>
+#include <lib/data/image_types.h>
#include <stdint.h>
#include <stddef.h>
@@ -10,33 +11,33 @@ size_t xy_to_coord(size_t x, size_t y, uint32_t width, uint32_t height);
// Determine if coordinate is on a mask boundary
// Assumes mask is (WxH)
-bool_t is_on_mask_boundary(uint16_t* mask, uint32_t width, uint32_t height, size_t x, size_t y);
+bool_t is_on_mask_boundary(ImageMaskData_t* mask, uint32_t width, uint32_t height, size_t x, size_t y);
// Dilate masks by one 4-connected pixel
-void dilate(uint16_t** mask, uint32_t width, uint32_t height);
+void dilate(ImageMaskData_t** mask, uint32_t width, uint32_t height);
// Erode masks by one 4-connected pixel
-void erode(uint16_t** mask, uint32_t width, uint32_t height);
+void erode(ImageMaskData_t** mask, uint32_t width, uint32_t height);
// Close up masks by N-pixels
-void closeup(uint16_t** mask, uint32_t width, uint32_t height, size_t count);
+void closeup(ImageMaskData_t** mask, uint32_t width, uint32_t height, size_t count);
// Combine Label Masks
// For all empty spaces in the destination, put the extra label if it exists
// Allocates an array if destination is unallocated
-uint16_t* combine_masks(uint16_t *destination, uint16_t *extra_labels, uint32_t width, uint32_t height);
+ImageMaskData_t* combine_masks(ImageMaskData_t *destination, ImageMaskData_t *extra_labels, uint32_t width, uint32_t height);
// Process Tif File to Labels
// width, height will be overwritten with image dimensions
// starting_label_p will be incremented for each label found in the image
-uint16_t* tif_to_labels(char* tif_file_name, uint32_t *width, uint32_t *height, uint16_t *starting_label_p);
+ImageMaskData_t* tif_to_labels(char* tif_file_name, uint32_t *width, uint32_t *height, ImageMaskData_t *starting_label_p);
// Convert mask to bitmap
-struct bitmap_t* uint16_to_bitmap(uint16_t* buffer, uint32_t width, uint32_t height);
+struct bitmap_t* image_mask_data_to_bitmap(ImageMaskData_t* buffer, uint32_t width, uint32_t height);
// Reduce a mask to the contiguous regions
// Automatically update pointer to contiguous mask
// Freeing previous mask
-void reduce_contiguous_regions(uint16_t** masks_p, uint32_t width, uint32_t height, uint16_t* total_labels);
+void reduce_contiguous_regions(ImageMaskData_t** masks_p, uint32_t width, uint32_t height, ImageMaskData_t* total_labels);
#endif
diff --git a/include/test/__meta__.h b/include/test/__meta__.h
index 305698a..17e0b99 100644
--- a/include/test/__meta__.h
+++ b/include/test/__meta__.h
@@ -3,6 +3,9 @@
#include <lib/bool.h>
#include <stdio.h>
+#include <stddef.h>
+
+#define TestCount_t uint16_t
#ifdef TEST_SHOW_PASS
#define _TEST_PASS(s,sub,n) fprintf(stderr, "(%4X) \x1b[92mPASS\x1b[0m %s/%s\n", ++n, s, sub)
diff --git a/include/test/lib/color.h b/include/test/lib/color.h
index be0d62f..2e9b863 100644
--- a/include/test/lib/color.h
+++ b/include/test/lib/color.h
@@ -7,9 +7,10 @@
#endif
#include <lib/color.h>
+#include <lib/data/image_types.h>
-bool_t test_color_zero(const uint8_t* color1, size_t channels, bool_t result);
-bool_t test_color_equal(const uint8_t* color1, const uint8_t* color2, size_t channels, bool_t result);
+bool_t test_color_zero(const ImageData_t* color1, size_t channels, bool_t result);
+bool_t test_color_equal(const ImageData_t* color1, const ImageData_t* color2, size_t channels, bool_t result);
// Meta test function
bool_t TEST_lib_color();