swf: Add ColorTransform::multiply_from

This method is used to instantiate ColorTransform with its
multiplicative component equal to the given color.
This commit is contained in:
Kamil Jarosz 2024-06-23 18:05:35 +02:00
parent 2d6eefd622
commit 78b2d84fa7
2 changed files with 11 additions and 7 deletions

View File

@ -653,13 +653,7 @@ pub fn chunk_blends<'a>(
needs_stencil,
descriptors,
matrix,
ColorTransform {
r_multiply: Fixed8::from_f32(f32::from(color.r) / 255.0),
g_multiply: Fixed8::from_f32(f32::from(color.g) / 255.0),
b_multiply: Fixed8::from_f32(f32::from(color.b) / 255.0),
a_multiply: Fixed8::from_f32(f32::from(color.a) / 255.0),
..Default::default()
},
ColorTransform::multiply_from(color),
|transform_buffer| DrawCommand::DrawRect { transform_buffer },
),
Command::PushMask => {

View File

@ -25,6 +25,16 @@ impl ColorTransform {
a_add: 0,
};
pub fn multiply_from(color: Color) -> Self {
Self {
r_multiply: Fixed8::from_f32(f32::from(color.r) / 255.0),
g_multiply: Fixed8::from_f32(f32::from(color.g) / 255.0),
b_multiply: Fixed8::from_f32(f32::from(color.b) / 255.0),
a_multiply: Fixed8::from_f32(f32::from(color.a) / 255.0),
..Default::default()
}
}
/// Returns the multiplicative component of this color transform in RGBA order
/// with the values normalized [0.0, 1.0].
pub fn mult_rgba_normalized(&self) -> [f32; 4] {