diff options
Diffstat (limited to 'src/lib/seg')
-rw-r--r-- | src/lib/seg/util.c | 30 |
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; +} |