aboutsummaryrefslogtreecommitdiff
path: root/src/lib/seg
diff options
context:
space:
mode:
authorChristian C <cc@localhost>2025-03-05 21:57:20 -0800
committerChristian C <cc@localhost>2025-03-05 21:57:20 -0800
commit22db7ab4cb3b2928095bd9775fb015a5e28487f6 (patch)
tree24f1d1538809795b8b356810b6b3e6fc8dc627b4 /src/lib/seg
parent74ae06a582b7c567caf3c04e5bf5dfabf6671f31 (diff)
Save to PNG
Diffstat (limited to 'src/lib/seg')
-rw-r--r--src/lib/seg/util.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/lib/seg/util.c b/src/lib/seg/util.c
index 530c326..10b8fa8 100644
--- a/src/lib/seg/util.c
+++ b/src/lib/seg/util.c
@@ -1,5 +1,6 @@
#include <lib/seg/util.h>
#include <lib/algo/flood_fill.h>
+#include <lib/png.h>
#include <tiffio.h>
#include <assert.h>
#include <stdio.h>
@@ -260,3 +261,32 @@ uint16_t* tif_to_labels(char* tif_file_name, uint32_t *width, uint32_t *height,
TIFFClose(tif);
return labels;
}
+
+// Convert mask to bitmap
+struct bitmap_t* uint16_to_bitmap(uint16_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) {
+ return NULL;
+ }
+ struct bitmap_t* bitmap = (struct bitmap_t*)malloc(sizeof(struct bitmap_t));
+ 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;
+ uint8_t red = (buffer[coord] & 0xF00) >> 4*2;
+ uint8_t green = (buffer[coord] & 0x0F0) >> 4*1;
+ uint8_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);
+ }
+ }
+ bitmap->image_buffer = out_buffer;
+ bitmap->width = (size_t)width;
+ bitmap->height = (size_t)height;
+ return bitmap;
+}