@loaders.gl/images 3.1.0-alpha.1 → 3.1.0-alpha.5
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/dist/bundle.d.ts +1 -0
- package/dist/dist.min.js +1 -1
- package/dist/dist.min.js.map +1 -1
- package/dist/es5/bundle.js +7 -0
- package/dist/es5/bundle.js.map +1 -0
- package/dist/es5/image-loader.js +38 -0
- package/dist/es5/image-loader.js.map +1 -0
- package/dist/es5/image-writer.js +27 -0
- package/dist/es5/image-writer.js.map +1 -0
- package/dist/es5/index.js +86 -0
- package/dist/es5/index.js.map +1 -0
- package/dist/es5/lib/category-api/binary-image-api.js +126 -0
- package/dist/es5/lib/category-api/binary-image-api.js.map +1 -0
- package/dist/es5/lib/category-api/image-format.js +53 -0
- package/dist/es5/lib/category-api/image-format.js.map +1 -0
- package/dist/es5/lib/category-api/image-type.js +53 -0
- package/dist/es5/lib/category-api/image-type.js.map +1 -0
- package/dist/es5/lib/category-api/parsed-image-api.js +79 -0
- package/dist/es5/lib/category-api/parsed-image-api.js.map +1 -0
- package/dist/es5/lib/encoders/encode-image.js +79 -0
- package/dist/es5/lib/encoders/encode-image.js.map +1 -0
- package/dist/es5/lib/parsers/parse-image.js +67 -0
- package/dist/es5/lib/parsers/parse-image.js.map +1 -0
- package/dist/es5/lib/parsers/parse-to-image-bitmap.js +55 -0
- package/dist/es5/lib/parsers/parse-to-image-bitmap.js.map +1 -0
- package/dist/es5/lib/parsers/parse-to-image.js +44 -0
- package/dist/es5/lib/parsers/parse-to-image.js.map +1 -0
- package/dist/es5/lib/parsers/parse-to-node-image.js +20 -0
- package/dist/es5/lib/parsers/parse-to-node-image.js.map +1 -0
- package/dist/es5/lib/parsers/svg-utils.js +43 -0
- package/dist/es5/lib/parsers/svg-utils.js.map +1 -0
- package/dist/es5/lib/texture-api/async-deep-map.js +48 -0
- package/dist/es5/lib/texture-api/async-deep-map.js.map +1 -0
- package/dist/es5/lib/texture-api/deep-load.js +20 -0
- package/dist/es5/lib/texture-api/deep-load.js.map +1 -0
- package/dist/es5/lib/texture-api/generate-url.js +30 -0
- package/dist/es5/lib/texture-api/generate-url.js.map +1 -0
- package/dist/es5/lib/texture-api/load-image.js +69 -0
- package/dist/es5/lib/texture-api/load-image.js.map +1 -0
- package/dist/es5/lib/utils/version.js +9 -0
- package/dist/es5/lib/utils/version.js.map +1 -0
- package/dist/es5/types.js +2 -0
- package/dist/{types.js.map → es5/types.js.map} +0 -0
- package/dist/esm/bundle.js +5 -0
- package/dist/esm/bundle.js.map +1 -0
- package/dist/{image-loader.js → esm/image-loader.js} +7 -6
- package/dist/esm/image-loader.js.map +1 -0
- package/dist/{image-writer.js → esm/image-writer.js} +0 -0
- package/dist/esm/image-writer.js.map +1 -0
- package/dist/{index.js → esm/index.js} +1 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/{lib → esm/lib}/category-api/binary-image-api.js +0 -0
- package/dist/esm/lib/category-api/binary-image-api.js.map +1 -0
- package/dist/esm/lib/category-api/image-format.js +44 -0
- package/dist/esm/lib/category-api/image-format.js.map +1 -0
- package/dist/{lib → esm/lib}/category-api/image-type.js +3 -3
- package/dist/esm/lib/category-api/image-type.js.map +1 -0
- package/dist/{lib → esm/lib}/category-api/parsed-image-api.js +0 -0
- package/dist/esm/lib/category-api/parsed-image-api.js.map +1 -0
- package/dist/{lib → esm/lib}/encoders/encode-image.js +1 -2
- package/dist/esm/lib/encoders/encode-image.js.map +1 -0
- package/dist/{lib → esm/lib}/parsers/parse-image.js +1 -1
- package/dist/esm/lib/parsers/parse-image.js.map +1 -0
- package/dist/{lib → esm/lib}/parsers/parse-to-image-bitmap.js +0 -0
- package/dist/esm/lib/parsers/parse-to-image-bitmap.js.map +1 -0
- package/dist/{lib → esm/lib}/parsers/parse-to-image.js +1 -1
- package/dist/esm/lib/parsers/parse-to-image.js.map +1 -0
- package/dist/esm/lib/parsers/parse-to-node-image.js +11 -0
- package/dist/esm/lib/parsers/parse-to-node-image.js.map +1 -0
- package/dist/{lib → esm/lib}/parsers/svg-utils.js +1 -1
- package/dist/esm/lib/parsers/svg-utils.js.map +1 -0
- package/dist/{lib → esm/lib}/texture-api/async-deep-map.js +0 -0
- package/dist/esm/lib/texture-api/async-deep-map.js.map +1 -0
- package/dist/{lib → esm/lib}/texture-api/deep-load.js +0 -0
- package/dist/esm/lib/texture-api/deep-load.js.map +1 -0
- package/dist/{lib → esm/lib}/texture-api/generate-url.js +2 -3
- package/dist/esm/lib/texture-api/generate-url.js.map +1 -0
- package/dist/{lib → esm/lib}/texture-api/load-image.js +1 -1
- package/dist/esm/lib/texture-api/load-image.js.map +1 -0
- package/dist/esm/lib/utils/version.js +2 -0
- package/dist/esm/lib/utils/version.js.map +1 -0
- package/dist/{types.js → esm/types.js} +0 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/image-loader.d.ts +25 -0
- package/dist/image-writer.d.ts +15 -0
- package/dist/index.d.ts +9 -0
- package/dist/lib/category-api/binary-image-api.d.ts +18 -0
- package/dist/lib/category-api/image-format.d.ts +4 -0
- package/dist/lib/category-api/image-type.d.ts +11 -0
- package/dist/lib/category-api/parsed-image-api.d.ts +9 -0
- package/dist/lib/encoders/encode-image.d.ts +11 -0
- package/dist/lib/parsers/parse-image.d.ts +4 -0
- package/dist/lib/parsers/parse-to-image-bitmap.d.ts +9 -0
- package/dist/lib/parsers/parse-to-image.d.ts +3 -0
- package/dist/lib/parsers/parse-to-node-image.d.ts +3 -0
- package/dist/lib/parsers/svg-utils.d.ts +3 -0
- package/dist/lib/texture-api/async-deep-map.d.ts +2 -0
- package/dist/lib/texture-api/deep-load.d.ts +2 -0
- package/dist/lib/texture-api/generate-url.d.ts +1 -0
- package/dist/lib/texture-api/load-image.d.ts +6 -0
- package/dist/lib/utils/version.d.ts +1 -0
- package/dist/types.d.ts +17 -0
- package/package.json +7 -6
- package/src/bundle.ts +2 -3
- package/src/image-loader.ts +18 -8
- package/src/index.ts +4 -0
- package/src/lib/category-api/image-format.ts +66 -0
- package/src/lib/category-api/image-type.ts +2 -2
- package/src/lib/encoders/encode-image.ts +1 -2
- package/src/lib/parsers/parse-image.ts +9 -2
- package/src/lib/parsers/parse-to-image-bitmap.ts +10 -2
- package/src/lib/parsers/parse-to-image.ts +7 -2
- package/src/lib/parsers/parse-to-node-image.ts +24 -6
- package/src/lib/parsers/svg-utils.ts +2 -2
- package/src/lib/texture-api/generate-url.ts +1 -2
- package/src/lib/texture-api/load-image.ts +1 -1
- package/dist/bundle.js +0 -7
- package/dist/bundle.js.map +0 -1
- package/dist/image-loader.js.map +0 -1
- package/dist/image-writer.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/category-api/binary-image-api.js.map +0 -1
- package/dist/lib/category-api/image-type.js.map +0 -1
- package/dist/lib/category-api/parsed-image-api.js.map +0 -1
- package/dist/lib/encoders/encode-image.js.map +0 -1
- package/dist/lib/parsers/parse-image.js.map +0 -1
- package/dist/lib/parsers/parse-to-image-bitmap.js.map +0 -1
- package/dist/lib/parsers/parse-to-image.js.map +0 -1
- package/dist/lib/parsers/parse-to-node-image.js +0 -14
- package/dist/lib/parsers/parse-to-node-image.js.map +0 -1
- package/dist/lib/parsers/svg-utils.js.map +0 -1
- package/dist/lib/texture-api/async-deep-map.js.map +0 -1
- package/dist/lib/texture-api/deep-load.js.map +0 -1
- package/dist/lib/texture-api/generate-url.js.map +0 -1
- package/dist/lib/texture-api/load-image.js.map +0 -1
- package/dist/lib/utils/assert.js +0 -6
- package/dist/lib/utils/assert.js.map +0 -1
- package/dist/lib/utils/globals.js +0 -16
- package/dist/lib/utils/globals.js.map +0 -1
- package/dist/lib/utils/version.js +0 -2
- package/dist/lib/utils/version.js.map +0 -1
- package/src/lib/utils/assert.js +0 -5
- package/src/lib/utils/globals.ts +0 -48
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/parsers/svg-utils.ts"],"names":["SVG_DATA_URL_PATTERN","SVG_URL_PATTERN","isSVG","url","test","getBlobOrSVGDataUrl","arrayBuffer","textDecoder","TextDecoder","xmlText","decode","unescape","encodeURIComponent","error","Error","message","src","btoa","getBlob","Blob","Uint8Array"],"mappings":"AAGA,MAAMA,oBAAoB,GAAG,uBAA7B;AACA,MAAMC,eAAe,GAAG,mBAAxB;AAEA,OAAO,SAASC,KAAT,CAAeC,GAAf,EAAoB;AACzB,SAAOA,GAAG,KAAKH,oBAAoB,CAACI,IAArB,CAA0BD,GAA1B,KAAkCF,eAAe,CAACG,IAAhB,CAAqBD,GAArB,CAAvC,CAAV;AACD;AAED,OAAO,SAASE,mBAAT,CAA6BC,WAA7B,EAAuDH,GAAvD,EAAoF;AACzF,MAAID,KAAK,CAACC,GAAD,CAAT,EAAgB;AAEd,UAAMI,WAAW,GAAG,IAAIC,WAAJ,EAApB;AACA,QAAIC,OAAO,GAAGF,WAAW,CAACG,MAAZ,CAAmBJ,WAAnB,CAAd;;AAEA,QAAI;AACF,UAAI,OAAOK,QAAP,KAAoB,UAApB,IAAkC,OAAOC,kBAAP,KAA8B,UAApE,EAAgF;AAC9EH,QAAAA,OAAO,GAAGE,QAAQ,CAACC,kBAAkB,CAACH,OAAD,CAAnB,CAAlB;AACD;AACF,KAJD,CAIE,OAAOI,KAAP,EAAc;AACd,YAAM,IAAIC,KAAJ,CAAWD,KAAD,CAAiBE,OAA3B,CAAN;AACD;;AAED,UAAMC,GAAG,uCAAgCC,IAAI,CAACR,OAAD,CAApC,CAAT;AACA,WAAOO,GAAP;AACD;;AACD,SAAOE,OAAO,CAACZ,WAAD,EAAcH,GAAd,CAAd;AACD;AAED,OAAO,SAASe,OAAT,CAAiBZ,WAAjB,EAA2CH,GAA3C,EAA+D;AACpE,MAAID,KAAK,CAACC,GAAD,CAAT,EAAgB;AAGd,UAAM,IAAIW,KAAJ,CAAU,8CAAV,CAAN;AACD;;AAED,SAAO,IAAIK,IAAJ,CAAS,CAAC,IAAIC,UAAJ,CAAed,WAAf,CAAD,CAAT,CAAP;AACD","sourcesContent":["// SVG parsing has limitations, e.g:\n// https://bugs.chromium.org/p/chromium/issues/detail?id=606319\n\nconst SVG_DATA_URL_PATTERN = /^data:image\\/svg\\+xml/;\nconst SVG_URL_PATTERN = /\\.svg((\\?|#).*)?$/;\n\nexport function isSVG(url) {\n return url && (SVG_DATA_URL_PATTERN.test(url) || SVG_URL_PATTERN.test(url));\n}\n\nexport function getBlobOrSVGDataUrl(arrayBuffer: ArrayBuffer, url?: string): Blob | string {\n if (isSVG(url)) {\n // Prepare a properly tagged data URL, and load using normal mechanism\n const textDecoder = new TextDecoder();\n let xmlText = textDecoder.decode(arrayBuffer);\n // TODO Escape in browser to support e.g. Chinese characters\n try {\n if (typeof unescape === 'function' && typeof encodeURIComponent === 'function') {\n xmlText = unescape(encodeURIComponent(xmlText));\n }\n } catch (error) {\n throw new Error((error as Error).message);\n }\n // base64 encoding is safer. utf-8 fails in some browsers\n const src = `data:image/svg+xml;base64,${btoa(xmlText)}`;\n return src;\n }\n return getBlob(arrayBuffer, url);\n}\n\nexport function getBlob(arrayBuffer: ArrayBuffer, url?: string): Blob {\n if (isSVG(url)) {\n // https://bugs.chromium.org/p/chromium/issues/detail?id=606319\n // return new Blob([new Uint8Array(arrayBuffer)], {type: 'image/svg+xml'});\n throw new Error('SVG cannot be parsed directly to imagebitmap');\n }\n // TODO - how to determine mime type? Param? Sniff here?\n return new Blob([new Uint8Array(arrayBuffer)]); // MIME type not needed?\n}\n"],"file":"svg-utils.js"}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/texture-api/async-deep-map.ts"],"names":["isObject","value","asyncDeepMap","tree","func","options","mapSubtree","object","Array","isArray","mapArray","mapObject","url","promises","values","key","promise","then","push","Promise","all","urlArray","map"],"mappings":"AAgBA,MAAMA,QAAQ,GAAIC,KAAD,IAAWA,KAAK,IAAI,OAAOA,KAAP,KAAiB,QAAtD;;AAKA,OAAO,eAAeC,YAAf,CAA4BC,IAA5B,EAAkCC,IAAlC,EAAwCC,OAAO,GAAG,EAAlD,EAAsD;AAC3D,SAAO,MAAMC,UAAU,CAACH,IAAD,EAAOC,IAAP,EAAaC,OAAb,CAAvB;AACD;AAED,OAAO,eAAeC,UAAf,CAA0BC,MAA1B,EAAkCH,IAAlC,EAAwCC,OAAxC,EAAiD;AACtD,MAAIG,KAAK,CAACC,OAAN,CAAcF,MAAd,CAAJ,EAA2B;AACzB,WAAO,MAAMG,QAAQ,CAACH,MAAD,EAASH,IAAT,EAAeC,OAAf,CAArB;AACD;;AAED,MAAIL,QAAQ,CAACO,MAAD,CAAZ,EAAsB;AACpB,WAAO,MAAMI,SAAS,CAACJ,MAAD,EAASH,IAAT,EAAeC,OAAf,CAAtB;AACD;;AAGD,QAAMO,GAAG,GAAGL,MAAZ;AACA,SAAO,MAAMH,IAAI,CAACQ,GAAD,EAAMP,OAAN,CAAjB;AACD;;AAID,eAAeM,SAAf,CAAyBJ,MAAzB,EAAiCH,IAAjC,EAAuCC,OAAvC,EAAgD;AAC9C,QAAMQ,QAAwB,GAAG,EAAjC;AACA,QAAMC,MAAM,GAAG,EAAf;;AAEA,OAAK,MAAMC,GAAX,IAAkBR,MAAlB,EAA0B;AACxB,UAAMK,GAAG,GAAGL,MAAM,CAACQ,GAAD,CAAlB;AACA,UAAMC,OAAO,GAAGV,UAAU,CAACM,GAAD,EAAMR,IAAN,EAAYC,OAAZ,CAAV,CAA+BY,IAA/B,CAAqChB,KAAD,IAAW;AAC7Da,MAAAA,MAAM,CAACC,GAAD,CAAN,GAAcd,KAAd;AACD,KAFe,CAAhB;AAGAY,IAAAA,QAAQ,CAACK,IAAT,CAAcF,OAAd;AACD;;AAED,QAAMG,OAAO,CAACC,GAAR,CAAYP,QAAZ,CAAN;AAEA,SAAOC,MAAP;AACD;;AAED,eAAeJ,QAAf,CAAwBW,QAAxB,EAAkCjB,IAAlC,EAAwCC,OAAO,GAAG,EAAlD,EAAsD;AACpD,QAAMQ,QAAQ,GAAGQ,QAAQ,CAACC,GAAT,CAAcV,GAAD,IAASN,UAAU,CAACM,GAAD,EAAMR,IAAN,EAAYC,OAAZ,CAAhC,CAAjB;AACA,SAAO,MAAMc,OAAO,CAACC,GAAR,CAAYP,QAAZ,CAAb;AACD","sourcesContent":["/*\nAsynchronously maps a deep structure of values (e.g. objects and arrays of urls).\n\nE.g. a mipmapped cubemap\n{\n [CUBE_FACE_FRONT]: [\n \"image-front-0.jpg\",\n \"image-front-1.jpg\",\n \"image-front-2.jpg\",\n ],\n [CUBE_MAP_BACK]: [\n ...\n ]\n}\n*/\n\nconst isObject = (value) => value && typeof value === 'object';\n\n// Loads a deep structure of urls (objects and arrays of urls)\n// Returns an object with six key-value pairs containing the images (or image mip arrays)\n// for each cube face\nexport async function asyncDeepMap(tree, func, options = {}) {\n return await mapSubtree(tree, func, options);\n}\n\nexport async function mapSubtree(object, func, options) {\n if (Array.isArray(object)) {\n return await mapArray(object, func, options);\n }\n\n if (isObject(object)) {\n return await mapObject(object, func, options);\n }\n\n // TODO - ignore non-urls, non-arraybuffers?\n const url = object;\n return await func(url, options);\n}\n\n// HELPERS\n\nasync function mapObject(object, func, options) {\n const promises: Promise<any>[] = [];\n const values = {};\n\n for (const key in object) {\n const url = object[key];\n const promise = mapSubtree(url, func, options).then((value) => {\n values[key] = value;\n });\n promises.push(promise);\n }\n\n await Promise.all(promises);\n\n return values;\n}\n\nasync function mapArray(urlArray, func, options = {}) {\n const promises = urlArray.map((url) => mapSubtree(url, func, options));\n return await Promise.all(promises);\n}\n"],"file":"async-deep-map.js"}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/texture-api/deep-load.ts"],"names":["asyncDeepMap","deepLoad","urlTree","load","options","url","shallowLoad","response","fetch","arrayBuffer"],"mappings":"AAAA,SAAQA,YAAR,QAA2B,kBAA3B;AAEA,OAAO,eAAeC,QAAf,CAAwBC,OAAxB,EAAiCC,IAAjC,EAAuCC,OAAvC,EAAgD;AACrD,SAAO,MAAMJ,YAAY,CAACE,OAAD,EAAWG,GAAD,IAASC,WAAW,CAACD,GAAD,EAAMF,IAAN,EAAYC,OAAZ,CAA9B,CAAzB;AACD;AAED,OAAO,eAAeE,WAAf,CAA2BD,GAA3B,EAAgCF,IAAhC,EAAsCC,OAAtC,EAA+C;AAEpD,QAAMG,QAAQ,GAAG,MAAMC,KAAK,CAACH,GAAD,EAAMD,OAAO,CAACI,KAAd,CAA5B;AACA,QAAMC,WAAW,GAAG,MAAMF,QAAQ,CAACE,WAAT,EAA1B;AACA,SAAO,MAAMN,IAAI,CAACM,WAAD,EAAcL,OAAd,CAAjB;AACD","sourcesContent":["import {asyncDeepMap} from './async-deep-map';\n\nexport async function deepLoad(urlTree, load, options) {\n return await asyncDeepMap(urlTree, (url) => shallowLoad(url, load, options));\n}\n\nexport async function shallowLoad(url, load, options) {\n // console.error('loading', url);\n const response = await fetch(url, options.fetch);\n const arrayBuffer = await response.arrayBuffer();\n return await load(arrayBuffer, options);\n}\n"],"file":"deep-load.js"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { resolvePath } from '@loaders.gl/loader-utils';
|
|
2
|
-
import { assert } from '../utils/assert';
|
|
1
|
+
import { resolvePath, assert } from '@loaders.gl/loader-utils';
|
|
3
2
|
export function generateUrl(getUrl, options, urlOptions) {
|
|
4
3
|
let url = getUrl;
|
|
5
4
|
|
|
@@ -15,7 +14,7 @@ export function generateUrl(getUrl, options, urlOptions) {
|
|
|
15
14
|
} = options;
|
|
16
15
|
|
|
17
16
|
if (baseUrl) {
|
|
18
|
-
url = baseUrl[baseUrl.length - 1] === '/' ?
|
|
17
|
+
url = baseUrl[baseUrl.length - 1] === '/' ? "".concat(baseUrl).concat(url) : "".concat(baseUrl, "/").concat(url);
|
|
19
18
|
}
|
|
20
19
|
|
|
21
20
|
return resolvePath(url);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/texture-api/generate-url.ts"],"names":["resolvePath","assert","generateUrl","getUrl","options","urlOptions","url","baseUrl","length"],"mappings":"AAAA,SAAQA,WAAR,EAAqBC,MAArB,QAAkC,0BAAlC;AAGA,OAAO,SAASC,WAAT,CAAqBC,MAArB,EAA6BC,OAA7B,EAAsCC,UAAtC,EAAkD;AAEvD,MAAIC,GAAG,GAAGH,MAAV;;AACA,MAAI,OAAOA,MAAP,KAAkB,UAAtB,EAAkC;AAChCG,IAAAA,GAAG,GAAGH,MAAM,CAAC,EAAC,GAAGC,OAAJ;AAAa,SAAGC;AAAhB,KAAD,CAAZ;AACD;;AACDJ,EAAAA,MAAM,CAAC,OAAOK,GAAP,KAAe,QAAhB,CAAN;AAGA,QAAM;AAACC,IAAAA;AAAD,MAAYH,OAAlB;;AACA,MAAIG,OAAJ,EAAa;AACXD,IAAAA,GAAG,GAAGC,OAAO,CAACA,OAAO,CAACC,MAAR,GAAiB,CAAlB,CAAP,KAAgC,GAAhC,aAAyCD,OAAzC,SAAmDD,GAAnD,cAA8DC,OAA9D,cAAyED,GAAzE,CAAN;AACD;;AAED,SAAON,WAAW,CAACM,GAAD,CAAlB;AACD","sourcesContent":["import {resolvePath, assert} from '@loaders.gl/loader-utils';\n\n// Generate a url by calling getUrl with mix of options, applying options.baseUrl\nexport function generateUrl(getUrl, options, urlOptions) {\n // Get url\n let url = getUrl;\n if (typeof getUrl === 'function') {\n url = getUrl({...options, ...urlOptions});\n }\n assert(typeof url === 'string');\n\n // Apply options.baseUrl\n const {baseUrl} = options;\n if (baseUrl) {\n url = baseUrl[baseUrl.length - 1] === '/' ? `${baseUrl}${url}` : `${baseUrl}/${url}`;\n }\n\n return resolvePath(url);\n}\n"],"file":"generate-url.js"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/texture-api/load-image.ts"],"names":["assert","parseImage","getImageSize","generateUrl","deepLoad","shallowLoad","loadImage","getUrl","options","imageUrls","getImageUrls","urlOptions","mipLevels","image","getMipmappedImageUrls","urls","url","lod","width","height","getMipLevels","push","mipLevel","length","Math","floor","log2","max"],"mappings":"AAAA,SAAQA,MAAR,QAAqB,0BAArB;AACA,OAAOC,UAAP,MAAuB,wBAAvB;AACA,SAAQC,YAAR,QAA2B,kCAA3B;AACA,SAAQC,WAAR,QAA0B,gBAA1B;AACA,SAAQC,QAAR,EAAkBC,WAAlB,QAAoC,aAApC;AAEA,OAAO,eAAeC,SAAf,CAAyBC,MAAzB,EAAiCC,OAAO,GAAG,EAA3C,EAA+C;AACpD,QAAMC,SAAS,GAAG,MAAMC,YAAY,CAACH,MAAD,EAASC,OAAT,CAApC;AACA,SAAO,MAAMJ,QAAQ,CAACK,SAAD,EAAYR,UAAZ,EAAwBO,OAAxB,CAArB;AACD;AAED,OAAO,eAAeE,YAAf,CAA4BH,MAA5B,EAAoCC,OAApC,EAA6CG,UAAU,GAAG,EAA1D,EAA8D;AACnE,QAAMC,SAAS,GAAIJ,OAAO,IAAIA,OAAO,CAACK,KAAnB,IAA4BL,OAAO,CAACK,KAAR,CAAcD,SAA3C,IAAyD,CAA3E;AACA,SAAOA,SAAS,KAAK,CAAd,GACH,MAAME,qBAAqB,CAACP,MAAD,EAASK,SAAT,EAAoBJ,OAApB,EAA6BG,UAA7B,CADxB,GAEHR,WAAW,CAACI,MAAD,EAASC,OAAT,EAAkBG,UAAlB,CAFf;AAGD;;AAED,eAAeG,qBAAf,CAAqCP,MAArC,EAA6CK,SAA7C,EAAwDJ,OAAxD,EAAiEG,UAAjE,EAA6E;AAC3E,QAAMI,IAAc,GAAG,EAAvB;;AAGA,MAAIH,SAAS,KAAK,MAAlB,EAA0B;AACxB,UAAMI,GAAG,GAAGb,WAAW,CAACI,MAAD,EAASC,OAAT,EAAkB,EAAC,GAAGG,UAAJ;AAAgBM,MAAAA,GAAG,EAAE;AAArB,KAAlB,CAAvB;AACA,UAAMJ,KAAK,GAAG,MAAMR,WAAW,CAACW,GAAD,EAAMf,UAAN,EAAkBO,OAAlB,CAA/B;AAEA,UAAM;AAACU,MAAAA,KAAD;AAAQC,MAAAA;AAAR,QAAkBjB,YAAY,CAACW,KAAD,CAApC;AACAD,IAAAA,SAAS,GAAGQ,YAAY,CAAC;AAACF,MAAAA,KAAD;AAAQC,MAAAA;AAAR,KAAD,CAAxB;AAGAJ,IAAAA,IAAI,CAACM,IAAL,CAAUL,GAAV;AACD;;AAGDhB,EAAAA,MAAM,CAACY,SAAS,GAAG,CAAb,CAAN;;AAEA,OAAK,IAAIU,QAAQ,GAAGP,IAAI,CAACQ,MAAzB,EAAiCD,QAAQ,GAAGV,SAA5C,EAAuD,EAAEU,QAAzD,EAAmE;AACjE,UAAMN,GAAG,GAAGb,WAAW,CAACI,MAAD,EAASC,OAAT,EAAkB,EAAC,GAAGG,UAAJ;AAAgBM,MAAAA,GAAG,EAAEK;AAArB,KAAlB,CAAvB;AACAP,IAAAA,IAAI,CAACM,IAAL,CAAUL,GAAV;AACD;;AAED,SAAOD,IAAP;AACD;;AAGD,OAAO,SAASK,YAAT,CAAsB;AAACF,EAAAA,KAAD;AAAQC,EAAAA;AAAR,CAAtB,EAAuC;AAC5C,SAAO,IAAIK,IAAI,CAACC,KAAL,CAAWD,IAAI,CAACE,IAAL,CAAUF,IAAI,CAACG,GAAL,CAAST,KAAT,EAAgBC,MAAhB,CAAV,CAAX,CAAX;AACD","sourcesContent":["import {assert} from '@loaders.gl/loader-utils';\nimport parseImage from '../parsers/parse-image';\nimport {getImageSize} from '../category-api/parsed-image-api';\nimport {generateUrl} from './generate-url';\nimport {deepLoad, shallowLoad} from './deep-load';\n\nexport async function loadImage(getUrl, options = {}) {\n const imageUrls = await getImageUrls(getUrl, options);\n return await deepLoad(imageUrls, parseImage, options);\n}\n\nexport async function getImageUrls(getUrl, options, urlOptions = {}) {\n const mipLevels = (options && options.image && options.image.mipLevels) || 0;\n return mipLevels !== 0\n ? await getMipmappedImageUrls(getUrl, mipLevels, options, urlOptions)\n : generateUrl(getUrl, options, urlOptions);\n}\n\nasync function getMipmappedImageUrls(getUrl, mipLevels, options, urlOptions) {\n const urls: string[] = [];\n\n // If no mip levels supplied, we need to load the level 0 image and calculate based on size\n if (mipLevels === 'auto') {\n const url = generateUrl(getUrl, options, {...urlOptions, lod: 0});\n const image = await shallowLoad(url, parseImage, options);\n\n const {width, height} = getImageSize(image);\n mipLevels = getMipLevels({width, height});\n\n // TODO - push image and make `deepLoad` pass through non-url values, avoid loading twice?\n urls.push(url);\n }\n\n // We now know how many mipLevels we need, remaining image urls can now be constructed\n assert(mipLevels > 0);\n\n for (let mipLevel = urls.length; mipLevel < mipLevels; ++mipLevel) {\n const url = generateUrl(getUrl, options, {...urlOptions, lod: mipLevel});\n urls.push(url);\n }\n\n return urls;\n}\n\n// Calculates number of mipmaps based on texture size (log2)\nexport function getMipLevels({width, height}) {\n return 1 + Math.floor(Math.log2(Math.max(width, height)));\n}\n"],"file":"load-image.js"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/utils/version.ts"],"names":["VERSION"],"mappings":"AAGA,OAAO,MAAMA,OAAO,GAAG,2BAAuB,WAAvB,qBAAmD,QAAnE","sourcesContent":["// Version constant cannot be imported, it needs to correspond to the build version of **this** module.\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nexport const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n"],"file":"version.js"}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[],"file":"types.js"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { LoaderOptions, LoaderWithParser } from '@loaders.gl/loader-utils';
|
|
2
|
+
import parseImage from './lib/parsers/parse-image';
|
|
3
|
+
export declare type ImageLoaderOptions = LoaderOptions & {
|
|
4
|
+
image?: {
|
|
5
|
+
type?: 'auto' | 'data' | 'imagebitmap' | 'image';
|
|
6
|
+
decode?: boolean;
|
|
7
|
+
};
|
|
8
|
+
imagebitmap?: ImageBitmapOptions;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Loads a platform-specific image type
|
|
12
|
+
* Note: This type can be used as input data to WebGL texture creation
|
|
13
|
+
*/
|
|
14
|
+
export declare const ImageLoader: {
|
|
15
|
+
id: string;
|
|
16
|
+
module: string;
|
|
17
|
+
name: string;
|
|
18
|
+
version: any;
|
|
19
|
+
mimeTypes: string[];
|
|
20
|
+
extensions: string[];
|
|
21
|
+
parse: typeof parseImage;
|
|
22
|
+
tests: ((arrayBuffer: any) => boolean)[];
|
|
23
|
+
options: ImageLoaderOptions;
|
|
24
|
+
};
|
|
25
|
+
export declare const _typecheckImageLoader: LoaderWithParser;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { encodeImage } from './lib/encoders/encode-image';
|
|
2
|
+
export declare const ImageWriter: {
|
|
3
|
+
name: string;
|
|
4
|
+
id: string;
|
|
5
|
+
module: string;
|
|
6
|
+
version: any;
|
|
7
|
+
extensions: string[];
|
|
8
|
+
options: {
|
|
9
|
+
image: {
|
|
10
|
+
mimeType: string;
|
|
11
|
+
jpegQuality: null;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
encode: typeof encodeImage;
|
|
15
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type { ImageDataType, ImageType, ImageTypeEnum } from './types';
|
|
2
|
+
export type { ImageLoaderOptions } from './image-loader';
|
|
3
|
+
export { ImageLoader } from './image-loader';
|
|
4
|
+
export { ImageWriter } from './image-writer';
|
|
5
|
+
export { getBinaryImageMetadata } from './lib/category-api/binary-image-api';
|
|
6
|
+
export { isImageTypeSupported, getDefaultImageType } from './lib/category-api/image-type';
|
|
7
|
+
export { isImage, getImageType, getImageSize, getImageData } from './lib/category-api/parsed-image-api';
|
|
8
|
+
export { _isImageFormatSupported } from './lib/category-api/image-format';
|
|
9
|
+
export { loadImage } from './lib/texture-api/load-image';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** MIME type, width and height extracted from binary compressed image data */
|
|
2
|
+
export declare type BinaryImageMetadata = {
|
|
3
|
+
mimeType: string;
|
|
4
|
+
width: number;
|
|
5
|
+
height: number;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Extracts `{mimeType, width and height}` from a memory buffer containing a known image format
|
|
9
|
+
* Currently supports `image/png`, `image/jpeg`, `image/bmp` and `image/gif`.
|
|
10
|
+
* @param binaryData image file memory to parse
|
|
11
|
+
* @returns metadata or null if memory is not a valid image file format layout.
|
|
12
|
+
*/
|
|
13
|
+
export declare function getBinaryImageMetadata(binaryData: DataView | ArrayBuffer): BinaryImageMetadata | null;
|
|
14
|
+
export declare function getBmpMetadata(binaryData: any): {
|
|
15
|
+
mimeType: string;
|
|
16
|
+
width: number;
|
|
17
|
+
height: number;
|
|
18
|
+
} | null;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ImageTypeEnum } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* Checks if a loaders.gl image type is supported
|
|
4
|
+
* @param type image type string
|
|
5
|
+
*/
|
|
6
|
+
export declare function isImageTypeSupported(type: string): boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Returns the "most performant" supported image type on this platform
|
|
9
|
+
* @returns image type string
|
|
10
|
+
*/
|
|
11
|
+
export declare function getDefaultImageType(): ImageTypeEnum;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ImageType, ImageTypeEnum, ImageDataType } from '../../types';
|
|
2
|
+
export declare function isImage(image: ImageType): boolean;
|
|
3
|
+
export declare function deleteImage(image: ImageType): void;
|
|
4
|
+
export declare function getImageType(image: ImageType): ImageTypeEnum;
|
|
5
|
+
export declare function getImageSize(image: ImageType): {
|
|
6
|
+
width: number;
|
|
7
|
+
height: number;
|
|
8
|
+
};
|
|
9
|
+
export declare function getImageData(image: ImageType): ImageDataType | ImageData;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns data bytes representing a compressed image in PNG or JPG format,
|
|
3
|
+
* This data can be saved using file system (f) methods or used in a request.
|
|
4
|
+
* @param image - ImageBitmap Image or Canvas
|
|
5
|
+
* @param options
|
|
6
|
+
* param opt.type='png' - png, jpg or image/png, image/jpg are valid
|
|
7
|
+
* param mimeType= - Whether to include a data URI header
|
|
8
|
+
*/
|
|
9
|
+
export declare function encodeImage(image: any, options?: {
|
|
10
|
+
[key: string]: any;
|
|
11
|
+
}): Promise<ArrayBuffer>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { LoaderContext } from '@loaders.gl/loader-utils';
|
|
2
|
+
import type { ImageType } from '../../types';
|
|
3
|
+
import type { ImageLoaderOptions } from '../../image-loader';
|
|
4
|
+
export default function parseImage(arrayBuffer: ArrayBuffer, options?: ImageLoaderOptions, context?: LoaderContext): Promise<ImageType>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ImageLoaderOptions } from '../../image-loader';
|
|
2
|
+
/**
|
|
3
|
+
* Asynchronously parses an array buffer into an ImageBitmap - this contains the decoded data
|
|
4
|
+
* ImageBitmaps are supported on worker threads, but not supported on Edge, IE11 and Safari
|
|
5
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/ImageBitmap#Browser_compatibility
|
|
6
|
+
*
|
|
7
|
+
* TODO - createImageBitmap supports source rect (5 param overload), pass through?
|
|
8
|
+
*/
|
|
9
|
+
export default function parseToImageBitmap(arrayBuffer: ArrayBuffer, options: ImageLoaderOptions, url?: string): Promise<ImageBitmap>;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { ImageLoaderOptions } from '../../image-loader';
|
|
2
|
+
export default function parseToImage(arrayBuffer: ArrayBuffer, options: ImageLoaderOptions, url?: string): Promise<HTMLImageElement>;
|
|
3
|
+
export declare function loadToImage(url: any, options: any): Promise<HTMLImageElement>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function generateUrl(getUrl: any, options: any, urlOptions: any): string;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function loadImage(getUrl: any, options?: {}): Promise<any>;
|
|
2
|
+
export declare function getImageUrls(getUrl: any, options: any, urlOptions?: {}): Promise<string | string[]>;
|
|
3
|
+
export declare function getMipLevels({ width, height }: {
|
|
4
|
+
width: any;
|
|
5
|
+
height: any;
|
|
6
|
+
}): number;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const VERSION: any;
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* data images
|
|
3
|
+
*/
|
|
4
|
+
export declare type ImageDataType = {
|
|
5
|
+
data: Uint8Array;
|
|
6
|
+
width: number;
|
|
7
|
+
height: number;
|
|
8
|
+
compressed?: boolean;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Supported Image Types
|
|
12
|
+
*/
|
|
13
|
+
export declare type ImageType = ImageBitmap | typeof Image | ImageDataType;
|
|
14
|
+
/**
|
|
15
|
+
* Image type string used to control or determine the type of images returned from ImageLoader
|
|
16
|
+
*/
|
|
17
|
+
export declare type ImageTypeEnum = 'imagebitmap' | 'image' | 'data';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/images",
|
|
3
|
-
"version": "3.1.0-alpha.
|
|
3
|
+
"version": "3.1.0-alpha.5",
|
|
4
4
|
"description": "Framework-independent loaders and writers for images (PNG, JPG, ...)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -18,9 +18,9 @@
|
|
|
18
18
|
"point cloud",
|
|
19
19
|
"PLY"
|
|
20
20
|
],
|
|
21
|
-
"types": "
|
|
22
|
-
"main": "dist/index.js",
|
|
23
|
-
"module": "dist/index.js",
|
|
21
|
+
"types": "dist/index.d.ts",
|
|
22
|
+
"main": "dist/es5/index.js",
|
|
23
|
+
"module": "dist/esm/index.js",
|
|
24
24
|
"sideEffects": false,
|
|
25
25
|
"files": [
|
|
26
26
|
"src",
|
|
@@ -29,11 +29,12 @@
|
|
|
29
29
|
],
|
|
30
30
|
"scripts": {
|
|
31
31
|
"pre-build": "npm run build-bundle",
|
|
32
|
+
"post-build": "tsc",
|
|
32
33
|
"build-bundle": "webpack --display=minimal --config ../../scripts/webpack/bundle.js",
|
|
33
34
|
"build-worker": "webpack --entry ./src/image-worker.js --output ./dist/image-worker.js --config ../../scripts/webpack/worker.js"
|
|
34
35
|
},
|
|
35
36
|
"dependencies": {
|
|
36
|
-
"@loaders.gl/loader-utils": "3.1.0-alpha.
|
|
37
|
+
"@loaders.gl/loader-utils": "3.1.0-alpha.5"
|
|
37
38
|
},
|
|
38
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "352241dd910a8c6307a235dadbe154ca915b885b"
|
|
39
40
|
}
|
package/src/bundle.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
// @ts-nocheck
|
|
2
2
|
const moduleExports = require('./index');
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
module.exports = Object.assign(_global.loaders, moduleExports);
|
|
3
|
+
globalThis.loaders = globalThis.loaders || {};
|
|
4
|
+
module.exports = Object.assign(globalThis.loaders, moduleExports);
|
package/src/image-loader.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {LoaderWithParser} from '@loaders.gl/loader-utils';
|
|
1
|
+
import type {LoaderOptions, LoaderWithParser} from '@loaders.gl/loader-utils';
|
|
2
2
|
import {VERSION} from './lib/utils/version';
|
|
3
3
|
import parseImage from './lib/parsers/parse-image';
|
|
4
4
|
import {getBinaryImageMetadata} from './lib/category-api/binary-image-api';
|
|
@@ -14,6 +14,22 @@ const MIME_TYPES = [
|
|
|
14
14
|
'image/svg+xml'
|
|
15
15
|
];
|
|
16
16
|
|
|
17
|
+
export type ImageLoaderOptions = LoaderOptions & {
|
|
18
|
+
image?: {
|
|
19
|
+
type?: 'auto' | 'data' | 'imagebitmap' | 'image';
|
|
20
|
+
decode?: boolean;
|
|
21
|
+
};
|
|
22
|
+
imagebitmap?: ImageBitmapOptions;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const DEFAULT_IMAGE_LOADER_OPTIONS: ImageLoaderOptions = {
|
|
26
|
+
image: {
|
|
27
|
+
type: 'auto',
|
|
28
|
+
decode: true // if format is HTML
|
|
29
|
+
}
|
|
30
|
+
// imagebitmap: {} - passes (platform dependent) parameters to ImageBitmap constructor
|
|
31
|
+
};
|
|
32
|
+
|
|
17
33
|
/**
|
|
18
34
|
* Loads a platform-specific image type
|
|
19
35
|
* Note: This type can be used as input data to WebGL texture creation
|
|
@@ -28,13 +44,7 @@ export const ImageLoader = {
|
|
|
28
44
|
parse: parseImage,
|
|
29
45
|
// TODO: byteOffset, byteLength;
|
|
30
46
|
tests: [(arrayBuffer) => Boolean(getBinaryImageMetadata(new DataView(arrayBuffer)))],
|
|
31
|
-
options:
|
|
32
|
-
image: {
|
|
33
|
-
type: 'auto',
|
|
34
|
-
decode: true // if format is HTML
|
|
35
|
-
}
|
|
36
|
-
// imagebitmap: {} - passes (platform dependent) parameters to ImageBitmap constructor
|
|
37
|
-
}
|
|
47
|
+
options: DEFAULT_IMAGE_LOADER_OPTIONS
|
|
38
48
|
};
|
|
39
49
|
|
|
40
50
|
export const _typecheckImageLoader: LoaderWithParser = ImageLoader;
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// TYPES
|
|
2
2
|
export type {ImageDataType, ImageType, ImageTypeEnum} from './types';
|
|
3
|
+
export type {ImageLoaderOptions} from './image-loader';
|
|
3
4
|
|
|
4
5
|
// LOADERS AND WRITERS
|
|
5
6
|
export {ImageLoader} from './image-loader';
|
|
@@ -20,5 +21,8 @@ export {
|
|
|
20
21
|
getImageData
|
|
21
22
|
} from './lib/category-api/parsed-image-api';
|
|
22
23
|
|
|
24
|
+
// EXPERIMENTAL
|
|
25
|
+
export {_isImageFormatSupported} from './lib/category-api/image-format';
|
|
26
|
+
|
|
23
27
|
// DEPRECATED - Remove in V3 (fix dependency in luma.gl)
|
|
24
28
|
export {loadImage} from './lib/texture-api/load-image';
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import {isBrowser} from '@loaders.gl/loader-utils';
|
|
2
|
+
|
|
3
|
+
// The following formats are supported by loaders.gl polyfills
|
|
4
|
+
const NODE_FORMAT_SUPPORT = ['image/png', 'image/jpeg', 'image/gif'];
|
|
5
|
+
|
|
6
|
+
/** Cache values for speed */
|
|
7
|
+
const mimeTypeSupported: {[mimeType: string]: boolean} = {};
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Check if image MIME type is supported. Result is cached.
|
|
11
|
+
*/
|
|
12
|
+
export function _isImageFormatSupported(mimeType: string): boolean {
|
|
13
|
+
if (mimeTypeSupported[mimeType] === undefined) {
|
|
14
|
+
mimeTypeSupported[mimeType] = checkFormatSupport(mimeType);
|
|
15
|
+
}
|
|
16
|
+
return mimeTypeSupported[mimeType];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Check if image MIME type is supported.
|
|
21
|
+
*/
|
|
22
|
+
function checkFormatSupport(mimeType: string): boolean {
|
|
23
|
+
switch (mimeType) {
|
|
24
|
+
case 'image/webp':
|
|
25
|
+
return checkWebPSupport();
|
|
26
|
+
case 'image/svg':
|
|
27
|
+
return isBrowser;
|
|
28
|
+
default:
|
|
29
|
+
if (!isBrowser) {
|
|
30
|
+
// @ts-ignore
|
|
31
|
+
const {_parseImageNode} = globalThis;
|
|
32
|
+
return Boolean(_parseImageNode) && NODE_FORMAT_SUPPORT.includes(mimeType);
|
|
33
|
+
}
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Check WebPSupport synchronously */
|
|
39
|
+
function checkWebPSupport() {
|
|
40
|
+
if (!isBrowser) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
const element = document.createElement('canvas');
|
|
45
|
+
return element.toDataURL('image/webp').indexOf('data:image/webp') === 0;
|
|
46
|
+
} catch {
|
|
47
|
+
// Probably Safari...
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Note: better test but asynchronous
|
|
53
|
+
|
|
54
|
+
// Lossy test image. Support for lossy images doesn't guarantee support for all WebP images.
|
|
55
|
+
// https://stackoverflow.com/questions/5573096/detecting-webp-support
|
|
56
|
+
// const WEBP_TEST_IMAGE = 'data:image/webp;base64,UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA';
|
|
57
|
+
|
|
58
|
+
// Check WebPSupport asynchronously
|
|
59
|
+
// async function isWebPSupported() {
|
|
60
|
+
// return new Promise( resolve => {
|
|
61
|
+
// const image = new Image();
|
|
62
|
+
// image.src = WEBP_TEST_IMAGE;
|
|
63
|
+
// image.onload = image.onerror = function () {
|
|
64
|
+
// resolve( image.height === 1 );
|
|
65
|
+
// }
|
|
66
|
+
// }
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import {isBrowser} from '@loaders.gl/loader-utils';
|
|
1
2
|
import type {ImageTypeEnum} from '../../types';
|
|
2
|
-
import {global, isBrowser} from '../utils/globals';
|
|
3
3
|
|
|
4
4
|
// @ts-ignore TS2339: Property does not exist on type
|
|
5
|
-
const {_parseImageNode} =
|
|
5
|
+
const {_parseImageNode} = globalThis;
|
|
6
6
|
|
|
7
7
|
const IMAGE_SUPPORTED = typeof Image !== 'undefined'; // NOTE: "false" positives if jsdom is installed
|
|
8
8
|
const IMAGE_BITMAP_SUPPORTED = typeof ImageBitmap !== 'undefined';
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
// Image loading/saving for browser and Node.js
|
|
2
|
-
import {global} from '../utils/globals';
|
|
3
2
|
import {getImageSize} from '../category-api/parsed-image-api';
|
|
4
3
|
|
|
5
4
|
// @ts-ignore TS2339: Property does not exist on type
|
|
6
|
-
const {_encodeImageNode} =
|
|
5
|
+
const {_encodeImageNode} = globalThis;
|
|
7
6
|
|
|
8
7
|
/**
|
|
9
8
|
* Returns data bytes representing a compressed image in PNG or JPG format,
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {LoaderContext} from '@loaders.gl/loader-utils';
|
|
2
|
+
import {assert} from '@loaders.gl/loader-utils';
|
|
3
|
+
import type {ImageType} from '../../types';
|
|
4
|
+
import type {ImageLoaderOptions} from '../../image-loader';
|
|
2
5
|
import {isImageTypeSupported, getDefaultImageType} from '../category-api/image-type';
|
|
3
6
|
import {getImageData} from '../category-api/parsed-image-api';
|
|
4
7
|
import parseToImage from './parse-to-image';
|
|
@@ -7,7 +10,11 @@ import parseToNodeImage from './parse-to-node-image';
|
|
|
7
10
|
|
|
8
11
|
// Parse to platform defined image type (data on node, ImageBitmap or HTMLImage on browser)
|
|
9
12
|
// eslint-disable-next-line complexity
|
|
10
|
-
export default async function parseImage(
|
|
13
|
+
export default async function parseImage(
|
|
14
|
+
arrayBuffer: ArrayBuffer,
|
|
15
|
+
options?: ImageLoaderOptions,
|
|
16
|
+
context?: LoaderContext
|
|
17
|
+
): Promise<ImageType> {
|
|
11
18
|
options = options || {};
|
|
12
19
|
const imageOptions = options.image || {};
|
|
13
20
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type {ImageLoaderOptions} from '../../image-loader';
|
|
1
2
|
import {isSVG, getBlob} from './svg-utils';
|
|
2
3
|
import parseToImage from './parse-to-image';
|
|
3
4
|
|
|
@@ -12,7 +13,11 @@ let imagebitmapOptionsSupported = true;
|
|
|
12
13
|
*
|
|
13
14
|
* TODO - createImageBitmap supports source rect (5 param overload), pass through?
|
|
14
15
|
*/
|
|
15
|
-
export default async function parseToImageBitmap(
|
|
16
|
+
export default async function parseToImageBitmap(
|
|
17
|
+
arrayBuffer: ArrayBuffer,
|
|
18
|
+
options: ImageLoaderOptions,
|
|
19
|
+
url?: string
|
|
20
|
+
): Promise<ImageBitmap> {
|
|
16
21
|
let blob;
|
|
17
22
|
|
|
18
23
|
// Cannot parse SVG directly to ImageBitmap, parse to Image first
|
|
@@ -36,7 +41,10 @@ export default async function parseToImageBitmap(arrayBuffer, options, url) {
|
|
|
36
41
|
* Firefox crashes if imagebitmapOptions is supplied
|
|
37
42
|
* Avoid supplying if not provided or supported, remember if not supported
|
|
38
43
|
*/
|
|
39
|
-
async function safeCreateImageBitmap(
|
|
44
|
+
async function safeCreateImageBitmap(
|
|
45
|
+
blob: Blob,
|
|
46
|
+
imagebitmapOptions: ImageBitmapOptions | null = null
|
|
47
|
+
): Promise<ImageBitmap> {
|
|
40
48
|
if (isEmptyObject(imagebitmapOptions) || !imagebitmapOptionsSupported) {
|
|
41
49
|
imagebitmapOptions = null;
|
|
42
50
|
}
|
|
@@ -1,7 +1,12 @@
|
|
|
1
|
+
import type {ImageLoaderOptions} from '../../image-loader';
|
|
1
2
|
import {getBlobOrSVGDataUrl} from './svg-utils';
|
|
2
3
|
|
|
3
4
|
// Parses html image from array buffer
|
|
4
|
-
export default async function parseToImage(
|
|
5
|
+
export default async function parseToImage(
|
|
6
|
+
arrayBuffer: ArrayBuffer,
|
|
7
|
+
options: ImageLoaderOptions,
|
|
8
|
+
url?: string
|
|
9
|
+
): Promise<HTMLImageElement> {
|
|
5
10
|
// Note: image parsing requires conversion to Blob (for createObjectURL).
|
|
6
11
|
// Potentially inefficient for not using `response.blob()` (and for File / Blob inputs)...
|
|
7
12
|
// But presumably not worth adding 'blob' flag to loader objects?
|
|
@@ -18,7 +23,7 @@ export default async function parseToImage(arrayBuffer, options, url) {
|
|
|
18
23
|
}
|
|
19
24
|
}
|
|
20
25
|
|
|
21
|
-
export async function loadToImage(url, options) {
|
|
26
|
+
export async function loadToImage(url, options): Promise<HTMLImageElement> {
|
|
22
27
|
const image = new Image();
|
|
23
28
|
image.src = url;
|
|
24
29
|
|
|
@@ -1,14 +1,32 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type {ImageLoaderOptions} from '../../image-loader';
|
|
2
|
+
import type {ImageDataType} from '../../types';
|
|
3
|
+
import {assert} from '@loaders.gl/loader-utils';
|
|
3
4
|
import {getBinaryImageMetadata} from '../category-api/binary-image-api';
|
|
4
5
|
|
|
5
|
-
//
|
|
6
|
-
|
|
6
|
+
// Note: These types should be consistent with loaders.gl/polyfills
|
|
7
|
+
|
|
8
|
+
type NDArray = {
|
|
9
|
+
shape: number[];
|
|
10
|
+
data: Uint8Array;
|
|
11
|
+
width: number;
|
|
12
|
+
height: number;
|
|
13
|
+
components: number;
|
|
14
|
+
layers: number[];
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
type ParseImageNode = (arrayBuffer: ArrayBuffer, mimeType: string) => Promise<NDArray>;
|
|
18
|
+
|
|
19
|
+
// Use polyfills if installed to parsed image using get-pixels
|
|
20
|
+
export default async function parseToNodeImage(
|
|
21
|
+
arrayBuffer: ArrayBuffer,
|
|
22
|
+
options: ImageLoaderOptions
|
|
23
|
+
): Promise<ImageDataType> {
|
|
7
24
|
const {mimeType} = getBinaryImageMetadata(arrayBuffer) || {};
|
|
8
25
|
|
|
9
26
|
// @ts-ignore
|
|
10
|
-
const
|
|
27
|
+
const _parseImageNode: ParseImageNode = globalThis._parseImageNode;
|
|
11
28
|
assert(_parseImageNode); // '@loaders.gl/polyfills not installed'
|
|
12
29
|
|
|
13
|
-
|
|
30
|
+
// @ts-expect-error TODO should we throw error in this case?
|
|
31
|
+
return await _parseImageNode(arrayBuffer, mimeType);
|
|
14
32
|
}
|
|
@@ -8,7 +8,7 @@ export function isSVG(url) {
|
|
|
8
8
|
return url && (SVG_DATA_URL_PATTERN.test(url) || SVG_URL_PATTERN.test(url));
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
export function getBlobOrSVGDataUrl(arrayBuffer, url) {
|
|
11
|
+
export function getBlobOrSVGDataUrl(arrayBuffer: ArrayBuffer, url?: string): Blob | string {
|
|
12
12
|
if (isSVG(url)) {
|
|
13
13
|
// Prepare a properly tagged data URL, and load using normal mechanism
|
|
14
14
|
const textDecoder = new TextDecoder();
|
|
@@ -28,7 +28,7 @@ export function getBlobOrSVGDataUrl(arrayBuffer, url) {
|
|
|
28
28
|
return getBlob(arrayBuffer, url);
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
export function getBlob(arrayBuffer, url) {
|
|
31
|
+
export function getBlob(arrayBuffer: ArrayBuffer, url?: string): Blob {
|
|
32
32
|
if (isSVG(url)) {
|
|
33
33
|
// https://bugs.chromium.org/p/chromium/issues/detail?id=606319
|
|
34
34
|
// return new Blob([new Uint8Array(arrayBuffer)], {type: 'image/svg+xml'});
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {resolvePath} from '@loaders.gl/loader-utils';
|
|
2
|
-
import {assert} from '../utils/assert';
|
|
1
|
+
import {resolvePath, assert} from '@loaders.gl/loader-utils';
|
|
3
2
|
|
|
4
3
|
// Generate a url by calling getUrl with mix of options, applying options.baseUrl
|
|
5
4
|
export function generateUrl(getUrl, options, urlOptions) {
|