diff --git a/core/src/avm2/globals/flash/display/bitmap_data.rs b/core/src/avm2/globals/flash/display/bitmap_data.rs index c936c0df2..4fd206a94 100644 --- a/core/src/avm2/globals/flash/display/bitmap_data.rs +++ b/core/src/avm2/globals/flash/display/bitmap_data.rs @@ -301,8 +301,8 @@ pub fn get_vector<'gc>( this: Option>, args: &[Value<'gc>], ) -> Result, Error<'gc>> { - if let Some(bitmap_data) = this.and_then(|t| t.as_bitmap_data()) { - bitmap_data.read().check_valid(activation)?; + if let Some(bitmap_data) = this.and_then(|t| t.as_bitmap_data_wrapper()) { + bitmap_data.check_valid(activation)?; let rectangle = args.get_object(activation, 0, "rect")?; let x = rectangle .get_public_property("x", activation)? @@ -317,7 +317,7 @@ pub fn get_vector<'gc>( .get_public_property("height", activation)? .coerce_to_i32(activation)?; - let pixels = bitmap_data.read().get_vector(x, y, width, height); + let pixels = bitmap_data_operations::get_vector(bitmap_data, x, y, width, height); let value_type = activation.avm2().classes().uint; let new_storage = VectorStorage::from_values(pixels, false, value_type); diff --git a/core/src/bitmap/bitmap_data.rs b/core/src/bitmap/bitmap_data.rs index 1363cf587..30bf42b24 100644 --- a/core/src/bitmap/bitmap_data.rs +++ b/core/src/bitmap/bitmap_data.rs @@ -597,26 +597,6 @@ impl<'gc> BitmapData<'gc> { Ok(result) } - pub fn get_vector(&self, x: i32, y: i32, width: i32, height: i32) -> Vec> { - let x0 = x.max(0) as u32; - let y0 = y.max(0) as u32; - let x1 = (x + width).clamp(0, self.width as i32) as u32; - let y1 = (y + height).clamp(0, self.height as i32) as u32; - - let capacity = (y1 - y0) * (x1 - x0); - let mut result = Vec::with_capacity(capacity as usize); - - for y in y0..y1 { - for x in x0..x1 { - let color = self.pixels[(x + y * self.width) as usize]; - let color = color.to_un_multiplied_alpha().0 as u32; - result.push(color.into()); - } - } - - result - } - #[inline] pub fn set_pixel32_raw(&mut self, x: u32, y: u32, color: Color) { self.pixels[(x + y * self.width) as usize] = color; diff --git a/core/src/bitmap/bitmap_data_operations.rs b/core/src/bitmap/bitmap_data_operations.rs index cd095e427..713b050ff 100644 --- a/core/src/bitmap/bitmap_data_operations.rs +++ b/core/src/bitmap/bitmap_data_operations.rs @@ -1,3 +1,4 @@ +use crate::avm2::Value as Avm2Value; use crate::bitmap::bitmap_data::{ BitmapData, BitmapDataDrawError, BitmapDataWrapper, ChannelOptions, Color, IBitmapDrawable, LehmerRng, ThresholdOperation, @@ -1304,3 +1305,31 @@ pub fn draw<'gc>( None => Err(BitmapDataDrawError::Unimplemented), } } + +pub fn get_vector( + target: BitmapDataWrapper, + x: i32, + y: i32, + width: i32, + height: i32, +) -> Vec { + let x0 = x.max(0) as u32; + let y0 = y.max(0) as u32; + let x1 = (x + width).clamp(0, target.width() as i32) as u32; + let y1 = (y + height).clamp(0, target.height() as i32) as u32; + + let capacity = (y1 - y0) * (x1 - x0); + let mut result = Vec::with_capacity(capacity as usize); + + let target = target.sync(); + let read = target.read(); + for y in y0..y1 { + for x in x0..x1 { + let color = read.get_pixel32_raw(x, y); + let color = u32::from(color.to_un_multiplied_alpha()); + result.push(color.into()); + } + } + + result +}