Merge pull request #3371 from Beep6581/tiff_exif_fix
Exif lost when saving compressed tiff from raw on windows builds, fix…
This commit is contained in:
commit
df15f735dc
@ -1285,11 +1285,13 @@ int ImageIO::saveTIFF (Glib::ustring fname, int bps, bool uncompressed)
|
|||||||
// little hack to get libTiff to use proper byte order (see TIFFClienOpen()):
|
// little hack to get libTiff to use proper byte order (see TIFFClienOpen()):
|
||||||
const char *mode = !exifRoot ? "w" : (exifRoot->getOrder() == rtexif::INTEL ? "wl" : "wb");
|
const char *mode = !exifRoot ? "w" : (exifRoot->getOrder() == rtexif::INTEL ? "wl" : "wb");
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
wchar_t *wfilename = (wchar_t*)g_utf8_to_utf16 (fname.c_str(), -1, NULL, NULL, NULL);
|
FILE *file = g_fopen_withBinaryAndLock (fname);
|
||||||
TIFF* out = TIFFOpenW (wfilename, mode);
|
int fileno = _fileno(file);
|
||||||
g_free (wfilename);
|
int osfileno = _get_osfhandle(fileno);
|
||||||
|
TIFF* out = TIFFFdOpen (osfileno, fname.c_str(), mode);
|
||||||
#else
|
#else
|
||||||
TIFF* out = TIFFOpen(fname.c_str(), mode);
|
TIFF* out = TIFFOpen(fname.c_str(), mode);
|
||||||
|
int fileno = TIFFFileno (out);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!out) {
|
if (!out) {
|
||||||
@ -1314,7 +1316,9 @@ int ImageIO::saveTIFF (Glib::ustring fname, int bps, bool uncompressed)
|
|||||||
// TIFFOpen writes out the header and sets file pointer at position 8
|
// TIFFOpen writes out the header and sets file pointer at position 8
|
||||||
|
|
||||||
exif->write (8, buffer);
|
exif->write (8, buffer);
|
||||||
write (TIFFFileno (out), buffer + 8, exif_size);
|
|
||||||
|
write (fileno, buffer + 8, exif_size);
|
||||||
|
|
||||||
delete [] buffer;
|
delete [] buffer;
|
||||||
// let libtiff know that scanlines or any other following stuff should go
|
// let libtiff know that scanlines or any other following stuff should go
|
||||||
// at a different offset:
|
// at a different offset:
|
||||||
@ -1352,7 +1356,7 @@ int ImageIO::saveTIFF (Glib::ustring fname, int bps, bool uncompressed)
|
|||||||
TIFFSetField (out, TIFFTAG_IMAGELENGTH, height);
|
TIFFSetField (out, TIFFTAG_IMAGELENGTH, height);
|
||||||
TIFFSetField (out, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
|
TIFFSetField (out, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
|
||||||
TIFFSetField (out, TIFFTAG_SAMPLESPERPIXEL, 3);
|
TIFFSetField (out, TIFFTAG_SAMPLESPERPIXEL, 3);
|
||||||
TIFFSetField(out, TIFFTAG_ROWSPERSTRIP, height);
|
TIFFSetField (out, TIFFTAG_ROWSPERSTRIP, height);
|
||||||
TIFFSetField (out, TIFFTAG_BITSPERSAMPLE, bps);
|
TIFFSetField (out, TIFFTAG_BITSPERSAMPLE, bps);
|
||||||
TIFFSetField (out, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
|
TIFFSetField (out, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
|
||||||
TIFFSetField (out, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_UINT);
|
TIFFSetField (out, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_UINT);
|
||||||
@ -1386,6 +1390,9 @@ int ImageIO::saveTIFF (Glib::ustring fname, int bps, bool uncompressed)
|
|||||||
}
|
}
|
||||||
|
|
||||||
TIFFClose (out);
|
TIFFClose (out);
|
||||||
|
#ifdef WIN32
|
||||||
|
fclose (file);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
delete [] linebuffer;
|
delete [] linebuffer;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user