mirror of
https://github.com/opencv/opencv.git
synced 2026-09-13 05:42:51 -05:00
Merge remote-tracking branch 'upstream/3.4' into merge-3.4
This commit is contained in:
@@ -301,7 +301,7 @@ CV_EXPORTS Mat imdecode( InputArray buf, int flags, Mat* dst);
|
||||
The function imencode compresses the image and stores it in the memory buffer that is resized to fit the
|
||||
result. See cv::imwrite for the list of supported formats and flags description.
|
||||
|
||||
@param ext File extension that defines the output format.
|
||||
@param ext File extension that defines the output format. Must include a leading period.
|
||||
@param img Image to be written.
|
||||
@param buf Output buffer resized to fit the compressed image.
|
||||
@param params Format-specific parameters. See cv::imwrite and cv::ImwriteFlags.
|
||||
|
||||
@@ -602,9 +602,9 @@ bool JpegEncoder::write( const Mat& img, const std::vector<int>& params )
|
||||
JpegErrorMgr jerr;
|
||||
JpegDestination dest;
|
||||
|
||||
jpeg_create_compress(&cinfo);
|
||||
cinfo.err = jpeg_std_error(&jerr.pub);
|
||||
jerr.pub.error_exit = error_exit;
|
||||
jpeg_create_compress(&cinfo);
|
||||
|
||||
if( !m_buf )
|
||||
{
|
||||
|
||||
@@ -1121,7 +1121,7 @@ bool TiffEncoder::writeLibTiff( const std::vector<Mat>& img_vec, const std::vect
|
||||
|
||||
CV_TIFF_CHECK_CALL(TIFFSetField(tif, TIFFTAG_SAMPLEFORMAT, sample_format));
|
||||
|
||||
if (page_compression != COMPRESSION_NONE)
|
||||
if (page_compression == COMPRESSION_LZW || page_compression == COMPRESSION_ADOBE_DEFLATE || page_compression == COMPRESSION_DEFLATE)
|
||||
{
|
||||
CV_TIFF_CHECK_CALL(TIFFSetField(tif, TIFFTAG_PREDICTOR, predictor));
|
||||
}
|
||||
|
||||
@@ -359,6 +359,49 @@ TEST(Imgcodecs_Tiff, read_palette_color_image)
|
||||
ASSERT_EQ(CV_8UC3, img.type());
|
||||
}
|
||||
|
||||
TEST(Imgcodecs_Tiff, readWrite_predictor)
|
||||
{
|
||||
/* see issue #21871
|
||||
*/
|
||||
const uchar sample_data[160] = {
|
||||
0xff, 0xff, 0xff, 0xff, 0x88, 0x88, 0xff, 0xff, 0x88, 0x88, 0xff, 0xff, 0xff, 0xff, 0xff, 0x88,
|
||||
0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00,
|
||||
0xff, 0x00, 0x00, 0x44, 0xff, 0xff, 0x88, 0xff, 0x33, 0x00, 0x66, 0xff, 0xff, 0x88, 0x00, 0x44,
|
||||
0x88, 0x00, 0x44, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x44, 0xff, 0xff, 0x11, 0x00, 0xff,
|
||||
0x11, 0x00, 0x88, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff,
|
||||
0x11, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x33, 0x00, 0x88, 0xff, 0x00, 0x66, 0xff,
|
||||
0x11, 0x00, 0x66, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x44, 0x33, 0x00, 0xff, 0xff,
|
||||
0x88, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff,
|
||||
0xff, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x33, 0x00, 0x00, 0x66, 0xff, 0xff,
|
||||
0xff, 0xff, 0x88, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff
|
||||
};
|
||||
|
||||
cv::Mat mat(10, 16, CV_8UC1, (void*)sample_data);
|
||||
int methods[] = {
|
||||
COMPRESSION_NONE, COMPRESSION_LZW,
|
||||
COMPRESSION_PACKBITS, COMPRESSION_DEFLATE, COMPRESSION_ADOBE_DEFLATE
|
||||
};
|
||||
for (size_t i = 0; i < sizeof(methods) / sizeof(int); i++)
|
||||
{
|
||||
string out = cv::tempfile(".tif");
|
||||
|
||||
std::vector<int> params;
|
||||
params.push_back(TIFFTAG_COMPRESSION);
|
||||
params.push_back(methods[i]);
|
||||
params.push_back(TIFFTAG_PREDICTOR);
|
||||
params.push_back(PREDICTOR_HORIZONTAL);
|
||||
|
||||
EXPECT_NO_THROW(cv::imwrite(out, mat, params));
|
||||
|
||||
const Mat img = cv::imread(out, IMREAD_UNCHANGED);
|
||||
ASSERT_FALSE(img.empty());
|
||||
|
||||
ASSERT_EQ(0, cv::norm(mat, img, cv::NORM_INF));
|
||||
|
||||
EXPECT_EQ(0, remove(out.c_str()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
|
||||
|
||||
Reference in New Issue
Block a user