diff --git a/waifu2x/unlimited_waifu2x/appendix/unlimited.waifu2x.net b/waifu2x/unlimited_waifu2x/appendix/unlimited.waifu2x.net index 7429494b..4dae7691 100644 --- a/waifu2x/unlimited_waifu2x/appendix/unlimited.waifu2x.net +++ b/waifu2x/unlimited_waifu2x/appendix/unlimited.waifu2x.net @@ -8,9 +8,19 @@ server { } location / { add_header Cache-Control "public, max-age=3600, must-revalidate"; + # If you want to enable multi-threading + #add_header Cross-Origin-Resource-Policy "cross-origin"; + #add_header Cross-Origin-Embedder-Policy "require-corp"; + #add_header Cross-Origin-Opener-Policy "same-origin"; } location ~* \.(onnx|pth) { add_header Cache-Control "public, max-age=86400, must-revalidate"; } + location ~* \.wasm$ { + types { + application/wasm wasm; + } + } + listen 80; } diff --git a/waifu2x/unlimited_waifu2x/public_html/script.js b/waifu2x/unlimited_waifu2x/public_html/script.js index 1d8cbf6a..c57c3bb3 100644 --- a/waifu2x/unlimited_waifu2x/public_html/script.js +++ b/waifu2x/unlimited_waifu2x/public_html/script.js @@ -542,6 +542,7 @@ const onnx_runner = { $(function () { /* init */ ort.env.wasm.proxy = true; + ort.env.wasm.numThreads = navigator.hardwareConcurrency; function removeAlpha(blob) { diff --git a/waifu2x/unlimited_waifu2x/test_server.py b/waifu2x/unlimited_waifu2x/test_server.py index a8a66bcb..871f9343 100644 --- a/waifu2x/unlimited_waifu2x/test_server.py +++ b/waifu2x/unlimited_waifu2x/test_server.py @@ -2,9 +2,15 @@ # View at http://localhost:8812/ # Do not use this server in product environments. import bottle +import argparse from os import path +parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter) +parser.add_argument("--cors", action="store_true", + help=("Add CORS header for testing wasm multi-threading." + " google-chrome does not work for security reasons (localhost CORS), use firefox")) +args = parser.parse_args() ROOT_DIR = path.abspath(path.join(path.dirname(__file__), "public_html")) @@ -12,7 +18,12 @@ def static_file(url): if not url: url = "index.html" - return bottle.static_file(url, root=ROOT_DIR) + response = bottle.static_file(url, root=ROOT_DIR) + if args.cors: + response.set_header("Cross-Origin-Resource-Policy", "cross-origin") + response.set_header("Cross-Origin-Embedder-Policy", "require-corp") + response.set_header("Cross-Origin-Opener-Policy", "same-origin") + return response def main():