about summary refs log tree commit diff
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2007-10-11 16:02:42 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2007-10-11 16:02:42 +0000
commit10dad0e3b2584fba5af7fc9485d2c362f8659782 (patch)
treee6acc3103ad1d291776319d971b8a11decf59292
parent21ba49d92988441424445549a4020d86dc13638b (diff)
downloadnetpbm-mirror-10dad0e3b2584fba5af7fc9485d2c362f8659782.tar.gz
netpbm-mirror-10dad0e3b2584fba5af7fc9485d2c362f8659782.tar.xz
netpbm-mirror-10dad0e3b2584fba5af7fc9485d2c362f8659782.zip
Fix bug dividing by a zero maxval
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@430 9d0c8265-081b-0410-96cb-a4ca84ce46f8
-rw-r--r--converter/other/bmptopnm.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/converter/other/bmptopnm.c b/converter/other/bmptopnm.c
index 39a90aa2..dd7be892 100644
--- a/converter/other/bmptopnm.c
+++ b/converter/other/bmptopnm.c
@@ -42,6 +42,10 @@ struct bitPosition {
 
        Example: if 16 bits are laid out as XRRRRRGGGGGBBBBB then the shift
        count for the R component is 10 and the mask is 0000000000011111.
+
+       A 'mask' of zero denotes absence of any bits; e.g. in the example
+       above, the mask for the transparency component is zero because there
+       is no transparency component .  'shift' is arbitrary in that case.
     */
     unsigned int shift;
         /* How many bits right you have to shift the value to get the subject
@@ -667,11 +671,15 @@ extractBitFields(unsigned int       const rasterval,
         (rasterval >> pixelformat.blu.shift) & pixelformat.blu.mask;
     unsigned int const abits = 
         (rasterval >> pixelformat.trn.shift) & pixelformat.trn.mask;
-    
-    *rP = (unsigned int) rbits * maxval / pixelformat.red.mask;
-    *gP = (unsigned int) gbits * maxval / pixelformat.blu.mask;
-    *bP = (unsigned int) bbits * maxval / pixelformat.grn.mask;
-    *aP = (unsigned int) abits * maxval / pixelformat.trn.mask;
+
+    *rP = pixelformat.red.mask > 0 ?
+        (unsigned int) rbits * maxval / pixelformat.red.mask : 0;
+    *gP = pixelformat.grn.mask > 0 ?
+        (unsigned int) gbits * maxval / pixelformat.grn.mask : 0;
+    *bP = pixelformat.blu.mask > 0 ?
+        (unsigned int) bbits * maxval / pixelformat.blu.mask : 0;
+    *aP = pixelformat.trn.mask > 0 ?
+        (unsigned int) abits * maxval / pixelformat.trn.mask : 0;
 }