Browse Source

Fix crash when trying to write 16-bit TIFF file (LP bug 1222922)

Note: does not actually add support for writing 16-bit tifs; Panda just doesn't crash but automatically downsamples to 8-bit.
rdb 9 years ago
parent
commit
2ac1734566
2 changed files with 3 additions and 2 deletions
  1. 1 0
      doc/ReleaseNotes
  2. 2 2
      panda/src/pnmimagetypes/pnmFileTypeTIFF.cxx

+ 1 - 0
doc/ReleaseNotes

@@ -76,6 +76,7 @@ remained in the 1.9.1 release, including:
 * Fix constant reloading of texture when gl-ignore-mipmaps is set
 * BamReader now releases the GIL (so it can be used threaded)
 * Fix AttributeError in direct.stdpy.threading module
+* Fix crash when writing 16-bit .tif file (now silently downsamples)
 
 ------------------------  RELEASE 1.9.1  ------------------------
 

+ 2 - 2
panda/src/pnmimagetypes/pnmFileTypeTIFF.cxx

@@ -1114,13 +1114,13 @@ write_data(xel *array, xelval *alpha) {
       bytesperrow = _x_size * samplesperpixel;
     } else if ( grayscale ) {
       samplesperpixel = 1;
-      bitspersample = pm_maxvaltobits( _maxval );
+      bitspersample = min(8, pm_maxvaltobits(_maxval));
       photometric = PHOTOMETRIC_MINISBLACK;
       i = 8 / bitspersample;
       bytesperrow = ( _x_size + i - 1 ) / i;
     } else {
       samplesperpixel = 1;
-      bitspersample = 8;
+      bitspersample = min(8, pm_maxvaltobits(_maxval));
       photometric = PHOTOMETRIC_PALETTE;
       bytesperrow = _x_size;
     }