ansilove

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

commit 04cfca15557254bb61f2aac7c23c33dbe492534d
parent f000c590e9058ea2aa788c76d6d055ffa42882e0
Author: Frederic Cambus <fred@statdns.com>
Date:   Sun, 16 Apr 2017 21:52:48 +0200

Create a retina function instead of duplicating code in all loaders

Diffstat:
MCMakeLists.txt | 2+-
Msrc/ansilove.h | 1+
Msrc/loaders/ansi.c | 19++-----------------
Msrc/loaders/artworx.c | 19++-----------------
Msrc/loaders/binary.c | 19++-----------------
Msrc/loaders/icedraw.c | 19++-----------------
Msrc/loaders/pcboard.c | 16+---------------
Msrc/loaders/tundra.c | 19++-----------------
Msrc/loaders/xbin.c | 19++-----------------
Asrc/retina.c | 30++++++++++++++++++++++++++++++
Asrc/retina.h | 21+++++++++++++++++++++
11 files changed, 66 insertions(+), 118 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/strtolower.c src/sauce.c) +set(SRC src/main.c src/fonts.c src/ansilove.c src/explode.c src/strtolower.c src/retina.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.h b/src/ansilove.h @@ -19,6 +19,7 @@ #include "config.h" #include "fonts.h" #include "explode.h" +#include "retina.h" #include "sauce.h" #ifndef HAVE_STRTONUM diff --git a/src/loaders/ansi.c b/src/loaders/ansi.c @@ -517,23 +517,8 @@ void ansi(unsigned char *inputFileBuffer, int32_t inputFileSize, char *output, c fclose(file_Out); // in case Retina image output is wanted - if (createRetinaRep) - { - gdImagePtr im_RetinaANSi; - - // make the Retina image @2x as large as im_ANSi - im_RetinaANSi = gdImageCreate(im_ANSi->sx * 2, im_ANSi->sy * 2); - - gdImageCopyResized(im_RetinaANSi, im_ANSi, 0, 0, 0, 0, - im_RetinaANSi->sx, im_RetinaANSi->sy, - im_ANSi->sx, im_ANSi->sy); - - // create retina output image - FILE *file_RetinaOut = fopen(retinaout, "wb"); - gdImagePng(im_RetinaANSi, file_RetinaOut); - fclose(file_RetinaOut); - - gdImageDestroy(im_RetinaANSi); + if (createRetinaRep) { + retina(im_ANSi, retinaout); } // free memory diff --git a/src/loaders/artworx.c b/src/loaders/artworx.c @@ -86,23 +86,8 @@ void artworx(unsigned char *inputFileBuffer, int32_t inputFileSize, char *output fclose(file_Out); // in case Retina image output is wanted - if (createRetinaRep) - { - gdImagePtr im_RetinaANSi; - - // make the Retina image @2x as large as im_ADF - im_RetinaANSi = gdImageCreate(im_ADF->sx * 2, im_ADF->sy * 2); - - gdImageCopyResized(im_RetinaANSi, im_ADF, 0, 0, 0, 0, - im_RetinaANSi->sx, im_RetinaANSi->sy, - im_ADF->sx, im_ADF->sy); - - // create retina output image - FILE *file_RetinaOut = fopen(retinaout, "wb"); - gdImagePng(im_RetinaANSi, file_RetinaOut); - fclose(file_RetinaOut); - - gdImageDestroy(im_RetinaANSi); + if (createRetinaRep) { + retina(im_ADF, retinaout); } // nuke garbage diff --git a/src/loaders/binary.c b/src/loaders/binary.c @@ -90,23 +90,8 @@ void binary(unsigned char *inputFileBuffer, int32_t inputFileSize, char *output, fclose(file_Out); // in case Retina image output is wanted - if (createRetinaRep) - { - gdImagePtr im_RetinaANSi; - - // make the Retina image @2x as large as im_Binary - im_RetinaANSi = gdImageCreate(im_Binary->sx * 2, im_Binary->sy * 2); - - gdImageCopyResized(im_RetinaANSi, im_Binary, 0, 0, 0, 0, - im_RetinaANSi->sx, im_RetinaANSi->sy, - im_Binary->sx, im_Binary->sy); - - // create retina output image - FILE *file_RetinaOut = fopen(retinaout, "wb"); - gdImagePng(im_RetinaANSi, file_RetinaOut); - fclose(file_RetinaOut); - - gdImageDestroy(im_RetinaANSi); + if (createRetinaRep) { + retina(im_Binary, retinaout); } // free memory diff --git a/src/loaders/icedraw.c b/src/loaders/icedraw.c @@ -145,23 +145,8 @@ void icedraw(unsigned char *inputFileBuffer, int32_t inputFileSize, char *output fclose(file_Out); // in case Retina image output is wanted - if (createRetinaRep) - { - gdImagePtr im_RetinaANSi; - - // make the Retina image @2x as large as im_IDF - im_RetinaANSi = gdImageCreate(im_IDF->sx * 2, im_IDF->sy * 2); - - gdImageCopyResized(im_RetinaANSi, im_IDF, 0, 0, 0, 0, - im_RetinaANSi->sx, im_RetinaANSi->sy, - im_IDF->sx, im_IDF->sy); - - // create retina output image - FILE *file_RetinaOut = fopen(retinaout, "wb"); - gdImagePng(im_RetinaANSi, file_RetinaOut); - fclose(file_RetinaOut); - - gdImageDestroy(im_RetinaANSi); + if (createRetinaRep) { + retina(im_IDF, retinaout); } // nuke garbage diff --git a/src/loaders/pcboard.c b/src/loaders/pcboard.c @@ -195,21 +195,7 @@ void pcboard(unsigned char *inputFileBuffer, int32_t inputFileSize, char *output // in case Retina image output is wanted if (createRetinaRep) { - gdImagePtr im_RetinaANSi; - - // make the Retina image @2x as large as im_PCB - im_RetinaANSi = gdImageCreate(im_PCB->sx * 2, im_PCB->sy * 2); - - gdImageCopyResized(im_RetinaANSi, im_PCB, 0, 0, 0, 0, - im_RetinaANSi->sx, im_RetinaANSi->sy, - im_PCB->sx, im_PCB->sy); - - // create retina output image - FILE *file_RetinaOut = fopen(retinaout, "wb"); - gdImagePng(im_RetinaANSi, file_RetinaOut); - fclose(file_RetinaOut); - - gdImageDestroy(im_RetinaANSi); + retina(im_PCB, retinaout); } // free memory diff --git a/src/loaders/tundra.c b/src/loaders/tundra.c @@ -184,23 +184,8 @@ void tundra(unsigned char *inputFileBuffer, int32_t inputFileSize, char *output, fclose(file_Out); // in case Retina image output is wanted - if (createRetinaRep) - { - gdImagePtr im_RetinaANSi; - - // make the Retina image @2x as large as im_Tundra - im_RetinaANSi = gdImageCreate(im_Tundra->sx * 2, im_Tundra->sy * 2); - - gdImageCopyResized(im_RetinaANSi, im_Tundra, 0, 0, 0, 0, - im_RetinaANSi->sx, im_RetinaANSi->sy, - im_Tundra->sx, im_Tundra->sy); - - // create retina output image - FILE *file_RetinaOut = fopen(retinaout, "wb"); - gdImagePng(im_RetinaANSi, file_RetinaOut); - fclose(file_RetinaOut); - - gdImageDestroy(im_RetinaANSi); + if (createRetinaRep) { + retina(im_Tundra, retinaout); } // free memory diff --git a/src/loaders/xbin.c b/src/loaders/xbin.c @@ -191,23 +191,8 @@ void xbin(unsigned char *inputFileBuffer, int32_t inputFileSize, char *output, c fclose(file_Out); // in case Retina image output is wanted - if (createRetinaRep) - { - gdImagePtr im_RetinaANSi; - - // make the Retina image @2x as large as im_XBIN - im_RetinaANSi = gdImageCreate(im_XBIN->sx * 2, im_XBIN->sy * 2); - - gdImageCopyResized(im_RetinaANSi, im_XBIN, 0, 0, 0, 0, - im_RetinaANSi->sx, im_RetinaANSi->sy, - im_XBIN->sx, im_XBIN->sy); - - // create retina output image - FILE *file_RetinaOut = fopen(retinaout, "wb"); - gdImagePng(im_RetinaANSi, file_RetinaOut); - fclose(file_RetinaOut); - - gdImageDestroy(im_RetinaANSi); + if (createRetinaRep) { + retina(im_XBIN, retinaout); } // nuke garbage diff --git a/src/retina.c b/src/retina.c @@ -0,0 +1,30 @@ +// +// retina.c +// AnsiLove/C +// +// Copyright (C) 2011-2017 Stefan Vogt, Brian Cassidy, and Frederic Cambus. +// All rights reserved. +// +// This source code is licensed under the BSD 2-Clause License. +// See the file LICENSE for details. +// + +#include "retina.h" + +void retina(gdImagePtr im_Source, char *retinaout) { + gdImagePtr im_Retina; + + // make the Retina image @2x as large as im_Source + im_Retina = gdImageCreate(im_Source->sx * 2, im_Source->sy * 2); + + gdImageCopyResized(im_Retina, im_Source, 0, 0, 0, 0, + im_Retina->sx, im_Retina->sy, + im_Source->sx, im_Source->sy); + + // create retina output image + FILE *file_RetinaOut = fopen(retinaout, "wb"); + gdImagePng(im_Retina, file_RetinaOut); + fclose(file_RetinaOut); + + gdImageDestroy(im_Retina); +} diff --git a/src/retina.h b/src/retina.h @@ -0,0 +1,21 @@ +// +// retina.h +// AnsiLove/C +// +// Copyright (C) 2011-2017 Stefan Vogt, Brian Cassidy, and 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 <gd.h> + +#ifndef retina_h +#define retina_h + +// prototypes +void retina(gdImagePtr im_Source, char *retinaout); + +#endif