feat: Enable tuning of the WebP encoder settings. #225
+562
−148
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds fine-grained control over WebP encoding, particularly useful for animated WebP outputs. The changes introduce several new configuration options that allow users to optimize the encoding process for different use cases, from ultra-fast encoding to high-quality compression.
Key Changes
New WebP Encoding Options
Added support for the following WebP encoder parameters:
WebpMethod
(0-6): Controls compression method, trading speed for efficiencyWebpFilterStrength
(0-100): Controls spatial filter strengthWebpFilterType
(0-1): Allows choosing between simple and strong filteringWebpAutofilter
(0-1): Enables automatic filter strength adjustmentWebpPartitions
(0-3): Controls partition count for encodingWebpSegments
(1-4): Controls segment countWebpPreprocessing
(0-1): Enables preprocessing filterWebpThreadLevel
(0-1): Controls multi-threadingWebpPalette
(0-1): Enables palette-based optimizationImplementation Details
webp.cpp
to properly handle these options through theWebPConfig
structureWebPAnimEncoderAssemble
set of libwebp APIs which automatically apply key-frame/partial-frame optimizations; previously only key-frames were produced, leading to larger files with more image data to compress.The improvements in file size are evident when describing an encoded animated WebP image with
webpmux
. Although this introduces a step of determining the optimal size for non-key-frames, it's offset by having to compress less image data for those frames which is typically far more expensive.Before
After
Testing
Notes