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

Merge pull request #26859 from Kumataro:fix26858

imgcodecs:gif: support IMREAD_UNCHANGED and IMREAD_GRAYSCALE #26859

Close #26858 

### 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.
- [x] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
Kumataro
2025-02-07 01:29:54 +09:00
committed by GitHub
parent 7563cebad5
commit 01e3fe8791
4 changed files with 78 additions and 14 deletions
+19 -4
View File
@@ -241,17 +241,17 @@ TEST(Imgcodecs_Gif, read_gif_special){
const string gif_filename2 = root + "gifsuite/special2.gif";
const string png_filename2 = root + "gifsuite/special2.png";
cv::Mat gif_img1;
ASSERT_NO_THROW(gif_img1 = cv::imread(gif_filename1,IMREAD_UNCHANGED));
ASSERT_NO_THROW(gif_img1 = cv::imread(gif_filename1,IMREAD_COLOR));
ASSERT_FALSE(gif_img1.empty());
cv::Mat png_img1;
ASSERT_NO_THROW(png_img1 = cv::imread(png_filename1,IMREAD_UNCHANGED));
ASSERT_NO_THROW(png_img1 = cv::imread(png_filename1,IMREAD_COLOR));
ASSERT_FALSE(png_img1.empty());
EXPECT_PRED_FORMAT2(cvtest::MatComparator(0, 0), gif_img1, png_img1);
cv::Mat gif_img2;
ASSERT_NO_THROW(gif_img2 = cv::imread(gif_filename2,IMREAD_UNCHANGED));
ASSERT_NO_THROW(gif_img2 = cv::imread(gif_filename2,IMREAD_COLOR));
ASSERT_FALSE(gif_img2.empty());
cv::Mat png_img2;
ASSERT_NO_THROW(png_img2 = cv::imread(png_filename2,IMREAD_UNCHANGED));
ASSERT_NO_THROW(png_img2 = cv::imread(png_filename2,IMREAD_COLOR));
ASSERT_FALSE(png_img2.empty());
EXPECT_PRED_FORMAT2(cvtest::MatComparator(0, 0), gif_img2, png_img2);
}
@@ -351,6 +351,21 @@ TEST(Imgcodecs_Gif, write_gif_multi) {
EXPECT_EQ(0, remove(gif_filename.c_str()));
}
TEST(Imgcodecs_Gif, encode_IMREAD_GRAYSCALE) {
cv::Mat src;
cv::Mat decoded;
vector<uint8_t> buf;
vector<int> param;
bool ret = false;
src = cv::Mat(240,240,CV_8UC3,cv::Scalar(128,64,32));
EXPECT_NO_THROW(ret = imencode(".gif", src, buf, param));
EXPECT_TRUE(ret);
EXPECT_NO_THROW(decoded = imdecode(buf, cv::IMREAD_GRAYSCALE));
EXPECT_FALSE(decoded.empty());
EXPECT_EQ(decoded.channels(), 1);
}
}//opencv_test
}//namespace