~evantj/imgtobraille

9cf50f02ac9069cd584488ea82a25c454c0711e0 — Evan Johnston 1 year, 1 month ago 6f6d1df master
represent pixels as uint8_t

It used to be bool[8], that was dumb.
3 files changed, 8 insertions(+), 16 deletions(-)

M braille.c
M color.c
M imgtobraille.h
M braille.c => braille.c +4 -10
@@ 17,13 17,9 @@ output_block(FILE *out, struct block cell)
{
	fprintf(out, "\033[38;2;%u;%u;%um", cell.color_a[R], cell.color_a[G], cell.color_a[B]);
	fprintf(out, "\033[48;2;%u;%u;%um", cell.color_b[R], cell.color_b[G], cell.color_b[B]);
	fputc('\xe2', out);
	fputc('\xa0' + (cell.pixels[7] << 1) + cell.pixels[6], out);
	char tmp = '\x80';
	for (int i = 0; i < 6; i++) {
		tmp += cell.pixels[i] << i;
	}
	fputc(tmp, out);
	fputc(0xe2, out);
	fputc(0xa0 | ((cell.pixels >> 6) & 0x03), out);
	fputc(0x80 | (cell.pixels & 0x3F), out);
}

struct block*


@@ 56,9 52,7 @@ image_to_blocks(uint8_t *image, int w, int h)
				}

			}
			for (int i = 0; i < 8; i++) {
				output[y * w + x].pixels[i] = true;
			}
			output[y * w + x].pixels = 0xFF;

			output[y * w + x] = two_tone(pixel_block);
		}

M color.c => color.c +3 -5
@@ 70,9 70,7 @@ get_split_value(uint8_t colors[24], enum axis split_axis)
void
reverse(struct block *cell)
{
	for (int i = 0; i < 8; i++) {
		cell->pixels[i] = !cell->pixels[i];
	}
	cell->pixels = ~cell->pixels;

	uint8_t tmp[3];
	for (int i = 0; i < 3; i++) {


@@ 101,13 99,13 @@ two_tone(uint8_t colors[24])
				color_a[n] += colors[i * 3 + n];
			}
			color_a_sums++;
			output.pixels[i] = true;
			output.pixels |= 1 << i;
		} else {
			for (int n = 0; n < 3; n++) {
				color_b[n] += colors[i * 3 + n];
			}
			color_b_sums++;
			output.pixels[i] = false;
			output.pixels &= ~(1 << i);
		}
	}


M imgtobraille.h => imgtobraille.h +1 -1
@@ 11,7 11,7 @@ enum axis {


struct block {
	bool pixels[8];
	uint8_t pixels;
	uint8_t color_a[3];
	uint8_t color_b[3];
};