Skip to content

Commit 082cd7a

Browse files
authored
Merge pull request opencv#25691 from redhecker:gifSupport
[GSoC] Add GIF decode and encode for imgcodecs opencv#25691 this is related to opencv#24855 we add gif support for `imread`, `imreadmulti`, `imwrite` and `imwritemulti` opencv_extra: opencv/opencv_extra#1203 ### 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 - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work - [x] 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
1 parent 7fbf3c1 commit 082cd7a

File tree

9 files changed

+1729
-5
lines changed

9 files changed

+1729
-5
lines changed

CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,9 @@ OCV_OPTION(WITH_ITT "Include Intel ITT support" ON
432432
OCV_OPTION(WITH_PROTOBUF "Enable libprotobuf" ON
433433
VISIBLE_IF TRUE
434434
VERIFY HAVE_PROTOBUF)
435+
OCV_OPTION(WITH_IMGCODEC_GIF "Include GIF support" OFF
436+
VISIBLE_IF TRUE
437+
VERIFY HAVE_IMGCODEC_GIF)
435438
OCV_OPTION(WITH_IMGCODEC_HDR "Include HDR support" ON
436439
VISIBLE_IF TRUE
437440
VERIFY HAVE_IMGCODEC_HDR)
@@ -1557,6 +1560,10 @@ if(WITH_GDCM OR HAVE_GDCM)
15571560
status(" GDCM:" HAVE_GDCM THEN "YES (${GDCM_VERSION})" ELSE "NO")
15581561
endif()
15591562

1563+
if(WITH_IMGCODEC_GIF OR DEFINED HAVE_IMGCODEC_GIF)
1564+
status(" GIF:" HAVE_IMGCODEC_GIF THEN "YES" ELSE "NO")
1565+
endif()
1566+
15601567
if(WITH_IMGCODEC_HDR OR DEFINED HAVE_IMGCODEC_HDR)
15611568
status(" HDR:" HAVE_IMGCODEC_HDR THEN "YES" ELSE "NO")
15621569
endif()

cmake/OpenCVFindLibsGrfmt.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,11 @@ if(WITH_GDCM)
371371
endif()
372372
endif()
373373

374+
if(WITH_IMGCODEC_GIF)
375+
set(HAVE_IMGCODEC_GIF ON)
376+
elseif(DEFINED WITH_IMGCODEC_GIF)
377+
set(HAVE_IMGCODEC_GIF OFF)
378+
endif()
374379
if(WITH_IMGCODEC_HDR)
375380
set(HAVE_IMGCODEC_HDR ON)
376381
elseif(DEFINED WITH_IMGCODEC_HDR)

modules/imgcodecs/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ if(HAVE_GDAL)
8888
list(APPEND GRFMT_LIBS ${GDAL_LIBRARY})
8989
endif()
9090

91+
if(HAVE_IMGCODEC_GIF)
92+
add_definitions(-DHAVE_IMGCODEC_GIF)
93+
endif()
94+
9195
if(HAVE_IMGCODEC_HDR)
9296
add_definitions(-DHAVE_IMGCODEC_HDR)
9397
endif()

modules/imgcodecs/include/opencv2/imgcodecs.hpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,13 @@ enum ImwriteFlags {
111111
IMWRITE_JPEG2000_COMPRESSION_X1000 = 272,//!< For JPEG2000, use to specify the target compression rate (multiplied by 1000). The value can be from 0 to 1000. Default is 1000.
112112
IMWRITE_AVIF_QUALITY = 512,//!< For AVIF, it can be a quality between 0 and 100 (the higher the better). Default is 95.
113113
IMWRITE_AVIF_DEPTH = 513,//!< For AVIF, it can be 8, 10 or 12. If >8, it is stored/read as CV_32F. Default is 8.
114-
IMWRITE_AVIF_SPEED = 514 //!< For AVIF, it is between 0 (slowest) and (fastest). Default is 9.
114+
IMWRITE_AVIF_SPEED = 514,//!< For AVIF, it is between 0 (slowest) and (fastest). Default is 9.
115+
IMWRITE_GIF_LOOP = 1024,//!< For GIF, it can be a loop flag from 0 to 65535. Default is 0 - loop forever.
116+
IMWRITE_GIF_SPEED = 1025,//!< For GIF, it is between 1 (slowest) and 100 (fastest). Default is 96.
117+
IMWRITE_GIF_QUALITY = 1026, //!< For GIF, it can be a quality from 1 to 8. Default is 2. See cv::ImwriteGifCompressionFlags.
118+
IMWRITE_GIF_DITHER = 1027, //!< For GIF, it can be a quality from -1(most dither) to 3(no dither). Default is 0.
119+
IMWRITE_GIF_TRANSPARENCY = 1028, //!< For GIF, the alpha channel lower than this will be set to transparent. Default is 1.
120+
IMWRITE_GIF_COLORTABLE = 1029 //!< For GIF, 0 means global color table is used, 1 means local color table is used. Default is 0.
115121
};
116122

117123
enum ImwriteJPEGSamplingFactorParams {
@@ -216,6 +222,18 @@ enum ImwriteHDRCompressionFlags {
216222
IMWRITE_HDR_COMPRESSION_RLE = 1
217223
};
218224

225+
//! Imwrite GIF specific values for IMWRITE_GIF_QUALITY parameter key, if larger than 3, then its related to the size of the color table.
226+
enum ImwriteGIFCompressionFlags {
227+
IMWRITE_GIF_FAST_NO_DITHER = 1,
228+
IMWRITE_GIF_FAST_FLOYD_DITHER = 2,
229+
IMWRITE_GIF_COLORTABLE_SIZE_8 = 3,
230+
IMWRITE_GIF_COLORTABLE_SIZE_16 = 4,
231+
IMWRITE_GIF_COLORTABLE_SIZE_32 = 5,
232+
IMWRITE_GIF_COLORTABLE_SIZE_64 = 6,
233+
IMWRITE_GIF_COLORTABLE_SIZE_128 = 7,
234+
IMWRITE_GIF_COLORTABLE_SIZE_256 = 8
235+
};
236+
219237
//! @} imgcodecs_flags
220238

221239
/** @brief Loads an image from a file.
@@ -229,6 +247,7 @@ returns an empty matrix.
229247
Currently, the following file formats are supported:
230248
231249
- Windows bitmaps - \*.bmp, \*.dib (always supported)
250+
- GIF files - \*.gif (always supported)
232251
- JPEG files - \*.jpeg, \*.jpg, \*.jpe (see the *Note* section)
233252
- JPEG 2000 files - \*.jp2 (see the *Note* section)
234253
- Portable Network Graphics - \*.png (see the *Note* section)

0 commit comments

Comments
 (0)