mirror of
https://github.com/zebrajr/opencv.git
synced 2025-12-06 00:19:46 +01:00
Fixed build with libpng older than 1.5.x
This commit is contained in:
parent
07cf36cbb0
commit
eebb15683f
|
|
@ -648,7 +648,11 @@ bool PngDecoder::readData( Mat& img )
|
|||
|
||||
png_charp icc_name;
|
||||
int compression_type;
|
||||
#if (PNG_LIBPNG_VER_MAJOR*10000 + PNG_LIBPNG_VER_MINOR*100 + PNG_LIBPNG_VER_RELEASE >= 10500)
|
||||
png_bytep icc_profile;
|
||||
#else
|
||||
png_charp icc_profile;
|
||||
#endif
|
||||
png_uint_32 icc_length;
|
||||
|
||||
if (png_get_iCCP(m_png_ptr, m_info_ptr, &icc_name, &compression_type, &icc_profile, &icc_length)) {
|
||||
|
|
@ -1028,7 +1032,11 @@ bool PngEncoder::write( const Mat& img, const std::vector<int>& params )
|
|||
if (!m_metadata.empty()) {
|
||||
std::vector<uchar>& exif = m_metadata[IMAGE_METADATA_EXIF];
|
||||
if (!exif.empty()) {
|
||||
#ifdef PNG_eXIf_SUPPORTED
|
||||
png_set_eXIf_1(png_ptr, info_ptr, static_cast<png_uint_32>(exif.size()), exif.data());
|
||||
#else
|
||||
CV_LOG_WARNING(NULL, "Libpng is too old and does not support EXIF.");
|
||||
#endif
|
||||
}
|
||||
|
||||
std::vector<uchar>& xmp = m_metadata[IMAGE_METADATA_XMP];
|
||||
|
|
@ -1045,7 +1053,7 @@ bool PngEncoder::write( const Mat& img, const std::vector<int>& params )
|
|||
std::vector<uchar> iccp = m_metadata[IMAGE_METADATA_ICCP];
|
||||
if (!iccp.empty()) {
|
||||
// PNG standard requires a profile name (null-terminated, max 79 characters, printable Latin-1)
|
||||
const char* iccp_profile_name = "ICC Profile";
|
||||
char iccp_profile_name[] = "ICC Profile";
|
||||
|
||||
// Compression type must be 0 (deflate) as per libpng docs
|
||||
int compression_type = PNG_COMPRESSION_TYPE_BASE;
|
||||
|
|
@ -1056,7 +1064,11 @@ bool PngEncoder::write( const Mat& img, const std::vector<int>& params )
|
|||
png_set_iCCP(png_ptr, info_ptr,
|
||||
iccp_profile_name,
|
||||
compression_type,
|
||||
#if (PNG_LIBPNG_VER_MAJOR*10000 + PNG_LIBPNG_VER_MINOR*100 + PNG_LIBPNG_VER_RELEASE >= 10500)
|
||||
reinterpret_cast<png_const_bytep>(iccp.data()),
|
||||
#else
|
||||
reinterpret_cast<png_charp>(iccp.data()),
|
||||
#endif
|
||||
static_cast<png_uint_32>(iccp.size()));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -452,7 +452,7 @@ TEST(Imgcodecs_Png, Read_Write_With_Exif)
|
|||
EXPECT_EQ(img2.rows, img.rows);
|
||||
EXPECT_EQ(img2.type(), imgtype);
|
||||
EXPECT_EQ(read_metadata_types, read_metadata_types2);
|
||||
EXPECT_GE(read_metadata_types.size(), 1u);
|
||||
ASSERT_GE(read_metadata_types.size(), 1u);
|
||||
EXPECT_EQ(read_metadata, read_metadata2);
|
||||
EXPECT_EQ(read_metadata_types[0], IMAGE_METADATA_EXIF);
|
||||
EXPECT_EQ(read_metadata_types.size(), read_metadata.size());
|
||||
|
|
|
|||
0
modules/imgcodecs/test/test_gdal.cpp
Executable file → Normal file
0
modules/imgcodecs/test/test_gdal.cpp
Executable file → Normal file
|
|
@ -19,7 +19,9 @@ TEST(Imgcodecs_Png, write_big)
|
|||
EXPECT_EQ(13917, img.rows);
|
||||
|
||||
vector<uchar> buff;
|
||||
ASSERT_NO_THROW(imencode(".png", img, buff, { IMWRITE_PNG_ZLIBBUFFER_SIZE, INT_MAX }));
|
||||
bool status = false;
|
||||
ASSERT_NO_THROW(status = imencode(".png", img, buff, { IMWRITE_PNG_ZLIBBUFFER_SIZE, 1024*1024 }));
|
||||
ASSERT_TRUE(status);
|
||||
#ifdef HAVE_PNG
|
||||
EXPECT_EQ((size_t)816219, buff.size());
|
||||
#else
|
||||
|
|
@ -34,7 +36,9 @@ TEST(Imgcodecs_Png, encode)
|
|||
vector<int> param;
|
||||
param.push_back(IMWRITE_PNG_COMPRESSION);
|
||||
param.push_back(3); //default(3) 0-9.
|
||||
EXPECT_NO_THROW(imencode(".png", img_gt, buff, param));
|
||||
bool status = false;
|
||||
EXPECT_NO_THROW(status = imencode(".png", img_gt, buff, param));
|
||||
ASSERT_TRUE(status);
|
||||
Mat img;
|
||||
EXPECT_NO_THROW(img = imdecode(buff, IMREAD_ANYDEPTH)); // hang
|
||||
EXPECT_FALSE(img.empty());
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user