core: Move set_pixel from BitmapData to bitmap_data_operations
This commit is contained in:
parent
a41a797b4a
commit
eb04738b73
|
@ -206,10 +206,13 @@ pub fn set_pixel<'gc>(
|
|||
let y = y_val.coerce_to_u32(activation)?;
|
||||
let color = color_val.coerce_to_i32(activation)?;
|
||||
|
||||
bitmap_data
|
||||
.bitmap_data()
|
||||
.write(activation.context.gc_context)
|
||||
.set_pixel(x, y, color.into());
|
||||
bitmap_data_operations::set_pixel(
|
||||
&mut activation.context,
|
||||
bitmap_data.bitmap_data_wrapper(),
|
||||
x,
|
||||
y,
|
||||
color.into(),
|
||||
);
|
||||
|
||||
return Ok(Value::Undefined);
|
||||
}
|
||||
|
|
|
@ -379,13 +379,11 @@ pub fn set_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()) {
|
||||
if let Some(bitmap_data) = this.and_then(|t| t.as_bitmap_data_wrapper()) {
|
||||
let x = args.get_u32(activation, 0)?;
|
||||
let y = args.get_u32(activation, 1)?;
|
||||
let color = args.get_i32(activation, 2)?;
|
||||
bitmap_data
|
||||
.write(activation.context.gc_context)
|
||||
.set_pixel(x, y, color.into());
|
||||
bitmap_data_operations::set_pixel(&mut activation.context, bitmap_data, x, y, color.into());
|
||||
}
|
||||
|
||||
Ok(Value::Undefined)
|
||||
|
|
|
@ -621,19 +621,6 @@ impl<'gc> BitmapData<'gc> {
|
|||
result
|
||||
}
|
||||
|
||||
pub fn set_pixel(&mut self, x: u32, y: u32, color: Color) {
|
||||
if x < self.width && y < self.height {
|
||||
if self.transparency {
|
||||
let current_alpha = self.get_pixel32_raw(x, y).alpha();
|
||||
let color = color.with_alpha(current_alpha).to_premultiplied_alpha(true);
|
||||
self.set_pixel32_raw(x, y, color);
|
||||
} else {
|
||||
self.set_pixel32_raw(x, y, color.with_alpha(0xFF));
|
||||
}
|
||||
self.set_cpu_dirty(PixelRegion::for_whole_size(x, y));
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_pixel32_raw(&mut self, x: u32, y: u32, color: Color) {
|
||||
self.pixels[(x + y * self.width) as usize] = color;
|
||||
|
|
|
@ -82,6 +82,29 @@ pub fn get_pixel32(target: BitmapDataWrapper, x: u32, y: u32) -> i32 {
|
|||
read.get_pixel32_raw(x, y).to_un_multiplied_alpha().into()
|
||||
}
|
||||
|
||||
pub fn set_pixel<'gc>(
|
||||
context: &mut UpdateContext<'_, 'gc>,
|
||||
target: BitmapDataWrapper<'gc>,
|
||||
x: u32,
|
||||
y: u32,
|
||||
color: Color,
|
||||
) {
|
||||
if x >= target.width() || y >= target.height() {
|
||||
return;
|
||||
}
|
||||
let target = target.sync();
|
||||
let mut write = target.write(context.gc_context);
|
||||
|
||||
if write.transparency() {
|
||||
let current_alpha = write.get_pixel32_raw(x, y).alpha();
|
||||
let color = color.with_alpha(current_alpha).to_premultiplied_alpha(true);
|
||||
write.set_pixel32_raw(x, y, color);
|
||||
} else {
|
||||
write.set_pixel32_raw(x, y, color.with_alpha(0xFF));
|
||||
}
|
||||
write.set_cpu_dirty(PixelRegion::for_whole_size(x, y));
|
||||
}
|
||||
|
||||
pub fn get_pixel(target: BitmapDataWrapper, x: u32, y: u32) -> i32 {
|
||||
if target.disposed() || x >= target.width() || y >= target.height() {
|
||||
return 0;
|
||||
|
|
Loading…
Reference in New Issue