about summary refs log tree commit diff
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2011-08-20 02:15:14 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2011-08-20 02:15:14 +0000
commit867769ed48c6b42894923965dd2c2670323092ee (patch)
tree94be4dd76e93d10f47c78f442a6bc3089d450626
parent68f8361a5914cb47162cc73819f7ca75297c5ad4 (diff)
downloadnetpbm-mirror-867769ed48c6b42894923965dd2c2670323092ee.tar.gz
netpbm-mirror-867769ed48c6b42894923965dd2c2670323092ee.tar.xz
netpbm-mirror-867769ed48c6b42894923965dd2c2670323092ee.zip
Cleanup: Move stuff to pngx
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@1549 9d0c8265-081b-0410-96cb-a4ca84ce46f8
-rw-r--r--converter/other/pngtopam.c65
-rw-r--r--converter/other/pngx.c84
-rw-r--r--converter/other/pngx.h19
3 files changed, 106 insertions, 62 deletions
diff --git a/converter/other/pngtopam.c b/converter/other/pngtopam.c
index 2daa33d2..21bc7f82 100644
--- a/converter/other/pngtopam.c
+++ b/converter/other/pngtopam.c
@@ -228,26 +228,6 @@ gammaCorrectColor(pngcolor    const color,
 
 
 
-static void
-verifyFileIsPng(FILE *   const ifP,
-                size_t * const consumedByteCtP) {
-
-    unsigned char buffer[4];
-    size_t bytesRead;
-
-    bytesRead = fread(buffer, 1, sizeof(buffer), ifP);
-    if (bytesRead != sizeof(buffer))
-        pm_error("input file is empty or too short");
-
-    if (png_sig_cmp(buffer, (png_size_t) 0, (png_size_t) sizeof(buffer)) != 0)
-        pm_error("input file is not a PNG file "
-                 "(does not have the PNG signature in its first 4 bytes)");
-    else
-        *consumedByteCtP = bytesRead;
-}
-
-
-
 static unsigned int
 computePngLineSize(struct pngx * const pngxP) {
 
@@ -358,7 +338,7 @@ reader_createAllAtOnce(struct pngx * const pngxP,
 
     readerP->rowBuf = NULL;
 
-    png_read_image(pngxP->png_ptr, readerP->pngRaster);
+    pngx_readImage(pngxP, readerP->pngRaster);
 
     readerP->nextRowNum = 0;
 
@@ -433,7 +413,7 @@ reader_read(Reader * const readerP) {
         else
             retval = readerP->pngRaster[readerP->nextRowNum];
     } else {
-        png_read_row(readerP->pngxP->png_ptr, readerP->rowBuf, NULL);
+        pngx_readRow(readerP->pngxP, readerP->rowBuf, NULL);
         retval = readerP->rowBuf;
     }
 
@@ -444,43 +424,6 @@ reader_read(Reader * const readerP) {
 
 
 
-static void
-readPngInit(struct pngx * const pngxP,
-            FILE *        const ifP) {
-
-    size_t sigByteCt;
-            
-    verifyFileIsPng(ifP, &sigByteCt);
-
-    /* Declare that we already read the signature bytes */
-    pngx_setSigBytes(pngxP, (unsigned int)sigByteCt);
-
-    png_init_io(pngxP->png_ptr, ifP);
-
-    png_read_info(pngxP->png_ptr, pngxP->info_ptr);
-
-    if (pngx_bitDepth(pngxP) < 8)
-        pngx_setPacking(pngxP);
-}
-
-
-
-static void
-readPngTerm(struct pngx * const pngxP) {
-
-    png_read_end(pngxP->png_ptr, pngxP->info_ptr);
-    
-    /* Note that some of info_ptr is not defined until png_read_end() 
-       completes.  That's because it comes from chunks that are at the
-       end of the stream.  In particular, comment and time chunks may
-       be at the end.  Furthermore, they may be in both places, in
-       which case info_ptr contains different information before and
-       after png_read_end().
-    */
-}
-
-
-
 static png_uint_16
 getPngVal(const png_byte ** const pp,
           int               const bitDepth) {
@@ -1486,7 +1429,7 @@ convertpng(FILE *             const ifP,
 
     pngx_create(&pngxP, PNGX_READ, &jmpbuf);
 
-    readPngInit(pngxP, ifP);
+    pngx_readStart(pngxP, ifP);
 
     if (verbose)
         dumpPngInfo(pngxP);
@@ -1524,7 +1467,7 @@ convertpng(FILE *             const ifP,
 
     reader_destroy(rasterReaderP);
 
-    readPngTerm(pngxP);
+    pngx_readEnd(pngxP);
 
     fflush(stdout);
 
diff --git a/converter/other/pngx.c b/converter/other/pngx.c
index 5fa02d1f..b33f5ab8 100644
--- a/converter/other/pngx.c
+++ b/converter/other/pngx.c
@@ -513,6 +513,14 @@ pngx_setTrnsValue(struct pngx * const pngxP,
 
 
 void
+pngx_readInfo(struct pngx * const pngxP) {
+
+    png_read_info(pngxP->png_ptr, pngxP->info_ptr);
+}
+
+
+
+void
 pngx_writeInfo(struct pngx * const pngxP) {
 
     png_write_info(pngxP->png_ptr, pngxP->info_ptr);
@@ -520,6 +528,66 @@ pngx_writeInfo(struct pngx * const pngxP) {
 
 
 
+static void
+verifyFileIsPng(FILE *   const ifP,
+                size_t * const consumedByteCtP) {
+
+    unsigned char buffer[4];
+    size_t bytesRead;
+
+    bytesRead = fread(buffer, 1, sizeof(buffer), ifP);
+    if (bytesRead != sizeof(buffer))
+        pm_error("input file is empty or too short");
+
+    if (png_sig_cmp(buffer, (png_size_t) 0, (png_size_t) sizeof(buffer)) != 0)
+        pm_error("input file is not a PNG file "
+                 "(does not have the PNG signature in its first 4 bytes)");
+    else
+        *consumedByteCtP = bytesRead;
+}
+
+
+
+void
+pngx_readStart(struct pngx * const pngxP,
+               FILE *        const ifP) {
+
+    size_t sigByteCt;
+            
+    verifyFileIsPng(ifP, &sigByteCt);
+
+    /* Declare that we already read the signature bytes */
+    pngx_setSigBytes(pngxP, (unsigned int)sigByteCt);
+
+    png_init_io(pngxP->png_ptr, ifP);
+
+    pngx_readInfo(pngxP);
+
+    if (pngx_bitDepth(pngxP) < 8)
+        pngx_setPacking(pngxP);
+}
+
+
+
+void
+pngx_readRow(struct pngx * const pngxP,
+             png_byte *    const rowBuf,
+             png_byte *    const displayRow) {
+
+    png_read_row(pngxP->png_ptr, rowBuf, displayRow);
+}
+
+
+
+void
+pngx_readImage(struct pngx * const pngxP,
+               png_byte **   const image) {
+
+    png_read_image(pngxP->png_ptr, image);
+}
+
+
+
 void
 pngx_writeRow(struct pngx *    const pngxP,
               const png_byte * const line) {
@@ -530,6 +598,21 @@ pngx_writeRow(struct pngx *    const pngxP,
 
 
 void
+pngx_readEnd(struct pngx * const pngxP) {
+
+    /* Note that some of info_ptr is not defined until png_read_end() 
+       completes.  That's because it comes from chunks that are at the
+       end of the stream.  In particular, comment and time chunks may
+       be at the end.  Furthermore, they may be in both places, in
+       which case info_ptr contains different information before and
+       after png_read_end().
+    */
+    png_read_end(pngxP->png_ptr, pngxP->info_ptr);
+}
+
+
+
+void
 pngx_writeEnd(struct pngx * const pngxP) {
 
     png_write_end(pngxP->png_ptr, pngxP->info_ptr);
@@ -537,4 +620,3 @@ pngx_writeEnd(struct pngx * const pngxP) {
 
 
 
-
diff --git a/converter/other/pngx.h b/converter/other/pngx.h
index 7eb77cbf..10e8204d 100644
--- a/converter/other/pngx.h
+++ b/converter/other/pngx.h
@@ -208,13 +208,32 @@ pngx_setTrnsValue(struct pngx * const pngxP,
                   png_color_16  const transColorArg);
 
 void
+pngx_readInfo(struct pngx * const pngxP);
+
+void
 pngx_writeInfo(struct pngx * const pngxP);
 
 void
+pngx_readStart(struct pngx * const pngxP,
+               FILE *        const ifP);
+
+void
+pngx_readRow(struct pngx * const pngxP,
+             png_byte *    const rowBuf,
+             png_byte *    const displayRow);
+
+void
+pngx_readImage(struct pngx * const pngxP,
+               png_byte **   const image);
+
+void
 pngx_writeRow(struct pngx *    const pngxP,
               const png_byte * const line);
 
 void
+pngx_readEnd(struct pngx * const pngxP);
+
+void
 pngx_writeEnd(struct pngx * const pngxP);
 
 #endif