From d76bbf04879add9d5586e8b2ce8017670be63523 Mon Sep 17 00:00:00 2001 From: britt-j <128912908+britt-j@users.noreply.github.com> Date: Fri, 4 Oct 2024 21:57:43 +0200 Subject: [PATCH 1/2] avm1: Make initialization of ConvolutionFilter with color set its alpha to 1 Initializing ConvolutionFilter with a substitute color will result in the alpha being set to 1 in AVM1, despite the documentation claiming alpha always defaults to 0. --- core/src/avm1/globals/convolution_filter.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/core/src/avm1/globals/convolution_filter.rs b/core/src/avm1/globals/convolution_filter.rs index 7bbd531e5637..8bd16ee81621 100644 --- a/core/src/avm1/globals/convolution_filter.rs +++ b/core/src/avm1/globals/convolution_filter.rs @@ -121,7 +121,18 @@ impl<'gc> ConvolutionFilter<'gc> { convolution_filter.set_bias(activation, args.get(4))?; convolution_filter.set_preserve_alpha(activation, args.get(5))?; convolution_filter.set_clamp(activation, args.get(6))?; - convolution_filter.set_color(activation, args.get(7))?; + if let Some(value) = args.get(7) { + convolution_filter.set_color(activation, Some(value))?; + + // If a substitute color is specified in the constructor in AVM1, + // the substitute alpha is set to 1, despite the documentation claiming otherwise. + // This does not happen in AVM2. + convolution_filter + .0 + .write(activation.context.gc_context) + .color + .a = 255; + } convolution_filter.set_alpha(activation, args.get(8))?; Ok(convolution_filter) } From a30475e0f5016405ec1e0ad94e034af4ec08fd20 Mon Sep 17 00:00:00 2001 From: britt-j <128912908+britt-j@users.noreply.github.com> Date: Fri, 18 Oct 2024 23:25:36 +0200 Subject: [PATCH 2/2] tests: Add test for AVM1 ConvolutionFilter initialization --- .../output.txt | 18 ++++++++++ .../avm1_convolution_initialization/test.as | 31 ++++++++++++++++++ .../avm1_convolution_initialization/test.swf | Bin 0 -> 410 bytes .../avm1_convolution_initialization/test.toml | 1 + 4 files changed, 50 insertions(+) create mode 100644 tests/tests/swfs/visual/filters/avm1_convolution_initialization/output.txt create mode 100644 tests/tests/swfs/visual/filters/avm1_convolution_initialization/test.as create mode 100644 tests/tests/swfs/visual/filters/avm1_convolution_initialization/test.swf create mode 100644 tests/tests/swfs/visual/filters/avm1_convolution_initialization/test.toml diff --git a/tests/tests/swfs/visual/filters/avm1_convolution_initialization/output.txt b/tests/tests/swfs/visual/filters/avm1_convolution_initialization/output.txt new file mode 100644 index 000000000000..c68c88f85869 --- /dev/null +++ b/tests/tests/swfs/visual/filters/avm1_convolution_initialization/output.txt @@ -0,0 +1,18 @@ +1 +0 +true +128 +9 +1,1,1,1,1,1,1,1,1 +3 +3 +true +0 +0 +true +0 +9 +1,1,1,1,1,1,1,1,1 +3 +3 +true diff --git a/tests/tests/swfs/visual/filters/avm1_convolution_initialization/test.as b/tests/tests/swfs/visual/filters/avm1_convolution_initialization/test.as new file mode 100644 index 000000000000..9caa33a6428a --- /dev/null +++ b/tests/tests/swfs/visual/filters/avm1_convolution_initialization/test.as @@ -0,0 +1,31 @@ +// Compile with: mtasc -main -version 8 -header 200:150:30 -swf test.swf test.as + +// TODO: Incorporate this into a more comprehensive test of ConvolutionFilter + +import flash.filters.ConvolutionFilter; +class Test { + static function main() { + // Initializing a ConvolutionFilter and specifying a color + var convoTest = new ConvolutionFilter(3,3,[1,1,1,1,1,1,1,1,1],9,0,true,true,128); + trace(convoTest.alpha); + trace(convoTest.bias); + trace(convoTest.clamp); + trace(convoTest.color); + trace(convoTest.divisor); + trace(convoTest.matrix); + trace(convoTest.matrixX); + trace(convoTest.matrixY); + trace(convoTest.preserveAlpha); + // Initializing a ConvolutionFilter without specifying a color + var convoTest2 = new ConvolutionFilter(3,3,[1,1,1,1,1,1,1,1,1],9,0,true,true); + trace(convoTest2.alpha); + trace(convoTest2.bias); + trace(convoTest2.clamp); + trace(convoTest2.color); + trace(convoTest2.divisor); + trace(convoTest2.matrix); + trace(convoTest2.matrixX); + trace(convoTest2.matrixY); + trace(convoTest2.preserveAlpha); + } +} \ No newline at end of file diff --git a/tests/tests/swfs/visual/filters/avm1_convolution_initialization/test.swf b/tests/tests/swfs/visual/filters/avm1_convolution_initialization/test.swf new file mode 100644 index 0000000000000000000000000000000000000000..4b77ffcbbcd2e9a804b2772a949cab2c8c061a5d GIT binary patch literal 410 zcmV;L0cHL}S5pW80{{Sc+N_ezP69Cy$EWQsyZ8Y@Oo$2bXyU~;FnmQ44=hAD=!q0u zU}M>Cwv}MKc$1Tfm%aHyK7)_p9osIwc`>nv|NLjtc7Dxt4d@%d{Q@{e(7{`^iUm+> zfRr>!$4ZqOjK>2yeW3GDT#P~?VOxr^-nDs$3Yf}x&iI5fNK!7jd`d!C(kO-*qhbNG zh{-S&(Bbilvqu^6xNAy4S+bxoiKu`nqss)QobeRyqg5nSTvC}v>s`3r#XHp`6k)mw zTjq3YI1J?=(3*lJ9ZO z;TdID;Jv8CMK1Dm)hlX2e-VA6omIdiIy0gh_>LiR1FeOj0>B0U`(ALC8{e9uHG9_V zTXSH|p*1CI%E~nV8{PXAofvdt(TPPT7M)mhV$q33Cl;MpbfVGwSvjY`4l=F%qstmJ zNL$%WT@9)?Y7IN%Uh6slxrjvm1I>Rklh)&{?I!Q#H~H9blbaeeRr&(}0RR6300wY- EGJoO0y#N3J literal 0 HcmV?d00001 diff --git a/tests/tests/swfs/visual/filters/avm1_convolution_initialization/test.toml b/tests/tests/swfs/visual/filters/avm1_convolution_initialization/test.toml new file mode 100644 index 000000000000..2708ada71a1d --- /dev/null +++ b/tests/tests/swfs/visual/filters/avm1_convolution_initialization/test.toml @@ -0,0 +1 @@ +num_frames = 1 \ No newline at end of file