about summary refs log tree commit diff
path: root/converter/ppm
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2023-10-02 23:39:43 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2023-10-02 23:39:43 +0000
commit9552225818dfb888e895ec883afd71ae61f3e646 (patch)
tree2aa2123d0b9410b048a3b4500b1e02d40f8d8102 /converter/ppm
parent881e494f2311931b737483c597f1cd415f41794a (diff)
downloadnetpbm-mirror-9552225818dfb888e895ec883afd71ae61f3e646.tar.gz
netpbm-mirror-9552225818dfb888e895ec883afd71ae61f3e646.tar.xz
netpbm-mirror-9552225818dfb888e895ec883afd71ae61f3e646.zip
cleanup
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@4718 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'converter/ppm')
-rw-r--r--converter/ppm/ppmtopjxl.c42
1 files changed, 29 insertions, 13 deletions
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,22 +102,44 @@ 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;
 }