aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/lib/algo/avl_tree.h26
-rw-r--r--include/lib/algo/flood_fill.h7
-rw-r--r--include/lib/color.h11
-rw-r--r--include/lib/data/image_types.h14
-rw-r--r--include/lib/dir.h10
-rw-r--r--include/lib/file.h2
-rw-r--r--include/lib/monad.h2
-rw-r--r--include/lib/png.h4
-rw-r--r--include/lib/seg/mask_data.h33
-rw-r--r--include/lib/seg/util.h20
-rw-r--r--include/lib/time.h4
-rw-r--r--include/test/__meta__.h18
-rw-r--r--include/test/lib/color.h9
-rw-r--r--include/test/lib/dir.h9
-rw-r--r--include/test/lib/time.h6
-rw-r--r--lib/algo/avl_tree.c77
-rw-r--r--lib/algo/flood_fill.c23
-rw-r--r--lib/color.c11
-rw-r--r--lib/data/image_types.c29
-rw-r--r--lib/dir.c47
-rw-r--r--lib/file.c3
-rw-r--r--lib/lib.c2
-rw-r--r--lib/png.c27
-rw-r--r--lib/seg/mask_data.c122
-rw-r--r--lib/seg/util.c188
-rw-r--r--lib/time.c8
-rw-r--r--test/lib/color.c73
-rw-r--r--test/lib/dir.c47
-rw-r--r--test/lib/time.c31
-rw-r--r--test/test.c10
30 files changed, 429 insertions, 444 deletions
diff --git a/include/lib/algo/avl_tree.h b/include/lib/algo/avl_tree.h
index 0221952..18cf34b 100644
--- a/include/lib/algo/avl_tree.h
+++ b/include/lib/algo/avl_tree.h
@@ -9,44 +9,44 @@
#define AvlHeight_t uint8_t
-typedef bool_t (*AvlComparator)(void*, void*);
+typedef bool_t (*AvlComparator)(void *, void *);
typedef struct AVLNode {
- void* data;
+ void *data;
AvlComparator compare;
- struct AVLNode* left;
- struct AVLNode* right;
+ struct AVLNode *left;
+ struct AVLNode *right;
AvlHeight_t height;
} AVLNode;
// Get the height of an AVL node
-AvlHeight_t get_height(AVLNode* node);
+AvlHeight_t get_height(AVLNode *node);
// Get the Maximum Height between two
AvlHeight_t max_height(AvlHeight_t a, AvlHeight_t b);
// Get the balance factor of a node
-ssize_t get_balance_factor(AVLNode* node);
+ssize_t get_balance_factor(AVLNode *node);
// Rotate an AVL node right
-AVLNode* right_rotate(AVLNode* parent);
+AVLNode *right_rotate(AVLNode *parent);
// Rotate an AVL node left
-AVLNode* left_rotate(AVLNode* parent);
+AVLNode *left_rotate(AVLNode *parent);
// Create AVL node
-AVLNode* create_avl_node(void* data, AvlComparator compare);
+AVLNode *create_avl_node(void *data, AvlComparator compare);
// Insert data into AVL tree
-Result avl_insert(AVLNode* node, void* data, AvlComparator compare);
+Result avl_insert(AVLNode *node, void *data, AvlComparator compare);
// In-order traversal print pointer
-void print_in_order(AVLNode* root);
+void print_in_order(AVLNode *root);
// Free avl tree nodes starting at root
-void free_avl_tree(AVLNode* root);
+void free_avl_tree(AVLNode *root);
// Free avl tree and their data starting at root
-void free_avl_tree_nodes(AVLNode* root);
+void free_avl_tree_nodes(AVLNode *root);
#endif
diff --git a/include/lib/algo/flood_fill.h b/include/lib/algo/flood_fill.h
index f446e3b..3bacaf9 100644
--- a/include/lib/algo/flood_fill.h
+++ b/include/lib/algo/flood_fill.h
@@ -12,9 +12,12 @@
// 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);
#endif
diff --git a/include/lib/color.h b/include/lib/color.h
index ceaecbd..f462a05 100644
--- a/include/lib/color.h
+++ b/include/lib/color.h
@@ -1,20 +1,21 @@
#ifndef INC_LIB_COLOR_H
#define INC_LIB_COLOR_H
-#include <stdint.h>
-#include <stddef.h>
#include <lib/bool.h>
#include <lib/data/image_types.h>
+#include <stddef.h>
+#include <stdint.h>
// Color Equal to Background
// Background: zeros in RGB, alpha can be whatever
-bool_t color_zero(const ImageData_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 ImageData_t* color1, const ImageData_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(ImageData_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 8df5feb..af533ce 100644
--- a/include/lib/data/image_types.h
+++ b/include/lib/data/image_types.h
@@ -1,13 +1,13 @@
#ifndef INC_LIB_DATA_IMAGE_TYPES_H
#define INC_LIB_DATA_IMAGE_TYPES_H
-#include <stdint.h>
#include <stddef.h>
+#include <stdint.h>
#define ImageData_t uint8_t
-#define Image_t ImageData_t***
+#define Image_t ImageData_t ***
#define MaskData_t uint16_t
-#define Mask_t MaskData_t**
+#define Mask_t MaskData_t **
typedef struct Image {
size_t width;
@@ -22,10 +22,10 @@ typedef struct Mask {
Mask_t image;
} Mask;
-Image* create_image(size_t width, size_t height, size_t depth);
-Mask* create_image_mask(size_t width, size_t height);
+Image *create_image(size_t width, size_t height, size_t depth);
+Mask *create_image_mask(size_t width, size_t height);
-void free_image(Image* image);
-void free_image_mask(Mask* image_mask);
+void free_image(Image *image);
+void free_image_mask(Mask *image_mask);
#endif
diff --git a/include/lib/dir.h b/include/lib/dir.h
index 0ec9cac..81f37f3 100644
--- a/include/lib/dir.h
+++ b/include/lib/dir.h
@@ -1,19 +1,19 @@
#ifndef INC_LIB_DIR_H
#define INC_LIB_DIR_H
-#include <lib/lib.h>
#include <lib/bool.h>
+#include <lib/lib.h>
// Is directory
-bool_t is_directory(char* dirname);
+bool_t is_directory(char *dirname);
// List directory
-char** list_directory(char* dirname);
+char **list_directory(char *dirname);
// Get full path
-char* full_path(char* dir, char* file);
+char *full_path(char *dir, char *file);
// Determines if file name has tif file extension
-bool_t is_tif_ext(char* file_name);
+bool_t is_tif_ext(char *file_name);
#endif
diff --git a/include/lib/file.h b/include/lib/file.h
index 9a231cc..395c1f8 100644
--- a/include/lib/file.h
+++ b/include/lib/file.h
@@ -5,6 +5,6 @@
#include <stddef.h>
// Write array to a file
-bool_t write_array(char* output_file_name, void* array, size_t size);
+bool_t write_array(char *output_file_name, void *array, size_t size);
#endif
diff --git a/include/lib/monad.h b/include/lib/monad.h
index af5eb3a..21cbe61 100644
--- a/include/lib/monad.h
+++ b/include/lib/monad.h
@@ -4,7 +4,7 @@
#include <lib/bool.h>
typedef struct Result {
- void* data;
+ void *data;
bool_t success;
} Result;
diff --git a/include/lib/png.h b/include/lib/png.h
index c21fede..ca1179b 100644
--- a/include/lib/png.h
+++ b/include/lib/png.h
@@ -15,12 +15,12 @@ typedef struct pixel_t {
} Pixel;
typedef struct bitmap_t {
- Pixel* image_buffer;
+ Pixel *image_buffer;
size_t width;
size_t height;
} Bitmap;
// Save bitmap to file
-void save_png(Bitmap* bitmap, char* fname);
+void save_png(Bitmap *bitmap, char *fname);
#endif
diff --git a/include/lib/seg/mask_data.h b/include/lib/seg/mask_data.h
index 70bacfa..02276f0 100644
--- a/include/lib/seg/mask_data.h
+++ b/include/lib/seg/mask_data.h
@@ -12,55 +12,56 @@ typedef struct MaskData {
} MaskData;
// Allocate Mask Data for Label
-MaskData* create_mask_data(MaskData_t label);
+MaskData *create_mask_data(MaskData_t label);
// Compare mask data labels
-bool_t compare_labels(MaskData* left, MaskData* right);
+bool_t compare_labels(MaskData *left, MaskData *right);
// Create AVL Mask node
-AVLNode* create_avl_mask_node(MaskData* data);
+AVLNode *create_avl_mask_node(MaskData *data);
// Insert MaskData into the AVL Tree
-Result insert_mask(AVLNode* node, MaskData* data);
+Result insert_mask(AVLNode *node, MaskData *data);
// Allocate a label's Mask data in a tree
// If it already exists, skip the allocation
-AVLNode* insert_mask_alloc(AVLNode* node, MaskData_t label);
+AVLNode *insert_mask_alloc(AVLNode *node, MaskData_t label);
// Print AVL Node Mask Data Label
-void print_label(AVLNode* root);
+void print_label(AVLNode *root);
// Increase the label's area
-bool_t increase_label_area(AVLNode* root, MaskData_t label);
+bool_t increase_label_area(AVLNode *root, MaskData_t label);
// Increase the label's perimeter
-bool_t increase_label_perimeter(AVLNode* root, MaskData_t label);
+bool_t increase_label_perimeter(AVLNode *root, MaskData_t label);
// Increase the label's area
// Create an AVL node if it doesn't exist
-AVLNode* increase_label_area_alloc(AVLNode* root, MaskData_t label);
+AVLNode *increase_label_area_alloc(AVLNode *root, MaskData_t label);
// Increase the label's perimeter
// Create an AVL node if it doesn't exist
-AVLNode* increase_label_perimeter_alloc(AVLNode* root, MaskData_t label);
+AVLNode *increase_label_perimeter_alloc(AVLNode *root, MaskData_t label);
// Comparison of MaskData_ts
-bool_t compare_image_mask_data_t(MaskData_t* s1, MaskData_t* s2);
+bool_t compare_image_mask_data_t(MaskData_t *s1, MaskData_t *s2);
// In-order traversal print pointer
-void print_in_order_image_mask_data_t(AVLNode* root);
+void print_in_order_image_mask_data_t(AVLNode *root);
// Check if MaskData_t in AVLTree with MaskData_t* data
-bool_t in_image_mask_data_t_tree(AVLNode* root, MaskData_t value);
+bool_t in_image_mask_data_t_tree(AVLNode *root, MaskData_t value);
// Filter out small masks
// Assumption: Contiguous labeling
-AVLNode* get_small_labels(AVLNode* removal_tree, AVLNode* label_tree, size_t min_area, size_t min_perimeter);
+AVLNode *get_small_labels(AVLNode *removal_tree, AVLNode *label_tree,
+ size_t min_area, size_t min_perimeter);
// Get mask label data
-AVLNode* get_mask_data(Mask* mask);
+AVLNode *get_mask_data(Mask *mask);
// Filter out small masks in mask
-void filter_small_masks(Mask* mask, size_t min_area, size_t min_perimeter);
+void filter_small_masks(Mask *mask, size_t min_area, size_t min_perimeter);
#endif
diff --git a/include/lib/seg/util.h b/include/lib/seg/util.h
index 9f66670..d726be8 100644
--- a/include/lib/seg/util.h
+++ b/include/lib/seg/util.h
@@ -2,40 +2,40 @@
#define INC_LIB_SEG_UTIL_H
#include <lib/bool.h>
-#include <lib/png.h>
#include <lib/data/image_types.h>
-#include <stdint.h>
+#include <lib/png.h>
#include <stddef.h>
+#include <stdint.h>
// Determine if coordinate is on a mask boundary
// Assumes mask is (WxH)
-bool_t is_on_mask_boundary(Mask* mask, size_t x, size_t y);
+bool_t is_on_mask_boundary(Mask *mask, size_t x, size_t y);
// Dilate masks by one 4-connected pixel
-void dilate(Mask* mask);
+void dilate(Mask *mask);
// Erode masks by one 4-connected pixel
-void erode(Mask* mask);
+void erode(Mask *mask);
// Close up masks by N-pixels
-void closeup(Mask* mask, size_t count);
+void closeup(Mask *mask, 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
-Mask* combine_masks(Mask *destination, Mask *extra_labels);
+Mask *combine_masks(Mask *destination, Mask *extra_labels);
// 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
-Mask* tif_to_labels(char* tif_file_name, MaskData_t *starting_label_p);
+Mask *tif_to_labels(char *tif_file_name, MaskData_t *starting_label_p);
// Convert mask to bitmap
-Bitmap* image_mask_data_to_bitmap(const Mask* mask);
+Bitmap *image_mask_data_to_bitmap(const Mask *mask);
// Reduce a mask to the contiguous regions
// Automatically update pointer to contiguous mask
// Freeing previous mask
-void reduce_contiguous_regions(Mask* mask, MaskData_t* total_labels);
+void reduce_contiguous_regions(Mask *mask, MaskData_t *total_labels);
#endif
diff --git a/include/lib/time.h b/include/lib/time.h
index 1adf428..809a8a0 100644
--- a/include/lib/time.h
+++ b/include/lib/time.h
@@ -3,7 +3,9 @@
#include <time.h>
-#define TIME(var) struct timespec var;get_time(&var)
+#define TIME(var) \
+ struct timespec var; \
+ get_time(&var)
// Difference in Time
// Compute the difference between timespec structs
diff --git a/include/test/__meta__.h b/include/test/__meta__.h
index 17e0b99..f0c10b4 100644
--- a/include/test/__meta__.h
+++ b/include/test/__meta__.h
@@ -2,21 +2,29 @@
#define INC_TEST___META___H
#include <lib/bool.h>
-#include <stdio.h>
#include <stddef.h>
+#include <stdio.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)
+#define _TEST_PASS(s, sub, n) \
+ fprintf(stderr, "(%4X) \x1b[92mPASS\x1b[0m %s/%s\n", ++n, s, sub)
#else
-#define _TEST_PASS(s,sub,n) ++n
+#define _TEST_PASS(s, sub, n) ++n
#endif
-#define _TEST_FAIL(s,sub,n) fprintf(stderr, "(%4X) \x1b[91mFAIL\x1b[0m %s/%s\n", ++n, s, sub)
+#define _TEST_FAIL(s, sub, n) \
+ fprintf(stderr, "(%4X) \x1b[91mFAIL\x1b[0m %s/%s\n", ++n, s, sub)
#ifndef _TEST_RESULT
-#define _TEST_RESULT(main_string,subtest_string,result,n,n_success) if (!result) {_TEST_FAIL(main_string,subtest_string, n);} else {_TEST_PASS(main_string,subtest_string,n);n_success++;}
+#define _TEST_RESULT(main_string, subtest_string, result, n, n_success) \
+ if (!result) { \
+ _TEST_FAIL(main_string, subtest_string, n); \
+ } else { \
+ _TEST_PASS(main_string, subtest_string, n); \
+ n_success++; \
+ }
#endif
#endif
diff --git a/include/test/lib/color.h b/include/test/lib/color.h
index 2e9b863..e1598cb 100644
--- a/include/test/lib/color.h
+++ b/include/test/lib/color.h
@@ -3,14 +3,17 @@
#include <test/__meta__.h>
#ifndef TEST_RESULT
-#define TEST_RESULT(subtest,result,n,n_success) _TEST_RESULT("LIB/COLOR",subtest,result,n,n_success)
+#define TEST_RESULT(subtest, result, n, n_success) \
+ _TEST_RESULT("LIB/COLOR", subtest, result, n, n_success)
#endif
#include <lib/color.h>
#include <lib/data/image_types.h>
-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);
+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/include/test/lib/dir.h b/include/test/lib/dir.h
index 64482df..6d46267 100644
--- a/include/test/lib/dir.h
+++ b/include/test/lib/dir.h
@@ -3,14 +3,15 @@
#include <test/__meta__.h>
#ifndef TEST_RESULT
-#define TEST_RESULT(subtest,result,n,n_success) _TEST_RESULT("LIB/DIR",subtest,result,n,n_success)
+#define TEST_RESULT(subtest, result, n, n_success) \
+ _TEST_RESULT("LIB/DIR", subtest, result, n, n_success)
#endif
#include <lib/dir.h>
-bool_t test_is_directory(char* dirname, bool_t result);
-bool_t test_full_path(char* dirname, char* file, char* result);
-bool_t test_is_tif_ext(char* file_name, bool_t result);
+bool_t test_is_directory(char *dirname, bool_t result);
+bool_t test_full_path(char *dirname, char *file, char *result);
+bool_t test_is_tif_ext(char *file_name, bool_t result);
// Meta test function
bool_t TEST_lib_dir();
diff --git a/include/test/lib/time.h b/include/test/lib/time.h
index cdf464e..d242c65 100644
--- a/include/test/lib/time.h
+++ b/include/test/lib/time.h
@@ -3,12 +3,14 @@
#include <test/__meta__.h>
#ifndef TEST_RESULT
-#define TEST_RESULT(subtest,result,n,n_success) _TEST_RESULT("LIB/TIME",subtest,result,n,n_success)
+#define TEST_RESULT(subtest, result, n, n_success) \
+ _TEST_RESULT("LIB/TIME", subtest, result, n, n_success)
#endif
#include <lib/time.h>
-bool_t test_diff_time(const struct timespec *time1, const struct timespec *time0, double result);
+bool_t test_diff_time(const struct timespec *time1,
+ const struct timespec *time0, double result);
// Meta test function
bool_t TEST_lib_time();
diff --git a/lib/algo/avl_tree.c b/lib/algo/avl_tree.c
index 7b86bab..cc06254 100644
--- a/lib/algo/avl_tree.c
+++ b/lib/algo/avl_tree.c
@@ -5,8 +5,7 @@
#include <stdio.h>
// Get the height of an AVL node
-AvlHeight_t get_height(AVLNode* node)
-{
+AvlHeight_t get_height(AVLNode *node) {
if (node == NULL) {
return 0;
}
@@ -14,14 +13,10 @@ AvlHeight_t get_height(AVLNode* node)
}
// Get the Maximum Height between two
-AvlHeight_t max_height(AvlHeight_t a, AvlHeight_t b)
-{
- return (a > b) ? a : b;
-}
+AvlHeight_t max_height(AvlHeight_t a, AvlHeight_t b) { return (a > b) ? a : b; }
// Get the balance factor of a node
-ssize_t get_balance_factor(AVLNode* node)
-{
+ssize_t get_balance_factor(AVLNode *node) {
if (node == NULL) {
return 0;
}
@@ -29,37 +24,38 @@ ssize_t get_balance_factor(AVLNode* node)
}
// Rotate an AVL node right
-AVLNode* right_rotate(AVLNode* parent)
-{
- AVLNode* child1 = parent->left;
- AVLNode* child2 = child1->right;
+AVLNode *right_rotate(AVLNode *parent) {
+ AVLNode *child1 = parent->left;
+ AVLNode *child2 = child1->right;
child1->right = parent;
parent->left = child2;
- parent->height = max_height(get_height(parent->left), get_height(parent->right)) + 1;
- child1->height = max_height(get_height(child1->left), get_height(child1->right)) + 1;
+ parent->height =
+ max_height(get_height(parent->left), get_height(parent->right)) + 1;
+ child1->height =
+ max_height(get_height(child1->left), get_height(child1->right)) + 1;
return child1;
}
// Rotate an AVL node left
-AVLNode* left_rotate(AVLNode* parent)
-{
- AVLNode* child1 = parent->right;
- AVLNode* child2 = child1->left;
+AVLNode *left_rotate(AVLNode *parent) {
+ AVLNode *child1 = parent->right;
+ AVLNode *child2 = child1->left;
child1->left = parent;
parent->right = child2;
- parent->height = max_height(get_height(parent->left), get_height(parent->right)) + 1;
- child1->height = max_height(get_height(child1->left), get_height(child1->right)) + 1;
+ parent->height =
+ max_height(get_height(parent->left), get_height(parent->right)) + 1;
+ child1->height =
+ max_height(get_height(child1->left), get_height(child1->right)) + 1;
return child1;
}
// Create AVL node
-AVLNode* create_avl_node(void* data, AvlComparator compare)
-{
- AVLNode* node = (AVLNode*)malloc(sizeof(AVLNode));
+AVLNode *create_avl_node(void *data, AvlComparator compare) {
+ AVLNode *node = (AVLNode *)malloc(sizeof(AVLNode));
if (node == NULL) {
return NULL;
}
@@ -72,12 +68,11 @@ AVLNode* create_avl_node(void* data, AvlComparator compare)
}
// Insert data into AVL tree
-Result avl_insert(AVLNode* node, void* data, AvlComparator compare)
-{
+Result avl_insert(AVLNode *node, void *data, AvlComparator compare) {
Result result;
// 1. Standard BST insertion
if (node == NULL) {
- return (Result) {create_avl_node(data, compare), TRUE};
+ return (Result){create_avl_node(data, compare), TRUE};
}
if (node->compare(data, node->data)) {
@@ -86,20 +81,21 @@ Result avl_insert(AVLNode* node, void* data, AvlComparator compare)
fprintf(stderr, "Failed to insert!");
return result;
}
- node->left = (AVLNode*)result.data;
+ node->left = (AVLNode *)result.data;
} else if (node->compare(node->data, data)) {
result = avl_insert(node->right, data, compare);
if (!result.success) {
fprintf(stderr, "Failed to insert!");
return result;
}
- node->right = (AVLNode*)result.data;
+ node->right = (AVLNode *)result.data;
} else {
- return (Result) {node, FALSE};
+ return (Result){node, FALSE};
}
// 2. Update height of the ancestor node
- node->height = 1 + max_height(get_height(node->left), get_height(node->right));
+ node->height =
+ 1 + max_height(get_height(node->left), get_height(node->right));
ssize_t balance = get_balance_factor(node);
@@ -107,26 +103,25 @@ Result avl_insert(AVLNode* node, void* data, AvlComparator compare)
// LeftLeft
if ((balance > 1) && node->compare(data, node->left->data)) {
- return (Result) {right_rotate(node), TRUE};
+ return (Result){right_rotate(node), TRUE};
}
// RightRight
if ((balance < -1) && node->compare(node->right->data, data)) {
- return (Result) {left_rotate(node), TRUE};
+ return (Result){left_rotate(node), TRUE};
}
// LeftRight
if ((balance > 1) && node->compare(node->left->data, data)) {
- return (Result) {right_rotate(node), TRUE};
+ return (Result){right_rotate(node), TRUE};
}
// RightLeft
- if ((balance < -1) && node->compare(data,node->right->data)) {
- return (Result) {left_rotate(node), TRUE};
+ if ((balance < -1) && node->compare(data, node->right->data)) {
+ return (Result){left_rotate(node), TRUE};
}
- return (Result) {node, TRUE};
+ return (Result){node, TRUE};
}
// In-order traversal print pointer
-void print_in_order(AVLNode* root)
-{
+void print_in_order(AVLNode *root) {
if (root != NULL) {
print_in_order(root->left);
printf("%p ", root->data);
@@ -135,8 +130,7 @@ void print_in_order(AVLNode* root)
}
// Free avl tree nodes starting at root
-void free_avl_tree(AVLNode* root)
-{
+void free_avl_tree(AVLNode *root) {
if (root != NULL) {
free_avl_tree(root->left);
free_avl_tree(root->right);
@@ -145,8 +139,7 @@ void free_avl_tree(AVLNode* root)
}
// Free avl tree and their data starting at root
-void free_avl_tree_nodes(AVLNode* root)
-{
+void free_avl_tree_nodes(AVLNode *root) {
if (root != NULL) {
free_avl_tree_nodes(root->left);
free_avl_tree_nodes(root->right);
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;
}
-
diff --git a/lib/color.c b/lib/color.c
index 172b627..564d7c5 100644
--- a/lib/color.c
+++ b/lib/color.c
@@ -1,10 +1,10 @@
-#include <stdio.h>
-#include <lib/color.h>
#include <lib/bool.h>
+#include <lib/color.h>
+#include <stdio.h>
// Color Equal to Background
// Background: zeros in RGB, alpha can be whatever
-bool_t color_zero(const ImageData_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,8 @@ bool_t color_zero(const ImageData_t* color1, size_t channels) {
// Color Equality
// Determine if two colors are identical
-bool_t color_equal(const ImageData_t* color1, const ImageData_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 +29,7 @@ bool_t color_equal(const ImageData_t* color1, const ImageData_t* color2, size_t
}
// Print out the `channels` length color vector
-void print_color(ImageData_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/data/image_types.c b/lib/data/image_types.c
index 0e40ad1..9a0e0ce 100644
--- a/lib/data/image_types.c
+++ b/lib/data/image_types.c
@@ -1,10 +1,9 @@
#include <lib/data/image_types.h>
-#include <stdlib.h>
#include <stdio.h>
+#include <stdlib.h>
-Image* create_image(size_t width, size_t height, size_t channels)
-{
- Image* ip = (Image*)malloc(sizeof(Image));
+Image *create_image(size_t width, size_t height, size_t channels) {
+ Image *ip = (Image *)malloc(sizeof(Image));
if (ip == NULL) {
return NULL;
}
@@ -17,7 +16,8 @@ Image* create_image(size_t width, size_t height, size_t channels)
free(ip);
return NULL;
}
- ImageData_t *image_data = calloc(width * height*channels, sizeof(ImageData_t));
+ ImageData_t *image_data =
+ calloc(width * height * channels, sizeof(ImageData_t));
if (image_data == NULL) {
fprintf(stderr, "Memory allocation error\n");
free(ip->image);
@@ -36,39 +36,37 @@ Image* create_image(size_t width, size_t height, size_t channels)
free(ip);
}
for (size_t x = 0; x < width; x++) {
- ip->image[y][x] = &image_data[(y * width + x)*channels];
+ ip->image[y][x] = &image_data[(y * width + x) * channels];
}
}
return ip;
}
-Mask* create_image_mask(size_t width, size_t height)
-{
- Mask* ip = (Mask*)malloc(sizeof(Mask));
+Mask *create_image_mask(size_t width, size_t height) {
+ Mask *ip = (Mask *)malloc(sizeof(Mask));
if (ip == NULL) {
return NULL;
}
ip->width = width;
ip->height = height;
- ip->image = (MaskData_t**)malloc(sizeof(MaskData_t*) * ip->height);
+ ip->image = (MaskData_t **)malloc(sizeof(MaskData_t *) * ip->height);
if (ip->image == NULL) {
free(ip);
return NULL;
}
- MaskData_t* image_data = calloc(width*height, sizeof(MaskData_t));
+ MaskData_t *image_data = calloc(width * height, sizeof(MaskData_t));
if (image_data == NULL) {
free(ip->image);
free(ip);
return NULL;
}
for (size_t y = 0; y < height; y++) {
- ip->image[y] = &image_data[y*width];
+ ip->image[y] = &image_data[y * width];
}
return ip;
}
-void free_image(Image* image)
-{
+void free_image(Image *image) {
if (image->image[0] != NULL) {
free(image->image[0]);
image->image[0] = NULL;
@@ -82,8 +80,7 @@ void free_image(Image* image)
}
}
-void free_image_mask(Mask* image_mask)
-{
+void free_image_mask(Mask *image_mask) {
if (image_mask->image[0] != NULL) {
free(image_mask->image[0]);
image_mask->image[0] = NULL;
diff --git a/lib/dir.c b/lib/dir.c
index be2a2ac..7200c52 100644
--- a/lib/dir.c
+++ b/lib/dir.c
@@ -1,11 +1,11 @@
-#include <lib/dir.h>
#include <dirent.h>
-#include <sys/stat.h>
-#include <string.h>
+#include <lib/dir.h>
#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
// Is directory
-bool_t is_directory(char* dirname) {
+bool_t is_directory(char *dirname) {
struct stat st;
if (stat(dirname, &st) == 0) {
if (S_ISDIR(st.st_mode)) {
@@ -16,11 +16,11 @@ bool_t is_directory(char* dirname) {
}
// List directory
-char** list_directory(char* dirname) {
+char **list_directory(char *dirname) {
DIR *d;
struct dirent *dir;
d = opendir(dirname);
- char** file_names = (char**)malloc(sizeof(char*));
+ char **file_names = (char **)malloc(sizeof(char *));
if (!file_names) {
return NULL;
}
@@ -29,15 +29,15 @@ char** list_directory(char* dirname) {
if (d) {
while ((dir = readdir(d)) != NULL) {
if (dir->d_type == DT_REG) {
- // When a regular file is reached
- /// Create space for it in the list
- file_names = realloc(file_names, (file_count+1+1)*sizeof(char*));
- /// Create space for the name
- file_names[file_count] = calloc(strlen(dir->d_name)+1, sizeof(char));
- /// Copy the name
- strcpy(file_names[file_count], dir->d_name);
- /// Mark the end of the file list with a NULL entry
- file_names[++file_count] = NULL;
+ // When a regular file is reached
+ /// Create space for it in the list
+ file_names = realloc(file_names, (file_count + 1 + 1) * sizeof(char *));
+ /// Create space for the name
+ file_names[file_count] = calloc(strlen(dir->d_name) + 1, sizeof(char));
+ /// Copy the name
+ strcpy(file_names[file_count], dir->d_name);
+ /// Mark the end of the file list with a NULL entry
+ file_names[++file_count] = NULL;
}
}
return file_names;
@@ -46,23 +46,22 @@ char** list_directory(char* dirname) {
}
// Get full path
-char* full_path(char* dir, char* file)
-{
- char* fpath = NULL;
+char *full_path(char *dir, char *file) {
+ char *fpath = NULL;
size_t dir_len = strlen(dir);
size_t file_len = strlen(file);
- fpath = (char*)calloc(dir_len+file_len+2,sizeof(char));
- strcpy(fpath,dir);
- strcpy(fpath+dir_len+1,file);
+ fpath = (char *)calloc(dir_len + file_len + 2, sizeof(char));
+ strcpy(fpath, dir);
+ strcpy(fpath + dir_len + 1, file);
fpath[dir_len] = '/';
return fpath;
}
// Determines if file name has tif file extension
-bool_t is_tif_ext(char* file_name)
-{
+bool_t is_tif_ext(char *file_name) {
size_t file_len = strlen(file_name);
- if ((file_name[file_len-3] == 't') && (file_name[file_len-2] == 'i') && (file_name[file_len-1] == 'f')) {
+ if ((file_name[file_len - 3] == 't') && (file_name[file_len - 2] == 'i') &&
+ (file_name[file_len - 1] == 'f')) {
return TRUE;
}
return FALSE;
diff --git a/lib/file.c b/lib/file.c
index b6ec1d0..6700451 100644
--- a/lib/file.c
+++ b/lib/file.c
@@ -2,8 +2,7 @@
#include <stdio.h>
// Write array to a file
-bool_t write_array(char* output_file_name, void* array, size_t size)
-{
+bool_t write_array(char *output_file_name, void *array, size_t size) {
FILE *file = fopen(output_file_name, "wb");
if (file == NULL) {
fprintf(stderr, "Error opening file %s\n", output_file_name);
diff --git a/lib/lib.c b/lib/lib.c
index c1f26fc..1376a77 100644
--- a/lib/lib.c
+++ b/lib/lib.c
@@ -1,4 +1,4 @@
#include <lib/lib.h>
-const uint32_t SCREEN_WIDTH = 640;
+const uint32_t SCREEN_WIDTH = 640;
const uint32_t SCREEN_HEIGHT = 480;
diff --git a/lib/png.c b/lib/png.c
index 5da0b95..1264a5a 100644
--- a/lib/png.c
+++ b/lib/png.c
@@ -1,17 +1,16 @@
#include <lib/png.h>
-#include <stdio.h>
#include <png.h>
+#include <stdio.h>
// Save bitmap to file
-void save_png(Bitmap* bitmap, char* fname)
-{
+void save_png(Bitmap *bitmap, char *fname) {
FILE *fp;
png_structp png_ptr = NULL;
png_infop info_ptr = NULL;
PixelSize_t pixel_size = 3;
PixelDepth_t pixel_depth = 8;
- png_byte ** row_pointers = NULL;
+ png_byte **row_pointers = NULL;
size_t x, y;
fp = fopen(fname, "wb");
if (fp == NULL) {
@@ -35,20 +34,19 @@ void save_png(Bitmap* bitmap, char* fname)
fclose(fp);
return;
}
- png_set_IHDR(png_ptr, info_ptr,
- bitmap->width, bitmap->height,
- pixel_depth,
- PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT,
- PNG_FILTER_TYPE_DEFAULT);
+ png_set_IHDR(png_ptr, info_ptr, bitmap->width, bitmap->height, pixel_depth,
+ PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE,
+ PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
- row_pointers = png_malloc(png_ptr, bitmap->height*sizeof(png_byte*));
+ 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(PixelChannel_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;
- *row++ = bitmap->image_buffer[x + y*bitmap->width].green;
- *row++ = bitmap->image_buffer[x + y*bitmap->width].blue;
+ *row++ = bitmap->image_buffer[x + y * bitmap->width].red;
+ *row++ = bitmap->image_buffer[x + y * bitmap->width].green;
+ *row++ = bitmap->image_buffer[x + y * bitmap->width].blue;
}
}
png_init_io(png_ptr, fp);
@@ -61,4 +59,3 @@ void save_png(Bitmap* bitmap, char* fname)
png_destroy_write_struct(&png_ptr, &info_ptr);
fclose(fp);
}
-
diff --git a/lib/seg/mask_data.c b/lib/seg/mask_data.c
index d1713e2..144c7ca 100644
--- a/lib/seg/mask_data.c
+++ b/lib/seg/mask_data.c
@@ -4,9 +4,8 @@
#include <stdio.h>
// Allocate Mask Data for Label
-MaskData* create_mask_data(MaskData_t label)
-{
- MaskData *data = (MaskData*)malloc(sizeof(MaskData));
+MaskData *create_mask_data(MaskData_t label) {
+ MaskData *data = (MaskData *)malloc(sizeof(MaskData));
data->label = label;
data->area = 0;
data->perimeter = 0;
@@ -14,79 +13,68 @@ MaskData* create_mask_data(MaskData_t label)
}
// Compare mask data labels
-bool_t compare_labels(MaskData* left, MaskData* right)
-{
+bool_t compare_labels(MaskData *left, MaskData *right) {
return left->label < right->label;
}
// Create AVL Mask node
-AVLNode* create_avl_mask_node(MaskData* data)
-{
- return create_avl_node((void*)data, (AvlComparator)compare_labels);
+AVLNode *create_avl_mask_node(MaskData *data) {
+ return create_avl_node((void *)data, (AvlComparator)compare_labels);
}
// Insert MaskData into the AVL Tree
-Result insert_mask(AVLNode* node, MaskData* data)
-{
- return avl_insert(node, (void*)data, (AvlComparator)compare_labels);
+Result insert_mask(AVLNode *node, MaskData *data) {
+ return avl_insert(node, (void *)data, (AvlComparator)compare_labels);
}
// Allocate a label's Mask data in a tree
// If it already exists, skip the allocation
-AVLNode* insert_mask_alloc(AVLNode* node, MaskData_t label)
-{
- MaskData* data = create_mask_data(label);
+AVLNode *insert_mask_alloc(AVLNode *node, MaskData_t label) {
+ MaskData *data = create_mask_data(label);
Result result = insert_mask(node, data);
if (!result.success) {
free(data);
}
- return (AVLNode*)result.data;
+ return (AVLNode *)result.data;
}
// Print AVL Node Mask Data Label
-void print_label(AVLNode* root)
-{
+void print_label(AVLNode *root) {
if (root != NULL) {
print_label(root->left);
- MaskData* data = root->data;
+ MaskData *data = root->data;
printf("%d: (%zu, %zu) ", data->label, data->area, data->perimeter);
print_label(root->right);
}
}
// Increase the label's area
-bool_t increase_label_area(AVLNode* root, MaskData_t label)
-{
+bool_t increase_label_area(AVLNode *root, MaskData_t label) {
if (root == NULL) {
return FALSE;
}
- MaskData* data = (MaskData*)root->data;
+ MaskData *data = (MaskData *)root->data;
if (data->label == label) {
data->area++;
- }
- else if (data->label > label) {
+ } else if (data->label > label) {
return increase_label_area(root->left, label);
- }
- else if (data->label < label) {
+ } else if (data->label < label) {
return increase_label_area(root->right, label);
}
return TRUE;
}
// Increase the label's perimeter
-bool_t increase_label_perimeter(AVLNode* root, MaskData_t label)
-{
+bool_t increase_label_perimeter(AVLNode *root, MaskData_t label) {
if (root == NULL) {
return FALSE;
}
- MaskData* data = (MaskData*)root->data;
+ MaskData *data = (MaskData *)root->data;
if (data->label == label) {
data->perimeter++;
- }
- else if (data->label > label) {
+ } else if (data->label > label) {
return increase_label_perimeter(root->left, label);
- }
- else if (data->label < label) {
+ } else if (data->label < label) {
return increase_label_perimeter(root->right, label);
}
return TRUE;
@@ -94,9 +82,8 @@ bool_t increase_label_perimeter(AVLNode* root, MaskData_t label)
// Increase the label's area
// Create an AVL node if it doesn't exist
-AVLNode* increase_label_area_alloc(AVLNode* root, MaskData_t label)
-{
- AVLNode* new_root = root;
+AVLNode *increase_label_area_alloc(AVLNode *root, MaskData_t label) {
+ AVLNode *new_root = root;
bool_t success = increase_label_area(new_root, label);
if (success == FALSE) {
new_root = insert_mask_alloc(new_root, label);
@@ -107,9 +94,8 @@ AVLNode* increase_label_area_alloc(AVLNode* root, MaskData_t label)
// Increase the label's perimeter
// Create an AVL node if it doesn't exist
-AVLNode* increase_label_perimeter_alloc(AVLNode* root, MaskData_t label)
-{
- AVLNode* new_root = root;
+AVLNode *increase_label_perimeter_alloc(AVLNode *root, MaskData_t label) {
+ AVLNode *new_root = root;
bool_t success = increase_label_perimeter(new_root, label);
if (success == FALSE) {
new_root = insert_mask_alloc(new_root, label);
@@ -119,30 +105,27 @@ AVLNode* increase_label_perimeter_alloc(AVLNode* root, MaskData_t label)
}
// Comparison of MaskData_ts
-bool_t compare_image_mask_data_t(MaskData_t* s1, MaskData_t* s2)
-{
+bool_t compare_image_mask_data_t(MaskData_t *s1, MaskData_t *s2) {
return *s1 < *s2;
}
// In-order traversal print pointer
-void print_in_order_image_mask_data_t(AVLNode* root)
-{
+void print_in_order_image_mask_data_t(AVLNode *root) {
if (root != NULL) {
print_in_order_image_mask_data_t(root->left);
- printf("%d ", *((MaskData_t*)root->data));
+ printf("%d ", *((MaskData_t *)root->data));
print_in_order_image_mask_data_t(root->right);
}
}
// Check if MaskData_t in AVLTree with MaskData_t* data
-bool_t in_image_mask_data_t_tree(AVLNode* root, MaskData_t value)
-{
+bool_t in_image_mask_data_t_tree(AVLNode *root, MaskData_t value) {
if (root == NULL) {
return FALSE;
}
- if (*((MaskData_t*)root->data) == value) {
+ if (*((MaskData_t *)root->data) == value) {
return TRUE;
- } else if (value < *((MaskData_t*)root->data)) {
+ } else if (value < *((MaskData_t *)root->data)) {
return in_image_mask_data_t_tree(root->left, value);
} else {
return in_image_mask_data_t_tree(root->right, value);
@@ -151,37 +134,41 @@ bool_t in_image_mask_data_t_tree(AVLNode* root, MaskData_t value)
// Filter out small masks
// Assumption: Contiguous labeling
-AVLNode* get_small_labels(AVLNode* removal_tree, AVLNode* label_tree, size_t min_area, size_t min_perimeter)
-{
- AVLNode* return_tree = removal_tree;
+AVLNode *get_small_labels(AVLNode *removal_tree, AVLNode *label_tree,
+ size_t min_area, size_t min_perimeter) {
+ AVLNode *return_tree = removal_tree;
if (label_tree != NULL) {
- return_tree = get_small_labels(return_tree, label_tree->left, min_area, min_perimeter);
- MaskData* node_data = (MaskData*)label_tree->data;
- if ((node_data->area < min_area) || (node_data->perimeter < min_perimeter)) {
+ return_tree = get_small_labels(return_tree, label_tree->left, min_area,
+ min_perimeter);
+ MaskData *node_data = (MaskData *)label_tree->data;
+ if ((node_data->area < min_area) ||
+ (node_data->perimeter < min_perimeter)) {
// Insert
- Result result = avl_insert(return_tree, &node_data->label, (bool_t (*)(void*,void*))compare_image_mask_data_t);
+ 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;
+ return_tree = result.data;
}
}
- return_tree = get_small_labels(return_tree, label_tree->right, min_area, min_perimeter);
+ return_tree = get_small_labels(return_tree, label_tree->right, min_area,
+ min_perimeter);
}
return return_tree;
}
// Get mask label data
-AVLNode *get_mask_data(Mask *mask)
-{
+AVLNode *get_mask_data(Mask *mask) {
uint32_t width = mask->width;
uint32_t height = mask->height;
- AVLNode* root = NULL;
+ AVLNode *root = NULL;
for (size_t y = 0; y < height; y++) {
for (size_t x = 0; x < width; x++) {
if (mask->image[y][x] != 0) {
- root = increase_label_area_alloc(root, mask->image[y][x]);
- if (is_on_mask_boundary(mask, x, y)) {
- increase_label_perimeter(root, mask->image[y][x]);
- }
+ root = increase_label_area_alloc(root, mask->image[y][x]);
+ if (is_on_mask_boundary(mask, x, y)) {
+ increase_label_perimeter(root, mask->image[y][x]);
+ }
}
}
}
@@ -189,17 +176,16 @@ AVLNode *get_mask_data(Mask *mask)
}
// Filter out small masks in mask
-void filter_small_masks(Mask *mask, size_t min_area, size_t min_perimeter)
-{
+void filter_small_masks(Mask *mask, size_t min_area, size_t min_perimeter) {
uint32_t width = mask->width;
uint32_t height = mask->height;
- AVLNode* root = get_mask_data(mask);
- AVLNode* small_label_tree = NULL;
+ AVLNode *root = get_mask_data(mask);
+ AVLNode *small_label_tree = NULL;
small_label_tree = get_small_labels(NULL, root, min_area, min_perimeter);
for (size_t y = 0; y < height; y++) {
for (size_t x = 0; x < width; x++) {
if (in_image_mask_data_t_tree(small_label_tree, mask->image[y][x])) {
- mask->image[y][x] = 0;
+ mask->image[y][x] = 0;
}
}
}
diff --git a/lib/seg/util.c b/lib/seg/util.c
index 7b8d317..8af8199 100644
--- a/lib/seg/util.c
+++ b/lib/seg/util.c
@@ -1,43 +1,41 @@
-#include <lib/seg/util.h>
+#include <assert.h>
#include <lib/algo/flood_fill.h>
#include <lib/png.h>
-#include <tiffio.h>
-#include <assert.h>
+#include <lib/seg/util.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <tiffio.h>
// Suppress Tiff Warnings
-void TiffDummyHandler(const char* module, const char* fmt, va_list ap)
-{
- // ignore errors and warnings (or handle them your own way)
+void TiffDummyHandler(const char *module, const char *fmt, va_list ap) {
+ // ignore errors and warnings (or handle them your own way)
}
// Determine if coordinate is on a mask boundary
// Assumes mask is (WxH)
-bool_t is_on_mask_boundary(Mask* mask, size_t x, size_t y)
-{
+bool_t is_on_mask_boundary(Mask *mask, size_t x, size_t y) {
MaskData_t current_value = mask->image[y][x];
// Left neighbor
if (x != 0) {
- if (mask->image[y][x-1] != current_value) {
+ if (mask->image[y][x - 1] != current_value) {
return TRUE;
}
}
// Right neighbor
- if ((x+1) != mask->width) {
- if (mask->image[y][x+1] != current_value) {
+ if ((x + 1) != mask->width) {
+ if (mask->image[y][x + 1] != current_value) {
return TRUE;
}
}
if (y != 0) {
- if (mask->image[y-1][x] != current_value) {
+ if (mask->image[y - 1][x] != current_value) {
return TRUE;
}
}
- if ((y+1) != mask->height) {
- if (mask->image[y+1][x] != current_value) {
+ if ((y + 1) != mask->height) {
+ if (mask->image[y + 1][x] != current_value) {
return TRUE;
}
}
@@ -45,40 +43,39 @@ bool_t is_on_mask_boundary(Mask* mask, size_t x, size_t y)
}
// Dilate masks by one 4-connected pixel
-MaskData_t* _dilate(const Mask* mask)
-{
+MaskData_t *_dilate(const Mask *mask) {
uint32_t width = mask->width;
uint32_t height = mask->height;
Mask *new_mask = create_image_mask(width, height);
for (size_t y = 0; y < height; y++) {
for (size_t x = 0; x < width; x++) {
if (mask->image[y][x] != 0) {
- new_mask->image[y][x] = mask->image[y][x];
- continue;
+ new_mask->image[y][x] = mask->image[y][x];
+ continue;
}
if (x != 0) {
- if (mask->image[y][x-1] != 0) {
- new_mask->image[y][x] = mask->image[y][x-1];
- continue;
- }
+ if (mask->image[y][x - 1] != 0) {
+ new_mask->image[y][x] = mask->image[y][x - 1];
+ continue;
+ }
}
- if ((x+1) != width) {
- if (mask->image[y][x+1] != 0) {
- new_mask->image[y][x] = mask->image[y][x+1];
- continue;
- }
+ if ((x + 1) != width) {
+ if (mask->image[y][x + 1] != 0) {
+ new_mask->image[y][x] = mask->image[y][x + 1];
+ continue;
+ }
}
if (y != 0) {
- if (mask->image[y-1][x] != 0) {
- new_mask->image[y][x] = mask->image[y-1][x];
- continue;
- }
+ if (mask->image[y - 1][x] != 0) {
+ new_mask->image[y][x] = mask->image[y - 1][x];
+ continue;
+ }
}
- if ((y+1) != height) {
- if (mask->image[y+1][x] != 0) {
- new_mask->image[y][x] = mask->image[y+1][x];
- continue;
- }
+ if ((y + 1) != height) {
+ if (mask->image[y + 1][x] != 0) {
+ new_mask->image[y][x] = mask->image[y + 1][x];
+ continue;
+ }
}
}
}
@@ -89,49 +86,48 @@ MaskData_t* _dilate(const Mask* mask)
}
// Dilate masks by one 4-connected pixel
-void dilate(Mask* mask)
-{
+void dilate(Mask *mask) {
MaskData_t *new_mask = _dilate(mask);
if (new_mask != NULL) {
free(mask->image[0]);
for (size_t y = 0; y < mask->height; y++) {
- mask->image[y] = &(new_mask[y*mask->width]);
+ mask->image[y] = &(new_mask[y * mask->width]);
}
}
}
// Erode masks by one 4-connected pixel
-MaskData_t* _erode(const Mask* mask)
-{
+MaskData_t *_erode(const Mask *mask) {
uint32_t width = mask->width;
uint32_t height = mask->height;
Mask *new_mask = create_image_mask(width, height);
- memcpy(new_mask->image[0], mask->image[0], width*height*sizeof(MaskData_t));
+ memcpy(new_mask->image[0], mask->image[0],
+ width * height * sizeof(MaskData_t));
for (size_t y = 0; y < height; y++) {
for (size_t x = 0; x < width; x++) {
if (x != 0) {
- if (mask->image[y][x-1] == 0) {
- new_mask->image[y][x] = 0;
- continue;
- }
+ if (mask->image[y][x - 1] == 0) {
+ new_mask->image[y][x] = 0;
+ continue;
+ }
}
- if ((x+1) != width) {
- if (mask->image[y][x+1] == 0) {
- new_mask->image[y][x] = 0;
- continue;
- }
+ if ((x + 1) != width) {
+ if (mask->image[y][x + 1] == 0) {
+ new_mask->image[y][x] = 0;
+ continue;
+ }
}
if (y != 0) {
- if (mask->image[y-1][x] == 0) {
- new_mask->image[y][x] = 0;
- continue;
- }
+ if (mask->image[y - 1][x] == 0) {
+ new_mask->image[y][x] = 0;
+ continue;
+ }
}
- if ((y+1) != height) {
- if (mask->image[y+1][x] == 0) {
- new_mask->image[y][x] = 0;
- continue;
- }
+ if ((y + 1) != height) {
+ if (mask->image[y + 1][x] == 0) {
+ new_mask->image[y][x] = 0;
+ continue;
+ }
}
}
}
@@ -142,20 +138,18 @@ MaskData_t* _erode(const Mask* mask)
}
// Erode masks by one 4-connected pixel
-void erode(Mask* mask)
-{
+void erode(Mask *mask) {
MaskData_t *new_mask = _erode(mask);
if (new_mask != NULL) {
free(mask->image[0]);
for (size_t y = 0; y < mask->height; y++) {
- mask->image[y] = &(new_mask[y*mask->width]);
+ mask->image[y] = &(new_mask[y * mask->width]);
}
}
}
// Close up masks by N-pixels
-MaskData_t* _closeup(Mask* mask, size_t num_pixels)
-{
+MaskData_t *_closeup(Mask *mask, size_t num_pixels) {
Mask *new_mask = create_image_mask(mask->width, mask->height);
memcpy(new_mask->image[0], mask->image[0],
mask->width * mask->height * sizeof(MaskData_t));
@@ -169,7 +163,7 @@ MaskData_t* _closeup(Mask* mask, size_t num_pixels)
for (size_t x = 0; x < mask->width; x++) {
if (mask->image[y][x] != 0) {
if (new_mask->image[y][x] != mask->image[y][x]) {
- new_mask->image[y][x] = mask->image[y][x];
+ new_mask->image[y][x] = mask->image[y][x];
}
}
}
@@ -182,13 +176,12 @@ MaskData_t* _closeup(Mask* mask, size_t num_pixels)
// Close up masks by N-pixels
// Update pointer
-void closeup(Mask* mask, size_t num_pixels)
-{
+void closeup(Mask *mask, size_t num_pixels) {
MaskData_t *new_mask = _closeup(mask, num_pixels);
if (new_mask != NULL) {
free(mask->image[0]);
for (size_t y = 0; y < mask->height; y++) {
- mask->image[y] = &(new_mask[y*mask->width]);
+ mask->image[y] = &(new_mask[y * mask->width]);
}
}
}
@@ -196,15 +189,14 @@ void closeup(Mask* mask, 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
-Mask* combine_masks(Mask *destination, Mask *extra_labels)
-{
+Mask *combine_masks(Mask *destination, Mask *extra_labels) {
if (destination == NULL) {
destination = create_image_mask(extra_labels->width, extra_labels->height);
}
for (size_t y = 0; y < destination->height; y++) {
for (size_t x = 0; x < destination->width; x++) {
if (destination->image[y][x] == 0) {
- destination->image[y][x] = extra_labels->image[y][x];
+ destination->image[y][x] = extra_labels->image[y][x];
}
}
}
@@ -214,8 +206,7 @@ Mask* combine_masks(Mask *destination, Mask *extra_labels)
// 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
-Mask *tif_to_labels(char *tif_file_name, MaskData_t *starting_label_p)
-{
+Mask *tif_to_labels(char *tif_file_name, MaskData_t *starting_label_p) {
uint32_t width = 0;
uint32_t height = 0;
TIFFSetWarningHandler(TiffDummyHandler);
@@ -233,10 +224,10 @@ Mask *tif_to_labels(char *tif_file_name, MaskData_t *starting_label_p)
tmsize_t STRIP_LENGTH = TIFFStripSize(tif);
tmsize_t STRIP_COUNT = TIFFNumberOfStrips(tif);
- channels = (STRIP_LENGTH*STRIP_COUNT)/(width*height);
+ channels = (STRIP_LENGTH * STRIP_COUNT) / (width * height);
//-TIFF-LOAD-DATA--------------------------------
- void* buffer = malloc(STRIP_LENGTH*sizeof(ImageData_t));
+ void *buffer = malloc(STRIP_LENGTH * sizeof(ImageData_t));
if (buffer == NULL) {
fprintf(stderr, "Memory allocation error\n");
TIFFClose(tif);
@@ -253,7 +244,7 @@ Mask *tif_to_labels(char *tif_file_name, MaskData_t *starting_label_p)
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->image[0][0][x + y*STRIP_LENGTH] = ((ImageData_t*)buffer)[x];
+ image->image[0][0][x + y * STRIP_LENGTH] = ((ImageData_t *)buffer)[x];
}
}
free(buffer);
@@ -271,7 +262,8 @@ Mask *tif_to_labels(char *tif_file_name, MaskData_t *starting_label_p)
// Increase label for each success
for (size_t y = 0; y < height; y++) {
for (size_t x = 0; x < width; x++) {
- if(flood(image->image[0][0], im_data->image[0], width, height, channels, x, y, image->image[y][x], *starting_label_p)) {
+ if (flood(image->image[0][0], im_data->image[0], width, height, channels,
+ x, y, image->image[y][x], *starting_label_p)) {
*starting_label_p += 1;
}
}
@@ -279,30 +271,29 @@ Mask *tif_to_labels(char *tif_file_name, MaskData_t *starting_label_p)
free_image(image);
TIFFClose(tif);
return im_data;
- //return labels;
+ // return labels;
}
// Convert mask to bitmap
-Bitmap* image_mask_data_to_bitmap(const Mask* mask)
-{
+Bitmap *image_mask_data_to_bitmap(const Mask *mask) {
MaskData_t *buffer = mask->image[0];
uint32_t width = mask->width;
uint32_t height = mask->height;
- Pixel* out_buffer = (Pixel*)calloc(width*height, sizeof(Pixel));
+ Pixel *out_buffer = (Pixel *)calloc(width * height, sizeof(Pixel));
if (out_buffer == NULL) {
return NULL;
}
- Bitmap* bitmap = (Bitmap*)malloc(sizeof(Bitmap));
+ Bitmap *bitmap = (Bitmap *)malloc(sizeof(Bitmap));
if (bitmap == NULL) {
free(out_buffer);
return NULL;
}
for (size_t y = 0; y < height; y++) {
for (size_t x = 0; x < width; x++) {
- size_t coord = x + y*width;
- ImageData_t red = (buffer[coord] & 0xF00) >> 4*2;
- ImageData_t green = (buffer[coord] & 0x0F0) >> 4*1;
- ImageData_t blue = (buffer[coord] & 0x00F) >> 4*0;
+ size_t coord = x + y * width;
+ 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);
@@ -315,19 +306,22 @@ Bitmap* image_mask_data_to_bitmap(const Mask* mask)
}
// Reduce a mask to the contiguous regions
-MaskData_t* _reduce_contiguous_regions(MaskData_t* masks, uint32_t width, uint32_t height, MaskData_t* total_labels)
-{
+MaskData_t *_reduce_contiguous_regions(MaskData_t *masks, uint32_t width,
+ uint32_t height,
+ MaskData_t *total_labels) {
MaskData_t starting_label = 1;
- MaskData_t* new_masks = (MaskData_t*)calloc(width*height, sizeof(MaskData_t));
+ MaskData_t *new_masks =
+ (MaskData_t *)calloc(width * height, sizeof(MaskData_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;
+ size_t coord = x + y * width;
ImageData_t channels = 2; // MaskData_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++;
+ if (flood((ImageData_t *)masks, new_masks, width, height, channels, x, y,
+ &(((ImageData_t *)masks)[coord * channels]), starting_label)) {
+ starting_label++;
}
}
}
@@ -340,16 +334,16 @@ MaskData_t* _reduce_contiguous_regions(MaskData_t* masks, uint32_t width, uint32
// Reduce a mask to the contiguous regions
// Automatically update pointer to contiguous mask
// Freeing previous mask
-void reduce_contiguous_regions(Mask* mask, MaskData_t* total_labels)
-{
+void reduce_contiguous_regions(Mask *mask, MaskData_t *total_labels) {
if (mask == NULL) {
return;
}
- MaskData_t* new_masks = _reduce_contiguous_regions(mask->image[0], mask->width, mask->height, total_labels);
+ MaskData_t *new_masks = _reduce_contiguous_regions(
+ mask->image[0], mask->width, mask->height, total_labels);
if (new_masks != NULL) {
free(mask->image[0]);
for (size_t y = 0; y < mask->height; y++) {
- mask->image[y] = &new_masks[y*mask->width];
+ mask->image[y] = &new_masks[y * mask->width];
}
}
}
diff --git a/lib/time.c b/lib/time.c
index 623a696..e31cbb7 100644
--- a/lib/time.c
+++ b/lib/time.c
@@ -3,11 +3,9 @@
// Difference in Time
// Compute the difference between timespec structs
double diff_time(const struct timespec *time1, const struct timespec *time0) {
- return (time1->tv_sec - time0->tv_sec)
- + (time1->tv_nsec - time0->tv_nsec) / 1000000000.0;
+ return (time1->tv_sec - time0->tv_sec) +
+ (time1->tv_nsec - time0->tv_nsec) / 1000000000.0;
}
// Get Current Time
-void get_time(struct timespec *ts) {
- timespec_get(ts, TIME_UTC);
-}
+void get_time(struct timespec *ts) { timespec_get(ts, TIME_UTC); }
diff --git a/test/lib/color.c b/test/lib/color.c
index e791d95..a93d47d 100644
--- a/test/lib/color.c
+++ b/test/lib/color.c
@@ -1,13 +1,13 @@
#include <test/lib/color.h>
-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 ImageData_t* color1, size_t channels, bool_t result)
-{
+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 ImageData_t *color1, size_t channels,
+ bool_t result) {
bool_t fcall_result = color_zero(color1, channels);
if (fcall_result == result) {
return TRUE;
@@ -15,66 +15,66 @@ bool_t test_color_zero(const ImageData_t* color1, size_t channels, bool_t result
return FALSE;
}
-void _TEST_color_zero(bool_t* result, TestCount_t* test_count, TestCount_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
// Should result: True
sub_result = test_color_zero(test_rgba, 1, TRUE);
*result &= sub_result;
- TEST_RESULT("COLOR_ZERO",sub_result, *test_count, (*test_pass));
+ TEST_RESULT("COLOR_ZERO", sub_result, *test_count, (*test_pass));
// Test 2: 1 channel non-zero color
// Should result: False
sub_result = test_color_zero(test_Rgba, 1, FALSE);
*result &= sub_result;
- TEST_RESULT("COLOR_ZERO",sub_result, *test_count, (*test_pass));
+ TEST_RESULT("COLOR_ZERO", sub_result, *test_count, (*test_pass));
// Test 3: 2 channel zero color
// Should result: True
sub_result = test_color_zero(test_rgba, 2, TRUE);
*result &= sub_result;
- TEST_RESULT("COLOR_ZERO",sub_result, *test_count, (*test_pass));
+ TEST_RESULT("COLOR_ZERO", sub_result, *test_count, (*test_pass));
// Test 4: 2 channel non-zero color
// Should result: False
sub_result = test_color_zero(test_rGba, 2, FALSE);
*result &= sub_result;
- TEST_RESULT("COLOR_ZERO",sub_result, *test_count, (*test_pass));
+ TEST_RESULT("COLOR_ZERO", sub_result, *test_count, (*test_pass));
// Test 5: 3 channel zero color
// Should result: True
sub_result = test_color_zero(test_rgba, 3, TRUE);
*result &= sub_result;
- TEST_RESULT("COLOR_ZERO",sub_result, *test_count, (*test_pass));
+ TEST_RESULT("COLOR_ZERO", sub_result, *test_count, (*test_pass));
// Test 6: 3 channel non-zero color
// Should result: False
sub_result = test_color_zero(test_rgBa, 3, FALSE);
*result &= sub_result;
- TEST_RESULT("COLOR_ZERO",sub_result, *test_count, (*test_pass));
+ TEST_RESULT("COLOR_ZERO", sub_result, *test_count, (*test_pass));
// Test 7: 4 channel zero color
// Should result: True
sub_result = test_color_zero(test_rgba, 4, TRUE);
*result &= sub_result;
- TEST_RESULT("COLOR_ZERO",sub_result, *test_count, (*test_pass));
+ TEST_RESULT("COLOR_ZERO", sub_result, *test_count, (*test_pass));
// Test 8: 4 channel non-zero color
// Should result: False
sub_result = test_color_zero(test_rgBa, 4, FALSE);
*result &= sub_result;
- TEST_RESULT("COLOR_ZERO",sub_result, *test_count, (*test_pass));
+ TEST_RESULT("COLOR_ZERO", sub_result, *test_count, (*test_pass));
// Test 9: 4 channel non-zero color (Alpha non-zero)
// Should result: True
sub_result = test_color_zero(test_rgbA, 4, TRUE);
*result &= sub_result;
- TEST_RESULT("COLOR_ZERO",sub_result, *test_count, (*test_pass));
+ TEST_RESULT("COLOR_ZERO", sub_result, *test_count, (*test_pass));
}
-bool_t test_color_equal(const ImageData_t* color1, const ImageData_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) {
return TRUE;
@@ -82,85 +82,84 @@ bool_t test_color_equal(const ImageData_t* color1, const ImageData_t* color2, si
return FALSE;
}
-void _TEST_color_equal(bool_t* result, TestCount_t* test_count, TestCount_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)
// Should result: True
sub_result = test_color_equal(test_rgba, test_rgba, 1, TRUE);
*result &= sub_result;
- TEST_RESULT("COLOR_EQUAL",sub_result, *test_count, (*test_pass));
+ TEST_RESULT("COLOR_EQUAL", sub_result, *test_count, (*test_pass));
// Test 2: 1 channel equal (nonzero)
// Should result: True
sub_result = test_color_equal(test_Rgba, test_Rgba, 1, TRUE);
*result &= sub_result;
- TEST_RESULT("COLOR_EQUAL",sub_result, *test_count, (*test_pass));
+ TEST_RESULT("COLOR_EQUAL", sub_result, *test_count, (*test_pass));
// Test 3: 1 channel nonequal
// Should result: True
sub_result = test_color_equal(test_rgba, test_Rgba, 1, FALSE);
*result &= sub_result;
- TEST_RESULT("COLOR_EQUAL",sub_result, *test_count, (*test_pass));
+ TEST_RESULT("COLOR_EQUAL", sub_result, *test_count, (*test_pass));
// Test 4: 2 channel equal (zero)
// Should result: True
sub_result = test_color_equal(test_rgba, test_rgba, 2, TRUE);
*result &= sub_result;
- TEST_RESULT("COLOR_EQUAL",sub_result, *test_count, (*test_pass));
+ TEST_RESULT("COLOR_EQUAL", sub_result, *test_count, (*test_pass));
// Test 5: 2 channel equal (nonzero)
// Should result: True
sub_result = test_color_equal(test_rGba, test_rGba, 2, TRUE);
*result &= sub_result;
- TEST_RESULT("COLOR_EQUAL",sub_result, *test_count, (*test_pass));
+ TEST_RESULT("COLOR_EQUAL", sub_result, *test_count, (*test_pass));
// Test 6: 2 channel nonequal
// Should result: False
sub_result = test_color_equal(test_Rgba, test_rGba, 2, FALSE);
*result &= sub_result;
- TEST_RESULT("COLOR_EQUAL",sub_result, *test_count, (*test_pass));
+ TEST_RESULT("COLOR_EQUAL", sub_result, *test_count, (*test_pass));
// Test 7: 3 channel equal (zero)
// Should result: True
sub_result = test_color_equal(test_rgba, test_rgba, 3, TRUE);
*result &= sub_result;
- TEST_RESULT("COLOR_EQUAL",sub_result, *test_count, (*test_pass));
+ TEST_RESULT("COLOR_EQUAL", sub_result, *test_count, (*test_pass));
// Test 8: 3 channel equal (nonzero)
// Should result: True
sub_result = test_color_equal(test_rgBa, test_rgBa, 3, TRUE);
*result &= sub_result;
- TEST_RESULT("COLOR_EQUAL",sub_result, *test_count, (*test_pass));
+ TEST_RESULT("COLOR_EQUAL", sub_result, *test_count, (*test_pass));
// Test 9: 3 channel nonequal
// Should result: False
sub_result = test_color_equal(test_Rgba, test_rgBa, 3, FALSE);
*result &= sub_result;
- TEST_RESULT("COLOR_EQUAL",sub_result, *test_count, (*test_pass));
+ TEST_RESULT("COLOR_EQUAL", sub_result, *test_count, (*test_pass));
// Test 7: 4 channel equal (zero)
// Should result: True
sub_result = test_color_equal(test_rgba, test_rgba, 4, TRUE);
*result &= sub_result;
- TEST_RESULT("COLOR_EQUAL",sub_result, *test_count, (*test_pass));
+ TEST_RESULT("COLOR_EQUAL", sub_result, *test_count, (*test_pass));
// Test 8: 4 channel equal (nonzero)
// Should result: True
sub_result = test_color_equal(test_rgbA, test_rgbA, 4, TRUE);
*result &= sub_result;
- TEST_RESULT("COLOR_EQUAL",sub_result, *test_count, (*test_pass));
+ TEST_RESULT("COLOR_EQUAL", sub_result, *test_count, (*test_pass));
// Test 9: 4 channel nonequal
// Should result: False
sub_result = test_color_equal(test_Rgba, test_rgbA, 4, FALSE);
*result &= sub_result;
- TEST_RESULT("COLOR_EQUAL",sub_result, *test_count, (*test_pass));
+ TEST_RESULT("COLOR_EQUAL", sub_result, *test_count, (*test_pass));
}
// Meta test function
-bool_t TEST_lib_color()
-{
+bool_t TEST_lib_color() {
TestCount_t test_count = 0;
TestCount_t test_pass = 0;
bool_t result = TRUE;
diff --git a/test/lib/dir.c b/test/lib/dir.c
index 21b4284..85ef400 100644
--- a/test/lib/dir.c
+++ b/test/lib/dir.c
@@ -1,10 +1,9 @@
-#include <test/lib/dir.h>
-#include <string.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
+#include <test/lib/dir.h>
-bool_t test_is_directory(char* dirname, bool_t result)
-{
+bool_t test_is_directory(char *dirname, bool_t result) {
bool_t fcall_result = is_directory(dirname);
if (fcall_result == result) {
return TRUE;
@@ -12,23 +11,22 @@ bool_t test_is_directory(char* dirname, bool_t result)
return FALSE;
}
-void _TEST_is_directory(bool_t* result, TestCount_t* test_count, TestCount_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]
sub_result = test_is_directory("sample_data", TRUE);
*result &= sub_result;
- TEST_RESULT("IS_DIRECTORY",sub_result, *test_count, (*test_pass));
+ TEST_RESULT("IS_DIRECTORY", sub_result, *test_count, (*test_pass));
// Test 2: asdf/ (FALSE) [On clean git folder]
sub_result = test_is_directory("asdf", FALSE);
*result &= sub_result;
- TEST_RESULT("IS_DIRECTORY",sub_result, *test_count, (*test_pass));
+ TEST_RESULT("IS_DIRECTORY", sub_result, *test_count, (*test_pass));
}
-bool_t test_full_path(char* dirname, char* file, char* result)
-{
- char* fpath = full_path(dirname, file);
+bool_t test_full_path(char *dirname, char *file, char *result) {
+ char *fpath = full_path(dirname, file);
bool_t cmp_result = strcmp(result, fpath);
free(fpath);
if (cmp_result == 0) {
@@ -37,47 +35,46 @@ bool_t test_full_path(char* dirname, char* file, char* result)
return FALSE;
}
-void _TEST_full_path(bool_t* result, TestCount_t* test_count, TestCount_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
- sub_result = test_full_path("sample_data/small", "small.tif", "sample_data/small/small.tif");
+ sub_result = test_full_path("sample_data/small", "small.tif",
+ "sample_data/small/small.tif");
*result &= sub_result;
- TEST_RESULT("FULL_PATH",sub_result, *test_count, (*test_pass));
+ TEST_RESULT("FULL_PATH", sub_result, *test_count, (*test_pass));
}
-bool_t test_is_tif_ext(char* file_name, bool_t result)
-{
+bool_t test_is_tif_ext(char *file_name, bool_t result) {
size_t file_name_len = strlen(file_name);
file_name_len -= 3;
- bool_t cmp_result = strcmp(file_name+file_name_len, "tif");
+ bool_t cmp_result = strcmp(file_name + file_name_len, "tif");
if (cmp_result == 0) {
return TRUE == result;
}
return FALSE == result;
}
-void _TEST_is_tif_ext(bool_t* result, TestCount_t* test_count, TestCount_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)
sub_result = test_is_tif_ext("sample_data/small/small.tif", TRUE);
*result &= sub_result;
- TEST_RESULT("IS_TIF_EXT",sub_result, *test_count, (*test_pass));
+ TEST_RESULT("IS_TIF_EXT", sub_result, *test_count, (*test_pass));
// Test 2: data/test.tif (TRUE)
sub_result = test_is_tif_ext("data/test.tif", TRUE);
*result &= sub_result;
- TEST_RESULT("IS_TIF_EXT",sub_result, *test_count, (*test_pass));
+ TEST_RESULT("IS_TIF_EXT", sub_result, *test_count, (*test_pass));
// Test 3: sample_data/small/small (FALSE)
sub_result = test_is_tif_ext("sample_data/small/small", FALSE);
*result &= sub_result;
- TEST_RESULT("IS_TIF_EXT",sub_result, *test_count, (*test_pass));
+ TEST_RESULT("IS_TIF_EXT", sub_result, *test_count, (*test_pass));
}
-bool_t TEST_lib_dir()
-{
+bool_t TEST_lib_dir() {
TestCount_t test_count = 0;
TestCount_t test_pass = 0;
bool_t result = TRUE;
diff --git a/test/lib/time.c b/test/lib/time.c
index 67c8f33..a69d5a9 100644
--- a/test/lib/time.c
+++ b/test/lib/time.c
@@ -1,12 +1,12 @@
#include <test/lib/time.h>
-const struct timespec zero = {0,0};
-const struct timespec one_s = {1,0};
-const struct timespec one_ns = {0,1};
-const struct timespec one_s_ns = {1,1};
+const struct timespec zero = {0, 0};
+const struct timespec one_s = {1, 0};
+const struct timespec one_ns = {0, 1};
+const struct timespec one_s_ns = {1, 1};
-bool_t test_diff_time(const struct timespec *time1, const struct timespec *time0, double result)
-{
+bool_t test_diff_time(const struct timespec *time1,
+ const struct timespec *time0, double result) {
double fcall_result = diff_time(time1, time0);
if (fcall_result == result) {
return TRUE;
@@ -14,42 +14,41 @@ bool_t test_diff_time(const struct timespec *time1, const struct timespec *time0
return FALSE;
}
-void _TEST_diff_time(bool_t* result, TestCount_t* test_count, TestCount_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
sub_result = test_diff_time(&zero, &zero, 0.0);
*result &= sub_result;
- TEST_RESULT("DIFF_TIME",sub_result, *test_count, (*test_pass));
+ TEST_RESULT("DIFF_TIME", sub_result, *test_count, (*test_pass));
// Test 2: 1s-0=1s
sub_result = test_diff_time(&one_s, &zero, 1.0);
*result &= sub_result;
- TEST_RESULT("DIFF_TIME",sub_result, *test_count, (*test_pass));
+ TEST_RESULT("DIFF_TIME", sub_result, *test_count, (*test_pass));
// Test 3: 1ns-0=1ns
sub_result = test_diff_time(&one_ns, &zero, 0.000000001);
*result &= sub_result;
- TEST_RESULT("DIFF_TIME",sub_result, *test_count, (*test_pass));
+ TEST_RESULT("DIFF_TIME", sub_result, *test_count, (*test_pass));
// Test 4: 1s1ns-0=1s1ns
sub_result = test_diff_time(&one_s_ns, &zero, 1.000000001);
*result &= sub_result;
- TEST_RESULT("DIFF_TIME",sub_result, *test_count, (*test_pass));
+ TEST_RESULT("DIFF_TIME", sub_result, *test_count, (*test_pass));
// Test 5: 1s1ns-1ns=1s
sub_result = test_diff_time(&one_s_ns, &one_ns, 1.0);
*result &= sub_result;
- TEST_RESULT("DIFF_TIME",sub_result, *test_count, (*test_pass));
+ TEST_RESULT("DIFF_TIME", sub_result, *test_count, (*test_pass));
// Test 6: 1s1ns-1s=1ns
sub_result = test_diff_time(&one_s_ns, &one_s, 0.000000001);
*result &= sub_result;
- TEST_RESULT("DIFF_TIME",sub_result, *test_count, (*test_pass));
+ TEST_RESULT("DIFF_TIME", sub_result, *test_count, (*test_pass));
}
-bool_t TEST_lib_time()
-{
+bool_t TEST_lib_time() {
TestCount_t test_count = 0;
TestCount_t test_pass = 0;
bool_t result = TRUE;
diff --git a/test/test.c b/test/test.c
index 40e2d6f..786ab2e 100644
--- a/test/test.c
+++ b/test/test.c
@@ -2,10 +2,14 @@
#include <test/lib/dir.h>
#include <test/lib/time.h>
-#define _META_TEST_RESULT(name,result) if (result) { fprintf(stderr, " \x1b[92mPASS\x1b[0m %s\n", name);} else { fprintf(stderr, "%s: \x1b[91mFAIL\x1b[0m\n", name);}
+#define _META_TEST_RESULT(name, result) \
+ if (result) { \
+ fprintf(stderr, " \x1b[92mPASS\x1b[0m %s\n", name); \
+ } else { \
+ fprintf(stderr, "%s: \x1b[91mFAIL\x1b[0m\n", name); \
+ }
-int main()
-{
+int main() {
bool_t all_success = TRUE;
bool_t test_success;
// lib/color.c Test