diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2015-05-27 02:22:38 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2015-05-27 02:22:38 +0000 |
commit | e22c0eb3aec55c8bfe7817fb603d3e22507cad55 (patch) | |
tree | bcbb0791a214ee02e530721549e595d604a66ffb | |
parent | f1ba7a9d6a5b5f3fa4e29ed930d707b1e94e35b5 (diff) | |
download | netpbm-mirror-e22c0eb3aec55c8bfe7817fb603d3e22507cad55.tar.gz netpbm-mirror-e22c0eb3aec55c8bfe7817fb603d3e22507cad55.tar.xz netpbm-mirror-e22c0eb3aec55c8bfe7817fb603d3e22507cad55.zip |
cleanup
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@2525 9d0c8265-081b-0410-96cb-a4ca84ce46f8
-rw-r--r-- | converter/pbm/pbmto10x.c | 113 |
1 files changed, 81 insertions, 32 deletions
diff --git a/converter/pbm/pbmto10x.c b/converter/pbm/pbmto10x.c index 8a3edb36..d040b3ed 100644 --- a/converter/pbm/pbmto10x.c +++ b/converter/pbm/pbmto10x.c @@ -12,16 +12,14 @@ ** Modified to shorten stripes and eliminate blank stripes. Dec 1994. */ +#include <stdbool.h> + #include "pbm.h" #include "mallocvar.h" #define LOW_RES_ROWS 8 /* printed per pass */ #define HIGH_RES_ROWS 16 /* printed per pass */ -static int highres = 0; -static FILE *ifp; -static int rows, cols, format; - static void @@ -29,8 +27,6 @@ outstripe(char * const stripe, char * const sP, int const reschar) { - int ncols; - char * p; p = sP; /* initial value */ @@ -41,10 +37,14 @@ outstripe(char * const stripe, ++p; break; } - ncols = p - stripe; - if (ncols > 0) { - printf("\033%c%c%c", reschar, ncols % 256, ncols / 256); - fwrite(stripe, sizeof(char), ncols, stdout); + + { + unsigned int const ncols = p - stripe; + + if (ncols > 0) { + printf("\033%c%c%c", reschar, ncols % 256, ncols / 256); + fwrite(stripe, sizeof(char), ncols, stdout); + } } putchar('\n'); /* flush buffer */ } @@ -52,26 +52,44 @@ outstripe(char * const stripe, static void -res_60x72(void) { - int i, item, npins, row, col; - bit *bitrows[LOW_RES_ROWS], *bP[LOW_RES_ROWS]; - char *stripe, *sP; +res_60x72(FILE * const ifP, + int const rows, + int const cols, + int const format) { + + int row; + unsigned int i; + bit * bitrows[LOW_RES_ROWS]; + char *stripe; + char *sP; MALLOCARRAY(stripe, cols); if (stripe == NULL) pm_error("Unable to allocate %u bytes for a stripe buffer.", (unsigned)(cols * sizeof(stripe[0]))); + for (i = 0; i < LOW_RES_ROWS; ++i) bitrows[i] = pbm_allocrow(cols); + printf("\033A\010"); /* '\n' = 8/72 */ + for (row = 0, sP = stripe; row < rows; row += LOW_RES_ROWS, sP = stripe) { + unsigned int col; + unsigned int i; + unsigned int npins; + bit * bP[LOW_RES_ROWS]; + if (row + LOW_RES_ROWS <= rows) npins = LOW_RES_ROWS; else npins = rows - row; + for (i = 0; i < npins; ++i) - pbm_readpbmrow(ifp, bP[i] = bitrows[i], cols, format); + pbm_readpbmrow(ifP, bP[i] = bitrows[i], cols, format); + for (col = 0; col < cols; ++col) { + unsigned int item; + item = 0; for (i = 0; i < npins; ++i) if (*(bP[i]++) == PBM_BLACK) @@ -81,32 +99,52 @@ res_60x72(void) { outstripe(stripe, sP, 'K'); } printf("\033@"); + + for (i = 0; i < LOW_RES_ROWS; ++i) + pbm_freerow(bitrows[i]); + free(stripe); } static void -res_120x144(void) { - int i, pin, item, npins, row, col; - bit *bitrows[HIGH_RES_ROWS], *bP[HIGH_RES_ROWS]; - char *stripe, *sP; +res_120x144(FILE * const ifP, + int const rows, + int const cols, + int const format) { + + unsigned int i; + int row; + char *stripe; + char * sP; + bit * bitrows[HIGH_RES_ROWS]; MALLOCARRAY(stripe, cols); if (stripe == NULL) pm_error("Unable to allocate %u bytes for a stripe buffer.", (unsigned)(cols * sizeof(stripe[0]))); + for (i = 0; i < HIGH_RES_ROWS; ++i) bitrows[i] = pbm_allocrow(cols); + printf("\0333\001"); /* \n = 1/144" */ + for (row = 0, sP = stripe; row < rows; row += HIGH_RES_ROWS, sP = stripe) { + unsigned int i; + unsigned int col; + bit * bP[HIGH_RES_ROWS]; + unsigned int npins; + if (row + HIGH_RES_ROWS <= rows) npins = HIGH_RES_ROWS; else npins = rows - row; for (i = 0; i < npins; ++i) - pbm_readpbmrow(ifp, bP[i] = bitrows[i], cols, format); + pbm_readpbmrow(ifP, bP[i] = bitrows[i], cols, format); for (col = 0; col < cols; ++col) { + unsigned int pin; + unsigned int item; item = 0; /* even rows */ for (pin = i = 0; i < npins; i += 2, ++pin) @@ -115,8 +153,9 @@ res_120x144(void) { *sP++ = item; } outstripe(stripe, sP, 'L'); - sP = stripe; - for (col = 0; col < cols; ++col) { + for (col = 0, sP = stripe; col < cols; ++col) { + unsigned int pin; + unsigned int item; item = 0; /* odd rows */ for (i = 1, pin = 0; i < npins; i += 2, ++pin) @@ -128,20 +167,29 @@ res_120x144(void) { printf("\033J\016"); /* 14/144 down, \n did 1/144 */ } printf("\033@"); + + for (i = 0; i < LOW_RES_ROWS; ++i) + pbm_freerow(bitrows[i]); + free(stripe); } int -main(int argc, char * argv[]) { +main(int argc, const char ** argv) { const char * fname; + static FILE * ifP; + int rows, cols, format; + + bool isHighRes; - pbm_init( &argc, argv ); + pm_proginit(&argc, argv); + isHighRes = false; /* initial assumption */ if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'h') { - highres = 1; + isHighRes = true; --argc; ++argv; } @@ -152,17 +200,18 @@ main(int argc, char * argv[]) { else fname = "-"; - ifp = pm_openr(fname); + ifP = pm_openr(fname); - pbm_readpbminit(ifp, &cols, &rows, &format); + pbm_readpbminit(ifP, &cols, &rows, &format); - if (highres) - res_120x144(); + if (isHighRes) + res_120x144(ifP, rows, cols, format); else - res_60x72(); + res_60x72(ifP, rows, cols, format); + + pm_close(ifP); - pm_close(ifp); - exit(0); + return 0; } |