Don't get ICC color space files if required API options are missing

This commit improves validation of the API options for the ICC color
space logic. If `useWasm` is `true` but the corresponding `wasmUrl`
or `iccUrl` API options are not provided we can avoid requesting
files with `null` URLs which always results in a 404 response.
This commit is contained in:
Tim van der Meij 2025-03-16 14:40:15 +01:00
parent d86045eacb
commit f44cba86d5
No known key found for this signature in database
GPG Key ID: 8C3FD2925A5F2762
2 changed files with 23 additions and 6 deletions

View File

@ -289,7 +289,7 @@ class ColorSpaceUtils {
} }
static get cmyk() { static get cmyk() {
if (IccColorSpace.isUsable) { if (CmykICCBasedCS.isUsable) {
try { try {
return shadow(this, "cmyk", new CmykICCBasedCS()); return shadow(this, "cmyk", new CmykICCBasedCS());
} catch { } catch {

View File

@ -130,12 +130,16 @@ class IccColorSpace extends ColorSpace {
static get isUsable() { static get isUsable() {
let isUsable = false; let isUsable = false;
if (this.#useWasm) { if (this.#useWasm) {
if (this.#wasmUrl) {
try { try {
this._module = QCMS._module = this.#load(); this._module = QCMS._module = this.#load();
isUsable = !!this._module; isUsable = !!this._module;
} catch (e) { } catch (e) {
warn(`ICCBased color space: "${e}".`); warn(`ICCBased color space: "${e}".`);
} }
} else {
warn("No ICC color space support due to missing `wasmUrl` API option");
}
} }
return shadow(this, "isUsable", isUsable); return shadow(this, "isUsable", isUsable);
@ -169,6 +173,19 @@ class CmykICCBasedCS extends IccColorSpace {
static setOptions({ iccUrl }) { static setOptions({ iccUrl }) {
this.#iccUrl = iccUrl; this.#iccUrl = iccUrl;
} }
static get isUsable() {
let isUsable = false;
if (IccColorSpace.isUsable) {
if (this.#iccUrl) {
isUsable = true;
} else {
warn("No CMYK ICC profile support due to missing `iccUrl` API option");
}
}
return shadow(this, "isUsable", isUsable);
}
} }
export { CmykICCBasedCS, IccColorSpace }; export { CmykICCBasedCS, IccColorSpace };