ansilove

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

commit 838979e8afabc3a56aa0b269c8b3bff9a8d8cc83
parent 8c45f18378deb4dc1bb4fc8ff4ccb631a101e779
Author: ByteProject <stefan.vogt@byteproject.net>
Date:   Tue, 13 Mar 2012 20:33:15 +0100

Merge branch 'master' of github.com:ByteProject/AnsiLove-C

Diffstat:
Mansilove/ansilove.c | 85+++++++++++++++++++++++++++++++++++++------------------------------------------
1 file changed, 40 insertions(+), 45 deletions(-)

diff --git a/ansilove/ansilove.c b/ansilove/ansilove.c @@ -236,8 +236,9 @@ void alAnsiLoader(char *input, char output[], char font[], char bits[], char ice workbench = true; transparent = true; } + // force defaults if necessary - else if ((strcmp(bits, "8") != 0 && strcmp(bits, "9") != 0) || isAmigaFont == true) { + if ((strcmp(bits, "8") != 0 && strcmp(bits, "9") != 0) || isAmigaFont == true) { sprintf(bits, "%s", "8"); } @@ -299,29 +300,6 @@ void alAnsiLoader(char *input, char output[], char font[], char bits[], char ice // Allocate font image buffer im_Font = gdImageCreate(font_size_x*256,font_size_y*16); - - // Allocate ANSi colors - int32_t colors[21]; - - colors[0] = gdImageColorAllocate(im_Font, 0, 0, 0); - colors[1] = gdImageColorAllocate(im_Font, 170, 0, 0); - colors[2] = gdImageColorAllocate(im_Font, 0, 170, 0); - colors[3] = gdImageColorAllocate(im_Font, 170, 85, 0); - colors[4] = gdImageColorAllocate(im_Font, 0, 0, 170); - colors[5] = gdImageColorAllocate(im_Font, 170, 0, 170); - colors[6] = gdImageColorAllocate(im_Font, 0, 170, 170); - colors[7] = gdImageColorAllocate(im_Font, 170, 170, 170); - colors[8] = gdImageColorAllocate(im_Font, 85, 85, 85); - colors[9] = gdImageColorAllocate(im_Font, 255, 85, 85); - colors[10] = gdImageColorAllocate(im_Font, 85, 255, 85); - colors[11] = gdImageColorAllocate(im_Font, 255, 255, 85); - colors[12] = gdImageColorAllocate(im_Font, 85, 85, 255); - colors[13] = gdImageColorAllocate(im_Font, 255, 85, 255); - colors[14] = gdImageColorAllocate(im_Font, 85, 255, 255); - colors[15] = gdImageColorAllocate(im_Font, 255, 255, 255); - colors[20] = gdImageColorAllocate(im_Font, 200, 220, 169); - - gdImagePaletteCopy(im_Backgrnd, im_Font); // set transparent color index for the font gdImageColorTransparent(im_Font, 20); @@ -702,7 +680,7 @@ void alAnsiLoader(char *input, char output[], char font[], char bits[], char ice if (isDizFile == true) { columns = MIN(position_x_max,80); } - + // create that damn thingy im_ANSi = gdImageCreate(columns * int_bits,(position_y_max)*font_size_y); @@ -710,6 +688,8 @@ void alAnsiLoader(char *input, char output[], char font[], char bits[], char ice fputs ("\nCan't allocate ANSi buffer image memory.\n\n", stderr); exit (6); } + int32_t colors[21]; + if (ced == true) { // get ced colors from configuration @@ -728,8 +708,11 @@ void alAnsiLoader(char *input, char output[], char font[], char bits[], char ice cedForegroundColor[i] = atoi(cedForegroundArray[i]); } - gdImageColorAllocate(im_ANSi, cedBackgroundColor[0], cedBackgroundColor[1], cedBackgroundColor[2]); - + for (loop=0; loop<16; loop++) + { + colors[loop]=gdImageColorAllocate(im_ANSi, cedBackgroundColor[0], cedBackgroundColor[1], cedBackgroundColor[2]); + } + int32_t ced_color; ced_color = gdImageColorAllocate(im_ANSi, cedBackgroundColor[0], cedBackgroundColor[1], cedBackgroundColor[2]); ced_color = gdImageColorAllocate(im_Backgrnd, cedBackgroundColor[0], cedBackgroundColor[1], cedBackgroundColor[2]); @@ -737,10 +720,6 @@ void alAnsiLoader(char *input, char output[], char font[], char bits[], char ice gdImageFill(im_ANSi,0,0,ced_color); gdImageFilledRectangle(im_Backgrnd, 0, 0, 144, 16, ced_color); - for (loop = 0; loop < 16; loop++) - { -// imagecolorset(im_Font,cedForegroundColor[0],cedForegroundColor[1],cedForegroundColor[2]); - } } else if (workbench == true) { @@ -794,30 +773,46 @@ void alAnsiLoader(char *input, char output[], char font[], char bits[], char ice gdImageColorAllocate(im_ANSi, workbench_color[0][0], workbench_color[0][1], workbench_color[0][2]); int32_t workbench_background; - - workbench_background = - gdImageColorAllocate(im_ANSi, workbench_color[0][0], workbench_color[0][1], workbench_color[0][2]); - workbench_background = - gdImageColorAllocate(im_Backgrnd, workbench_color[0][0], workbench_color[0][1], workbench_color[0][2]); - + gdImageFill(im_ANSi, 0, 0, workbench_background); for (loop=0; loop<8; loop++) { -// imagecolorset(im_Backgrnd, loop, workbench_color[loop][0], workbench_color[loop][1], workbench_color[loop][2]); -// imagecolorset(im_Backgrnd, loop+8, workbench_color[loop][0], workbench_color[loop][1], workbench_color[loop][2]); -// imagecolorset(im_Font, loop, workbench_color[loop][0], workbench_color[loop][1], workbench_color[loop][2]); -// imagecolorset(im_Font, loop+8, workbench_color[loop][0], workbench_color[loop][1], workbench_color[loop][2]); + colors[loop]=gdImageColorAllocate(im_Backgrnd, workbench_color[loop][0], workbench_color[loop][1], workbench_color[loop][2]); + colors[loop+8]=gdImageColorAllocate(im_Backgrnd, workbench_color[loop][0], workbench_color[loop][1], workbench_color[loop][2]); + colors[loop]=gdImageColorAllocate(im_Font, workbench_color[loop][0], workbench_color[loop][1], workbench_color[loop][2]); + colors[loop+8]=gdImageColorAllocate(im_Font, workbench_color[loop][0], workbench_color[loop][1], workbench_color[loop][2]); } } else { + // Allocate standard ANSi color palette + + colors[0] = gdImageColorAllocate(im_Font, 0, 0, 0); + colors[1] = gdImageColorAllocate(im_Font, 170, 0, 0); + colors[2] = gdImageColorAllocate(im_Font, 0, 170, 0); + colors[3] = gdImageColorAllocate(im_Font, 170, 85, 0); + colors[4] = gdImageColorAllocate(im_Font, 0, 0, 170); + colors[5] = gdImageColorAllocate(im_Font, 170, 0, 170); + colors[6] = gdImageColorAllocate(im_Font, 0, 170, 170); + colors[7] = gdImageColorAllocate(im_Font, 170, 170, 170); + colors[8] = gdImageColorAllocate(im_Font, 85, 85, 85); + colors[9] = gdImageColorAllocate(im_Font, 255, 85, 85); + colors[10] = gdImageColorAllocate(im_Font, 85, 255, 85); + colors[11] = gdImageColorAllocate(im_Font, 255, 255, 85); + colors[12] = gdImageColorAllocate(im_Font, 85, 85, 255); + colors[13] = gdImageColorAllocate(im_Font, 255, 85, 255); + colors[14] = gdImageColorAllocate(im_Font, 85, 255, 255); + colors[15] = gdImageColorAllocate(im_Font, 255, 255, 255); + colors[20] = gdImageColorAllocate(im_Font, 200, 220, 169); + + gdImagePaletteCopy(im_Backgrnd, im_Font); + background_canvas = gdImageColorAllocate(im_ANSi, 0, 0, 0); } // color array and RGB definitions -// int32_t colors[17]; int32_t Red, Green, Blue; // generating ANSi colors array in order to draw underlines @@ -1690,7 +1685,7 @@ void alIcedrawLoader(char *input, char output[], char bits[], bool fileHasSAUCE) color_background = (attribute & 240) >> 4; color_foreground = attribute & 15; - alDrawChar(im_IDF, font_data, 8, 8, 16, position_x, position_y, color_background, color_foreground, character); + alDrawChar(im_IDF, font_data, 8, 8, 16, position_x, position_y, colors[color_background], colors[color_foreground], character); position_x++; } @@ -2096,7 +2091,7 @@ void alXbinLoader(char *input, char output[], char bits[]) color_background = (attribute & 240) >> 4; color_foreground = attribute & 15; - alDrawChar(im_XBIN, font_data, 8, 8, 16, position_x, position_y, color_background, color_foreground, character); + alDrawChar(im_XBIN, font_data, 8, 8, 16, position_x, position_y, colors[color_background], colors[color_foreground], character); position_x++; @@ -2124,7 +2119,7 @@ void alXbinLoader(char *input, char output[], char bits[]) color_background = (attribute & 240) >> 4; color_foreground = attribute & 15; - alDrawChar(im_XBIN, font_data, 8, 8, 16, position_x, position_y, color_background, color_foreground, character); + alDrawChar(im_XBIN, font_data, 8, 8, 16, position_x, position_y, colors[color_background], colors[color_foreground], character); position_x++; offset+=2;