diff options
-rw-r--r-- | src/character.c | 11 | ||||
-rw-r--r-- | src/character.h | 7 | ||||
-rw-r--r-- | src/color.c | 40 | ||||
-rw-r--r-- | src/color.h | 29 | ||||
-rw-r--r-- | src/main.c | 2 |
5 files changed, 18 insertions, 71 deletions
diff --git a/src/character.c b/src/character.c index 8a42370..5aa2e92 100644 --- a/src/character.c +++ b/src/character.c @@ -10,3 +10,14 @@ char calc_char(uint8_t _c , uint8_t _min, uint8_t _max, char *_custom_map) float c = (float)(_c) / (_max - _min); return map [(int)( strlen( map ) * (c))]; } + +char* calc_col_ansi(uint8_t R, uint8_t G, uint8_t B, uint8_t _mode) +{ + int mode = _mode == COLOR_BG ? 4 : 3; + int num = 36 * (R/51) + 6 * (G/51) + (B/51); + char *c = malloc(12); + snprintf( c, 8, "\e[%i8;5;", mode ); + snprintf( c + 7, 5, "%im", num + 16 ); + + return c; +} diff --git a/src/character.h b/src/character.h index b5ea368..0afdf0d 100644 --- a/src/character.h +++ b/src/character.h @@ -2,8 +2,13 @@ #define _CHARACTER_H_ #include <stdint.h> +#include <stdio.h> +#include <stdlib.h> #include <string.h> +#define COLOR_FG 1 +#define COLOR_BG 2 + //Both maps produce very different results extern const char *default_character_map; @@ -11,4 +16,6 @@ extern const char *default_character_map; //if _custom_map == NULL default map is used char calc_char(uint8_t _c, uint8_t _min, uint8_t _max, char *_custom_map); +char *calc_col_ansi(uint8_t R, uint8_t G, uint8_t B, uint8_t _mode); + #endif //_CHARACTER_H_ diff --git a/src/color.c b/src/color.c deleted file mode 100644 index 10afeea..0000000 --- a/src/color.c +++ /dev/null @@ -1,40 +0,0 @@ -#include "color.h" - -struct console_color colors[] = { //Standard VGA colors - {0, 0, 0, "30"}, //Black - {170, 0, 0, "31"}, //red - {0, 170, 0, "32"}, //Green - {170, 85, 0, "33"}, //Brown - {0, 0, 170, "34"}, //blue - {170, 0, 170, "35"}, //Magenta - {0, 170, 170, "36"}, //Cyan - {170,170,170, "37"}, //Grey - {85,85,85, "30;1"}, - {255,85,85, "31;1"}, - {85,255,85, "32;1"}, - {255,255,85, "33;1"}, - {85,85,255, "34;1"}, - {255,85,255, "35;1"}, - {85,255,255, "36;1"}, - {255, 255, 255, "37;1"} -}; - -uint8_t rgb_luminance(uint8_t R, uint8_t G, uint8_t B) -{ - uint8_t ret; - - ret = sqrt( 0.299*pow(R,2) + 0.587*pow(G,2) + 0.114*pow(B,2) ); //(char)(R+R+B+G+G+G)/6; - - return ret; -} - -char* calc_col_ansi(uint8_t R, uint8_t G, uint8_t B, uint8_t _mode) -{ - int mode = _mode == COLOR_BG ? 4 : 3; - int num = 36 * (R/51) + 6 * (G/51) + (B/51); - char *c = malloc(12); - snprintf( c, 8, "\e[%i8;5;", mode ); - snprintf( c + 7, 5, "%im", num + 16 ); - - return c; -} diff --git a/src/color.h b/src/color.h deleted file mode 100644 index ffe1916..0000000 --- a/src/color.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef _COLOR_H_ -#define _COLOR_H_ - -#include <stdint.h> -#include <math.h> -#include <stdio.h> -#include <stdlib.h> - -#define _COLORS_SIZE 16u -#define COLOR_FG 1 -#define COLOR_BG 2 - -struct console_color -{ - uint8_t R; - uint8_t G; - uint8_t B; - - char *no; -}; - -extern struct console_color colors[ _COLORS_SIZE ]; - -//Calculate luminance -//Order LSB first: BGR -uint8_t rgb_luminance(uint8_t R, uint8_t G, uint8_t B); - -char *calc_col_ansi(uint8_t R, uint8_t G, uint8_t B, uint8_t _mode); -#endif //_COLOR_H_ @@ -12,7 +12,6 @@ #include "bitmap.h" #include "character.h" -#include "color.h" #ifdef _DEBUG #warning "Compiling with DEBUG" @@ -187,4 +186,3 @@ void print_help( void ) printf(" -d: Dynamic brightness range\n -m PALETTE: specify custom character palette from darkest to brightest\n"); } - |