nareshmlx/opencv-pr huggingface dataset:
**File:** modules/dnn/src/layers/topk2_layer.cpp
**Change Type:** added
**Context:** PR #27547: Added TopK layer with dynamic K support for new DNN engine

**Code Changes:**
```diff
@@ -0,0 +1,218 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+
+#include "../precomp.hpp"
+#include <opencv2/dnn/shape_utils.hpp>
+
+namespace cv { namespace dnn {
+
```

Review comment:
this is very suspicious place. Subsequent offset values inside loop form arithmetic progression (for fixed b). You add this offset to data inside cmp.addOffset(), so data addresses form geometric progression. It's wrong, they should form arithmetic progression as well. That's why I suggest you to remove addOffset and minusOffset and pass the proper data pointer to comparator constructor, which you need to place inside the inner loop.
**File:** modules/dnn/src/layers/topk2_layer.cpp
**Change Type:** added
**Context:** PR #27547: Added TopK layer with dynamic K support for new DNN engine

**Code Changes:**
```diff
@@ -0,0 +1,218 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+
+#include "../precomp.hpp"
+#include <opencv2/dnn/shape_utils.hpp>
+
+namespace cv { namespace dnn {
+
```

Review comment:
1) add CV_16BF branch as well 2) sorting hfloat's on x86 and sorting bfloat's on any platform will be slow because there is no support in hardware for scalar arithmetics on such types. Add yet another parameter, WT (work type) to the template method, set it to the type itself for all types except for hfloat and bfloat. For hfloat and bfloat set it to float. 3) in the comment above I recommended you to cache sorted values into a temporary buffer. Use WT for elements of that buffer.
**File:** modules/dnn/src/layers/topk2_layer.cpp
**Change Type:** added
**Context:** PR #27547: Added TopK layer with dynamic K support for new DNN engine

**Code Changes:**
```diff
@@ -0,0 +1,218 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+
+#include "../precomp.hpp"
+#include <opencv2/dnn/shape_utils.hpp>
+
+namespace cv { namespace dnn {
+
```

Review comment:
I suggest you to construct `ComparatorGreater<T>` or `ComparatorLess<T>` (actually, it should be WT instead of T, see the comment below) inside FindTopK(), depending on the `largest` flag. This way you reduce the amount of code with basically no loss in efficiency, you will have just one switch
**File:** modules/dnn/src/layers/topk2_layer.cpp
**Change Type:** added
**Context:** PR #27547: Added TopK layer with dynamic K support for new DNN engine

**Code Changes:**
```diff
@@ -0,0 +1,218 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+
+#include "../precomp.hpp"
+#include <opencv2/dnn/shape_utils.hpp>
+
+namespace cv { namespace dnn {
+
```

Review comment:
modify it to take 2 `std::pair<>` and don't use indirect access to data: ``` template <typename T, typename VT> class ComparatorLess { using value_type = std::pair<T, VT> bool operator() (const value_type& a, const value_type& b) const { return (a.second < b.second || (a.second == b.second && a.first < b.first); } }; ... ```
**File:** modules/dnn/src/layers/topk2_layer.cpp
**Change Type:** added
**Context:** PR #27547: Added TopK layer with dynamic K support for new DNN engine

**Code Changes:**
```diff
@@ -0,0 +1,218 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+
+#include "../precomp.hpp"
+#include <opencv2/dnn/shape_utils.hpp>
+
+namespace cv { namespace dnn {
+
```

Review comment:
simply pass cmp here
**File:** modules/dnn/src/layers/topk2_layer.cpp
**Change Type:** added
**Context:** PR #27547: Added TopK layer with dynamic K support for new DNN engine

**Code Changes:**
```diff
@@ -0,0 +1,218 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+
+#include "../precomp.hpp"
+#include <opencv2/dnn/shape_utils.hpp>
+
+namespace cv { namespace dnn {
+
```

Review comment:
no need to pass data pointer into the constructor anymore
**File:** modules/dnn/src/layers/topk2_layer.cpp
**Change Type:** added
**Context:** PR #27547: Added TopK layer with dynamic K support for new DNN engine

**Code Changes:**
```diff
@@ -0,0 +1,218 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+
+#include "../precomp.hpp"
+#include <opencv2/dnn/shape_utils.hpp>
+
+namespace cv { namespace dnn {
+
```

Review comment:
it should be `std::pair<uint32_t, WT>` instead
**File:** modules/dnn/src/layers/topk2_layer.cpp
**Change Type:** added
**Context:** PR #27547: Added TopK layer with dynamic K support for new DNN engine

**Code Changes:**
```diff
@@ -0,0 +1,218 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html.
+
+#include "../precomp.hpp"
+#include <opencv2/dnn/shape_utils.hpp>
+
+namespace cv { namespace dnn {
+
```

Review comment:
cast T => WT: `sortbuf[u].second = WT(inPtr[offset + u * inner]);`
**File:** modules/imgcodecs/src/grfmt_png.cpp
**Change Type:** modified
**Context:** PR #27503: [GSOC 2025] PNG&WebP Metadata Reading Writing Improvements

**Code Changes:**
```diff
@@ -218,16 +218,14 @@ bool PngDecoder::InitPngPtr() {
         return false;
 
     m_info_ptr = png_create_info_struct(m_png_ptr);
-    m_end_info = png_create_info_struct(m_png_ptr);
-    return (m_info_ptr && m_end_info);
+    return (m_info_ptr != nullptr);
 }
 
 void PngDecoder::ClearPngPtr() {
```

Review comment:
Please remove XMP from todo. It's added by the PR.
**File:** modules/imgcodecs/src/grfmt_png.cpp
**Change Type:** modified
**Context:** PR #27503: [GSOC 2025] PNG&WebP Metadata Reading Writing Improvements

**Code Changes:**
```diff
@@ -218,16 +218,14 @@ bool PngDecoder::InitPngPtr() {
         return false;
 
     m_info_ptr = png_create_info_struct(m_png_ptr);
-    m_end_info = png_create_info_struct(m_png_ptr);
-    return (m_info_ptr && m_end_info);
+    return (m_info_ptr != nullptr);
 }
 
 void PngDecoder::ClearPngPtr() {
```

Review comment:
The idea of zero separator should be documented somewhere. It's not obvious from OpenCV API how to use the key-value approach.
**File:** modules/imgcodecs/test/test_exif.cpp
**Change Type:** modified
**Context:** PR #27503: [GSOC 2025] PNG&WebP Metadata Reading Writing Improvements

**Code Changes:**
```diff
@@ -9,7 +9,142 @@
 
 namespace opencv_test { namespace {
 
-/**
+    static Mat makeCirclesImage(Size size, int type, int nbits)
+    {
+        Mat img(size, type);
+        img.setTo(Scalar::all(0));
+        RNG& rng = theRNG();
```

Review comment:
Are there images with Text and XML in PNG test suite? It'll be great to test not only with self-generated files/
**File:** modules/imgcodecs/include/opencv2/imgcodecs.hpp
**Change Type:** modified
**Context:** PR #27503: [GSOC 2025] PNG&WebP Metadata Reading Writing Improvements

**Code Changes:**
```diff
@@ -253,11 +253,13 @@ enum ImwriteGIFCompressionFlags {
 
 enum ImageMetadataType
 {
-    IMAGE_METADATA_UNKNOWN = -1,
-    IMAGE_METADATA_EXIF = 0,
-    IMAGE_METADATA_XMP = 1,
-    IMAGE_METADATA_ICCP = 2,
-    IMAGE_METADATA_MAX = 2
+    IMAGE_METADATA_UNKNOWN = -1, // Used when metadata type is unrecognized or not set
```

Review comment:
AVIF is not mentioned.
**File:** modules/imgcodecs/src/grfmt_base.cpp
**Change Type:** modified
**Context:** PR #27503: [GSOC 2025] PNG&WebP Metadata Reading Writing Improvements
**Review Line:** 60

**Code Changes:**
```diff
@@ -56,6 +56,8 @@ BaseImageDecoder::BaseImageDecoder()
     m_scale_denom = 1;
     m_use_rgb = false;
     m_frame_count = 1;
+    m_read_options = 0;
+    m_metadata.resize(IMAGE_METADATA_MAX + 1);
 }
 
 bool BaseImageDecoder::haveMetadata(ImageMetadataType type) const
@@ -67,12 +69,21 @@ bool BaseImageDecoder::haveMetadata(ImageMetadataType type) const
 
```

Review comment:
``` enum ImageMetadataType { IMAGE_METADATA_UNKNOWN = -1, // Unrecognized IMAGE_METADATA_EXIF = 0, IMAGE_METADATA_XMP = 1, IMAGE_METADATA_ICCP = 2, IMAGE_METADATA_TEXT = 3, IMAGE_METADATA_MAX = 3 // Highest legal index (NOT a count) }; ``` // Allocate metadata storage std::vector<std::vector<uchar>> m_metadata(IMAGE_METADATA_MAX + 1); // Access m_metadata[IMAGE_METADATA_EXIF]; // 0 m_metadata[IMAGE_METADATA_XMP]; // 1 m_metadata[IMAGE_METADATA_ICCP]; // 2 m_metadata[IMAGE_METADATA_TEXT]; // 3
**File:** modules/imgcodecs/test/test_exif.cpp
**Change Type:** modified
**Context:** PR #27503: [GSOC 2025] PNG&WebP Metadata Reading Writing Improvements

**Code Changes:**
```diff
@@ -9,7 +9,142 @@
 
 namespace opencv_test { namespace {
 
-/**
+    static Mat makeCirclesImage(Size size, int type, int nbits)
+    {
+        Mat img(size, type);
+        img.setTo(Scalar::all(0));
+        RNG& rng = theRNG();
```

Review comment:
Could you add some comment how you got/generated the bytes array?
**File:** modules/imgcodecs/test/test_exif.cpp
**Change Type:** modified
**Context:** PR #27503: [GSOC 2025] PNG&WebP Metadata Reading Writing Improvements

**Code Changes:**
```diff
@@ -9,7 +9,142 @@
 
 namespace opencv_test { namespace {
 
-/**
+    static Mat makeCirclesImage(Size size, int type, int nbits)
+    {
+        Mat img(size, type);
+        img.setTo(Scalar::all(0));
+        RNG& rng = theRNG();
```

Review comment:
it is generated by chatGPT. let me add a comment later.
**File:** modules/imgcodecs/test/test_exif.cpp
**Change Type:** modified
**Context:** PR #27503: [GSOC 2025] PNG&WebP Metadata Reading Writing Improvements
**Review Line:** 59

**Code Changes:**
```diff
+            '<','/','x',':','x','m','p','m','e','t','a','>',0
+        };
+    }
+
+    // Returns a Minimal ICC profile data (Generated with help from ChatGPT)
+    static std::vector<uchar> getSampleIccpData() {
+        std::vector<uchar> iccp_data(192, 0);
+
+        iccp_data[3] = 192; // Profile size: 192 bytes
+
+        iccp_data[12] = 'm';
```

Review comment:
Why do you use different ICCP metadata generators for WEBP and PNG? I would expect it's the same for different formats, is not it?
**File:** modules/imgcodecs/test/test_exif.cpp
**Change Type:** modified
**Context:** PR #27503: [GSOC 2025] PNG&WebP Metadata Reading Writing Improvements
**Review Line:** 59

**Code Changes:**
```diff
+            '<','/','x',':','x','m','p','m','e','t','a','>',0
+        };
+    }
+
+    // Returns a Minimal ICC profile data (Generated with help from ChatGPT)
+    static std::vector<uchar> getSampleIccpData() {
+        std::vector<uchar> iccp_data(192, 0);
+
+        iccp_data[3] = 192; // Profile size: 192 bytes
+
+        iccp_data[12] = 'm';
```

Review comment:
No different data was intended; it was just temporary test data and has been fixed in the latest commit.
**File:** modules/imgcodecs/test/test_exif.cpp
**Change Type:** modified
**Context:** PR #27503: [GSOC 2025] PNG&WebP Metadata Reading Writing Improvements

**Code Changes:**
```diff
@@ -9,7 +9,142 @@
 
 namespace opencv_test { namespace {
 
-/**
+    static Mat makeCirclesImage(Size size, int type, int nbits)
+    {
+        Mat img(size, type);
+        img.setTo(Scalar::all(0));
+        RNG& rng = theRNG();
```

Review comment:
There is `Imgcodecs_WebP, ReadWriteWithExifXmpIccp`. I propose to remove ad-hoc cases here. Also I propose to extent the test parameters list and add orientation check for webp too. Most probably you have to add an image to opencv_extra.
**File:** modules/imgcodecs/test/test_exif.cpp
**Change Type:** modified
**Context:** PR #27583: Jpeg Metadata (iccp and xmp)
**Review Line:** 570

**Code Changes:**
```diff
     EXPECT_EQ(exif.type(), CV_8U);
     EXPECT_EQ(exif.total(), exif_size);
     ASSERT_GE(exif_size, 26u); // minimal exif should take at least 26 bytes
                                  // (the header + IDF0 with at least 1 entry).
     EXPECT_TRUE(exif.data[0] == 'I' || exif.data[0] == 'M');
     EXPECT_EQ(exif.data[0], exif.data[1]);
     EXPECT_EQ(locateString(exif.data, exif_size, pattern), ploc);
+
+    if (metadata_types.size() > IMAGE_METADATA_XMP)
+    {
+       const Mat xmp = Mat(metadata[IMAGE_METADATA_XMP]);
```

Review comment:
The macro was added for some old versions of PNG without exif support. I propose to restore it back.
**File:** modules/imgcodecs/src/grfmt_jpeg.cpp
**Change Type:** modified
**Context:** PR #27583: Jpeg Metadata (iccp and xmp)

**Code Changes:**
```diff
@@ -247,8 +247,43 @@ bool  JpegDecoder::readHeader()
         if (state->cinfo.src != 0)
         {
             jpeg_save_markers(&state->cinfo, APP1, 0xffff);
+            jpeg_save_markers(&state->cinfo, APP2, 0xffff);
             jpeg_read_header( &state->cinfo, TRUE );
 
+            const std::streamsize EXIF_HEADER_SIZE = 6;   // "Exif\0\0"
+            const std::streamsize XMP_HEADER_SIZE  = 29;  // "http://ns.adobe.com/xap/1.0/"
+            const std::streamsize ICC_HEADER_SIZE  = 14;  // "ICC_PROFILE\0" + seq/total
```

Review comment:
I propose to create named constant for 29 like EXIF_HEADER_SIZE
**File:** cmake/OpenCVDetectCUDAUtils.cmake
**Change Type:** modified
**Context:** PR #27522: fix compilation problems with MSVC+Cuda 12.9

**Code Changes:**
```diff
@@ -388,8 +388,13 @@ macro(ocv_nvcc_flags)
     set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcompiler=-fno-finite-math-only)
   endif()
 
-  if(WIN32 AND NOT (CUDA_VERSION VERSION_LESS "11.2"))
-    set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcudafe --display_error_number --diag-suppress 1394,1388)
+  if(WIN32)
+    if (NOT (CUDA_VERSION VERSION_LESS "11.2"))
+        set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcudafe --display_error_number --diag-suppress 1394,1388)
+    endif()
```

Review comment:
Which compilation errors do you get with this version of CUDA without the `--expt-relaxed-constexpr` flag? I'm interested because I can build against CUDA 12.8 on windows without this experimental flag.
**File:** cmake/OpenCVDetectCUDAUtils.cmake
**Change Type:** modified
**Context:** PR #27522: fix compilation problems with MSVC+Cuda 12.9

**Code Changes:**
```diff
@@ -388,8 +388,13 @@ macro(ocv_nvcc_flags)
     set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcompiler=-fno-finite-math-only)
   endif()
 
-  if(WIN32 AND NOT (CUDA_VERSION VERSION_LESS "11.2"))
-    set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcudafe --display_error_number --diag-suppress 1394,1388)
+  if(WIN32)
+    if (NOT (CUDA_VERSION VERSION_LESS "11.2"))
+        set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcudafe --display_error_number --diag-suppress 1394,1388)
+    endif()
```

Review comment:
You get this with CUDA 12.8 and the latest version of Visual Studio 2022? I only see those errors with CUDA 12.9 without the addition of `-Xcompiler /Zc:preprocessor`. I'm building with Ninja are you building directly in VS? <hr> **Update:** I can't recreate this, can you provide your CMake arguments, the version of VS, CUDA and CMake you are using please. I can build OpenCV without the `--expt-relaxed-constexpr` flag in VS 17.14.7 with CUDA 12.8, and CMake 4.01 using both the Ninja and VS generator.
**File:** cmake/OpenCVDetectCUDAUtils.cmake
**Change Type:** modified
**Context:** PR #27522: fix compilation problems with MSVC+Cuda 12.9

**Code Changes:**
```diff
@@ -388,8 +388,13 @@ macro(ocv_nvcc_flags)
     set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcompiler=-fno-finite-math-only)
   endif()
 
-  if(WIN32 AND NOT (CUDA_VERSION VERSION_LESS "11.2"))
-    set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcudafe --display_error_number --diag-suppress 1394,1388)
+  if(WIN32)
+    if (NOT (CUDA_VERSION VERSION_LESS "11.2"))
+        set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcudafe --display_error_number --diag-suppress 1394,1388)
+    endif()
```

Review comment:
You are right, I can't reproduce it either with 12.8. I must have fooled myself among my different experiments. I will update the PR.
**File:** cmake/OpenCVDetectCUDAUtils.cmake
**Change Type:** modified
**Context:** PR #27522: fix compilation problems with MSVC+Cuda 12.9

**Code Changes:**
```diff
@@ -388,8 +388,13 @@ macro(ocv_nvcc_flags)
     set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcompiler=-fno-finite-math-only)
   endif()
 
-  if(WIN32 AND NOT (CUDA_VERSION VERSION_LESS "11.2"))
-    set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcudafe --display_error_number --diag-suppress 1394,1388)
+  if(WIN32)
+    if (NOT (CUDA_VERSION VERSION_LESS "11.2"))
+        set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcudafe --display_error_number --diag-suppress 1394,1388)
+    endif()
```

Review comment:
For consistency with the rest of the file I would use `-Xcompiler=/Zc:preprocessor`
**File:** cmake/OpenCVDetectCUDAUtils.cmake
**Change Type:** modified
**Context:** PR #27522: fix compilation problems with MSVC+Cuda 12.9

**Code Changes:**
```diff
@@ -388,8 +388,13 @@ macro(ocv_nvcc_flags)
     set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcompiler=-fno-finite-math-only)
   endif()
 
-  if(WIN32 AND NOT (CUDA_VERSION VERSION_LESS "11.2"))
-    set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcudafe --display_error_number --diag-suppress 1394,1388)
+  if(WIN32)
+    if (NOT (CUDA_VERSION VERSION_LESS "11.2"))
+        set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcudafe --display_error_number --diag-suppress 1394,1388)
+    endif()
```

Review comment:
It is with ``` if(WIN32) if (NOT (CUDA_VERSION VERSION_LESS "11.2")) set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcudafe --display_error_number --diag-suppress 1394,1388) endif() if(CUDA_VERSION GREATER "12.8") #set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} --expt-relaxed-constexpr) set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcompiler=/Zc:preprocessor) endif() endif() ```
**File:** cmake/OpenCVDetectCUDAUtils.cmake
**Change Type:** modified
**Context:** PR #27522: fix compilation problems with MSVC+Cuda 12.9

**Code Changes:**
```diff
@@ -388,8 +388,13 @@ macro(ocv_nvcc_flags)
     set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcompiler=-fno-finite-math-only)
   endif()
 
-  if(WIN32 AND NOT (CUDA_VERSION VERSION_LESS "11.2"))
-    set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcudafe --display_error_number --diag-suppress 1394,1388)
+  if(WIN32)
+    if (NOT (CUDA_VERSION VERSION_LESS "11.2"))
+        set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcudafe --display_error_number --diag-suppress 1394,1388)
+    endif()
```

Review comment:
To fix the **cudev** error you need to apply the PR I linked to. Without it I get the errors you mentioned above even with the experimental flag (`--expt-relaxed-constexpr`).
**File:** cmake/OpenCVDetectCUDAUtils.cmake
**Change Type:** modified
**Context:** PR #27522: fix compilation problems with MSVC+Cuda 12.9

**Code Changes:**
```diff
@@ -388,8 +388,13 @@ macro(ocv_nvcc_flags)
     set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcompiler=-fno-finite-math-only)
   endif()
 
-  if(WIN32 AND NOT (CUDA_VERSION VERSION_LESS "11.2"))
-    set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcudafe --display_error_number --diag-suppress 1394,1388)
+  if(WIN32)
+    if (NOT (CUDA_VERSION VERSION_LESS "11.2"))
+        set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -Xcudafe --display_error_number --diag-suppress 1394,1388)
+    endif()
```

Review comment:
Indending the inner if statements will make it easier to read.
**File:** modules/imgcodecs/src/loadsave.cpp
**Change Type:** modified
**Context:** PR #25691: [GSoC] Add GIF decode and encode for imgcodecs

**Code Changes:**
```diff
@@ -148,14 +148,18 @@ struct ImageCodecInitializer
     */
     ImageCodecInitializer()
     {
-#ifdef HAVE_AVIF
-        decoders.push_back(makePtr<AvifDecoder>());
-        encoders.push_back(makePtr<AvifEncoder>());
-#endif
         /// BMP Support
         decoders.push_back( makePtr<BmpDecoder>() );
```

Review comment:
You need to guard that code with an `#ifdef HAVE_GIF`
**File:** modules/imgcodecs/src/grfmt_gif.cpp
**Change Type:** added
**Context:** PR #25691: [GSoC] Add GIF decode and encode for imgcodecs

**Code Changes:**
```diff
@@ -0,0 +1,1144 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level
+// directory of this distribution and at http://opencv.org/license.html
+
+#include "precomp.hpp"
+#include "grfmt_gif.hpp"
+
+#ifdef HAVE_IMGCODEC_GIF
+namespace cv
```

Review comment:
Please add signature check.
**File:** modules/imgcodecs/src/grfmt_gif.cpp
**Change Type:** added
**Context:** PR #25691: [GSoC] Add GIF decode and encode for imgcodecs

**Code Changes:**
```diff
@@ -0,0 +1,1144 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level
+// directory of this distribution and at http://opencv.org/license.html
+
+#include "precomp.hpp"
+#include "grfmt_gif.hpp"
+
+#ifdef HAVE_IMGCODEC_GIF
+namespace cv
```

Review comment:
cv::Mat::zeros()
**File:** modules/imgcodecs/test/test_gif.cpp
**Change Type:** added
**Context:** PR #25691: [GSoC] Add GIF decode and encode for imgcodecs

**Code Changes:**
```diff
@@ -0,0 +1,357 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html
+#include "test_precomp.hpp"
+
+#ifdef HAVE_IMGCODEC_GIF
+
+namespace opencv_test { namespace {
+
```

Review comment:
The solution is very inefficient in terms of OpenCV Extra repository. I propose the following: - Cherry pick several key images for regular unit testing, convert the reference xmls to png and put pngs to extra - Add disabled test with all cases and describe how to get/generate data for it in the test comments. As alternative, you can put it to https://github.com/opencv/opencv_benchmarks as dedicated app with instruction
**File:** modules/imgcodecs/test/test_gif.cpp
**Change Type:** added
**Context:** PR #25691: [GSoC] Add GIF decode and encode for imgcodecs

**Code Changes:**
```diff
@@ -0,0 +1,357 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level directory
+// of this distribution and at http://opencv.org/license.html
+#include "test_precomp.hpp"
+
+#ifdef HAVE_IMGCODEC_GIF
+
+namespace opencv_test { namespace {
+
```

Review comment:
Please use png for reference frames. 161 is to much. I propose to check some key frames and sequence size only.
**File:** modules/imgcodecs/src/grfmt_gif.cpp
**Change Type:** added
**Context:** PR #25691: [GSoC] Add GIF decode and encode for imgcodecs

**Code Changes:**
```diff
@@ -0,0 +1,1144 @@
+// This file is part of OpenCV project.
+// It is subject to the license terms in the LICENSE file found in the top-level
+// directory of this distribution and at http://opencv.org/license.html
+
+#include "precomp.hpp"
+#include "grfmt_gif.hpp"
+
+#ifdef HAVE_IMGCODEC_GIF
+namespace cv
```

Review comment:
please use std::vector, std::array or cv::AutoBuffer to prevent memory leaks in cases of parser failrue.
**File:** modules/imgcodecs/src/loadsave.cpp
**Change Type:** modified
**Context:** PR #25691: [GSoC] Add GIF decode and encode for imgcodecs

**Code Changes:**
```diff
@@ -148,14 +148,18 @@ struct ImageCodecInitializer
     */
     ImageCodecInitializer()
     {
-#ifdef HAVE_AVIF
-        decoders.push_back(makePtr<AvifDecoder>());
-        encoders.push_back(makePtr<AvifEncoder>());
-#endif
         /// BMP Support
         decoders.push_back( makePtr<BmpDecoder>() );
```

Review comment:
done， i set that initially on