jaredforth / webp

WebP Image Conversion Library
Other
69 stars 20 forks source link

feat: consume frame after added, for reducing memory usage #32

Open meowtec opened 1 year ago

meowtec commented 1 year ago

If we encode a WebP animation with many frames, caching all frames into a Vec and then adding them all to the encoder at once is not a good approach. This could potentially lead to excessive memory usage.

It is better to consume each frames after they are added.

API BREAKING CHANGE

AnimEncoder::add_frame() should return a Result. (AnimEncoder::encode maybe should rename to AnimEncoder::finish, I'm not sure.)

In addition I update the example code to create a more complex and beautiful animation.

BTW, the animation decoder should return a iterator instead of a vector for the same reason.

langyo commented 7 months ago

Sorry to disturb you. If you are free, I hope you can review and merge this submission to follow up with the latest version (0.25) of the image library. @jaredforth