core: Move get_vector from BitmapData to bitmap_data_operations
This commit is contained in:
parent
e4caedcc12
commit
89c2fc841e
|
@ -301,8 +301,8 @@ pub fn get_vector<'gc>(
|
|||
this: Option<Object<'gc>>,
|
||||
args: &[Value<'gc>],
|
||||
) -> Result<Value<'gc>, 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);
|
||||
|
|
|
@ -597,26 +597,6 @@ impl<'gc> BitmapData<'gc> {
|
|||
Ok(result)
|
||||
}
|
||||
|
||||
pub fn get_vector(&self, x: i32, y: i32, width: i32, height: i32) -> Vec<Avm2Value<'gc>> {
|
||||
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;
|
||||
|
|
|
@ -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<Avm2Value> {
|
||||
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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue