Fix convertion from Color to Pixel
This commit is contained in:
parent
f0ab184ea8
commit
a014b3e144
10
src/utils.rs
10
src/utils.rs
@ -175,10 +175,10 @@ impl Color {
|
|||||||
//that the values are within [0.0, 1.0], meaning we won't ever overflow an u8
|
//that the values are within [0.0, 1.0], meaning we won't ever overflow an u8
|
||||||
unsafe {
|
unsafe {
|
||||||
Pixel {
|
Pixel {
|
||||||
r: self.r.to_int_unchecked::<u8>() * 255,
|
r: (self.r * 255.0).to_int_unchecked::<u8>(),
|
||||||
g: self.g.to_int_unchecked::<u8>() * 255,
|
g: (self.g * 255.0).to_int_unchecked::<u8>(),
|
||||||
b: self.b.to_int_unchecked::<u8>() * 255,
|
b: (self.b * 255.0).to_int_unchecked::<u8>(),
|
||||||
a: self.a.to_int_unchecked::<u8>() * 255,
|
a: (self.a * 255.0).to_int_unchecked::<u8>(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -193,7 +193,7 @@ impl Color {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn alpha_blend(&self, other: &Self) -> Self {
|
pub fn alpha_blend(&self, other: &Self) -> Self {
|
||||||
//apply alpha compisting's "over" operator, see
|
//apply alpha compositing's "over" operator, see
|
||||||
//[https://en.wikipedia.org/wiki/Alpha_compositing] for more detail
|
//[https://en.wikipedia.org/wiki/Alpha_compositing] for more detail
|
||||||
let a = self.a + other.a * (1.0 - self.a);
|
let a = self.a + other.a * (1.0 - self.a);
|
||||||
Self {
|
Self {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user