-
-
Notifications
You must be signed in to change notification settings - Fork 831
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement flash.filters.BitmapFilter and flash.filters.BlurFilter avm1 built-ins #1041
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1e9762c
core: Add basic flash.filters.(BlurFilter|BitmapFilter)
CUB3D b95dc03
core: Add tests for bitmap_filter
CUB3D e8d9b38
core: Add blurFilter and test
CUB3D e134ab1
core: Fix clippy lints and format
CUB3D 044faee
core: Make blurX and blurY floating point
CUB3D File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
//! flash.filter.BitmapFilter object | ||
|
||
use crate::avm1::activation::Activation; | ||
use crate::avm1::error::Error; | ||
use crate::avm1::{Object, ScriptObject, Value}; | ||
use enumset::EnumSet; | ||
use gc_arena::MutationContext; | ||
|
||
pub fn constructor<'gc>( | ||
_activation: &mut Activation<'_, 'gc, '_>, | ||
_this: Object<'gc>, | ||
_args: &[Value<'gc>], | ||
) -> Result<Value<'gc>, Error<'gc>> { | ||
Ok(Value::Undefined) | ||
} | ||
|
||
pub fn clone<'gc>( | ||
_activation: &mut Activation<'_, 'gc, '_>, | ||
_this: Object<'gc>, | ||
_args: &[Value<'gc>], | ||
) -> Result<Value<'gc>, Error<'gc>> { | ||
Ok(Value::Undefined) | ||
} | ||
|
||
pub fn create_proto<'gc>( | ||
gc_context: MutationContext<'gc, '_>, | ||
proto: Object<'gc>, | ||
fn_proto: Option<Object<'gc>>, | ||
) -> Object<'gc> { | ||
let mut object = ScriptObject::object(gc_context, Some(proto)); | ||
|
||
object.force_set_function("clone", clone, gc_context, EnumSet::empty(), fn_proto); | ||
|
||
object.into() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,201 @@ | ||
//! flash.filter.BlurFilter object | ||
|
||
use crate::avm1::activation::Activation; | ||
use crate::avm1::error::Error; | ||
use crate::avm1::function::{Executable, FunctionObject}; | ||
use crate::avm1::object::blur_filter::BlurFilterObject; | ||
use crate::avm1::{Object, TObject, Value}; | ||
use enumset::EnumSet; | ||
use gc_arena::MutationContext; | ||
|
||
pub fn constructor<'gc>( | ||
activation: &mut Activation<'_, 'gc, '_>, | ||
this: Object<'gc>, | ||
args: &[Value<'gc>], | ||
) -> Result<Value<'gc>, Error<'gc>> { | ||
let blur_x = args | ||
.get(0) | ||
.unwrap_or(&4.into()) | ||
.coerce_to_f64(activation) | ||
.map(|x| x.max(0.0).min(255.0))?; | ||
|
||
let blur_y = args | ||
.get(1) | ||
.unwrap_or(&4.into()) | ||
.coerce_to_f64(activation) | ||
.map(|x| x.max(0.0).min(255.0))?; | ||
|
||
let quality = args | ||
.get(2) | ||
.unwrap_or(&1.into()) | ||
.coerce_to_i32(activation) | ||
.map(|x| x.max(0).min(15))?; | ||
|
||
let blur_filter = this.as_blur_filter_object().unwrap(); | ||
|
||
blur_filter.set_blur_x(activation.context.gc_context, blur_x); | ||
blur_filter.set_blur_y(activation.context.gc_context, blur_y); | ||
blur_filter.set_quality(activation.context.gc_context, quality); | ||
|
||
Ok(Value::Undefined) | ||
} | ||
|
||
pub fn clone<'gc>( | ||
activation: &mut Activation<'_, 'gc, '_>, | ||
this: Object<'gc>, | ||
_args: &[Value<'gc>], | ||
) -> Result<Value<'gc>, Error<'gc>> { | ||
let proto = activation.context.avm1.prototypes.blur_filter_constructor; | ||
|
||
let blur_x = this.get("blurX", activation)?; | ||
let blur_y = this.get("blurY", activation)?; | ||
let quality = this.get("quality", activation)?; | ||
|
||
let cloned = proto.construct(activation, &[blur_x, blur_y, quality])?; | ||
Ok(cloned.into()) | ||
} | ||
|
||
pub fn get_blur_x<'gc>( | ||
_activation: &mut Activation<'_, 'gc, '_>, | ||
this: Object<'gc>, | ||
_args: &[Value<'gc>], | ||
) -> Result<Value<'gc>, Error<'gc>> { | ||
Ok(this.as_blur_filter_object().unwrap().get_blur_x().into()) | ||
} | ||
|
||
pub fn set_blur_x<'gc>( | ||
activation: &mut Activation<'_, 'gc, '_>, | ||
this: Object<'gc>, | ||
args: &[Value<'gc>], | ||
) -> Result<Value<'gc>, Error<'gc>> { | ||
let blur_x = args | ||
.get(0) | ||
.unwrap_or(&Value::Undefined) | ||
.coerce_to_f64(activation) | ||
.map(|x| x.max(0.0).min(255.0))?; | ||
|
||
this.as_blur_filter_object() | ||
.unwrap() | ||
.set_blur_x(activation.context.gc_context, blur_x); | ||
|
||
Ok(Value::Undefined) | ||
} | ||
|
||
pub fn get_blur_y<'gc>( | ||
_activation: &mut Activation<'_, 'gc, '_>, | ||
this: Object<'gc>, | ||
_args: &[Value<'gc>], | ||
) -> Result<Value<'gc>, Error<'gc>> { | ||
Ok(this.as_blur_filter_object().unwrap().get_blur_y().into()) | ||
} | ||
|
||
pub fn set_blur_y<'gc>( | ||
activation: &mut Activation<'_, 'gc, '_>, | ||
this: Object<'gc>, | ||
args: &[Value<'gc>], | ||
) -> Result<Value<'gc>, Error<'gc>> { | ||
let blur_y = args | ||
.get(0) | ||
.unwrap_or(&Value::Undefined) | ||
.coerce_to_f64(activation) | ||
.map(|x| x.max(0.0).min(255.0))?; | ||
|
||
this.as_blur_filter_object() | ||
.unwrap() | ||
.set_blur_y(activation.context.gc_context, blur_y); | ||
|
||
Ok(Value::Undefined) | ||
} | ||
|
||
pub fn get_quality<'gc>( | ||
_activation: &mut Activation<'_, 'gc, '_>, | ||
this: Object<'gc>, | ||
_args: &[Value<'gc>], | ||
) -> Result<Value<'gc>, Error<'gc>> { | ||
Ok(this.as_blur_filter_object().unwrap().get_quality().into()) | ||
} | ||
|
||
pub fn set_quality<'gc>( | ||
activation: &mut Activation<'_, 'gc, '_>, | ||
this: Object<'gc>, | ||
args: &[Value<'gc>], | ||
) -> Result<Value<'gc>, Error<'gc>> { | ||
let blur_y = args | ||
.get(0) | ||
.unwrap_or(&Value::Undefined) | ||
.coerce_to_i32(activation) | ||
.map(|x| x.max(0).min(15))?; | ||
|
||
this.as_blur_filter_object() | ||
.unwrap() | ||
.set_quality(activation.context.gc_context, blur_y); | ||
|
||
Ok(Value::Undefined) | ||
} | ||
|
||
pub fn create_proto<'gc>( | ||
gc_context: MutationContext<'gc, '_>, | ||
proto: Object<'gc>, | ||
fn_proto: Object<'gc>, | ||
) -> Object<'gc> { | ||
let blur_filter = BlurFilterObject::empty_object(gc_context, Some(proto)); | ||
let mut object = blur_filter.as_script_object().unwrap(); | ||
|
||
object.force_set_function("clone", clone, gc_context, EnumSet::empty(), Some(fn_proto)); | ||
|
||
object.add_property( | ||
gc_context, | ||
"blurX", | ||
FunctionObject::function( | ||
gc_context, | ||
Executable::Native(get_blur_x), | ||
Some(fn_proto), | ||
fn_proto, | ||
), | ||
Some(FunctionObject::function( | ||
gc_context, | ||
Executable::Native(set_blur_x), | ||
Some(fn_proto), | ||
fn_proto, | ||
)), | ||
EnumSet::empty(), | ||
); | ||
|
||
object.add_property( | ||
gc_context, | ||
"blurY", | ||
FunctionObject::function( | ||
gc_context, | ||
Executable::Native(get_blur_y), | ||
Some(fn_proto), | ||
fn_proto, | ||
), | ||
Some(FunctionObject::function( | ||
gc_context, | ||
Executable::Native(set_blur_y), | ||
Some(fn_proto), | ||
fn_proto, | ||
)), | ||
EnumSet::empty(), | ||
); | ||
|
||
object.add_property( | ||
gc_context, | ||
"quality", | ||
FunctionObject::function( | ||
gc_context, | ||
Executable::Native(get_quality), | ||
Some(fn_proto), | ||
fn_proto, | ||
), | ||
Some(FunctionObject::function( | ||
gc_context, | ||
Executable::Native(set_quality), | ||
Some(fn_proto), | ||
fn_proto, | ||
)), | ||
EnumSet::empty(), | ||
); | ||
|
||
blur_filter.into() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clone
doesn't seem to be overridden in the filter subclasses. (Does it copy the underlying object instead?)Flash: true, 10
Ruffle: false, undefined