Skip to content

Test for in-memory animation encoding and decoding#27013

Merged
asmorkalov merged 2 commits intoopencv:4.xfrom
asmorkalov:as/imencode_animation
Mar 12, 2025
Merged

Test for in-memory animation encoding and decoding#27013
asmorkalov merged 2 commits intoopencv:4.xfrom
asmorkalov:as/imencode_animation

Conversation

@asmorkalov
Copy link
Copy Markdown
Contributor

Tests for #26964

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • 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

@sturkmen72
Copy link
Copy Markdown
Contributor

sturkmen72 commented Mar 5, 2025

imho this will be better ( no need to TEST(Imgcodecs_APNG, imdecode_animation) )

TEST(Imgcodecs_APNG, imencode_imdecode_animation)
{
    Animation gt_animation, mem_animation;
    EXPECT_TRUE(fillFrames(gt_animation, true));

    std::vector<unsigned char> buf;
    EXPECT_TRUE(imencodeanimation(".png", gt_animation, buf));
    EXPECT_TRUE(imdecodeanimation(buf, mem_animation));

    // Since the last frames are identical, APNG encoder optimizes by storing only one of them,
    // and the duration value for the last frame is calculated by APNG encoder.
    EXPECT_EQ(mem_animation.frames.size(), gt_animation.frames.size() - 2);
    EXPECT_EQ(mem_animation.bgcolor, gt_animation.bgcolor);
    EXPECT_EQ(mem_animation.loop_count, gt_animation.loop_count);
    for (size_t i = 0; i < mem_animation.frames.size() - 1; i++)
    {
        EXPECT_EQ(0, cvtest::norm(mem_animation.frames[i], gt_animation.frames[i], NORM_INF));
        EXPECT_EQ(mem_animation.durations[i], gt_animation.durations[i]);
    }
}

@asmorkalov
Copy link
Copy Markdown
Contributor Author

@mshabunin @vrabaud What is your opinion? I propose to have 2 tests: decoding only, encoding+decoding. It allows easily triage the issue in case of test failure.

@asmorkalov asmorkalov force-pushed the as/imencode_animation branch from cea80c7 to 66ec644 Compare March 11, 2025 11:25

@return Returns true if the animation was successfully encoded; returns false otherwise.
*/
CV_EXPORTS_W bool imencodeanimation(const String& ext, const Animation& animation, CV_OUT std::vector<uchar>& buf, const std::vector<int>& params = std::vector<int>());
Copy link
Copy Markdown
Contributor

@mshabunin mshabunin Mar 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe buf should be of type OutputArray. Or not?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All analogs use std::vector:

Most probably, they call std::vector::resize() to fit encoded size. It's not available throw OutputArray interface.

@asmorkalov asmorkalov force-pushed the as/imencode_animation branch from 66ec644 to dbf877c Compare March 12, 2025 07:07
@asmorkalov asmorkalov merged commit 7481cb5 into opencv:4.x Mar 12, 2025
73 of 82 checks passed
@asmorkalov asmorkalov mentioned this pull request Apr 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants