core: Move get_pixel from BitmapData to bitmap_data_operations
This commit is contained in:
parent
758d8f1492
commit
c2af7b92c0
|
@ -162,7 +162,9 @@ pub fn get_pixel<'gc>(
|
||||||
if let (Some(x_val), Some(y_val)) = (args.get(0), args.get(1)) {
|
if let (Some(x_val), Some(y_val)) = (args.get(0), args.get(1)) {
|
||||||
let x = x_val.coerce_to_u32(activation)?;
|
let x = x_val.coerce_to_u32(activation)?;
|
||||||
let y = y_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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -348,11 +348,12 @@ pub fn get_pixel<'gc>(
|
||||||
this: Option<Object<'gc>>,
|
this: Option<Object<'gc>>,
|
||||||
args: &[Value<'gc>],
|
args: &[Value<'gc>],
|
||||||
) -> Result<Value<'gc>, Error<'gc>> {
|
) -> Result<Value<'gc>, Error<'gc>> {
|
||||||
if let Some(bitmap_data) = this.and_then(|t| t.as_bitmap_data()) {
|
if let Some(bitmap_data) = this.and_then(|t| t.as_bitmap_data_wrapper()) {
|
||||||
bitmap_data.read().check_valid(activation)?;
|
bitmap_data.check_valid(activation)?;
|
||||||
let x = args.get_u32(activation, 0)?;
|
let x = args.get_u32(activation, 0)?;
|
||||||
let y = args.get_u32(activation, 1)?;
|
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)
|
Ok(Value::Undefined)
|
||||||
|
|
|
@ -556,17 +556,6 @@ impl<'gc> BitmapData<'gc> {
|
||||||
x >= 0 && x < self.width() as i32 && y >= 0 && y < self.height() as i32
|
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(
|
pub fn get_pixels(
|
||||||
&self,
|
&self,
|
||||||
x: i32,
|
x: i32,
|
||||||
|
|
|
@ -76,3 +76,15 @@ pub fn get_pixel32(target: BitmapDataWrapper, x: u32, y: u32) -> i32 {
|
||||||
let read = target.read();
|
let read = target.read();
|
||||||
read.get_pixel32_raw(x, y).to_un_multiplied_alpha().into()
|
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()
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue