about summary refs log tree commit diff
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2021-12-31 01:15:45 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2021-12-31 01:15:45 +0000
commitb2941c9345606afc6abd7032353038040e541620 (patch)
tree0c33668283513b6a65d4de9f93fd1e5380bb2c42
parentfb7ccf223d4ea231afe10a161c3b353125669370 (diff)
downloadnetpbm-mirror-b2941c9345606afc6abd7032353038040e541620.tar.gz
netpbm-mirror-b2941c9345606afc6abd7032353038040e541620.tar.xz
netpbm-mirror-b2941c9345606afc6abd7032353038040e541620.zip
Fix bogus 'sample value exceeds maxval' failure
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@4229 9d0c8265-081b-0410-96cb-a4ca84ce46f8
-rw-r--r--doc/HISTORY3
-rw-r--r--other/pamendian.c18
2 files changed, 18 insertions, 3 deletions
diff --git a/doc/HISTORY b/doc/HISTORY
index 24448e11..0d467405 100644
--- a/doc/HISTORY
+++ b/doc/HISTORY
@@ -6,6 +6,9 @@ CHANGE HISTORY
 
 not yet  BJH  Release 10.98.00
 
+              pamendian: fix bogus "sample exceeds maxval" failure.
+              Introduced in Netpbm 10.66 (March 2014).
+
 21.12.27 BJH  Release 10.97.00
 
               Add pbnnoise.
diff --git a/other/pamendian.c b/other/pamendian.c
index 3d194a26..8826b06f 100644
--- a/other/pamendian.c
+++ b/other/pamendian.c
@@ -47,18 +47,30 @@ int main(int argc, const char ** argv) {
 
     pnm_writepaminit(&outpam);
 
+    /* We read the samples as if the maxval is 65535 so pnm_readpamrow, which
+       assumes big-endian samples, doesn't choke on a little-endian sample,
+       finding it to exceed the maxval.  (The pure way to do this would be not
+       to use libnetpbm row reading and writing facilities on little-endian
+       pseudo-Netpbm images, but this program isn't important enough to
+       justify that effort).
+    */
+    inpam.maxval = 65535;
+
     intuplerow  = pnm_allocpamrow(&inpam);
     outtuplerow = pnm_allocpamrow(&outpam);
 
-    for (row = 0; row < inpam.height; row++) {
+    for (row = 0; row < inpam.height; ++row) {
         unsigned int col;
+
         pnm_readpamrow(&inpam, intuplerow);
-        for (col = 0; col < inpam.width; col++) {
+        for (col = 0; col < inpam.width; ++col) {
             unsigned int plane;
-            for (plane = 0; plane < inpam.depth; plane++)
+
+            for (plane = 0; plane < inpam.depth; ++plane) {
                 outtuplerow[col][plane] =
                     reverseSample(intuplerow[col][plane],
                                   inpam.bytes_per_sample);
+            }
         }
         pnm_writepamrow(&outpam, outtuplerow);
     }