From d38fee759928d631ea2947c67e5ee9eb347693b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hajo=20Nils=20Krabbenho=CC=88ft?= Date: Wed, 16 Sep 2015 22:04:42 +0200 Subject: [PATCH 1/2] fix crash for large BW tif images --- modules/highgui/src/grfmt_tiff.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/highgui/src/grfmt_tiff.cpp b/modules/highgui/src/grfmt_tiff.cpp index 9b05b364e..18ec116aa 100644 --- a/modules/highgui/src/grfmt_tiff.cpp +++ b/modules/highgui/src/grfmt_tiff.cpp @@ -221,6 +221,11 @@ bool TiffDecoder::readData( Mat& img ) (!is_tiled && tile_height0 == std::numeric_limits::max()) ) tile_height0 = m_height; + if(dst_bpp == 8) { + // we will use TIFFReadRGBA* functions, so allocate temporary buffer for 32bit RGBA + bpp = 8; + ncn = 4; + } const size_t buffer_size = bpp * ncn * tile_height0 * tile_width0; AutoBuffer _buffer( buffer_size ); uchar* buffer = _buffer; From 7825cbeb7d70c2e1e558808d7433ece414394177 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hajo=20Nils=20Krabbenho=CC=88ft?= Date: Wed, 16 Sep 2015 22:19:51 +0200 Subject: [PATCH 2/2] buffer_size should be in bytes, not bits --- modules/highgui/src/grfmt_tiff.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/highgui/src/grfmt_tiff.cpp b/modules/highgui/src/grfmt_tiff.cpp index 18ec116aa..78711189b 100644 --- a/modules/highgui/src/grfmt_tiff.cpp +++ b/modules/highgui/src/grfmt_tiff.cpp @@ -226,7 +226,7 @@ bool TiffDecoder::readData( Mat& img ) bpp = 8; ncn = 4; } - const size_t buffer_size = bpp * ncn * tile_height0 * tile_width0; + const size_t buffer_size = (bpp/bitsPerByte) * ncn * tile_height0 * tile_width0; AutoBuffer _buffer( buffer_size ); uchar* buffer = _buffer; ushort* buffer16 = (ushort*)buffer;