@@ -28,6 +28,17 @@ import { shadow, warn } from "../shared/util.js";
2828import { ColorSpace } from "./colorspace.js" ;
2929import { QCMS } from "../../external/qcms/qcms_utils.js" ;
3030
31+ function fetchSync ( url ) {
32+ // Parsing and using color spaces is still synchronous,
33+ // so we must load the wasm module synchronously.
34+ // TODO: Make the color space stuff asynchronous and use fetch.
35+ const xhr = new XMLHttpRequest ( ) ;
36+ xhr . open ( "GET" , url , false ) ;
37+ xhr . responseType = "arraybuffer" ;
38+ xhr . send ( null ) ;
39+ return xhr . response ;
40+ }
41+
3142class IccColorSpace extends ColorSpace {
3243 #transformer;
3344
@@ -132,7 +143,9 @@ class IccColorSpace extends ColorSpace {
132143 if ( this . #useWasm) {
133144 if ( this . #wasmUrl) {
134145 try {
135- this . _module = QCMS . _module = this . #load( ) ;
146+ this . _module = QCMS . _module = initSync ( {
147+ module : fetchSync ( `${ this . #wasmUrl} qcms_bg.wasm` ) ,
148+ } ) ;
136149 isUsable = ! ! this . _module ;
137150 } catch ( e ) {
138151 warn ( `ICCBased color space: "${ e } ".` ) ;
@@ -144,30 +157,16 @@ class IccColorSpace extends ColorSpace {
144157
145158 return shadow ( this , "isUsable" , isUsable ) ;
146159 }
147-
148- static #load( ) {
149- // Parsing and using color spaces is still synchronous,
150- // so we must load the wasm module synchronously.
151- // TODO: Make the color space stuff asynchronous and use fetch.
152- const filename = "qcms_bg.wasm" ;
153- const xhr = new XMLHttpRequest ( ) ;
154- xhr . open ( "GET" , `${ this . #wasmUrl} ${ filename } ` , false ) ;
155- xhr . responseType = "arraybuffer" ;
156- xhr . send ( null ) ;
157- return initSync ( { module : xhr . response } ) ;
158- }
159160}
160161
161162class CmykICCBasedCS extends IccColorSpace {
162163 static #iccUrl;
163164
164165 constructor ( ) {
165- const filename = "CGATS001Compat-v2-micro.icc" ;
166- const xhr = new XMLHttpRequest ( ) ;
167- xhr . open ( "GET" , `${ CmykICCBasedCS . #iccUrl} ${ filename } ` , false ) ;
168- xhr . responseType = "arraybuffer" ;
169- xhr . send ( null ) ;
170- super ( new Uint8Array ( xhr . response ) , "DeviceCMYK" , 4 ) ;
166+ const iccProfile = new Uint8Array (
167+ fetchSync ( `${ CmykICCBasedCS . #iccUrl} CGATS001Compat-v2-micro.icc` )
168+ ) ;
169+ super ( iccProfile , "DeviceCMYK" , 4 ) ;
171170 }
172171
173172 static setOptions ( { iccUrl } ) {
0 commit comments