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

avoid using grayscale base when mixing richer colors #2408

Merged

Conversation

dginev
Copy link
Collaborator

@dginev dginev commented Aug 25, 2024

Fixes #2407

The problem was that when a base model is grayscale, a mix operation with rgb would remain in the base model - i.e. remain in grayscale. So when mix or add executes, the "richer" color model ought to be used.

Suggestions welcome if my code should be structured better, I almost made a new sub to hold the model-switching logic. Are there more places that could benefit from this treatment?

# have components discarded.
if ($base_model eq 'gray') {
my $enriched_base = $self->convert($mix_model);
return $enriched_base->mix($color, $fraction);
Copy link
Owner

Choose a reason for hiding this comment

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

Interesting; looks like you've likely got the right idea. I'm wondering out-loud whether it might be slightly less convoluted than a return from the middle to start with my $base = $self; and then if gray, do $base = $self->convert($mix_model);, and do the last few lines with $base instead of $self ? That would seem to make more transparent that you're really just re-expressing self in a different color model.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point, the extra recursion is just needless performance tax here. Now adjusted.

my @a = $self->components;
my @b = $color->components;
my @b = $other->components;
return $self->new(map { $a[$_] + $b[$_] } 0 .. $#a); }
Copy link
Owner

Choose a reason for hiding this comment

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

shouldn't the last 2 $self be $base? (like for mix)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Duh. How did that slip happen? One quote I overheard this morning:

"If it isn't tested, it is broken."

Copy link
Collaborator Author

@dginev dginev Sep 10, 2024

Choose a reason for hiding this comment

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

Thank you for catching that and avoiding a very annoying encounter+report+debug cascade later on. Fixed.

@dginev dginev force-pushed the avoid-grayscale-base-in-color-mix branch from 1939322 to 64349cc Compare September 10, 2024 21:05
Copy link
Owner

@brucemiller brucemiller left a comment

Choose a reason for hiding this comment

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

Looks good!

@brucemiller brucemiller merged commit 2373c01 into brucemiller:master Sep 17, 2024
13 checks passed
@brucemiller brucemiller deleted the avoid-grayscale-base-in-color-mix branch September 17, 2024 02:32
teepeemm pushed a commit to teepeemm/LaTeXML that referenced this pull request Oct 29, 2024
* avoid using grayscale base when mixing richer colors

* avoid needless recursion in color mixing/adding
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.

Color Mixing Desaturates Result
2 participants