avoid callling TIFFs global structures ref #2391

This commit is contained in:
artemp 2014-09-05 12:30:33 +01:00
parent aea77a7155
commit 3cb047fc5c

View file

@ -150,7 +150,6 @@ private:
void read_stripped(unsigned x,unsigned y,image_data_32& image);
void read_tiled(unsigned x,unsigned y,image_data_32& image);
TIFF* open(std::istream & input);
static void on_error(const char* , const char* fmt, va_list argptr);
};
namespace
@ -204,29 +203,17 @@ tiff_reader<T>::tiff_reader(char const* data, std::size_t size)
init();
}
template <typename T>
void tiff_reader<T>::on_error(const char* , const char* fmt, va_list argptr)
{
char msg[10240];
vsprintf(msg, fmt, argptr);
throw image_reader_exception(msg);
}
template <typename T>
void tiff_reader<T>::init()
{
// avoid calling TIFFs global structures
TIFFSetWarningHandler(0);
// Note - we intentially set the error handling to null
// when opening the image for the first time to avoid
// leaking in TiffOpen: https://github.com/mapnik/mapnik/issues/1783
TIFFSetErrorHandler(0);
TIFF* tif = open(stream_);
if (!tif) throw image_reader_exception("Can't open tiff file");
TIFFSetErrorHandler(on_error);
char msg[1024];
if (TIFFRGBAImageOK(tif,msg))