diff options
author | jonas <himself@jonasgunz.de> | 2019-02-04 14:53:18 +0100 |
---|---|---|
committer | jonas <himself@jonasgunz.de> | 2019-02-04 14:53:18 +0100 |
commit | a00fe50633ea4b8bfbbf9af9a4a9b1f120dfde00 (patch) | |
tree | b064516cac40e55932c75bf807ef57bdd0803e46 | |
parent | 9d7f9525e89cb4e218c5bf5e529900fa6dc0fccc (diff) | |
download | AsciiMap-a00fe50633ea4b8bfbbf9af9a4a9b1f120dfde00.tar.gz |
Cleanups, addd rgb_avg
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | main.c | 37 |
2 files changed, 29 insertions, 12 deletions
@@ -4,6 +4,8 @@ LDFLAGS = OUTPUT = bitmap BUILDDIR = build +FILE = 02 + OBJ = main.o build: $(OBJ) @@ -29,4 +31,4 @@ clean: rm -Rdf $(BUILDDIR) run: build - @LD_LIBRARY_PATH=../lib/ $(BUILDDIR)/$(OUTPUT) a.bmp a.txt + $(BUILDDIR)/$(OUTPUT) $(FILE).bmp $(FILE).txt @@ -19,10 +19,10 @@ #define BI_CLR_USED 0x2e #define BI_CLR_IMPORTANT 0x32 -#define CHAR_SIZE_X 10 //How many pixels should form one ASCII char? +#define CHAR_SIZE_X 5 //How many pixels should form one ASCII char? #define CHAR_SIZE_Y (2 * CHAR_SIZE_X) -const char map[] = {' ', '.', ',', '-', '~', ':', ';', '!', '/','?', '%', '$', '#'}; +const char map[] = {' ', '.', ',', '-', '*', '~', ':', ';', '<', '!', '/','?', '%', '=', '$', '#'}; //Routine for flipping bytes uint32_t flip(unsigned char* _v, int _c); @@ -30,6 +30,10 @@ uint32_t flip(unsigned char* _v, int _c); //Calculate average char avg(int argc, char *argv); +//Calculate luminance from rgb_avg +//Order LSB first: BGR +char rgb_avg(uint32_t *arg); + //Select Char based on 1B brightness Value char calc_char(uint8_t _c); @@ -117,11 +121,11 @@ int main(int argc, char *argv[]) //Read to start of Pixel block //This block contains Colormasks and Colortables. //Unused - uint32_t d = bfOffBits - read_counter; - tables = malloc(sizeof(char)* d); - fread(tables, sizeof(char), d, bitmap); - read_counter += d; - printf("Read to %x\n", read_counter); + uint32_t haeder_end = bfOffBits - read_counter; + tables = malloc(sizeof(char)* haeder_end); + fread(tables, sizeof(char), haeder_end, bitmap); + read_counter += haeder_end; + printf("Data starts at %x\n", read_counter); //One pixel is 3Byte, One line is multiple of 4Bytes uint32_t row_size = biWidth * 3; @@ -174,11 +178,12 @@ int main(int argc, char *argv[]) for(int c = 0; c < CHAR_SIZE_X; c++) { int col = x * CHAR_SIZE_X + c; - b[c][r] = avg(3, (char*)&bitmap_buff[row][col]); + //b[c][r] = avg(3, (char*)&bitmap_buff[row][col]); + b[c][r] = rgb_avg(&bitmap_buff[row][col]); } } - ascii_buff[x][y] = calc_char(avg(CHAR_SIZE_X * CHAR_SIZE_Y, &b)); + ascii_buff[x][y] = calc_char( avg(CHAR_SIZE_X * CHAR_SIZE_Y, (char*)&b) ); } } @@ -242,10 +247,20 @@ char avg(int argc, char *argv) ret = (char)(sum / argc); return ret; -}//flip +}//avg char calc_char(uint8_t _c) { float c = (float)(_c) / 255.0; - return map [(int)(sizeof(map) * c)]; + return map [(int)((sizeof(map)-1) * c) ]; +} + +char rgb_avg(uint32_t *arg) +{ + char ret; + uint32_t R = (*arg & 0xff0000)>>16;; + uint32_t G = (*arg & 0xff00)>>8; + uint32_t B = *arg & 0xff; + ret = (char)(R+R+B+G+G+G)/6; + return ret; } |