aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jonas Gunz <himself@jonasgunz.de> 2019-07-12 13:22:25 +0200
committerGravatar Jonas Gunz <himself@jonasgunz.de> 2019-07-12 13:22:25 +0200
commit251daaa806397817a2a5e1779a06222c09c99296 (patch)
treeefb8da25ee581a2e1ac7007e98863a1e395682bb
parenta954555f2e1d13a8ff55ac12a9c0e6e162a4d313 (diff)
downloadAsciiMap-251daaa806397817a2a5e1779a06222c09c99296.tar.gz
Added whitespace mode
-rw-r--r--Readme.md1
-rw-r--r--src/color.c9
-rw-r--r--src/color.h1
-rw-r--r--src/main.c28
4 files changed, 31 insertions, 8 deletions
diff --git a/Readme.md b/Readme.md
index 97fd6d8..eea48ee 100644
--- a/Readme.md
+++ b/Readme.md
@@ -10,6 +10,7 @@ CMDline tool to Convert 24bit Windows BitMap files to ASCII with optional ANSI-c
* -i use STDIN as file input
+* -w to print whitespaces with background color instead of ASCII chars. Only useful with -c
To use with other image types, use imagemagick: `magick convert <image> -depth 24 bmp:- | asciimap -i`
License: MIT
diff --git a/src/color.c b/src/color.c
index d822d56..b4f4a40 100644
--- a/src/color.c
+++ b/src/color.c
@@ -72,3 +72,12 @@ char* calc_col_ansi(uint8_t R, uint8_t G, uint8_t B)
return c;
}
+char* calc_bg_col_ansi(uint8_t R, uint8_t G, uint8_t B)
+{
+ int num = 36 * (R/51) + 6 * (G/51) + (B/51);
+ char *c = malloc(9);
+ snprintf( c, 6, "48;5;" );
+ snprintf( c + 5, 4, "%i", num + 16 );
+
+ return c;
+}
diff --git a/src/color.h b/src/color.h
index 10d376e..83d10f7 100644
--- a/src/color.h
+++ b/src/color.h
@@ -30,4 +30,5 @@ char *calc_col(uint8_t R, uint8_t G, uint8_t B);
char *calc_col_ansi(uint8_t R, uint8_t G, uint8_t B);
+char *calc_bg_col_ansi(uint8_t R, uint8_t G, uint8_t B);
#endif //_COLOR_H_
diff --git a/src/main.c b/src/main.c
index a2cbe81..da30c28 100644
--- a/src/main.c
+++ b/src/main.c
@@ -26,6 +26,7 @@ struct prog_param
unsigned int charsize_y;
uint8_t color;
uint8_t use_stdin;
+ uint8_t use_whitespace;
};
struct prog_param parse_args(int argc, char *argv[]);
@@ -105,10 +106,16 @@ int main(int argc, char *argv[])
ascii_buff[x][y] = avg(args.charsize_x * args.charsize_y, *brightness);
if(args.color) {
- col_buff[x][y] = calc_col_ansi(
- (uint8_t)avg(args.charsize_x * args.charsize_y, cc[0]),
- (uint8_t)avg(args.charsize_x * args.charsize_y, cc[1]),
- (uint8_t)avg(args.charsize_x * args.charsize_y, cc[2]));
+ if(args.use_whitespace)
+ col_buff[x][y] = calc_bg_col_ansi(
+ (uint8_t)avg(args.charsize_x * args.charsize_y, cc[0]),
+ (uint8_t)avg(args.charsize_x * args.charsize_y, cc[1]),
+ (uint8_t)avg(args.charsize_x * args.charsize_y, cc[2]));
+ else
+ col_buff[x][y] = calc_col_ansi(
+ (uint8_t)avg(args.charsize_x * args.charsize_y, cc[0]),
+ (uint8_t)avg(args.charsize_x * args.charsize_y, cc[1]),
+ (uint8_t)avg(args.charsize_x * args.charsize_y, cc[2]));
}
if((uint8_t)ascii_buff[x][y] < b_min)
@@ -128,10 +135,12 @@ int main(int argc, char *argv[])
for(int x = 0; x < size_x; x++) {
if(args.color)
printf("\e[%sm", col_buff[x][y]);
-
- printf("%c", calc_char(ascii_buff[x][y], 0,255));//b_min, b_max));
+ if(args.use_whitespace)
+ printf(" ");
+ else
+ printf("%c", calc_char(ascii_buff[x][y], 0,255));//b_min, b_max));
}
- printf("\n");
+ printf("\e[0m\n");
}
if(args.color)
@@ -191,6 +200,9 @@ struct prog_param parse_args(int argc, char *argv[])
case 'i':
ret.use_stdin = 1;
break;
+ case 'w':
+ ret.use_whitespace = 1;
+ break;
default:
printf("Unrecognized Option '%c'\n", argv[icpy][o]);
print_help();
@@ -226,7 +238,7 @@ void print_help( void )
printf("ASCIIMap prints a ASCII representation of a bitmap image\n\nUsage: [OPTIONS] FILENAME\n");
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");
+ printf(" -i: Read from STDIN instead of file.\n -w: print only whitespaces with background color\n");
}