chore: Use to_le_bytes in more places

This commit is contained in:
relrelb 2021-06-22 20:07:00 +03:00 committed by relrelb
parent 87e9dda250
commit 580d8c3562
5 changed files with 18 additions and 26 deletions

View File

@ -130,21 +130,20 @@ fn set_rgb<'gc>(
) -> Result<Value<'gc>, Error<'gc>> {
if let Some(target) = target(activation, this)? {
target.set_transformed_by_script(activation.context.gc_context, true);
let mut color_transform = target.color_transform_mut(activation.context.gc_context);
let rgb = args
.get(0)
.unwrap_or(&Value::Undefined)
.coerce_to_i32(activation)? as i32;
let r = (rgb >> 16) & 0xff;
let g = (rgb >> 8) & 0xff;
let b = rgb & 0xff;
let [b, g, r, _] = rgb.to_le_bytes();
let mut color_transform = target.color_transform_mut(activation.context.gc_context);
color_transform.r_mult = Fixed8::ZERO;
color_transform.g_mult = Fixed8::ZERO;
color_transform.b_mult = Fixed8::ZERO;
color_transform.r_add = r as i16;
color_transform.g_add = g as i16;
color_transform.b_add = b as i16;
color_transform.r_add = r.into();
color_transform.g_add = g.into();
color_transform.b_add = b.into();
}
Ok(Value::Undefined)
}

View File

@ -140,15 +140,12 @@ pub fn set_rgb<'gc>(
.get(0)
.unwrap_or(&Value::Undefined)
.coerce_to_u32(activation)?;
let red = ((new_rgb >> 16) & 0xFF) as f64;
let green = ((new_rgb >> 8) & 0xFF) as f64;
let blue = (new_rgb & 0xFF) as f64;
let [b, g, r, _] = new_rgb.to_le_bytes();
if let Some(ct) = this.as_color_transform_object() {
ct.set_red_offset(activation.context.gc_context, red);
ct.set_green_offset(activation.context.gc_context, green);
ct.set_blue_offset(activation.context.gc_context, blue);
ct.set_red_offset(activation.context.gc_context, r.into());
ct.set_green_offset(activation.context.gc_context, g.into());
ct.set_blue_offset(activation.context.gc_context, b.into());
ct.set_red_multiplier(activation.context.gc_context, 0.0);
ct.set_green_multiplier(activation.context.gc_context, 0.0);

View File

@ -513,7 +513,7 @@ fn lerp_matrix(start: &swf::Matrix, end: &swf::Matrix, a: f32, b: f32) -> swf::M
fn lerp_gradient(start: &swf::Gradient, end: &swf::Gradient, a: f32, b: f32) -> swf::Gradient {
use swf::{Gradient, GradientRecord};
// Morph gradients are guaranteed to have the same number of records in the start/end gradient.
debug_assert!(start.records.len() == end.records.len());
debug_assert_eq!(start.records.len(), end.records.len());
let records: Vec<GradientRecord> = start
.records
.iter()

View File

@ -124,12 +124,12 @@ impl<W: Write> Writer<W> {
Ok(())
}
#[allow(dead_code)]
fn write_i24(&mut self, n: i32) -> Result<()> {
// TODO: Verify n fits in 24-bits.
self.write_u8(((n >> 16) & 0xff) as u8)?;
self.write_u8(((n >> 8) & 0xff) as u8)?;
self.write_u8((n & 0xff) as u8)?;
let bytes = n.to_le_bytes();
debug_assert!(bytes[3] == 0 || bytes[3] == 0xFF);
self.write_u8(bytes[2])?;
self.write_u8(bytes[1])?;
self.write_u8(bytes[0])?;
Ok(())
}

View File

@ -420,12 +420,8 @@ impl Color {
/// let blue = Color::from_rgb(0x0000FF, 255);
/// ```
pub const fn from_rgb(rgb: u32, alpha: u8) -> Self {
Self {
r: ((rgb & 0xFF_0000) >> 16) as u8,
g: ((rgb & 0x00_FF00) >> 8) as u8,
b: (rgb & 0x00_00FF) as u8,
a: alpha,
}
let [b, g, r, _] = rgb.to_le_bytes();
Self { r, g, b, a: alpha }
}
/// Converts the color to a 32-bit RGB value.