-
Notifications
You must be signed in to change notification settings - Fork 648
feat(webp): Allow finer grained control over WEBP compression settings #4772
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(webp): Allow finer grained control over WEBP compression settings #4772
Conversation
Signed-off-by: Jesse Yurkovich <[email protected]>
lgritz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
For my own curiosity: what's the difference between method and quality? They both are described as somehow trading size for time. Is method selecting between totally different algorithms? |
|
There's little actual documentation about it... The There's a chart in the source about it but I don't have the necessary background to really understand what those various items mean: https://github.com/webmproject/libwebp/blob/main/src/enc/webp_enc.c#L74. So it seems like it controls some tuning mechanisms during Color encoding. It also seems to control some "effort" mechanism when encoding Alpha -- the method eventually sets the effort_level here: https://github.com/webmproject/libwebp/blob/main/src/enc/alpha_enc.c#L39 |
AcademySoftwareFoundation#4772) WEBP uses the `WebPConfig::factor` setting to also control how hard it tries to compress when lossless compression is used. It also uses another `WebPConfig::method` setting to further tune both lossless and lossy schemes. [1] Expose both of these settings so client applications using OIIO can adjust these values as they see fit. This PR makes 4 changes: - Adds support for using a `lossless:factor` value for the `compression` attribute. The 'factor' value controls the effort that WEBP uses during the compression process. - Adds support for using a `webp:method` int attribute. The value of this attribute controls the `WebPConfig::method` setting. Note: this is different than the compression settings but will also affect speed and quality in various ways. - Sets `WebPPicture::use_argb` to `true` when using lossless compression (per the WEBP documentation[2]) - Changes default lossless "quality" from 100 to 70. This results in much faster image output at a very minor increase in file size (e.g. a 2048x2048 test image goes from 1300ms/364kb to 800ms/371kb after this change) Before - just 2 basic forms were possible: ``` Client uses "compression=lossless" - OIIO uses lossless=true, method=6, quality=100, use_argb=false Client uses "compression=webp:90" - OIIO uses lossless=false, method=6, quality=90, use_argb=false ``` After - several additional variations are possible: ``` Client uses "compression=lossless" - OIIO uses lossless=true, method=6, quality=70, use_argb=true Client uses "compression=lossless:100" and "webp:method=4" - OIIO uses lossless=true, method=4, quality=100, use_argb=true Client uses "compression=webp:90" - OIIO uses lossless=false, method=6, quality=90, use_argb=false Client uses "compression=webp:90" and "webp:method=4" - OIIO uses lossless=false, method=4, quality=90, use_argb=false ``` [1] https://developers.google.com/speed/webp/docs/api#advanced_encoding_api [2] See notes around `use_argb` from the above link and see also the internal Encode helper function which keeps lossless and use_argb in sync: https://github.com/webmproject/libwebp/blob/main/src/enc/picture_enc.c#L241 Signed-off-by: Jesse Yurkovich <[email protected]>
AcademySoftwareFoundation#4772) WEBP uses the `WebPConfig::factor` setting to also control how hard it tries to compress when lossless compression is used. It also uses another `WebPConfig::method` setting to further tune both lossless and lossy schemes. [1] Expose both of these settings so client applications using OIIO can adjust these values as they see fit. This PR makes 4 changes: - Adds support for using a `lossless:factor` value for the `compression` attribute. The 'factor' value controls the effort that WEBP uses during the compression process. - Adds support for using a `webp:method` int attribute. The value of this attribute controls the `WebPConfig::method` setting. Note: this is different than the compression settings but will also affect speed and quality in various ways. - Sets `WebPPicture::use_argb` to `true` when using lossless compression (per the WEBP documentation[2]) - Changes default lossless "quality" from 100 to 70. This results in much faster image output at a very minor increase in file size (e.g. a 2048x2048 test image goes from 1300ms/364kb to 800ms/371kb after this change) Before - just 2 basic forms were possible: ``` Client uses "compression=lossless" - OIIO uses lossless=true, method=6, quality=100, use_argb=false Client uses "compression=webp:90" - OIIO uses lossless=false, method=6, quality=90, use_argb=false ``` After - several additional variations are possible: ``` Client uses "compression=lossless" - OIIO uses lossless=true, method=6, quality=70, use_argb=true Client uses "compression=lossless:100" and "webp:method=4" - OIIO uses lossless=true, method=4, quality=100, use_argb=true Client uses "compression=webp:90" - OIIO uses lossless=false, method=6, quality=90, use_argb=false Client uses "compression=webp:90" and "webp:method=4" - OIIO uses lossless=false, method=4, quality=90, use_argb=false ``` [1] https://developers.google.com/speed/webp/docs/api#advanced_encoding_api [2] See notes around `use_argb` from the above link and see also the internal Encode helper function which keeps lossless and use_argb in sync: https://github.com/webmproject/libwebp/blob/main/src/enc/picture_enc.c#L241 Signed-off-by: Jesse Yurkovich <[email protected]>
Description
WEBP uses the
WebPConfig::factorsetting to also control how hard it tries to compress when lossless compression is used. It also uses anotherWebPConfig::methodsetting to further tune both lossless and lossy schemes. [1]Expose both of these settings so client applications using OIIO can adjust these values as they see fit.
This PR makes 4 changes:
lossless:factorvalue for thecompressionattribute. The 'factor' value controls the effort that WEBP uses during the compression process.webp:methodint attribute. The value of this attribute controls theWebPConfig::methodsetting. Note: this is different than the compression settings but will also affect speed and quality in various ways.WebPPicture::use_argbtotruewhen using lossless compression (per the WEBP documentation[2])Before - just 2 basic forms were possible:
After - several additional variations are possible:
[1] https://developers.google.com/speed/webp/docs/api#advanced_encoding_api
[2] See notes around
use_argbfrom the above link and see also the internal Encode helper function which keeps lossless and use_argb in sync: https://github.com/webmproject/libwebp/blob/main/src/enc/picture_enc.c#L241Tests
Checklist:
need to update the documentation, for example if this is a bug fix that
doesn't change the API.)
(adding new test cases if necessary).
corresponding Python bindings (and if altering ImageBufAlgo functions, also
exposed the new functionality as oiiotool options).
already run clang-format before submitting, I definitely will look at the CI
test that runs clang-format and fix anything that it highlights as being
nonconforming.