about summary refs log tree commit diff
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2006-12-02 17:14:38 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2006-12-02 17:14:38 +0000
commit4dd3bf19f65a5d3d414a5fe8b2387bd02b1d535b (patch)
treea41581f119a56e6b960b6bc6060386439f48a711
parent72cab9afab6e82ff2ded34bff0c897f92ce9ff0a (diff)
downloadnetpbm-mirror-4dd3bf19f65a5d3d414a5fe8b2387bd02b1d535b.tar.gz
netpbm-mirror-4dd3bf19f65a5d3d414a5fe8b2387bd02b1d535b.tar.xz
netpbm-mirror-4dd3bf19f65a5d3d414a5fe8b2387bd02b1d535b.zip
Make pamtopnm work on multi-image stream
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@161 9d0c8265-081b-0410-96cb-a4ca84ce46f8
-rw-r--r--converter/other/pamtopnm.c59
-rw-r--r--doc/HISTORY2
2 files changed, 34 insertions, 27 deletions
diff --git a/converter/other/pamtopnm.c b/converter/other/pamtopnm.c
index cc1164da..6835b43f 100644
--- a/converter/other/pamtopnm.c
+++ b/converter/other/pamtopnm.c
@@ -108,6 +108,7 @@ main(int argc, char *argv[]) {
 
     struct cmdlineInfo cmdline;
     FILE* ifP;
+    bool eof;   /* no more images in input stream */
     struct pam inpam;   /* Input PAM image */
     struct pam outpam;  /* Output PNM image */
 
@@ -117,39 +118,45 @@ main(int argc, char *argv[]) {
 
     ifP = pm_openr(cmdline.inputFilespec);
 
-    pnm_readpaminit(ifP, &inpam, PAM_STRUCT_SIZE(tuple_type));
+    eof = FALSE;
+    while (!eof) {
+        pnm_readpaminit(ifP, &inpam, PAM_STRUCT_SIZE(tuple_type));
 
-    validateTupleType(inpam, cmdline.assume);
+        validateTupleType(inpam, cmdline.assume);
 
-    outpam = inpam;
-    outpam.file = stdout;
-    
-    if (inpam.depth < 3) {
-        outpam.depth = 1;
-        if (inpam.maxval == 1)
-            outpam.format = PBM_FORMAT;
-        else 
-            outpam.format = PGM_FORMAT;
-    } else {
-        outpam.depth = 3;
-        outpam.format = PPM_FORMAT;
-    }
+        outpam = inpam;
+        outpam.file = stdout;
+        
+        if (inpam.depth < 3) {
+            outpam.depth = 1;
+            if (inpam.maxval == 1)
+                outpam.format = PBM_FORMAT;
+            else 
+                outpam.format = PGM_FORMAT;
+        } else {
+            outpam.depth = 3;
+            outpam.format = PPM_FORMAT;
+        }
 
-    pnm_writepaminit(&outpam);
+        pnm_writepaminit(&outpam);
 
-    {
-        tuple *tuplerow;
-        
-        tuplerow = pnm_allocpamrow(&inpam);      
-        { 
-            int row;
+        {
+            tuple *tuplerow;
             
-            for (row = 0; row < inpam.height; row++) {
-                pnm_readpamrow(&inpam, tuplerow);
-                pnm_writepamrow(&outpam, tuplerow);
+            tuplerow = pnm_allocpamrow(&inpam);      
+            { 
+                int row;
+                
+                for (row = 0; row < inpam.height; row++) {
+                    pnm_readpamrow(&inpam, tuplerow);
+                    pnm_writepamrow(&outpam, tuplerow);
+                }
             }
+            pnm_freepamrow(tuplerow);        
         }
-        pnm_freepamrow(tuplerow);        
+
+        pnm_nextimage(ifP, &eof);
     }
+
     return 0;
 }
diff --git a/doc/HISTORY b/doc/HISTORY
index a7ec07c2..4496741d 100644
--- a/doc/HISTORY
+++ b/doc/HISTORY
@@ -8,7 +8,7 @@ not yet  BJH  Release 10.37.0
 
               pbmtext: Fix crash when there is only one character.
 
-              pnmcrop: work on multi-image stream.
+              pnmcrop, pamtopnm: work on multi-image stream.
               Thanks Erik Auerswald <auerswal@unix-ag.uni-kl.de>.
 
               pnmtopng: fix transparency optimization on PPM input.