aboutsummaryrefslogtreecommitdiff
path: root/brailleboi.c
diff options
context:
space:
mode:
authorDrNuget <drnuget@outlook.com>2025-11-02 01:45:52 +0200
committerDrNuget <drnuget@outlook.com>2025-11-02 01:45:52 +0200
commit8afd5f50c068bd9a802496455a08c76433b3fd0d (patch)
tree3b8b1e7aa0315d7110f89734cd5cd20c037ae887 /brailleboi.c
parentc0b5e476f5cf98fae12d2b4c80ae9d907669f1e2 (diff)
downloadbrailleboi-8afd5f50c068bd9a802496455a08c76433b3fd0d.tar.gz
change width, height to braille character width, height. also fixes boundary checks
Diffstat (limited to 'brailleboi.c')
-rw-r--r--brailleboi.c17
1 files changed, 9 insertions, 8 deletions
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;x<buf->width;x++) {
- for (int y=0;y<buf->height;y++) {
+ for (int x=0;x<buf->char_width;x++) {
+ for (int y=0;y<buf->char_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]));
}
}
}