Windows loading of Tiff images in a cross-platform app
On 1st Oct 2017, commit #ce52cefb introduced an assumption that anyone working with TIFF images on Windows will be using Windows-specific file handling (CreateFile() / OpenFile() etc). Consequently, 'gdk_pixbuf__tiff_image_load()' got changed to accommodate this - i.e.
#ifndef G_OS_WIN32 // <--- This line added !!!
tiff = TIFFFdOpen (fd, "libpixbuf-tiff", "r");
#else // <--- and this section added !!!
/* W32 version of this function takes HANDLE.
* What's worse, the caller will close the file,
* but TIFFClose() will *also* close it, so we
* need to make a duplicate.
*/
{
HANDLE h;
if (DuplicateHandle (GetCurrentProcess (),
(HANDLE) _get_osfhandle (fd),
GetCurrentProcess (),
&h,
0,
FALSE,
DUPLICATE_SAME_ACCESS)) {
tiff = TIFFFdOpen ((intptr_t) h, "libpixbuf-tiff", "r");
if (tiff == NULL)
CloseHandle (h);
}
}
#endif
However... if you're building a cross-platform app you'll probably be trying to avoid the Windows-specific functions and carry on using 'open()' etc which works on the other platforms too...
LibTiff itself accommodates this by using a #define called AVOID_WIN32_FILEIO - which you can specify if you want to avoid using CreateFile() etc. Gdk-pixbuf probably needs to adopt something similar - e.g.
#if ( (!defined (G_OS_WIN32)) || (defined (AVOID_WIN32_FILEIO)))
tiff = TIFFFdOpen (fd, "libpixbuf-tiff", "r");
#else
// the newly added section
#endif