ansilove

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

commit 3caaff64430945ae28c2164e6ade851fa0fbac93
parent cd59b9c316950290bb996ba701a5f3f42a03274e
Author: Frederic Cambus <fred@statdns.com>
Date:   Thu, 29 Jun 2017 10:08:04 +0200

Use defined palettes instead of hardcoding each color value in the loaders

Diffstat:
Msrc/loaders/ansi.c | 43++++++++++---------------------------------
Msrc/loaders/binary.c | 21+++++----------------
Msrc/loaders/xbin.c | 21+++++----------------
3 files changed, 20 insertions(+), 65 deletions(-)

diff --git a/src/loaders/ansi.c b/src/loaders/ansi.c @@ -446,44 +446,21 @@ void ansi(unsigned char *inputFileBuffer, int32_t inputFileSize, char *outputFil { gdImageFill(canvas, 0, 0, 0); - colors[0] = gdImageColorAllocate(canvas, 170, 170, 170); - colors[1] = gdImageColorAllocate(canvas, 0, 0, 0); - colors[2] = gdImageColorAllocate(canvas, 255, 255, 255); - colors[3] = gdImageColorAllocate(canvas, 102, 136, 187); - colors[4] = gdImageColorAllocate(canvas, 0, 0, 255); - colors[5] = gdImageColorAllocate(canvas, 255, 0, 255); - colors[6] = gdImageColorAllocate(canvas, 0, 255, 255); - colors[7] = gdImageColorAllocate(canvas, 255, 255, 255); - colors[8] = gdImageColorAllocate(canvas, 170, 170, 170); - colors[9] = gdImageColorAllocate(canvas, 0, 0, 0); - colors[10] = gdImageColorAllocate(canvas, 255, 255, 255); - colors[11] = gdImageColorAllocate(canvas, 102, 136, 187); - colors[12] = gdImageColorAllocate(canvas, 0, 0, 255); - colors[13] = gdImageColorAllocate(canvas, 255, 0, 255); - colors[14] = gdImageColorAllocate(canvas, 0, 255, 255); - colors[15] = gdImageColorAllocate(canvas, 255, 255, 255); + for (int i=0; i<16; i++) { + colors[i] = gdImageColorAllocate(canvas, workbench_palette[i*3], + workbench_palette[i*3+1], + workbench_palette[i*3+2]); + } } - else { // Allocate standard ANSi color palette - colors[0] = gdImageColorAllocate(canvas, 0, 0, 0); - colors[1] = gdImageColorAllocate(canvas, 170, 0, 0); - colors[2] = gdImageColorAllocate(canvas, 0, 170, 0); - colors[3] = gdImageColorAllocate(canvas, 170, 85, 0); - colors[4] = gdImageColorAllocate(canvas, 0, 0, 170); - colors[5] = gdImageColorAllocate(canvas, 170, 0, 170); - colors[6] = gdImageColorAllocate(canvas, 0, 170, 170); - colors[7] = gdImageColorAllocate(canvas, 170, 170, 170); - colors[8] = gdImageColorAllocate(canvas, 85, 85, 85); - colors[9] = gdImageColorAllocate(canvas, 255, 85, 85); - colors[10] = gdImageColorAllocate(canvas, 85, 255, 85); - colors[11] = gdImageColorAllocate(canvas, 255, 255, 85); - colors[12] = gdImageColorAllocate(canvas, 85, 85, 255); - colors[13] = gdImageColorAllocate(canvas, 255, 85, 255); - colors[14] = gdImageColorAllocate(canvas, 85, 255, 255); - colors[15] = gdImageColorAllocate(canvas, 255, 255, 255); + 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]); + } } // even more definitions, sigh diff --git a/src/loaders/binary.c b/src/loaders/binary.c @@ -43,22 +43,11 @@ void binary(unsigned char *inputFileBuffer, int32_t inputFileSize, char *outputF // allocate color palette int32_t colors[16]; - colors[0] = gdImageColorAllocate(canvas, 0, 0, 0); - colors[1] = gdImageColorAllocate(canvas, 0, 0, 170); - colors[2] = gdImageColorAllocate(canvas, 0, 170, 0); - colors[3] = gdImageColorAllocate(canvas, 0, 170, 170); - colors[4] = gdImageColorAllocate(canvas, 170, 0, 0); - colors[5] = gdImageColorAllocate(canvas, 170, 0, 170); - colors[6] = gdImageColorAllocate(canvas, 170, 85, 0); - colors[7] = gdImageColorAllocate(canvas, 170, 170, 170); - colors[8] = gdImageColorAllocate(canvas, 85, 85, 85); - colors[9] = gdImageColorAllocate(canvas, 85, 85, 255); - colors[10] = gdImageColorAllocate(canvas, 85, 255, 85); - colors[11] = gdImageColorAllocate(canvas, 85, 255, 255); - colors[12] = gdImageColorAllocate(canvas, 255, 85, 85); - colors[13] = gdImageColorAllocate(canvas, 255, 85, 255); - colors[14] = gdImageColorAllocate(canvas, 255, 255, 85); - colors[15] = gdImageColorAllocate(canvas, 255, 255, 255); + for (int i=0; i<16; i++) { + colors[i] = gdImageColorAllocate(canvas, binary_palette[i*3], + binary_palette[i*3+1], + binary_palette[i*3+2]); + } // process binary int32_t character, attribute, background, foreground; diff --git a/src/loaders/xbin.c b/src/loaders/xbin.c @@ -57,22 +57,11 @@ void xbin(unsigned char *inputFileBuffer, int32_t inputFileSize, char *outputFil offset += 48; } else { - colors[0] = gdImageColorAllocate(canvas, 0, 0, 0); - colors[1] = gdImageColorAllocate(canvas, 0, 0, 170); - colors[2] = gdImageColorAllocate(canvas, 0, 170, 0); - colors[3] = gdImageColorAllocate(canvas, 0, 170, 170); - colors[4] = gdImageColorAllocate(canvas, 170, 0, 0); - colors[5] = gdImageColorAllocate(canvas, 170, 0, 170); - colors[6] = gdImageColorAllocate(canvas, 170, 85, 0); - colors[7] = gdImageColorAllocate(canvas, 170, 170, 170); - colors[8] = gdImageColorAllocate(canvas, 85, 85, 85); - colors[9] = gdImageColorAllocate(canvas, 85, 85, 255); - colors[10] = gdImageColorAllocate(canvas, 85, 255, 85); - colors[11] = gdImageColorAllocate(canvas, 85, 255, 255); - colors[12] = gdImageColorAllocate(canvas, 255, 85, 85); - colors[13] = gdImageColorAllocate(canvas, 255, 85, 255); - colors[14] = gdImageColorAllocate(canvas, 255, 255, 85); - colors[15] = gdImageColorAllocate(canvas, 255, 255, 255); + for (int i=0; i<16; i++) { + colors[i] = gdImageColorAllocate(canvas, binary_palette[i*3], + binary_palette[i*3+1], + binary_palette[i*3+2]); + } } // font