Skip to content

Handle almost-transparent and transparent pixels better #37

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

Merged
merged 3 commits into from
Sep 4, 2024

Conversation

trotzig
Copy link
Contributor

@trotzig trotzig commented Aug 26, 2024

I came across a case where one pixel is almost transparent and the other is fully transparent. Consider these pixels:

[ 1, 46, 250, 0 ]
[ 1, 42, 250, 4 ]

With our old logic, there was a color-delta of 1 between these pixels. If we blend them both with white, we instead get a very low color-delta value.

At first I was going to always blend with white, but I realized we are using fully transparent as a signal that there is a gap/missing pixels in either the before or after image. So I instead changed it to "intentional transparency" where something like

[255, 255, 255, 0]
[0, 0, 0, 0]
[100, 100, 100, 0]

would be considered "intentional transparency". Of course, this assumption can't always be made. But for us I think we can use it to get rid of the edge-case that I present here. There's still a risk that we'll encounter "wild" transparency with r===g===b but at least this is better than what we have.

I came across a case where one pixel is almost transparent and the other
is fully transparent. Consider these pixels:

[ 1, 46, 250, 0 ]
[ 1, 42, 250, 4 ]

With our old logic, there was a color-delta of `1` between these pixels.
If we blend them both with white, we instead get a very low color-delta
value.

At first I was going to always blend with white, but I realized we are
using fully transparent as a signal that there is a gap/missing pixels
in either the before or after image. So I instead changed it to
"intentional transparency" where something like

[255, 255, 255, 0]
[0, 0, 0, 0]
[100, 100, 100, 0]

would be considered "intentional transparency". Of course, this
assumption can't always be made. But for us I think we can use it to get
rid of the edge-case that I present here. There's still a risk that
we'll encounter "wild" transparency with r===g===b but at least this is
better than what we have.
@trotzig trotzig requested a review from lencioni August 26, 2024 08:50
Copy link
Collaborator

@lencioni lencioni left a comment

Choose a reason for hiding this comment

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

I don't think I understand, why can't we always blend with white?

@trotzig
Copy link
Contributor Author

trotzig commented Sep 2, 2024

I thought we used fully transparent when constructing the "gaps" in the image. But I was wrong, it looks like we use a semi-transparent pixel.

result[i + 3] = 122;

I'll change to blending with white and see what happens.

@trotzig
Copy link
Contributor Author

trotzig commented Sep 2, 2024

Okay, seems like commit d4ecfac is relevant here. Basically the avoidance of blending with white for fully transparent pixels was to make diffs that are different in width better. The missing area to the right for one of the images will be represented as fully transparent. If we blend it with white and then run color-delta there would be no difference.

Some code we had was assuming that everything fully transparent was
intentionally added by us as filler for missing content on the right of
either the before or after image. To make things more explicit, I'm
using the term "filler pixel" here and setting it to always be 1,1,1,1.
This way the intentions in the code become clearer and at the same time
we have less risk of collisions with a transparent pixel that we do not
control.
@trotzig
Copy link
Contributor Author

trotzig commented Sep 2, 2024

Pushed another commit to clarify some intentions. While this isn't great, it's slightly better than what we currently have.

This diff image looks slightly different now that we've made some
changes to the filler pixel.
@trotzig trotzig merged commit d772300 into main Sep 4, 2024
1 check passed
@trotzig trotzig deleted the intentional-transparency branch September 4, 2024 12:12
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