aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDrNuget <drnuget@outlook.com>2025-11-02 02:06:32 +0200
committerDrNuget <drnuget@outlook.com>2025-11-02 02:06:32 +0200
commit715eccf5d8e937a156190bbb03a93562c59618c5 (patch)
tree2c44b1e90f09941ad01f3273c33a47dc35206aad
parent98effe2f3d51dce1f0314e9bfff5082e61ab7ae8 (diff)
parent016253c53f633379ac43d2552e1ba8c6f9180524 (diff)
downloadbrailleboi-715eccf5d8e937a156190bbb03a93562c59618c5.tar.gz
Merge branch 'dev'v0.1.0
-rw-r--r--Makefile2
-rw-r--r--brailleboi.c30
-rw-r--r--brailleboi.h5
3 files changed, 32 insertions, 5 deletions
diff --git a/Makefile b/Makefile
index d52f23b..ad60240 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
CC = gcc
-CFLAGS = -std=c23 -Wpedantic
+CFLAGS = -std=c99 -Wall -Wpedantic
SRC = main.c brailleboi.c brailleboi.h
diff --git a/brailleboi.c b/brailleboi.c
index e04d17c..82fbeeb 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;
}
@@ -22,9 +24,10 @@ int brailleStop(image_buffer* buf)
int brailleReorganizeBits(int old)
{
- int new = (old&0b10000111) |
- (old&0b01110000)>>1 |
- (old&0b00001000)<<3;
+ //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;
}
@@ -32,3 +35,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-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->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->char_width + x]));
+ }
+ }
+}
diff --git a/brailleboi.h b/brailleboi.h
index f909181..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;
@@ -14,4 +15,8 @@ int brailleReorganizeBits(int old);
void braillePrint(int data);
+int braillePlot(int x, int y, image_buffer* buf);
+
+void brailleUpdateScreen(image_buffer* buf);
+
#endif