core: Move get_pixel from BitmapData to bitmap_data_operations

This commit is contained in:
Nathan Adams 2023-03-24 08:09:16 +01:00
parent 758d8f1492
commit c2af7b92c0
4 changed files with 19 additions and 15 deletions

View File

@ -162,7 +162,9 @@ pub fn get_pixel<'gc>(
if let (Some(x_val), Some(y_val)) = (args.get(0), args.get(1)) {
let x = x_val.coerce_to_u32(activation)?;
let y = y_val.coerce_to_u32(activation)?;
return Ok(bitmap_data.bitmap_data().read().get_pixel(x, y).into());
let col =
bitmap_data_operations::get_pixel(bitmap_data.bitmap_data_wrapper(), x, y);
return Ok(col.into());
}
}
}

View File

@ -348,11 +348,12 @@ pub fn get_pixel<'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 x = args.get_u32(activation, 0)?;
let y = args.get_u32(activation, 1)?;
return Ok((bitmap_data.read().get_pixel(x, y) as u32).into());
let col = bitmap_data_operations::get_pixel(bitmap_data, x, y);
return Ok(col.into());
}
Ok(Value::Undefined)

View File

@ -556,17 +556,6 @@ impl<'gc> BitmapData<'gc> {
x >= 0 && x < self.width() as i32 && y >= 0 && y < self.height() as i32
}
pub fn get_pixel(&self, x: u32, y: u32) -> i32 {
if x < self.width && y < self.height {
self.get_pixel32_raw(x, y)
.to_un_multiplied_alpha()
.with_alpha(0x0)
.into()
} else {
0
}
}
pub fn get_pixels(
&self,
x: i32,

View File

@ -76,3 +76,15 @@ pub fn get_pixel32(target: BitmapDataWrapper, x: u32, y: u32) -> i32 {
let read = target.read();
read.get_pixel32_raw(x, y).to_un_multiplied_alpha().into()
}
pub fn get_pixel(target: BitmapDataWrapper, x: u32, y: u32) -> i32 {
if target.disposed() || x >= target.width() || y >= target.height() {
return 0;
}
let target = target.sync();
let read = target.read();
read.get_pixel32_raw(x, y)
.to_un_multiplied_alpha()
.with_alpha(0x0)
.into()
}