From 78b2d84fa711a8d874d36ca70d5ab8bb1ebcebd8 Mon Sep 17 00:00:00 2001 From: Kamil Jarosz Date: Sun, 23 Jun 2024 18:05:35 +0200 Subject: [PATCH] swf: Add ColorTransform::multiply_from This method is used to instantiate ColorTransform with its multiplicative component equal to the given color. --- render/wgpu/src/surface/commands.rs | 8 +------- swf/src/types/color_transform.rs | 10 ++++++++++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/render/wgpu/src/surface/commands.rs b/render/wgpu/src/surface/commands.rs index ac5cbbb0c..c150f828b 100644 --- a/render/wgpu/src/surface/commands.rs +++ b/render/wgpu/src/surface/commands.rs @@ -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 => { diff --git a/swf/src/types/color_transform.rs b/swf/src/types/color_transform.rs index 01a249a4b..5ce5d728b 100644 --- a/swf/src/types/color_transform.rs +++ b/swf/src/types/color_transform.rs @@ -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] {