1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-30 07:43:03 +04:00

Merge pull request #27741 from dkurt:libpng_1.6.45

libpng upgrade to 1.6.45 and cICP metadata support for PNG imwrite #27741

### Pull Request Readiness Checklist

resolves #24185

libpng docs: https://www.w3.org/TR/png-3/#cICP-chunk
similar code from ffmpeg: https://github.com/FFmpeg/FFmpeg/blob/a700f0f72d1f073e5adcfbb16f4633850b0ef51c/libavcodec/pngenc.c#L452-L456

So issue #24185 can be solved by replacing `cv.imwrite` in user's code to `cv.imwriteWithMetadata`:
```python
cv.imwriteWithMetadata("frame.png", frame, [cv.IMAGE_METADATA_CICP], np.array([[9, 18, 0, 1]], np.uint8))
```
```
$ exiftool /home/d.kurtaev/opencv_build/frames_pr/image_38.png
ExifTool Version Number         : 12.76
File Name                       : image_38.png
Directory                       : /home/d.kurtaev/opencv_build/frames_pr
File Size                       : 3.8 MB
File Modification Date/Time     : 2025:09:02 20:48:22+03:00
File Access Date/Time           : 2025:09:02 20:48:22+03:00
File Inode Change Date/Time     : 2025:09:02 20:48:22+03:00
File Permissions                : -rw-r--r--
File Type                       : PNG
File Type Extension             : png
MIME Type                       : image/png
Image Width                     : 1080
Image Height                    : 1920
Bit Depth                       : 8
Color Type                      : RGB
Compression                     : Deflate/Inflate
Filter                          : Adaptive
Interlace                       : Noninterlaced
Color Primaries                 : BT.2020, BT.2100
Transfer Characteristics        : BT.2100 HLG, ARIB STD-B67
Matrix Coefficients             : Identity matrix
Video Full Range Flag           : 1
Image Size                      : 1080x1920
Megapixels                      : 2.1
```

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
Dmitry Kurtaev
2025-09-08 09:49:26 +03:00
committed by GitHub
parent e22c1065ec
commit 65cb3fd86c
37 changed files with 615 additions and 565 deletions
+11
View File
@@ -901,6 +901,7 @@ PngEncoder::PngEncoder()
m_support_metadata[IMAGE_METADATA_EXIF] = true;
m_support_metadata[IMAGE_METADATA_XMP] = true;
m_support_metadata[IMAGE_METADATA_ICCP] = true;
m_support_metadata[IMAGE_METADATA_CICP] = true;
op_zstream1.zalloc = NULL;
op_zstream2.zalloc = NULL;
next_seq_num = 0;
@@ -1116,6 +1117,16 @@ bool PngEncoder::write( const Mat& img, const std::vector<int>& params )
#endif
static_cast<png_uint_32>(iccp.size()));
}
std::vector<uchar>& cicp = m_metadata[IMAGE_METADATA_CICP];
if (!cicp.empty()) {
#ifdef PNG_cICP_SUPPORTED
CV_CheckEQ((size_t)4, cicp.size(), "The cICP chunk consists of four 1-byte unsigned integers");
png_set_cICP(png_ptr, info_ptr, cicp[0], cicp[1], cicp[2], cicp[3]);
#else
CV_LOG_WARNING(NULL, "Libpng is too old and does not support cICP.");
#endif
}
}
png_write_info( png_ptr, info_ptr );