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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 27 additions & 10 deletions lib/LaTeXML/Common/Color.pm
Original file line number Diff line number Diff line change
Expand Up @@ -118,18 +118,35 @@ sub complement {

# Mix $self*$fraction + $color*(1-$fraction)
sub mix {
my ($self, $color, $fraction) = @_;
$color = $color->convert($self->model) unless $self->model eq $color->model;
my @a = $self->components;
my @b = $color->components;
return $self->new(map { $fraction * $a[$_] + (1 - $fraction) * $b[$_] } 0 .. $#a); }
my ($self, $other, $fraction) = @_;
my $base = $self;
my $base_model = $base->model;
my $mix_model = $other->model;
if ($base_model ne $mix_model) {
# mixing 'rgb|cmy' with 'gray' should yield 'rgb|cmy'.
if ($base_model eq 'gray') {
$base = $base->convert($mix_model);
} else {
$other = $other->convert($base_model);
} }
my @a = $base->components;
my @b = $other->components;
return $base->new(map { $fraction * $a[$_] + (1 - $fraction) * $b[$_] } 0 .. $#a); }

sub add {
my ($self, $color) = @_;
$color = $color->convert($self->model) unless $self->model eq $color->model;
my @a = $self->components;
my @b = $color->components;
return $self->new(map { $a[$_] + $b[$_] } 0 .. $#a); }
my ($self, $other) = @_;
my $base = $self;
my $base_model = $base->model;
my $mix_model = $other->model;
if ($base_model ne $mix_model) {
# mixing 'rgb|cmy' with 'gray' should yield 'rgb|cmy'.
if ($base_model eq 'gray') {
$base = $base->convert($mix_model);
} else {
$other = $other->convert($base_model); } }
my @a = $base->components;
my @b = $other->components;
return $base->new(map { $a[$_] + $b[$_] } 0 .. $#a); }

# The next 2 methods multiply the components of a color by some value(s)
# This assumes that such a thing makes sense in the given model, for some purpose.
Expand Down
Loading