From 566557eab39b8b3c1d5c2f5cb7af852bf2e1f6c5 Mon Sep 17 00:00:00 2001 From: Scott Allen Date: Thu, 2 Jul 2020 16:10:36 -0400 Subject: [PATCH] Delete trailing whitespace in cabi.c --- extras/cabi/cabi.c | 92 +++++++++++++++++++++++----------------------- 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/extras/cabi/cabi.c b/extras/cabi/cabi.c index faed6ae..ae88575 100644 --- a/extras/cabi/cabi.c +++ b/extras/cabi/cabi.c @@ -44,12 +44,12 @@ void draw_sprite_ascii(const uint8_t *dat, unsigned w, unsigned h) { unsigned x, y; unsigned row, bit; - + for (y = 0; y < h; y ++) { row = y/8; bit = y&7; - + for (x = 0; x < w; x++) { if (dat[x + (row*w)] & (1 << bit)) @@ -111,33 +111,33 @@ void draw_compressed_sprite_ascii(const uint8_t *src) unsigned w, h; unsigned x, y; unsigned total = 0; - + memset(&cs, 0, sizeof(cs)); cs.src = src; cs.bit = 0x100; cs.src_pos = 0; - + // header - + w = getval(8) + 1; h = getval(8) + 1; col = getval(1); // starting colour - + x = y = 0; - + while (y < h) { bl = 1; while (!getval(1)) bl += 2; - + len = getval(bl)+1; // span length - + for (i = 0; i < len; i++) { //if ((x%8) == 0) // every 8th bit (format test) printf("%s", col ? "#":"."); - + if (col) total++; x++; if (x >= w) @@ -146,11 +146,11 @@ void draw_compressed_sprite_ascii(const uint8_t *src) y ++; x = 0; } - + //if ((x+y*w)%(w*8) == 0) printf("\n"); // print every 8th line (format test) - + } - + col = 1-col; // toggle } printf("\ntotal: %u\n", total); @@ -164,13 +164,13 @@ void draw_compressed_sprite_ascii(const uint8_t *src) /* getcol - + pos is the index of the pixel: 0 .. w*h-1 */ static unsigned getcol(unsigned pos) { unsigned x, y; - + // display order if (reading_order == 0) @@ -178,7 +178,7 @@ static unsigned getcol(unsigned pos) if (cs.src[pos/8] & (1 << (pos&7))) return 1; return 0; } - + // reading order (compresses slightly better but harder to optimize sprite blit) // or use this after loading png into display order (no need for extra conversion) @@ -189,17 +189,17 @@ static unsigned getcol(unsigned pos) } -static unsigned find_rlen(unsigned pos, unsigned plen) +static unsigned find_rlen(unsigned pos, unsigned plen) { unsigned col; unsigned pos0; - + col = getcol(pos); pos0 = pos; while(getcol(pos) == col && pos < plen) pos ++; - + return pos-pos0; } @@ -214,11 +214,11 @@ static void putbit(unsigned val) if (cs.out_pos != 0) printf(","); if (cs.out_pos % 16 == 0) printf("\n"); printf("0x%02x", cs.byte); - + cs.out_pos ++; cs.bit = 0x1; cs.byte = 0; - + } } @@ -226,7 +226,7 @@ static void putbit(unsigned val) static void putval(unsigned val, unsigned bits) { unsigned i; - + if (bits <= 0) return; for (i = 0; i < bits; i++) putbit(val & (1 << i)); @@ -250,46 +250,46 @@ static void putsplen(unsigned len) /* comp - + compress plen 1-bit pixels from src to dest - + */ unsigned compress_rle(const uint8_t *src, unsigned w, unsigned h, char *prefix, char *suffix) { unsigned pos; unsigned rlen; - + printf("const PROGMEM uint8_t %s%s[] = {", prefix, suffix); fflush(stdout); - + memset(&cs, 0, sizeof(cs)); cs.src = src; cs.bit = 1; cs.w = w; cs.h = h; - + // header putval(w-1, 8); putval(h-1, 8); putval(getcol(0), 1); // first colour - + pos = 0; - + // span data - + while (pos < w*h) { rlen = find_rlen(pos, w*h); pos += rlen; putsplen(rlen-1); } - + // pad with zeros and flush while (cs.bit != 0x1) putbit(0); - + printf("\n};\n"); - + return cs.out_pos; // bytes } @@ -308,8 +308,8 @@ int main(int argc, char **argv) unsigned row, bit; char default_prefix[] = "compressed_image"; char *prefix = default_prefix; - - + + if (argc < 2) { printf("cabi - Compress Arduboy Image\n"); @@ -323,24 +323,24 @@ int main(int argc, char **argv) if (argc >= 3) { prefix = argv[2]; } - + result = lodepng_decode32_file(&bmp, &w, &h, argv[1]); - + if (result != 0) { printf("error %u: file %s: %s\n", result, argv[1], lodepng_error_text(result)); free(bmp); exit(result); } - + // generate sprite and mask - + rawlen = w * (h+7) / 8; - + bmp0 = malloc(rawlen); memset(bmp0, 0, rawlen); bmp1 = malloc(rawlen); memset(bmp1, 0, rawlen); - + printf("// %s width: %u height: %u\n", argv[1], w, h); - + for (y = 0; y < h; y++) { for (x = 0; x < w; x++) @@ -360,20 +360,20 @@ int main(int argc, char **argv) // set mask bmp1[x + (row*w)] |= (1 << bit); } - + } } - + compressed_len = compress_rle(bmp0, w, h, prefix, ""); printf("// bytes:%u ratio: %3.3f\n\n", compressed_len, (float)(compressed_len * 8)/ (float)(w*h)); compressed_len = compress_rle(bmp1, w, h, prefix, "_mask"); printf("// bytes:%u ratio: %3.3f\n\n", compressed_len, (float)(compressed_len * 8)/ (float)(w*h)); - + free(bmp); free(bmp0); free(bmp1); - + return 0; }