mirror of
https://github.com/opencv/opencv.git
synced 2025-01-18 06:03:15 +08:00
Added minimal support for tiff encoder parameters and test for issue #2161
This commit is contained in:
parent
3dbb98e454
commit
b4d0dff4c5
@ -402,7 +402,18 @@ void TiffEncoder::writeTag( WLByteStream& strm, TiffTag tag,
|
||||
}
|
||||
|
||||
#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;
|
||||
@ -429,7 +440,9 @@ bool TiffEncoder::writeLibTiff( const Mat& img, const vector<int>& /*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<int>& /*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)
|
||||
|
@ -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<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
|
||||
|
Loading…
Reference in New Issue
Block a user