From 238d341c328075454b6b82dc8348a335dc04254d Mon Sep 17 00:00:00 2001 From: DrNuget Date: Thu, 30 Oct 2025 09:08:41 +0200 Subject: some broken stuff, will fix later --- brailleboi.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'brailleboi.c') diff --git a/brailleboi.c b/brailleboi.c index e04d17c..9bc6b8b 100644 --- a/brailleboi.c +++ b/brailleboi.c @@ -22,6 +22,7 @@ int brailleStop(image_buffer* buf) 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; @@ -32,3 +33,22 @@ 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 * buf->width + x] |= 1<<((1+x%2)*y); + return 0; +} + +void brailleUpdateScreen(image_buffer* buf) +{ + for (int x=0;xwidth;x++) { + for (int y=0;yheight;y++) { + printf("\e[%d;%dH", y, x); + braillePrint(buf->contents[y * buf->width + x]); + } + } +} -- cgit v1.2.3 From 1e07325fed7f3e5b0354a977da0fc1739c0b2a3c Mon Sep 17 00:00:00 2001 From: DrNuget Date: Fri, 31 Oct 2025 20:51:54 +0200 Subject: something slightly less broken shit --- brailleboi.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'brailleboi.c') diff --git a/brailleboi.c b/brailleboi.c index 9bc6b8b..d8ff8e9 100644 --- a/brailleboi.c +++ b/brailleboi.c @@ -37,9 +37,11 @@ void braillePrint(int 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 * buf->width + x] |= 1<<((1+x%2)*y); + //TODO: fix boundary check +// if (x>buf->width | y>buf->height) +// return 1; + buf->contents[y/4 * buf->width + x/2] |= 128>>y%4+x%2*4; + //printf("%#08x\n", buf->contents[y/4 * buf->width + x/2]); return 0; } @@ -47,7 +49,7 @@ void brailleUpdateScreen(image_buffer* buf) { for (int x=0;xwidth;x++) { for (int y=0;yheight;y++) { - printf("\e[%d;%dH", y, x); + wprintf(L"\e[%d;%dH", y, x); braillePrint(buf->contents[y * buf->width + x]); } } -- cgit v1.2.3 From db2e43856b5dc9473a6311e3cc60f2645172ac3f Mon Sep 17 00:00:00 2001 From: DrNuget Date: Sat, 1 Nov 2025 18:39:47 +0200 Subject: fix the math formula for bit shifting --- brailleboi.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'brailleboi.c') diff --git a/brailleboi.c b/brailleboi.c index d8ff8e9..e47ca8b 100644 --- a/brailleboi.c +++ b/brailleboi.c @@ -40,7 +40,8 @@ int braillePlot(int x, int y, image_buffer* buf) //TODO: fix boundary check // if (x>buf->width | y>buf->height) // return 1; - buf->contents[y/4 * buf->width + x/2] |= 128>>y%4+x%2*4; + 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; } @@ -50,7 +51,7 @@ 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(buf->contents[y * buf->width + x]); + braillePrint(brailleReorganizeBits(buf->contents[y * buf->width + x])); } } } -- cgit v1.2.3 From c0b5e476f5cf98fae12d2b4c80ae9d907669f1e2 Mon Sep 17 00:00:00 2001 From: DrNuget Date: Sun, 2 Nov 2025 01:35:40 +0200 Subject: fix plotting to right coordinates --- brailleboi.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'brailleboi.c') diff --git a/brailleboi.c b/brailleboi.c index e47ca8b..58fecce 100644 --- a/brailleboi.c +++ b/brailleboi.c @@ -40,9 +40,7 @@ int braillePlot(int x, int y, image_buffer* buf) //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]); + buf->contents[(y-1)/4 * buf->width + (x-1)/2] |= 1<<(y-1)%4+(1-x%2)*4; return 0; } @@ -50,7 +48,7 @@ void brailleUpdateScreen(image_buffer* buf) { for (int x=0;xwidth;x++) { for (int y=0;yheight;y++) { - wprintf(L"\e[%d;%dH", y, x); + wprintf(L"\e[%d;%dH", y+1, x+1); braillePrint(brailleReorganizeBits(buf->contents[y * buf->width + x])); } } -- cgit v1.2.3 From 8afd5f50c068bd9a802496455a08c76433b3fd0d Mon Sep 17 00:00:00 2001 From: DrNuget Date: Sun, 2 Nov 2025 01:45:52 +0200 Subject: change width, height to braille character width, height. also fixes boundary checks --- brailleboi.c | 17 +++++++++-------- brailleboi.h | 1 + 2 files changed, 10 insertions(+), 8 deletions(-) (limited to 'brailleboi.c') diff --git a/brailleboi.c b/brailleboi.c index 58fecce..d28a7d1 100644 --- a/brailleboi.c +++ b/brailleboi.c @@ -8,9 +8,11 @@ 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; + 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; } @@ -37,19 +39,18 @@ void braillePrint(int 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-1)/4 * buf->width + (x-1)/2] |= 1<<(y-1)%4+(1-x%2)*4; + 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;xwidth;x++) { - for (int y=0;yheight;y++) { + 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->width + x])); + braillePrint(brailleReorganizeBits(buf->contents[y * buf->char_width + x])); } } } diff --git a/brailleboi.h b/brailleboi.h index 1138e09..f06d0da 100644 --- a/brailleboi.h +++ b/brailleboi.h @@ -3,6 +3,7 @@ typedef struct image_buffer { int width, height; + int char_width, char_height; int* contents; } image_buffer; -- cgit v1.2.3 From e3d7dfb83b06239c10e3e5b0f5dcd9e3b93925e8 Mon Sep 17 00:00:00 2001 From: DrNuget Date: Sun, 2 Nov 2025 01:51:45 +0200 Subject: turn code back to c99 compliant, change c standard back to c99 --- Makefile | 2 +- brailleboi.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'brailleboi.c') diff --git a/Makefile b/Makefile index d52f23b..8983dce 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ CC = gcc -CFLAGS = -std=c23 -Wpedantic +CFLAGS = -std=c99 -Wpedantic SRC = main.c brailleboi.c brailleboi.h diff --git a/brailleboi.c b/brailleboi.c index d28a7d1..7957d8b 100644 --- a/brailleboi.c +++ b/brailleboi.c @@ -25,9 +25,9 @@ int brailleStop(image_buffer* buf) 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; + int new = (old&0x87) | // 0b10000111 + (old&0x70)>>1 | // 0b01110000 + (old&0x08)<<3; // 0b00001000 return new; } -- cgit v1.2.3 From 016253c53f633379ac43d2552e1ba8c6f9180524 Mon Sep 17 00:00:00 2001 From: DrNuget Date: Sun, 2 Nov 2025 02:04:07 +0200 Subject: fix some parenthesis compiler warnings --- brailleboi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'brailleboi.c') diff --git a/brailleboi.c b/brailleboi.c index 7957d8b..82fbeeb 100644 --- a/brailleboi.c +++ b/brailleboi.c @@ -39,9 +39,9 @@ void braillePrint(int data) int braillePlot(int x, int y, image_buffer* buf) { //Check if plot is within bounds - if (x>buf->width | y>buf->height) + 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; + buf->contents[(y-1)/4 * buf->char_width + (x-1)/2] |= 1<<((y-1)%4+(1-x%2)*4); return 0; } -- cgit v1.2.3