From 9552225818dfb888e895ec883afd71ae61f3e646 Mon Sep 17 00:00:00 2001 From: giraffedata Date: Mon, 2 Oct 2023 23:39:43 +0000 Subject: cleanup git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@4718 9d0c8265-081b-0410-96cb-a4ca84ce46f8 --- converter/ppm/ppmtopjxl.c | 42 +++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) (limited to 'converter/ppm') diff --git a/converter/ppm/ppmtopjxl.c b/converter/ppm/ppmtopjxl.c index 54ad8c07..e6d9b8f8 100644 --- a/converter/ppm/ppmtopjxl.c +++ b/converter/ppm/ppmtopjxl.c @@ -102,21 +102,43 @@ bitwidth(unsigned int v) { +/* The following belong to the bit putter. They really should be in a + struct passed to the methods of the bit putter instead. +*/ + static char *inrow; static char *outrow; /* "signed" was commented out below, but it caused warnings on an SGI compiler, which defaulted to unsigned character. 2001.03.30 BJH */ static signed char * runcnt; - -/* The following belong to the bit putter. They really should be in a - struct passed to the methods of the bit putter instead. -*/ - static int out = 0; static int cnt = 0; static int num = 0; static bool pack = false; +static void +initbits(unsigned int const bytesPerRow) { + + MALLOCARRAY(inrow, bytesPerRow); + MALLOCARRAY(outrow, bytesPerRow * 2); + MALLOCARRAY(runcnt, bytesPerRow); + + if (!inrow || !outrow || !runcnt) + pm_error("can't allocate space for row"); +} + + + +static void +termbits() { + + free(runcnt); + free(outrow); + free(inrow); +} + + + static void putbits(int const bArg, int const nArg) { @@ -495,11 +517,7 @@ main(int argc, const char * argv[]) { computeColorDownloadingMode(colorCt, cols, maxval, &bytesPerRow, &bpg, &bpb, &bpr, &pclIndex); - MALLOCARRAY(inrow, bytesPerRow); - MALLOCARRAY(outrow, bytesPerRow * 2); - MALLOCARRAY(runcnt, bytesPerRow); - if (!inrow || !outrow || !runcnt) - pm_error("can't allocate space for row"); + initbits(bytesPerRow); /* set up image details */ if (xscale != 0.0) @@ -523,9 +541,7 @@ main(int argc, const char * argv[]) { ppm_freecolorhash(cht); ppm_freecolorhist(chv); - free(runcnt); - free(outrow); - free(inrow); + termbits(); return 0; } -- cgit 1.4.1