From 2ac1734566dbe5174a72b878a429b581421461ad Mon Sep 17 00:00:00 2001 From: rdb Date: Fri, 23 Dec 2016 00:36:59 +0100 Subject: [PATCH] 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. --- doc/ReleaseNotes | 1 + panda/src/pnmimagetypes/pnmFileTypeTIFF.cxx | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/ReleaseNotes b/doc/ReleaseNotes index 4ba7c0930f..3ad0ecd49b 100644 --- a/doc/ReleaseNotes +++ b/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 ------------------------ diff --git a/panda/src/pnmimagetypes/pnmFileTypeTIFF.cxx b/panda/src/pnmimagetypes/pnmFileTypeTIFF.cxx index ab09b1f034..5bfb87e5c3 100644 --- a/panda/src/pnmimagetypes/pnmFileTypeTIFF.cxx +++ b/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; }