From 3a61b957905ed1952f6ec15f684a03bf0f55a2ba Mon Sep 17 00:00:00 2001 From: Christian C Date: Wed, 5 Mar 2025 13:22:37 -0800 Subject: Dump output to file --- include/lib/file.h | 10 ++++++++++ src/lib/file.c | 15 +++++++++++++++ src/main.c | 13 ++++++++++++- 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 include/lib/file.h create mode 100644 src/lib/file.c diff --git a/include/lib/file.h b/include/lib/file.h new file mode 100644 index 0000000..9a231cc --- /dev/null +++ b/include/lib/file.h @@ -0,0 +1,10 @@ +#ifndef INC_LIB_FILE_H +#define INC_LIB_FILE_H + +#include +#include + +// Write array to a file +bool_t write_array(char* output_file_name, void* array, size_t size); + +#endif diff --git a/src/lib/file.c b/src/lib/file.c new file mode 100644 index 0000000..b6ec1d0 --- /dev/null +++ b/src/lib/file.c @@ -0,0 +1,15 @@ +#include +#include + +// Write array to a file +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); + return FALSE; + } + fwrite(array, size, 1, file); + fclose(file); + return TRUE; +} diff --git a/src/main.c b/src/main.c index abfc57f..94315e4 100644 --- a/src/main.c +++ b/src/main.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -80,7 +81,9 @@ int main(int argc, char** argv) // This assumes 4096 (2^12) > labels for (size_t y = 0; y < height; y++) { for (size_t x = 0; x < width; x++) { - masks[x + y*width] |= 0xFF000000; + /// RGBA channels: Move labels to RGB + masks[x + y*width] <<= 4; + masks[x + y*width] |= 0x000F; } } //----------------------------------------------- @@ -139,6 +142,14 @@ int main(int argc, char** argv) } 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; + } + } + write_array("../out.bin", masks, width*height*sizeof(uint16_t)); free(masks); } CloseWindow(); -- cgit v1.2.1