diff --git a/rtengine/imageio.cc b/rtengine/imageio.cc index e7a45ecf6..ba52c4672 100644 --- a/rtengine/imageio.cc +++ b/rtengine/imageio.cc @@ -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;