From 125e25428b5faa36e1ac96f091079282b4851b3e Mon Sep 17 00:00:00 2001 From: DrNuget Date: Sun, 2 Nov 2025 02:16:10 +0200 Subject: create src folder, move library codes there --- src/brailleboi.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/brailleboi.h | 22 ++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 src/brailleboi.c create mode 100644 src/brailleboi.h (limited to 'src') diff --git a/src/brailleboi.c b/src/brailleboi.c new file mode 100644 index 0000000..82fbeeb --- /dev/null +++ b/src/brailleboi.c @@ -0,0 +1,56 @@ +#include +#include +#include +#include + +#include "brailleboi.h" + +int brailleInit(int width, int height, image_buffer* buf) +{ + setlocale(LC_ALL, ""); + buf->width = width; + buf->height = height; + buf->char_width = (width+1)/2; + buf->char_height = (height+1)/2; + buf->contents = malloc((buf->char_width * buf->char_height) * sizeof(int)); + return 0; +} + +int brailleStop(image_buffer* buf) +{ + free(buf->contents); + return 0; +} + +int brailleReorganizeBits(int old) +{ + //Reorganizes bits because the unicode standard for 8 dotted braille is weird + int new = (old&0x87) | // 0b10000111 + (old&0x70)>>1 | // 0b01110000 + (old&0x08)<<3; // 0b00001000 + return new; +} + +void braillePrint(int data) +{ + wprintf(L"%lc", (0x2800|data)); +} + +int braillePlot(int x, int y, image_buffer* buf) +{ + //Check if plot is within bounds + if ((x>buf->width) | (y>buf->height)) + return 1; + buf->contents[(y-1)/4 * buf->char_width + (x-1)/2] |= 1<<((y-1)%4+(1-x%2)*4); + return 0; +} + +void brailleUpdateScreen(image_buffer* buf) +{ + for (int x=0;xchar_width;x++) { + for (int y=0;ychar_height;y++) { + wprintf(L"\e[%d;%dH", y+1, x+1); + braillePrint(brailleReorganizeBits(buf->contents[y * buf->char_width + x])); + } + } +} diff --git a/src/brailleboi.h b/src/brailleboi.h new file mode 100644 index 0000000..f06d0da --- /dev/null +++ b/src/brailleboi.h @@ -0,0 +1,22 @@ +#ifndef BRAILLEBOI_H +#define BRAILLEBOI_H + +typedef struct image_buffer { + int width, height; + int char_width, char_height; + int* contents; +} image_buffer; + +int brailleInit(int width, int height, image_buffer* buf); + +int brailleStop(image_buffer* buf); + +int brailleReorganizeBits(int old); + +void braillePrint(int data); + +int braillePlot(int x, int y, image_buffer* buf); + +void brailleUpdateScreen(image_buffer* buf); + +#endif -- cgit v1.2.3