swf2js 0.1.2 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +81 -14
- package/package.json +11 -7
- package/studio/actionscript-roundtrip.test.js +54 -0
- package/studio/actionscript-scripts.test.js +169 -0
- package/studio/animated-image.test.js +137 -0
- package/studio/arithmetic.test.js +16 -0
- package/studio/as3-import.test.js +110 -0
- package/studio/audio-info.test.js +44 -0
- package/studio/components.test.js +152 -0
- package/studio/document-editing.test.js +92 -0
- package/studio/examples/01-space-mission.json +1628 -0
- package/studio/examples/02-clockwork-vault.json +1079 -0
- package/studio/examples/03-neon-synth.json +1364 -0
- package/studio/examples/04-kinetic-poster.json +923 -0
- package/studio/examples/05-signal-relay.json +1131 -0
- package/studio/examples/06-calculator.json +564 -0
- package/studio/frame-editing.test.js +129 -0
- package/studio/frame-events.test.js +117 -0
- package/studio/groups.test.js +88 -0
- package/studio/index.html +962 -0
- package/studio/interaction-triggers.test.js +37 -0
- package/studio/linked-actions.test.js +48 -0
- package/studio/lottie.test.js +208 -0
- package/studio/masks.test.js +43 -0
- package/studio/media-assets.test.js +62 -0
- package/studio/paint-tools.test.js +60 -0
- package/studio/playback.test.js +17 -0
- package/studio/project-io.test.js +405 -0
- package/studio/project-preview.test.js +475 -0
- package/studio/scene-transition.test.js +32 -0
- package/studio/server/archive-companions.js +27 -0
- package/studio/server/as3-library.js +91 -0
- package/studio/server/assets.js +162 -0
- package/studio/server/audio-info.js +82 -0
- package/studio/server/font-files.js +332 -0
- package/studio/server/http.js +135 -0
- package/studio/server/linked-actions.js +93 -0
- package/studio/server/png-decode.js +1 -0
- package/studio/server/project-movie.js +1164 -0
- package/studio/server/project-preview.js +152 -0
- package/studio/server/projects.js +370 -0
- package/studio/server/report.js +29 -0
- package/studio/server/routes.js +93 -0
- package/studio/server/swf-authoring.js +90 -0
- package/studio/server/swf-control-runtime.as +513 -0
- package/studio/server/swf-controls.js +119 -0
- package/studio/server/swf-export.js +293 -0
- package/studio/server/swf-import.js +1675 -0
- package/studio/server/swf-morphs.js +64 -0
- package/studio/server/swf-routes.js +42 -0
- package/studio/server/swf-streams.js +80 -0
- package/studio/server/swf-transition-runtime.as +52 -0
- package/studio/server/tween-recovery.js +106 -0
- package/studio/server-api.test.js +283 -0
- package/studio/server.js +320 -0
- package/studio/src/animated-image.js +423 -0
- package/studio/src/appearance-inspector.js +63 -0
- package/studio/src/arithmetic.js +50 -0
- package/studio/src/authored-controls.js +42 -0
- package/studio/src/busy.js +41 -0
- package/studio/src/canvas.js +430 -0
- package/studio/src/clipper-browser.js +2 -0
- package/studio/src/color-transform.js +38 -0
- package/studio/src/component-inspector.js +126 -0
- package/studio/src/components.js +268 -0
- package/studio/src/display-frame.js +262 -0
- package/studio/src/document-editing.js +69 -0
- package/studio/src/event-editor.js +150 -0
- package/studio/src/frame-editing.js +150 -0
- package/studio/src/frame-events.js +128 -0
- package/studio/src/frame-image.js +28 -0
- package/studio/src/groups.js +125 -0
- package/studio/src/handler-editor.js +122 -0
- package/studio/src/history.js +83 -0
- package/studio/src/imported-paths.js +99 -0
- package/studio/src/index.js +3582 -0
- package/studio/src/interaction-triggers.js +42 -0
- package/studio/src/json-patch.js +77 -0
- package/studio/src/layer-icons.js +25 -0
- package/studio/src/lottie-export.js +948 -0
- package/studio/src/lottie-import.js +1138 -0
- package/studio/src/masks.js +69 -0
- package/studio/src/media-assets.js +188 -0
- package/studio/src/media-library.js +193 -0
- package/studio/src/model.js +431 -0
- package/studio/src/numeric-fields.js +46 -0
- package/studio/src/object-list.js +57 -0
- package/studio/src/paint-tools.js +76 -0
- package/studio/src/placement-effects.js +74 -0
- package/studio/src/playback.js +10 -0
- package/studio/src/preview-audio.js +64 -0
- package/studio/src/preview-interactions.js +106 -0
- package/studio/src/preview-recorder.js +335 -0
- package/studio/src/preview-surface.js +338 -0
- package/studio/src/project-io.js +905 -0
- package/studio/src/project-session.js +375 -0
- package/studio/src/projects-dialog.js +319 -0
- package/studio/src/scene-transition.js +129 -0
- package/studio/src/script-editor.js +175 -0
- package/studio/src/script-references.js +74 -0
- package/studio/src/scripted-controls.js +146 -0
- package/studio/src/scripts.js +185 -0
- package/studio/src/stage-guides.js +101 -0
- package/studio/src/svg-animation.js +416 -0
- package/studio/src/svg-context.js +522 -0
- package/studio/src/svg-frame.js +413 -0
- package/studio/src/svg-import.js +1208 -0
- package/studio/src/swf-recording.js +104 -0
- package/studio/src/symbol-library.js +39 -0
- package/studio/src/symbols.js +62 -0
- package/studio/src/text-fields.js +58 -0
- package/studio/src/theme.js +43 -0
- package/studio/src/timeline.js +321 -0
- package/studio/src/vector-cut.js +103 -0
- package/studio/src/vector-geometry.js +254 -0
- package/studio/src/vector-style.js +146 -0
- package/studio/src/video-encode.js +84 -0
- package/studio/src/video-export.js +331 -0
- package/studio/src/video-mux.js +339 -0
- package/studio/src/video-playback.js +281 -0
- package/studio/src/workspace.js +344 -0
- package/studio/stroke-style.test.js +119 -0
- package/studio/styles.css +1547 -0
- package/studio/svg-export.test.js +162 -0
- package/studio/svg-import.test.js +318 -0
- package/studio/swf-authoring.test.js +140 -0
- package/studio/swf-export.test.js +324 -0
- package/studio/swf-import.test.js +489 -0
- package/studio/symbols.test.js +68 -0
- package/studio/tests/accessibility-interactions.mjs +138 -0
- package/studio/tests/appearance-interactions.mjs +103 -0
- package/studio/tests/control-interactions.mjs +60 -0
- package/studio/tests/event-interactions.mjs +117 -0
- package/studio/tests/external-resources.mjs +174 -0
- package/studio/tests/frame-image.mjs +71 -0
- package/studio/tests/html-export.mjs +68 -0
- package/studio/tests/import-files.mjs +131 -0
- package/studio/tests/lottie.mjs +125 -0
- package/studio/tests/mask-interactions.mjs +148 -0
- package/studio/tests/media-interactions.mjs +109 -0
- package/studio/tests/paint-interactions.mjs +64 -0
- package/studio/tests/project-interactions.mjs +244 -0
- package/studio/tests/script-interactions.mjs +178 -0
- package/studio/tests/scripted-control-interactions.mjs +107 -0
- package/studio/tests/svg-export.mjs +149 -0
- package/studio/tests/text-field-interactions.mjs +64 -0
- package/studio/tests/theme-interactions.mjs +53 -0
- package/studio/tests/timeline-browser.mjs +507 -0
- package/studio/tests/transition-interactions.mjs +94 -0
- package/studio/tests/trigger-interactions.mjs +93 -0
- package/studio/tests/video-export.mjs +243 -0
- package/studio/tests/workspace-interactions.mjs +226 -0
- package/studio/tween-recovery.test.js +31 -0
- package/studio/vector-style.test.js +56 -0
- package/studio/video-export.test.js +326 -0
- package/studiospec/actionscript.md +88 -0
- package/studiospec/architecture.md +378 -0
- package/studiospec/controls.md +100 -0
- package/studiospec/file-support.md +268 -0
- package/studiospec/lottie.md +69 -0
- package/studiospec/requirements.md +135 -0
- package/studiospec/stroke-style.md +95 -0
- package/studiospec/svg-export.md +83 -0
- package/studiospec/svg-import.md +139 -0
- package/studiospec/swooflib-integration.md +115 -0
- package/studiospec/tasks.md +573 -0
- package/studiospec/video-export.md +127 -0
- package/swf2js/__tests__/actionscript.test.js +1609 -0
- package/swf2js/__tests__/adpcm-audio.test.js +43 -0
- package/swf2js/__tests__/as2-compiler.test.js +153 -0
- package/swf2js/__tests__/as3-mixed-depth.test.js +498 -0
- package/swf2js/__tests__/authored-sprite-hit.test.js +118 -0
- package/swf2js/__tests__/authored-sprite-sizing.test.js +164 -0
- package/swf2js/__tests__/avm1-action-prefix.test.js +134 -0
- package/swf2js/__tests__/avm1-attach-movie.test.js +1151 -0
- package/swf2js/__tests__/avm1-boxhead-budget.test.js +73 -0
- package/swf2js/__tests__/avm1-cfg-bubble-tanks.test.js +101 -0
- package/swf2js/__tests__/avm1-cfg-mario-kart.test.js +184 -0
- package/swf2js/__tests__/avm1-cfg-mario.test.js +31 -0
- package/swf2js/__tests__/avm1-cfg-pacman.test.js +49 -0
- package/swf2js/__tests__/avm1-checkers-gameplay.test.js +122 -0
- package/swf2js/__tests__/avm1-clip-actions.test.js +2002 -0
- package/swf2js/__tests__/avm1-clone-drag.test.js +626 -0
- package/swf2js/__tests__/avm1-decompiler.test.js +102 -0
- package/swf2js/__tests__/avm1-dynamic-locals.test.js +159 -0
- package/swf2js/__tests__/avm1-formal-parameters.test.js +71 -0
- package/swf2js/__tests__/avm1-key-events.test.js +52 -0
- package/swf2js/__tests__/avm1-load-bitmap.test.js +75 -0
- package/swf2js/__tests__/avm1-loading-host-actions.test.js +764 -0
- package/swf2js/__tests__/avm1-multibyte-strings.test.js +63 -0
- package/swf2js/__tests__/avm1-pacman-gameplay.test.js +115 -0
- package/swf2js/__tests__/avm1-shape-hittest.test.js +311 -0
- package/swf2js/__tests__/avm1-shared-bodies.test.js +57 -0
- package/swf2js/__tests__/avm1-shared-runtime.test.js +1364 -0
- package/swf2js/__tests__/avm1-snake-gameplay.test.js +139 -0
- package/swf2js/__tests__/avm1-super.test.js +70 -0
- package/swf2js/__tests__/avm1-target-path.test.js +325 -0
- package/swf2js/__tests__/avm1-try.test.js +229 -0
- package/swf2js/__tests__/avm2-activation-closures.test.js +65 -0
- package/swf2js/__tests__/avm2-applytype.test.js +180 -0
- package/swf2js/__tests__/avm2-call-ops.test.js +232 -0
- package/swf2js/__tests__/avm2-callsuperid.test.js +231 -0
- package/swf2js/__tests__/avm2-class-initializer.test.js +219 -0
- package/swf2js/__tests__/avm2-custom-namespace.test.js +139 -0
- package/swf2js/__tests__/avm2-describe-type.test.js +96 -0
- package/swf2js/__tests__/avm2-dictionary.test.js +96 -0
- package/swf2js/__tests__/avm2-domain-memory.test.js +332 -0
- package/swf2js/__tests__/avm2-e4x.test.js +326 -0
- package/swf2js/__tests__/avm2-exceptions.test.js +81 -0
- package/swf2js/__tests__/avm2-findprop.test.js +110 -0
- package/swf2js/__tests__/avm2-getlex.test.js +166 -0
- package/swf2js/__tests__/avm2-global-slot.test.js +106 -0
- package/swf2js/__tests__/avm2-interface.test.js +95 -0
- package/swf2js/__tests__/avm2-multiname-precedence.test.js +148 -0
- package/swf2js/__tests__/avm2-named-namespace-types.test.js +106 -0
- package/swf2js/__tests__/avm2-optional-args.test.js +100 -0
- package/swf2js/__tests__/avm2-outer-scopes.test.js +101 -0
- package/swf2js/__tests__/avm2-package-internal-class.test.js +106 -0
- package/swf2js/__tests__/avm2-protected-namespace.test.js +105 -0
- package/swf2js/__tests__/avm2-protected.test.js +214 -0
- package/swf2js/__tests__/avm2-qwop-gameplay.test.js +116 -0
- package/swf2js/__tests__/avm2-runtime-namespaces.test.js +159 -0
- package/swf2js/__tests__/avm2-script-traits.test.js +89 -0
- package/swf2js/__tests__/avm2-shared-runtime.test.js +52 -0
- package/swf2js/__tests__/avm2-slot-ops.test.js +117 -0
- package/swf2js/__tests__/avm2-type-ops.test.js +224 -0
- package/swf2js/__tests__/bevel-filter.test.js +116 -0
- package/swf2js/__tests__/bitmap-button-mask.test.js +106 -0
- package/swf2js/__tests__/bitmap-data-draw.test.js +388 -0
- package/swf2js/__tests__/bitmap-decoder.test.js +108 -0
- package/swf2js/__tests__/bitmapdata-color-bounds.test.js +70 -0
- package/swf2js/__tests__/bitmapdata-copy-channel.test.js +91 -0
- package/swf2js/__tests__/bitmapdata-copy-pixels.test.js +136 -0
- package/swf2js/__tests__/bitmapdata-fill-compare.test.js +241 -0
- package/swf2js/__tests__/bitmapdata-filter.test.js +232 -0
- package/swf2js/__tests__/bitmapdata-hit-test.test.js +71 -0
- package/swf2js/__tests__/bitmapdata-merge.test.js +84 -0
- package/swf2js/__tests__/bitmapdata-palette-map.test.js +92 -0
- package/swf2js/__tests__/bitmapdata-pixels-io.test.js +198 -0
- package/swf2js/__tests__/bitmapdata-threshold.test.js +97 -0
- package/swf2js/__tests__/bitmapdata-vector.test.js +82 -0
- package/swf2js/__tests__/blur-filter.test.js +48 -0
- package/swf2js/__tests__/bundle-emitter.test.js +394 -0
- package/swf2js/__tests__/button-actions.test.js +370 -0
- package/swf2js/__tests__/button-color-transform.test.js +48 -0
- package/swf2js/__tests__/button-decoder.test.js +106 -0
- package/swf2js/__tests__/button-hit-test.test.js +825 -0
- package/swf2js/__tests__/button-scaling-grid.test.js +124 -0
- package/swf2js/__tests__/button-sound.test.js +105 -0
- package/swf2js/__tests__/bytearray-coercion.test.js +23 -0
- package/swf2js/__tests__/bytearray-object-serialization.test.js +380 -0
- package/swf2js/__tests__/cfg-switch-loop.test.js +103 -0
- package/swf2js/__tests__/clip-depth-mask.test.js +119 -0
- package/swf2js/__tests__/clipped-bitmap-fill.test.js +118 -0
- package/swf2js/__tests__/companion-swf.test.js +638 -0
- package/swf2js/__tests__/context-menu.test.js +149 -0
- package/swf2js/__tests__/convolution-filter.test.js +74 -0
- package/swf2js/__tests__/definefont4.test.js +280 -0
- package/swf2js/__tests__/display-displacement.test.js +161 -0
- package/swf2js/__tests__/display-list.test.js +80 -0
- package/swf2js/__tests__/display-mask-render.test.js +656 -0
- package/swf2js/__tests__/displayobject-stage.test.js +320 -0
- package/swf2js/__tests__/embedded-script-audio.test.js +131 -0
- package/swf2js/__tests__/embedded-swf.test.js +202 -0
- package/swf2js/__tests__/embedded-textfield.test.js +107 -0
- package/swf2js/__tests__/embedded-timeline-audio.test.js +182 -0
- package/swf2js/__tests__/embedded-timeline-input.test.js +420 -0
- package/swf2js/__tests__/embedded-timer-lifecycle.test.js +145 -0
- package/swf2js/__tests__/event-priority-order.test.js +125 -0
- package/swf2js/__tests__/event-weak-listeners.test.js +53 -0
- package/swf2js/__tests__/event-will-trigger.test.js +43 -0
- package/swf2js/__tests__/flash-text-engine-content.test.js +115 -0
- package/swf2js/__tests__/flash-text-engine-format.test.js +95 -0
- package/swf2js/__tests__/flash-text-engine-line.test.js +314 -0
- package/swf2js/__tests__/font-encoder.test.js +95 -0
- package/swf2js/__tests__/font-outline-text.test.js +659 -0
- package/swf2js/__tests__/glow-shadow-filter.test.js +68 -0
- package/swf2js/__tests__/graphics-bitmap-smoothing.test.js +32 -0
- package/swf2js/__tests__/graphics-fill-lifetime.test.js +36 -0
- package/swf2js/__tests__/graphics-gradient-matrix.test.js +53 -0
- package/swf2js/__tests__/graphics-stroke-hit-test.test.js +457 -0
- package/swf2js/__tests__/hit-test-primitives.test.js +414 -0
- package/swf2js/__tests__/input-events.test.js +714 -0
- package/swf2js/__tests__/integration/corpus.test.js +41 -0
- package/swf2js/__tests__/loader-embedded-swf.test.js +210 -0
- package/swf2js/__tests__/loader-info.test.js +81 -0
- package/swf2js/__tests__/local-connection.test.js +122 -0
- package/swf2js/__tests__/morph-focal-gradient.test.js +51 -0
- package/swf2js/__tests__/morph-topology.test.js +267 -0
- package/swf2js/__tests__/movie-data-codec.test.js +128 -0
- package/swf2js/__tests__/nellymoser-audio.test.js +84 -0
- package/swf2js/__tests__/opaque-background-cache.test.js +352 -0
- package/swf2js/__tests__/path-stream.test.js +81 -0
- package/swf2js/__tests__/place-object-filters.test.js +88 -0
- package/swf2js/__tests__/place-object3-decoder.test.js +116 -0
- package/swf2js/__tests__/place-object3-image.test.js +85 -0
- package/swf2js/__tests__/player-version.test.js +46 -0
- package/swf2js/__tests__/root-textfield.test.js +287 -0
- package/swf2js/__tests__/scaling-grid.test.js +183 -0
- package/swf2js/__tests__/shape-decoder.test.js +361 -0
- package/swf2js/__tests__/shape-line-style2.test.js +138 -0
- package/swf2js/__tests__/shape-nonscaling-stroke.test.js +131 -0
- package/swf2js/__tests__/shape-pixel-hint.test.js +101 -0
- package/swf2js/__tests__/simplebutton-pointer.test.js +1477 -0
- package/swf2js/__tests__/socket-offline.test.js +67 -0
- package/swf2js/__tests__/sound-avm1-stop.test.js +99 -0
- package/swf2js/__tests__/sound-envelope.test.js +110 -0
- package/swf2js/__tests__/sound-extract.test.js +168 -0
- package/swf2js/__tests__/sound-id3.test.js +283 -0
- package/swf2js/__tests__/sound-load.test.js +259 -0
- package/swf2js/__tests__/sound-mixer-spectrum.test.js +261 -0
- package/swf2js/__tests__/sound-stream-sprite.test.js +624 -0
- package/swf2js/__tests__/sound-transform.test.js +104 -0
- package/swf2js/__tests__/speex-audio.test.js +77 -0
- package/swf2js/__tests__/stage-noscale.test.js +45 -0
- package/swf2js/__tests__/swf-encoder.test.js +134 -0
- package/swf2js/__tests__/swflib-assemble.test.js +20 -0
- package/swf2js/__tests__/textfield-html-text.test.js +368 -0
- package/swf2js/__tests__/textfield-line-layout.test.js +339 -0
- package/swf2js/__tests__/textfield-programmatic-overlay.test.js +2506 -0
- package/swf2js/__tests__/textfield-scroll.test.js +79 -0
- package/swf2js/__tests__/textfield-selection.test.js +383 -0
- package/swf2js/__tests__/timeline-effect-surfaces.test.js +295 -0
- package/swf2js/__tests__/timeline-named-anchor.test.js +139 -0
- package/swf2js/__tests__/timeline-scenes.test.js +1723 -0
- package/swf2js/__tests__/urlloader-http-status.test.js +236 -0
- package/{src → swf2js}/cli.js +43 -11
- package/swf2js/compiler/as2-classes.js +156 -0
- package/swf2js/compiler/as2-parser.js +598 -0
- package/swf2js/compiler/avm1-codegen.js +897 -0
- package/swf2js/compiler/index.js +28 -0
- package/{src → swf2js}/decoder/button-decoder.js +3 -1
- package/swf2js/decoder/png.js +114 -0
- package/{src → swf2js}/decoder/shape-decoder.js +20 -10
- package/{src → swf2js}/decoder/tag-decoder.js +5 -3
- package/{src → swf2js}/decoder/tag-types.js +4 -0
- package/swf2js/decompiler/avm1-decompiler.js +1138 -0
- package/{src → swf2js}/emitter/asset-encoder.js +66 -113
- package/{src → swf2js}/emitter/bundle-emitter.js +209 -78
- package/swf2js/emitter/external-resources.js +39 -0
- package/swf2js/emitter/movie-data-codec.js +91 -0
- package/swf2js/encoder/bit-writer.js +182 -0
- package/swf2js/encoder/shape-encoder.js +310 -0
- package/swf2js/encoder/swf-builder.js +639 -0
- package/swf2js/encoder/swf-writer.js +55 -0
- package/{src/runtime/swflib/assemble.js → swf2js/runtime/assemble-swooflib.js} +4 -3
- package/{src → swf2js}/runtime/avm1-runtime.js +102 -63
- package/{src → swf2js}/runtime/index.js +1 -1
- package/{src → swf2js}/runtime/movie-runtime.js +28 -2
- package/{src → swf2js}/transpiler/actionscript.js +82 -19
- package/{src → swf2js}/transpiler/avm1/avm1-opcodes.js +5 -3
- package/{src → swf2js}/transpiler/avm1/avm1-transpiler.js +69 -6
- package/{src → swf2js}/transpiler/avm2/avm2-transpiler.js +1 -1
- package/{src → swf2js}/transpiler/timeline/display-list.js +41 -22
- package/{src → swf2js}/transpiler/timeline/timeline-codegen.js +97 -36
- package/swooflib/README.md +569 -0
- package/swooflib/adpcm.js +147 -0
- package/{src/runtime/swflib → swooflib}/builtins.js +6 -0
- package/{src/runtime/swflib → swooflib}/context-menu.js +7 -1
- package/swooflib/control-definitions.js +42 -0
- package/swooflib/control-widget.js +763 -0
- package/swooflib/controls.js +300 -0
- package/{src/runtime/swflib → swooflib}/display.js +16 -10
- package/{src/runtime/swflib → swooflib}/events.js +11 -0
- package/{src/runtime/swflib → swooflib}/flash.js +6 -5
- package/{src/runtime/swflib → swooflib}/graphics.js +81 -19
- package/{src/runtime/swflib → swooflib}/input.js +12 -14
- package/{src/runtime/swflib → swooflib}/loader.js +52 -22
- package/swooflib/movie-network.js +86 -0
- package/swooflib/path-stream.js +169 -0
- package/{src/runtime/swflib → swooflib}/render.js +3 -13
- package/{src/runtime/swflib → swooflib}/sound.js +25 -2
- package/{src/runtime/swflib → swooflib}/stage.js +3 -3
- package/swooflib/stream-time.js +21 -0
- package/{src/runtime/swflib → swooflib}/system.js +88 -37
- package/{src/runtime/swflib → swooflib}/text-paint.js +14 -3
- package/{src/runtime/swflib → swooflib}/text.js +8 -0
- package/swooflib/xml-node.js +53 -0
- package/src/emitter/timeline-data-codec.js +0 -58
- /package/{src → swf2js}/decoder/symbol-table.js +0 -0
- /package/{src → swf2js}/emitter/embedded-swf.js +0 -0
- /package/{src → swf2js}/emitter/font-encoder.js +0 -0
- /package/{src → swf2js}/model/swf-document.js +0 -0
- /package/{src → swf2js}/model/transpile-result.js +0 -0
- /package/{src → swf2js}/parser/bit-reader.js +0 -0
- /package/{src → swf2js}/parser/decompressor.js +0 -0
- /package/{src → swf2js}/parser/swf-parser.js +0 -0
- /package/{src → swf2js}/pretty-printer/pretty-printer.js +0 -0
- /package/{src → swf2js}/runtime/avm2-runtime.js +0 -0
- /package/{src → swf2js}/runtime/embedded-movie-runtime.js +0 -0
- /package/{src → swf2js}/transpiler/avm1/avm1-ir.js +0 -0
- /package/{src → swf2js}/transpiler/avm1/avm1-rewrite.js +0 -0
- /package/{src → swf2js}/transpiler/avm2/abc-reader.js +0 -0
- /package/{src → swf2js}/transpiler/cfg-structurer.js +0 -0
- /package/{src → swf2js}/util/diagnostics.js +0 -0
- /package/{src → swf2js}/util/logger.js +0 -0
- /package/{src/runtime/swflib → swooflib}/bitmap-image.js +0 -0
- /package/{src/runtime/swflib → swooflib}/bitmap.js +0 -0
- /package/{src/runtime/swflib → swooflib}/bytearray.js +0 -0
- /package/{src/runtime/swflib → swooflib}/compiled-swf.js +0 -0
- /package/{src/runtime/swflib → swooflib}/cursor-flag.js +0 -0
- /package/{src/runtime/swflib → swooflib}/dictionary.js +0 -0
- /package/{src/runtime/swflib → swooflib}/filters.js +0 -0
- /package/{src/runtime/swflib → swooflib}/geom.js +0 -0
- /package/{src/runtime/swflib → swooflib}/glyph-metrics.js +0 -0
- /package/{src/runtime/swflib → swooflib}/host.js +0 -0
- /package/{src/runtime/swflib → swooflib}/inherit.js +0 -0
- /package/{src/runtime/swflib → swooflib}/marks.js +0 -0
- /package/{src/runtime/swflib → swooflib}/matrix3d.js +0 -0
- /package/{src/runtime/swflib → swooflib}/pointer-bridge.js +0 -0
- /package/{src/runtime/swflib → swooflib}/projection.js +0 -0
- /package/{src/runtime/swflib → swooflib}/sprite-drag.js +0 -0
- /package/{src/runtime/swflib → swooflib}/stage-ref.js +0 -0
- /package/{src/runtime/swflib → swooflib}/text-field.js +0 -0
- /package/{src/runtime/swflib → swooflib}/transform.js +0 -0
- /package/{src/runtime/swflib → swooflib}/xml.js +0 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it } from 'vitest';
|
|
2
|
+
import { SWFLIB_SOURCE } from '../runtime/index.js';
|
|
3
|
+
|
|
4
|
+
const previousDocument = globalThis.document;
|
|
5
|
+
afterEach(() => {
|
|
6
|
+
if (previousDocument === undefined) delete globalThis.document;
|
|
7
|
+
else globalThis.document = previousDocument;
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
function makeCanvas() {
|
|
11
|
+
let width = 0, height = 0;
|
|
12
|
+
const canvas = { pixels: new Uint8ClampedArray(0) };
|
|
13
|
+
Object.defineProperties(canvas, {
|
|
14
|
+
width: { get: () => width, set: (value) => { width = value; canvas.pixels = new Uint8ClampedArray(width * height * 4); } },
|
|
15
|
+
height: { get: () => height, set: (value) => { height = value; canvas.pixels = new Uint8ClampedArray(width * height * 4); } },
|
|
16
|
+
});
|
|
17
|
+
canvas.getContext = () => ({
|
|
18
|
+
canvas,
|
|
19
|
+
getImageData(x, y, w, h) {
|
|
20
|
+
const data = new Uint8ClampedArray(w * h * 4);
|
|
21
|
+
for (let row = 0; row < h; row++) for (let col = 0; col < w; col++) {
|
|
22
|
+
const from = ((y + row) * canvas.width + x + col) * 4;
|
|
23
|
+
data.set(canvas.pixels.subarray(from, from + 4), (row * w + col) * 4);
|
|
24
|
+
}
|
|
25
|
+
return { data, width: w, height: h };
|
|
26
|
+
},
|
|
27
|
+
putImageData(image, x, y) {
|
|
28
|
+
for (let row = 0; row < image.height; row++) for (let col = 0; col < image.width; col++) {
|
|
29
|
+
const from = (row * image.width + col) * 4;
|
|
30
|
+
const to = ((y + row) * canvas.width + x + col) * 4;
|
|
31
|
+
canvas.pixels.set(image.data.subarray(from, from + 4), to);
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
fillRect() {}, clearRect() {}, drawImage() {},
|
|
35
|
+
});
|
|
36
|
+
return canvas;
|
|
37
|
+
}
|
|
38
|
+
function makeRuntime() {
|
|
39
|
+
globalThis.document = { createElement: () => makeCanvas(), getElementById: () => null };
|
|
40
|
+
return new Function(`${SWFLIB_SOURCE}\nreturn __swoof_swflib;`)();
|
|
41
|
+
}
|
|
42
|
+
function setPixels(bitmap, pixels) { bitmap._canvas.pixels.set(pixels.flat(2)); }
|
|
43
|
+
function pixel(bitmap, x, y = 0) {
|
|
44
|
+
const i = (y * bitmap.width + x) * 4;
|
|
45
|
+
return Array.from(bitmap._canvas.pixels.subarray(i, i + 4));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
describe('BitmapData.merge', () => {
|
|
49
|
+
it('blends each channel independently with 0, 128, and 256 multipliers', () => {
|
|
50
|
+
const { builtins } = makeRuntime();
|
|
51
|
+
const source = new builtins.BitmapData(1, 1, true);
|
|
52
|
+
const dest = new builtins.BitmapData(1, 1, true);
|
|
53
|
+
setPixels(source, [[[200, 100, 50, 128]]]);
|
|
54
|
+
setPixels(dest, [[[20, 60, 100, 64]]]);
|
|
55
|
+
dest.merge(source, { x: 0, y: 0, width: 1, height: 1 }, { x: 0, y: 0 }, 256, 0, 128, 128);
|
|
56
|
+
expect(pixel(dest, 0)).toEqual([200, 60, 75, 96]);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('clips source and destination regions and leaves outside pixels unchanged', () => {
|
|
60
|
+
const { builtins } = makeRuntime();
|
|
61
|
+
const source = new builtins.BitmapData(3, 1, true);
|
|
62
|
+
const dest = new builtins.BitmapData(3, 1, true);
|
|
63
|
+
setPixels(source, [[[10, 20, 30, 40], [50, 60, 70, 80], [90, 100, 110, 120]]]);
|
|
64
|
+
setPixels(dest, [[[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]]);
|
|
65
|
+
dest.merge(source, { x: -1, y: 0, width: 4, height: 1 }, { x: 0, y: 0 }, 256, 256, 256, 256);
|
|
66
|
+
expect([pixel(dest, 0), pixel(dest, 1), pixel(dest, 2)]).toEqual([
|
|
67
|
+
[1, 2, 3, 4], [10, 20, 30, 40], [50, 60, 70, 80],
|
|
68
|
+
]);
|
|
69
|
+
dest.merge(source, { x: 0, y: 0, width: 3, height: 1 }, { x: -1, y: 0 }, 256, 256, 256, 256);
|
|
70
|
+
expect([pixel(dest, 0), pixel(dest, 1), pixel(dest, 2)]).toEqual([
|
|
71
|
+
[50, 60, 70, 80], [90, 100, 110, 120], [50, 60, 70, 80],
|
|
72
|
+
]);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('keeps opaque destination alpha opaque', () => {
|
|
76
|
+
const { builtins } = makeRuntime();
|
|
77
|
+
const source = new builtins.BitmapData(1, 1, true);
|
|
78
|
+
const dest = new builtins.BitmapData(1, 1, false);
|
|
79
|
+
setPixels(source, [[[1, 2, 3, 0]]]);
|
|
80
|
+
setPixels(dest, [[[10, 20, 30, 255]]]);
|
|
81
|
+
dest.merge(source, { x: 0, y: 0, width: 1, height: 1 }, { x: 0, y: 0 }, 0, 0, 0, 0);
|
|
82
|
+
expect(pixel(dest, 0)).toEqual([10, 20, 30, 255]);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it } from 'vitest';
|
|
2
|
+
import { SWFLIB_SOURCE } from '../runtime/index.js';
|
|
3
|
+
|
|
4
|
+
const previousDocument = globalThis.document;
|
|
5
|
+
afterEach(() => {
|
|
6
|
+
if (previousDocument === undefined) delete globalThis.document;
|
|
7
|
+
else globalThis.document = previousDocument;
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
function makeCanvas() {
|
|
11
|
+
let width = 0, height = 0;
|
|
12
|
+
const canvas = { pixels: new Uint8ClampedArray(0) };
|
|
13
|
+
Object.defineProperties(canvas, {
|
|
14
|
+
width: { get: () => width, set: (value) => { width = value; canvas.pixels = new Uint8ClampedArray(width * height * 4); } },
|
|
15
|
+
height: { get: () => height, set: (value) => { height = value; canvas.pixels = new Uint8ClampedArray(width * height * 4); } },
|
|
16
|
+
});
|
|
17
|
+
canvas.getContext = () => ({
|
|
18
|
+
canvas,
|
|
19
|
+
getImageData(x, y, w, h) {
|
|
20
|
+
const data = new Uint8ClampedArray(w * h * 4);
|
|
21
|
+
for (let row = 0; row < h; row++) for (let col = 0; col < w; col++) {
|
|
22
|
+
const from = ((y + row) * canvas.width + x + col) * 4;
|
|
23
|
+
data.set(canvas.pixels.subarray(from, from + 4), (row * w + col) * 4);
|
|
24
|
+
}
|
|
25
|
+
return { data, width: w, height: h };
|
|
26
|
+
},
|
|
27
|
+
putImageData(image, x, y) {
|
|
28
|
+
for (let row = 0; row < image.height; row++) for (let col = 0; col < image.width; col++) {
|
|
29
|
+
const from = (row * image.width + col) * 4;
|
|
30
|
+
const to = ((y + row) * canvas.width + x + col) * 4;
|
|
31
|
+
canvas.pixels.set(image.data.subarray(from, from + 4), to);
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
fillRect() {}, clearRect() {}, drawImage() {},
|
|
35
|
+
});
|
|
36
|
+
return canvas;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function makeRuntime() {
|
|
40
|
+
globalThis.document = { createElement: () => makeCanvas(), getElementById: () => null };
|
|
41
|
+
return new Function(`${SWFLIB_SOURCE}\nreturn __swoof_swflib;`)();
|
|
42
|
+
}
|
|
43
|
+
function setPixels(bitmap, pixels) { bitmap._canvas.pixels.set(pixels.flat(2)); }
|
|
44
|
+
function pixel(bitmap, x, y = 0) {
|
|
45
|
+
const i = (y * bitmap.width + x) * 4;
|
|
46
|
+
return Array.from(bitmap._canvas.pixels.subarray(i, i + 4));
|
|
47
|
+
}
|
|
48
|
+
function table(value) { const result = new Array(256).fill(0); result[value.index] = value.color >>> 0; return result; }
|
|
49
|
+
|
|
50
|
+
describe('BitmapData.paletteMap', () => {
|
|
51
|
+
it('combines the four lookup table contributions into the mapped ARGB pixel', () => {
|
|
52
|
+
const { builtins } = makeRuntime();
|
|
53
|
+
const source = new builtins.BitmapData(1, 1, true);
|
|
54
|
+
setPixels(source, [[[10, 20, 30, 40]]]);
|
|
55
|
+
const dest = new builtins.BitmapData(1, 1, true);
|
|
56
|
+
dest.paletteMap(source, { x: 0, y: 0, width: 1, height: 1 }, { x: 0, y: 0 },
|
|
57
|
+
table({ index: 10, color: 0x00010000 }), table({ index: 20, color: 0x00000200 }),
|
|
58
|
+
table({ index: 30, color: 0x00000003 }), table({ index: 40, color: 0x04000000 }));
|
|
59
|
+
expect(pixel(dest, 0)).toEqual([1, 2, 3, 4]);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('uses identity contributions for null tables and maps only supplied channels', () => {
|
|
63
|
+
const { builtins } = makeRuntime();
|
|
64
|
+
const source = new builtins.BitmapData(2, 1, true);
|
|
65
|
+
setPixels(source, [[[10, 20, 30, 40], [50, 60, 70, 80]]]);
|
|
66
|
+
const dest = new builtins.BitmapData(2, 1, true);
|
|
67
|
+
dest.paletteMap(source, { x: 0, y: 0, width: 2, height: 1 }, { x: 0, y: 0 });
|
|
68
|
+
expect([pixel(dest, 0), pixel(dest, 1)]).toEqual([[10, 20, 30, 40], [50, 60, 70, 80]]);
|
|
69
|
+
|
|
70
|
+
const redMap = table({ index: 10, color: 0x00110000 });
|
|
71
|
+
dest.paletteMap(source, { x: 0, y: 0, width: 1, height: 1 }, { x: 1, y: 0 }, redMap);
|
|
72
|
+
expect(pixel(dest, 1)).toEqual([17, 20, 30, 40]);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('clips source and destination while preserving pixels outside the copied area', () => {
|
|
76
|
+
const { builtins } = makeRuntime();
|
|
77
|
+
const source = new builtins.BitmapData(3, 1, true);
|
|
78
|
+
setPixels(source, [[[10, 1, 2, 255], [20, 3, 4, 255], [30, 5, 6, 255]]]);
|
|
79
|
+
const dest = new builtins.BitmapData(3, 1, true);
|
|
80
|
+
setPixels(dest, [[[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]]);
|
|
81
|
+
const redMap = new Array(256).fill(0);
|
|
82
|
+
redMap[10] = 0x00aa0000; redMap[20] = 0x00bb0000; redMap[30] = 0x00cc0000;
|
|
83
|
+
dest.paletteMap(source, { x: -1, y: 0, width: 4, height: 1 }, { x: 0, y: 0 }, redMap);
|
|
84
|
+
expect([pixel(dest, 0), pixel(dest, 1), pixel(dest, 2)]).toEqual([
|
|
85
|
+
[1, 2, 3, 4], [0xaa, 1, 2, 255], [0xbb, 3, 4, 255],
|
|
86
|
+
]);
|
|
87
|
+
dest.paletteMap(source, { x: 0, y: 0, width: 3, height: 1 }, { x: -1, y: 0 }, redMap);
|
|
88
|
+
expect([pixel(dest, 0), pixel(dest, 1), pixel(dest, 2)]).toEqual([
|
|
89
|
+
[0xbb, 3, 4, 255], [0xcc, 5, 6, 255], [0xbb, 3, 4, 255],
|
|
90
|
+
]);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it } from 'vitest';
|
|
2
|
+
import { SWFLIB_SOURCE } from '../runtime/index.js';
|
|
3
|
+
|
|
4
|
+
const previousDocument = globalThis.document;
|
|
5
|
+
afterEach(() => {
|
|
6
|
+
if (previousDocument === undefined) delete globalThis.document;
|
|
7
|
+
else globalThis.document = previousDocument;
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
function makeCanvas() {
|
|
11
|
+
let width = 0, height = 0;
|
|
12
|
+
const canvas = { pixels: new Uint8ClampedArray(0) };
|
|
13
|
+
Object.defineProperties(canvas, {
|
|
14
|
+
width: { get: () => width, set: (value) => { width = value; canvas.pixels = new Uint8ClampedArray(width * height * 4); } },
|
|
15
|
+
height: { get: () => height, set: (value) => { height = value; canvas.pixels = new Uint8ClampedArray(width * height * 4); } },
|
|
16
|
+
});
|
|
17
|
+
canvas.getContext = () => ({
|
|
18
|
+
canvas,
|
|
19
|
+
createImageData: (width, height) => ({ data: new Uint8ClampedArray(width * height * 4), width, height }),
|
|
20
|
+
getImageData(x, y, w, h) {
|
|
21
|
+
const data = new Uint8ClampedArray(w * h * 4);
|
|
22
|
+
for (let row = 0; row < h; row++) for (let col = 0; col < w; col++) {
|
|
23
|
+
const from = ((y + row) * canvas.width + x + col) * 4;
|
|
24
|
+
data.set(canvas.pixels.subarray(from, from + 4), (row * w + col) * 4);
|
|
25
|
+
}
|
|
26
|
+
return { data, width: w, height: h };
|
|
27
|
+
},
|
|
28
|
+
putImageData(image, x, y) {
|
|
29
|
+
for (let row = 0; row < image.height; row++) for (let col = 0; col < image.width; col++) {
|
|
30
|
+
const from = (row * image.width + col) * 4;
|
|
31
|
+
const to = ((y + row) * canvas.width + x + col) * 4;
|
|
32
|
+
canvas.pixels.set(image.data.subarray(from, from + 4), to);
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
fillRect() {}, clearRect() {}, drawImage() {},
|
|
36
|
+
});
|
|
37
|
+
return canvas;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function makeRuntime() {
|
|
41
|
+
globalThis.document = { createElement: () => makeCanvas(), getElementById: () => null };
|
|
42
|
+
return new Function(`${SWFLIB_SOURCE}\nreturn __swoof_swflib;`)();
|
|
43
|
+
}
|
|
44
|
+
function setPixels(bitmap, pixels) { bitmap._canvas.pixels.set(pixels.flat(2)); }
|
|
45
|
+
function pixel(bitmap, x, y = 0) {
|
|
46
|
+
const i = (y * bitmap.width + x) * 4;
|
|
47
|
+
return Array.from(bitmap._canvas.pixels.subarray(i, i + 4));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
describe('BitmapData.noise', () => {
|
|
51
|
+
it('matches the reference seed sequence and writes opaque alpha by default', () => {
|
|
52
|
+
const { builtins } = makeRuntime();
|
|
53
|
+
const bitmap = new builtins.BitmapData(2, 2, true);
|
|
54
|
+
const expected = [[167, 241, 217, 255], [42, 130, 200, 255], [216, 254, 67, 255], [77, 152, 85, 255]];
|
|
55
|
+
for (const seed of [1, 0]) {
|
|
56
|
+
bitmap.noise(seed);
|
|
57
|
+
expect([pixel(bitmap, 0, 0), pixel(bitmap, 1, 0), pixel(bitmap, 0, 1), pixel(bitmap, 1, 1)]).toEqual(expected);
|
|
58
|
+
}
|
|
59
|
+
bitmap.noise(-2147483648);
|
|
60
|
+
expect(pixel(bitmap, 0)).toEqual([78, 226, 179, 255]);
|
|
61
|
+
bitmap.noise(2147483647);
|
|
62
|
+
expect(pixel(bitmap, 0)).toEqual([0, 0, 0, 255]);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('uses one grayscale sample for all RGB and samples alpha only on transparent bitmaps', () => {
|
|
66
|
+
const { builtins } = makeRuntime();
|
|
67
|
+
const { ALPHA, GREEN } = builtins.BitmapDataChannel;
|
|
68
|
+
const transparent = new builtins.BitmapData(2, 1, true);
|
|
69
|
+
transparent.noise(1, 0, 255, ALPHA, true);
|
|
70
|
+
expect([pixel(transparent, 0), pixel(transparent, 1)]).toEqual([[167, 167, 167, 241], [217, 217, 217, 42]]);
|
|
71
|
+
const opaque = new builtins.BitmapData(2, 1, false);
|
|
72
|
+
opaque.noise(1, 0, 255, GREEN | ALPHA);
|
|
73
|
+
expect([pixel(opaque, 0), pixel(opaque, 1)]).toEqual([[0, 167, 0, 255], [0, 241, 0, 255]]);
|
|
74
|
+
transparent.noise(1, 0, 255, GREEN, true);
|
|
75
|
+
expect([pixel(transparent, 0), pixel(transparent, 1)]).toEqual([[167, 167, 167, 255], [241, 241, 241, 255]]);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('uses byte-range coercion, inclusive bounds, and collapses an inverted high value', () => {
|
|
79
|
+
const { builtins } = makeRuntime();
|
|
80
|
+
const bitmap = new builtins.BitmapData(2, 1, true);
|
|
81
|
+
bitmap.noise(1, 258, 259, 1);
|
|
82
|
+
expect([pixel(bitmap, 0), pixel(bitmap, 1)]).toEqual([[3, 0, 0, 255], [3, 0, 0, 255]]);
|
|
83
|
+
bitmap.noise(1, 259, 258, 7);
|
|
84
|
+
expect(pixel(bitmap, 0)).toEqual([3, 3, 3, 255]);
|
|
85
|
+
bitmap.noise(1, 0, 255, null);
|
|
86
|
+
expect(pixel(bitmap, 0)).toEqual([0, 0, 0, 255]);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
describe('BitmapData.perlinNoise', () => {
|
|
91
|
+
function pixels(bitmap) {
|
|
92
|
+
return Array.from({ length: bitmap.width * bitmap.height }, (_, i) =>
|
|
93
|
+
pixel(bitmap, i % bitmap.width, Math.floor(i / bitmap.width)));
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Golden bytes from Ruffle's Rust turbulence reference and Flash byte conversion.
|
|
97
|
+
it('matches seeded fractal RGB samples and overwrites the whole bitmap', () => {
|
|
98
|
+
const { BitmapData } = makeRuntime().builtins;
|
|
99
|
+
const bitmap = new BitmapData(4, 2, true);
|
|
100
|
+
const expected = [
|
|
101
|
+
[127, 127, 127, 255], [132, 80, 155, 255], [116, 100, 134, 255], [125, 137, 97, 255],
|
|
102
|
+
[166, 131, 118, 255], [152, 58, 141, 255], [153, 88, 146, 255], [137, 118, 100, 255],
|
|
103
|
+
];
|
|
104
|
+
bitmap.perlinNoise(2.5, 3.5, 2, 1, false, true);
|
|
105
|
+
expect(pixels(bitmap)).toEqual(expected);
|
|
106
|
+
bitmap.perlinNoise(2.5, 3.5, 0, 1, false, false);
|
|
107
|
+
expect(pixels(bitmap)).toEqual(Array(8).fill([0, 0, 0, 255]));
|
|
108
|
+
bitmap.perlinNoise(2.5, 3.5, 2, 0, false, true);
|
|
109
|
+
expect(pixels(bitmap)).toEqual(expected);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('matches stitched turbulence with separate octave offsets and selected channels', () => {
|
|
113
|
+
const { builtins } = makeRuntime();
|
|
114
|
+
const { Point } = builtins;
|
|
115
|
+
const bitmap = new builtins.BitmapData(4, 2, true);
|
|
116
|
+
const { GREEN, ALPHA } = builtins.BitmapDataChannel;
|
|
117
|
+
const offsets = [new Point(0.25, -0.5), new Point(1.25, 0.75)];
|
|
118
|
+
bitmap.perlinNoise(2.5, 3.5, 2, -7, true, false, GREEN | ALPHA, false, offsets);
|
|
119
|
+
expect(pixels(bitmap)).toEqual([
|
|
120
|
+
[0, 83, 0, 74], [0, 7, 0, 51], [0, 60, 0, 54], [0, 44, 0, 83],
|
|
121
|
+
[0, 55, 0, 45], [0, 105, 0, 69], [0, 20, 0, 48], [0, 17, 0, 21],
|
|
122
|
+
]);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('uses the grayscale bank regardless of RGB flags and leaves opaque alpha intact', () => {
|
|
126
|
+
const { BitmapData, BitmapDataChannel } = makeRuntime().builtins;
|
|
127
|
+
const expected = [[127, 127, 127, 127], [132, 132, 132, 80], [116, 116, 116, 100], [125, 125, 125, 137]];
|
|
128
|
+
for (const transparent of [true, false]) {
|
|
129
|
+
const bitmap = new BitmapData(4, 2, transparent);
|
|
130
|
+
bitmap.perlinNoise(2.5, 0, 2, 0, false, true, BitmapDataChannel.ALPHA, true, [{ x: 4, y: 6 }]);
|
|
131
|
+
const row = expected.map(([r, g, b, a]) => [r, g, b, transparent ? a : 255]);
|
|
132
|
+
expect(pixels(bitmap)).toEqual([...row, ...row]);
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
describe('BitmapData getPixels/setPixels', () => {
|
|
138
|
+
it('writes clipped unmultiplied ARGB words in big-endian order and leaves position at end', () => {
|
|
139
|
+
const { builtins, packages } = makeRuntime();
|
|
140
|
+
const bitmap = new builtins.BitmapData(2, 1, true);
|
|
141
|
+
setPixels(bitmap, [[[0x11, 0x22, 0x33, 0x44], [0xaa, 0xbb, 0xcc, 0xdd]]]);
|
|
142
|
+
const bytes = bitmap.getPixels({ x: -1, y: 0, width: 3, height: 1 });
|
|
143
|
+
expect(bytes.length).toBe(8);
|
|
144
|
+
expect(bytes.position).toBe(8);
|
|
145
|
+
expect(bytes.endian).toBe(packages.utils.Endian.BIG_ENDIAN);
|
|
146
|
+
expect(Array.from(bytes._getU8())).toEqual([0x44, 0x11, 0x22, 0x33, 0xdd, 0xaa, 0xbb, 0xcc]);
|
|
147
|
+
expect(bitmap.getPixels({ x: 4, y: 0, width: 1, height: 1 }).length).toBe(0);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it('reads from the ByteArray current position using its endian setting', () => {
|
|
151
|
+
const { builtins } = makeRuntime();
|
|
152
|
+
const bytes = new builtins.ByteArray();
|
|
153
|
+
bytes.writeUnsignedInt(0xdeadbeef); // skipped prefix
|
|
154
|
+
bytes.writeUnsignedInt(0x11223344);
|
|
155
|
+
bytes.writeUnsignedInt(0xaabbccdd);
|
|
156
|
+
bytes.position = 4;
|
|
157
|
+
const dest = new builtins.BitmapData(2, 1, true);
|
|
158
|
+
dest.setPixels({ x: 0, y: 0, width: 2, height: 1 }, bytes);
|
|
159
|
+
expect(bytes.position).toBe(12);
|
|
160
|
+
expect([pixel(dest, 0), pixel(dest, 1)]).toEqual([[0x22, 0x33, 0x44, 0x11], [0xbb, 0xcc, 0xdd, 0xaa]]);
|
|
161
|
+
|
|
162
|
+
const little = new builtins.ByteArray();
|
|
163
|
+
little.endian = 'littleEndian';
|
|
164
|
+
little.writeUnsignedInt(0x80402010);
|
|
165
|
+
little.position = 0;
|
|
166
|
+
dest.setPixels({ x: 1, y: 0, width: 1, height: 1 }, little);
|
|
167
|
+
expect(little.position).toBe(4);
|
|
168
|
+
expect(pixel(dest, 1)).toEqual([0x40, 0x20, 0x10, 0x80]);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it('round-trips a partially clipped rectangle without touching outside pixels', () => {
|
|
172
|
+
const { builtins } = makeRuntime();
|
|
173
|
+
const source = new builtins.BitmapData(3, 1, true);
|
|
174
|
+
setPixels(source, [[[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]]);
|
|
175
|
+
const rect = { x: -1, y: 0, width: 3, height: 1 };
|
|
176
|
+
const bytes = source.getPixels(rect);
|
|
177
|
+
expect(bytes.length).toBe(8);
|
|
178
|
+
bytes.position = 0;
|
|
179
|
+
const dest = new builtins.BitmapData(3, 1, true);
|
|
180
|
+
setPixels(dest, [[[100, 101, 102, 103], [104, 105, 106, 107], [108, 109, 110, 111]]]);
|
|
181
|
+
dest.setPixels(rect, bytes);
|
|
182
|
+
expect(bytes.position).toBe(8);
|
|
183
|
+
expect([pixel(dest, 0), pixel(dest, 1), pixel(dest, 2)]).toEqual([
|
|
184
|
+
[1, 2, 3, 4], [5, 6, 7, 8], [108, 109, 110, 111],
|
|
185
|
+
]);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it('writes available pixels before reporting an incomplete byte stream', () => {
|
|
189
|
+
const { builtins } = makeRuntime();
|
|
190
|
+
const bytes = new builtins.ByteArray();
|
|
191
|
+
bytes.writeUnsignedInt(0x7f123456);
|
|
192
|
+
bytes.position = 0;
|
|
193
|
+
const dest = new builtins.BitmapData(2, 1, true);
|
|
194
|
+
expect(() => dest.setPixels({ x: 0, y: 0, width: 2, height: 1 }, bytes)).toThrow(/ByteArray ended/);
|
|
195
|
+
expect(pixel(dest, 0)).toEqual([0x12, 0x34, 0x56, 0x7f]);
|
|
196
|
+
expect(bytes.position).toBe(4);
|
|
197
|
+
});
|
|
198
|
+
});
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it } from 'vitest';
|
|
2
|
+
import { SWFLIB_SOURCE } from '../runtime/index.js';
|
|
3
|
+
|
|
4
|
+
const previousDocument = globalThis.document;
|
|
5
|
+
afterEach(() => {
|
|
6
|
+
if (previousDocument === undefined) delete globalThis.document;
|
|
7
|
+
else globalThis.document = previousDocument;
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
function makeCanvas() {
|
|
11
|
+
let width = 0, height = 0;
|
|
12
|
+
const canvas = { pixels: new Uint8ClampedArray(0) };
|
|
13
|
+
Object.defineProperties(canvas, {
|
|
14
|
+
width: { get: () => width, set: (value) => { width = value; canvas.pixels = new Uint8ClampedArray(width * height * 4); } },
|
|
15
|
+
height: { get: () => height, set: (value) => { height = value; canvas.pixels = new Uint8ClampedArray(width * height * 4); } },
|
|
16
|
+
});
|
|
17
|
+
canvas.getContext = () => ({
|
|
18
|
+
canvas,
|
|
19
|
+
getImageData(x, y, w, h) {
|
|
20
|
+
const data = new Uint8ClampedArray(w * h * 4);
|
|
21
|
+
for (let row = 0; row < h; row++) for (let col = 0; col < w; col++) {
|
|
22
|
+
const from = ((y + row) * canvas.width + x + col) * 4;
|
|
23
|
+
data.set(canvas.pixels.subarray(from, from + 4), (row * w + col) * 4);
|
|
24
|
+
}
|
|
25
|
+
return { data, width: w, height: h };
|
|
26
|
+
},
|
|
27
|
+
putImageData(image, x, y) {
|
|
28
|
+
for (let row = 0; row < image.height; row++) for (let col = 0; col < image.width; col++) {
|
|
29
|
+
const from = (row * image.width + col) * 4;
|
|
30
|
+
const to = ((y + row) * canvas.width + x + col) * 4;
|
|
31
|
+
canvas.pixels.set(image.data.subarray(from, from + 4), to);
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
fillRect() {}, clearRect() {}, drawImage() {},
|
|
35
|
+
});
|
|
36
|
+
return canvas;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function makeRuntime() {
|
|
40
|
+
globalThis.document = { createElement: () => makeCanvas(), getElementById: () => null };
|
|
41
|
+
return new Function(`${SWFLIB_SOURCE}\nreturn __swoof_swflib;`)();
|
|
42
|
+
}
|
|
43
|
+
function setPixels(bitmap, pixels) { bitmap._canvas.pixels.set(pixels.flat(2)); }
|
|
44
|
+
function pixel(bitmap, x, y = 0) {
|
|
45
|
+
const i = (y * bitmap.width + x) * 4;
|
|
46
|
+
return Array.from(bitmap._canvas.pixels.subarray(i, i + 4));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
describe('BitmapData.threshold', () => {
|
|
50
|
+
it.each([
|
|
51
|
+
['<', [0, 1]], ['<=', [0, 1, 2]], ['>', [3, 4, 5]],
|
|
52
|
+
['>=', [2, 3, 4, 5]], ['==', [2]], ['!=', [0, 1, 3, 4, 5]],
|
|
53
|
+
])('supports the %s comparison operator', (operation, matches) => {
|
|
54
|
+
const { builtins } = makeRuntime();
|
|
55
|
+
const source = new builtins.BitmapData(6, 1, true);
|
|
56
|
+
setPixels(source, [[10, 20, 30, 40, 50, 60].map((v) => [v, v, v, 255])]);
|
|
57
|
+
const dest = new builtins.BitmapData(6, 1, true);
|
|
58
|
+
const count = dest.threshold(source, { x: 0, y: 0, width: 6, height: 1 }, { x: 0, y: 0 },
|
|
59
|
+
operation, 30, 0xffff0000, 0xff, false);
|
|
60
|
+
expect(count).toBe(matches.length);
|
|
61
|
+
for (let x = 0; x < 6; x++) {
|
|
62
|
+
expect(pixel(dest, x)).toEqual(matches.includes(x) ? [255, 0, 0, 255] : [0, 0, 0, 0]);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('applies threshold mask/color and copies nonmatches when requested', () => {
|
|
67
|
+
const { builtins } = makeRuntime();
|
|
68
|
+
const source = new builtins.BitmapData(3, 1, true);
|
|
69
|
+
setPixels(source, [[[0x0a, 1, 2, 255], [0x09, 3, 4, 255], [0x0b, 5, 6, 255]]]);
|
|
70
|
+
const dest = new builtins.BitmapData(3, 1, true);
|
|
71
|
+
const count = dest.threshold(source, { x: 0, y: 0, width: 3, height: 1 }, { x: 0, y: 0 },
|
|
72
|
+
'>=', 0x000a0000, 0xff00ff00, 0x00ff0000, true);
|
|
73
|
+
expect(count).toBe(3);
|
|
74
|
+
expect([pixel(dest, 0), pixel(dest, 1), pixel(dest, 2)]).toEqual([
|
|
75
|
+
[0, 255, 0, 255], [9, 3, 4, 255], [0, 255, 0, 255],
|
|
76
|
+
]);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('clips source/destination edges and rejects invalid operations', () => {
|
|
80
|
+
const { builtins } = makeRuntime();
|
|
81
|
+
const source = new builtins.BitmapData(3, 1, true);
|
|
82
|
+
setPixels(source, [[[11, 0, 0, 255], [22, 0, 0, 255], [33, 0, 0, 255]]]);
|
|
83
|
+
const dest = new builtins.BitmapData(3, 1, true);
|
|
84
|
+
setPixels(dest, [[[1, 2, 3, 255], [4, 5, 6, 255], [7, 8, 9, 255]]]);
|
|
85
|
+
const sourceRect = { x: -1, y: 0, width: 4, height: 1 };
|
|
86
|
+
expect(dest.threshold(source, sourceRect, { x: 0, y: 0 }, '<', 0, 0, 0xff, true)).toBe(2);
|
|
87
|
+
expect([pixel(dest, 0), pixel(dest, 1), pixel(dest, 2)]).toEqual([
|
|
88
|
+
[1, 2, 3, 255], [11, 0, 0, 255], [22, 0, 0, 255],
|
|
89
|
+
]);
|
|
90
|
+
dest.threshold(source, { x: 0, y: 0, width: 3, height: 1 }, { x: -1, y: 0 }, '<', 0, 0, 0xff, true);
|
|
91
|
+
expect([pixel(dest, 0), pixel(dest, 1), pixel(dest, 2)]).toEqual([
|
|
92
|
+
[22, 0, 0, 255], [33, 0, 0, 255], [22, 0, 0, 255],
|
|
93
|
+
]);
|
|
94
|
+
expect(() => dest.threshold(source, { x: 0, y: 0, width: 1, height: 1 }, { x: 0, y: 0 }, '===', 0))
|
|
95
|
+
.toThrow(/Invalid threshold operation/);
|
|
96
|
+
});
|
|
97
|
+
});
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it } from 'vitest';
|
|
2
|
+
import { SWFLIB_SOURCE } from '../runtime/index.js';
|
|
3
|
+
|
|
4
|
+
const previousDocument = globalThis.document;
|
|
5
|
+
afterEach(() => {
|
|
6
|
+
if (previousDocument === undefined) delete globalThis.document;
|
|
7
|
+
else globalThis.document = previousDocument;
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
function makeCanvas() {
|
|
11
|
+
let width = 0, height = 0;
|
|
12
|
+
const canvas = { pixels: new Uint8ClampedArray(0) };
|
|
13
|
+
Object.defineProperties(canvas, {
|
|
14
|
+
width: { get: () => width, set: (value) => { width = value; canvas.pixels = new Uint8ClampedArray(width * height * 4); } },
|
|
15
|
+
height: { get: () => height, set: (value) => { height = value; canvas.pixels = new Uint8ClampedArray(width * height * 4); } },
|
|
16
|
+
});
|
|
17
|
+
canvas.getContext = () => ({
|
|
18
|
+
canvas,
|
|
19
|
+
getImageData(x, y, w, h) {
|
|
20
|
+
const data = new Uint8ClampedArray(w * h * 4);
|
|
21
|
+
for (let row = 0; row < h; row++) for (let col = 0; col < w; col++) {
|
|
22
|
+
const from = ((y + row) * canvas.width + x + col) * 4;
|
|
23
|
+
data.set(canvas.pixels.subarray(from, from + 4), (row * w + col) * 4);
|
|
24
|
+
}
|
|
25
|
+
return { data, width: w, height: h };
|
|
26
|
+
},
|
|
27
|
+
putImageData(image, x, y) {
|
|
28
|
+
for (let row = 0; row < image.height; row++) for (let col = 0; col < image.width; col++) {
|
|
29
|
+
const from = (row * image.width + col) * 4;
|
|
30
|
+
const to = ((y + row) * canvas.width + x + col) * 4;
|
|
31
|
+
canvas.pixels.set(image.data.subarray(from, from + 4), to);
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
fillRect() {}, clearRect() {}, drawImage() {},
|
|
35
|
+
});
|
|
36
|
+
return canvas;
|
|
37
|
+
}
|
|
38
|
+
function makeRuntime() {
|
|
39
|
+
globalThis.document = { createElement: () => makeCanvas(), getElementById: () => null };
|
|
40
|
+
return new Function(`${SWFLIB_SOURCE}\nreturn __swoof_swflib;`)();
|
|
41
|
+
}
|
|
42
|
+
function setPixels(bitmap, pixels) { bitmap._canvas.pixels.set(pixels.flat(2)); }
|
|
43
|
+
function pixel(bitmap, x, y = 0) {
|
|
44
|
+
const i = (y * bitmap.width + x) * 4;
|
|
45
|
+
return Array.from(bitmap._canvas.pixels.subarray(i, i + 4));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
describe('BitmapData getVector/setVector', () => {
|
|
49
|
+
it('returns row-major unsigned ARGB pixels from a clipped rectangle', () => {
|
|
50
|
+
const { builtins } = makeRuntime();
|
|
51
|
+
const bitmap = new builtins.BitmapData(2, 2, true);
|
|
52
|
+
setPixels(bitmap, [
|
|
53
|
+
[[1, 2, 3, 4], [5, 6, 7, 8]],
|
|
54
|
+
[[9, 10, 11, 12], [13, 14, 15, 16]],
|
|
55
|
+
]);
|
|
56
|
+
const values = bitmap.getVector({ x: -1, y: 0, width: 2, height: 2 });
|
|
57
|
+
expect(Array.from(values)).toEqual([0x04010203, 0x0c090a0b]);
|
|
58
|
+
expect(values.fixed).toBe(false);
|
|
59
|
+
expect(Array.from(bitmap.getVector({ x: 5, y: 0, width: 1, height: 1 }))).toEqual([]);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('writes vector pixels into the clipped area and leaves other pixels unchanged', () => {
|
|
63
|
+
const { builtins } = makeRuntime();
|
|
64
|
+
const bitmap = new builtins.BitmapData(3, 1, true);
|
|
65
|
+
setPixels(bitmap, [[[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3]]]);
|
|
66
|
+
bitmap.setVector({ x: -1, y: 0, width: 3, height: 1 }, [0xff112233, 0x80445566]);
|
|
67
|
+
expect([pixel(bitmap, 0), pixel(bitmap, 1), pixel(bitmap, 2)]).toEqual([
|
|
68
|
+
[0x11, 0x22, 0x33, 0xff], [0x44, 0x55, 0x66, 0x80], [3, 3, 3, 3],
|
|
69
|
+
]);
|
|
70
|
+
bitmap.setVector({ x: 0, y: 0, width: 1, height: 1 }, [0xffaabbcc]);
|
|
71
|
+
expect(pixel(bitmap, 0)).toEqual([0xaa, 0xbb, 0xcc, 0xff]);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('throws after applying available values when the input vector is short', () => {
|
|
75
|
+
const { builtins } = makeRuntime();
|
|
76
|
+
const bitmap = new builtins.BitmapData(2, 1, true);
|
|
77
|
+
expect(() => bitmap.setVector({ x: 0, y: 0, width: 2, height: 1 }, [0xff123456]))
|
|
78
|
+
.toThrow(/inputVector does not contain enough pixels/);
|
|
79
|
+
expect(pixel(bitmap, 0)).toEqual([0x12, 0x34, 0x56, 0xff]);
|
|
80
|
+
expect(pixel(bitmap, 1)).toEqual([0, 0, 0, 0]);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { runInNewContext } from 'node:vm';
|
|
2
|
+
import { describe, expect, it } from 'vitest';
|
|
3
|
+
import { SWFLIB_SOURCE } from '../runtime/index.js';
|
|
4
|
+
|
|
5
|
+
const runtime = runInNewContext(SWFLIB_SOURCE + '\n__swoof_swflib;', {});
|
|
6
|
+
const { BlurFilter } = runtime.packages.filters;
|
|
7
|
+
const width = 7, height = 7;
|
|
8
|
+
|
|
9
|
+
function render(filter, dots = [[3, 3, 200, 50, 10, 240]]) {
|
|
10
|
+
let pixels = new Uint8ClampedArray(width * height * 4);
|
|
11
|
+
for (const [x, y, ...color] of dots) pixels.set(color, (y * width + x) * 4);
|
|
12
|
+
runtime.applyDisplayEffects({
|
|
13
|
+
canvas: { width, height },
|
|
14
|
+
getImageData: () => ({ data: pixels.slice() }),
|
|
15
|
+
putImageData: image => { pixels = image.data; },
|
|
16
|
+
}, null, [filter]);
|
|
17
|
+
return {
|
|
18
|
+
pixel: (x, y) => [...pixels.slice((y * width + x) * 4, (y * width + x + 1) * 4)],
|
|
19
|
+
alpha: (x, y) => pixels[(y * width + x) * 4 + 3],
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
describe('BlurFilter separable pixel kernel', () => {
|
|
24
|
+
it('blurs independent axes with weighted fractional box edges', () => {
|
|
25
|
+
const output = render(new BlurFilter(3, 2, 1));
|
|
26
|
+
expect(output.pixel(3, 3)).toEqual([200, 50, 10, 40]);
|
|
27
|
+
expect(output.pixel(2, 3)).toEqual([200, 50, 10, 40]);
|
|
28
|
+
expect(output.pixel(2, 2)).toEqual([200, 50, 10, 20]);
|
|
29
|
+
expect(output.alpha(1, 3)).toBe(0);
|
|
30
|
+
expect(output.alpha(3, 1)).toBe(0);
|
|
31
|
+
expect(render(new BlurFilter(0, 3, 1)).alpha(3, 2)).toBe(80);
|
|
32
|
+
expect(render(new BlurFilter(0, 3, 1)).alpha(2, 3)).toBe(0);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('repeats each requested quality pass for programmatic and authored filters', () => {
|
|
36
|
+
for (const filter of [new BlurFilter(3, 0, 2), { type: 'blur', blurX: 3, blurY: 0, passes: 2 }]) {
|
|
37
|
+
const output = render(filter);
|
|
38
|
+
expect([1, 2, 3, 4, 5].map(x => output.alpha(x, 3))).toEqual([27, 53, 80, 53, 27]);
|
|
39
|
+
}
|
|
40
|
+
expect(render(new BlurFilter(3, 3, 0)).alpha(3, 3)).toBe(240);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('blurs premultiplied pixels and treats samples beyond the canvas as transparent', () => {
|
|
44
|
+
const output = render(new BlurFilter(3, 0, 1), [[0, 3, 255, 0, 0, 240], [1, 3, 0, 0, 255, 120]]);
|
|
45
|
+
expect(output.pixel(0, 3)).toEqual([170, 0, 85, 120]);
|
|
46
|
+
expect(output.pixel(2, 3)).toEqual([0, 0, 255, 40]);
|
|
47
|
+
});
|
|
48
|
+
});
|