Skip to content

Conversation

@jessey-git
Copy link
Contributor

Description

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

Tests

Checklist:

  • I have read the contribution guidelines.
  • I have updated the documentation, if applicable. (Check if there is no
    need to update the documentation, for example if this is a bug fix that
    doesn't change the API.)
  • I have ensured that the change is tested somewhere in the testsuite
    (adding new test cases if necessary).
  • If I added or modified a C++ API call, I have also amended the
    corresponding Python bindings (and if altering ImageBufAlgo functions, also
    exposed the new functionality as oiiotool options).
  • My code follows the prevailing code style of this project. If I haven't
    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.

Copy link
Collaborator

@lgritz lgritz left a comment

Choose a reason for hiding this comment

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

LGTM

@lgritz
Copy link
Collaborator

lgritz commented May 20, 2025

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?

@jessey-git
Copy link
Contributor Author

There's little actual documentation about it... The WebPConfigInit and WebPConfigPreset functions will default to method=4 though.

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

@lgritz lgritz merged commit 73be2d8 into AcademySoftwareFoundation:main May 21, 2025
30 checks passed
lgritz pushed a commit to lgritz/OpenImageIO that referenced this pull request May 21, 2025
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]>
@jessey-git jessey-git deleted the webp-compression branch June 23, 2025 00:24
zachlewis pushed a commit to zachlewis/OpenImageIO that referenced this pull request Aug 1, 2025
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants