aboutsummaryrefslogtreecommitdiff
path: root/brailleboi.c
blob: 9bc6b8b86ea7e9b1ad71f2d3d24d015f77bbdb66 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <stdlib.h>
#include <stdio.h>
#include <wchar.h>
#include <locale.h>

#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
	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;x<buf->width;x++) {
		for (int y=0;y<buf->height;y++) {
			printf("\e[%d;%dH", y, x);
			braillePrint(buf->contents[y * buf->width + x]);
		}
	}
}