aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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
-rw-r--r--lib/algo/avl_tree.c4
-rw-r--r--lib/algo/flood_fill.c2
-rw-r--r--lib/color.c6
-rw-r--r--lib/png.c6
-rw-r--r--lib/seg/mask_data.c44
-rw-r--r--lib/seg/util.c72
-rw-r--r--src/prog.c10
-rw-r--r--src/visual.c14
-rw-r--r--test/lib/color.c22
-rw-r--r--test/lib/dir.c10
-rw-r--r--test/lib/time.c6
20 files changed, 153 insertions, 136 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();
diff --git a/lib/algo/avl_tree.c b/lib/algo/avl_tree.c
index 9d38662..3b5c8aa 100644
--- a/lib/algo/avl_tree.c
+++ b/lib/algo/avl_tree.c
@@ -5,7 +5,7 @@
#include <stdio.h>
// Get the height of an AVL node
-uint8_t get_height(struct AVLNode* node)
+AvlHeight_t get_height(struct AVLNode* node)
{
if (node == NULL) {
return 0;
@@ -14,7 +14,7 @@ uint8_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)
{
return (a > b) ? a : b;
}
diff --git a/lib/algo/flood_fill.c b/lib/algo/flood_fill.c
index 62db658..0506532 100644
--- a/lib/algo/flood_fill.c
+++ b/lib/algo/flood_fill.c
@@ -8,7 +8,7 @@
// 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)
{
if ((x >= width) | (y >= height)) {
return FALSE;
diff --git a/lib/color.c b/lib/color.c
index a0a50fd..172b627 100644
--- a/lib/color.c
+++ b/lib/color.c
@@ -4,7 +4,7 @@
// 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) {
for (size_t idx = 0; idx < channels; idx++) {
if (idx == 3) {
break;
@@ -18,7 +18,7 @@ bool_t color_zero(const uint8_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) {
for (size_t idx = 0; idx < channels; idx++) {
if (color1[idx] != color2[idx]) {
return FALSE;
@@ -28,7 +28,7 @@ bool_t color_equal(const uint8_t* color1, const uint8_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) {
for (size_t index = 0; index < channels; index++) {
printf("%hhu ", color[index]);
}
diff --git a/lib/png.c b/lib/png.c
index d12a765..8d71ac8 100644
--- a/lib/png.c
+++ b/lib/png.c
@@ -9,8 +9,8 @@ void save_png(struct bitmap_t* bitmap, char* fname)
FILE *fp;
png_structp png_ptr = NULL;
png_infop info_ptr = NULL;
- uint8_t pixel_size = 3;
- uint8_t pixel_depth = 8;
+ PixelSize_t pixel_size = 3;
+ PixelDepth_t pixel_depth = 8;
png_byte ** row_pointers = NULL;
size_t x, y;
fp = fopen(fname, "wb");
@@ -43,7 +43,7 @@ void save_png(struct bitmap_t* bitmap, char* fname)
row_pointers = png_malloc(png_ptr, bitmap->height*sizeof(png_byte*));
for (y = 0; y < bitmap->height; y++) {
- png_byte *row = png_malloc(png_ptr, sizeof(uint8_t)*bitmap->width*pixel_size);
+ png_byte *row = png_malloc(png_ptr, sizeof(PixelChannel_t)*bitmap->width*pixel_size);
row_pointers[y] = row;
for (x = 0; x < bitmap->width; x++) {
*row++ = bitmap->image_buffer[x + y*bitmap->width].red;
diff --git a/lib/seg/mask_data.c b/lib/seg/mask_data.c
index 8c4b037..dc3a811 100644
--- a/lib/seg/mask_data.c
+++ b/lib/seg/mask_data.c
@@ -4,7 +4,7 @@
#include <stdio.h>
// Allocate Mask Data for Label
-struct MaskData* create_mask_data(uint16_t label)
+struct MaskData* create_mask_data(ImageMaskData_t label)
{
struct MaskData *data = (struct MaskData*)malloc(sizeof(struct MaskData));
data->label = label;
@@ -90,7 +90,7 @@ 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)
{
struct MaskData* data = create_mask_data(label);
struct Result result = insert_mask(node, data);
@@ -112,7 +112,7 @@ 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)
{
if (root == NULL) {
return FALSE;
@@ -131,7 +131,7 @@ bool_t increase_label_area(struct AVLNode* root, uint16_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)
{
if (root == NULL) {
return FALSE;
@@ -151,7 +151,7 @@ bool_t increase_label_perimeter(struct AVLNode* root, uint16_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)
{
struct AVLNode* new_root = root;
bool_t success = increase_label_area(new_root, label);
@@ -164,7 +164,7 @@ struct AVLNode* increase_label_area_alloc(struct AVLNode* root, uint16_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)
{
struct AVLNode* new_root = root;
bool_t success = increase_label_perimeter(new_root, label);
@@ -175,34 +175,34 @@ struct AVLNode* increase_label_perimeter_alloc(struct AVLNode* root, uint16_t la
return new_root;
}
-// 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)
{
return *s1 < *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)
{
if (root != NULL) {
- print_in_order_uint16_t(root->left);
- printf("%d ", *((uint16_t*)root->data));
- print_in_order_uint16_t(root->right);
+ print_in_order_image_mask_data_t(root->left);
+ printf("%d ", *((ImageMaskData_t*)root->data));
+ print_in_order_image_mask_data_t(root->right);
}
}
-// 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)
{
if (root == NULL) {
return FALSE;
}
- if (*((uint16_t*)root->data) == value) {
+ if (*((ImageMaskData_t*)root->data) == value) {
return TRUE;
- } else if (value < *((uint16_t*)root->data)) {
- return in_uint16_t_tree(root->left, value);
+ } else if (value < *((ImageMaskData_t*)root->data)) {
+ return in_image_mask_data_t_tree(root->left, value);
} else {
- return in_uint16_t_tree(root->right, value);
+ return in_image_mask_data_t_tree(root->right, value);
}
}
@@ -216,7 +216,7 @@ struct AVLNode* get_small_labels(struct AVLNode* removal_tree, struct AVLNode* l
struct MaskData* node_data = (struct MaskData*)label_tree->data;
if ((node_data->area < min_area) || (node_data->perimeter < min_perimeter)) {
// Insert
- struct Result result = avl_insert(return_tree, &node_data->label, (bool_t (*)(void*,void*))compare_uint16_t);
+ struct Result result = avl_insert(return_tree, &node_data->label, (bool_t (*)(void*,void*))compare_image_mask_data_t);
if (result.success) {
return_tree = result.data;
}
@@ -227,7 +227,7 @@ struct AVLNode* get_small_labels(struct AVLNode* removal_tree, struct AVLNode* l
}
// 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)
{
struct AVLNode* root = NULL;
for (size_t y = 0; y < height; y++) {
@@ -245,7 +245,7 @@ struct AVLNode* get_mask_data(uint16_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)
{
struct AVLNode* root = get_mask_data(masks, width, height);
struct AVLNode* small_label_tree = NULL;
@@ -253,7 +253,7 @@ void filter_small_masks(uint16_t* masks, uint32_t width, uint32_t height, size_t
for (size_t y = 0; y < height; y++) {
for (size_t x = 0; x < width; x++) {
size_t coord = x + y*width;
- if (in_uint16_t_tree(small_label_tree, masks[coord])) {
+ if (in_image_mask_data_t_tree(small_label_tree, masks[coord])) {
masks[coord] = 0;
}
}
diff --git a/lib/seg/util.c b/lib/seg/util.c
index 677e8f5..4290d46 100644
--- a/lib/seg/util.c
+++ b/lib/seg/util.c
@@ -1,4 +1,4 @@
- #include <lib/seg/util.h>
+#include <lib/seg/util.h>
#include <lib/algo/flood_fill.h>
#include <lib/png.h>
#include <tiffio.h>
@@ -21,11 +21,11 @@ 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)
{
size_t starting_coord = xy_to_coord(x, y, width, height);
size_t proposed_position;
- uint16_t current_value = mask[starting_coord];
+ ImageMaskData_t current_value = mask[starting_coord];
// Left neighbor
if (x != 0) {
@@ -57,9 +57,9 @@ bool_t is_on_mask_boundary(uint16_t* mask, uint32_t width, uint32_t height, size
}
// Dilate masks by one 4-connected pixel
-uint16_t* _dilate(uint16_t* mask, uint32_t width, uint32_t height)
+ImageMaskData_t* _dilate(ImageMaskData_t* mask, uint32_t width, uint32_t height)
{
- uint16_t *new_mask = (uint16_t*)calloc(width*height,sizeof(uint16_t));
+ ImageMaskData_t *new_mask = (ImageMaskData_t*)calloc(width*height,sizeof(ImageMaskData_t));
for (size_t y = 0; y < height; y++) {
for (size_t x = 0; x < width; x++) {
size_t current_position = xy_to_coord(x, y, width, height);
@@ -102,9 +102,9 @@ uint16_t* _dilate(uint16_t* mask, uint32_t width, uint32_t height)
}
// 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)
{
- uint16_t *new_mask = _dilate(*mask, width, height);
+ ImageMaskData_t *new_mask = _dilate(*mask, width, height);
if (new_mask != NULL) {
free(*mask);
*mask = new_mask;
@@ -112,10 +112,10 @@ void dilate(uint16_t** mask, uint32_t width, uint32_t height)
}
// Erode masks by one 4-connected pixel
-uint16_t* _erode(uint16_t* mask, uint32_t width, uint32_t height)
+ImageMaskData_t* _erode(ImageMaskData_t* mask, uint32_t width, uint32_t height)
{
- uint16_t *new_mask = (uint16_t*)calloc(width*height,sizeof(uint16_t));
- memcpy(new_mask, mask, width*height*sizeof(uint16_t));
+ ImageMaskData_t *new_mask = (ImageMaskData_t*)calloc(width*height,sizeof(ImageMaskData_t));
+ memcpy(new_mask, mask, width*height*sizeof(ImageMaskData_t));
for (size_t y = 0; y < height; y++) {
for (size_t x = 0; x < width; x++) {
size_t current_position = xy_to_coord(x, y, width, height);
@@ -154,9 +154,9 @@ uint16_t* _erode(uint16_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)
{
- uint16_t *new_mask = _erode(*mask, width, height);
+ ImageMaskData_t *new_mask = _erode(*mask, width, height);
if (new_mask != NULL) {
free(*mask);
*mask = new_mask;
@@ -164,10 +164,10 @@ void erode(uint16_t** mask, uint32_t width, uint32_t height)
}
// Close up masks by N-pixels
-uint16_t* _closeup(uint16_t* mask, uint32_t width, uint32_t height, size_t num_pixels)
+ImageMaskData_t* _closeup(ImageMaskData_t* mask, uint32_t width, uint32_t height, size_t num_pixels)
{
- uint16_t *new_mask = (uint16_t*)calloc(width*height,sizeof(uint16_t));
- memcpy(new_mask, mask, width*height*sizeof(uint16_t));
+ ImageMaskData_t *new_mask = (ImageMaskData_t*)calloc(width*height,sizeof(ImageMaskData_t));
+ memcpy(new_mask, mask, width*height*sizeof(ImageMaskData_t));
for (size_t count = 0; count < num_pixels; count++) {
dilate(&new_mask, width, height);
}
@@ -190,9 +190,9 @@ uint16_t* _closeup(uint16_t* mask, uint32_t width, uint32_t height, size_t num_p
// Close up masks by N-pixels
// Update pointer
-void closeup(uint16_t** mask, uint32_t width, uint32_t height, size_t num_pixels)
+void closeup(ImageMaskData_t** mask, uint32_t width, uint32_t height, size_t num_pixels)
{
- uint16_t *new_mask = _closeup(*mask, width, height, num_pixels);
+ ImageMaskData_t *new_mask = _closeup(*mask, width, height, num_pixels);
if (new_mask != NULL) {
free(*mask);
*mask = new_mask;
@@ -202,10 +202,10 @@ void closeup(uint16_t** mask, uint32_t width, uint32_t height, size_t num_pixels
// 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)
{
if (destination == NULL) {
- destination = (uint16_t*)calloc(width*height, sizeof(uint16_t));
+ destination = (ImageMaskData_t*)calloc(width*height, sizeof(ImageMaskData_t));
}
for (size_t y = 0; y < height; y++) {
for (size_t x = 0; x < width; x++) {
@@ -221,7 +221,7 @@ uint16_t* combine_masks(uint16_t *destination, uint16_t *extra_labels, uint32_t
// 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)
{
TIFFSetWarningHandler(TiffDummyHandler);
//-TIFF-IMAGE-OPEN-------------------------------
@@ -245,13 +245,13 @@ uint16_t* tif_to_labels(char* tif_file_name, uint32_t *width, uint32_t *height,
}
//-TIFF-LOAD-DATA--------------------------------
- void* buffer = malloc(STRIP_LENGTH*sizeof(uint8_t));
+ void* buffer = malloc(STRIP_LENGTH*sizeof(ImageData_t));
if (buffer == NULL) {
fprintf(stderr, "Memory allocation error\n");
TIFFClose(tif);
return NULL;
}
- uint8_t* image_data = calloc((*width)*(*height)*channels,sizeof(uint8_t));
+ ImageData_t* image_data = calloc((*width)*(*height)*channels,sizeof(ImageData_t));
if (image_data == NULL) {
fprintf(stderr, "Memory allocation error\n");
free(buffer);
@@ -262,15 +262,15 @@ uint16_t* tif_to_labels(char* tif_file_name, uint32_t *width, uint32_t *height,
tmsize_t strip_size = TIFFReadRawStrip(tif, y, buffer, STRIP_LENGTH);
assert(strip_size == STRIP_LENGTH);
for (size_t x = 0; x < STRIP_LENGTH; x++) {
- image_data[x + y*STRIP_LENGTH] = ((uint8_t*)buffer)[x];
+ image_data[x + y*STRIP_LENGTH] = ((ImageData_t*)buffer)[x];
}
}
free(buffer);
//-FLOOD-FILL-SEGMENTATION-----------------------
//-CONTIGUOUS-REGION-FINDING---------------------
- uint16_t *labels = NULL;
- labels = (uint16_t*)calloc((*width)*(*height),sizeof(uint16_t));
+ ImageMaskData_t *labels = NULL;
+ labels = (ImageMaskData_t*)calloc((*width)*(*height),sizeof(ImageMaskData_t));
if (labels == NULL) {
fprintf(stderr, "Memory allocation error\n");
free(image_data);
@@ -293,7 +293,7 @@ uint16_t* tif_to_labels(char* tif_file_name, uint32_t *width, uint32_t *height,
}
// 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)
{
struct pixel_t* out_buffer = (struct pixel_t*)calloc(width*height, sizeof(struct pixel_t));
if (out_buffer == NULL) {
@@ -307,9 +307,9 @@ struct bitmap_t* uint16_to_bitmap(uint16_t* buffer, uint32_t width, uint32_t hei
for (size_t y = 0; y < height; y++) {
for (size_t x = 0; x < width; x++) {
size_t coord = x + y*width;
- uint8_t red = (buffer[coord] & 0xF00) >> 4*2;
- uint8_t green = (buffer[coord] & 0x0F0) >> 4*1;
- uint8_t blue = (buffer[coord] & 0x00F) >> 4*0;
+ ImageData_t red = (buffer[coord] & 0xF00) >> 4*2;
+ ImageData_t green = (buffer[coord] & 0x0F0) >> 4*1;
+ ImageData_t blue = (buffer[coord] & 0x00F) >> 4*0;
out_buffer[coord].red = red | (red << 4);
out_buffer[coord].green = green | (green << 4);
out_buffer[coord].blue = blue | (blue << 4);
@@ -322,18 +322,18 @@ struct bitmap_t* uint16_to_bitmap(uint16_t* buffer, uint32_t width, uint32_t hei
}
// Reduce a mask to the contiguous regions
-uint16_t* _reduce_contiguous_regions(uint16_t* masks, uint32_t width, uint32_t height, uint16_t* total_labels)
+ImageMaskData_t* _reduce_contiguous_regions(ImageMaskData_t* masks, uint32_t width, uint32_t height, ImageMaskData_t* total_labels)
{
- uint16_t starting_label = 1;
- uint16_t* new_masks = (uint16_t*)calloc(width*height, sizeof(uint16_t));
+ ImageMaskData_t starting_label = 1;
+ ImageMaskData_t* new_masks = (ImageMaskData_t*)calloc(width*height, sizeof(ImageMaskData_t));
if (new_masks == NULL) {
return NULL;
}
for (size_t y = 0; y < height; y++) {
for (size_t x = 0; x < width; x++) {
size_t coord = x + y*width;
- uint8_t channels = 2; // uint16_t = 2*uint8_t
- if (flood((uint8_t*)masks, new_masks, width, height, channels, x, y, &(((uint8_t*)masks)[coord*channels]), starting_label)) {
+ ImageData_t channels = 2; // ImageMaskData_t = 2*uint8_t
+ if (flood((ImageData_t*)masks, new_masks, width, height, channels, x, y, &(((ImageData_t*)masks)[coord*channels]), starting_label)) {
starting_label++;
}
}
@@ -347,12 +347,12 @@ uint16_t* _reduce_contiguous_regions(uint16_t* masks, uint32_t width, uint32_t h
// 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)
{
if (masks_p == NULL) {
return;
}
- uint16_t* new_masks = _reduce_contiguous_regions(*masks_p, width, height, total_labels);
+ ImageMaskData_t* new_masks = _reduce_contiguous_regions(*masks_p, width, height, total_labels);
if (new_masks != NULL) {
free(*masks_p);
*masks_p = new_masks;
diff --git a/src/prog.c b/src/prog.c
index f23da54..57bb93d 100644
--- a/src/prog.c
+++ b/src/prog.c
@@ -86,8 +86,8 @@ int main(int argc, char** argv)
//-----------------------------------------------
char** file_list = NULL;
uint32_t width, height;
- uint16_t starting_label = 1;
- uint16_t *masks = NULL;
+ ImageMaskData_t starting_label = 1;
+ ImageMaskData_t *masks = NULL;
// Expect a directory to be passed as the first argument
if (directory != NULL) {
// Ensure the directory exists
@@ -117,7 +117,7 @@ int main(int argc, char** argv)
//-----------------------------------------------
//-PROCESS-TIFF-TO-LABELS------------------------
//-----------------------------------------------
- uint16_t *file_labels = tif_to_labels(fpath, &width, &height, &starting_label);
+ ImageMaskData_t *file_labels = tif_to_labels(fpath, &width, &height, &starting_label);
if (file_labels == NULL) {
free(fpath);
free(file_list[index]);
@@ -198,12 +198,12 @@ int main(int argc, char** argv)
//-SAVE-MASK-AS-BINARY-AND-PNG-------------------
//-----------------------------------------------
if (masks != NULL) {
- struct bitmap_t* bitmap = uint16_to_bitmap(masks, width, height);
+ struct bitmap_t* bitmap = image_mask_data_to_bitmap(masks, width, height);
if (bitmap != NULL) {
save_png(bitmap, png_file);
free(bitmap);
}
- write_array(bin_file, masks, width*height*sizeof(uint16_t));
+ write_array(bin_file, masks, width*height*sizeof(ImageMaskData_t));
free(masks);
}
TIME(ts_g_end);
diff --git a/src/visual.c b/src/visual.c
index ac6f63d..b41267b 100644
--- a/src/visual.c
+++ b/src/visual.c
@@ -87,8 +87,8 @@ int main(int argc, char** argv)
//-----------------------------------------------
char** file_list = NULL;
uint32_t width, height;
- uint16_t starting_label = 1;
- uint16_t *masks = NULL;
+ ImageMaskData_t starting_label = 1;
+ ImageMaskData_t *masks = NULL;
// Expect a directory to be passed as the first argument
if (directory != NULL) {
// Ensure the directory exists
@@ -118,7 +118,7 @@ int main(int argc, char** argv)
//-----------------------------------------------
//-PROCESS-TIFF-TO-LABELS------------------------
//-----------------------------------------------
- uint16_t *file_labels = tif_to_labels(fpath, &width, &height, &starting_label);
+ ImageMaskData_t *file_labels = tif_to_labels(fpath, &width, &height, &starting_label);
if (file_labels == NULL) {
free(fpath);
free(file_list[index]);
@@ -280,12 +280,12 @@ int main(int argc, char** argv)
masks[x + y*width] >>= 4;
}
}
- struct bitmap_t* bitmap = uint16_to_bitmap(masks, width, height);
+ struct bitmap_t* bitmap = image_mask_data_to_bitmap(masks, width, height);
if (bitmap != NULL) {
save_png(bitmap, png_file);
free(bitmap);
}
- write_array(bin_file, masks, width*height*sizeof(uint16_t));
+ write_array(bin_file, masks, width*height*sizeof(ImageMaskData_t));
free(masks);
}
CloseWindow();
@@ -294,12 +294,12 @@ int main(int argc, char** argv)
//-SAVE-MASK-AS-BINARY-AND-PNG-------------------
//-----------------------------------------------
if (masks != NULL) {
- struct bitmap_t* bitmap = uint16_to_bitmap(masks, width, height);
+ struct bitmap_t* bitmap = image_mask_data_to_bitmap(masks, width, height);
if (bitmap != NULL) {
save_png(bitmap, png_file);
free(bitmap);
}
- write_array(bin_file, masks, width*height*sizeof(uint16_t));
+ write_array(bin_file, masks, width*height*sizeof(ImageMaskData_t));
free(masks);
}
#endif
diff --git a/test/lib/color.c b/test/lib/color.c
index 69ce97b..e791d95 100644
--- a/test/lib/color.c
+++ b/test/lib/color.c
@@ -1,12 +1,12 @@
#include <test/lib/color.h>
-const uint8_t test_rgba[4] = {0,0,0,0};
-const uint8_t test_Rgba[4] = {1,0,0,0};
-const uint8_t test_rGba[4] = {0,1,0,0};
-const uint8_t test_rgBa[4] = {0,0,1,0};
-const uint8_t test_rgbA[4] = {0,0,0,1};
+const ImageData_t test_rgba[4] = {0,0,0,0};
+const ImageData_t test_Rgba[4] = {1,0,0,0};
+const ImageData_t test_rGba[4] = {0,1,0,0};
+const ImageData_t test_rgBa[4] = {0,0,1,0};
+const ImageData_t test_rgbA[4] = {0,0,0,1};
-bool_t test_color_zero(const uint8_t* color1, size_t channels, bool_t result)
+bool_t test_color_zero(const ImageData_t* color1, size_t channels, bool_t result)
{
bool_t fcall_result = color_zero(color1, channels);
if (fcall_result == result) {
@@ -15,7 +15,7 @@ bool_t test_color_zero(const uint8_t* color1, size_t channels, bool_t result)
return FALSE;
}
-void _TEST_color_zero(bool_t* result, uint16_t* test_count, uint16_t* test_pass)
+void _TEST_color_zero(bool_t* result, TestCount_t* test_count, TestCount_t* test_pass)
{
bool_t sub_result;
// Test 1: 1 channel zero color
@@ -73,7 +73,7 @@ void _TEST_color_zero(bool_t* result, uint16_t* test_count, uint16_t* test_pass)
TEST_RESULT("COLOR_ZERO",sub_result, *test_count, (*test_pass));
}
-bool_t test_color_equal(const uint8_t* color1, const uint8_t* color2, 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)
{
bool_t fcall_result = color_equal(color1, color2, channels);
if (fcall_result == result) {
@@ -82,7 +82,7 @@ bool_t test_color_equal(const uint8_t* color1, const uint8_t* color2, size_t cha
return FALSE;
}
-void _TEST_color_equal(bool_t* result, uint16_t* test_count, uint16_t* test_pass)
+void _TEST_color_equal(bool_t* result, TestCount_t* test_count, TestCount_t* test_pass)
{
bool_t sub_result;
// Test 1: 1 channel equal (zero)
@@ -161,8 +161,8 @@ void _TEST_color_equal(bool_t* result, uint16_t* test_count, uint16_t* test_pass
// Meta test function
bool_t TEST_lib_color()
{
- uint16_t test_count = 0;
- uint16_t test_pass = 0;
+ TestCount_t test_count = 0;
+ TestCount_t test_pass = 0;
bool_t result = TRUE;
// Testing color_zero
diff --git a/test/lib/dir.c b/test/lib/dir.c
index 66ce672..21b4284 100644
--- a/test/lib/dir.c
+++ b/test/lib/dir.c
@@ -12,7 +12,7 @@ bool_t test_is_directory(char* dirname, bool_t result)
return FALSE;
}
-void _TEST_is_directory(bool_t* result, uint16_t* test_count, uint16_t* test_pass)
+void _TEST_is_directory(bool_t* result, TestCount_t* test_count, TestCount_t* test_pass)
{
bool_t sub_result;
// Test 1: sample_data/ (TRUE) [On clean git folder]
@@ -37,7 +37,7 @@ bool_t test_full_path(char* dirname, char* file, char* result)
return FALSE;
}
-void _TEST_full_path(bool_t* result, uint16_t* test_count, uint16_t* test_pass)
+void _TEST_full_path(bool_t* result, TestCount_t* test_count, TestCount_t* test_pass)
{
bool_t sub_result;
// Test 1: sample_data/small + small.tif = sample_data/small/small.tif
@@ -57,7 +57,7 @@ bool_t test_is_tif_ext(char* file_name, bool_t result)
return FALSE == result;
}
-void _TEST_is_tif_ext(bool_t* result, uint16_t* test_count, uint16_t* test_pass)
+void _TEST_is_tif_ext(bool_t* result, TestCount_t* test_count, TestCount_t* test_pass)
{
bool_t sub_result;
// Test 1: sample_data/small/small.tif (TRUE)
@@ -78,8 +78,8 @@ void _TEST_is_tif_ext(bool_t* result, uint16_t* test_count, uint16_t* test_pass
bool_t TEST_lib_dir()
{
- uint16_t test_count = 0;
- uint16_t test_pass = 0;
+ TestCount_t test_count = 0;
+ TestCount_t test_pass = 0;
bool_t result = TRUE;
// Testing directory existence
diff --git a/test/lib/time.c b/test/lib/time.c
index 5c29bbc..67c8f33 100644
--- a/test/lib/time.c
+++ b/test/lib/time.c
@@ -14,7 +14,7 @@ bool_t test_diff_time(const struct timespec *time1, const struct timespec *time0
return FALSE;
}
-void _TEST_diff_time(bool_t* result, uint16_t* test_count, uint16_t* test_pass)
+void _TEST_diff_time(bool_t* result, TestCount_t* test_count, TestCount_t* test_pass)
{
bool_t sub_result;
// Test 1: 0-0=0
@@ -50,8 +50,8 @@ void _TEST_diff_time(bool_t* result, uint16_t* test_count, uint16_t* test_pass)
bool_t TEST_lib_time()
{
- uint16_t test_count = 0;
- uint16_t test_pass = 0;
+ TestCount_t test_count = 0;
+ TestCount_t test_pass = 0;
bool_t result = TRUE;
// Testing directory existence