ansilove

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

commit 860278da3314ca7e027e83ad98c2a3248b870c6b
parent a9b525413cbc01e64d5d71e8ba83faea207b9d51
Author: Frederic Cambus <fred@statdns.com>
Date:   Thu, 28 Jul 2016 10:57:11 +0200

Merge branch 'file-loading'

Diffstat:
MCMakeLists.txt | 2+-
Msrc/ansilove.c | 14+++++++-------
Msrc/ansilove.h | 3+--
Dsrc/filesize.c | 41-----------------------------------------
Dsrc/filesize.h | 22----------------------
Msrc/loaders/ansi.c | 59+++++++++++++++--------------------------------------------
Msrc/loaders/ansi.h | 2+-
Msrc/loaders/artworx.c | 47+++++++++--------------------------------------
Msrc/loaders/artworx.h | 2+-
Msrc/loaders/binary.c | 45++++++++-------------------------------------
Msrc/loaders/binary.h | 2+-
Msrc/loaders/icedraw.c | 63++++++++++++++-------------------------------------------------
Msrc/loaders/icedraw.h | 2+-
Msrc/loaders/pcboard.c | 57++++++++++++++-------------------------------------------
Msrc/loaders/pcboard.h | 2+-
Msrc/loaders/tundra.c | 96++++++++++++++++++++++++++-----------------------------------------------------
Msrc/loaders/tundra.h | 2+-
Msrc/loaders/xbin.c | 77++++++++++++++++++++++++-----------------------------------------------------
Msrc/loaders/xbin.h | 2+-
Msrc/main.c | 105+++++++++++++++++++++++++++++++++++++++++++++++++------------------------------
20 files changed, 196 insertions(+), 449 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt @@ -18,7 +18,7 @@ find_path(GD_INCLUDE_DIRS gd.h) find_library(GD_LIBRARIES NAMES gd REQUIRED) include_directories(${GD_INCLUDE_DIRS}) -set(SRC src/main.c src/fonts.c src/ansilove.c src/explode.c src/filesize.c src/strtolower.c src/substr.c src/sauce.c) +set(SRC src/main.c src/fonts.c src/ansilove.c src/explode.c src/strtolower.c src/substr.c src/sauce.c) set(LOADERS src/loaders/ansi.c src/loaders/artworx.c src/loaders/binary.c src/loaders/icedraw.c src/loaders/pcboard.c src/loaders/tundra.c src/loaders/xbin.c) diff --git a/src/ansilove.c b/src/ansilove.c @@ -12,24 +12,24 @@ #include "ansilove.h" // shared method for drawing characters -void alDrawChar(gdImagePtr im, const unsigned char *font_data, int32_t int_bits, +void alDrawChar(gdImagePtr im, const unsigned char *font_data, int32_t bits, int32_t font_size_y, int32_t position_x, int32_t position_y, int32_t color_background, int32_t color_foreground, unsigned char character) { int32_t column, line; - gdImageFilledRectangle(im, position_x * int_bits, position_y*font_size_y, position_x * int_bits + - int_bits - 1, position_y * font_size_y + font_size_y - 1, color_background); + gdImageFilledRectangle(im, position_x * bits, position_y*font_size_y, position_x * bits + + bits - 1, position_y * font_size_y + font_size_y - 1, color_background); for (line = 0; line < font_size_y; line++) { - for (column = 0; column < int_bits; column++) { + for (column = 0; column < bits; column++) { if ((font_data[line+character*font_size_y] & (0x80 >> column)) != 0) { - gdImageSetPixel(im, position_x * int_bits + column, position_y*font_size_y + line, color_foreground); + gdImageSetPixel(im, position_x * bits + column, position_y*font_size_y + line, color_foreground); - if (int_bits==9 && column==7 && character > 191 && character < 224) + if (bits==9 && column==7 && character > 191 && character < 224) { - gdImageSetPixel(im, position_x * int_bits + 8, position_y * font_size_y + line, color_foreground); + gdImageSetPixel(im, position_x * bits + 8, position_y * font_size_y + line, color_foreground); } } } diff --git a/src/ansilove.h b/src/ansilove.h @@ -21,7 +21,6 @@ #include "strtolower.h" #include "substr.h" #include "explode.h" -#include "filesize.h" #include "sauce.h" #ifndef HAVE_STRTONUM @@ -32,7 +31,7 @@ #define ansilove_h // prototypes -void alDrawChar(gdImagePtr im, const unsigned char *font_data, int32_t int_bits, +void alDrawChar(gdImagePtr im, const unsigned char *font_data, int32_t bits, int32_t font_size_y, int32_t position_x, int32_t position_y, int32_t color_background, int32_t color_foreground, unsigned char character); diff --git a/src/filesize.c b/src/filesize.c @@ -1,41 +0,0 @@ -// -// filesize.c -// AnsiLove/C -// -// Copyright (C) 2011-2016 Stefan Vogt, Brian Cassidy, Frederic Cambus. -// All rights reserved. -// -// This source code is licensed under the BSD 2-Clause License. -// See the file LICENSE for details. -// - -#include "filesize.h" - -size_t filesize(char *filepath) -{ - // pointer to file at path - size_t size; - FILE *file; - - // To properly determine the size, we open it in binary mode. - file = fopen(filepath, "rb"); - - if(file != NULL) - { - // Error while seeking to end of file? - if(fseek(file, 0, SEEK_END)) { - rewind(file); - fclose(file); - return -1; - } - - size = ftell(file); - // Close file and return the file size. - rewind(file); - fclose(file); - return size; - } - - // In case we encounter an error. - return -1; -} diff --git a/src/filesize.h b/src/filesize.h @@ -1,22 +0,0 @@ -// -// filesize.h -// AnsiLove/C -// -// Copyright (C) 2011-2016 Stefan Vogt, Brian Cassidy, Frederic Cambus. -// All rights reserved. -// -// This source code is licensed under the BSD 2-Clause License. -// See the file LICENSE for details. -// - -#include <stdio.h> -#include <stdlib.h> - -#ifndef filesize_h -#define filesize_h - -// Returns size of a file at a given path as integer. - -size_t filesize(char *filepath); - -#endif diff --git a/src/loaders/ansi.c b/src/loaders/ansi.c @@ -11,7 +11,7 @@ #include "ansi.h" -void ansi(char *input, char *output, char *retinaout, char *font, int32_t int_bits, char *mode, bool icecolors, char *fext, bool createRetinaRep) +void ansi(unsigned char *inputFileBuffer, int32_t inputFileSize, char *output, char *retinaout, char *font, int32_t bits, char *mode, bool icecolors, char *fext, bool createRetinaRep) { // ladies and gentlemen, it's type declaration time struct fontStruct fontData; @@ -39,35 +39,6 @@ void ansi(char *input, char *output, char *retinaout, char *font, int32_t int_bi workbench = true; } - // load input file - FILE *input_file = fopen(input, "r"); - if (input_file == NULL) { - fputs("\nFile error.\n\n", stderr); exit (1); - } - - // get the file size (bytes) - size_t get_file_size = filesize(input); - int32_t input_file_size = (int32_t)get_file_size; - - // next up is loading our file into a dynamically allocated memory buffer - unsigned char *input_file_buffer; - int32_t result; - - // allocate memory to contain the whole file - input_file_buffer = (unsigned char *) malloc(sizeof(unsigned char)*input_file_size); - if (input_file_buffer == NULL) { - fputs ("\nMemory error.\n\n", stderr); exit (2); - } - - // copy the file into the buffer - result = fread(input_file_buffer, 1, input_file_size, input_file); - if (result != input_file_size) { - fputs ("\nReading error.\n\n", stderr); exit (3); - } // whole file is now loaded into input_file_buffer - - // close input file, we don't need it anymore - fclose(input_file); - // check if current file has a .diz extension if (!strcmp(fext, ".diz")) { isDizFile = true; @@ -106,10 +77,10 @@ void ansi(char *input, char *output, char *retinaout, char *font, int32_t int_bi ansi_buffer = malloc(sizeof(struct ansiChar)); // ANSi interpreter - while (loop < input_file_size) + while (loop < inputFileSize) { - current_character = input_file_buffer[loop]; - next_character = input_file_buffer[loop + 1]; + current_character = inputFileBuffer[loop]; + next_character = inputFileBuffer[loop + 1]; if (position_x==80 && WRAP_COLUMN_80) { @@ -148,13 +119,13 @@ void ansi(char *input, char *output, char *retinaout, char *font, int32_t int_bi { for (ansi_sequence_loop = 0; ansi_sequence_loop < 12; ansi_sequence_loop++) { - ansi_sequence_character = input_file_buffer[loop + 2 + ansi_sequence_loop]; + ansi_sequence_character = inputFileBuffer[loop + 2 + ansi_sequence_loop]; // cursor position if (ansi_sequence_character == 'H' || ansi_sequence_character == 'f') { // create substring from the sequence's content - seqGrab = substr((char *)input_file_buffer, loop+2, ansi_sequence_loop); + seqGrab = substr((char *)inputFileBuffer, loop+2, ansi_sequence_loop); // create sequence content array seqArrayCount = explode(&seqArray, ';', seqGrab); @@ -181,7 +152,7 @@ void ansi(char *input, char *output, char *retinaout, char *font, int32_t int_bi if (ansi_sequence_character=='A') { // create substring from the sequence's content - seqGrab = substr((char *)input_file_buffer, loop+2, ansi_sequence_loop); + seqGrab = substr((char *)inputFileBuffer, loop+2, ansi_sequence_loop); // now get escape sequence's position value int32_t seq_line = strtonum(seqGrab, 0, INT32_MAX, &errstr); @@ -200,7 +171,7 @@ void ansi(char *input, char *output, char *retinaout, char *font, int32_t int_bi if (ansi_sequence_character=='B') { // create substring from the sequence's content - seqGrab = substr((char *)input_file_buffer, loop+2, ansi_sequence_loop); + seqGrab = substr((char *)inputFileBuffer, loop+2, ansi_sequence_loop); // now get escape sequence's position value int32_t seq_line = strtonum(seqGrab, 0, INT32_MAX, &errstr); @@ -219,7 +190,7 @@ void ansi(char *input, char *output, char *retinaout, char *font, int32_t int_bi if (ansi_sequence_character=='C') { // create substring from the sequence's content - seqGrab = substr((char *)input_file_buffer, loop+2, ansi_sequence_loop); + seqGrab = substr((char *)inputFileBuffer, loop+2, ansi_sequence_loop); // now get escape sequence's position value int32_t seq_column = strtonum(seqGrab, 0, INT32_MAX, &errstr); @@ -243,7 +214,7 @@ void ansi(char *input, char *output, char *retinaout, char *font, int32_t int_bi if (ansi_sequence_character=='D') { // create substring from the sequence's content - seqGrab = substr((char *)input_file_buffer, loop+2, ansi_sequence_loop); + seqGrab = substr((char *)inputFileBuffer, loop+2, ansi_sequence_loop); // now get escape sequence's content length int32_t seq_column = strtonum(seqGrab, 0, INT32_MAX, &errstr); @@ -287,7 +258,7 @@ void ansi(char *input, char *output, char *retinaout, char *font, int32_t int_bi if (ansi_sequence_character=='J') { // create substring from the sequence's content - seqGrab = substr((char *)input_file_buffer, loop+2, ansi_sequence_loop); + seqGrab = substr((char *)inputFileBuffer, loop+2, ansi_sequence_loop); // convert grab to an integer int32_t eraseDisplayInt = strtonum(seqGrab, 0, INT32_MAX, &errstr); @@ -313,7 +284,7 @@ void ansi(char *input, char *output, char *retinaout, char *font, int32_t int_bi if (ansi_sequence_character=='m') { // create substring from the sequence's content - seqGrab = substr((char *)input_file_buffer, loop+2, ansi_sequence_loop); + seqGrab = substr((char *)inputFileBuffer, loop+2, ansi_sequence_loop); // create sequence content array seqArrayCount = explode(&seqArray, ';', seqGrab); @@ -452,7 +423,7 @@ void ansi(char *input, char *output, char *retinaout, char *font, int32_t int_bi } // create that damn thingy - im_ANSi = gdImageCreate(columns * int_bits,(position_y_max)*fontData.font_size_y); + im_ANSi = gdImageCreate(columns * bits,(position_y_max)*fontData.font_size_y); if (!im_ANSi) { fputs ("\nCan't allocate ANSi buffer image memory.\n\n", stderr); exit (6); @@ -529,10 +500,10 @@ void ansi(char *input, char *output, char *retinaout, char *font, int32_t int_bi position_y = ansi_buffer[loop].position_y; if (ced) { - alDrawChar(im_ANSi, fontData.font_data, int_bits, fontData.font_size_y, + alDrawChar(im_ANSi, fontData.font_data, bits, fontData.font_size_y, position_x, position_y, ced_background, ced_foreground, character); } else { - alDrawChar(im_ANSi, fontData.font_data, int_bits, fontData.font_size_y, + alDrawChar(im_ANSi, fontData.font_data, bits, fontData.font_size_y, position_x, position_y, colors[color_background], colors[color_foreground], character); } diff --git a/src/loaders/ansi.h b/src/loaders/ansi.h @@ -26,6 +26,6 @@ struct ansiChar { bool underline; }; -void ansi(char *input, char *output, char *retinaout, char *font, int32_t int_bits, char *mode, bool icecolors, char *fext, bool createRetinaRep); +void ansi(unsigned char *inputFileBuffer, int32_t inputFileSize, char *output, char *retinaout, char *font, int32_t bits, char *mode, bool icecolors, char *fext, bool createRetinaRep); #endif diff --git a/src/loaders/artworx.c b/src/loaders/artworx.c @@ -11,45 +11,16 @@ #include "artworx.h" -void artworx(char *input, char *output, char *retinaout, bool createRetinaRep) +void artworx(unsigned char *inputFileBuffer, int32_t inputFileSize, char *output, char *retinaout, bool createRetinaRep) { const unsigned char *font_data; unsigned char *font_data_adf; - // load input file - FILE *input_file = fopen(input, "r"); - if (input_file == NULL) { - fputs("\nFile error.\n\n", stderr); exit (1); - } - - // get the file size (bytes) - size_t get_file_size = filesize(input); - int32_t input_file_size = (int32_t)get_file_size; - - // next up is loading our file into a dynamically allocated memory buffer - unsigned char *input_file_buffer; - int32_t result; - - // allocate memory to contain the whole file - input_file_buffer = (unsigned char *) malloc(sizeof(unsigned char)*input_file_size); - if (input_file_buffer == NULL) { - fputs ("\nMemory error.\n\n", stderr); exit (2); - } - - // copy the file into the buffer - result = fread(input_file_buffer, 1, input_file_size, input_file); - if (result != input_file_size) { - fputs ("\nReading error.\n\n", stderr); exit (3); - } // whole file is now loaded into input_file_buffer - - // close input file, we don't need it anymore - fclose(input_file); - // libgd image pointers gdImagePtr im_ADF; // create ADF instance - im_ADF = gdImageCreate(640,(((input_file_size - 192 - 4096 -1) / 2) / 80) * 16); + im_ADF = gdImageCreate(640,(((inputFileSize - 192 - 4096 -1) / 2) / 80) * 16); // error output if (!im_ADF) { @@ -67,7 +38,7 @@ void artworx(char *input, char *output, char *retinaout, bool createRetinaRep) if (font_data_adf == NULL) { fputs ("\nMemory error.\n\n", stderr); exit (7); } - memcpy(font_data_adf,input_file_buffer+193,4096); + memcpy(font_data_adf,inputFileBuffer+193,4096); font_data=font_data_adf; @@ -75,9 +46,9 @@ void artworx(char *input, char *output, char *retinaout, bool createRetinaRep) for (loop = 0; loop < 16; loop++) { index = (adf_colors[loop] * 3) + 1; - gdImageColorAllocate(im_ADF, (input_file_buffer[index] << 2 | input_file_buffer[index] >> 4), - (input_file_buffer[index + 1] << 2 | input_file_buffer[index + 1] >> 4), - (input_file_buffer[index + 2] << 2 | input_file_buffer[index + 2] >> 4)); + gdImageColorAllocate(im_ADF, (inputFileBuffer[index] << 2 | inputFileBuffer[index] >> 4), + (inputFileBuffer[index + 1] << 2 | inputFileBuffer[index + 1] >> 4), + (inputFileBuffer[index + 2] << 2 | inputFileBuffer[index + 2] >> 4)); } gdImageColorAllocate(im_ADF, 0, 0, 0); @@ -87,7 +58,7 @@ void artworx(char *input, char *output, char *retinaout, bool createRetinaRep) int32_t character, attribute, color_foreground, color_background; loop = 192 + 4096 + 1; - while(loop < input_file_size) + while(loop < inputFileSize) { if (position_x == 80) { @@ -95,8 +66,8 @@ void artworx(char *input, char *output, char *retinaout, bool createRetinaRep) position_y++; } - character = input_file_buffer[loop]; - attribute = input_file_buffer[loop+1]; + character = inputFileBuffer[loop]; + attribute = inputFileBuffer[loop+1]; color_background = (attribute & 240) >> 4; color_foreground = attribute & 15; diff --git a/src/loaders/artworx.h b/src/loaders/artworx.h @@ -14,6 +14,6 @@ #ifndef artworx_h #define artworx_h -void artworx(char *input, char *output, char *retinaout, bool createRetinaRep); +void artworx(unsigned char *inputFileBuffer, int32_t inputFileSize, char *output, char *retinaout, bool createRetinaRep); #endif diff --git a/src/loaders/binary.c b/src/loaders/binary.c @@ -11,7 +11,7 @@ #include "binary.h" -void binary(char *input, char *output, char *retinaout, int32_t int_columns, char *font, int32_t int_bits, bool icecolors, bool createRetinaRep) +void binary(unsigned char *inputFileBuffer, int32_t inputFileSize, char *output, char *retinaout, int32_t columns, char *font, int32_t bits, bool icecolors, bool createRetinaRep) { // some type declarations struct fontStruct fontData; @@ -19,41 +19,12 @@ void binary(char *input, char *output, char *retinaout, int32_t int_columns, cha // font selection alSelectFont(&fontData, font); - // load input file - FILE *input_file = fopen(input, "r"); - if (input_file == NULL) { - fputs("\nFile error.\n\n", stderr); exit (1); - } - - // get the file size (bytes) - size_t get_file_size = filesize(input); - int32_t input_file_size = (int32_t)get_file_size; - - // next up is loading our file into a dynamically allocated memory buffer - unsigned char *input_file_buffer; - int32_t result; - - // allocate memory to contain the whole file - input_file_buffer = (unsigned char *) malloc(sizeof(unsigned char)*input_file_size); - if (input_file_buffer == NULL) { - fputs ("\nMemory error.\n\n", stderr); exit (2); - } - - // copy the file into the buffer - result = fread(input_file_buffer, 1, input_file_size, input_file); - if (result != input_file_size) { - fputs ("\nReading error.\n\n", stderr); exit (3); - } // whole file is now loaded into input_file_buffer - - // close input file, we don't need it anymore - fclose(input_file); - // libgd image pointers gdImagePtr im_Binary; // allocate buffer image memory - im_Binary = gdImageCreate(int_columns * int_bits, - ((input_file_size / 2) / int_columns * fontData.font_size_y)); + im_Binary = gdImageCreate(columns * bits, + ((inputFileSize / 2) / columns * fontData.font_size_y)); if (!im_Binary) { fputs ("\nError, can't allocate buffer image memory.\n\n", stderr); exit (6); @@ -86,16 +57,16 @@ void binary(char *input, char *output, char *retinaout, int32_t int_columns, cha int32_t character, attribute, color_background, color_foreground; int32_t loop = 0, position_x = 0, position_y = 0; - while (loop < input_file_size) + while (loop < inputFileSize) { - if (position_x == int_columns) + if (position_x == columns) { position_x = 0; position_y++; } - character = input_file_buffer[loop]; - attribute = input_file_buffer[loop+1]; + character = inputFileBuffer[loop]; + attribute = inputFileBuffer[loop+1]; color_background = (attribute & 240) >> 4; color_foreground = (attribute & 15); @@ -105,7 +76,7 @@ void binary(char *input, char *output, char *retinaout, int32_t int_columns, cha color_background -= 8; } - alDrawChar(im_Binary, fontData.font_data, int_bits, fontData.font_size_y, + alDrawChar(im_Binary, fontData.font_data, bits, fontData.font_size_y, position_x, position_y, colors[color_background], colors[color_foreground], character); position_x++; diff --git a/src/loaders/binary.h b/src/loaders/binary.h @@ -14,7 +14,7 @@ #ifndef binary_h #define binary_h -void binary(char *input, char *output, char *retinaout, int32_t int_columns, char *font, int32_t int_bits, bool icecolors, bool createRetinaRep); +void binary(unsigned char *inputFileBuffer, int32_t inputFileSize, char *output, char *retinaout, int32_t columns, char *font, int32_t bits, bool icecolors, bool createRetinaRep); #endif diff --git a/src/loaders/icedraw.c b/src/loaders/icedraw.c @@ -11,48 +11,13 @@ #include "icedraw.h" -void icedraw(char *input, char *output, char *retinaout, bool fileHasSAUCE, bool createRetinaRep) +void icedraw(unsigned char *inputFileBuffer, int32_t inputFileSize, char *output, char *retinaout, bool createRetinaRep) { const unsigned char *font_data; unsigned char *font_data_idf; - // load input file - FILE *input_file = fopen(input, "r"); - if (input_file == NULL) { - fputs("\nFile error.\n\n", stderr); exit (1); - } - - // get the file size (bytes) - size_t get_file_size = filesize(input); - int32_t input_file_size = (int32_t)get_file_size; - - // next up is loading our file into a dynamically allocated memory buffer - unsigned char *input_file_buffer; - int32_t result; - - // allocate memory to contain the whole file - input_file_buffer = (unsigned char *) malloc(sizeof(unsigned char)*input_file_size); - if (input_file_buffer == NULL) { - fputs ("\nMemory error.\n\n", stderr); exit (2); - } - - // copy the file into the buffer - result = fread(input_file_buffer, 1, input_file_size, input_file); - if (result != input_file_size) { - fputs ("\nReading error.\n\n", stderr); exit (3); - } // whole file is now loaded into input_file_buffer - - // IDF related: file contains a SAUCE record? adjust the file size - if(fileHasSAUCE) { - sauce *saucerec = sauceReadFile(input_file); - input_file_size -= 129 - ( saucerec->comments > 0 ? 5 + 64 * saucerec->comments : 0); - } - - // close input file, we don't need it anymore - fclose(input_file); - // extract relevant part of the IDF header, 16-bit endian unsigned short - int32_t x2 = (input_file_buffer[9] << 8) + input_file_buffer[8]; + int32_t x2 = (inputFileBuffer[9] << 8) + inputFileBuffer[8]; // libgd image pointers gdImagePtr im_IDF; @@ -66,7 +31,7 @@ void icedraw(char *input, char *output, char *retinaout, bool fileHasSAUCE, bool if (font_data_idf == NULL) { fputs ("\nMemory error.\n\n", stderr); exit (7); } - memcpy(font_data_idf,input_file_buffer+(input_file_size - 48 - 4096),4096); + memcpy(font_data_idf,inputFileBuffer+(inputFileSize - 48 - 4096),4096); font_data=font_data_idf; @@ -80,14 +45,14 @@ void icedraw(char *input, char *output, char *retinaout, bool fileHasSAUCE, bool int16_t idf_data, idf_data_length; - while (loop < input_file_size - 4096 - 48) + while (loop < inputFileSize - 4096 - 48) { - memcpy(&idf_data,input_file_buffer+loop,2); + memcpy(&idf_data,inputFileBuffer+loop,2); // RLE compressed data if (idf_data==1) { - memcpy(&idf_data_length,input_file_buffer+loop+2,2); + memcpy(&idf_data_length,inputFileBuffer+loop+2,2); idf_sequence_length = idf_data_length & 255; @@ -102,8 +67,8 @@ void icedraw(char *input, char *output, char *retinaout, bool fileHasSAUCE, bool fputs ("\nError allocating IDF buffer memory.\n\n", stderr); exit (7); } - idf_buffer[i] = input_file_buffer[loop + 4]; - idf_buffer[i+1] = input_file_buffer[loop + 5]; + idf_buffer[i] = inputFileBuffer[loop + 4]; + idf_buffer[i+1] = inputFileBuffer[loop + 5]; i+=2; } loop += 4; @@ -119,8 +84,8 @@ void icedraw(char *input, char *output, char *retinaout, bool fileHasSAUCE, bool } // normal character - idf_buffer[i] = input_file_buffer[loop]; - idf_buffer[i+1] = input_file_buffer[loop + 1]; + idf_buffer[i] = inputFileBuffer[loop]; + idf_buffer[i+1] = inputFileBuffer[loop + 1]; i+=2; } loop += 2; @@ -138,10 +103,10 @@ void icedraw(char *input, char *output, char *retinaout, bool fileHasSAUCE, bool // process IDF palette for (loop = 0; loop < 16; loop++) { - index = (loop * 3) + input_file_size - 48; - colors[loop] = gdImageColorAllocate(im_IDF, (input_file_buffer[index] << 2 | input_file_buffer[index] >> 4), - (input_file_buffer[index + 1] << 2 | input_file_buffer[index + 1] >> 4), - (input_file_buffer[index + 2] << 2 | input_file_buffer[index + 2] >> 4)); + index = (loop * 3) + inputFileSize - 48; + colors[loop] = gdImageColorAllocate(im_IDF, (inputFileBuffer[index] << 2 | inputFileBuffer[index] >> 4), + (inputFileBuffer[index + 1] << 2 | inputFileBuffer[index + 1] >> 4), + (inputFileBuffer[index + 2] << 2 | inputFileBuffer[index + 2] >> 4)); } // render IDF diff --git a/src/loaders/icedraw.h b/src/loaders/icedraw.h @@ -14,7 +14,7 @@ #ifndef icedraw_h #define icedraw_h -void icedraw(char *input, char *output, char *retinaout, bool fileHasSAUCE, bool createRetinaRep); +void icedraw(unsigned char *inputFileBuffer, int32_t inputFileSize, char *output, char *retinaout, bool createRetinaRep); #endif diff --git a/src/loaders/pcboard.c b/src/loaders/pcboard.c @@ -11,7 +11,7 @@ #include "pcboard.h" -void pcboard(char *input, char *output, char *retinaout, char *font, int32_t int_bits, bool createRetinaRep) +void pcboard(unsigned char *inputFileBuffer, int32_t inputFileSize, char *output, char *retinaout, char *font, int32_t bits, bool createRetinaRep) { // some type declarations struct fontStruct fontData; @@ -21,35 +21,6 @@ void pcboard(char *input, char *output, char *retinaout, char *font, int32_t int // font selection alSelectFont(&fontData, font); - // load input file - FILE *input_file = fopen(input, "r"); - if (input_file == NULL) { - fputs("\nFile error.\n\n", stderr); exit (1); - } - - // get the file size (bytes) - size_t get_file_size = filesize(input); - int32_t input_file_size = (int32_t)get_file_size; - - // next up is loading our file into a dynamically allocated memory buffer - unsigned char *input_file_buffer; - int32_t result; - - // allocate memory to contain the whole file - input_file_buffer = (unsigned char *) malloc(sizeof(unsigned char)*input_file_size); - if (input_file_buffer == NULL) { - fputs ("\nMemory error.\n\n", stderr); exit (2); - } - - // copy the file into the buffer - result = fread(input_file_buffer, 1, input_file_size, input_file); - if (result != input_file_size) { - fputs ("\nReading error.\n\n", stderr); exit (3); - } // whole file is now loaded into input_file_buffer - - // close input file, we don't need it anymore - fclose(input_file); - // libgd image pointers gdImagePtr im_PCB; @@ -68,10 +39,10 @@ void pcboard(char *input, char *output, char *retinaout, char *font, int32_t int loop = 0; structIndex = 0; - while (loop < input_file_size) + while (loop < inputFileSize) { - current_character = input_file_buffer[loop]; - next_character = input_file_buffer[loop+1]; + current_character = inputFileBuffer[loop]; + next_character = inputFileBuffer[loop+1]; if (position_x == 80) { @@ -109,12 +80,12 @@ void pcboard(char *input, char *output, char *retinaout, char *font, int32_t int if (current_character == 64 && next_character == 88) { // set graphics rendition - color_background = input_file_buffer[loop+2]; - color_foreground = input_file_buffer[loop+3]; + color_background = inputFileBuffer[loop+2]; + color_foreground = inputFileBuffer[loop+3]; loop+=3; } else if (current_character == 64 && next_character == 67 && - input_file_buffer[loop+2] == 'L' && input_file_buffer[loop+3] == 'S') + inputFileBuffer[loop+2] == 'L' && inputFileBuffer[loop+3] == 'S') { // erase display position_x = 0; @@ -125,18 +96,18 @@ void pcboard(char *input, char *output, char *retinaout, char *font, int32_t int loop+=4; } - else if (current_character == 64 && next_character == 80 && input_file_buffer[loop+2] == 'O' - && input_file_buffer[loop+3] == 'S' && input_file_buffer[loop+4]== ':') + else if (current_character == 64 && next_character == 80 && inputFileBuffer[loop+2] == 'O' + && inputFileBuffer[loop+3] == 'S' && inputFileBuffer[loop+4]== ':') { // cursor position - if (input_file_buffer[loop+6]=='@') + if (inputFileBuffer[loop+6]=='@') { - position_x=((input_file_buffer[loop+5])-48)-1; + position_x=((inputFileBuffer[loop+5])-48)-1; loop+=5; } else { - position_x = (10 * ((input_file_buffer[loop+5])-48) + (input_file_buffer[loop+6])-48)-1; + position_x = (10 * ((inputFileBuffer[loop+5])-48) + (inputFileBuffer[loop+6])-48)-1; loop+=6; } } @@ -173,7 +144,7 @@ void pcboard(char *input, char *output, char *retinaout, char *font, int32_t int position_y_max++; // allocate buffer image memory - im_PCB = gdImageCreate(columns * int_bits, (position_y_max)*fontData.font_size_y); + im_PCB = gdImageCreate(columns * bits, (position_y_max)*fontData.font_size_y); // allocate black color and create background canvas gdImageColorAllocate(im_PCB, 0, 0, 0); @@ -212,7 +183,7 @@ void pcboard(char *input, char *output, char *retinaout, char *font, int32_t int color_foreground = pcboard_buffer[loop].color_foreground; character = pcboard_buffer[loop].current_character; - alDrawChar(im_PCB, fontData.font_data, int_bits, fontData.font_size_y, + alDrawChar(im_PCB, fontData.font_data, bits, fontData.font_size_y, position_x, position_y, colors[color_background], colors[color_foreground], character); } diff --git a/src/loaders/pcboard.h b/src/loaders/pcboard.h @@ -23,6 +23,6 @@ struct pcbChar { int32_t current_character; }; -void pcboard(char *input, char *output, char *retinaout, char *font, int32_t int_bits, bool createRetinaRep); +void pcboard(unsigned char *inputFileBuffer, int32_t inputFileSize, char *output, char *retinaout, char *font, int32_t bits, bool createRetinaRep); #endif diff --git a/src/loaders/tundra.c b/src/loaders/tundra.c @@ -11,7 +11,7 @@ #include "tundra.h" -void tundra(char *input, char *output, char *retinaout, char *font, int32_t int_bits, bool fileHasSAUCE, bool createRetinaRep) +void tundra(unsigned char *inputFileBuffer, int32_t inputFileSize, char *output, char *retinaout, char *font, int32_t bits, bool createRetinaRep) { // some type declarations struct fontStruct fontData; @@ -22,46 +22,12 @@ void tundra(char *input, char *output, char *retinaout, char *font, int32_t int_ // font selection alSelectFont(&fontData, font); - // load input file - FILE *input_file = fopen(input, "r"); - if (input_file == NULL) { - fputs("\nFile error.\n\n", stderr); exit (1); - } - - // get the file size (bytes) - size_t get_file_size = filesize(input); - int32_t input_file_size = (int32_t)get_file_size; - - // next up is loading our file into a dynamically allocated memory buffer - unsigned char *input_file_buffer; - int32_t result; - - // allocate memory to contain the whole file - input_file_buffer = (unsigned char *) malloc(sizeof(unsigned char)*input_file_size); - if (input_file_buffer == NULL) { - fputs ("\nMemory error.\n\n", stderr); exit (2); - } - - // copy the file into the buffer - result = fread(input_file_buffer, 1, input_file_size, input_file); - if (result != input_file_size) { - fputs ("\nReading error.\n\n", stderr); exit (3); - } // whole file is now loaded into input_file_buffer - - // exclude SAUCE record from file buffer - if(fileHasSAUCE) { - sauce *saucerec = sauceReadFile(input_file); - input_file_size -= 129 - ( saucerec->comments > 0 ? 5 + 64 * saucerec->comments : 0); - } - // close input file, we don't need it anymore - fclose(input_file); - // libgd image pointers gdImagePtr im_Tundra; // extract tundra header - tundra_version = input_file_buffer[0]; - memcpy(&tundra_header,input_file_buffer+1,8); + tundra_version = inputFileBuffer[0]; + memcpy(&tundra_header,inputFileBuffer+1,8); // need to add check for "TUNDRA24" string in the header if (tundra_version != 24) @@ -75,7 +41,7 @@ void tundra(char *input, char *output, char *retinaout, char *font, int32_t int_ loop=9; - while (loop < input_file_size) + while (loop < inputFileSize) { if (position_x == 80) { @@ -83,38 +49,38 @@ void tundra(char *input, char *output, char *retinaout, char *font, int32_t int_ position_y++; } - character = input_file_buffer[loop]; + character = inputFileBuffer[loop]; if (character == 1) { position_y = - (input_file_buffer[loop + 1] << 24) + (input_file_buffer[loop + 2] << 16) + - (input_file_buffer[loop + 3] << 8) + input_file_buffer[loop+4]; + (inputFileBuffer[loop + 1] << 24) + (inputFileBuffer[loop + 2] << 16) + + (inputFileBuffer[loop + 3] << 8) + inputFileBuffer[loop+4]; position_x = - (input_file_buffer[loop + 5] << 24) + (input_file_buffer[loop + 6] << 16) + - (input_file_buffer[loop + 7] << 8) + input_file_buffer[loop+8]; + (inputFileBuffer[loop + 5] << 24) + (inputFileBuffer[loop + 6] << 16) + + (inputFileBuffer[loop + 7] << 8) + inputFileBuffer[loop+8]; loop+=8; } if (character == 2) { - character = input_file_buffer[loop + 1]; + character = inputFileBuffer[loop + 1]; loop+=5; } if (character == 4) { - character = input_file_buffer[loop + 1]; + character = inputFileBuffer[loop + 1]; loop+=5; } if (character == 6) { - character = input_file_buffer[loop + 1]; + character = inputFileBuffer[loop + 1]; loop+=9; } @@ -129,7 +95,7 @@ void tundra(char *input, char *output, char *retinaout, char *font, int32_t int_ position_y++; // allocate buffer image memory - im_Tundra = gdImageCreateTrueColor(columns * int_bits , (position_y) * fontData.font_size_y); + im_Tundra = gdImageCreateTrueColor(columns * bits , (position_y) * fontData.font_size_y); if (!im_Tundra) { fputs ("\nError, can't allocate buffer image memory.\n\n", stderr); exit (6); @@ -141,7 +107,7 @@ void tundra(char *input, char *output, char *retinaout, char *font, int32_t int_ loop = 9; - while (loop < input_file_size) + while (loop < inputFileSize) { if (position_x == 80) { @@ -149,17 +115,17 @@ void tundra(char *input, char *output, char *retinaout, char *font, int32_t int_ position_y++; } - character = input_file_buffer[loop]; + character = inputFileBuffer[loop]; if (character == 1) { position_y = - (input_file_buffer[loop + 1] << 24) + (input_file_buffer[loop + 2] << 16) + - (input_file_buffer[loop + 3] << 8) + input_file_buffer[loop + 4]; + (inputFileBuffer[loop + 1] << 24) + (inputFileBuffer[loop + 2] << 16) + + (inputFileBuffer[loop + 3] << 8) + inputFileBuffer[loop + 4]; position_x = - (input_file_buffer[loop + 5] << 24) + (input_file_buffer[loop + 6] << 16) + - (input_file_buffer[loop + 7] << 8) + input_file_buffer[loop + 8]; + (inputFileBuffer[loop + 5] << 24) + (inputFileBuffer[loop + 6] << 16) + + (inputFileBuffer[loop + 7] << 8) + inputFileBuffer[loop + 8]; loop+=8; } @@ -167,20 +133,20 @@ void tundra(char *input, char *output, char *retinaout, char *font, int32_t int_ if (character == 2) { color_foreground = - (input_file_buffer[loop + 3] << 16) + (input_file_buffer[loop + 4] << 8) + - input_file_buffer[loop + 5]; + (inputFileBuffer[loop + 3] << 16) + (inputFileBuffer[loop + 4] << 8) + + inputFileBuffer[loop + 5]; - character = input_file_buffer[loop+1]; + character = inputFileBuffer[loop+1]; loop+=5; } if (character == 4) { - color_background = (input_file_buffer[loop + 3] << 16) + (input_file_buffer[loop + 4] << 8) + - input_file_buffer[loop+5]; + color_background = (inputFileBuffer[loop + 3] << 16) + (inputFileBuffer[loop + 4] << 8) + + inputFileBuffer[loop+5]; - character = input_file_buffer[loop+1]; + character = inputFileBuffer[loop+1]; loop+=5; } @@ -188,21 +154,21 @@ void tundra(char *input, char *output, char *retinaout, char *font, int32_t int_ if (character==6) { color_foreground = - (input_file_buffer[loop + 3] << 16) + (input_file_buffer[loop + 4] << 8) + - input_file_buffer[loop+5]; + (inputFileBuffer[loop + 3] << 16) + (inputFileBuffer[loop + 4] << 8) + + inputFileBuffer[loop+5]; color_background = - (input_file_buffer[loop + 7] << 16) + (input_file_buffer[loop + 8] << 8) + - input_file_buffer[loop+9]; + (inputFileBuffer[loop + 7] << 16) + (inputFileBuffer[loop + 8] << 8) + + inputFileBuffer[loop+9]; - character = input_file_buffer[loop+1]; + character = inputFileBuffer[loop+1]; loop+=9; } if (character !=1 && character !=2 && character !=4 && character !=6) { - alDrawChar(im_Tundra, fontData.font_data, int_bits, fontData.font_size_y, + alDrawChar(im_Tundra, fontData.font_data, bits, fontData.font_size_y, position_x, position_y, color_background, color_foreground, character); position_x++; diff --git a/src/loaders/tundra.h b/src/loaders/tundra.h @@ -14,6 +14,6 @@ #ifndef tundra_h #define tundra_h -void tundra(char *input, char *output, char *retinaout, char *font, int32_t int_bits, bool fileHasSAUCE, bool createRetinaRep); +void tundra(unsigned char *inputFileBuffer, int32_t inputFileSize, char *output, char *retinaout, char *font, int32_t bits, bool createRetinaRep); #endif diff --git a/src/loaders/xbin.c b/src/loaders/xbin.c @@ -11,48 +11,19 @@ #include "xbin.h" -void xbin(char *input, char *output, char *retinaout, bool createRetinaRep) +void xbin(unsigned char *inputFileBuffer, int32_t inputFileSize, char *output, char *retinaout, bool createRetinaRep) { const unsigned char *font_data; unsigned char *font_data_xbin; - // load input file - FILE *input_file = fopen(input, "r"); - if (input_file == NULL) { - fputs("\nFile error.\n\n", stderr); exit (1); - } - - // get the file size (bytes) - size_t get_file_size = filesize(input); - int32_t input_file_size = (int32_t)get_file_size; - - // next up is loading our file into a dynamically allocated memory buffer - unsigned char *input_file_buffer; - int32_t result; - - // allocate memory to contain the whole file - input_file_buffer = (unsigned char *) malloc(sizeof(unsigned char)*input_file_size); - if (input_file_buffer == NULL) { - fputs ("\nMemory error.\n\n", stderr); exit (2); - } - - // copy the file into the buffer - result = fread(input_file_buffer, 1, input_file_size, input_file); - if (result != input_file_size) { - fputs ("\nReading error.\n\n", stderr); exit (3); - } // whole file is now loaded into input_file_buffer - - // close input file, we don't need it anymore - fclose(input_file); - - if (strncmp((char *)input_file_buffer, "XBIN\x1a", 5) != 0) { + if (strncmp((char *)inputFileBuffer, "XBIN\x1a", 5) != 0) { fputs("\nNot an XBin.\n\n", stderr); exit (4); } - int32_t xbin_width = (input_file_buffer[ 6 ] << 8) + input_file_buffer[ 5 ]; - int32_t xbin_height = (input_file_buffer[ 8 ] << 8) + input_file_buffer[ 7 ]; - int32_t xbin_fontsize = input_file_buffer[ 9 ]; - int32_t xbin_flags = input_file_buffer[ 10 ]; + int32_t xbin_width = (inputFileBuffer[ 6 ] << 8) + inputFileBuffer[ 5 ]; + int32_t xbin_height = (inputFileBuffer[ 8 ] << 8) + inputFileBuffer[ 7 ]; + int32_t xbin_fontsize = inputFileBuffer[ 9 ]; + int32_t xbin_flags = inputFileBuffer[ 10 ]; gdImagePtr im_XBIN; @@ -77,9 +48,9 @@ void xbin(char *input, char *output, char *retinaout, bool createRetinaRep) { index = (loop * 3) + offset; - colors[loop] = gdImageColorAllocate(im_XBIN, (input_file_buffer[index] << 2 | input_file_buffer[index] >> 4), - (input_file_buffer[index + 1] << 2 | input_file_buffer[index + 1] >> 4), - (input_file_buffer[index + 2] << 2 | input_file_buffer[index + 2] >> 4)); + colors[loop] = gdImageColorAllocate(im_XBIN, (inputFileBuffer[index] << 2 | inputFileBuffer[index] >> 4), + (inputFileBuffer[index + 1] << 2 | inputFileBuffer[index + 1] >> 4), + (inputFileBuffer[index + 2] << 2 | inputFileBuffer[index + 2] >> 4)); } offset += 48; @@ -112,7 +83,7 @@ void xbin(char *input, char *output, char *retinaout, bool createRetinaRep) if (font_data_xbin == NULL) { fputs ("\nMemory error.\n\n", stderr); exit (5); } - memcpy(font_data_xbin,input_file_buffer+offset,(xbin_fontsize * numchars)); + memcpy(font_data_xbin,inputFileBuffer+offset,(xbin_fontsize * numchars)); font_data=font_data_xbin; @@ -128,10 +99,10 @@ void xbin(char *input, char *output, char *retinaout, bool createRetinaRep) // read compressed xbin if( (xbin_flags & 4) == 4) { - while(offset < input_file_size && position_y != xbin_height ) + while(offset < inputFileSize && position_y != xbin_height ) { - int32_t ctype = input_file_buffer[ offset ] & 0xC0; - int32_t counter = ( input_file_buffer[ offset ] & 0x3F ) + 1; + int32_t ctype = inputFileBuffer[ offset ] & 0xC0; + int32_t counter = ( inputFileBuffer[ offset ] & 0x3F ) + 1; character = -1; attribute = -1; @@ -140,36 +111,36 @@ void xbin(char *input, char *output, char *retinaout, bool createRetinaRep) while( counter-- ) { // none if( ctype == 0 ) { - character = input_file_buffer[ offset ]; - attribute = input_file_buffer[ offset + 1 ]; + character = inputFileBuffer[ offset ]; + attribute = inputFileBuffer[ offset + 1 ]; offset += 2; } // char else if ( ctype == 0x40 ) { if( character == -1 ) { - character = input_file_buffer[ offset ]; + character = inputFileBuffer[ offset ]; offset++; } - attribute = input_file_buffer[ offset ]; + attribute = inputFileBuffer[ offset ]; offset++; } // attr else if ( ctype == 0x80 ) { if( attribute == -1 ) { - attribute = input_file_buffer[ offset ]; + attribute = inputFileBuffer[ offset ]; offset++; } - character = input_file_buffer[ offset ]; + character = inputFileBuffer[ offset ]; offset++; } // both else { if( character == -1 ) { - character = input_file_buffer[ offset ]; + character = inputFileBuffer[ offset ]; offset++; } if( attribute == -1 ) { - attribute = input_file_buffer[ offset ]; + attribute = inputFileBuffer[ offset ]; offset++; } } @@ -191,7 +162,7 @@ void xbin(char *input, char *output, char *retinaout, bool createRetinaRep) } // read uncompressed xbin else { - while(offset < input_file_size && position_y != xbin_height ) + while(offset < inputFileSize && position_y != xbin_height ) { if (position_x == xbin_width) { @@ -199,8 +170,8 @@ void xbin(char *input, char *output, char *retinaout, bool createRetinaRep) position_y++; } - character = input_file_buffer[offset]; - attribute = input_file_buffer[offset+1]; + character = inputFileBuffer[offset]; + attribute = inputFileBuffer[offset+1]; color_background = (attribute & 240) >> 4; color_foreground = attribute & 15; diff --git a/src/loaders/xbin.h b/src/loaders/xbin.h @@ -14,6 +14,6 @@ #ifndef xbin_h #define xbin_h -void xbin(char *input, char *output, char *retinaout, bool createRetinaRep); +void xbin(unsigned char *inputFileBuffer, int32_t inputFileSize, char *output, char *retinaout, bool createRetinaRep); #endif diff --git a/src/main.c b/src/main.c @@ -10,6 +10,7 @@ // #define _XOPEN_SOURCE 700 +#include <sys/stat.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -134,9 +135,7 @@ int main(int argc, char *argv[]) { bool fileIsTundra = false; int getoptFlag; - char *bits = NULL; char *mode = NULL; - char *columns = NULL; char *font = NULL; char *input = NULL, *output = NULL; @@ -146,7 +145,11 @@ int main(int argc, char *argv[]) { const char *errstr; - int32_t int_bits, int_columns; + // default to 8 if bits option is not specified + int32_t bits = 8; + + // default to 160 if columns option is not specified + int32_t columns = 160; if (pledge("stdio cpath rpath wpath", NULL) == -1) { err(EXIT_FAILURE, "pledge"); @@ -155,10 +158,24 @@ int main(int argc, char *argv[]) { while ((getoptFlag = getopt(argc, argv, "b:c:ef:him:o:rsv")) != -1) { switch(getoptFlag) { case 'b': - bits = optarg; + // convert numeric command line flags to integer values + bits = strtonum(optarg, 8, 9, &errstr); + + if (errstr) { + printf("\nInvalid value for bits.\n\n"); + return EXIT_FAILURE; + } + break; case 'c': - columns = optarg; + // convert numeric command line flags to integer values + columns = strtonum(optarg, 1, 8192, &errstr); + + if (errstr) { + printf("\nInvalid value for columns.\n\n"); + return EXIT_FAILURE; + } + break; case 'e': listExamples(); @@ -235,37 +252,11 @@ int main(int argc, char *argv[]) { snprintf(retinaout, retinaLen, "%s%s", outputName, "@2x.png"); } - // default to 8 if bits option is not specified - if (bits) { - // convert numeric command line flags to integer values - int_bits = strtonum(bits, 8, 9, &errstr); - - if (errstr) { - printf("\nInvalid value for bits.\n\n"); - return EXIT_FAILURE; - } - } else { - int_bits = 8; - } - // default to empty string if mode option is not specified if (!mode) { mode = ""; } - // default to 160 if columns option is not specified - if (columns) { - // convert numeric command line flags to integer values - int_columns = strtonum(columns, 1, 8192, &errstr); - - if (errstr) { - printf("\nInvalid value for columns.\n\n"); - return EXIT_FAILURE; - } - } else { - int_columns = 160; - } - // default to 80x25 font if font option is not specified if (!font) { font = "80x25"; @@ -283,30 +274,64 @@ int main(int argc, char *argv[]) { char *fext = strrchr(input, '.'); fext = fext ? strtolower(strdup(fext)) : ""; + // load input file + FILE *input_file = fopen(input, "r"); + if (input_file == NULL) { + fputs("\nFile error.\n\n", stderr); exit (1); + } + + // get the file size (bytes) + struct stat input_file_stat; + stat (input, &input_file_stat); + size_t inputFileSize=input_file_stat.st_size; + + // next up is loading our file into a dynamically allocated memory buffer + unsigned char *inputFileBuffer; + + // allocate memory to contain the whole file + inputFileBuffer = (unsigned char *) malloc(sizeof(unsigned char)*inputFileSize); + if (inputFileBuffer == NULL) { + fputs ("\nMemory error.\n\n", stderr); exit (2); + } + + // copy the file into the buffer + if (fread(inputFileBuffer, 1, inputFileSize, input_file) != inputFileSize) { + fputs ("\nReading error.\n\n", stderr); exit (3); + } // whole file is now loaded into inputFileBuffer + + // adjust the file size if file contains a SAUCE record + if(fileHasSAUCE) { + sauce *saucerec = sauceReadFile(input_file); + inputFileSize -= 129 - ( saucerec->comments > 0 ? 5 + 64 * saucerec->comments : 0); + } + + // close input file, we don't need it anymore + fclose(input_file); + // create the output file by invoking the appropiate function if (!strcmp(fext, ".pcb")) { // params: input, output, font, bits, icecolors - pcboard(input, outputFile, retinaout, font, int_bits, createRetinaRep); + pcboard(inputFileBuffer, inputFileSize, outputFile, retinaout, font, bits, createRetinaRep); fileIsPCBoard = true; } else if (!strcmp(fext, ".bin")) { // params: input, output, columns, font, bits, icecolors - binary(input, outputFile, retinaout, int_columns, font, int_bits, icecolors, createRetinaRep); + binary(inputFileBuffer, inputFileSize, outputFile, retinaout, columns, font, bits, icecolors, createRetinaRep); fileIsBinary = true; } else if (!strcmp(fext, ".adf")) { // params: input, output, bits - artworx(input, outputFile, retinaout, createRetinaRep); + artworx(inputFileBuffer, inputFileSize, outputFile, retinaout, createRetinaRep); } else if (!strcmp(fext, ".idf")) { // params: input, output, bits - icedraw(input, outputFile, retinaout, fileHasSAUCE, createRetinaRep); + icedraw(inputFileBuffer, inputFileSize, outputFile, retinaout, createRetinaRep); } else if (!strcmp(fext, ".tnd")) { - tundra(input, outputFile, retinaout, font, int_bits, fileHasSAUCE, createRetinaRep); + tundra(inputFileBuffer, inputFileSize, outputFile, retinaout, font, bits, createRetinaRep); fileIsTundra = true; } else if (!strcmp(fext, ".xb")) { // params: input, output, bits - xbin(input, outputFile, retinaout, createRetinaRep); + xbin(inputFileBuffer, inputFileSize, outputFile, retinaout, createRetinaRep); } else { // params: input, output, font, bits, icecolors, fext - ansi(input, outputFile, retinaout, font, int_bits, mode, icecolors, fext, createRetinaRep); + ansi(inputFileBuffer, inputFileSize, outputFile, retinaout, font, bits, mode, icecolors, fext, createRetinaRep); fileIsANSi = true; } @@ -314,13 +339,13 @@ int main(int argc, char *argv[]) { if (fileIsANSi || fileIsBinary || fileIsPCBoard || fileIsTundra) { printf("Font: %s\n", font); - printf("Bits: %d\n", int_bits); + printf("Bits: %d\n", bits); } if (icecolors && (fileIsANSi || fileIsBinary)) { printf("iCE Colors: enabled\n"); } if (fileIsBinary) { - printf("Columns: %d\n", int_columns); + printf("Columns: %d\n", columns); } }