From: Andrey Kamaev Date: Tue, 29 Jan 2013 16:13:09 +0000 (+0400) Subject: Added minimal support for tiff encoder parameters and test for issue #2161 X-Git-Tag: accepted/2.0/20130307.220821~174^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b4d0dff4c597a2c2b8949dd2281f4f022894b37a;p=profile%2Fivi%2Fopencv.git Added minimal support for tiff encoder parameters and test for issue #2161 --- diff --git a/modules/highgui/src/grfmt_tiff.cpp b/modules/highgui/src/grfmt_tiff.cpp index d2321ce..07fe644 100644 --- a/modules/highgui/src/grfmt_tiff.cpp +++ b/modules/highgui/src/grfmt_tiff.cpp @@ -402,7 +402,18 @@ void TiffEncoder::writeTag( WLByteStream& strm, TiffTag tag, } #ifdef HAVE_TIFF -bool TiffEncoder::writeLibTiff( const Mat& img, const vector& /*params*/) + +static void readParam(const vector& 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& params) { int channels = img.channels(); int width = img.cols, height = img.rows; @@ -429,7 +440,9 @@ bool TiffEncoder::writeLibTiff( const Mat& img, const vector& /*params*/) 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; @@ -450,6 +463,9 @@ bool TiffEncoder::writeLibTiff( const Mat& img, const vector& /*params*/) 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) diff --git a/modules/highgui/test/test_grfmt.cpp b/modules/highgui/test/test_grfmt.cpp index 7226ebf..28d30c9 100644 --- a/modules/highgui/test/test_grfmt.cpp +++ b/modules/highgui/test/test_grfmt.cpp @@ -291,3 +291,22 @@ TEST(Highgui_Jpeg, encode_empty) 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 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