}
#ifdef HAVE_TIFF
-bool TiffEncoder::writeLibTiff( const Mat& img, const vector<int>& /*params*/)
+
+static void readParam(const vector<int>& params, int key, int& value)
+{
+ for(size_t i = 0; i + 1 < params.size(); i += 2)
+ if(params[i] == key)
+ {
+ value = params[i+1];
+ break;
+ }
+}
+
+bool TiffEncoder::writeLibTiff( const Mat& img, const vector<int>& params)
{
int channels = img.channels();
int width = img.cols, height = img.rows;
const int bitsPerByte = 8;
size_t fileStep = (width * channels * bitsPerChannel) / bitsPerByte;
+
int rowsPerStrip = (int)((1 << 13)/fileStep);
+ readParam(params, TIFFTAG_ROWSPERSTRIP, rowsPerStrip);
if( rowsPerStrip < 1 )
rowsPerStrip = 1;
int compression = COMPRESSION_LZW;
int predictor = PREDICTOR_HORIZONTAL;
+ readParam(params, TIFFTAG_COMPRESSION, compression);
+ readParam(params, TIFFTAG_PREDICTOR, predictor);
+
int colorspace = channels > 1 ? PHOTOMETRIC_RGB : PHOTOMETRIC_MINISBLACK;
if ( !TIFFSetField(pTiffHandle, TIFFTAG_IMAGEWIDTH, width)
ASSERT_THROW(cv::imencode(".jpg", img, jpegImg), cv::Exception);
}
#endif
+
+
+#ifdef HAVE_TIFF
+#include "tiff.h"
+TEST(Highgui_Tiff, decode_tile16384x16384)
+{
+ // see issue #2161
+ cv::Mat big(16384, 16384, CV_8UC1, cv::Scalar::all(0));
+ string file = cv::tempfile(".tiff");
+ std::vector<int> params;
+ params.push_back(TIFFTAG_ROWSPERSTRIP);
+ params.push_back(big.rows);
+ cv::imwrite(file, big, params);
+ big.release();
+
+ EXPECT_NO_THROW(cv::imread(file));
+ remove(file.c_str());
+}
+#endif