1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-29 15:23:05 +04:00

Merge pull request #26714 from sturkmen72:png

Fix for png durations and memory leak #26714

### Pull Request Readiness Checklist

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
- [ ] The PR is proposed to the proper branch
- [ ] 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.
- [ ] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
Suleyman TURKMEN
2025-01-06 14:25:08 +03:00
committed by GitHub
parent 904dbe9555
commit 2aee94752a
+15 -7
View File
@@ -423,7 +423,6 @@ bool PngDecoder::readData( Mat& img )
fseek(m_f, -8, SEEK_CUR);
else
m_buf_pos -= 8;
}
else
m_mat_next.copyTo(mat_cur);
@@ -456,9 +455,9 @@ bool PngDecoder::readData( Mat& img )
memcpy(frameNext.getPixels(), frameCur.getPixels(), imagesize);
compose_frame(frameCur.getRows(), frameRaw.getRows(), bop, x0, y0, w0, h0, mat_cur);
if (delay_den < 1000)
delay_num = cvRound(1000.0 / delay_den);
m_animation.durations.push_back(delay_num);
if (!delay_den)
delay_den = 100;
m_animation.durations.push_back(cvRound(1000.*delay_num/delay_den));
if (mat_cur.channels() == img.channels())
mat_cur.copyTo(img);
@@ -514,9 +513,9 @@ bool PngDecoder::readData( Mat& img )
if (processing_finish())
{
compose_frame(frameCur.getRows(), frameRaw.getRows(), bop, x0, y0, w0, h0, mat_cur);
if (delay_den < 1000)
delay_num = cvRound(1000.0 / delay_den);
m_animation.durations.push_back(delay_num);
if (!delay_den)
delay_den = 100;
m_animation.durations.push_back(cvRound(1000.*delay_num/delay_den));
if (mat_cur.channels() == img.channels())
mat_cur.copyTo(img);
@@ -736,6 +735,15 @@ bool PngDecoder::processing_start(void* frame_ptr, const Mat& img)
{
static uint8_t header[8] = { 137, 80, 78, 71, 13, 10, 26, 10 };
if (m_png_ptr)
{
png_structp png_ptr = (png_structp)m_png_ptr;
png_infop info_ptr = (png_infop)m_info_ptr;
png_infop end_info = (png_infop)m_end_info;
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
m_png_ptr = m_info_ptr = m_end_info = nullptr;
}
png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
png_infop info_ptr = png_create_info_struct(png_ptr);