Skip to content

Commit

Permalink
fix: optimize to unwrap_or_default for dark color and set 0.0 case fo…
Browse files Browse the repository at this point in the history
…r premultiplied alpha
  • Loading branch information
dt665m committed Mar 17, 2024
1 parent fa98121 commit 73ce0de
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
12 changes: 6 additions & 6 deletions src/draw/combined.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,13 @@ impl CombinedDrawer {
slot.attachment().and_then(|a| a.as_mesh())
{
let mut color = mesh_attachment.color() * slot.color() * skeleton.color();
let mut dark_color = slot
.dark_color()
.unwrap_or_else(|| Color::new_rgba(0.0, 0.0, 0.0, 0.0));
let mut dark_color = slot.dark_color().unwrap_or_default();
if self.premultiplied_alpha {
color.premultiply_alpha();
dark_color *= color.a;
dark_color.a = 1.0;
} else {
dark_color.a = 0.;
}
color = match self.color_space {
ColorSpace::SRGB => color,
Expand Down Expand Up @@ -271,13 +271,13 @@ impl CombinedDrawer {
(color, dark_color)
} else if let Some(region_attachment) = slot.attachment().and_then(|a| a.as_region()) {
let mut color = region_attachment.color() * slot.color() * skeleton.color();
let mut dark_color = slot
.dark_color()
.unwrap_or_else(|| Color::new_rgba(0.0, 0.0, 0.0, 0.0));
let mut dark_color = slot.dark_color().unwrap_or_default();
if self.premultiplied_alpha {
color.premultiply_alpha();
dark_color *= color.a;
dark_color.a = 1.0;
} else {
dark_color.a = 0.;
}
color = match self.color_space {
ColorSpace::SRGB => color,
Expand Down
6 changes: 3 additions & 3 deletions src/draw/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,13 @@ impl SimpleDrawer {
);

color *= slot.color() * skeleton.color();
let mut dark_color = slot
.dark_color()
.unwrap_or_else(|| Color::new_rgba(0.0, 0.0, 0.0, 0.0));
let mut dark_color = slot.dark_color().unwrap_or_default();
if self.premultiplied_alpha {
color.premultiply_alpha();
dark_color *= color.a;
dark_color.a = 1.0;
} else {
dark_color.a = 0.;
}
color = match self.color_space {
ColorSpace::SRGB => color,
Expand Down

0 comments on commit 73ce0de

Please sign in to comment.