[v0.99] Add color manually to ascii with replace=true and change the printing algorithm to support this new format

This commit is contained in:
Dr-Noob
2021-08-10 10:32:08 +02:00
parent 6a67b87abc
commit 7cd578b889
2 changed files with 108 additions and 78 deletions

View File

@@ -36,12 +36,20 @@ struct ascii_logo {
* the color in ascii_logo->color_ascii[N] * the color in ascii_logo->color_ascii[N]
* CR: Color reset, gets replaced by the reset * CR: Color reset, gets replaced by the reset
* color by printer.c * color by printer.c
* Logos with replace_blocks are replaced by character *
* Logos with replace_blocks=true are replaced by character
* blocks (actually, spaces with background color), so * blocks (actually, spaces with background color), so
* the color in the structure must be COLOR_BG_XXX. When * the color in the structure must be COLOR_BG_XXX. When
* replace_blocks is true, the characters '#' are replaced * replace_blocks is true, the characters '#' are replaced
* by spaces printed with color_ascii[0], and '@' are * by spaces printed with color_ascii[0], and '@' are
* printed with color_ascii[1] * printed with color_ascii[1]. If replace_blocks=true,
* color format specified in ASCIIs ($C1, $C2) are ignored.
*
* In any case, '$' is a illegal character to be used in
* the ascii logos because it is used to parse colors
*
* LONG_LOGOS will be printed only if the fit in the screen,
* otherwise SHORT_LOGOS will be used
*/ */
// SHORT LOGOS // // SHORT LOGOS //
@@ -162,87 +170,87 @@ $C1 ###### ## ### ### ## ### "
// jp2a --height=17 ibm.jpg // jp2a --height=17 ibm.jpg
#define ASCII_IBM \ #define ASCII_IBM \
"######### ################ ######### ######### \ "$C1######### ################ ######### ######### \
\ $C1 \
######### ################## ########## ########## \ $C1######### ################## ########## ########## \
\ $C1 \
##### ###### ###### #################### \ $C1 ##### ###### ###### #################### \
\ $C1 \
##### ############## #################### \ $C1 ##### ############## #################### \
\ $C1 \
##### ###### ###### ##### ###### ##### \ $C1 ##### ###### ###### ##### ###### ##### \
\ $C1 \
######### ################## ######## #### ######## \ $C1######### ################## ######## #### ######## \
\ $C1 \
######### ################ ######## ## ######## " $C1######### ################ ######## ## ######## "
// --------------------- LONG LOGOS ------------------------- // // --------------------- LONG LOGOS ------------------------- //
#define ASCII_AMD_L \ #define ASCII_AMD_L \
" \ "$C1 \
\ $C1 \
\ $C1 \
\ $C1 \
\ $C1 \
\ $C1 \
@@@@ @@@ @@@ @@@@@@@@ ############ \ $C1 @@@@ @@@ @@@ @@@@@@@@ $C2 ############ \
@@@@@@ @@@@@ @@@@@ @@@ @@@ ########## \ $C1 @@@@@@ @@@@@ @@@@@ @@@ @@@ $C2 ########## \
@@@ @@@ @@@@@@@@@@@@@ @@@ @@ # ##### \ $C1 @@@ @@@ @@@@@@@@@@@@@ @@@ @@ $C2 # ##### \
@@@ @@@ @@@ @@@ @@@ @@@ @@ ### ##### \ $C1 @@@ @@@ @@@ @@@ @@@ @@@ @@ $C2 ### ##### \
@@@@@@@@@@@@ @@@ @@@ @@@ @@@ ######### ### \ $C1 @@@@@@@@@@@@ @@@ @@@ @@@ @@@ $C2######### ### \
@@@ @@@ @@@ @@@ @@@@@@@@@ ######## ## \ $C1 @@@ @@@ @@@ @@@ @@@@@@@@@ $C2######## ## \
\ $C1 \
\ $C1 \
\ $C1 \
\ $C1 \
\ $C1 \
\ $C1 \
" $C1 "
#define ASCII_INTEL_L \ #define ASCII_INTEL_L \
" ###############@ \ "$C1 ###############@ \
######@ ######@ \ $C1 ######@ ######@ \
###@ ###@ \ $C1 ###@ ###@ \
##@ ###@ \ $C1 ##@ ###@ \
##@ ##@ \ $C1 ##@ ##@ \
##@ ##@ \ $C1 ##@ ##@ \
@ ##@ ##@ ##@ \ $C1 @ ##@ ##@ ##@ \
#@ ##@ ########@ #####@ #####@ ##@ ##@ \ $C1 #@ ##@ ########@ #####@ #####@ ##@ ##@ \
#@ ##@ ##@ ##@ ##@ ###@ ###@ ##@ ##@ \ $C1 #@ ##@ ##@ ##@ ##@ ###@ ###@ ##@ ##@ \
#@ ##@ ##@ ##@ ##@ ##@ ##@ ##@ ##@ \ $C1 #@ ##@ ##@ ##@ ##@ ##@ ##@ ##@ ##@ \
#@ ##@ ##@ ##@ ##@ #########@ ##@ ###@ \ $C1 #@ ##@ ##@ ##@ ##@ #########@ ##@ ###@ \
#@ ##@ ##@ ##@ ##@ ##@ ##@ ####@ \ $C1 #@ ##@ ##@ ##@ ##@ ##@ ##@ ####@ \
#@ #@ ##@ ##@ ####@ ########@ #@ ##@ \ $C1 #@ #@ ##@ ##@ ####@ ########@ #@ ##@ \
##@ \ $C1 ##@ \
##@ \ $C1 ##@ \
###@ ###@ \ $C1 ###@ ###@ \
####@ #########@ \ $C1 ####@ #########@ \
#########@ ###############@ \ $C1 #########@ ###############@ \
##############################@ " $C1 ##############################@ "
#define ASCII_ARM_L \ #define ASCII_ARM_L \
" ############ ########## #### ###### ######## \ "$C1 ############ ########## #### ###### ######## \
############### ######### ####################### \ $C1 ############### ######### ####################### \
#### #### #### ##### ####### ##### \ $C1 #### #### #### ##### ####### ##### \
#### #### #### #### ##### #### \ $C1#### #### #### #### ##### #### \
#### #### #### #### #### #### \ $C1#### #### #### #### #### #### \
#### ##### #### #### #### #### \ $C1 #### ##### #### #### #### #### \
############### #### #### #### #### \ $C1 ############### #### #### #### #### \
######## #### #### #### #### #### " $C1 ######## #### #### #### #### #### "
#define ASCII_IBM_L \ #define ASCII_IBM_L \
" ############ ################ ########## ########## \ "$C1 ############ ################ ########## ########## \
\ $C1 \
############ ################## ############ ############ \ $C1 ############ ################## ############ ############ \
\ $C1 \
###### ###### ###### #################### \ $C1 ###### ###### ###### #################### \
\ $C1 \
###### ############## #################### \ $C1 ###### ############## #################### \
\ $C1 \
###### ###### ###### ##### ###### ##### \ $C1 ###### ###### ###### ##### ###### ##### \
\ $C1 \
############ ################## ######### #### ######### \ $C1 ############ ################## ######### #### ######### \
\ $C1 \
############ ################ ######### ## ######### " $C1 ############ ################ ######### ## ######### "
typedef struct ascii_logo asciiL; typedef struct ascii_logo asciiL;

View File

@@ -204,6 +204,25 @@ bool ascii_fits_screen(int termw, struct ascii_logo logo, int lf) {
return termw - ((int) logo.width + lf) >= 0; return termw - ((int) logo.width + lf) >= 0;
} }
// TODO: Instead of using a function to do so, change ascii.h
// and store an color ID that is converted to BG or FG depending
// on logo->replace_blocks
void replace_bgbyfg_color(struct ascii_logo* logo) {
// Replace background by foreground color
for(int i=0; i < 2; i++) {
if(logo->color_ascii[i] == NULL) break;
if(strcmp(logo->color_ascii[i], COLOR_BG_BLACK) == 0) strcpy(logo->color_ascii[i], COLOR_FG_BLACK);
else if(strcmp(logo->color_ascii[i], COLOR_BG_RED) == 0) strcpy(logo->color_ascii[i], COLOR_FG_RED);
else if(strcmp(logo->color_ascii[i], COLOR_BG_GREEN) == 0) strcpy(logo->color_ascii[i], COLOR_FG_GREEN);
else if(strcmp(logo->color_ascii[i], COLOR_BG_YELLOW) == 0) strcpy(logo->color_ascii[i], COLOR_FG_YELLOW);
else if(strcmp(logo->color_ascii[i], COLOR_BG_BLUE) == 0) strcpy(logo->color_ascii[i], COLOR_FG_BLUE);
else if(strcmp(logo->color_ascii[i], COLOR_BG_MAGENTA) == 0) strcpy(logo->color_ascii[i], COLOR_FG_MAGENTA);
else if(strcmp(logo->color_ascii[i], COLOR_BG_CYAN) == 0) strcpy(logo->color_ascii[i], COLOR_FG_CYAN);
else if(strcmp(logo->color_ascii[i], COLOR_BG_WHITE) == 0) strcpy(logo->color_ascii[i], COLOR_FG_WHITE);
}
}
void choose_ascii_art(struct ascii* art, struct color** cs, struct terminal* term, int lf) { void choose_ascii_art(struct ascii* art, struct color** cs, struct terminal* term, int lf) {
// 1. Choose logo // 1. Choose logo
#ifdef ARCH_X86 #ifdef ARCH_X86
@@ -260,6 +279,7 @@ void choose_ascii_art(struct ascii* art, struct color** cs, struct terminal* ter
break; break;
case STYLE_RETRO: case STYLE_RETRO:
logo->replace_blocks = false; logo->replace_blocks = false;
replace_bgbyfg_color(logo);
// fall through // fall through
case STYLE_FANCY: case STYLE_FANCY:
if(cs != NULL) { if(cs != NULL) {
@@ -323,8 +343,9 @@ void print_ascii_generic(struct ascii* art, uint32_t la) {
// 1. Print logo // 1. Print logo
if(space_up > 0 || (space_up + n >= 0 && space_up + n < (int)logo->height)) { if(space_up > 0 || (space_up + n >= 0 && space_up + n < (int)logo->height)) {
for(uint32_t i=0; i < logo->width; i++) { for(uint32_t i=0; i < logo->width; i++) {
if(logo->art[logo_pos] == '$' || logo->art[logo_pos] == '\x1b') { if(logo->art[logo_pos] == '$') {
parse_print_color(art, &logo_pos); if(logo->replace_blocks) logo_pos += 3;
else parse_print_color(art, &logo_pos);
} }
if(logo->replace_blocks && logo->art[logo_pos] != ' ') { if(logo->replace_blocks && logo->art[logo_pos] != ' ') {
if(logo->art[logo_pos] == '#') printf("%s%c%s", logo->color_ascii[0], ' ', art->reset); if(logo->art[logo_pos] == '#') printf("%s%c%s", logo->color_ascii[0], ' ', art->reset);
@@ -521,8 +542,9 @@ void print_ascii_arm(struct ascii* art, uint32_t la) {
// 1. Print logo // 1. Print logo
if(n >= (int) art->additional_spaces && n < (int) logo->height + (int) art->additional_spaces) { if(n >= (int) art->additional_spaces && n < (int) logo->height + (int) art->additional_spaces) {
for(uint32_t i=0; i < logo->width; i++) { for(uint32_t i=0; i < logo->width; i++) {
if(logo->art[logo_pos] == '$' && logo->art[logo_pos+1] == 'C') { if(logo->art[logo_pos] == '$') {
parse_print_color(art, &logo_pos); if(logo->replace_blocks) logo_pos += 3;
else parse_print_color(art, &logo_pos);
} }
if(logo->replace_blocks && logo->art[logo_pos] != ' ') { if(logo->replace_blocks && logo->art[logo_pos] != ' ') {
if(logo->art[logo_pos] == '#') printf("%s%c%s", logo->color_ascii[0], ' ', art->reset); if(logo->art[logo_pos] == '#') printf("%s%c%s", logo->color_ascii[0], ' ', art->reset);