#include #include #include #include #include "brailleboi.h" int brailleInit(int width, int height, image_buffer* buf) { setlocale(LC_ALL, ""); buf->contents = malloc((width * height) * sizeof(int)); buf->width = width; buf->height = height; 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&0b10000111) | (old&0b01110000)>>1 | (old&0b00001000)<<3; 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 //TODO: fix boundary check // if (x>buf->width | y>buf->height) // return 1; buf->contents[y/4 * buf->width + x/2] |= 128>>(y-1)%4+(x%2)*4; // buf->contents[y/4 * buf->width + x/2] |= 128>>; //printf("%#08x\n", buf->contents[y/4 * buf->width + x/2]); return 0; } void brailleUpdateScreen(image_buffer* buf) { for (int x=0;xwidth;x++) { for (int y=0;yheight;y++) { wprintf(L"\e[%d;%dH", y, x); braillePrint(brailleReorganizeBits(buf->contents[y * buf->width + x])); } } }