Skip to content

Animated PNG Support#25715

Merged
asmorkalov merged 32 commits intoopencv:4.xfrom
sturkmen72:apng_support
Dec 30, 2024
Merged

Animated PNG Support#25715
asmorkalov merged 32 commits intoopencv:4.xfrom
sturkmen72:apng_support

Conversation

@sturkmen72
Copy link
Copy Markdown
Contributor

@sturkmen72 sturkmen72 commented Jun 5, 2024

Continues #25608

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 Author

@vrabaud i am willing to modify grfmt_apng.cpp to gain a solution.
i think i can work in this way. let me know if there is any problem.

@sturkmen72 sturkmen72 marked this pull request as draft June 5, 2024 20:54
@vrabaud
Copy link
Copy Markdown
Contributor

vrabaud commented Jun 6, 2024

You probably do not want to modify that file as it will make it harder to track changes upstream. Have it be its own file (apng.cpp? or whatever it was called in the first place). And then have your own grfmt_apng.cpp call it

@vrabaud
Copy link
Copy Markdown
Contributor

vrabaud commented Jun 10, 2024

@sturkmen72, did you get my mail? You should really first design an API that will handle animations. writemulti is not usable for animations, it misses critical details (e.g. timestamp, loops)

@sturkmen72
Copy link
Copy Markdown
Contributor Author

sturkmen72 commented Jun 25, 2024

hi @vrabaud
could you take a look the difference of results_test_imgcodecs. any advice on how to handle old versions of libpng

linux ci server

PNG:    /usr/lib/x86_64-linux-gnu/libpng.so (ver 1.2.54)

-------------------
w0 : 680
h0 : 900
x0 : 0
y0 : 0
delay_num : 100
delay_den : 1000
dop : 0
bop : 0
-------------------
[       OK ] Imgcodecs_Png.load_save_multiframes_rgba (1779 ms)
[ RUN      ] Imgcodecs_Png.load_save_multiframes_rgb
**frame props
-------------------
w0 : 680
h0 : 900
x0 : 0
y0 : 0
delay_num : 100
delay_den : 1000
dop : 0
bop : 0
-------------------

windows ci server
-- PNG: build (ver 1.6.43)
-- SIMD Support Request: YES
-- SIMD Support: YES (Intel SSE)

**frame props
-------------------
w0 : 680
h0 : 900
x0 : 0
y0 : 0
delay_num : 100
delay_den : 1000
dop : 0
bop : 0
-------------------
**frame props
-------------------
w0 : 662
h0 : 178
x0 : 9
y0 : 719
delay_num : 100
delay_den : 1000
dop : 1
bop : 0
-------------------

@sturkmen72
Copy link
Copy Markdown
Contributor Author

@asmorkalov is it possible to update versions of libpng and libwebp on linux ci servers.

Copy link
Copy Markdown
Contributor

@vrabaud vrabaud left a comment

Choose a reason for hiding this comment

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

Mostly, please split the code into what was taken from upstream, and what you added, this will make it easier to update files to upstream.

m_height = height;
m_color_type = PNG_COLOR_MASK_COLOR;

m_pixels = new uchar[m_height * rowbytes];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please use C++ to make it easier to track memory (std::vector here)


/****************************************************************************\
*
* this file includes some modified part of apngasm and APNG Optimizer 1.4
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can't the relevant code simply be copied from upstream? It will make it much easier to track upstream bug fixes. Which files did you take from upstream?

@sturkmen72
Copy link
Copy Markdown
Contributor Author

@vrabaud thank you for review. the PR is still a draft and not yet completely functional. i will take your remarks in account.

* The next generation of apngasm, the APNG Assembler.
* The apngasm CLI tool and library can assemble and disassemble APNG image files.
*
* https://github.com/apngasm/apngasm
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

How about mentioning which file got copied? Ideally, the first commit would be about adding the pristine file from upstream, and you would then have a commit to modify it to make sure we know what got modified.

if (pChunk->size > PNG_USER_CHUNK_MALLOC_MAX)
return 0;
pChunk->size += 12;
pChunk->p = new uchar[pChunk->size];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please do not use new as it makes its hard to track memory. Use std::vector if you can.

@asmorkalov asmorkalov added this to the 4.11.0 milestone Jul 12, 2024
@sturkmen72 sturkmen72 force-pushed the apng_support branch 2 times, most recently from ba23302 to 2ec4b67 Compare July 18, 2024 06:53
@sturkmen72 sturkmen72 force-pushed the apng_support branch 3 times, most recently from 8a5311c to 946a110 Compare July 27, 2024 16:53
@sturkmen72 sturkmen72 marked this pull request as ready for review August 12, 2024 07:59
@sturkmen72 sturkmen72 changed the title APNG Support Animated PNG Support Aug 26, 2024
@sturkmen72 sturkmen72 force-pushed the apng_support branch 2 times, most recently from 2daf9da to 5f716bd Compare August 27, 2024 19:19
@asmorkalov
Copy link
Copy Markdown
Contributor

@sturkmen72 Looks like Obj-C / Swift bindings generator does not handle uint32_t correctly. Please try to get rid of it in interface:

Traceback (most recent call last):
  File "/Users/opencv-cn/GHA-OCV-3/_work/opencv/opencv/opencv/modules/objc/generator/../generator/gen_objc.py", line 1716, in <module>
    generator.gen(srcfiles, module, dstdir, objc_base_path, common_headers, manual_classes)
  File "/Users/opencv-cn/GHA-OCV-3/_work/opencv/opencv/opencv/modules/objc/generator/../generator/gen_objc.py", line 953, in gen
    self.gen_class(ci, self.module, extension_implementations, extension_signatures)
  File "/Users/opencv-cn/GHA-OCV-3/_work/opencv/opencv/opencv/modules/objc/generator/../generator/gen_objc.py", line 1349, in gen_class
    type_data = type_dict[pi.ctype] if pi.ctype != "uchar" else {"objc_type" : "unsigned char", "is_primitive" : True}
KeyError: 'uint32_t'

@asmorkalov
Copy link
Copy Markdown
Contributor

@sturkmen72 I merged your patch for webp/avif. Please rebase and fix conflicts.

@sturkmen72
Copy link
Copy Markdown
Contributor Author

@asmorkalov there is 3 issues i am working on hopefully be completed soon.

  1. background color ( Marked TO DO on test )
  2. imdecode ( Marked TO DO on test )
  3. when saving identical frames drop frame and calculate delay ( like WebP ).

@sturkmen72
Copy link
Copy Markdown
Contributor Author

@asmorkalov @vrabaud i believe the PR is ready for final review.

@asmorkalov asmorkalov merged commit 8bc65a1 into opencv:4.x Dec 30, 2024
@sturkmen72 sturkmen72 deleted the apng_support branch December 30, 2024 08:53
@asmorkalov asmorkalov mentioned this pull request Jan 15, 2025
shyama7004 pushed a commit to shyama7004/opencv that referenced this pull request Jan 20, 2025
Animated PNG Support opencv#25715

Continues opencv#25608

### 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
asmorkalov pushed a commit that referenced this pull request Feb 13, 2025
NanQin555 pushed a commit to NanQin555/opencv that referenced this pull request Feb 24, 2025
Animated PNG Support opencv#25715

Continues opencv#25608

### 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
NanQin555 pushed a commit to NanQin555/opencv that referenced this pull request Feb 24, 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.

3 participants