aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/character.c12
-rw-r--r--src/character.h8
-rw-r--r--src/main.c22
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=" .,-~\"*:;<!/?%&=$#";
+//const char *default_character_map=" `.,:;/+#@";
-char calc_char(uint8_t _c , uint8_t _min, uint8_t _max)
+char calc_char(uint8_t _c , uint8_t _min, uint8_t _max, char *_custom_map)
{
- float c = (float)(_c) / (_max - _min);
- return character_luminance_map [(int)((sizeof(character_luminance_map)-1) * (c))];
+ const char *map = _custom_map == 0 ? default_character_map : _custom_map;
+
+ float c = (float)(_c) / (_max - _min);
+ return map [(int)( strlen( map ) * (c))];
}
diff --git a/src/character.h b/src/character.h
index 7e17cd7..be6af41 100644
--- a/src/character.h
+++ b/src/character.h
@@ -2,11 +2,13 @@
#define _CHARACTER_H_
#include <stdint.h>
+#include <string.h>
//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");
}