aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Jonas Gunz <himself@jonasgunz.de> 2020-05-12 00:25:42 +0200
committerGravatar Jonas Gunz <himself@jonasgunz.de> 2020-05-12 00:25:42 +0200
commit28baa52191099820ed2d1d5a33a0d29e50d82033 (patch)
tree5dd899ef4bc2d557e906e2f33c0a9808cf110760 /src
parent44cecf8d0b792c69cdfc398761d2ad27b05a122e (diff)
downloadAsciiMap-28baa52191099820ed2d1d5a33a0d29e50d82033.tar.gz
Added custom character palette
Diffstat (limited to 'src')
-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");
}