-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat(avif): add chroma subsampling control for AVIF export #19595
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(avif): add chroma subsampling control for AVIF export #19595
Conversation
Add a new chroma subsampling option to the AVIF export module, allowing users to manually select subsampling modes (4:4:4, 4:2:2, 4:2:0) or use auto mode based on quality thresholds. This provides finer control over compression and quality trade-offs in AVIF images.
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.
Pull Request Overview
This PR introduces manual chroma subsampling control for AVIF export, allowing users to independently select 4:4:4, 4:2:2, or 4:2:0 subsampling modes instead of relying solely on quality-based automatic selection. This addresses limitations where optimal AVIF quality ranges (50-70) forced 4:2:0 subsampling, compromising color fidelity.
Key Changes:
- Added new
avif_subsample_eenum with AUTO, 444, 422, and 420 options - Implemented subsample selection logic in
write_image()that respects manual settings while preserving auto mode - Added GUI combobox control with descriptive tooltips and Lua API support
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Tested the lua avif format and it works. Here's the script.... |
Add a new configuration option for AVIF chroma subsampling in the imageio plugin settings. This allows users to control subsampling levels (0-3) for AVIF exports, defaulting to 0.
TurboGit
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.
Tested for the first time and found an issue. If you select the lossless compression mode you still have the subsample option on the GUI but this has not effect as it is hardcoded as AVIF_PIXEL_FORMAT_YUV444 in this case:
case AVIF_COMP_LOSSLESS:
format = AVIF_PIXEL_FORMAT_YUV444;
break;
I suppose that in lossless mode we need to hide the sub-sample slider as done for the quality slider.
…mode When AVIF compression is set to lossless, the subsample control is now hidden from the GUI to prevent irrelevant options, and marked with no-show-all for better layout management. This improves user experience by simplifying the interface during lossless exports.
TurboGit
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.
Looks good now. Thanks!
|
@kadykov : Can you provide a release notes entry? TIA. |
|
@kadykov Sorry I wasn't here in time for the review. Even now I don't have enough time to test it thoroughly. I can only note from a cursory look at the code that it makes changes to
See the source code for exporting to other formats for an example of how this is done. |
|
@victoryforce Thanks! I have created a follow-up PR #19698 |
Add manual chroma subsampling control for AVIF export
Summary
This PR adds manual chroma subsampling control to AVIF export, allowing users to choose between 4:4:4, 4:2:2, and 4:2:0 subsampling modes independently of the quality setting. This feature is inspired by the existing implementation in JPEG export.
Problem
Currently, darktable automatically determines the chroma subsampling for AVIF export based on quality thresholds:
This approach is too restrictive for the AVIF format. AVIF is highly efficient, and its optimal quality range is typically 50-70, where it produces excellent results with reasonable file sizes. However, at these quality levels, users are forced to use 4:2:0 chroma subsampling, which can result in rough edges and reduced color fidelity, especially in images with high-contrast color transitions.
To achieve 4:4:4 chroma subsampling (no color subsampling), users must set quality to 91 or higher, which produces unnecessarily large files that defeat the purpose of AVIF's efficiency.
Solution
This PR adds a new "chroma subsampling" option to the AVIF export dialog with the following choices:
This allows users to optimize the quality-vs-size tradeoff according to their specific needs.
Implementation
The implementation follows the pattern used in JPEG export (
src/imageio/format/jpeg.c):avif_subsample_ewith AUTO, 444, 422, 420 optionssubsamplefield indt_imageio_avif_tanddt_imageio_avif_gui_twrite_image()to check subsample setting before determining pixel formatplugins/imageio/format/avif/subsampleconfig keyBackward compatibility: The "auto" mode is set as default, preserving the existing quality-based behavior for all users.
Testing Results
Testing was performed with a 200% crop of a pattern containing white and red ribbons to highlight chroma subsampling artifacts. The results demonstrate the benefits of manual control:
Quality vs File Size Comparison:
Result: 4:4:4 version has noticeably smoother edges with better color fidelity
Result: 4:4:4 version clearly looks better with cleaner color transitions
The 4:2:0 subsampled images show rough edges and color fringing artifacts that are not present in the 4:4:4 versions, even when the 4:2:0 images are exported at higher quality settings with similar file sizes.
Use Cases
This feature is particularly beneficial for:
Example Usage