Skip to content
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

avm2: Use slot access in filter code #18957

Merged
merged 10 commits into from
Dec 13, 2024
178 changes: 102 additions & 76 deletions core/src/avm2/filters.rs

Large diffs are not rendered by default.

143 changes: 84 additions & 59 deletions core/src/avm2/globals/flash/filters/BevelFilter.as
Original file line number Diff line number Diff line change
@@ -1,61 +1,86 @@
package flash.filters {
public final class BevelFilter extends BitmapFilter {
public var angle : Number;
public var blurX : Number;
public var blurY : Number;
public var distance : Number;
public var highlightAlpha : Number;
public var highlightColor : uint;
public var knockout : Boolean;
public var quality : int;
public var shadowAlpha : Number;
public var shadowColor : uint;
public var strength : Number;
public var type : String;

public function BevelFilter(
distance:Number = 4.0,
angle:Number = 45,
highlightColor:uint = 0xFFFFFF,
highlightAlpha:Number = 1.0,
shadowColor:uint = 0x000000,
shadowAlpha:Number = 1.0,
blurX:Number = 4.0,
blurY:Number = 4.0,
strength:Number = 1,
quality:int = 1,
type:String = "inner",
knockout:Boolean = false
) {
this.angle = angle;
this.blurX = blurX;
this.blurY = blurY;
this.distance = distance;
this.highlightAlpha = highlightAlpha;
this.highlightColor = highlightColor;
this.knockout = knockout;
this.quality = quality;
this.shadowAlpha = shadowAlpha;
this.shadowColor = shadowColor;
this.strength = strength;
this.type = type;
}

override public function clone(): BitmapFilter {
return new BevelFilter(
this.distance,
this.angle,
this.highlightColor,
this.highlightAlpha,
this.shadowColor,
this.shadowAlpha,
this.blurX,
this.blurY,
this.strength,
this.quality,
this.type,
this.knockout
);
}
}
public final class BevelFilter extends BitmapFilter {
// FIXME these should all be getters/setters to match Flash

[Ruffle(InternalSlot)]
public var angle : Number;

[Ruffle(InternalSlot)]
public var blurX : Number;

[Ruffle(InternalSlot)]
public var blurY : Number;

[Ruffle(InternalSlot)]
public var distance : Number;

[Ruffle(InternalSlot)]
public var highlightAlpha : Number;

[Ruffle(InternalSlot)]
public var highlightColor : uint;

[Ruffle(InternalSlot)]
public var knockout : Boolean;

[Ruffle(InternalSlot)]
public var quality : int;

[Ruffle(InternalSlot)]
public var shadowAlpha : Number;

[Ruffle(InternalSlot)]
public var shadowColor : uint;

[Ruffle(InternalSlot)]
public var strength : Number;

[Ruffle(InternalSlot)]
public var type : String;

public function BevelFilter(
distance:Number = 4.0,
angle:Number = 45,
highlightColor:uint = 0xFFFFFF,
highlightAlpha:Number = 1.0,
shadowColor:uint = 0x000000,
shadowAlpha:Number = 1.0,
blurX:Number = 4.0,
blurY:Number = 4.0,
strength:Number = 1,
quality:int = 1,
type:String = "inner",
knockout:Boolean = false
) {
this.angle = angle;
this.blurX = blurX;
this.blurY = blurY;
this.distance = distance;
this.highlightAlpha = highlightAlpha;
this.highlightColor = highlightColor;
this.knockout = knockout;
this.quality = quality;
this.shadowAlpha = shadowAlpha;
this.shadowColor = shadowColor;
this.strength = strength;
this.type = type;
}

override public function clone(): BitmapFilter {
return new BevelFilter(
this.distance,
this.angle,
this.highlightColor,
this.highlightAlpha,
this.shadowColor,
this.shadowAlpha,
this.blurX,
this.blurY,
this.strength,
this.quality,
this.type,
this.knockout
);
}
}
}
10 changes: 5 additions & 5 deletions core/src/avm2/globals/flash/filters/BitmapFilter.as
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package flash.filters {
public class BitmapFilter {
public function clone(): BitmapFilter {
return null;
}
}
public class BitmapFilter {
public function clone(): BitmapFilter {
return null;
}
}
}
31 changes: 18 additions & 13 deletions core/src/avm2/globals/flash/filters/BlurFilter.as
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
package flash.filters {
public final class BlurFilter extends BitmapFilter {
public var blurX: Number;
public var blurY: Number;
public var quality: int;
public final class BlurFilter extends BitmapFilter {
[Ruffle(InternalSlot)]
public var blurX: Number;

public function BlurFilter(blurX: Number = 4.0, blurY: Number = 4.0, quality: int = 1) {
this.blurX = blurX;
this.blurY = blurY;
this.quality = quality;
}
[Ruffle(InternalSlot)]
public var blurY: Number;

override public function clone(): BitmapFilter {
return new BlurFilter(this.blurX, this.blurY, this.quality);
}
}
[Ruffle(InternalSlot)]
public var quality: int;

public function BlurFilter(blurX: Number = 4.0, blurY: Number = 4.0, quality: int = 1) {
this.blurX = blurX;
this.blurY = blurY;
this.quality = quality;
}

override public function clone(): BitmapFilter {
return new BlurFilter(this.blurX, this.blurY, this.quality);
}
}
}
57 changes: 29 additions & 28 deletions core/src/avm2/globals/flash/filters/ColorMatrixFilter.as
Original file line number Diff line number Diff line change
@@ -1,35 +1,36 @@
package flash.filters {
public final class ColorMatrixFilter extends BitmapFilter {
private var _matrix: Array;
public final class ColorMatrixFilter extends BitmapFilter {
[Ruffle(InternalSlot)]
private var _matrix: Array;

public function ColorMatrixFilter(matrix: Array = null) {
if (matrix == null) {
matrix = [
1, 0, 0, 0, 0,
0, 1, 0, 0, 0,
0, 0, 1, 0, 0,
0, 0, 0, 1, 0
];
}
this.matrix = matrix;
}
public function ColorMatrixFilter(matrix: Array = null) {
if (matrix == null) {
matrix = [
1, 0, 0, 0, 0,
0, 1, 0, 0, 0,
0, 0, 1, 0, 0,
0, 0, 0, 1, 0
];
}
this.matrix = matrix;
}

// From the Flash docs, we need to make a copy of the `Array`,
// as modifying the `filter.matrix` directly should have no effect.
// We call the method in the AS3 namespace, as some SWFS define a
// extend `Array` and declare a *public* 'concat' method with a
// different signature.
// From the Flash docs, we need to make a copy of the `Array`,
// as modifying the `filter.matrix` directly should have no effect.
// We call the method in the AS3 namespace, as some SWFS define a
// extend `Array` and declare a *public* 'concat' method with a
// different signature.

public function get matrix(): Array {
return this._matrix.AS3::concat();
}
public function get matrix(): Array {
return this._matrix.AS3::concat();
}

public function set matrix(matrix:Array):void {
this._matrix = matrix.AS3::concat();
}
public function set matrix(matrix:Array):void {
this._matrix = matrix.AS3::concat();
}

override public function clone(): BitmapFilter {
return new ColorMatrixFilter(this.matrix.AS3::concat());
}
}
override public function clone(): BitmapFilter {
return new ColorMatrixFilter(this.matrix.AS3::concat());
}
}
}
91 changes: 54 additions & 37 deletions core/src/avm2/globals/flash/filters/ConvolutionFilter.as
Original file line number Diff line number Diff line change
@@ -1,39 +1,56 @@
package flash.filters {
public final class ConvolutionFilter extends BitmapFilter {
public var alpha : Number;
public var bias : Number;
public var clamp : Boolean;
public var color : uint;
public var divisor : Number;
public var matrix : Array;
public var matrixX : Number;
public var matrixY : Number;
public var preserveAlpha : Boolean;

public function ConvolutionFilter(
matrixX:Number = 0,
matrixY:Number = 0,
matrix:Array = null,
divisor:Number = 1.0,
bias:Number = 0.0,
preserveAlpha:Boolean = true,
clamp:Boolean = true,
color:uint = 0,
alpha:Number = 0.0
) {
this.alpha = alpha;
this.bias = bias;
this.clamp = clamp;
this.color = color;
this.divisor = divisor;
this.matrix = matrix;
this.matrixX = matrixX;
this.matrixY = matrixY;
this.preserveAlpha = preserveAlpha;
}

override public function clone(): BitmapFilter {
return new ConvolutionFilter(this.matrixX, this.matrixY, this.matrixull, this.divisor, this.bias, this.preserveAlpharue, this.clamprue, this.color, this.alpha);
}
}
public final class ConvolutionFilter extends BitmapFilter {
[Ruffle(InternalSlot)]
public var alpha : Number;

[Ruffle(InternalSlot)]
public var bias : Number;

[Ruffle(InternalSlot)]
public var clamp : Boolean;

[Ruffle(InternalSlot)]
public var color : uint;

[Ruffle(InternalSlot)]
public var divisor : Number;

[Ruffle(InternalSlot)]
public var matrix : Array;

[Ruffle(InternalSlot)]
public var matrixX : Number;

[Ruffle(InternalSlot)]
public var matrixY : Number;

[Ruffle(InternalSlot)]
public var preserveAlpha : Boolean;

public function ConvolutionFilter(
matrixX:Number = 0,
matrixY:Number = 0,
matrix:Array = null,
divisor:Number = 1.0,
bias:Number = 0.0,
preserveAlpha:Boolean = true,
clamp:Boolean = true,
color:uint = 0,
alpha:Number = 0.0
) {
this.alpha = alpha;
this.bias = bias;
this.clamp = clamp;
this.color = color;
this.divisor = divisor;
this.matrix = matrix;
this.matrixX = matrixX;
this.matrixY = matrixY;
this.preserveAlpha = preserveAlpha;
}

override public function clone(): BitmapFilter {
return new ConvolutionFilter(this.matrixX, this.matrixY, this.matrixull, this.divisor, this.bias, this.preserveAlpharue, this.clamprue, this.color, this.alpha);
}
}
}
Loading