Repository: opencv/opencv
File: modules/imgcodecs/src/grfmt_png.cpp (C++)

Code before:
        Mat mat_cur = Mat::zeros(img.rows, img.cols, m_type);
        uint32_t id = 0;
        uint32_t j = 0;
        uint32_t imagesize = m_width * m_height * (uint32_t)mat_cur.elemSize();
        m_is_IDAT_loaded = false;

        if (m_frame_no == 0)
        {
            m_mat_raw = Mat(img.rows, img.cols, m_type);
            m_mat_next = Mat(img.rows, img.cols, m_type);
            frameRaw.setMat(m_mat_raw);
            frameNext.setMat(m_mat_next);
            if (m_f)
                fseek(m_f, -8, SEEK_CUR);
            else
                m_buf_pos -= 8;
        }
        else
            m_mat_next.copyTo(mat_cur);

        frameCur.setMat(mat_cur);

        if (!processing_start((void*)&frameRaw, mat_cur))
            return false;

        if(setjmp(png_jmpbuf(m_png_ptr)))
            return false;

        while (true)
        {
            id = read_chunk(chunk);
            if (!id)
                return false;

            if (id == id_fcTL && m_is_IDAT_loaded)
            {
                if (!m_is_fcTL_loaded)
                {
                    m_is_fcTL_loaded = true;
                    w0 = m_width;
                    h0 = m_height;
                }

                if (processing_finish())
                {
                    if (dop == 2)
                        memcpy(frameNext.getPixels(), frameCur.getPixels(), imagesize);

                    compose_frame(frameCur.getRows(), frameRaw.getRows(), bop, x0, y0, w0, h0, mat_cur);
                    if (!delay_den)
                        delay_den = 100;

Review comment (suggestion):
i think we can delete this line which called in `processing_start()`
```
bool PngDecoder::processing_start(void* frame_ptr, const Mat& img)
{
    if (!InitPngPtr())
        return false;

    if (setjmp(png_jmpbuf(m_png_ptr)))
        return false;
.
.
.
}
```

Code after:
        Mat mat_cur = Mat::zeros(img.rows, img.cols, m_type);
        uint32_t id = 0;
        uint32_t j = 0;
        uint32_t imagesize = m_width * m_height * (uint32_t)mat_cur.elemSize();
        m_is_IDAT_loaded = false;

        if (m_frame_no == 0)
        {
            if (m_mat_raw.empty())
            {
                if (m_f)
                    fseek(m_f, -8, SEEK_CUR);
                else
                    m_buf_pos -= 8;
            }
            m_mat_raw = Mat(img.rows, img.cols, m_type);
            m_mat_next = Mat(img.rows, img.cols, m_type);
            frameRaw.setMat(m_mat_raw);
            frameNext.setMat(m_mat_next);
        }
        else
            m_mat_next.copyTo(mat_cur);

        frameCur.setMat(mat_cur);

        if (!processing_start((void*)&frameRaw, mat_cur))
            return false;

        while (true)
        {
            id = read_chunk(chunk);
            if (!id)
                return false;

            if (id == id_fcTL && m_is_IDAT_loaded)
            {
                if (!m_is_fcTL_loaded)
                {
                    m_mat_raw.copyTo(m_animation.still_image);
                }
                else
                {
                    if (processing_finish())
                    {
                        if (dop == 2)
                            memcpy(frameNext.getPixels(), frameCur.getPixels(), imagesize);

                        compose_frame(frameCur.getRows(), frameRaw.getRows(), bop, x0, y0, w0, h0, mat_cur);
                        if (!delay_den)
                            delay_den = 100;
                        m_animation.durations.push_back(cvRound(1000. * delay_num / delay_den));