about summary refs log tree commit diff
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2015-04-05 20:29:37 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2015-04-05 20:29:37 +0000
commit6fda73953a3bd305ae398b4ab9acecb68ab2bc9c (patch)
tree845703453966d9fa17c6bb9009695ef6ad5941c0
parent054dbf6d7e0f65b0d528716a5f9b3ca197f3a5b1 (diff)
downloadnetpbm-mirror-6fda73953a3bd305ae398b4ab9acecb68ab2bc9c.tar.gz
netpbm-mirror-6fda73953a3bd305ae398b4ab9acecb68ab2bc9c.tar.xz
netpbm-mirror-6fda73953a3bd305ae398b4ab9acecb68ab2bc9c.zip
Fix recent bug from subtracting two unsigned ints; round properly
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@2450 9d0c8265-081b-0410-96cb-a4ca84ce46f8
-rw-r--r--converter/ppm/ppmtoarbtxt.c14
-rw-r--r--doc/HISTORY5
2 files changed, 14 insertions, 5 deletions
diff --git a/converter/ppm/ppmtoarbtxt.c b/converter/ppm/ppmtoarbtxt.c
index 569f5ea2..93b3605b 100644
--- a/converter/ppm/ppmtoarbtxt.c
+++ b/converter/ppm/ppmtoarbtxt.c
@@ -18,6 +18,7 @@
   #include <printf.h>  /* Necessary for parse_printf_format() */
 #endif
 
+#include "pm_c_util.h"
 #include "mallocvar.h"
 #include "nstring.h"
 #include "shhopt.h"
@@ -219,12 +220,15 @@ writeIcol(FILE *           const ofP,
           SkeletonObject * const objectP,
           double           const value) {
 
+    /* Unlike Netpbm, the output format does not have an upper limit for
+       maxval.  Here we allow all values representable by unsigned int.
+    */
+
     struct Icdat * const icdataP = &objectP->odata.icolData;
-    
-    fprintf(ofP, icdataP->icformat,
-            (unsigned int)
-            (icdataP->icolmin
-             + (icdataP->icolmax - icdataP->icolmin) * value));
+    unsigned int const outValue = icdataP->icolmin +
+        ROUNDU(((double) icdataP->icolmax - icdataP->icolmin) * value);
+
+    fprintf(ofP, icdataP->icformat, outValue);
 }
 
 
diff --git a/doc/HISTORY b/doc/HISTORY
index a9daac86..f7fd788d 100644
--- a/doc/HISTORY
+++ b/doc/HISTORY
@@ -6,6 +6,11 @@ CHANGE HISTORY
 
 not yet  BJH  Release 10.71.00
 
+              ppmtoarbtxt: fix bug: wrong output when high numbers represent
+              darker.  Broken in Netpbm 10.69 (November 2014).
+
+              ppmtoarbtxt: better rounding in sample values.
+
               makeman: deal properly with backlash in source.  Thanks Willem
               van Schaik <willem@schaik.com>.