From 28baa52191099820ed2d1d5a33a0d29e50d82033 Mon Sep 17 00:00:00 2001 From: Jonas Gunz Date: Tue, 12 May 2020 00:25:42 +0200 Subject: Added custom character palette --- src/character.c | 12 +++++++----- src/character.h | 8 +++++--- src/main.c | 22 ++++++++++------------ 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/character.c b/src/character.c index 658f0be..8a42370 100644 --- a/src/character.c +++ b/src/character.c @@ -1,10 +1,12 @@ #include "character.h" -const char character_luminance_map [] = {' ', ' ', '.', ',', '`', '-', '~', '"', '*', ':', ';', '<', '!', '/', '?', '%', '&', '=', '$', '#'}; -//const char map[] = {' ', '`', '.', ',', ':', ';', '\"', '+', '#', '@'}; +const char *default_character_map=" .,-~\"*:; +#include //Both maps produce very different results -const char character_luminance_map [] ; +const char *default_character_map; -//Select Char based on 1B brightness Value -char calc_char(uint8_t _c, uint8_t _min, uint8_t _max); +//Select Char based on 1B brightness Value. +//if _custom_map == NULL default map is used +char calc_char(uint8_t _c, uint8_t _min, uint8_t _max, char *_custom_map); #endif //_CHARACTER_H_ diff --git a/src/main.c b/src/main.c index 1ca92e1..267f08d 100644 --- a/src/main.c +++ b/src/main.c @@ -22,6 +22,7 @@ struct prog_param { char *filename; + char *character_map; unsigned int charsize_x; unsigned int charsize_y; uint8_t color; @@ -153,7 +154,7 @@ int main(int argc, char *argv[]) if(args.use_whitespace) printf(" "); else - printf("%c", calc_char(ascii_buff[x][y], b_min, b_max)); + printf("%c", calc_char(ascii_buff[x][y], b_min, b_max, args.character_map)); } printf("\e[0m\n"); } @@ -186,7 +187,6 @@ struct prog_param parse_args(int argc, char *argv[]) memset(&ret, 0, sizeof ret); - ret.filename = NULL; ret.charsize_x = CHAR_SIZE_X; for (int i = 1; i < argc; i++) { @@ -196,17 +196,13 @@ struct prog_param parse_args(int argc, char *argv[]) switch(argv[icpy][o]) { case 'h': print_help(); - exit(1); + exit(0); break; case 'x': - DEBUG_PRINTF("x\n"); - i++; - ret.charsize_x = atoi(argv[i]); + ret.charsize_x = atoi(argv[++i]); break; case 'y': - DEBUG_PRINTF("y\n"); - i++; - ret.charsize_y = atoi(argv[i]); + ret.charsize_y = atoi(argv[++i]); break; case 'c': ret.color = 1; @@ -218,12 +214,14 @@ struct prog_param parse_args(int argc, char *argv[]) ret.use_whitespace = 1; break; case 's': - i++; - ret.fit_width = atoi(argv[i]); + ret.fit_width = atoi(argv[++i]); break; case 'd': ret.dynamic_range = 1; break; + case 'm': + ret.character_map = argv[++i]; + break; default: printf("Unrecognized Option '%c'\n", argv[icpy][o]); print_help(); @@ -260,7 +258,7 @@ void print_help( void ) printf("Options:\n -h: Print this help message\n -x VAL: set the width of block wich makes up one character. Default: %i\n", CHAR_SIZE_X); printf(" -y VAL: set the height of block wich makes up one character. Default: 2*x\n -c: Print in ANSI color mode. Default: OFF\n"); printf(" -i: Read from STDIN instead of file.\n -w: print only whitespaces with background color\n"); - printf(" -d: Dynamic brightness range"); + printf(" -d: Dynamic brightness range\n -m PALETTE: specify custom character palette from darkest to brightest\n"); } -- cgit v1.2.3