DanBloomberg / leptonica

Leptonica is an open source library containing software that is broadly useful for image processing and image analysis applications. The official github repository for Leptonica is: danbloomberg/leptonica. See leptonica.org for more documentation.
Other
1.81k stars 393 forks source link

Check return values of WebP API functions. #723

Closed vrabaud closed 1 year ago

vrabaud commented 1 year ago

Those will be made nodiscard at some point.

DanBloomberg commented 1 year ago

Thank you for this!

Two questions: (1) Does "nodiscard" mean that the return value must be caught? Used? Are we talking about compiler warnings? I've never heard of this for an application library -- how does that get implemented? Enforced? (2) Won't there be a leak from the malloc'd encoder structure with each of these new returns? if so, you would need to call WebPAnimEncoderDelete(enc) on each of them.

vrabaud commented 1 year ago

Thx for your responsiveness. I updated for animations and did some cosmetic changes (1) This is C23/C++17 feature: https://en.cppreference.com/w/c/language/attributes/nodiscard. WebP will enable it if the compiler supports it. This just generates a warning if the result is not used (in an if statement, or an assignment). We thought it would be a good thing for users to check allocations. (2) You are totally right, I fixed it.

DanBloomberg commented 1 year ago

I see that you're working on WebP and OpenCV at Google. Nice that Google is supporting this! I was an early supporter of WebP.

Perhaps you can tell me why Google doesn't support webpanim in Gmail. If you attach an animated gif to gmail, it will play. But not animated webp. That was one reason I never implemented reading webpanim.

Also, if you feel like it and have the time, you might enjoy implementing a function that reads webanim file data into a pixa:

       PIXA  *pixaReadMemWebPAnim(const l_uint8 *filedata, size_t filesize);

in analogy to the function pixReadMemWebP() in webpio.c