ansilove

ANSI and ASCII art to PNG converter in C
Log | Files | Refs | README | LICENSE

commit 0efa1921da368d16b19429bf0c6826016fbd881f
parent 3caaff64430945ae28c2164e6ade851fa0fbac93
Author: Frederic Cambus <fred@statdns.com>
Date:   Sun,  2 Jul 2017 17:12:18 +0200

Switch the PCBoard loader to use the ANSI color palette with a color mapping array

Diffstat:
Msrc/config.h | 9+++++++++
Msrc/loaders/pcboard.c | 29+++++++++--------------------
2 files changed, 18 insertions(+), 20 deletions(-)

diff --git a/src/config.h b/src/config.h @@ -36,4 +36,13 @@ static const uint8_t binary_palette[] = { 0xff, 0x55, 0x55, 0xff, 0x55, 0xff, 0xff, 0xff, 0x55, 0xff, 0xff, 0xff }; +static const uint8_t pcb_colors[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x04, 0x02, 0x06, 0x01, 0x05, 0x03, 0x07, 0x08, 0x0c, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x0e, 0x09, 0x0d, 0x0b, 0x0f +}; + #endif diff --git a/src/loaders/pcboard.c b/src/loaders/pcboard.c @@ -131,8 +131,8 @@ void pcboard(unsigned char *inputFileBuffer, int32_t inputFileSize, char *output // write current character in pcbChar structure pcboard_buffer[structIndex].column = column; pcboard_buffer[structIndex].row = row; - pcboard_buffer[structIndex].background = background; - pcboard_buffer[structIndex].foreground = foreground; + pcboard_buffer[structIndex].background = pcb_colors[background]; + pcboard_buffer[structIndex].foreground = pcb_colors[foreground]; pcboard_buffer[structIndex].current_character = current_character; column++; @@ -151,24 +151,13 @@ void pcboard(unsigned char *inputFileBuffer, int32_t inputFileSize, char *output gdImageFill(canvas, 0, 0, 0); // allocate color palette - int32_t colors[71]; - - colors[48] = gdImageColorAllocate(canvas, 0, 0, 0); - colors[49] = gdImageColorAllocate(canvas, 0, 0, 170); - colors[50] = gdImageColorAllocate(canvas, 0, 170, 0); - colors[51] = gdImageColorAllocate(canvas, 0, 170, 170); - colors[52] = gdImageColorAllocate(canvas, 170, 0, 0); - colors[53] = gdImageColorAllocate(canvas, 170, 0, 170); - colors[54] = gdImageColorAllocate(canvas, 170, 85, 0); - colors[55] = gdImageColorAllocate(canvas, 170, 170, 170); - colors[56] = gdImageColorAllocate(canvas, 85, 85, 85); - colors[57] = gdImageColorAllocate(canvas, 85, 85, 255); - colors[65] = gdImageColorAllocate(canvas, 85, 255, 85); - colors[66] = gdImageColorAllocate(canvas, 85, 255, 255); - colors[67] = gdImageColorAllocate(canvas, 255, 85, 85); - colors[68] = gdImageColorAllocate(canvas, 255, 85, 255); - colors[69] = gdImageColorAllocate(canvas, 255, 255, 85); - colors[70] = gdImageColorAllocate(canvas, 255, 255, 255); + int32_t colors[16]; + + for (int i=0; i<16; i++) { + colors[i] = gdImageColorAllocate(canvas, ansi_palette[i*3], + ansi_palette[i*3+1], + ansi_palette[i*3+2]); + } // the last value of loop tells us how many items are stored in there int32_t pcbBufferItems = structIndex;