Fixing #4233 : "Segfault opening PREDICTOR_FLOATINGPOINT image"

Now compressed file use Deflate compression for all bit depth, and
PREDICTOR_HORIZONTAL for 8/16 bit integer images, and
PREDICTOR_FLOATINGPOINT for 32 bits float images.
This commit is contained in:
Hombre 2017-12-19 22:28:52 +01:00
parent 912f9f436b
commit 5ea5cfd943

View File

@ -1373,16 +1373,37 @@ int ImageIO::saveTIFF (Glib::ustring fname, int bps, bool uncompressed)
TIFFSetField (out, TIFFTAG_SAMPLEFORMAT, bps == 32 ? SAMPLEFORMAT_IEEEFP : SAMPLEFORMAT_UINT);
if (!uncompressed) {
TIFFSetField (out, TIFFTAG_PREDICTOR, PREDICTOR_NONE);
TIFFSetField (out, TIFFTAG_PREDICTOR, bps == 32 ? PREDICTOR_FLOATINGPOINT : PREDICTOR_HORIZONTAL);
}
if (profileData) {
TIFFSetField (out, TIFFTAG_ICCPROFILE, profileLength, profileData);
}
#if __BYTE_ORDER__==__ORDER_LITTLE_ENDIAN__
bool needsReverse = (bps == 16 || bps == 32) && exifRoot->getOrder() == rtexif::MOTOROLA;
#else
bool needsReverse = (bps == 16 || bps == 32) && exifRoot->getOrder() == rtexif::INTEL;
#endif
for (int row = 0; row < height; row++) {
getScanline (row, linebuffer, bps);
if (needsReverse) {
if (bps == 16) {
for (int i = 0; i < lineWidth; i += 2) {
char c = linebuffer[i];
linebuffer[i] = linebuffer[i + 1];
linebuffer[i + 1] = c;
}
} else {
for (int i = 0; i < lineWidth; i += 4) {
std::swap(linebuffer[i], linebuffer[i+3]);
std::swap(linebuffer[i+1], linebuffer[i+2]);
}
}
}
if (TIFFWriteScanline (out, linebuffer, row, 0) < 0) {
TIFFClose (out);
delete [] linebuffer;