diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/lib/color.h | 4 | ||||
-rw-r--r-- | include/lib/monad.h | 2 | ||||
-rw-r--r-- | include/lib/time.h | 2 | ||||
-rw-r--r-- | include/snippets/raylib_block.c | 93 | ||||
-rw-r--r-- | include/test/__meta__.h | 19 | ||||
-rw-r--r-- | include/test/lib/color.h | 17 | ||||
-rw-r--r-- | include/test/lib/dir.h | 18 | ||||
-rw-r--r-- | include/test/lib/time.h | 16 |
8 files changed, 75 insertions, 96 deletions
diff --git a/include/lib/color.h b/include/lib/color.h index 5e7128b..1bc9393 100644 --- a/include/lib/color.h +++ b/include/lib/color.h @@ -7,11 +7,11 @@ // Color Equal to Background // Background: zeros in RGB, alpha can be whatever -bool_t color_zero(uint8_t* color1, size_t channels); +bool_t color_zero(const uint8_t* color1, size_t channels); // Color Equality // Determine if two colors are identical -bool_t color_equal(uint8_t* color1, uint8_t* color2, size_t channels); +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); diff --git a/include/lib/monad.h b/include/lib/monad.h index 4a68e0a..74db079 100644 --- a/include/lib/monad.h +++ b/include/lib/monad.h @@ -1,6 +1,8 @@ #ifndef INC_LIB_MONAD_H #define INC_LIB_MONAD_H +#include <lib/bool.h> + struct Result { void* data; bool_t success; diff --git a/include/lib/time.h b/include/lib/time.h index 9d69b44..1adf428 100644 --- a/include/lib/time.h +++ b/include/lib/time.h @@ -7,7 +7,7 @@ // Difference in Time // Compute the difference between timespec structs -double diff_time(struct timespec *time1, struct timespec *time0); +double diff_time(const struct timespec *time1, const struct timespec *time0); // Get Current Time void get_time(struct timespec *ts); diff --git a/include/snippets/raylib_block.c b/include/snippets/raylib_block.c deleted file mode 100644 index ef81fd2..0000000 --- a/include/snippets/raylib_block.c +++ /dev/null @@ -1,93 +0,0 @@ - //----------------------------------------------- - //-RAYLIB-INIT----------------------------------- - //----------------------------------------------- - SetTraceLogLevel(LOG_ERROR); - SetConfigFlags(FLAG_WINDOW_RESIZABLE); - const char* gui_title = "Image Manip - Useful for segmentations!"; - InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, gui_title); - - //----------------------------------------------- - // (When treating this as RGBA, last bits should ensure opaque) - // This assumes 4096 (2^12) > labels - for (size_t y = 0; y < height; y++) { - for (size_t x = 0; x < width; x++) { - /// RGBA channels: Move labels to RGB - masks[x + y*width] <<= 4; - masks[x + y*width] |= 0x000F; - } - } - //----------------------------------------------- - - //----------------------------------------------- - //-RAYLIB-IMAGE-STRUCTURING---------------------- - //----------------------------------------------- - Image RaylibImage; - RaylibImage.width = width; - RaylibImage.height = height; - RaylibImage.mipmaps = 1; - // Use Contiguous Labels - RaylibImage.data = masks; - RaylibImage.format = PIXELFORMAT_UNCOMPRESSED_R4G4B4A4; - //----------------------------------------------- - - // Image to a Texture - Texture2D RaylibTexture = LoadTextureFromImage(RaylibImage); - - // Scale the image to the viewport - /// Source Rectangle: Original Size - Rectangle sourceRec = { 0.0f, 0.0f, (float)width, (float)height }; - /// Destination Rectangle: Transformed Size - Rectangle destRec = { 0.0f, 0.0f, (float)SCREEN_WIDTH, (float)(SCREEN_HEIGHT-OFFSET) }; - /// Location to begin drawing - Vector2 origin = { (float)0, (float)-OFFSET }; - - // Raylib boilerplate - SetTargetFPS(60); - Camera2D camera = { 0 }; - camera.zoom = 1.0f; - - // GUI Loop - while (!WindowShouldClose()) { - //----------------------------------------------- - //-DRAWING--------------------------------------- - //----------------------------------------------- - BeginDrawing(); - ClearBackground(RAYWHITE); - BeginMode2D(camera); - EndMode2D(); - DrawText("Image Manip", 0, 0, OFFSET, DARKGRAY); - DrawTexturePro(RaylibTexture, sourceRec, destRec, origin, (float)0, - RAYWHITE); - /* - uint32_t x = 0x49, y = 0x4A; - uint32_t dx = 0x69 - x, dy = 0x6E - y; - x = (SCREEN_WIDTH*x)/width; - y = SCREEN_HEIGHT-((SCREEN_HEIGHT-OFFSET)*y)/height; - dx = (SCREEN_WIDTH*dx)/width; - dy = SCREEN_HEIGHT-((SCREEN_HEIGHT-OFFSET)*dy)/height; - DrawRectangleGradientH(x, y, dx, dy, BLUE, PURPLE); - */ - EndDrawing(); - //----------------------------------------------- - } - - //----------------------------------------------- - //-SAVE-MASK-AS-BINARY-AND-PNG------------------- - //----------------------------------------------- - if (masks != NULL) { - for (size_t y = 0; y < height; y++) { - for (size_t x = 0; x < width; x++) { - /// Restore labels from RGBA - masks[x + y*width] &= 0xFFF0; - masks[x + y*width] >>= 4; - } - } - struct bitmap_t* bitmap = uint16_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)); - free(masks); - } - CloseWindow(); diff --git a/include/test/__meta__.h b/include/test/__meta__.h new file mode 100644 index 0000000..305698a --- /dev/null +++ b/include/test/__meta__.h @@ -0,0 +1,19 @@ +#ifndef INC_TEST___META___H +#define INC_TEST___META___H + +#include <lib/bool.h> +#include <stdio.h> + +#ifdef TEST_SHOW_PASS +#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 +#endif + +#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++;} +#endif + +#endif diff --git a/include/test/lib/color.h b/include/test/lib/color.h new file mode 100644 index 0000000..be0d62f --- /dev/null +++ b/include/test/lib/color.h @@ -0,0 +1,17 @@ +#ifndef INC_TEST_LIB_COLOR_H +#define INC_TEST_LIB_COLOR_H + +#include <test/__meta__.h> +#ifndef TEST_RESULT +#define TEST_RESULT(subtest,result,n,n_success) _TEST_RESULT("LIB/COLOR",subtest,result,n,n_success) +#endif + +#include <lib/color.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); + +// Meta test function +bool_t TEST_lib_color(); + +#endif diff --git a/include/test/lib/dir.h b/include/test/lib/dir.h new file mode 100644 index 0000000..64482df --- /dev/null +++ b/include/test/lib/dir.h @@ -0,0 +1,18 @@ +#ifndef INC_TEST_LIB_DIR_H +#define INC_TEST_LIB_DIR_H + +#include <test/__meta__.h> +#ifndef TEST_RESULT +#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); + +// Meta test function +bool_t TEST_lib_dir(); + +#endif diff --git a/include/test/lib/time.h b/include/test/lib/time.h new file mode 100644 index 0000000..cdf464e --- /dev/null +++ b/include/test/lib/time.h @@ -0,0 +1,16 @@ +#ifndef INC_TEST_LIB_TIME_H +#define INC_TEST_LIB_TIME_H + +#include <test/__meta__.h> +#ifndef TEST_RESULT +#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); + +// Meta test function +bool_t TEST_lib_time(); + +#endif |