Repository navigation
feat: add saturation parameter to Color Correct layer - #3641
Conversation
Summary of ChangesHello @aviralgarg05, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a new saturation parameter to the Color Correct layer. The changes correctly add the new param_saturation member, initialize it, and integrate it into the parameter import/export methods and the parameter vocabulary. The saturation adjustment is also correctly applied in the accelerated rendering path within build_rendering_task_vfunc. However, a significant issue is that the non-accelerated rendering path, handled by the correct_color method, has not been updated to use the new saturation parameter. This will lead to inconsistent behavior between the final render and other UI elements like the color picker. This should be fixed to ensure consistent color correction across the application.
Added saturation adjustment to the correct_color function to ensure consistency between accelerated and non-accelerated rendering paths. The saturation parameter is now properly applied in both: - Accelerated path: via ColorMatrix::set_saturation() in build_rendering_task_vfunc - Non-accelerated path: via Color::set_s() in correct_color function The saturation adjustment is applied after brightness/contrast but before hue rotation, maintaining consistency with the transformation order in the accelerated rendering pipeline. This ensures that color pickers and other non-accelerated UI elements show the same saturation effect as the final rendered output. Addresses code review feedback on PR synfig#3641.
|
Hey @aviralgarg05 |
|
Thank you for your contribution, @aviralgarg05 ! Could you please remove this code style changes not directly related to your contribution code to be easier for our code review? You can do it just pushing another commit. Please pay attention we use tabs for indentation instead of spaces. |
|
Thank you for attempting to improve your contribution description! ✨ New Features
|
2d10836 to
8cdb2ef
Compare
|
Hi @aviralgarg05, I've tested this PR and it doesn't quite work as expected. Take a look at this: The top row is how it should be (when you decrease saturation in HSV wheel). The bottom row is the result produced by Color Correct layer. You can clearly see that not only saturation, but hue and value also changes. Do you have an idea why? Here's the source for test-case file: |
|
The saturation implementation is using YUV color space (via ColorMatrix::set_saturation() and Color::set_s()), which causes unwanted hue and value shifts. To get the expected behavior (matching the HSV wheel), the implementation would need to use HSV color space transformations instead, which properly isolates saturation from hue and value. The YUV approach works for certain color grading workflows, but it doesn't match the expectation of "saturation" as defined in HSV color models. I will make the required changes |
Replaced YUV-based saturation implementation with HSV-based approach to fix the issue where adjusting saturation also changed hue and value. Changes: - Non-accelerated path (correct_color): Implemented inline RGB-to-HSV conversion, saturation multiplication in HSV space, and HSV-to-RGB conversion. This preserves hue (H) and value (V) while only adjusting saturation (S). - Accelerated path (build_rendering_task_vfunc): Removed ColorMatrix saturation call since ColorMatrix uses YUV color space which causes the same hue/value shift issue. The saturation effect will now only apply in the non-accelerated path where it works correctly. Technical details: The HSV color space properly separates hue, saturation, and value as independent components. When adjusting saturation in HSV: - Hue (H): Color angle - preserved unchanged - Saturation (S): Color intensity - multiplied by parameter - Value (V): Brightness - preserved unchanged This matches the expected behavior of HSV wheel saturation adjustment as reported in issue feedback. Addresses maintainer feedback on PR synfig#3641 regarding hue/value shifts.
Are you absolutely sure about this? I haven't looked into it myself, but it's hard to believe that you need to convert stuff to a different representation just to change intensity of color. Anyway, I have tested your recent commits and now when you change saturation parameter nothing happens. Have you checked the example I provided in previous message? You need to get the bottom row to be the same as top one using Color Correct layer. |
|
I will test it out once again, although I tested it locally |
8136be9 to
8cdb2ef
Compare
Implement HSV-based saturation control for the Color Correct layer, allowing users to adjust color saturation independently from hue and value, matching the behavior of the HSV color wheel. Changes: - Added param_saturation member variable (default: 1.0, no change) - Implemented HSV saturation in both rendering paths: * Non-accelerated: in correct_color() function * Accelerated: via new TaskSaturation/TaskSaturationSW classes - Added saturation to parameter I/O and UI vocabulary The HSV saturation algorithm preserves the Value (max RGB component) while adjusting saturation: - 0.0: Grayscale (all RGB components equal to Value) - 1.0: Original saturation (no change) - >1.0: Enhanced saturation (more vivid colors) Unlike YUV-based saturation which preserves luminance, this HSV approach ensures that colors like pure red (1,0,0) at 0.5 saturation become (1,0.5,0.5) rather than shifting toward gray, matching user expectations from standard color pickers and the HSV wheel. Fixes: synfig#3634
8cdb2ef to
088850f
Compare
|
Maybe the issue was the order of color matrix transformations in the original PR commits? |
Yup, have done some turn arounds and fixes |
|
Sure I will do it as well |
Apply saturation adjustment BEFORE gamma correction in both rendering paths: - Non-accelerated path (correct_color): Moved saturation logic to before gamma.apply() - Accelerated path (build_rendering_task_vfunc): Reordered tasks so TaskSaturation runs before TaskPixelGamma The HSV saturation algorithm needs to operate in linear color space to produce correct results. When gamma correction is applied first, it transforms the colors non-linearly, which causes the saturation calculation to produce incorrect results. By applying saturation first (in linear space), then gamma, the saturation now works correctly regardless of the gamma correction setting in Canvas Properties. Fixes issue where saturation only worked when gamma=1.0
There was a problem hiding this comment.
Pull request overview
This PR adds a saturation parameter to the Color Correct layer, allowing users to independently adjust color saturation from 0.0 (grayscale) to values greater than 1.0 (enhanced saturation). The implementation uses a custom RGB-based saturation algorithm rather than the existing ColorMatrix YUV-based approach mentioned in the description.
Key Changes:
- Added
param_saturationmember variable initialized to 1.0 (neutral) - Implemented custom saturation adjustment in both rendering pipeline (TaskSaturation/TaskSaturationSW) and per-pixel path (correct_color)
- Integrated saturation into parameter import/export and vocabulary
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 8 comments.
| File | Description |
|---|---|
| synfig-core/src/modules/mod_filter/colorcorrect.h | Added TaskSaturation rendering classes and param_saturation member variable |
| synfig-core/src/modules/mod_filter/colorcorrect.cpp | Implemented saturation algorithm in two code paths, added parameter handling, and integrated into rendering pipeline |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Add clamping to [0,1] range for saturation values > 1.0 to prevent invalid color values when components extend beyond valid range - Fix misleading comments: change 'HSV-based' to 'RGB-based' since the implementation manipulates RGB values directly, not HSV - Remove unnecessary empty else block for grayscale color case - Cast saturation to ColorReal to fix type mismatch with std::min/max
Wait, wait, I am not talking about gamma parameter of the layer itself, I mean global gamma settings that's set in Menu->Canvas->Properties->Gamma correction. Did you check the test-case file I uploaded earlier in this thread? The gamma setting there is set to 0.45 so the result of saturation change isn't computed properly. |
|
Ok I will check and solve |
Abdelhadi-Wael
left a comment
There was a problem hiding this comment.
Please remove unrelated formatting changes
Saturation was not working correctly when canvas gamma != 1.0 because the saturation algorithm was operating on gamma-corrected colors instead of linear colors. Changes: - Added canvas_gamma field to TaskSaturation to pass canvas gamma settings - Updated apply_saturation to linearize colors (inverse gamma) before saturation calculation, then reapply gamma to output - Updated correct_color to get canvas gamma from get_canvas()->get_root()->rend_desc().get_gamma() and apply same linearization logic - Updated build_rendering_task_vfunc to pass canvas gamma to TaskSaturation This ensures saturation produces correct results regardless of the gamma correction setting in Menu->Canvas->Properties->Gamma correction. Fixes issue reported where saturation only worked with gamma=1.0 but failed with gamma=0.45 in the test case file.
70edbe9 to
a732e0d
Compare
|
@aviralgarg05 I checked the last commit and saturation now works as expected, hooray! But... The 'Contrast' parameter is now broken. To reproduce:
After that Synfig will either crash immediately or produce weird artifacts like this: Oh, and also, you still didn't address the indentation issue, please notice that we use tabs for indentation, not spaces. |
- Fixed TaskSaturationSW::run() to include proper validation checks matching TaskPixelGammaSW pattern (is_valid, sub_task, sub_task->is_valid) to prevent crash when changing Contrast parameter - Corrected offset calculation for source pixel access using the pattern from TaskPixelGammaSW to prevent out-of-bounds memory access - Changed indentation from spaces to tabs to match codebase style - Maintained all saturation functionality with canvas gamma linearization
|
@aviralgarg05 OK, I tested the last commit and everything works as expected now. |
|
@rodolforg @ice0 @BobSynfig @Abdelhadi-Wael Hey guys, Can some of you review the changes? There were a lot of mistakes and I am not confident reviewing it myself for I am not very good with C++. I can confirm that logic is correct and working properly but maybe you have some code-related feedback. If you approve, I'll merge it. |
rodolforg
left a comment
There was a problem hiding this comment.
@Svarov-RZM The only code issue I could see was outside of scope of this PR.
It seems the order of Hue Adjust, Brightness, Contrast and Exposure is different for the cobra render and the color pick/eyedrop tool.
I don't know if it could give different results though.
- Use references instead of pointers in TaskSaturationSW::run() loop - Add static inline apply_saturation_impl() to eliminate code duplication - Refactor TaskSaturationSW::apply_saturation() to use shared helper - Refactor Layer_ColorCorrect::correct_color() to use shared helper Addresses review comments by @rodolforg on PR synfig#3641
Wow, you were fast XD What about the change requests regarding the code style? |
Yup I was actually fixing them, was going through them one by one |
- Replace 'virtual' with 'override' for get_token() and run() methods
- Use 'Type& var' reference spacing instead of 'Type &var'
- Add set_description() for saturation parameter tooltip
- Replace std::max/std::min with synfig::clamp() for better readability
- Fix brace style: opening { on same line as if/for statements
- Add space between keywords (for, if) and opening parenthesis
- Keep pointer-based loop for efficiency (less address computation)
Addresses review comments by @rodolforg on PR synfig#3641
|
Thank you for the detailed review, @rodolforg! I've addressed all feedback in commits eb531ce and d39d348: Changes Made:
Regarding optional clamping:I kept clamping enabled for now because without it, saturation > 1.0 can push color components outside [0,1] range, potentially causing rendering artifacts. However, if you prefer, I can add a boolean parameter to make clamping optional for HDR workflows. Please let me know your preference. |
Oh, I suggested because I believe it would be something @morevnaproject would request lol |
When those artifacts are used to create some cool effects they become artistic vision :) @aviralgarg05 We have two things left to do:
And I believe we're done. |
- Fix reference spacing: 'Type &var' -> 'Type& var' for Surface variables - Remove clamping to allow artistic effects with saturation > 1.0 Addresses feedback from @rodolforg and @Abdelhadi-Wael on PR synfig#3641
|
Done with the feedbacks!! @Svarov-RZM @rodolforg |
I see that feedback was addressed, so I feel like I can handle it from here.
|
Sheesh, the history here is a mess... I am squashing it. @aviralgarg05 I finished testing it and didn't find any more problems. We struggled a bit with this but in the end we got it working. Thanks for not giving up and seeing it through. |
|
@Svarov-RZM @rodolforg is there a way I could personally connect with you, there is someone I got a message from looking to connect with you urgently regarding a few Synfig-related assets and has questions around licensing and legal responsibility for the community. |
|
@aviralgarg05 For legal matters, you should contact our project leader @morevnaproject (@KonstantinDmitriev on our forums) |
|
@aviralgarg05 Yeah, what Bob said - please use forums for this matter: https://forums.synfig.org/
There's no "urgently" in Open Source. |



This addresses issue #3634 by allowing independent control of color saturation without affecting brightness or contrast. The parameter works as follows:
The saturation parameter works independently from other color adjustments and is positioned in the transform chain after hue but before exposure, brightness, and contrast for optimal color processing.