diff --git a/core/src/avm2/globals/flash/display/bitmapdata.rs b/core/src/avm2/globals/flash/display/bitmapdata.rs index aa82cd4aa..d70a42178 100644 --- a/core/src/avm2/globals/flash/display/bitmapdata.rs +++ b/core/src/avm2/globals/flash/display/bitmapdata.rs @@ -121,7 +121,7 @@ pub fn class_init<'gc>( Ok(Value::Undefined) } -/// Implements BitmapData.width`'s getter. +/// Implements `BitmapData.width`'s getter. pub fn width<'gc>( _activation: &mut Activation<'_, 'gc, '_>, this: Option>, @@ -134,7 +134,7 @@ pub fn width<'gc>( Ok(Value::Undefined) } -/// Implements BitmapData.height`'s getter. +/// Implements `BitmapData.height`'s getter. pub fn height<'gc>( _activation: &mut Activation<'_, 'gc, '_>, this: Option>, @@ -147,7 +147,7 @@ pub fn height<'gc>( Ok(Value::Undefined) } -/// Implements BitmapData.transparent`'s getter. +/// Implements `BitmapData.transparent`'s getter. pub fn transparent<'gc>( _activation: &mut Activation<'_, 'gc, '_>, this: Option>, @@ -160,6 +160,27 @@ pub fn transparent<'gc>( Ok(Value::Undefined) } +/// Implements `BitmapData.getPixel`. +pub fn get_pixel<'gc>( + activation: &mut Activation<'_, 'gc, '_>, + this: Option>, + args: &[Value<'gc>], +) -> Result, Error> { + if let Some(bitmap_data) = this.and_then(|t| t.as_bitmap_data()) { + let x = args + .get(0) + .unwrap_or(&Value::Undefined) + .coerce_to_i32(activation)?; + let y = args + .get(1) + .unwrap_or(&Value::Undefined) + .coerce_to_i32(activation)?; + return Ok((bitmap_data.read().get_pixel(x, y) as u32).into()); + } + + Ok(Value::Undefined) +} + /// Construct `BitmapData`'s class. pub fn create_class<'gc>(mc: MutationContext<'gc, '_>) -> GcCell<'gc, Class<'gc>> { let class = Class::new( @@ -186,5 +207,8 @@ pub fn create_class<'gc>(mc: MutationContext<'gc, '_>) -> GcCell<'gc, Class<'gc> ]; write.define_public_builtin_instance_properties(mc, PUBLIC_INSTANCE_PROPERTIES); + const PUBLIC_INSTANCE_METHODS: &[(&str, NativeMethodImpl)] = &[("getPixel", get_pixel)]; + write.define_public_builtin_instance_methods(mc, PUBLIC_INSTANCE_METHODS); + class } diff --git a/tests/tests/swfs/avm2/bitmapdata_constr/Test.as b/tests/tests/swfs/avm2/bitmapdata_constr/Test.as index 16c7117ed..1a33c2c31 100644 --- a/tests/tests/swfs/avm2/bitmapdata_constr/Test.as +++ b/tests/tests/swfs/avm2/bitmapdata_constr/Test.as @@ -1,12 +1,12 @@ -package { +package { public class Test { } } import flash.display.BitmapData; -trace("///var bd = new BitmapData(128, 128, true, 0xCAFEBABE);"); -var bd = new BitmapData(128, 128, true, 0xCAFEBABE); +trace("///var bd = new BitmapData(128, 128, true, 0x88FEBABE);"); +var bd = new BitmapData(128, 128, true, 0x88FEBABE); trace("///bd.width;"); trace(bd.width); diff --git a/tests/tests/swfs/avm2/bitmapdata_constr/output.txt b/tests/tests/swfs/avm2/bitmapdata_constr/output.txt index 3cebac1aa..73227c282 100644 --- a/tests/tests/swfs/avm2/bitmapdata_constr/output.txt +++ b/tests/tests/swfs/avm2/bitmapdata_constr/output.txt @@ -1,4 +1,4 @@ -///var bd = new BitmapData(128, 128, true, 0xCAFEBABE); +///var bd = new BitmapData(128, 128, true, 0x88FEBABE); ///bd.width; 128 ///bd.height; @@ -6,7 +6,7 @@ ///bd.transparent; true ///bd.getPixel(0,0); -16693695 +16628413 ///bd = new BitmapData(128, 128, false, 0xCAFEBABE); ///bd.width; 128 diff --git a/tests/tests/swfs/avm2/bitmapdata_constr/test.swf b/tests/tests/swfs/avm2/bitmapdata_constr/test.swf index 3afaeed92..2b3745a9a 100644 Binary files a/tests/tests/swfs/avm2/bitmapdata_constr/test.swf and b/tests/tests/swfs/avm2/bitmapdata_constr/test.swf differ