Skip to content
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

fix: Unmultiply before brightening #3407

Merged
merged 2 commits into from
Dec 16, 2024

Conversation

jtmcdole
Copy link
Contributor

The image data read back is in a pre-multiplied state. Convert it back to straight alpha before brightening and then premultiply.

This just makes the colors go to white though:
image

You could alternatively use the HSV color space and increase the Value (brightness); this would be more subtle and keep the colors correct.

image

@spydon spydon changed the title Unmultiply before brightening fix: Unmultiply before brightening Dec 14, 2024
newPixelData[i + 1] = (color.g * 255).round();
newPixelData[i + 2] = (color.b * 255).round();
newPixelData[i + 3] = (color.a * 255).round();
final a = pixelData[i + 3] / 255;
Copy link
Member

Choose a reason for hiding this comment

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

do we need to do this on darken as well? [even though the issue is not visible with the example image on darken I imagine there could be similar thing going on]
or even put it on pixelsInUint8() so everyone gets it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I believe you want to operate on unmultiplied alpha to be accurate. I'll peek at the CI checks later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did want to ask: why not use HSL and increase L by the amount? I know the stack overflow comment makes it sound incorrect, but its more correct because it shouldn't be changing the hue or saturation. That being said, these functions are "brighten" and "darken" which I'm not clear on what the desired results are (white-out of colors?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also; what is "ammount" saying here? Are you wanting each pixel's individual's brightness to increase by some percentage amount (0 to 1) or are you trying to level all the brightness to a set level? If its individual; then 0 to 1 needs to be over the range of -<1.0> with 0 to 1 covering that.

Copy link
Member

Choose a reason for hiding this comment

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

I did want to ask: why not use HSL and increase L by the amount? I know the stack overflow comment makes it sound incorrect, but its more correct because it shouldn't be changing the hue or saturation. That being said, these functions are "brighten" and "darken" which I'm not clear on what the desired results are (white-out of colors?)

Sounds good to be, I think this was just our naive attempt at the implementation without doing any research. 😅
But maybe we should just be redirecting to those painting methods you mentioned?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I switched to HSL color from Painting and updated the darken call. The test errors and everything else has nothing to do with this code 😅

Copy link
Member

Choose a reason for hiding this comment

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

Also; what is "ammount" saying here? Are you wanting each pixel's individual's brightness to increase by some percentage amount (0 to 1) or are you trying to level all the brightness to a set level? If its individual; then 0 to 1 needs to be over the range of -<1.0> with 0 to 1 covering that.

Makes sense, I think we could also do a breaking change here since it hasn't really worked before. Or deprecate this method and create a new one if we have some name that could fit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I captured what was previously done here lighten = (color + (1 - color) * amount; darken = color * amount.

@luanpotter
Copy link
Member

Thank you so much @jtmcdole !
I will merge this as is to Spydon's branch so I can work on it more easily, and then fix the analyzer stuff.
I also want to extract the shared code between brighten and darken.

@luanpotter luanpotter merged commit 2d6c8c1 into flame-engine:fix/colors-darken Dec 16, 2024
3 of 8 checks passed
spydon added a commit that referenced this pull request Dec 17, 2024
Fix brighten and darken alpha issue.
This is all thanks to @jtmcdole's insight & fixes
[here](#3407).

---------

Co-authored-by: Lukas Klingsbo <[email protected]>
Co-authored-by: Erick Zanardo <[email protected]>
Co-authored-by: Lukas Klingsbo <[email protected]>
Co-authored-by: John McDole <[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.

3 participants