libansilove

Library for converting ANSI, ASCII, and other formats to PNG
Log | Files | Refs | README | LICENSE

commit ba23a93940612da60479c95646ecce29667e9f05
parent cdab91515752f8ecf5fe2fae0c0d647780185173
Author: Frederic Cambus <fred@statdns.com>
Date:   Thu,  4 Oct 2018 10:33:56 +0200

Introduce and use ADF_HEADER_LENGTH and IDF_HEADER_LENGTH macros

Diffstat:
Msrc/loaders/artworx.c | 6++++--
Msrc/loaders/icedraw.c | 6++++--
2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/loaders/artworx.c b/src/loaders/artworx.c @@ -11,13 +11,15 @@ #include "../ansilove.h" +#define ADF_HEADER_LENGTH 4289 /* 192 + 4096 + 1 */ + int ansilove_artworx(struct ansilove_ctx *ctx, struct ansilove_options *options) { // libgd image pointers gdImagePtr canvas; // create ADF instance - canvas = gdImageCreate(640, (((ctx->length - 192 - 4096 -1) / 2) / 80) * 16); + canvas = gdImageCreate(640, (((ctx->length - ADF_HEADER_LENGTH) / 2) / 80) * 16); // error output if (!canvas) { @@ -44,7 +46,7 @@ int ansilove_artworx(struct ansilove_ctx *ctx, struct ansilove_options *options) // process ADF uint32_t column = 0, row = 0; uint32_t character, attribute, foreground, background; - loop = 192 + 4096 + 1; + loop = ADF_HEADER_LENGTH; while (loop < ctx->length) { if (column == 80) { diff --git a/src/loaders/icedraw.c b/src/loaders/icedraw.c @@ -11,6 +11,8 @@ #include "../ansilove.h" +#define IDF_HEADER_LENGTH 4144 /* 4096 + 48 */ + int ansilove_icedraw(struct ansilove_ctx *ctx, struct ansilove_options *options) { // extract relevant part of the IDF header, 16-bit endian unsigned short @@ -32,7 +34,7 @@ int ansilove_icedraw(struct ansilove_ctx *ctx, struct ansilove_options *options) uint16_t idf_data, idf_data_length; - while (loop < ctx->length - 4096 - 48) { + while (loop < ctx->length - IDF_HEADER_LENGTH) { memcpy(&idf_data, ctx->buffer+loop, 2); // RLE compressed data @@ -109,7 +111,7 @@ int ansilove_icedraw(struct ansilove_ctx *ctx, struct ansilove_options *options) background = (attribute & 240) >> 4; foreground = attribute & 15; - drawchar(canvas, ctx->buffer+(ctx->length - 48 - 4096), 8, 16, column, row, colors[background], colors[foreground], character); + drawchar(canvas, ctx->buffer+(ctx->length - IDF_HEADER_LENGTH), 8, 16, column, row, colors[background], colors[foreground], character); column++; }