anyfile-cli 0.0.0-stage → 0.2.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.
Files changed (355) hide show
  1. package/LICENSE +177 -0
  2. package/README.md +56 -2
  3. package/SKILL.md +101 -0
  4. package/chunks/browser-probe-5STDX455.mjs +17 -0
  5. package/chunks/browser-probe-F5RX44T3.mjs +24 -0
  6. package/chunks/chunk-2C34VMNV.mjs +108 -0
  7. package/chunks/chunk-3OZ56PUH.mjs +97 -0
  8. package/chunks/chunk-3YRWCQGV.mjs +38 -0
  9. package/chunks/chunk-53MJMIN4.mjs +23 -0
  10. package/chunks/chunk-5LOC7IST.mjs +372 -0
  11. package/chunks/chunk-5OI4NQH7.mjs +2232 -0
  12. package/chunks/chunk-5XTYLZF3.mjs +559 -0
  13. package/chunks/chunk-5ZHDYRGV.mjs +64 -0
  14. package/chunks/chunk-6CQL4K2K.mjs +21 -0
  15. package/chunks/chunk-6EVJJFOH.mjs +243 -0
  16. package/chunks/chunk-6NWSQGYE.mjs +68 -0
  17. package/chunks/chunk-7O5JLQE7.mjs +1 -0
  18. package/chunks/chunk-A6AQI6DF.mjs +321 -0
  19. package/chunks/chunk-AYF63UBE.mjs +79 -0
  20. package/chunks/chunk-B27PR6Q4.mjs +17 -0
  21. package/chunks/chunk-BP7LORL4.mjs +13 -0
  22. package/chunks/chunk-BVCRJLCD.mjs +109 -0
  23. package/chunks/chunk-CLSEE3VA.mjs +28 -0
  24. package/chunks/chunk-CO2ZAQIK.mjs +52 -0
  25. package/chunks/chunk-CQWM5GMU.mjs +167 -0
  26. package/chunks/chunk-CZFFYCMJ.mjs +136 -0
  27. package/chunks/chunk-D3CS6TIK.mjs +419 -0
  28. package/chunks/chunk-DJLFVMDJ.mjs +807 -0
  29. package/chunks/chunk-DJXVCKIO.mjs +30 -0
  30. package/chunks/chunk-EMXODK3K.mjs +94 -0
  31. package/chunks/chunk-EOJ7ZCDK.mjs +227 -0
  32. package/chunks/chunk-H4TBN22D.mjs +100 -0
  33. package/chunks/chunk-HUSX3ZU3.mjs +58 -0
  34. package/chunks/chunk-IC3G2XE2.mjs +436 -0
  35. package/chunks/chunk-IZGTVZHE.mjs +90 -0
  36. package/chunks/chunk-J4G7LUPA.mjs +117 -0
  37. package/chunks/chunk-JBAJW66L.mjs +4220 -0
  38. package/chunks/chunk-JKQUF2MM.mjs +438 -0
  39. package/chunks/chunk-KAMPC5TK.mjs +131 -0
  40. package/chunks/chunk-KSKEMJVC.mjs +145 -0
  41. package/chunks/chunk-LRHHRZLE.mjs +29 -0
  42. package/chunks/chunk-M37ZOAUG.mjs +93 -0
  43. package/chunks/chunk-MG7LUDXO.mjs +187 -0
  44. package/chunks/chunk-NGVHHTQD.mjs +125 -0
  45. package/chunks/chunk-NQ7J2NH6.mjs +50 -0
  46. package/chunks/chunk-NUMNHVSI.mjs +60 -0
  47. package/chunks/chunk-ORJ3DN65.mjs +58 -0
  48. package/chunks/chunk-QOUEBPPL.mjs +15 -0
  49. package/chunks/chunk-QR3Y3UKM.mjs +194 -0
  50. package/chunks/chunk-RFKYE7SE.mjs +50 -0
  51. package/chunks/chunk-SH57XOAV.mjs +33 -0
  52. package/chunks/chunk-TB5ISPA4.mjs +1 -0
  53. package/chunks/chunk-UGAU3V4V.mjs +206 -0
  54. package/chunks/chunk-UUN2DVDC.mjs +1893 -0
  55. package/chunks/chunk-WDN6NMVU.mjs +36 -0
  56. package/chunks/chunk-WWTLSPEG.mjs +3999 -0
  57. package/chunks/chunk-XDW56XVX.mjs +69 -0
  58. package/chunks/chunk-XRT7TAAY.mjs +27 -0
  59. package/chunks/chunk-XTW4HNIJ.mjs +418 -0
  60. package/chunks/chunk-YPLWNGCC.mjs +17 -0
  61. package/chunks/chunk-ZBR7RQQE.mjs +64 -0
  62. package/chunks/chunk-ZUHJIGHP.mjs +300 -0
  63. package/chunks/deflate-IINN6MRE.mjs +19 -0
  64. package/chunks/jpeg-N3DSYEAQ.mjs +964 -0
  65. package/chunks/jxl_oxide_wasm-3UN6G3YN.mjs +589 -0
  66. package/chunks/lerc-5LP7Q554.mjs +2086 -0
  67. package/chunks/lzw-Z2ZZBEWD.mjs +137 -0
  68. package/chunks/packbits-3S2JASDB.mjs +34 -0
  69. package/chunks/pdf.worker-PUGU2NS2.mjs +67416 -0
  70. package/chunks/probe-22WNVZ3I.mjs +17 -0
  71. package/chunks/probe-2P4CTFCY.mjs +14 -0
  72. package/chunks/probe-2QBNDPYK.mjs +18 -0
  73. package/chunks/probe-34TOVXUI.mjs +11 -0
  74. package/chunks/probe-3W2HOWBM.mjs +20 -0
  75. package/chunks/probe-42OBMD35.mjs +23 -0
  76. package/chunks/probe-43RVHUBG.mjs +17 -0
  77. package/chunks/probe-4O362IEX.mjs +18 -0
  78. package/chunks/probe-4WF34ZXS.mjs +11 -0
  79. package/chunks/probe-5ZITS3T5.mjs +40 -0
  80. package/chunks/probe-5ZS5DHFP.mjs +21 -0
  81. package/chunks/probe-62RFYKCP.mjs +14 -0
  82. package/chunks/probe-64JTFRH4.mjs +41 -0
  83. package/chunks/probe-6YJQJJ3R.mjs +518 -0
  84. package/chunks/probe-6YMOOV53.mjs +39 -0
  85. package/chunks/probe-BYBD2WAK.mjs +239 -0
  86. package/chunks/probe-CZZNJOHV.mjs +20 -0
  87. package/chunks/probe-DJMPK6HU.mjs +11 -0
  88. package/chunks/probe-FMWIF4LX.mjs +33 -0
  89. package/chunks/probe-FYPH6CYY.mjs +206 -0
  90. package/chunks/probe-G6PPXKBE.mjs +15 -0
  91. package/chunks/probe-GJ5OUOQ3.mjs +32 -0
  92. package/chunks/probe-H6J7TUY2.mjs +95 -0
  93. package/chunks/probe-IGZ47OE3.mjs +68 -0
  94. package/chunks/probe-IL5HO3OK.mjs +46 -0
  95. package/chunks/probe-INYCDZHO.mjs +27 -0
  96. package/chunks/probe-JFH545GO.mjs +11 -0
  97. package/chunks/probe-JZYDRITV.mjs +18 -0
  98. package/chunks/probe-K3WW5O5K.mjs +26 -0
  99. package/chunks/probe-KB4T466L.mjs +70 -0
  100. package/chunks/probe-KY7SIIXD.mjs +13 -0
  101. package/chunks/probe-L2P263WT.mjs +16 -0
  102. package/chunks/probe-LEP3RQPD.mjs +11 -0
  103. package/chunks/probe-M2QWULOI.mjs +119 -0
  104. package/chunks/probe-M7AYZBD3.mjs +35 -0
  105. package/chunks/probe-MEN3BMBB.mjs +22 -0
  106. package/chunks/probe-MNIGKDWT.mjs +163 -0
  107. package/chunks/probe-NFVFWB4M.mjs +56 -0
  108. package/chunks/probe-NJGSTL6R.mjs +161 -0
  109. package/chunks/probe-O73EHWT3.mjs +14 -0
  110. package/chunks/probe-OG2XYCG2.mjs +25 -0
  111. package/chunks/probe-OTKJKTNS.mjs +10 -0
  112. package/chunks/probe-OZKO3C2V.mjs +27 -0
  113. package/chunks/probe-PBL4KITG.mjs +12 -0
  114. package/chunks/probe-PEFZNH2T.mjs +21 -0
  115. package/chunks/probe-R4SSEXES.mjs +27 -0
  116. package/chunks/probe-RCAUVV27.mjs +29 -0
  117. package/chunks/probe-RPGBKGPI.mjs +20 -0
  118. package/chunks/probe-S2I46SEO.mjs +10 -0
  119. package/chunks/probe-SGDD4U4Q.mjs +165 -0
  120. package/chunks/probe-SPQO5LHI.mjs +9 -0
  121. package/chunks/probe-TBR6UGRZ.mjs +19 -0
  122. package/chunks/probe-TNKNILAW.mjs +21 -0
  123. package/chunks/probe-TVRJBPXH.mjs +48 -0
  124. package/chunks/probe-UESMTUQ5.mjs +33 -0
  125. package/chunks/probe-VDXFEZ5Q.mjs +16 -0
  126. package/chunks/probe-VX7JCDW6.mjs +39 -0
  127. package/chunks/probe-W7M55OPE.mjs +64 -0
  128. package/chunks/probe-XUBTIWGE.mjs +13 -0
  129. package/chunks/probe-ZF7KIRHO.mjs +36 -0
  130. package/chunks/raw-JJRPYAXO.mjs +16 -0
  131. package/chunks/tiff-metadata-7MWLNVW2.mjs +2990 -0
  132. package/chunks/webimage-D6XSCCTJ.mjs +56 -0
  133. package/chunks/zip-reader-YUGANW4Z.mjs +92 -0
  134. package/chunks/zstd-AH2S24PU.mjs +121 -0
  135. package/cli-main.mjs +278 -0
  136. package/cli.mjs +3 -0
  137. package/extractors/apple-plist.mjs +145 -0
  138. package/extractors/archive-metadata-viewer.mjs +1401 -0
  139. package/extractors/bittorrent-metadata.mjs +369 -0
  140. package/extractors/calendar-contacts.mjs +328 -0
  141. package/extractors/camera-raw.mjs +201 -0
  142. package/extractors/chm-reader.mjs +1842 -0
  143. package/extractors/comic-book-reader.mjs +307 -0
  144. package/extractors/design-source.mjs +1801 -0
  145. package/extractors/dev-array-viewer.mjs +825 -0
  146. package/extractors/dev-native-binary-viewer.mjs +1661 -0
  147. package/extractors/dev-source-map-viewer.mjs +416 -0
  148. package/extractors/dev-wasm-viewer.mjs +506 -0
  149. package/extractors/dicom.mjs +383 -0
  150. package/extractors/djvu-reader.mjs +337 -0
  151. package/extractors/duckdb-data.mjs +49174 -0
  152. package/extractors/epub-reader.mjs +222 -0
  153. package/extractors/excel-workbook.mjs +27057 -0
  154. package/extractors/fictionbook-reader.mjs +362 -0
  155. package/extractors/font-viewer.mjs +441 -0
  156. package/extractors/general-raster.mjs +444 -0
  157. package/extractors/hdr-image.mjs +1685 -0
  158. package/extractors/http-archive.mjs +306 -0
  159. package/extractors/ifc.mjs +341 -0
  160. package/extractors/iwork.mjs +640 -0
  161. package/extractors/microsoft-project.mjs +174 -0
  162. package/extractors/mind-map.mjs +607 -0
  163. package/extractors/ml-weights.mjs +649 -0
  164. package/extractors/modern-raster.mjs +620 -0
  165. package/extractors/ofd-reader.mjs +973 -0
  166. package/extractors/outlook-pst.mjs +997 -0
  167. package/extractors/pdfjs-pdf.mjs +32056 -0
  168. package/extractors/photoshop-document.mjs +17448 -0
  169. package/extractors/safe-svg.mjs +163 -0
  170. package/extractors/scientific-data.mjs +2041 -0
  171. package/extractors/sqlite-database.mjs +333 -0
  172. package/extractors/statistical-data.mjs +297 -0
  173. package/extractors/visio.mjs +141 -0
  174. package/extractors/x509-certificate.mjs +588 -0
  175. package/extractors/xps-reader.mjs +896 -0
  176. package/index.mjs +83 -0
  177. package/licenses/dicom-parser/1.8.21/LICENSE +21 -0
  178. package/licenses/libraw-wasm/1.6.0/COPYRIGHT.LibRaw +27 -0
  179. package/licenses/libraw-wasm/1.6.0/LICENSE.Emscripten +102 -0
  180. package/licenses/libraw-wasm/1.6.0/LICENSE.LibRaw-CDDL-1.0 +340 -0
  181. package/licenses/libraw-wasm/1.6.0/LICENSE.Little-CMS-MIT +22 -0
  182. package/licenses/libraw-wasm/1.6.0/LICENSE.libpng +134 -0
  183. package/licenses/libraw-wasm/1.6.0/LICENSE.libraw-wasm-ISC +15 -0
  184. package/licenses/libraw-wasm/1.6.0/LICENSE.zlib +22 -0
  185. package/licenses/libraw-wasm/1.6.0/NOTICE.IJG-libjpeg +49 -0
  186. package/licenses/libraw-wasm/1.6.0/SOURCE.md +25 -0
  187. package/licenses/libraw-wasm/1.6.0/THIRD_PARTY_NOTICES.md +14 -0
  188. package/licenses/mediabunny/1.55.3/MPL-2.0.txt +373 -0
  189. package/licenses/mediabunny/1.55.3/SOURCE.md +16 -0
  190. package/licenses/openskp/1.3.0/LICENSE +21 -0
  191. package/package.json +33 -3
  192. package/renderer-host/assets/ColladaComposer-TCm9fgZa.js +1 -0
  193. package/renderer-host/assets/ColladaParser-BHTzbhBz.js +3 -0
  194. package/renderer-host/assets/FBXLoader-D1vDnL3o.js +8 -0
  195. package/renderer-host/assets/agent-CKvDbj87.js +1 -0
  196. package/renderer-host/assets/amf-CLBaywBr.js +1 -0
  197. package/renderer-host/assets/animation-DnPo99To.js +1 -0
  198. package/renderer-host/assets/archive-client-CyhEmSF7.js +1 -0
  199. package/renderer-host/assets/archive.worker-CcLnJ9FC.js +1 -0
  200. package/renderer-host/assets/audio-visualizer-CiyGNhY2.js +1 -0
  201. package/renderer-host/assets/basedecoder-BuG7fe0q.js +1 -0
  202. package/renderer-host/assets/book-source-28BQcBKR.js +1 -0
  203. package/renderer-host/assets/book-worker-DrtzCzPo.js +1 -0
  204. package/renderer-host/assets/browser-C0pGRq_c.js +1 -0
  205. package/renderer-host/assets/client-Dp-p4unY.js +1 -0
  206. package/renderer-host/assets/container-inspection-DZoaDYQR.js +1 -0
  207. package/renderer-host/assets/data-table-OJQe3aN5.js +1 -0
  208. package/renderer-host/assets/decode-D5vB6JN8.js +1 -0
  209. package/renderer-host/assets/decode-tiff-BuYdKp6p.js +5 -0
  210. package/renderer-host/assets/decoder-worker-B0sdTVlF.js +1 -0
  211. package/renderer-host/assets/decoder-worker-CBiHE971.js +3 -0
  212. package/renderer-host/assets/decoder-worker-Cr5oP97p.js +5 -0
  213. package/renderer-host/assets/decoder-worker-DIdLFebY.js +11 -0
  214. package/renderer-host/assets/decoder-worker-DLeuEYxq.js +1 -0
  215. package/renderer-host/assets/decoder.worker-BXAaF0Qj.js +1 -0
  216. package/renderer-host/assets/decoder.worker-yaM6uups.js +1 -0
  217. package/renderer-host/assets/deflate-DPjr4M2G.js +1 -0
  218. package/renderer-host/assets/deflate-S3QmZI-f.js +1 -0
  219. package/renderer-host/assets/dual-track-playback-lNQyU1GR.js +1 -0
  220. package/renderer-host/assets/ext-searchbox-BIdon51Z.js +164 -0
  221. package/renderer-host/assets/ffmpeg-playback-QcT_NwlK.js +1 -0
  222. package/renderer-host/assets/gltf-Cqq-xStc.js +1 -0
  223. package/renderer-host/assets/hdf5.worker-BO3TrRup.js +1 -0
  224. package/renderer-host/assets/heif-worker-CC9DI3ZR.js +1 -0
  225. package/renderer-host/assets/id3-uzaDmDwy.js +1 -0
  226. package/renderer-host/assets/ifc.worker-KIbgAIsy.js +1 -0
  227. package/renderer-host/assets/image-load-B1fNI3iO.js +1 -0
  228. package/renderer-host/assets/index-BCxD9rBl.js +2 -0
  229. package/renderer-host/assets/jpeg-AGQ46WDa.js +1 -0
  230. package/renderer-host/assets/jpeg-Dm0yBuYB.js +1 -0
  231. package/renderer-host/assets/jszip.min-DCdQ6XWv.js +2 -0
  232. package/renderer-host/assets/jxl_oxide_wasm-BJKDqoXP.js +1 -0
  233. package/renderer-host/assets/jxl_oxide_wasm_bg-C5JqlrFv.wasm +0 -0
  234. package/renderer-host/assets/kernel.worker-B58X9XWu.js +1 -0
  235. package/renderer-host/assets/kernel.worker-BcQYKb39.js +8 -0
  236. package/renderer-host/assets/kernel.worker-BdWmPdqg.js +1 -0
  237. package/renderer-host/assets/kernel.worker-C7qxomuK.js +1 -0
  238. package/renderer-host/assets/kernel.worker-D88TbQnz.js +1 -0
  239. package/renderer-host/assets/laz-Lt10LsWd.js +1 -0
  240. package/renderer-host/assets/lerc-BxVqCKaH.js +3 -0
  241. package/renderer-host/assets/lerc-CRhfhhOS.js +1 -0
  242. package/renderer-host/assets/lzw-D2FslT4L.js +1 -0
  243. package/renderer-host/assets/lzw-DODNa9l5.js +1 -0
  244. package/renderer-host/assets/mediabunny-viewer-BnJM6Yo0.js +16 -0
  245. package/renderer-host/assets/model-D2YSoRt5.js +1 -0
  246. package/renderer-host/assets/obj-DbUZkDna.js +9 -0
  247. package/renderer-host/assets/off-CzR_R_Tf.js +1 -0
  248. package/renderer-host/assets/ogg-probe-C2TT74FL.js +1 -0
  249. package/renderer-host/assets/ogg-viewer-CT31JEhG.js +9 -0
  250. package/renderer-host/assets/packbits-DCimUQ1T.js +1 -0
  251. package/renderer-host/assets/paged-CX-N_Pzy.js +319 -0
  252. package/renderer-host/assets/pako.esm-0UYEm1Jg.js +2 -0
  253. package/renderer-host/assets/pako.esm-CtVA0R7W.js +1 -0
  254. package/renderer-host/assets/pdf.worker.min-CHFwMXne.mjs +29 -0
  255. package/renderer-host/assets/ply-C-xrhUaO.js +2 -0
  256. package/renderer-host/assets/points.worker-CA8v75dl.js +2 -0
  257. package/renderer-host/assets/probe-asf-CvcaYQaR.js +14 -0
  258. package/renderer-host/assets/range-reader-9PeAh1Hv.js +1 -0
  259. package/renderer-host/assets/raw-A-vJRPpa.js +1 -0
  260. package/renderer-host/assets/resource-cache-CHocY8K3.js +1 -0
  261. package/renderer-host/assets/resources-WcZvn3-C.js +1 -0
  262. package/renderer-host/assets/rolldown-runtime-Dd_uD5pT.js +1 -0
  263. package/renderer-host/assets/safe-content-B61Ktgzp.js +1 -0
  264. package/renderer-host/assets/sanitize-D56ODnaM.js +1 -0
  265. package/renderer-host/assets/scene-adapter-CmaaVwsM.js +1 -0
  266. package/renderer-host/assets/scene.worker-CJViWLYo.js +24 -0
  267. package/renderer-host/assets/scene.worker-D7koFZY8.js +2 -0
  268. package/renderer-host/assets/skp-adapter-ByI1iX8S.js +1 -0
  269. package/renderer-host/assets/skp.worker-D9ujTXFV.js +1 -0
  270. package/renderer-host/assets/src-0DTp6SF8.js +1 -0
  271. package/renderer-host/assets/src-0QHjkpy0.js +44 -0
  272. package/renderer-host/assets/src-2X3Gt6Lk.js +2 -0
  273. package/renderer-host/assets/src-2tfD0huT.js +16 -0
  274. package/renderer-host/assets/src-5ZJshveh.js +29 -0
  275. package/renderer-host/assets/src-9k3CCYnZ.js +1 -0
  276. package/renderer-host/assets/src-B0zJlB0C.js +27 -0
  277. package/renderer-host/assets/src-B4jorJ2U.js +100 -0
  278. package/renderer-host/assets/src-BB6xj1UK.js +18 -0
  279. package/renderer-host/assets/src-BEn15PBT.js +52 -0
  280. package/renderer-host/assets/src-BLndk63N.js +7 -0
  281. package/renderer-host/assets/src-BMrLVJyB.js +169 -0
  282. package/renderer-host/assets/src-BPG8SYXq.js +10 -0
  283. package/renderer-host/assets/src-BZrNtUNO.js +2 -0
  284. package/renderer-host/assets/src-B_o7QilB.js +58 -0
  285. package/renderer-host/assets/src-BgM1jpe4.js +5 -0
  286. package/renderer-host/assets/src-BgUXah8O.js +1 -0
  287. package/renderer-host/assets/src-Bl5Lv4-d.js +1 -0
  288. package/renderer-host/assets/src-Blx9jp9x.js +90 -0
  289. package/renderer-host/assets/src-Bu1cTJNz.js +64 -0
  290. package/renderer-host/assets/src-BuN3y1yE.js +24 -0
  291. package/renderer-host/assets/src-Bw-O8ujJ.js +2 -0
  292. package/renderer-host/assets/src-BwZAUudm.js +2 -0
  293. package/renderer-host/assets/src-BydeR01n.js +1 -0
  294. package/renderer-host/assets/src-C2LKqLBA.js +182 -0
  295. package/renderer-host/assets/src-C4t_UvT8.js +8 -0
  296. package/renderer-host/assets/src-C5k8Ydia.js +1 -0
  297. package/renderer-host/assets/src-C6w9FGSB.js +1 -0
  298. package/renderer-host/assets/src-C9Uz3C-q.js +432 -0
  299. package/renderer-host/assets/src-CAdKRH5C.js +37 -0
  300. package/renderer-host/assets/src-CBE5sqjl.js +7 -0
  301. package/renderer-host/assets/src-CBo2yHRk.js +21 -0
  302. package/renderer-host/assets/src-CGx0nUS5.js +24 -0
  303. package/renderer-host/assets/src-CHNgoDf9.js +10 -0
  304. package/renderer-host/assets/src-CIDWSV97.js +1 -0
  305. package/renderer-host/assets/src-CPUYqpHZ.js +9 -0
  306. package/renderer-host/assets/src-CVc67mQv.js +1 -0
  307. package/renderer-host/assets/src-CXRrmfb0.js +7 -0
  308. package/renderer-host/assets/src-C_1M1IDo.js +8 -0
  309. package/renderer-host/assets/src-C_HAB_bn.js +5 -0
  310. package/renderer-host/assets/src-CeGmxOTi.js +1 -0
  311. package/renderer-host/assets/src-CifsQr3m.js +222 -0
  312. package/renderer-host/assets/src-Ck1ekdEN.js +1 -0
  313. package/renderer-host/assets/src-ClIHDiJ4.js +27 -0
  314. package/renderer-host/assets/src-Cvb3aCDG.js +10 -0
  315. package/renderer-host/assets/src-Cyw_3X-L.js +989 -0
  316. package/renderer-host/assets/src-D3OyeoQs.js +1 -0
  317. package/renderer-host/assets/src-D4cv_-u0.js +1 -0
  318. package/renderer-host/assets/src-DPm7_lsi.js +24 -0
  319. package/renderer-host/assets/src-DZE9IoBl.js +88 -0
  320. package/renderer-host/assets/src-DmzigsPg.js +7 -0
  321. package/renderer-host/assets/src-DpEmkhrn.js +6 -0
  322. package/renderer-host/assets/src-DrYYfoQO.js +7 -0
  323. package/renderer-host/assets/src-DsVDi0pr.js +4126 -0
  324. package/renderer-host/assets/src-ORHZWeVF.js +2 -0
  325. package/renderer-host/assets/src-Q-oKL3Dw.js +10 -0
  326. package/renderer-host/assets/src-QXdjrTaw.js +4 -0
  327. package/renderer-host/assets/src-R4bKlaNn.js +387 -0
  328. package/renderer-host/assets/src-TbSq3WSr.js +115 -0
  329. package/renderer-host/assets/src-TuTvYAR6.js +11 -0
  330. package/renderer-host/assets/src-eVKtGm4Q.js +17 -0
  331. package/renderer-host/assets/src-efHN2oAJ.js +17 -0
  332. package/renderer-host/assets/src-hCrza_Lf.js +1 -0
  333. package/renderer-host/assets/src-j_mEQ9Os.js +9 -0
  334. package/renderer-host/assets/src-lYIAi6Hw.js +1 -0
  335. package/renderer-host/assets/src-n2gsf381.js +20 -0
  336. package/renderer-host/assets/src-p14e1hma.js +23 -0
  337. package/renderer-host/assets/src-rJN_jaC5.js +1 -0
  338. package/renderer-host/assets/src-vPHMg1Fp.js +1 -0
  339. package/renderer-host/assets/src-wrrVkfrK.js +1 -0
  340. package/renderer-host/assets/stl-adapter-D1eozFH9.js +1 -0
  341. package/renderer-host/assets/stl.worker-C-anHijM.js +1 -0
  342. package/renderer-host/assets/three-mf-CbcWWdM8.js +2 -0
  343. package/renderer-host/assets/webimage-zQMH-_zR.js +1 -0
  344. package/renderer-host/assets/webm-_wYh_V7u.js +1 -0
  345. package/renderer-host/assets/worker-QK2gViTu.js +1 -0
  346. package/renderer-host/assets/x6-dng-worker-CNf3zUP-.js +1 -0
  347. package/renderer-host/assets/xml.browser-CC8-XAyN.js +1 -0
  348. package/renderer-host/assets/zip-core-base-CDv8KjIR.js +1 -0
  349. package/renderer-host/assets/zip-core-custom-D3VVVj-J.js +1 -0
  350. package/renderer-host/assets/zip-source-C5dFTDt7.js +1 -0
  351. package/renderer-host/assets/zstd-CmwSLjHB.js +1 -0
  352. package/renderer-host/assets/zstd-i4Jwubnx.js +1 -0
  353. package/renderer-host/index.html +65 -0
  354. package/vendor-manifest.json +1433 -0
  355. package/worker.mjs +261 -0
@@ -0,0 +1,2990 @@
1
+ import { createRequire as __anyfileCreateRequire } from "node:module"; import { dirname as __anyfileDirname } from "node:path"; import { fileURLToPath as __anyfileFileURLToPath } from "node:url"; const require = __anyfileCreateRequire(import.meta.url); const __filename = __anyfileFileURLToPath(import.meta.url); const __dirname = __anyfileDirname(__filename);
2
+ import {
3
+ ExtraSamplesValues,
4
+ fieldTypes,
5
+ geoKeyNames,
6
+ getFieldTypeSize,
7
+ globals_exports,
8
+ photometricInterpretations,
9
+ resolveTag,
10
+ tagDefinitions
11
+ } from "./chunk-XTW4HNIJ.mjs";
12
+ import "./chunk-BVCRJLCD.mjs";
13
+ import {
14
+ MAX_TIFF_PAGES,
15
+ checkedPixelCount
16
+ } from "./chunk-DJXVCKIO.mjs";
17
+ import {
18
+ ViewerError
19
+ } from "./chunk-IC3G2XE2.mjs";
20
+ import "./chunk-ORJ3DN65.mjs";
21
+
22
+ // ../../node_modules/.pnpm/@petamoriken+float16@3.9.3/node_modules/@petamoriken/float16/src/_util/messages.mjs
23
+ var CANNOT_CONVERT_UNDEFINED_OR_NULL_TO_OBJECT = "Cannot convert undefined or null to object";
24
+
25
+ // ../../node_modules/.pnpm/@petamoriken+float16@3.9.3/node_modules/@petamoriken/float16/src/_util/primordials.mjs
26
+ function uncurryThis(target) {
27
+ return (thisArg, ...args) => {
28
+ return ReflectApply(target, thisArg, args);
29
+ };
30
+ }
31
+ function uncurryThisGetter(target, key) {
32
+ return uncurryThis(
33
+ ReflectGetOwnPropertyDescriptor(
34
+ target,
35
+ key
36
+ ).get
37
+ );
38
+ }
39
+ var {
40
+ apply: ReflectApply,
41
+ construct: ReflectConstruct,
42
+ defineProperty: ReflectDefineProperty,
43
+ get: ReflectGet,
44
+ getOwnPropertyDescriptor: ReflectGetOwnPropertyDescriptor,
45
+ getPrototypeOf: ReflectGetPrototypeOf,
46
+ has: ReflectHas,
47
+ ownKeys: ReflectOwnKeys,
48
+ set: ReflectSet,
49
+ setPrototypeOf: ReflectSetPrototypeOf
50
+ } = Reflect;
51
+ var {
52
+ EPSILON,
53
+ MAX_SAFE_INTEGER,
54
+ isFinite: NumberIsFinite,
55
+ isNaN: NumberIsNaN
56
+ } = Number;
57
+ var {
58
+ iterator: SymbolIterator,
59
+ species: SymbolSpecies,
60
+ toStringTag: SymbolToStringTag,
61
+ for: SymbolFor
62
+ } = Symbol;
63
+ var NativeObject = Object;
64
+ var {
65
+ create: ObjectCreate,
66
+ defineProperty: ObjectDefineProperty,
67
+ freeze: ObjectFreeze,
68
+ is: ObjectIs
69
+ } = NativeObject;
70
+ var ObjectPrototype = NativeObject.prototype;
71
+ var ObjectPrototype__lookupGetter__ = (
72
+ /** @type {any} */
73
+ ObjectPrototype.__lookupGetter__ ? uncurryThis(
74
+ /** @type {any} */
75
+ ObjectPrototype.__lookupGetter__
76
+ ) : (object, key) => {
77
+ if (object == null) {
78
+ throw NativeTypeError(
79
+ CANNOT_CONVERT_UNDEFINED_OR_NULL_TO_OBJECT
80
+ );
81
+ }
82
+ let target = NativeObject(object);
83
+ do {
84
+ const descriptor = ReflectGetOwnPropertyDescriptor(target, key);
85
+ if (descriptor !== void 0) {
86
+ if (ObjectHasOwn(descriptor, "get")) {
87
+ return descriptor.get;
88
+ }
89
+ return;
90
+ }
91
+ } while ((target = ReflectGetPrototypeOf(target)) !== null);
92
+ }
93
+ );
94
+ var ObjectHasOwn = (
95
+ /** @type {any} */
96
+ NativeObject.hasOwn || uncurryThis(ObjectPrototype.hasOwnProperty)
97
+ );
98
+ var NativeArray = Array;
99
+ var ArrayIsArray = NativeArray.isArray;
100
+ var ArrayPrototype = NativeArray.prototype;
101
+ var ArrayPrototypeJoin = uncurryThis(ArrayPrototype.join);
102
+ var ArrayPrototypePush = uncurryThis(ArrayPrototype.push);
103
+ var ArrayPrototypeToLocaleString = uncurryThis(
104
+ ArrayPrototype.toLocaleString
105
+ );
106
+ var NativeArrayPrototypeSymbolIterator = ArrayPrototype[SymbolIterator];
107
+ var ArrayPrototypeSymbolIterator = uncurryThis(NativeArrayPrototypeSymbolIterator);
108
+ var {
109
+ abs: MathAbs,
110
+ trunc: MathTrunc
111
+ } = Math;
112
+ var NativeArrayBuffer = ArrayBuffer;
113
+ var ArrayBufferIsView = NativeArrayBuffer.isView;
114
+ var ArrayBufferPrototype = NativeArrayBuffer.prototype;
115
+ var ArrayBufferPrototypeSlice = uncurryThis(ArrayBufferPrototype.slice);
116
+ var ArrayBufferPrototypeGetByteLength = uncurryThisGetter(ArrayBufferPrototype, "byteLength");
117
+ var NativeSharedArrayBuffer = typeof SharedArrayBuffer !== "undefined" ? SharedArrayBuffer : null;
118
+ var SharedArrayBufferPrototypeGetByteLength = NativeSharedArrayBuffer && uncurryThisGetter(NativeSharedArrayBuffer.prototype, "byteLength");
119
+ var TypedArray = ReflectGetPrototypeOf(Uint8Array);
120
+ var TypedArrayFrom = TypedArray.from;
121
+ var TypedArrayPrototype = TypedArray.prototype;
122
+ var NativeTypedArrayPrototypeSymbolIterator = TypedArrayPrototype[SymbolIterator];
123
+ var TypedArrayPrototypeKeys = uncurryThis(TypedArrayPrototype.keys);
124
+ var TypedArrayPrototypeValues = uncurryThis(
125
+ TypedArrayPrototype.values
126
+ );
127
+ var TypedArrayPrototypeEntries = uncurryThis(
128
+ TypedArrayPrototype.entries
129
+ );
130
+ var TypedArrayPrototypeSet = uncurryThis(TypedArrayPrototype.set);
131
+ var TypedArrayPrototypeReverse = uncurryThis(
132
+ TypedArrayPrototype.reverse
133
+ );
134
+ var TypedArrayPrototypeFill = uncurryThis(TypedArrayPrototype.fill);
135
+ var TypedArrayPrototypeCopyWithin = uncurryThis(
136
+ TypedArrayPrototype.copyWithin
137
+ );
138
+ var TypedArrayPrototypeSort = uncurryThis(TypedArrayPrototype.sort);
139
+ var TypedArrayPrototypeSlice = uncurryThis(TypedArrayPrototype.slice);
140
+ var TypedArrayPrototypeSubarray = uncurryThis(
141
+ TypedArrayPrototype.subarray
142
+ );
143
+ var TypedArrayPrototypeGetBuffer = uncurryThisGetter(
144
+ TypedArrayPrototype,
145
+ "buffer"
146
+ );
147
+ var TypedArrayPrototypeGetByteOffset = uncurryThisGetter(
148
+ TypedArrayPrototype,
149
+ "byteOffset"
150
+ );
151
+ var TypedArrayPrototypeGetLength = uncurryThisGetter(
152
+ TypedArrayPrototype,
153
+ "length"
154
+ );
155
+ var TypedArrayPrototypeGetSymbolToStringTag = uncurryThisGetter(
156
+ TypedArrayPrototype,
157
+ SymbolToStringTag
158
+ );
159
+ var NativeUint8Array = Uint8Array;
160
+ var NativeUint16Array = Uint16Array;
161
+ var NativeUint32Array = Uint32Array;
162
+ var NativeFloat32Array = Float32Array;
163
+ var ArrayIteratorPrototype = ReflectGetPrototypeOf([][SymbolIterator]());
164
+ var ArrayIteratorPrototypeNext = uncurryThis(ArrayIteratorPrototype.next);
165
+ var GeneratorPrototypeNext = uncurryThis((function* () {
166
+ })().next);
167
+ var IteratorPrototype = ReflectGetPrototypeOf(ArrayIteratorPrototype);
168
+ var DataViewPrototype = DataView.prototype;
169
+ var DataViewPrototypeGetUint16 = uncurryThis(
170
+ DataViewPrototype.getUint16
171
+ );
172
+ var DataViewPrototypeSetUint16 = uncurryThis(
173
+ DataViewPrototype.setUint16
174
+ );
175
+ var NativeTypeError = TypeError;
176
+ var NativeWeakSet = WeakSet;
177
+ var WeakSetPrototype = NativeWeakSet.prototype;
178
+ var WeakSetPrototypeAdd = uncurryThis(WeakSetPrototype.add);
179
+ var WeakSetPrototypeHas = uncurryThis(WeakSetPrototype.has);
180
+ var NativeWeakMap = WeakMap;
181
+ var WeakMapPrototype = NativeWeakMap.prototype;
182
+ var WeakMapPrototypeGet = uncurryThis(WeakMapPrototype.get);
183
+ var WeakMapPrototypeHas = uncurryThis(WeakMapPrototype.has);
184
+ var WeakMapPrototypeSet = uncurryThis(WeakMapPrototype.set);
185
+
186
+ // ../../node_modules/.pnpm/@petamoriken+float16@3.9.3/node_modules/@petamoriken/float16/src/_util/arrayIterator.mjs
187
+ var arrayIterators = new NativeWeakMap();
188
+ var SafeIteratorPrototype = ObjectCreate(null, {
189
+ next: {
190
+ value: function next() {
191
+ const arrayIterator = WeakMapPrototypeGet(arrayIterators, this);
192
+ return ArrayIteratorPrototypeNext(arrayIterator);
193
+ }
194
+ },
195
+ [SymbolIterator]: {
196
+ value: function values() {
197
+ return this;
198
+ }
199
+ }
200
+ });
201
+ function safeIfNeeded(array) {
202
+ if (array[SymbolIterator] === NativeArrayPrototypeSymbolIterator && ArrayIteratorPrototype.next === ArrayIteratorPrototypeNext) {
203
+ return array;
204
+ }
205
+ const safe = ObjectCreate(SafeIteratorPrototype);
206
+ WeakMapPrototypeSet(arrayIterators, safe, ArrayPrototypeSymbolIterator(array));
207
+ return safe;
208
+ }
209
+ var generators = new NativeWeakMap();
210
+ var DummyArrayIteratorPrototype = ObjectCreate(IteratorPrototype, {
211
+ next: {
212
+ value: function next2() {
213
+ const generator = WeakMapPrototypeGet(generators, this);
214
+ return GeneratorPrototypeNext(generator);
215
+ },
216
+ writable: true,
217
+ configurable: true
218
+ }
219
+ });
220
+ for (const key of ReflectOwnKeys(ArrayIteratorPrototype)) {
221
+ if (key === "next") {
222
+ continue;
223
+ }
224
+ ObjectDefineProperty(DummyArrayIteratorPrototype, key, ReflectGetOwnPropertyDescriptor(ArrayIteratorPrototype, key));
225
+ }
226
+
227
+ // ../../node_modules/.pnpm/@petamoriken+float16@3.9.3/node_modules/@petamoriken/float16/src/_util/converter.mjs
228
+ var INVERSE_OF_EPSILON = 1 / EPSILON;
229
+ var FLOAT16_MIN_VALUE = 6103515625e-14;
230
+ var FLOAT16_EPSILON = 9765625e-10;
231
+ var FLOAT16_EPSILON_MULTIPLIED_BY_FLOAT16_MIN_VALUE = FLOAT16_EPSILON * FLOAT16_MIN_VALUE;
232
+ var FLOAT16_EPSILON_DEVIDED_BY_EPSILON = FLOAT16_EPSILON * INVERSE_OF_EPSILON;
233
+ var buffer = new NativeArrayBuffer(4);
234
+ var floatView = new NativeFloat32Array(buffer);
235
+ var uint32View = new NativeUint32Array(buffer);
236
+ var baseTable = new NativeUint16Array(512);
237
+ var shiftTable = new NativeUint8Array(512);
238
+ for (let i = 0; i < 256; ++i) {
239
+ const e = i - 127;
240
+ if (e < -24) {
241
+ baseTable[i] = 0;
242
+ baseTable[i | 256] = 32768;
243
+ shiftTable[i] = 24;
244
+ shiftTable[i | 256] = 24;
245
+ } else if (e < -14) {
246
+ baseTable[i] = 1024 >> -e - 14;
247
+ baseTable[i | 256] = 1024 >> -e - 14 | 32768;
248
+ shiftTable[i] = -e - 1;
249
+ shiftTable[i | 256] = -e - 1;
250
+ } else if (e <= 15) {
251
+ baseTable[i] = e + 15 << 10;
252
+ baseTable[i | 256] = e + 15 << 10 | 32768;
253
+ shiftTable[i] = 13;
254
+ shiftTable[i | 256] = 13;
255
+ } else if (e < 128) {
256
+ baseTable[i] = 31744;
257
+ baseTable[i | 256] = 64512;
258
+ shiftTable[i] = 24;
259
+ shiftTable[i | 256] = 24;
260
+ } else {
261
+ baseTable[i] = 31744;
262
+ baseTable[i | 256] = 64512;
263
+ shiftTable[i] = 13;
264
+ shiftTable[i | 256] = 13;
265
+ }
266
+ }
267
+ var mantissaTable = new NativeUint32Array(2048);
268
+ for (let i = 1; i < 1024; ++i) {
269
+ let m = i << 13;
270
+ let e = 0;
271
+ while ((m & 8388608) === 0) {
272
+ m <<= 1;
273
+ e -= 8388608;
274
+ }
275
+ m &= ~8388608;
276
+ e += 947912704;
277
+ mantissaTable[i] = m | e;
278
+ }
279
+ for (let i = 1024; i < 2048; ++i) {
280
+ mantissaTable[i] = 939524096 + (i - 1024 << 13);
281
+ }
282
+ var exponentTable = new NativeUint32Array(64);
283
+ for (let i = 1; i < 31; ++i) {
284
+ exponentTable[i] = i << 23;
285
+ }
286
+ exponentTable[31] = 1199570944;
287
+ exponentTable[32] = 2147483648;
288
+ for (let i = 33; i < 63; ++i) {
289
+ exponentTable[i] = 2147483648 + (i - 32 << 23);
290
+ }
291
+ exponentTable[63] = 3347054592;
292
+ var offsetTable = new NativeUint16Array(64);
293
+ for (let i = 1; i < 64; ++i) {
294
+ if (i !== 32) {
295
+ offsetTable[i] = 1024;
296
+ }
297
+ }
298
+ function convertToNumber(float16bits) {
299
+ const i = float16bits >> 10;
300
+ uint32View[0] = mantissaTable[offsetTable[i] + (float16bits & 1023)] + exponentTable[i];
301
+ return floatView[0];
302
+ }
303
+
304
+ // ../../node_modules/.pnpm/@petamoriken+float16@3.9.3/node_modules/@petamoriken/float16/src/DataView.mjs
305
+ function getFloat16(dataView, byteOffset, ...opts) {
306
+ return convertToNumber(
307
+ DataViewPrototypeGetUint16(dataView, byteOffset, ...safeIfNeeded(opts))
308
+ );
309
+ }
310
+
311
+ // ../../node_modules/.pnpm/xml-utils@1.10.2/node_modules/xml-utils/get-attribute.mjs
312
+ function getAttribute(tag, attributeName, options) {
313
+ const debug = options && options.debug || false;
314
+ if (debug) console.log("[xml-utils] getting " + attributeName + " in " + tag);
315
+ const xml = typeof tag === "object" ? tag.outer : tag;
316
+ const opening = xml.slice(0, xml.indexOf(">") + 1);
317
+ const quotechars = ['"', "'"];
318
+ for (let i = 0; i < quotechars.length; i++) {
319
+ const char = quotechars[i];
320
+ const pattern = attributeName + "\\=" + char + "([^" + char + "]*)" + char;
321
+ if (debug) console.log("[xml-utils] pattern:", pattern);
322
+ const re = new RegExp(pattern);
323
+ const match = re.exec(opening);
324
+ if (debug) console.log("[xml-utils] match:", match);
325
+ if (match) return match[1];
326
+ }
327
+ }
328
+
329
+ // ../../node_modules/.pnpm/xml-utils@1.10.2/node_modules/xml-utils/index-of-match.mjs
330
+ function indexOfMatch(xml, pattern, startIndex) {
331
+ const re = new RegExp(pattern);
332
+ const match = re.exec(xml.slice(startIndex));
333
+ if (match) return startIndex + match.index;
334
+ else return -1;
335
+ }
336
+
337
+ // ../../node_modules/.pnpm/xml-utils@1.10.2/node_modules/xml-utils/index-of-match-end.mjs
338
+ function indexOfMatchEnd(xml, pattern, startIndex) {
339
+ const re = new RegExp(pattern);
340
+ const match = re.exec(xml.slice(startIndex));
341
+ if (match) return startIndex + match.index + match[0].length - 1;
342
+ else return -1;
343
+ }
344
+
345
+ // ../../node_modules/.pnpm/xml-utils@1.10.2/node_modules/xml-utils/count-substring.mjs
346
+ function countSubstring(string, substring) {
347
+ const pattern = new RegExp(substring, "g");
348
+ const match = string.match(pattern);
349
+ return match ? match.length : 0;
350
+ }
351
+
352
+ // ../../node_modules/.pnpm/xml-utils@1.10.2/node_modules/xml-utils/find-tag-by-name.mjs
353
+ function findTagByName(xml, tagName2, options) {
354
+ const debug = options && options.debug || false;
355
+ const nested = !(options && typeof options.nested === false);
356
+ const startIndex = options && options.startIndex || 0;
357
+ if (debug) console.log("[xml-utils] starting findTagByName with", tagName2, " and ", options);
358
+ const start = indexOfMatch(xml, `<${tagName2}[
359
+ >/]`, startIndex);
360
+ if (debug) console.log("[xml-utils] start:", start);
361
+ if (start === -1) return void 0;
362
+ const afterStart = xml.slice(start + tagName2.length);
363
+ let relativeEnd = indexOfMatchEnd(afterStart, "^[^<]*[ /]>", 0);
364
+ const selfClosing = relativeEnd !== -1 && afterStart[relativeEnd - 1] === "/";
365
+ if (debug) console.log("[xml-utils] selfClosing:", selfClosing);
366
+ if (selfClosing === false) {
367
+ if (nested) {
368
+ let startIndex2 = 0;
369
+ let openings = 1;
370
+ let closings = 0;
371
+ while ((relativeEnd = indexOfMatchEnd(afterStart, "[ /]" + tagName2 + ">", startIndex2)) !== -1) {
372
+ const clip = afterStart.substring(startIndex2, relativeEnd + 1);
373
+ openings += countSubstring(clip, "<" + tagName2 + "[ \n >]");
374
+ closings += countSubstring(clip, "</" + tagName2 + ">");
375
+ if (closings >= openings) break;
376
+ startIndex2 = relativeEnd;
377
+ }
378
+ } else {
379
+ relativeEnd = indexOfMatchEnd(afterStart, "[ /]" + tagName2 + ">", 0);
380
+ }
381
+ }
382
+ const end = start + tagName2.length + relativeEnd + 1;
383
+ if (debug) console.log("[xml-utils] end:", end);
384
+ if (end === -1) return void 0;
385
+ const outer = xml.slice(start, end);
386
+ let inner;
387
+ if (selfClosing) {
388
+ inner = null;
389
+ } else {
390
+ inner = outer.slice(outer.indexOf(">") + 1, outer.lastIndexOf("<"));
391
+ }
392
+ return { inner, outer, start, end };
393
+ }
394
+
395
+ // ../../node_modules/.pnpm/xml-utils@1.10.2/node_modules/xml-utils/find-tags-by-name.mjs
396
+ function findTagsByName(xml, tagName2, options) {
397
+ const tags = [];
398
+ const debug = options && options.debug || false;
399
+ const nested = options && typeof options.nested === "boolean" ? options.nested : true;
400
+ let startIndex = options && options.startIndex || 0;
401
+ let tag;
402
+ while (tag = findTagByName(xml, tagName2, { debug, startIndex })) {
403
+ if (nested) {
404
+ startIndex = tag.start + 1 + tagName2.length;
405
+ } else {
406
+ startIndex = tag.end;
407
+ }
408
+ tags.push(tag);
409
+ }
410
+ if (debug) console.log("findTagsByName found", tags.length, "tags");
411
+ return tags;
412
+ }
413
+
414
+ // ../../node_modules/.pnpm/geotiff@3.0.5/node_modules/geotiff/dist-module/rgb.js
415
+ function fromWhiteIsZero(raster, max) {
416
+ const { width, height } = raster;
417
+ const rgbRaster = new Uint8Array(width * height * 3);
418
+ let value;
419
+ for (let i = 0, j = 0; i < raster.length; ++i, j += 3) {
420
+ value = 256 - raster[i] / max * 256;
421
+ rgbRaster[j] = value;
422
+ rgbRaster[j + 1] = value;
423
+ rgbRaster[j + 2] = value;
424
+ }
425
+ return rgbRaster;
426
+ }
427
+ function fromBlackIsZero(raster, max) {
428
+ const { width, height } = raster;
429
+ const rgbRaster = new Uint8Array(width * height * 3);
430
+ let value;
431
+ for (let i = 0, j = 0; i < raster.length; ++i, j += 3) {
432
+ value = raster[i] / max * 256;
433
+ rgbRaster[j] = value;
434
+ rgbRaster[j + 1] = value;
435
+ rgbRaster[j + 2] = value;
436
+ }
437
+ return rgbRaster;
438
+ }
439
+ function fromPalette(raster, colorMap) {
440
+ const { width, height } = raster;
441
+ const rgbRaster = new Uint8Array(width * height * 3);
442
+ const greenOffset = colorMap.length / 3;
443
+ const blueOffset = colorMap.length / 3 * 2;
444
+ for (let i = 0, j = 0; i < raster.length; ++i, j += 3) {
445
+ const mapIndex = raster[i];
446
+ rgbRaster[j] = colorMap[mapIndex] / 65536 * 256;
447
+ rgbRaster[j + 1] = colorMap[mapIndex + greenOffset] / 65536 * 256;
448
+ rgbRaster[j + 2] = colorMap[mapIndex + blueOffset] / 65536 * 256;
449
+ }
450
+ return rgbRaster;
451
+ }
452
+ function fromCMYK(cmykRaster) {
453
+ const { width, height } = cmykRaster;
454
+ const rgbRaster = new Uint8Array(width * height * 3);
455
+ for (let i = 0, j = 0; i < cmykRaster.length; i += 4, j += 3) {
456
+ const c = cmykRaster[i];
457
+ const m = cmykRaster[i + 1];
458
+ const y = cmykRaster[i + 2];
459
+ const k = cmykRaster[i + 3];
460
+ rgbRaster[j] = 255 * ((255 - c) / 256) * ((255 - k) / 256);
461
+ rgbRaster[j + 1] = 255 * ((255 - m) / 256) * ((255 - k) / 256);
462
+ rgbRaster[j + 2] = 255 * ((255 - y) / 256) * ((255 - k) / 256);
463
+ }
464
+ return rgbRaster;
465
+ }
466
+ function fromYCbCr(yCbCrRaster) {
467
+ const { width, height } = yCbCrRaster;
468
+ const rgbRaster = new Uint8ClampedArray(width * height * 3);
469
+ for (let i = 0, j = 0; i < yCbCrRaster.length; i += 3, j += 3) {
470
+ const y = yCbCrRaster[i];
471
+ const cb = yCbCrRaster[i + 1];
472
+ const cr = yCbCrRaster[i + 2];
473
+ rgbRaster[j] = y + 1.402 * (cr - 128);
474
+ rgbRaster[j + 1] = y - 0.34414 * (cb - 128) - 0.71414 * (cr - 128);
475
+ rgbRaster[j + 2] = y + 1.772 * (cb - 128);
476
+ }
477
+ return rgbRaster;
478
+ }
479
+ var Xn = 0.95047;
480
+ var Yn = 1;
481
+ var Zn = 1.08883;
482
+ function fromCIELab(cieLabRaster) {
483
+ const { width, height } = cieLabRaster;
484
+ const rgbRaster = new Uint8Array(width * height * 3);
485
+ for (let i = 0, j = 0; i < cieLabRaster.length; i += 3, j += 3) {
486
+ const L = cieLabRaster[i + 0];
487
+ const a_ = cieLabRaster[i + 1] << 24 >> 24;
488
+ const b_ = cieLabRaster[i + 2] << 24 >> 24;
489
+ let y = (L + 16) / 116;
490
+ let x = a_ / 500 + y;
491
+ let z = y - b_ / 200;
492
+ let r;
493
+ let g;
494
+ let b;
495
+ x = Xn * (x * x * x > 8856e-6 ? x * x * x : (x - 16 / 116) / 7.787);
496
+ y = Yn * (y * y * y > 8856e-6 ? y * y * y : (y - 16 / 116) / 7.787);
497
+ z = Zn * (z * z * z > 8856e-6 ? z * z * z : (z - 16 / 116) / 7.787);
498
+ r = x * 3.2406 + y * -1.5372 + z * -0.4986;
499
+ g = x * -0.9689 + y * 1.8758 + z * 0.0415;
500
+ b = x * 0.0557 + y * -0.204 + z * 1.057;
501
+ r = r > 31308e-7 ? 1.055 * r ** (1 / 2.4) - 0.055 : 12.92 * r;
502
+ g = g > 31308e-7 ? 1.055 * g ** (1 / 2.4) - 0.055 : 12.92 * g;
503
+ b = b > 31308e-7 ? 1.055 * b ** (1 / 2.4) - 0.055 : 12.92 * b;
504
+ rgbRaster[j] = Math.max(0, Math.min(1, r)) * 255;
505
+ rgbRaster[j + 1] = Math.max(0, Math.min(1, g)) * 255;
506
+ rgbRaster[j + 2] = Math.max(0, Math.min(1, b)) * 255;
507
+ }
508
+ return rgbRaster;
509
+ }
510
+
511
+ // ../../node_modules/.pnpm/geotiff@3.0.5/node_modules/geotiff/dist-module/compression/index.js
512
+ var registry = /* @__PURE__ */ new Map();
513
+ async function defaultDecoderParameterFn(fileDirectory) {
514
+ const isTiled = !fileDirectory.hasTag("StripOffsets");
515
+ return (
516
+ /** @type {BaseDecoderParameters} */
517
+ {
518
+ tileWidth: isTiled ? await fileDirectory.loadValue("TileWidth") : await fileDirectory.loadValue("ImageWidth"),
519
+ tileHeight: isTiled ? await fileDirectory.loadValue("TileLength") : await fileDirectory.loadValue("RowsPerStrip") || await fileDirectory.loadValue("ImageLength"),
520
+ planarConfiguration: await fileDirectory.loadValue("PlanarConfiguration"),
521
+ bitsPerSample: await fileDirectory.loadValue("BitsPerSample"),
522
+ predictor: await fileDirectory.loadValue("Predictor") || 1
523
+ }
524
+ );
525
+ }
526
+ function addDecoder(cases, importFn, decoderParameterFn = defaultDecoderParameterFn, preferWorker_ = true) {
527
+ if (!Array.isArray(cases)) {
528
+ cases = [cases];
529
+ }
530
+ cases.forEach((c) => {
531
+ registry.set(c, { importFn, decoderParameterFn, preferWorker: preferWorker_ });
532
+ });
533
+ }
534
+ async function getDecoderParameters(compression, fileDirectory) {
535
+ if (!registry.has(compression)) {
536
+ throw new Error(`Unknown compression method identifier: ${compression}`);
537
+ }
538
+ const { decoderParameterFn } = (
539
+ /** @type {RegistryEntry} */
540
+ registry.get(compression)
541
+ );
542
+ return decoderParameterFn(fileDirectory);
543
+ }
544
+ async function getDecoder(compression, decoderParameters) {
545
+ if (!registry.has(compression)) {
546
+ throw new Error(`Unknown compression method identifier: ${compression}`);
547
+ }
548
+ const { importFn } = (
549
+ /** @type {RegistryEntry} */
550
+ registry.get(compression)
551
+ );
552
+ const Decoder = await importFn();
553
+ return new Decoder(decoderParameters);
554
+ }
555
+ var defaultDecoderDefinitions = [
556
+ // No compression
557
+ {
558
+ cases: [void 0, 1],
559
+ importFn: () => import("./raw-JJRPYAXO.mjs").then((m) => m.default),
560
+ preferWorker: false
561
+ },
562
+ // LZW
563
+ {
564
+ cases: 5,
565
+ importFn: () => import("./lzw-Z2ZZBEWD.mjs").then((m) => m.default)
566
+ },
567
+ // Old-style JPEG
568
+ {
569
+ cases: 6,
570
+ importFn: () => {
571
+ throw new Error("old style JPEG compression is not supported.");
572
+ }
573
+ },
574
+ // JPEG
575
+ {
576
+ cases: 7,
577
+ importFn: () => import("./jpeg-N3DSYEAQ.mjs").then((m) => m.default),
578
+ /**
579
+ * @param {import("../imagefiledirectory.js").ImageFileDirectory} fileDirectory
580
+ */
581
+ decoderParameterFn: async (fileDirectory) => {
582
+ return {
583
+ ...await defaultDecoderParameterFn(fileDirectory),
584
+ JPEGTables: await fileDirectory.loadValue("JPEGTables")
585
+ };
586
+ }
587
+ },
588
+ // Deflate / Adobe Deflate
589
+ {
590
+ cases: [8, 32946],
591
+ importFn: () => import("./deflate-IINN6MRE.mjs").then((m) => m.default)
592
+ },
593
+ // PackBits
594
+ {
595
+ cases: 32773,
596
+ importFn: () => import("./packbits-3S2JASDB.mjs").then((m) => m.default)
597
+ },
598
+ // LERC
599
+ {
600
+ cases: 34887,
601
+ importFn: () => import("./lerc-5LP7Q554.mjs").then(async (m) => {
602
+ await m.zstd.init();
603
+ return m;
604
+ }).then((m) => m.default),
605
+ /**
606
+ * @param {import("../imagefiledirectory.js").ImageFileDirectory} fileDirectory
607
+ */
608
+ decoderParameterFn: async (fileDirectory) => {
609
+ return {
610
+ ...await defaultDecoderParameterFn(fileDirectory),
611
+ LercParameters: await fileDirectory.loadValue("LercParameters")
612
+ };
613
+ }
614
+ },
615
+ // zstd
616
+ {
617
+ cases: 5e4,
618
+ importFn: () => import("./zstd-AH2S24PU.mjs").then(async (m) => {
619
+ await m.zstd.init();
620
+ return m;
621
+ }).then((m) => m.default)
622
+ },
623
+ // WebP Images
624
+ {
625
+ cases: 50001,
626
+ importFn: () => import("./webimage-D6XSCCTJ.mjs").then((m) => m.default),
627
+ /**
628
+ * @param {import("../imagefiledirectory.js").ImageFileDirectory} fileDirectory
629
+ */
630
+ decoderParameterFn: async (fileDirectory) => {
631
+ return {
632
+ ...await defaultDecoderParameterFn(fileDirectory),
633
+ samplesPerPixel: Number(await fileDirectory.loadValue("SamplesPerPixel")) || 4
634
+ };
635
+ },
636
+ preferWorker: false
637
+ }
638
+ ];
639
+ for (const decoderDefinition of defaultDecoderDefinitions) {
640
+ const { cases, importFn, decoderParameterFn, preferWorker: preferWorker_ } = decoderDefinition;
641
+ addDecoder(cases, importFn, decoderParameterFn, preferWorker_);
642
+ }
643
+
644
+ // ../../node_modules/.pnpm/geotiff@3.0.5/node_modules/geotiff/dist-module/resample.js
645
+ function copyNewSize(array, width, height, samplesPerPixel = 1) {
646
+ return new (Object.getPrototypeOf(array)).constructor(width * height * samplesPerPixel);
647
+ }
648
+ function resampleNearest(valueArrays, inWidth, inHeight, outWidth, outHeight) {
649
+ const relX = inWidth / outWidth;
650
+ const relY = inHeight / outHeight;
651
+ return valueArrays.map((array) => {
652
+ const newArray = copyNewSize(array, outWidth, outHeight);
653
+ for (let y = 0; y < outHeight; ++y) {
654
+ const cy = Math.min(Math.round(relY * y), inHeight - 1);
655
+ for (let x = 0; x < outWidth; ++x) {
656
+ const cx = Math.min(Math.round(relX * x), inWidth - 1);
657
+ const value = array[cy * inWidth + cx];
658
+ newArray[y * outWidth + x] = value;
659
+ }
660
+ }
661
+ return newArray;
662
+ });
663
+ }
664
+ function lerp(v0, v1, t) {
665
+ return (1 - t) * v0 + t * v1;
666
+ }
667
+ function resampleBilinear(valueArrays, inWidth, inHeight, outWidth, outHeight) {
668
+ const relX = inWidth / outWidth;
669
+ const relY = inHeight / outHeight;
670
+ return valueArrays.map((array) => {
671
+ const newArray = copyNewSize(array, outWidth, outHeight);
672
+ for (let y = 0; y < outHeight; ++y) {
673
+ const rawY = relY * y;
674
+ const yl = Math.floor(rawY);
675
+ const yh = Math.min(Math.ceil(rawY), inHeight - 1);
676
+ for (let x = 0; x < outWidth; ++x) {
677
+ const rawX = relX * x;
678
+ const tx = rawX % 1;
679
+ const xl = Math.floor(rawX);
680
+ const xh = Math.min(Math.ceil(rawX), inWidth - 1);
681
+ const ll = array[yl * inWidth + xl];
682
+ const hl = array[yl * inWidth + xh];
683
+ const lh = array[yh * inWidth + xl];
684
+ const hh = array[yh * inWidth + xh];
685
+ const value = lerp(lerp(ll, hl, tx), lerp(lh, hh, tx), rawY % 1);
686
+ newArray[y * outWidth + x] = value;
687
+ }
688
+ }
689
+ return newArray;
690
+ });
691
+ }
692
+ function resample(valueArrays, inWidth, inHeight, outWidth, outHeight, method = "nearest") {
693
+ switch (method.toLowerCase()) {
694
+ case "nearest":
695
+ return resampleNearest(valueArrays, inWidth, inHeight, outWidth, outHeight);
696
+ case "bilinear":
697
+ case "linear":
698
+ return resampleBilinear(valueArrays, inWidth, inHeight, outWidth, outHeight);
699
+ default:
700
+ throw new Error(`Unsupported resampling method: '${method}'`);
701
+ }
702
+ }
703
+ function resampleNearestInterleaved(valueArray, inWidth, inHeight, outWidth, outHeight, samples) {
704
+ const relX = inWidth / outWidth;
705
+ const relY = inHeight / outHeight;
706
+ const newArray = copyNewSize(valueArray, outWidth, outHeight, samples);
707
+ for (let y = 0; y < outHeight; ++y) {
708
+ const cy = Math.min(Math.round(relY * y), inHeight - 1);
709
+ for (let x = 0; x < outWidth; ++x) {
710
+ const cx = Math.min(Math.round(relX * x), inWidth - 1);
711
+ for (let i = 0; i < samples; ++i) {
712
+ const value = valueArray[cy * inWidth * samples + cx * samples + i];
713
+ newArray[y * outWidth * samples + x * samples + i] = value;
714
+ }
715
+ }
716
+ }
717
+ return newArray;
718
+ }
719
+ function resampleBilinearInterleaved(valueArray, inWidth, inHeight, outWidth, outHeight, samples) {
720
+ const relX = inWidth / outWidth;
721
+ const relY = inHeight / outHeight;
722
+ const newArray = copyNewSize(valueArray, outWidth, outHeight, samples);
723
+ for (let y = 0; y < outHeight; ++y) {
724
+ const rawY = relY * y;
725
+ const yl = Math.floor(rawY);
726
+ const yh = Math.min(Math.ceil(rawY), inHeight - 1);
727
+ for (let x = 0; x < outWidth; ++x) {
728
+ const rawX = relX * x;
729
+ const tx = rawX % 1;
730
+ const xl = Math.floor(rawX);
731
+ const xh = Math.min(Math.ceil(rawX), inWidth - 1);
732
+ for (let i = 0; i < samples; ++i) {
733
+ const ll = valueArray[yl * inWidth * samples + xl * samples + i];
734
+ const hl = valueArray[yl * inWidth * samples + xh * samples + i];
735
+ const lh = valueArray[yh * inWidth * samples + xl * samples + i];
736
+ const hh = valueArray[yh * inWidth * samples + xh * samples + i];
737
+ const value = lerp(lerp(ll, hl, tx), lerp(lh, hh, tx), rawY % 1);
738
+ newArray[y * outWidth * samples + x * samples + i] = value;
739
+ }
740
+ }
741
+ }
742
+ return newArray;
743
+ }
744
+ function resampleInterleaved(valueArray, inWidth, inHeight, outWidth, outHeight, samples, method = "nearest") {
745
+ switch (method.toLowerCase()) {
746
+ case "nearest":
747
+ return resampleNearestInterleaved(valueArray, inWidth, inHeight, outWidth, outHeight, samples);
748
+ case "bilinear":
749
+ case "linear":
750
+ return resampleBilinearInterleaved(valueArray, inWidth, inHeight, outWidth, outHeight, samples);
751
+ default:
752
+ throw new Error(`Unsupported resampling method: '${method}'`);
753
+ }
754
+ }
755
+
756
+ // ../../node_modules/.pnpm/geotiff@3.0.5/node_modules/geotiff/dist-module/geotiffimage.js
757
+ function sum(array, start, end) {
758
+ let s = 0;
759
+ for (let i = start; i < end; ++i) {
760
+ s += array[i];
761
+ }
762
+ return s;
763
+ }
764
+ function arrayForType(format, bitsPerSample, sizeOrData) {
765
+ let TypedArrayConstructor;
766
+ switch (format) {
767
+ case 1:
768
+ if (bitsPerSample <= 8) {
769
+ TypedArrayConstructor = Uint8Array;
770
+ } else if (bitsPerSample <= 16) {
771
+ TypedArrayConstructor = Uint16Array;
772
+ } else if (bitsPerSample <= 32) {
773
+ TypedArrayConstructor = Uint32Array;
774
+ }
775
+ break;
776
+ case 2:
777
+ if (bitsPerSample === 8) {
778
+ TypedArrayConstructor = Int8Array;
779
+ } else if (bitsPerSample === 16) {
780
+ TypedArrayConstructor = Int16Array;
781
+ } else if (bitsPerSample === 32) {
782
+ TypedArrayConstructor = Int32Array;
783
+ }
784
+ break;
785
+ case 3:
786
+ switch (bitsPerSample) {
787
+ case 16:
788
+ case 32:
789
+ TypedArrayConstructor = Float32Array;
790
+ break;
791
+ case 64:
792
+ TypedArrayConstructor = Float64Array;
793
+ break;
794
+ default:
795
+ break;
796
+ }
797
+ break;
798
+ default:
799
+ break;
800
+ }
801
+ if (TypedArrayConstructor) {
802
+ if (typeof sizeOrData === "number") {
803
+ return new TypedArrayConstructor(sizeOrData);
804
+ } else if (sizeOrData instanceof ArrayBuffer) {
805
+ return new TypedArrayConstructor(sizeOrData);
806
+ }
807
+ }
808
+ throw Error("Unsupported data format/bitsPerSample");
809
+ }
810
+ function needsNormalization(format, bitsPerSample) {
811
+ if ((format === 1 || format === 2) && bitsPerSample <= 32 && bitsPerSample % 8 === 0) {
812
+ return false;
813
+ } else if (format === 3 && (bitsPerSample === 16 || bitsPerSample === 32 || bitsPerSample === 64)) {
814
+ return false;
815
+ }
816
+ return true;
817
+ }
818
+ function normalizeArray(inBuffer, format, planarConfiguration, samplesPerPixel, bitsPerSample, tileWidth, tileHeight) {
819
+ const view = new DataView(inBuffer);
820
+ const outSize = planarConfiguration === 2 ? tileHeight * tileWidth : tileHeight * tileWidth * samplesPerPixel;
821
+ const samplesToTransfer = planarConfiguration === 2 ? 1 : samplesPerPixel;
822
+ const outArray = arrayForType(format, bitsPerSample, outSize);
823
+ const bitMask = parseInt("1".repeat(bitsPerSample), 2);
824
+ if (format === 1) {
825
+ let pixelBitSkip;
826
+ if (planarConfiguration === 1) {
827
+ pixelBitSkip = samplesPerPixel * bitsPerSample;
828
+ } else {
829
+ pixelBitSkip = bitsPerSample;
830
+ }
831
+ let bitsPerLine = tileWidth * pixelBitSkip;
832
+ if ((bitsPerLine & 7) !== 0) {
833
+ bitsPerLine = bitsPerLine + 7 & ~7;
834
+ }
835
+ for (let y = 0; y < tileHeight; ++y) {
836
+ const lineBitOffset = y * bitsPerLine;
837
+ for (let x = 0; x < tileWidth; ++x) {
838
+ const pixelBitOffset = lineBitOffset + x * samplesToTransfer * bitsPerSample;
839
+ for (let i = 0; i < samplesToTransfer; ++i) {
840
+ const bitOffset = pixelBitOffset + i * bitsPerSample;
841
+ const outIndex = (y * tileWidth + x) * samplesToTransfer + i;
842
+ const byteOffset = Math.floor(bitOffset / 8);
843
+ const innerBitOffset = bitOffset % 8;
844
+ if (innerBitOffset + bitsPerSample <= 8) {
845
+ outArray[outIndex] = view.getUint8(byteOffset) >> 8 - bitsPerSample - innerBitOffset & bitMask;
846
+ } else if (innerBitOffset + bitsPerSample <= 16) {
847
+ outArray[outIndex] = view.getUint16(byteOffset) >> 16 - bitsPerSample - innerBitOffset & bitMask;
848
+ } else if (innerBitOffset + bitsPerSample <= 24) {
849
+ const raw = view.getUint16(byteOffset) << 8 | view.getUint8(byteOffset + 2);
850
+ outArray[outIndex] = raw >> 24 - bitsPerSample - innerBitOffset & bitMask;
851
+ } else {
852
+ outArray[outIndex] = view.getUint32(byteOffset) >> 32 - bitsPerSample - innerBitOffset & bitMask;
853
+ }
854
+ }
855
+ }
856
+ }
857
+ } else if (format === 3) {
858
+ }
859
+ return outArray.buffer;
860
+ }
861
+ var GeoTIFFImage = class {
862
+ /**
863
+ * @constructor
864
+ * @param {import("./imagefiledirectory.js").ImageFileDirectory} fileDirectory The parsed file directory
865
+ * @param {Boolean} littleEndian Whether the file is encoded in little or big endian
866
+ * @param {Boolean} cache Whether or not decoded tiles shall be cached
867
+ * @param {import('./source/basesource.js').BaseSource} source The datasource to read from
868
+ */
869
+ constructor(fileDirectory, littleEndian, cache, source) {
870
+ this.fileDirectory = fileDirectory;
871
+ this.littleEndian = littleEndian;
872
+ this.tiles = cache ? [] : null;
873
+ this.isTiled = !fileDirectory.hasTag("StripOffsets");
874
+ const planarConfiguration = fileDirectory.getValue("PlanarConfiguration") ?? 1;
875
+ if (planarConfiguration !== 1 && planarConfiguration !== 2) {
876
+ throw new Error("Invalid planar configuration.");
877
+ }
878
+ this.planarConfiguration = planarConfiguration;
879
+ this.source = source;
880
+ }
881
+ /**
882
+ * Returns the associated parsed file directory.
883
+ * @returns {import("./imagefiledirectory.js").ImageFileDirectory} the parsed file directory
884
+ */
885
+ getFileDirectory() {
886
+ return this.fileDirectory;
887
+ }
888
+ /**
889
+ * Returns the associated parsed geo keys.
890
+ * @returns {Partial<Record<import('./globals.js').GeoKeyName, *>>|null} the parsed geo keys
891
+ */
892
+ getGeoKeys() {
893
+ return this.fileDirectory.parseGeoKeyDirectory();
894
+ }
895
+ /**
896
+ * Returns the width of the image.
897
+ * @returns {Number} the width of the image
898
+ */
899
+ getWidth() {
900
+ return this.fileDirectory.getValue("ImageWidth") || 0;
901
+ }
902
+ /**
903
+ * Returns the height of the image.
904
+ * @returns {Number} the height of the image
905
+ */
906
+ getHeight() {
907
+ return this.fileDirectory.getValue("ImageLength") || 0;
908
+ }
909
+ /**
910
+ * Returns the number of samples per pixel.
911
+ * @returns {number} the number of samples per pixel
912
+ */
913
+ getSamplesPerPixel() {
914
+ return this.fileDirectory.getValue("SamplesPerPixel") ?? 1;
915
+ }
916
+ /**
917
+ * Returns the width of each tile.
918
+ * @returns {number} the width of each tile
919
+ */
920
+ getTileWidth() {
921
+ return this.isTiled ? this.fileDirectory.getValue("TileWidth") || 0 : this.getWidth();
922
+ }
923
+ /**
924
+ * Returns the height of each tile.
925
+ * @returns {number} the height of each tile
926
+ */
927
+ getTileHeight() {
928
+ if (this.isTiled) {
929
+ return this.fileDirectory.getValue("TileLength") || 0;
930
+ }
931
+ const rowsPerStrip = this.fileDirectory.hasTag("RowsPerStrip") && this.fileDirectory.getValue("RowsPerStrip");
932
+ if (rowsPerStrip) {
933
+ return Math.min(rowsPerStrip, this.getHeight());
934
+ }
935
+ return this.getHeight();
936
+ }
937
+ getBlockWidth() {
938
+ return this.getTileWidth();
939
+ }
940
+ /**
941
+ * @param {number} y
942
+ * @returns {number}
943
+ */
944
+ getBlockHeight(y) {
945
+ if (this.isTiled || (y + 1) * this.getTileHeight() <= this.getHeight()) {
946
+ return this.getTileHeight();
947
+ } else {
948
+ return this.getHeight() - y * this.getTileHeight();
949
+ }
950
+ }
951
+ /**
952
+ * Calculates the number of bytes for each pixel across all samples. Only full
953
+ * bytes are supported, an exception is thrown when this is not the case.
954
+ * @returns {Number} the bytes per pixel
955
+ */
956
+ getBytesPerPixel() {
957
+ let bytes = 0;
958
+ const bitsPerSample = this.fileDirectory.getValue("BitsPerSample") || [];
959
+ for (let i = 0; i < bitsPerSample.length; ++i) {
960
+ bytes += this.getSampleByteSize(i);
961
+ }
962
+ return bytes;
963
+ }
964
+ /**
965
+ * @param {number} i
966
+ * @returns {number}
967
+ */
968
+ getSampleByteSize(i) {
969
+ const bitsPerSample = this.fileDirectory.getValue("BitsPerSample") || [];
970
+ if (i >= bitsPerSample.length) {
971
+ throw new RangeError(`Sample index ${i} is out of range.`);
972
+ }
973
+ return Math.ceil(bitsPerSample[i] / 8);
974
+ }
975
+ /**
976
+ * @param {number} sampleIndex
977
+ * @returns {(this: DataView, byteOffset: number, littleEndian: boolean) => number}
978
+ */
979
+ getReaderForSample(sampleIndex) {
980
+ const sampleFormat = this.fileDirectory.getValue("SampleFormat");
981
+ const format = sampleFormat ? sampleFormat[sampleIndex] : 1;
982
+ const bitsPerSample = (this.fileDirectory.getValue("BitsPerSample") || [])[sampleIndex];
983
+ switch (format) {
984
+ case 1:
985
+ if (bitsPerSample <= 8) {
986
+ return DataView.prototype.getUint8;
987
+ } else if (bitsPerSample <= 16) {
988
+ return DataView.prototype.getUint16;
989
+ } else if (bitsPerSample <= 32) {
990
+ return DataView.prototype.getUint32;
991
+ }
992
+ break;
993
+ case 2:
994
+ if (bitsPerSample <= 8) {
995
+ return DataView.prototype.getInt8;
996
+ } else if (bitsPerSample <= 16) {
997
+ return DataView.prototype.getInt16;
998
+ } else if (bitsPerSample <= 32) {
999
+ return DataView.prototype.getInt32;
1000
+ }
1001
+ break;
1002
+ case 3:
1003
+ switch (bitsPerSample) {
1004
+ case 16:
1005
+ return function(offset, littleEndian) {
1006
+ return getFloat16(this, offset, littleEndian);
1007
+ };
1008
+ case 32:
1009
+ return DataView.prototype.getFloat32;
1010
+ case 64:
1011
+ return DataView.prototype.getFloat64;
1012
+ default:
1013
+ break;
1014
+ }
1015
+ break;
1016
+ default:
1017
+ break;
1018
+ }
1019
+ throw Error("Unsupported data format/bitsPerSample");
1020
+ }
1021
+ getSampleFormat(sampleIndex = 0) {
1022
+ const sampleFormat = this.fileDirectory.getValue("SampleFormat");
1023
+ return sampleFormat ? sampleFormat[sampleIndex] : 1;
1024
+ }
1025
+ getBitsPerSample(sampleIndex = 0) {
1026
+ const bitsPerSample = this.fileDirectory.getValue("BitsPerSample");
1027
+ return bitsPerSample ? bitsPerSample[sampleIndex] : 0;
1028
+ }
1029
+ /**
1030
+ * @param {number} sampleIndex
1031
+ * @param {number|ArrayBufferLike} sizeOrData
1032
+ * @returns {TypedArray}
1033
+ */
1034
+ getArrayForSample(sampleIndex, sizeOrData) {
1035
+ const format = (
1036
+ /** @type {1|2|3} */
1037
+ this.getSampleFormat(sampleIndex)
1038
+ );
1039
+ const bitsPerSample = this.getBitsPerSample(sampleIndex);
1040
+ return arrayForType(format, bitsPerSample, sizeOrData);
1041
+ }
1042
+ /**
1043
+ * Returns the decoded strip or tile.
1044
+ * @param {Number} x the strip or tile x-offset
1045
+ * @param {Number} y the tile y-offset (0 for stripped images)
1046
+ * @param {Number} sample the sample to get for separated samples
1047
+ * @param {DecoderWorker|import("./geotiff.js").BaseDecoder} poolOrDecoder the decoder or decoder pool
1048
+ * @param {AbortSignal} [signal] An AbortSignal that may be signalled if the request is
1049
+ * to be aborted
1050
+ * @returns {Promise.<{x: number, y: number, sample: number, data: ArrayBufferLike}>} the decoded strip or tile
1051
+ */
1052
+ async getTileOrStrip(x, y, sample, poolOrDecoder, signal) {
1053
+ const numTilesPerRow = Math.ceil(this.getWidth() / this.getTileWidth());
1054
+ const numTilesPerCol = Math.ceil(this.getHeight() / this.getTileHeight());
1055
+ let index;
1056
+ const { tiles } = this;
1057
+ if (this.planarConfiguration === 1) {
1058
+ index = y * numTilesPerRow + x;
1059
+ } else if (this.planarConfiguration === 2) {
1060
+ index = sample * numTilesPerRow * numTilesPerCol + y * numTilesPerRow + x;
1061
+ }
1062
+ if (index === void 0) {
1063
+ throw new Error("Could not determine tile or strip index.");
1064
+ }
1065
+ let offset;
1066
+ let byteCount;
1067
+ if (this.isTiled) {
1068
+ offset = Number(await this.fileDirectory.loadValueIndexed("TileOffsets", index));
1069
+ byteCount = Number(await this.fileDirectory.loadValueIndexed("TileByteCounts", index));
1070
+ } else {
1071
+ offset = Number(await this.fileDirectory.loadValueIndexed("StripOffsets", index));
1072
+ byteCount = Number(await this.fileDirectory.loadValueIndexed("StripByteCounts", index));
1073
+ }
1074
+ if (byteCount === 0) {
1075
+ const nPixels = this.getBlockHeight(y) * this.getTileWidth();
1076
+ const bytesPerPixel = this.planarConfiguration === 2 ? this.getSampleByteSize(sample) : this.getBytesPerPixel();
1077
+ const data = new ArrayBuffer(nPixels * bytesPerPixel);
1078
+ const view = this.getArrayForSample(sample, data);
1079
+ view.fill(this.getGDALNoData() || 0);
1080
+ return { x, y, sample, data };
1081
+ }
1082
+ const slice = (await this.source.fetch([{ offset, length: byteCount }], signal))[0];
1083
+ let request;
1084
+ if (tiles === null || !tiles[index]) {
1085
+ request = (async () => {
1086
+ let data = await poolOrDecoder.decode(slice);
1087
+ const sampleFormat = (
1088
+ /** @type {1|2|3} */
1089
+ this.getSampleFormat()
1090
+ );
1091
+ const bitsPerSample = this.getBitsPerSample();
1092
+ if (needsNormalization(sampleFormat, bitsPerSample)) {
1093
+ data = normalizeArray(data, sampleFormat, this.planarConfiguration, this.getSamplesPerPixel(), bitsPerSample, this.getTileWidth(), this.getBlockHeight(y));
1094
+ }
1095
+ return data;
1096
+ })();
1097
+ if (tiles !== null) {
1098
+ tiles[index] = request;
1099
+ }
1100
+ } else {
1101
+ request = tiles[index];
1102
+ }
1103
+ return { x, y, sample, data: await request };
1104
+ }
1105
+ /**
1106
+ * Internal read function.
1107
+ * @private
1108
+ * @param {Array<number>} imageWindow The image window in pixel coordinates
1109
+ * @param {Array<number>} samples The selected samples (0-based indices)
1110
+ * @param {TypedArray|TypedArray[]} valueArrays The array(s) to write into
1111
+ * @param {boolean|undefined} interleave Whether or not to write in an interleaved manner
1112
+ * @param {DecoderWorker|import("./geotiff.js").BaseDecoder} poolOrDecoder the decoder or decoder pool
1113
+ * @param {number} [width] the width of window to be read into
1114
+ * @param {number} [height] the height of window to be read into
1115
+ * @param {string} [resampleMethod] the resampling method to be used when interpolating
1116
+ * @param {AbortSignal} [signal] An AbortSignal that may be signalled if the request is
1117
+ * to be aborted
1118
+ * @returns {Promise<ReadRasterResult>}
1119
+ */
1120
+ async _readRaster(imageWindow, samples, valueArrays, interleave, poolOrDecoder, width, height, resampleMethod, signal) {
1121
+ const tileWidth = this.getTileWidth();
1122
+ const tileHeight = this.getTileHeight();
1123
+ const imageWidth = this.getWidth();
1124
+ const imageHeight = this.getHeight();
1125
+ const minXTile = Math.max(Math.floor(imageWindow[0] / tileWidth), 0);
1126
+ const maxXTile = Math.min(Math.ceil(imageWindow[2] / tileWidth), Math.ceil(imageWidth / tileWidth));
1127
+ const minYTile = Math.max(Math.floor(imageWindow[1] / tileHeight), 0);
1128
+ const maxYTile = Math.min(Math.ceil(imageWindow[3] / tileHeight), Math.ceil(imageHeight / tileHeight));
1129
+ const windowWidth = imageWindow[2] - imageWindow[0];
1130
+ let bytesPerPixel = this.getBytesPerPixel();
1131
+ const srcSampleOffsets = [];
1132
+ const sampleReaders = [];
1133
+ for (let i = 0; i < samples.length; ++i) {
1134
+ if (this.planarConfiguration === 1) {
1135
+ const bitsPerSample = await this.fileDirectory.loadValue("BitsPerSample");
1136
+ if (typeof bitsPerSample !== "object") {
1137
+ throw new Error("Expected BitsPerSample to be an array or typed array.");
1138
+ }
1139
+ srcSampleOffsets.push(sum(bitsPerSample, 0, samples[i]) / 8);
1140
+ } else {
1141
+ srcSampleOffsets.push(0);
1142
+ }
1143
+ sampleReaders.push(this.getReaderForSample(samples[i]));
1144
+ }
1145
+ const promises = [];
1146
+ const { littleEndian } = this;
1147
+ for (let yTile = minYTile; yTile < maxYTile; ++yTile) {
1148
+ for (let xTile = minXTile; xTile < maxXTile; ++xTile) {
1149
+ let getPromise;
1150
+ if (this.planarConfiguration === 1) {
1151
+ getPromise = this.getTileOrStrip(xTile, yTile, 0, poolOrDecoder, signal);
1152
+ }
1153
+ for (let sampleIndex = 0; sampleIndex < samples.length; ++sampleIndex) {
1154
+ const si = sampleIndex;
1155
+ const sample = samples[sampleIndex];
1156
+ if (this.planarConfiguration === 2) {
1157
+ bytesPerPixel = this.getSampleByteSize(sample);
1158
+ getPromise = this.getTileOrStrip(xTile, yTile, sample, poolOrDecoder, signal);
1159
+ }
1160
+ if (!getPromise) {
1161
+ throw new Error("Could not get tile or strip data.");
1162
+ }
1163
+ const promise = getPromise.then((tile) => {
1164
+ const buffer2 = tile.data;
1165
+ const dataView = new DataView(buffer2);
1166
+ const blockHeight = this.getBlockHeight(tile.y);
1167
+ const firstLine = tile.y * tileHeight;
1168
+ const firstCol = tile.x * tileWidth;
1169
+ const lastLine = firstLine + blockHeight;
1170
+ const lastCol = (tile.x + 1) * tileWidth;
1171
+ const reader = sampleReaders[si];
1172
+ const ymax = Math.min(blockHeight, blockHeight - (lastLine - imageWindow[3]), imageHeight - firstLine);
1173
+ const xmax = Math.min(tileWidth, tileWidth - (lastCol - imageWindow[2]), imageWidth - firstCol);
1174
+ for (let y = Math.max(0, imageWindow[1] - firstLine); y < ymax; ++y) {
1175
+ for (let x = Math.max(0, imageWindow[0] - firstCol); x < xmax; ++x) {
1176
+ const pixelOffset = (y * tileWidth + x) * bytesPerPixel;
1177
+ const value = reader.call(dataView, pixelOffset + srcSampleOffsets[si], littleEndian);
1178
+ let windowCoordinate;
1179
+ if (interleave) {
1180
+ windowCoordinate = (y + firstLine - imageWindow[1]) * windowWidth * samples.length + (x + firstCol - imageWindow[0]) * samples.length + si;
1181
+ valueArrays[windowCoordinate] = value;
1182
+ } else {
1183
+ windowCoordinate = (y + firstLine - imageWindow[1]) * windowWidth + x + firstCol - imageWindow[0];
1184
+ valueArrays[si][windowCoordinate] = value;
1185
+ }
1186
+ }
1187
+ }
1188
+ });
1189
+ promises.push(promise);
1190
+ }
1191
+ }
1192
+ }
1193
+ await Promise.all(promises);
1194
+ if (width && imageWindow[2] - imageWindow[0] !== width || height && imageWindow[3] - imageWindow[1] !== height) {
1195
+ let resampled;
1196
+ if (interleave) {
1197
+ resampled = resampleInterleaved(
1198
+ /** @type {TypedArray} */
1199
+ valueArrays,
1200
+ imageWindow[2] - imageWindow[0],
1201
+ imageWindow[3] - imageWindow[1],
1202
+ /** @type {number} */
1203
+ width,
1204
+ /** @type {number} */
1205
+ height,
1206
+ samples.length,
1207
+ resampleMethod
1208
+ );
1209
+ } else {
1210
+ resampled = resample(
1211
+ /** @type {TypedArray[]} */
1212
+ valueArrays,
1213
+ imageWindow[2] - imageWindow[0],
1214
+ imageWindow[3] - imageWindow[1],
1215
+ /** @type {number} */
1216
+ width,
1217
+ /** @type {number} */
1218
+ height,
1219
+ resampleMethod
1220
+ );
1221
+ }
1222
+ const resampledWithDimensions = (
1223
+ /** @type {ReadRasterResult} */
1224
+ resampled
1225
+ );
1226
+ resampledWithDimensions.width = width ?? imageWindow[2] - imageWindow[0];
1227
+ resampledWithDimensions.height = height ?? imageWindow[3] - imageWindow[1];
1228
+ return resampledWithDimensions;
1229
+ }
1230
+ const valueArraysWithDimensions = (
1231
+ /** @type {ReadRasterResult} */
1232
+ valueArrays
1233
+ );
1234
+ valueArraysWithDimensions.width = width || imageWindow[2] - imageWindow[0];
1235
+ valueArraysWithDimensions.height = height || imageWindow[3] - imageWindow[1];
1236
+ return valueArraysWithDimensions;
1237
+ }
1238
+ /**
1239
+ * @overload
1240
+ * @param {ReadRastersOptions & {interleave: true}} options optional parameters
1241
+ * @returns {Promise<import("./geotiff.js").TypedArrayWithDimensions>} the decoded arrays as a promise
1242
+ */
1243
+ /**
1244
+ * @overload
1245
+ * @param {ReadRastersOptions & {interleave: false}} options optional parameters
1246
+ * @returns {Promise<import("./geotiff.js").TypedArrayArrayWithDimensions>} the decoded arrays as a promise
1247
+ */
1248
+ /**
1249
+ * @overload
1250
+ * @param {ReadRastersOptions & {interleave: boolean}} options optional parameters
1251
+ * @returns {Promise<ReadRasterResult>} the decoded arrays as a promise
1252
+ */
1253
+ /**
1254
+ * @overload
1255
+ * @param {ReadRastersOptions} [options={}] optional parameters
1256
+ * @returns {Promise<import("./geotiff.js").TypedArrayArrayWithDimensions>} the decoded arrays as a promise
1257
+ */
1258
+ /**
1259
+ * Reads raster data from the image. This function reads all selected samples
1260
+ * into separate arrays of the correct type for that sample or into a single
1261
+ * combined array when `interleave` is set. When provided, only a subset
1262
+ * of the raster is read for each sample.
1263
+ *
1264
+ * @param {ReadRastersOptions} [options={}] optional parameters
1265
+ * @returns {Promise<ReadRasterResult>} the decoded arrays as a promise
1266
+ */
1267
+ async readRasters(options = {}) {
1268
+ const { window: wnd, samples = [], pool = null, width, height, resampleMethod, fillValue, signal } = options;
1269
+ const interleave = "interleave" in options && options.interleave;
1270
+ const imageWindow = wnd || [0, 0, this.getWidth(), this.getHeight()];
1271
+ if (imageWindow[0] > imageWindow[2] || imageWindow[1] > imageWindow[3]) {
1272
+ throw new Error("Invalid subsets");
1273
+ }
1274
+ const imageWindowWidth = imageWindow[2] - imageWindow[0];
1275
+ const imageWindowHeight = imageWindow[3] - imageWindow[1];
1276
+ const numPixels = imageWindowWidth * imageWindowHeight;
1277
+ const samplesPerPixel = this.getSamplesPerPixel();
1278
+ if (!samples || !samples.length) {
1279
+ for (let i = 0; i < samplesPerPixel; ++i) {
1280
+ samples.push(i);
1281
+ }
1282
+ } else {
1283
+ for (let i = 0; i < samples.length; ++i) {
1284
+ if (samples[i] >= samplesPerPixel) {
1285
+ return Promise.reject(new RangeError(`Invalid sample index '${samples[i]}'.`));
1286
+ }
1287
+ }
1288
+ }
1289
+ let valueArrays;
1290
+ if (interleave) {
1291
+ const { fileDirectory } = this;
1292
+ const sampleFormat = fileDirectory.getValue("SampleFormat");
1293
+ const format = sampleFormat ? Math.max.apply(null, Array.from(sampleFormat)) : 1;
1294
+ if (format !== 1 && format !== 2 && format !== 3) {
1295
+ throw new Error("Unsupported sample format for interleaved data. Must be 1, 2, or 3.");
1296
+ }
1297
+ const bitsPerSample_ = fileDirectory.getValue("BitsPerSample");
1298
+ const bitsPerSample = bitsPerSample_ ? Math.max.apply(null, Array.from(bitsPerSample_)) : 8;
1299
+ valueArrays = arrayForType(format, bitsPerSample, numPixels * samples.length);
1300
+ if (fillValue) {
1301
+ if (Array.isArray(fillValue)) {
1302
+ throw new Error("When reading interleaved data, fillValue must be a single number.");
1303
+ }
1304
+ valueArrays.fill(fillValue);
1305
+ }
1306
+ } else {
1307
+ valueArrays = [];
1308
+ for (let i = 0; i < samples.length; ++i) {
1309
+ const valueArray = this.getArrayForSample(samples[i], numPixels);
1310
+ if (Array.isArray(fillValue) && i < fillValue.length) {
1311
+ valueArray.fill(fillValue[i]);
1312
+ } else if (fillValue && !Array.isArray(fillValue)) {
1313
+ valueArray.fill(fillValue);
1314
+ }
1315
+ valueArrays.push(valueArray);
1316
+ }
1317
+ }
1318
+ const compression = this.fileDirectory.getValue("Compression") || 1;
1319
+ const decoderParameters = await getDecoderParameters(compression, this.fileDirectory);
1320
+ const poolOrDecoder = pool ? pool.bindParameters(compression, decoderParameters) : await getDecoder(compression, decoderParameters);
1321
+ const result = await this._readRaster(imageWindow, samples, valueArrays, interleave, poolOrDecoder, width, height, resampleMethod, signal);
1322
+ return result;
1323
+ }
1324
+ /**
1325
+ * @overload
1326
+ * @param {ReadRGBOptions & {interleave: true}} options optional parameters
1327
+ * @returns {Promise<import("./geotiff.js").TypedArrayWithDimensions>} the RGB array as a Promise
1328
+ */
1329
+ /**
1330
+ * @overload
1331
+ * @param {ReadRGBOptions & {interleave: false}} options optional parameters
1332
+ * @returns {Promise<import("./geotiff.js").TypedArrayArrayWithDimensions>} the RGB array as a Promise
1333
+ */
1334
+ /**
1335
+ * @overload
1336
+ * @param {ReadRGBOptions & {interleave: boolean}} options optional parameters
1337
+ * @returns {Promise<ReadRasterResult>} the RGB array as a Promise
1338
+ */
1339
+ /**
1340
+ * @overload
1341
+ * @param {ReadRGBOptions} [options={}] optional parameters
1342
+ * @returns {Promise<import("./geotiff.js").TypedArrayArrayWithDimensions>} the RGB array as a Promise
1343
+ */
1344
+ /**
1345
+ * Reads raster data from the image as RGB.
1346
+ * Colorspaces other than RGB will be transformed to RGB, color maps expanded.
1347
+ * When no other method is applicable, the first sample is used to produce a
1348
+ * grayscale image.
1349
+ * When provided, only a subset of the raster is read for each sample.
1350
+ *
1351
+ * @param {ReadRGBOptions} [options] optional parameters
1352
+ * @returns {Promise<ReadRasterResult>} the RGB array as a Promise
1353
+ */
1354
+ async readRGB(options = {}) {
1355
+ const { window, pool = null, width, height, resampleMethod, enableAlpha = false, signal } = options;
1356
+ const interleave = ("interleave" in options && options.interleave) ?? false;
1357
+ const imageWindow = window || [0, 0, this.getWidth(), this.getHeight()];
1358
+ if (imageWindow[0] > imageWindow[2] || imageWindow[1] > imageWindow[3]) {
1359
+ throw new Error("Invalid subsets");
1360
+ }
1361
+ const pi = this.fileDirectory.getValue("PhotometricInterpretation");
1362
+ if (pi === photometricInterpretations.RGB) {
1363
+ let s = [0, 1, 2];
1364
+ const extraSamples = this.fileDirectory.getValue("ExtraSamples");
1365
+ if (extraSamples && extraSamples[0] !== ExtraSamplesValues.Unspecified && enableAlpha) {
1366
+ s = [];
1367
+ const bitsPerSample = this.fileDirectory.getValue("BitsPerSample") || [];
1368
+ for (let i = 0; i < bitsPerSample.length; i += 1) {
1369
+ s.push(i);
1370
+ }
1371
+ }
1372
+ return this.readRasters({
1373
+ window,
1374
+ interleave,
1375
+ samples: s,
1376
+ pool,
1377
+ width,
1378
+ height,
1379
+ resampleMethod,
1380
+ signal
1381
+ });
1382
+ }
1383
+ let samples;
1384
+ switch (pi) {
1385
+ case photometricInterpretations.WhiteIsZero:
1386
+ case photometricInterpretations.BlackIsZero:
1387
+ case photometricInterpretations.Palette:
1388
+ samples = [0];
1389
+ break;
1390
+ case photometricInterpretations.CMYK:
1391
+ samples = [0, 1, 2, 3];
1392
+ break;
1393
+ case photometricInterpretations.YCbCr:
1394
+ case photometricInterpretations.CIELab:
1395
+ samples = [0, 1, 2];
1396
+ break;
1397
+ default:
1398
+ throw new Error("Invalid or unsupported photometric interpretation.");
1399
+ }
1400
+ const subOptions = {
1401
+ window: imageWindow,
1402
+ /** @type {true} */
1403
+ interleave: true,
1404
+ samples,
1405
+ pool,
1406
+ width,
1407
+ height,
1408
+ resampleMethod,
1409
+ signal
1410
+ };
1411
+ const { fileDirectory } = this;
1412
+ const raster = await this.readRasters(subOptions);
1413
+ const max = 2 ** this.getBitsPerSample(0);
1414
+ let data;
1415
+ switch (pi) {
1416
+ case photometricInterpretations.WhiteIsZero:
1417
+ data = fromWhiteIsZero(raster, max);
1418
+ break;
1419
+ case photometricInterpretations.BlackIsZero:
1420
+ data = fromBlackIsZero(raster, max);
1421
+ break;
1422
+ case photometricInterpretations.Palette:
1423
+ data = fromPalette(
1424
+ raster,
1425
+ /** @type {Uint16Array} */
1426
+ await fileDirectory.loadValue("ColorMap")
1427
+ );
1428
+ break;
1429
+ case photometricInterpretations.CMYK:
1430
+ data = fromCMYK(raster);
1431
+ break;
1432
+ case photometricInterpretations.YCbCr:
1433
+ data = fromYCbCr(raster);
1434
+ break;
1435
+ case photometricInterpretations.CIELab:
1436
+ data = fromCIELab(raster);
1437
+ break;
1438
+ default:
1439
+ throw new Error("Unsupported photometric interpretation.");
1440
+ }
1441
+ if (!interleave) {
1442
+ const red = new Uint8Array(data.length / 3);
1443
+ const green = new Uint8Array(data.length / 3);
1444
+ const blue = new Uint8Array(data.length / 3);
1445
+ for (let i = 0, j = 0; i < data.length; i += 3, ++j) {
1446
+ red[j] = data[i];
1447
+ green[j] = data[i + 1];
1448
+ blue[j] = data[i + 2];
1449
+ }
1450
+ data = [red, green, blue];
1451
+ }
1452
+ const dataWithDimensions = (
1453
+ /** @type {import("./geotiff.js").ReadRasterResult} */
1454
+ data
1455
+ );
1456
+ dataWithDimensions.width = raster.width;
1457
+ dataWithDimensions.height = raster.height;
1458
+ return dataWithDimensions;
1459
+ }
1460
+ /**
1461
+ * Returns an array of tiepoints.
1462
+ * @returns {Promise<Array<{i: number, j: number, k: number, x: number, y: number, z: number}>>} the tiepoints
1463
+ */
1464
+ async getTiePoints() {
1465
+ if (!this.fileDirectory.hasTag("ModelTiepoint")) {
1466
+ return [];
1467
+ }
1468
+ const modelTiePoint = await this.fileDirectory.loadValue("ModelTiepoint");
1469
+ if (typeof modelTiePoint !== "object") {
1470
+ throw new Error("Expected ModelTiepoint to be an array or typed array.");
1471
+ }
1472
+ const tiePoints = [];
1473
+ for (let i = 0; i < modelTiePoint.length; i += 6) {
1474
+ tiePoints.push({
1475
+ i: modelTiePoint[i],
1476
+ j: modelTiePoint[i + 1],
1477
+ k: modelTiePoint[i + 2],
1478
+ x: modelTiePoint[i + 3],
1479
+ y: modelTiePoint[i + 4],
1480
+ z: modelTiePoint[i + 5]
1481
+ });
1482
+ }
1483
+ return tiePoints;
1484
+ }
1485
+ /**
1486
+ * Returns the parsed GDAL metadata items.
1487
+ *
1488
+ * If sample is passed to null, dataset-level metadata will be returned.
1489
+ * Otherwise only metadata specific to the provided sample will be returned.
1490
+ *
1491
+ * @param {number|null} [sample=null] The sample index.
1492
+ * @returns {Promise<Record<string, unknown>|null>} The GDAL metadata items
1493
+ */
1494
+ async getGDALMetadata(sample = null) {
1495
+ const metadata = {};
1496
+ if (!this.fileDirectory.hasTag("GDAL_METADATA")) {
1497
+ return null;
1498
+ }
1499
+ const string = await this.fileDirectory.loadValue("GDAL_METADATA");
1500
+ let items = findTagsByName(string, "Item");
1501
+ if (sample === null) {
1502
+ items = items.filter((item) => getAttribute(item, "sample") === void 0);
1503
+ } else {
1504
+ items = items.filter((item) => Number(getAttribute(item, "sample")) === sample);
1505
+ }
1506
+ for (let i = 0; i < items.length; ++i) {
1507
+ const item = items[i];
1508
+ metadata[getAttribute(item, "name")] = item.inner;
1509
+ }
1510
+ return metadata;
1511
+ }
1512
+ /**
1513
+ * Returns the GDAL nodata value
1514
+ * @returns {number|null}
1515
+ */
1516
+ getGDALNoData() {
1517
+ const string = this.fileDirectory.hasTag("GDAL_NODATA") && this.fileDirectory.getValue("GDAL_NODATA");
1518
+ if (!string) {
1519
+ return null;
1520
+ }
1521
+ return Number(string.substring(0, string.length - 1));
1522
+ }
1523
+ /**
1524
+ * Returns the image origin as a XYZ-vector. When the image has no affine
1525
+ * transformation, then an exception is thrown.
1526
+ * @returns {Array<number>} The origin as a vector
1527
+ */
1528
+ getOrigin() {
1529
+ const tiePoints = this.fileDirectory.getValue("ModelTiepoint");
1530
+ const modelTransformation = this.fileDirectory.getValue("ModelTransformation");
1531
+ if (tiePoints && tiePoints.length === 6) {
1532
+ return [
1533
+ tiePoints[3],
1534
+ tiePoints[4],
1535
+ tiePoints[5]
1536
+ ];
1537
+ }
1538
+ if (modelTransformation) {
1539
+ return [
1540
+ modelTransformation[3],
1541
+ modelTransformation[7],
1542
+ modelTransformation[11]
1543
+ ];
1544
+ }
1545
+ throw new Error("The image does not have an affine transformation.");
1546
+ }
1547
+ /**
1548
+ * Returns the image resolution as a XYZ-vector. When the image has no affine
1549
+ * transformation, then an exception is thrown.
1550
+ * @param {GeoTIFFImage|null} [referenceImage=null] A reference image to calculate the resolution from
1551
+ * in cases when the current image does not have the
1552
+ * required tags on its own.
1553
+ * @returns {Array<number>} The resolution as a vector
1554
+ */
1555
+ getResolution(referenceImage = null) {
1556
+ const modelPixelScale = this.fileDirectory.getValue("ModelPixelScale");
1557
+ const modelTransformation = this.fileDirectory.getValue("ModelTransformation");
1558
+ if (modelPixelScale) {
1559
+ return [
1560
+ modelPixelScale[0],
1561
+ -modelPixelScale[1],
1562
+ modelPixelScale[2]
1563
+ ];
1564
+ }
1565
+ if (modelTransformation) {
1566
+ if (modelTransformation[1] === 0 && modelTransformation[4] === 0) {
1567
+ return [
1568
+ modelTransformation[0],
1569
+ -modelTransformation[5],
1570
+ modelTransformation[10]
1571
+ ];
1572
+ }
1573
+ return [
1574
+ Math.sqrt(modelTransformation[0] * modelTransformation[0] + modelTransformation[4] * modelTransformation[4]),
1575
+ -Math.sqrt(modelTransformation[1] * modelTransformation[1] + modelTransformation[5] * modelTransformation[5]),
1576
+ modelTransformation[10]
1577
+ ];
1578
+ }
1579
+ if (referenceImage) {
1580
+ const [refResX, refResY, refResZ] = referenceImage.getResolution();
1581
+ return [
1582
+ refResX * referenceImage.getWidth() / this.getWidth(),
1583
+ refResY * referenceImage.getHeight() / this.getHeight(),
1584
+ refResZ * referenceImage.getWidth() / this.getWidth()
1585
+ ];
1586
+ }
1587
+ throw new Error("The image does not have an affine transformation.");
1588
+ }
1589
+ /**
1590
+ * Returns whether or not the pixels of the image depict an area (or point).
1591
+ * @returns {Boolean} Whether the pixels are a point
1592
+ */
1593
+ pixelIsArea() {
1594
+ return this.getGeoKeys()?.GTRasterTypeGeoKey === 1;
1595
+ }
1596
+ /**
1597
+ * Returns the image bounding box as an array of 4 values: min-x, min-y,
1598
+ * max-x and max-y. When the image has no affine transformation, then an
1599
+ * exception is thrown.
1600
+ * @param {boolean} [tilegrid=false] If true return extent for a tilegrid
1601
+ * without adjustment for ModelTransformation.
1602
+ * @returns {Array<number>} The bounding box
1603
+ */
1604
+ getBoundingBox(tilegrid = false) {
1605
+ const height = this.getHeight();
1606
+ const width = this.getWidth();
1607
+ const modelTransformation = this.fileDirectory.getValue("ModelTransformation");
1608
+ if (modelTransformation && !tilegrid) {
1609
+ const [a, b, , d, e, f, , h] = modelTransformation;
1610
+ const corners = [
1611
+ [0, 0],
1612
+ [0, height],
1613
+ [width, 0],
1614
+ [width, height]
1615
+ ];
1616
+ const projected = corners.map(([I, J]) => [
1617
+ d + a * I + b * J,
1618
+ h + e * I + f * J
1619
+ ]);
1620
+ const xs = projected.map((pt) => pt[0]);
1621
+ const ys = projected.map((pt) => pt[1]);
1622
+ return [
1623
+ Math.min(...xs),
1624
+ Math.min(...ys),
1625
+ Math.max(...xs),
1626
+ Math.max(...ys)
1627
+ ];
1628
+ } else {
1629
+ const origin = this.getOrigin();
1630
+ const resolution = this.getResolution();
1631
+ const x1 = origin[0];
1632
+ const y1 = origin[1];
1633
+ const x2 = x1 + resolution[0] * width;
1634
+ const y2 = y1 + resolution[1] * height;
1635
+ return [
1636
+ Math.min(x1, x2),
1637
+ Math.min(y1, y2),
1638
+ Math.max(x1, x2),
1639
+ Math.max(y1, y2)
1640
+ ];
1641
+ }
1642
+ }
1643
+ };
1644
+ var geotiffimage_default = GeoTIFFImage;
1645
+
1646
+ // ../../node_modules/.pnpm/geotiff@3.0.5/node_modules/geotiff/dist-module/dataview64.js
1647
+ var DataView64 = class {
1648
+ /**
1649
+ * @param {ArrayBufferLike} arrayBuffer
1650
+ */
1651
+ constructor(arrayBuffer) {
1652
+ this._dataView = new DataView(arrayBuffer);
1653
+ }
1654
+ get buffer() {
1655
+ return this._dataView.buffer;
1656
+ }
1657
+ /**
1658
+ * @param {number} offset
1659
+ * @param {boolean} littleEndian
1660
+ * @returns {number}
1661
+ */
1662
+ getUint64(offset, littleEndian) {
1663
+ const left = this.getUint32(offset, littleEndian);
1664
+ const right = this.getUint32(offset + 4, littleEndian);
1665
+ let combined;
1666
+ if (littleEndian) {
1667
+ combined = left + 2 ** 32 * right;
1668
+ if (!Number.isSafeInteger(combined)) {
1669
+ throw new Error(`${combined} exceeds MAX_SAFE_INTEGER. Precision may be lost. Please report if you get this message to https://github.com/geotiffjs/geotiff.js/issues`);
1670
+ }
1671
+ return combined;
1672
+ }
1673
+ combined = 2 ** 32 * left + right;
1674
+ if (!Number.isSafeInteger(combined)) {
1675
+ throw new Error(`${combined} exceeds MAX_SAFE_INTEGER. Precision may be lost. Please report if you get this message to https://github.com/geotiffjs/geotiff.js/issues`);
1676
+ }
1677
+ return combined;
1678
+ }
1679
+ /**
1680
+ * Adapted from https://stackoverflow.com/a/55338384/8060591
1681
+ * @param {number} offset
1682
+ * @param {boolean} littleEndian
1683
+ * @returns {number}
1684
+ */
1685
+ getInt64(offset, littleEndian) {
1686
+ let value = 0;
1687
+ const isNegative = (this._dataView.getUint8(offset + (littleEndian ? 7 : 0)) & 128) > 0;
1688
+ let carrying = true;
1689
+ for (let i = 0; i < 8; i++) {
1690
+ let byte = this._dataView.getUint8(offset + (littleEndian ? i : 7 - i));
1691
+ if (isNegative) {
1692
+ if (carrying) {
1693
+ if (byte !== 0) {
1694
+ byte = ~(byte - 1) & 255;
1695
+ carrying = false;
1696
+ }
1697
+ } else {
1698
+ byte = ~byte & 255;
1699
+ }
1700
+ }
1701
+ value += byte * 256 ** i;
1702
+ }
1703
+ if (isNegative) {
1704
+ value = -value;
1705
+ }
1706
+ return value;
1707
+ }
1708
+ /**
1709
+ * @param {number} offset
1710
+ * @returns {number}
1711
+ */
1712
+ getUint8(offset) {
1713
+ return this._dataView.getUint8(offset);
1714
+ }
1715
+ /**
1716
+ * @param {number} offset
1717
+ * @returns {number}
1718
+ */
1719
+ getInt8(offset) {
1720
+ return this._dataView.getInt8(offset);
1721
+ }
1722
+ /**
1723
+ * @param {number} offset
1724
+ * @param {boolean} littleEndian
1725
+ * @returns {number}
1726
+ */
1727
+ getUint16(offset, littleEndian) {
1728
+ return this._dataView.getUint16(offset, littleEndian);
1729
+ }
1730
+ /**
1731
+ * @param {number} offset
1732
+ * @param {boolean} littleEndian
1733
+ * @returns {number}
1734
+ */
1735
+ getInt16(offset, littleEndian) {
1736
+ return this._dataView.getInt16(offset, littleEndian);
1737
+ }
1738
+ /**
1739
+ * @param {number} offset
1740
+ * @param {boolean} littleEndian
1741
+ * @returns {number}
1742
+ */
1743
+ getUint32(offset, littleEndian) {
1744
+ return this._dataView.getUint32(offset, littleEndian);
1745
+ }
1746
+ /**
1747
+ * @param {number} offset
1748
+ * @param {boolean} littleEndian
1749
+ * @returns {number}
1750
+ */
1751
+ getInt32(offset, littleEndian) {
1752
+ return this._dataView.getInt32(offset, littleEndian);
1753
+ }
1754
+ /**
1755
+ * @param {number} offset
1756
+ * @param {boolean} littleEndian
1757
+ * @returns {number}
1758
+ */
1759
+ getFloat16(offset, littleEndian) {
1760
+ return getFloat16(this._dataView, offset, littleEndian);
1761
+ }
1762
+ /**
1763
+ * @param {number} offset
1764
+ * @param {boolean} littleEndian
1765
+ * @returns {number}
1766
+ */
1767
+ getFloat32(offset, littleEndian) {
1768
+ return this._dataView.getFloat32(offset, littleEndian);
1769
+ }
1770
+ /**
1771
+ * @param {number} offset
1772
+ * @param {boolean} littleEndian
1773
+ * @returns {number}
1774
+ */
1775
+ getFloat64(offset, littleEndian) {
1776
+ return this._dataView.getFloat64(offset, littleEndian);
1777
+ }
1778
+ };
1779
+
1780
+ // ../../node_modules/.pnpm/geotiff@3.0.5/node_modules/geotiff/dist-module/dataslice.js
1781
+ var DataSlice = class {
1782
+ /**
1783
+ * @param {ArrayBufferLike} arrayBuffer
1784
+ * @param {number} sliceOffset
1785
+ * @param {boolean} littleEndian
1786
+ * @param {boolean} bigTiff
1787
+ */
1788
+ constructor(arrayBuffer, sliceOffset, littleEndian, bigTiff) {
1789
+ this._dataView = new DataView(arrayBuffer);
1790
+ this._sliceOffset = sliceOffset;
1791
+ this._littleEndian = littleEndian;
1792
+ this._bigTiff = bigTiff;
1793
+ }
1794
+ get sliceOffset() {
1795
+ return this._sliceOffset;
1796
+ }
1797
+ get sliceTop() {
1798
+ return this._sliceOffset + this.buffer.byteLength;
1799
+ }
1800
+ get littleEndian() {
1801
+ return this._littleEndian;
1802
+ }
1803
+ get bigTiff() {
1804
+ return this._bigTiff;
1805
+ }
1806
+ get buffer() {
1807
+ return this._dataView.buffer;
1808
+ }
1809
+ /**
1810
+ * @param {number} offset
1811
+ * @param {number} length
1812
+ * @returns {boolean}
1813
+ */
1814
+ covers(offset, length) {
1815
+ return this.sliceOffset <= offset && this.sliceTop >= offset + length;
1816
+ }
1817
+ /**
1818
+ * @param {number} offset
1819
+ * @returns {number}
1820
+ */
1821
+ readUint8(offset) {
1822
+ return this._dataView.getUint8(offset - this._sliceOffset);
1823
+ }
1824
+ /**
1825
+ * @param {number} offset
1826
+ * @returns {number}
1827
+ */
1828
+ readInt8(offset) {
1829
+ return this._dataView.getInt8(offset - this._sliceOffset);
1830
+ }
1831
+ /**
1832
+ * @param {number} offset
1833
+ * @returns {number}
1834
+ */
1835
+ readUint16(offset) {
1836
+ return this._dataView.getUint16(offset - this._sliceOffset, this._littleEndian);
1837
+ }
1838
+ /**
1839
+ * @param {number} offset
1840
+ * @returns {number}
1841
+ */
1842
+ readInt16(offset) {
1843
+ return this._dataView.getInt16(offset - this._sliceOffset, this._littleEndian);
1844
+ }
1845
+ /**
1846
+ * @param {number} offset
1847
+ * @returns {number}
1848
+ */
1849
+ readUint32(offset) {
1850
+ return this._dataView.getUint32(offset - this._sliceOffset, this._littleEndian);
1851
+ }
1852
+ /**
1853
+ * @param {number} offset
1854
+ * @returns {number}
1855
+ */
1856
+ readInt32(offset) {
1857
+ return this._dataView.getInt32(offset - this._sliceOffset, this._littleEndian);
1858
+ }
1859
+ /**
1860
+ * @param {number} offset
1861
+ * @returns {number}
1862
+ */
1863
+ readFloat32(offset) {
1864
+ return this._dataView.getFloat32(offset - this._sliceOffset, this._littleEndian);
1865
+ }
1866
+ /**
1867
+ * @param {number} offset
1868
+ * @returns {number}
1869
+ */
1870
+ readFloat64(offset) {
1871
+ return this._dataView.getFloat64(offset - this._sliceOffset, this._littleEndian);
1872
+ }
1873
+ /**
1874
+ * @param {number} offset
1875
+ * @returns {number}
1876
+ */
1877
+ readUint64(offset) {
1878
+ const left = this.readUint32(offset);
1879
+ const right = this.readUint32(offset + 4);
1880
+ let combined;
1881
+ if (this._littleEndian) {
1882
+ combined = left + 2 ** 32 * right;
1883
+ if (!Number.isSafeInteger(combined)) {
1884
+ throw new Error(`${combined} exceeds MAX_SAFE_INTEGER. Precision may be lost. Please report if you get this message to https://github.com/geotiffjs/geotiff.js/issues`);
1885
+ }
1886
+ return combined;
1887
+ }
1888
+ combined = 2 ** 32 * left + right;
1889
+ if (!Number.isSafeInteger(combined)) {
1890
+ throw new Error(`${combined} exceeds MAX_SAFE_INTEGER. Precision may be lost. Please report if you get this message to https://github.com/geotiffjs/geotiff.js/issues`);
1891
+ }
1892
+ return combined;
1893
+ }
1894
+ /**
1895
+ * Adapted from https://stackoverflow.com/a/55338384/8060591
1896
+ * @param {number} offset
1897
+ * @returns {number}
1898
+ */
1899
+ readInt64(offset) {
1900
+ let value = 0;
1901
+ const isNegative = (this._dataView.getUint8(offset + (this._littleEndian ? 7 : 0)) & 128) > 0;
1902
+ let carrying = true;
1903
+ for (let i = 0; i < 8; i++) {
1904
+ let byte = this._dataView.getUint8(offset + (this._littleEndian ? i : 7 - i));
1905
+ if (isNegative) {
1906
+ if (carrying) {
1907
+ if (byte !== 0) {
1908
+ byte = ~(byte - 1) & 255;
1909
+ carrying = false;
1910
+ }
1911
+ } else {
1912
+ byte = ~byte & 255;
1913
+ }
1914
+ }
1915
+ value += byte * 256 ** i;
1916
+ }
1917
+ if (isNegative) {
1918
+ value = -value;
1919
+ }
1920
+ return value;
1921
+ }
1922
+ /**
1923
+ * @param {number} offset
1924
+ * @returns {number}
1925
+ */
1926
+ readOffset(offset) {
1927
+ if (this._bigTiff) {
1928
+ return this.readUint64(offset);
1929
+ }
1930
+ return this.readUint32(offset);
1931
+ }
1932
+ };
1933
+
1934
+ // ../../node_modules/.pnpm/geotiff@3.0.5/node_modules/geotiff/dist-module/imagefiledirectory.js
1935
+ function getArrayForSamples(fieldType, count) {
1936
+ switch (fieldType) {
1937
+ case fieldTypes.BYTE:
1938
+ case fieldTypes.ASCII:
1939
+ case fieldTypes.UNDEFINED:
1940
+ return new Uint8Array(count);
1941
+ case fieldTypes.SBYTE:
1942
+ return new Int8Array(count);
1943
+ case fieldTypes.SHORT:
1944
+ return new Uint16Array(count);
1945
+ case fieldTypes.SSHORT:
1946
+ return new Int16Array(count);
1947
+ case fieldTypes.LONG:
1948
+ case fieldTypes.IFD:
1949
+ return new Uint32Array(count);
1950
+ case fieldTypes.SLONG:
1951
+ return new Int32Array(count);
1952
+ case fieldTypes.LONG8:
1953
+ case fieldTypes.IFD8:
1954
+ return new Array(count);
1955
+ case fieldTypes.SLONG8:
1956
+ return new Array(count);
1957
+ case fieldTypes.RATIONAL:
1958
+ return new Uint32Array(count * 2);
1959
+ case fieldTypes.SRATIONAL:
1960
+ return new Int32Array(count * 2);
1961
+ case fieldTypes.FLOAT:
1962
+ return new Float32Array(count);
1963
+ case fieldTypes.DOUBLE:
1964
+ return new Float64Array(count);
1965
+ default:
1966
+ throw new RangeError(`Invalid field type: ${fieldType}`);
1967
+ }
1968
+ }
1969
+ function getDataSliceReader(dataSlice, fieldType) {
1970
+ switch (fieldType) {
1971
+ case fieldTypes.BYTE:
1972
+ case fieldTypes.ASCII:
1973
+ case fieldTypes.UNDEFINED:
1974
+ return dataSlice.readUint8;
1975
+ case fieldTypes.SBYTE:
1976
+ return dataSlice.readInt8;
1977
+ case fieldTypes.SHORT:
1978
+ return dataSlice.readUint16;
1979
+ case fieldTypes.SSHORT:
1980
+ return dataSlice.readInt16;
1981
+ case fieldTypes.LONG:
1982
+ case fieldTypes.IFD:
1983
+ return dataSlice.readUint32;
1984
+ case fieldTypes.SLONG:
1985
+ return dataSlice.readInt32;
1986
+ case fieldTypes.LONG8:
1987
+ case fieldTypes.IFD8:
1988
+ return dataSlice.readUint64;
1989
+ case fieldTypes.SLONG8:
1990
+ return dataSlice.readInt64;
1991
+ case fieldTypes.RATIONAL:
1992
+ return dataSlice.readUint32;
1993
+ case fieldTypes.SRATIONAL:
1994
+ return dataSlice.readInt32;
1995
+ case fieldTypes.FLOAT:
1996
+ return dataSlice.readFloat32;
1997
+ case fieldTypes.DOUBLE:
1998
+ return dataSlice.readFloat64;
1999
+ default:
2000
+ throw new RangeError(`Invalid field type: ${fieldType}`);
2001
+ }
2002
+ }
2003
+ function getValues(outValues = null, readMethod, dataSlice, fieldType, count, offset, isArray = false) {
2004
+ const fieldTypeLength = getFieldTypeSize(fieldType);
2005
+ const values2 = outValues || getArrayForSamples(fieldType, count);
2006
+ const isRational = fieldType === fieldTypes.RATIONAL || fieldType === fieldTypes.SRATIONAL;
2007
+ if (!isRational) {
2008
+ for (let i = 0; i < count; ++i) {
2009
+ values2[i] = readMethod.call(dataSlice, offset + i * fieldTypeLength);
2010
+ }
2011
+ } else {
2012
+ for (let i = 0; i < count; i += 2) {
2013
+ values2[i] = readMethod.call(dataSlice, offset + i * fieldTypeLength);
2014
+ values2[i + 1] = readMethod.call(dataSlice, offset + (i * fieldTypeLength + 4));
2015
+ }
2016
+ }
2017
+ if (fieldType === fieldTypes.ASCII) {
2018
+ return new TextDecoder("utf-8").decode(
2019
+ /** @type {Uint8Array} */
2020
+ values2
2021
+ );
2022
+ }
2023
+ if (count === 1 && !isArray && !isRational) {
2024
+ return values2[0];
2025
+ }
2026
+ return values2;
2027
+ }
2028
+ var DeferredArray = class {
2029
+ /**
2030
+ * Creates a DeferredArray for lazy-loading of large TIFF field arrays.
2031
+ * @param {import("./source/basesource.js").BaseSource} source - Data source for fetching
2032
+ * @param {number} arrayOffset - Byte offset where the array data starts
2033
+ * @param {boolean} littleEndian - Endianness of the data
2034
+ * @param {import('./globals.js').FieldType} fieldType - TIFF field type constant
2035
+ * @param {number} length - Number of elements in the array
2036
+ */
2037
+ constructor(source, arrayOffset, littleEndian, fieldType, length) {
2038
+ this.source = source;
2039
+ this.arrayOffset = arrayOffset;
2040
+ this.littleEndian = littleEndian;
2041
+ this.fieldType = fieldType;
2042
+ this.length = length;
2043
+ this.data = getArrayForSamples(fieldType, length);
2044
+ this.itemSize = getFieldTypeSize(fieldType);
2045
+ this.maskBitmap = new Uint8Array(Math.ceil(length / 8));
2046
+ this.fetchIndexPromises = /* @__PURE__ */ new Map();
2047
+ this.fullFetchPromise = null;
2048
+ }
2049
+ /**
2050
+ * Loads all values in the deferred array at once.
2051
+ * Subsequent calls return the same promise to avoid redundant fetches.
2052
+ * @returns {Promise<import('./geotiff.js').TypedArray|Array<number>>} Promise resolving to the fully loaded array
2053
+ */
2054
+ async loadAll() {
2055
+ if (!this.fullFetchPromise) {
2056
+ this.fullFetchPromise = this.source.fetch([{
2057
+ offset: this.arrayOffset,
2058
+ length: this.itemSize * this.length
2059
+ }]).then((data) => {
2060
+ const dataSlice = new DataSlice(data[0], this.arrayOffset, true, false);
2061
+ const result = getValues(this.data, getDataSliceReader(dataSlice, this.fieldType), dataSlice, this.fieldType, this.length, this.arrayOffset, true);
2062
+ this.maskBitmap.fill(255);
2063
+ this.fetchIndexPromises.clear();
2064
+ return result;
2065
+ });
2066
+ }
2067
+ return this.fullFetchPromise;
2068
+ }
2069
+ /**
2070
+ * Loads and returns a single value at the specified index.
2071
+ * If the value is already loaded, returns it immediately. Otherwise, fetches it
2072
+ * from the source. Multiple calls for the same index reuse the same promise.
2073
+ * @param {number} index - Zero-based index of the value to load
2074
+ * @returns {Promise<number|bigint>} Promise resolving to the value at the given index
2075
+ * @throws {RangeError} If index is out of bounds
2076
+ */
2077
+ async get(index) {
2078
+ if (index < 0 || index >= this.data.length) {
2079
+ throw new RangeError(`Index ${index} out of bounds for length ${this.data.length}`);
2080
+ }
2081
+ const byteIndex = Math.floor(index / 8);
2082
+ const bitMask = 1 << index % 8;
2083
+ const offset = this.arrayOffset + index * this.itemSize;
2084
+ if ((this.maskBitmap[byteIndex] & bitMask) === 0) {
2085
+ if (!this.fetchIndexPromises.has(index)) {
2086
+ const fetchPromise = this.source.fetch([{
2087
+ offset,
2088
+ length: this.itemSize
2089
+ }]).then((data) => {
2090
+ const dataSlice = new DataSlice(data[0], this.arrayOffset + index * this.itemSize, true, false);
2091
+ const readMethod = getDataSliceReader(dataSlice, this.fieldType);
2092
+ const value = readMethod.call(dataSlice, offset);
2093
+ this.data[index] = value;
2094
+ this.maskBitmap[byteIndex] |= bitMask;
2095
+ this.fetchIndexPromises.delete(index);
2096
+ return value;
2097
+ });
2098
+ this.fetchIndexPromises.set(index, fetchPromise);
2099
+ }
2100
+ return this.fetchIndexPromises.get(index);
2101
+ }
2102
+ return this.data[index];
2103
+ }
2104
+ };
2105
+ var ImageFileDirectory = class {
2106
+ /**
2107
+ * Create an ImageFileDirectory.
2108
+ * @param {Map<string|number, number|string|Array<number|string>>} actualizedFields the file directory,
2109
+ * mapping tag names to values
2110
+ * @param {Map<string|number, Function>} deferredFields the deferred fields, mapping tag names to async functions
2111
+ * @param {Map<string|number, DeferredArray>} deferredArrays the deferred arrays, mapping tag names to
2112
+ * DeferredArray objects
2113
+ * @param {number} nextIFDByteOffset the byte offset to the next IFD
2114
+ */
2115
+ constructor(actualizedFields, deferredFields, deferredArrays, nextIFDByteOffset) {
2116
+ this.actualizedFields = actualizedFields;
2117
+ this.deferredFields = deferredFields;
2118
+ this.deferredFieldsBeingResolved = /* @__PURE__ */ new Map();
2119
+ this.deferredArrays = deferredArrays;
2120
+ this.nextIFDByteOffset = nextIFDByteOffset;
2121
+ }
2122
+ /**
2123
+ * @param {import('./globals.js').TagName|number} tagIdentifier The field tag ID or name
2124
+ * @returns {boolean} whether the field exists (actualized or deferred)
2125
+ */
2126
+ hasTag(tagIdentifier) {
2127
+ const tag = resolveTag(tagIdentifier);
2128
+ return this.actualizedFields.has(tag) || this.deferredFields.has(tag) || this.deferredArrays.has(tag);
2129
+ }
2130
+ /**
2131
+ * Synchronously retrieves the value for a given tag. If it is deferred, an error is thrown.
2132
+ * @template {import('./globals.js').EagerTagName | import('./globals.js').EagerTag} [T=any]
2133
+ * @param {T} tagIdentifier The field tag ID or name
2134
+ * @returns {T extends import('./globals.js').TagName ? (import('./globals.js').TagValue<T> | undefined) : any}
2135
+ * the field value,
2136
+ * or undefined if it does not exist
2137
+ * @throws {Error} If the tag is deferred and requires asynchronous loading
2138
+ */
2139
+ getValue(tagIdentifier) {
2140
+ const tag = resolveTag(tagIdentifier);
2141
+ if (this.deferredFields.has(tag) || this.deferredArrays.has(tag)) {
2142
+ const tagDef = tagDefinitions[tag];
2143
+ const tagName2 = tagDef?.name || `Tag${tag}`;
2144
+ throw new Error(`Field '${tagName2}' (${tag}) is deferred. Use loadValue() to load it asynchronously.`);
2145
+ }
2146
+ if (!this.actualizedFields.has(tag)) {
2147
+ return (
2148
+ /** @type {any} */
2149
+ void 0
2150
+ );
2151
+ }
2152
+ return (
2153
+ /** @type {any} */
2154
+ this.actualizedFields.get(tag)
2155
+ );
2156
+ }
2157
+ /**
2158
+ * Retrieves the value for a given tag. If it is deferred, it will be loaded first.
2159
+ * @template {import('./globals.js').TagName} [T=any]
2160
+ * @param {T|number} tagIdentifier The field tag ID or name
2161
+ * @returns {Promise<T extends import('./globals.js').TagName ? (import('./globals.js').TagValue<T> | undefined) : any>}
2162
+ * the field value, or undefined if it does not exist
2163
+ */
2164
+ async loadValue(tagIdentifier) {
2165
+ const tag = resolveTag(tagIdentifier);
2166
+ if (this.actualizedFields.has(tag)) {
2167
+ return (
2168
+ /** @type {any} */
2169
+ this.actualizedFields.get(tag)
2170
+ );
2171
+ }
2172
+ if (this.deferredFieldsBeingResolved.has(tag)) {
2173
+ return (
2174
+ /** @type {any} */
2175
+ this.deferredFieldsBeingResolved.get(tag)
2176
+ );
2177
+ }
2178
+ const loaderFn = this.deferredFields.get(tag);
2179
+ if (loaderFn) {
2180
+ this.deferredFields.delete(tag);
2181
+ const valuePromise = (async () => {
2182
+ try {
2183
+ const value = await loaderFn();
2184
+ this.actualizedFields.set(tag, value);
2185
+ return value;
2186
+ } finally {
2187
+ this.deferredFieldsBeingResolved.delete(tag);
2188
+ }
2189
+ })();
2190
+ this.deferredFieldsBeingResolved.set(tag, valuePromise);
2191
+ return (
2192
+ /** @type {any} */
2193
+ valuePromise
2194
+ );
2195
+ }
2196
+ const deferredArray = this.deferredArrays.get(tag);
2197
+ if (deferredArray) {
2198
+ return (
2199
+ /** @type {any} */
2200
+ deferredArray.loadAll()
2201
+ );
2202
+ }
2203
+ return (
2204
+ /** @type {any} */
2205
+ void 0
2206
+ );
2207
+ }
2208
+ /**
2209
+ * Retrieves the value at a given index for a tag that is an array. If it is deferred, it will be loaded first.
2210
+ * @param {number|string} tagIdentifier The field tag ID or name
2211
+ * @param {number} index The index within the array
2212
+ * @returns {Promise<number|string|bigint|undefined>} the field value at the given index, or undefined if it does not exist
2213
+ */
2214
+ async loadValueIndexed(tagIdentifier, index) {
2215
+ const tag = resolveTag(tagIdentifier);
2216
+ if (this.actualizedFields.has(tag)) {
2217
+ const value = this.actualizedFields.get(tag);
2218
+ return (
2219
+ /** @type {any} */
2220
+ value[index]
2221
+ );
2222
+ } else if (this.deferredArrays.has(tag)) {
2223
+ const deferredArray = (
2224
+ /** @type {DeferredArray} */
2225
+ this.deferredArrays.get(tag)
2226
+ );
2227
+ return deferredArray.get(index);
2228
+ } else if (this.hasTag(tag)) {
2229
+ const value = await this.loadValue(tag);
2230
+ if (value && typeof value !== "number") {
2231
+ return value[index];
2232
+ }
2233
+ }
2234
+ return void 0;
2235
+ }
2236
+ /**
2237
+ * Parses the GeoTIFF GeoKeyDirectory tag into a structured object.
2238
+ * The GeoKeyDirectory is a special TIFF tag that contains geographic metadata
2239
+ * in a key-value format as defined by the GeoTIFF specification.
2240
+ * @returns {Partial<Record<import('./globals.js').GeoKeyName, *>>|null} Parsed geo key directory
2241
+ * mapping key names to values, or null if not present
2242
+ * @throws {Error} If a referenced geo key value cannot be retrieved
2243
+ */
2244
+ parseGeoKeyDirectory() {
2245
+ const rawGeoKeyDirectory = this.getValue("GeoKeyDirectory");
2246
+ if (!rawGeoKeyDirectory) {
2247
+ return null;
2248
+ }
2249
+ const geoKeyDirectory = {};
2250
+ for (let i = 4; i <= rawGeoKeyDirectory[3] * 4; i += 4) {
2251
+ const key = (
2252
+ /** @type {Record<number, import('./globals.js').GeoKeyName>} */
2253
+ geoKeyNames[rawGeoKeyDirectory[i]]
2254
+ );
2255
+ const location = (
2256
+ /** @type {import('./globals.js').EagerTag} */
2257
+ rawGeoKeyDirectory[i + 1] || null
2258
+ );
2259
+ const count = rawGeoKeyDirectory[i + 2];
2260
+ const offset = rawGeoKeyDirectory[i + 3];
2261
+ let value = null;
2262
+ if (!location) {
2263
+ value = offset;
2264
+ } else {
2265
+ value = this.getValue(location);
2266
+ if (typeof value === "undefined" || value === null) {
2267
+ throw new Error(`Could not get value of geoKey '${key}'.`);
2268
+ } else if (typeof value === "string") {
2269
+ value = value.substring(offset, offset + count - 1);
2270
+ } else if (value.subarray) {
2271
+ value = value.subarray(offset, offset + count);
2272
+ if (count === 1) {
2273
+ value = value[0];
2274
+ }
2275
+ }
2276
+ }
2277
+ geoKeyDirectory[key] = value;
2278
+ }
2279
+ return geoKeyDirectory;
2280
+ }
2281
+ toObject() {
2282
+ const obj = {};
2283
+ for (const [tag, value] of this.actualizedFields.entries()) {
2284
+ const tagDefinition = typeof tag === "number" ? tagDefinitions[tag] : void 0;
2285
+ const tagName2 = tagDefinition ? tagDefinition.name : `Tag${tag}`;
2286
+ obj[tagName2] = value;
2287
+ }
2288
+ return obj;
2289
+ }
2290
+ };
2291
+ var ImageFileDirectoryParser = class {
2292
+ /**
2293
+ * @param {import("./source/basesource.js").BaseSource} source the data source to fetch from
2294
+ * @param {boolean} littleEndian the endianness of the file
2295
+ * @param {boolean} bigTiff whether the file is a BigTIFF
2296
+ * @param {boolean} [eager=false] whether to eagerly fetch deferred fields.
2297
+ * When false (default), tags are loaded lazily on-demand.
2298
+ * When true, all tags are loaded immediately during parsing.
2299
+ */
2300
+ constructor(source, littleEndian, bigTiff, eager = false) {
2301
+ this.source = source;
2302
+ this.littleEndian = littleEndian;
2303
+ this.bigTiff = bigTiff;
2304
+ this.eager = eager;
2305
+ }
2306
+ /**
2307
+ * Helper function to retrieve a DataSlice from the source.
2308
+ * @param {number} offset Byte offset of the slice
2309
+ * @param {number} [length] Length of the slice
2310
+ * @returns {Promise<DataSlice>}
2311
+ */
2312
+ async getSlice(offset, length) {
2313
+ const fallbackLength = this.bigTiff ? 4048 : 1024;
2314
+ return new DataSlice((await this.source.fetch([
2315
+ {
2316
+ offset,
2317
+ length: typeof length !== "undefined" ? length : fallbackLength
2318
+ }
2319
+ ]))[0], offset, this.littleEndian, this.bigTiff);
2320
+ }
2321
+ /**
2322
+ * Instructs to parse an image file directory at the given file offset.
2323
+ * As there is no way to ensure that a location is indeed the start of an IFD,
2324
+ * this function must be called with caution (e.g only using the IFD offsets from
2325
+ * the headers or other IFDs).
2326
+ * @param {number} offset the offset to parse the IFD at
2327
+ * @returns {Promise<ImageFileDirectory>} the parsed IFD
2328
+ */
2329
+ async parseFileDirectoryAt(offset) {
2330
+ const entrySize = this.bigTiff ? 20 : 12;
2331
+ const offsetSize = this.bigTiff ? 8 : 2;
2332
+ let dataSlice = await this.getSlice(offset);
2333
+ const numDirEntries = this.bigTiff ? dataSlice.readUint64(offset) : dataSlice.readUint16(offset);
2334
+ const byteSize = numDirEntries * (entrySize + (this.bigTiff ? 16 : 6));
2335
+ if (!dataSlice.covers(offset, byteSize)) {
2336
+ dataSlice = await this.getSlice(offset, byteSize);
2337
+ }
2338
+ const actualizedFields = /* @__PURE__ */ new Map();
2339
+ const deferredFields = /* @__PURE__ */ new Map();
2340
+ const deferredArrays = /* @__PURE__ */ new Map();
2341
+ let i = offset + (this.bigTiff ? 8 : 2);
2342
+ for (let entryCount = 0; entryCount < numDirEntries; i += entrySize, ++entryCount) {
2343
+ const fieldTag = dataSlice.readUint16(i);
2344
+ const fieldType = (
2345
+ /** @type {import('./globals.js').FieldType} */
2346
+ dataSlice.readUint16(i + 2)
2347
+ );
2348
+ const typeCount = this.bigTiff ? dataSlice.readUint64(i + 4) : dataSlice.readUint32(i + 4);
2349
+ let fieldValues = null;
2350
+ let deferredFieldValues = null;
2351
+ let deferredArray = null;
2352
+ const fieldTypeLength = getFieldTypeSize(fieldType);
2353
+ const valueOffset = i + (this.bigTiff ? 12 : 8);
2354
+ const isArray = tagDefinitions[fieldTag]?.isArray;
2355
+ const eager = tagDefinitions[fieldTag]?.eager || this.eager;
2356
+ if (fieldTypeLength * typeCount <= (this.bigTiff ? 8 : 4)) {
2357
+ fieldValues = getValues(getArrayForSamples(fieldType, typeCount), getDataSliceReader(dataSlice, fieldType), dataSlice, fieldType, typeCount, valueOffset, isArray);
2358
+ } else {
2359
+ const actualOffset = dataSlice.readOffset(valueOffset);
2360
+ const length = getFieldTypeSize(fieldType) * typeCount;
2361
+ if (dataSlice.covers(actualOffset, length)) {
2362
+ fieldValues = getValues(getArrayForSamples(fieldType, typeCount), getDataSliceReader(dataSlice, fieldType), dataSlice, fieldType, typeCount, actualOffset, isArray);
2363
+ } else if (eager) {
2364
+ const fieldDataSlice = await this.getSlice(actualOffset, length);
2365
+ fieldValues = getValues(getArrayForSamples(fieldType, typeCount), getDataSliceReader(fieldDataSlice, fieldType), fieldDataSlice, fieldType, typeCount, actualOffset, isArray);
2366
+ } else if (isArray) {
2367
+ deferredArray = new DeferredArray(this.source, actualOffset, this.littleEndian, fieldType, typeCount);
2368
+ } else {
2369
+ deferredFieldValues = async () => {
2370
+ const fieldDataSlice = await this.getSlice(actualOffset, length);
2371
+ return getValues(getArrayForSamples(fieldType, typeCount), getDataSliceReader(fieldDataSlice, fieldType), fieldDataSlice, fieldType, typeCount, actualOffset, isArray);
2372
+ };
2373
+ }
2374
+ }
2375
+ if (fieldValues !== null) {
2376
+ actualizedFields.set(fieldTag, fieldValues);
2377
+ } else if (deferredFieldValues !== null) {
2378
+ deferredFields.set(fieldTag, deferredFieldValues);
2379
+ } else if (deferredArray !== null) {
2380
+ deferredArrays.set(fieldTag, deferredArray);
2381
+ }
2382
+ }
2383
+ const nextIFDByteOffset = dataSlice.readOffset(offset + offsetSize + entrySize * numDirEntries);
2384
+ return new ImageFileDirectory(actualizedFields, deferredFields, deferredArrays, nextIFDByteOffset);
2385
+ }
2386
+ };
2387
+
2388
+ // ../../node_modules/.pnpm/geotiff@3.0.5/node_modules/geotiff/dist-module/geotiff.js
2389
+ function getValues2(dataSlice, fieldType, count, offset) {
2390
+ let values2 = null;
2391
+ let readMethod = null;
2392
+ const fieldTypeLength = getFieldTypeSize(fieldType);
2393
+ switch (fieldType) {
2394
+ case fieldTypes.BYTE:
2395
+ case fieldTypes.ASCII:
2396
+ case fieldTypes.UNDEFINED:
2397
+ values2 = new Uint8Array(count);
2398
+ readMethod = dataSlice.readUint8;
2399
+ break;
2400
+ case fieldTypes.SBYTE:
2401
+ values2 = new Int8Array(count);
2402
+ readMethod = dataSlice.readInt8;
2403
+ break;
2404
+ case fieldTypes.SHORT:
2405
+ values2 = new Uint16Array(count);
2406
+ readMethod = dataSlice.readUint16;
2407
+ break;
2408
+ case fieldTypes.SSHORT:
2409
+ values2 = new Int16Array(count);
2410
+ readMethod = dataSlice.readInt16;
2411
+ break;
2412
+ case fieldTypes.LONG:
2413
+ case fieldTypes.IFD:
2414
+ values2 = new Uint32Array(count);
2415
+ readMethod = dataSlice.readUint32;
2416
+ break;
2417
+ case fieldTypes.SLONG:
2418
+ values2 = new Int32Array(count);
2419
+ readMethod = dataSlice.readInt32;
2420
+ break;
2421
+ case fieldTypes.LONG8:
2422
+ case fieldTypes.IFD8:
2423
+ values2 = new Array(count);
2424
+ readMethod = dataSlice.readUint64;
2425
+ break;
2426
+ case fieldTypes.SLONG8:
2427
+ values2 = new Array(count);
2428
+ readMethod = dataSlice.readInt64;
2429
+ break;
2430
+ case fieldTypes.RATIONAL:
2431
+ values2 = new Uint32Array(count * 2);
2432
+ readMethod = dataSlice.readUint32;
2433
+ break;
2434
+ case fieldTypes.SRATIONAL:
2435
+ values2 = new Int32Array(count * 2);
2436
+ readMethod = dataSlice.readInt32;
2437
+ break;
2438
+ case fieldTypes.FLOAT:
2439
+ values2 = new Float32Array(count);
2440
+ readMethod = dataSlice.readFloat32;
2441
+ break;
2442
+ case fieldTypes.DOUBLE:
2443
+ values2 = new Float64Array(count);
2444
+ readMethod = dataSlice.readFloat64;
2445
+ break;
2446
+ default:
2447
+ }
2448
+ if (values2 === null || readMethod === null) {
2449
+ throw new RangeError(`Invalid field type: ${fieldType}`);
2450
+ }
2451
+ if (!(fieldType === fieldTypes.RATIONAL || fieldType === fieldTypes.SRATIONAL)) {
2452
+ for (let i = 0; i < count; ++i) {
2453
+ values2[i] = readMethod.call(dataSlice, offset + i * fieldTypeLength);
2454
+ }
2455
+ } else {
2456
+ for (let i = 0; i < count; i += 2) {
2457
+ values2[i] = readMethod.call(dataSlice, offset + i * fieldTypeLength);
2458
+ values2[i + 1] = readMethod.call(dataSlice, offset + (i * fieldTypeLength + 4));
2459
+ }
2460
+ }
2461
+ if (fieldType === fieldTypes.ASCII) {
2462
+ return new TextDecoder("utf-8").decode(
2463
+ /** @type {Uint8Array} */
2464
+ values2
2465
+ );
2466
+ }
2467
+ return values2;
2468
+ }
2469
+ var GeoTIFFImageIndexError = class extends Error {
2470
+ /**
2471
+ * @param {number} index
2472
+ */
2473
+ constructor(index) {
2474
+ super(`No image at index ${index}`);
2475
+ this.index = index;
2476
+ }
2477
+ };
2478
+ var GeoTIFFBase = class {
2479
+ /**
2480
+ * @param {number} [_index=0] the index of the image to return.
2481
+ * @returns {Promise<GeoTIFFImage>} the image at the given index
2482
+ */
2483
+ async getImage(_index = 0) {
2484
+ throw new Error("Not implemented");
2485
+ }
2486
+ /**
2487
+ * @returns {Promise<number>} the number of internal subfile images
2488
+ */
2489
+ async getImageCount() {
2490
+ throw new Error("Not implemented");
2491
+ }
2492
+ /**
2493
+ * @typedef {Object} ReadRastersWindowOptions
2494
+ * @property {number} [resX] desired Y resolution (world units per pixel)
2495
+ * @property {number} [resY] desired X resolution (world units per pixel)
2496
+ * @property {Array<number>} [bbox] the subset to read data from in
2497
+ * geographical coordinates. Whole image if not specified.
2498
+ */
2499
+ /**
2500
+ * (experimental) Reads raster data from the best fitting image. This function uses
2501
+ * the image with the lowest resolution that is still a higher resolution than the
2502
+ * requested resolution.
2503
+ * When specified, the `bbox` option is translated to the `window` option and the
2504
+ * `resX` and `resY` to `width` and `height` respectively.
2505
+ * Then, the [readRasters]{@link GeoTIFFImage#readRasters} method of the selected
2506
+ * image is called and the result returned.
2507
+ * @see GeoTIFFImage.readRasters
2508
+ * @param {ReadRastersOptions & ReadRastersWindowOptions} options optional parameters
2509
+ * @returns {Promise<ReadRasterResult>} the decoded array(s), with `height` and `width`, as a promise
2510
+ */
2511
+ async readRasters(options = {}) {
2512
+ const { window: imageWindow, width, height } = options;
2513
+ let { resX, resY, bbox } = options;
2514
+ const firstImage = await this.getImage();
2515
+ let usedImage = firstImage;
2516
+ const imageCount = await this.getImageCount();
2517
+ const imgBBox = firstImage.getBoundingBox();
2518
+ if (imageWindow && bbox) {
2519
+ throw new Error('Both "bbox" and "window" passed.');
2520
+ }
2521
+ if (width || height) {
2522
+ if (imageWindow) {
2523
+ const [oX, oY] = firstImage.getOrigin();
2524
+ const [rX, rY] = firstImage.getResolution();
2525
+ bbox = [
2526
+ oX + imageWindow[0] * rX,
2527
+ oY + imageWindow[1] * rY,
2528
+ oX + imageWindow[2] * rX,
2529
+ oY + imageWindow[3] * rY
2530
+ ];
2531
+ }
2532
+ const usedBBox = bbox || imgBBox;
2533
+ if (width) {
2534
+ if (resX) {
2535
+ throw new Error("Both width and resX passed");
2536
+ }
2537
+ resX = (usedBBox[2] - usedBBox[0]) / width;
2538
+ }
2539
+ if (height) {
2540
+ if (resY) {
2541
+ throw new Error("Both width and resY passed");
2542
+ }
2543
+ resY = (usedBBox[3] - usedBBox[1]) / height;
2544
+ }
2545
+ }
2546
+ if (resX || resY) {
2547
+ const allImages = [];
2548
+ for (let i = 0; i < imageCount; ++i) {
2549
+ const image = await this.getImage(i);
2550
+ const subfileType = image.fileDirectory.getValue("SubfileType");
2551
+ const newSubfileType = image.fileDirectory.getValue("NewSubfileType");
2552
+ if (i === 0 || subfileType === 2 || (newSubfileType || 0) & 1) {
2553
+ allImages.push(image);
2554
+ }
2555
+ }
2556
+ allImages.sort((a, b) => a.getWidth() - b.getWidth());
2557
+ for (let i = 0; i < allImages.length; ++i) {
2558
+ const image = allImages[i];
2559
+ const imgResX = (imgBBox[2] - imgBBox[0]) / image.getWidth();
2560
+ const imgResY = (imgBBox[3] - imgBBox[1]) / image.getHeight();
2561
+ usedImage = image;
2562
+ if (resX && resX > imgResX || resY && resY > imgResY) {
2563
+ break;
2564
+ }
2565
+ }
2566
+ }
2567
+ let wnd = imageWindow;
2568
+ if (bbox) {
2569
+ const [oX, oY] = firstImage.getOrigin();
2570
+ const [imageResX, imageResY] = usedImage.getResolution(firstImage);
2571
+ wnd = [
2572
+ Math.round((bbox[0] - oX) / imageResX),
2573
+ Math.round((bbox[1] - oY) / imageResY),
2574
+ Math.round((bbox[2] - oX) / imageResX),
2575
+ Math.round((bbox[3] - oY) / imageResY)
2576
+ ];
2577
+ wnd = [
2578
+ Math.min(wnd[0], wnd[2]),
2579
+ Math.min(wnd[1], wnd[3]),
2580
+ Math.max(wnd[0], wnd[2]),
2581
+ Math.max(wnd[1], wnd[3])
2582
+ ];
2583
+ }
2584
+ return usedImage.readRasters({ ...options, window: wnd });
2585
+ }
2586
+ };
2587
+ var GeoTIFF = class _GeoTIFF extends GeoTIFFBase {
2588
+ /**
2589
+ * @constructor
2590
+ * @param {BaseSource} source The datasource to read from.
2591
+ * @param {boolean} littleEndian Whether the image uses little endian.
2592
+ * @param {boolean} bigTiff Whether the image uses bigTIFF conventions.
2593
+ * @param {number} firstIFDOffset The numeric byte-offset from the start of the image
2594
+ * to the first IFD.
2595
+ * @param {GeoTIFFOptions} [options] further options.
2596
+ */
2597
+ constructor(source, littleEndian, bigTiff, firstIFDOffset, options = {}) {
2598
+ super();
2599
+ this.source = source;
2600
+ this.parser = new ImageFileDirectoryParser(source, littleEndian, bigTiff, false);
2601
+ this.littleEndian = littleEndian;
2602
+ this.bigTiff = bigTiff;
2603
+ this.firstIFDOffset = firstIFDOffset;
2604
+ this.cache = options.cache || false;
2605
+ this.ifdRequests = [];
2606
+ this.ghostValues = null;
2607
+ }
2608
+ /**
2609
+ * @param {number} offset
2610
+ * @param {number} [size]
2611
+ * @returns {Promise<DataSlice>}
2612
+ */
2613
+ async getSlice(offset, size) {
2614
+ const fallbackSize = this.bigTiff ? 4048 : 1024;
2615
+ return new DataSlice((await this.source.fetch([{
2616
+ offset,
2617
+ length: typeof size !== "undefined" ? size : fallbackSize
2618
+ }]))[0], offset, this.littleEndian, this.bigTiff);
2619
+ }
2620
+ /**
2621
+ * @param {number} index
2622
+ * @return {Promise<import('./imagefiledirectory.js').ImageFileDirectory>}
2623
+ */
2624
+ async requestIFD(index) {
2625
+ if (this.ifdRequests[index]) {
2626
+ return this.ifdRequests[index];
2627
+ } else if (index === 0) {
2628
+ this.ifdRequests[index] = this.parser.parseFileDirectoryAt(this.firstIFDOffset);
2629
+ return this.ifdRequests[index];
2630
+ } else if (!this.ifdRequests[index - 1]) {
2631
+ try {
2632
+ this.ifdRequests[index - 1] = this.requestIFD(index - 1);
2633
+ } catch (e) {
2634
+ if (e instanceof GeoTIFFImageIndexError) {
2635
+ throw new GeoTIFFImageIndexError(index);
2636
+ }
2637
+ throw e;
2638
+ }
2639
+ }
2640
+ this.ifdRequests[index] = (async () => {
2641
+ const previousPromise = this.ifdRequests[index - 1];
2642
+ if (!previousPromise) {
2643
+ throw new Error("Previous IFD request missing");
2644
+ }
2645
+ const previousIfd = await previousPromise;
2646
+ if (previousIfd.nextIFDByteOffset === 0) {
2647
+ throw new GeoTIFFImageIndexError(index);
2648
+ }
2649
+ return this.parser.parseFileDirectoryAt(previousIfd.nextIFDByteOffset);
2650
+ })();
2651
+ return this.ifdRequests[index];
2652
+ }
2653
+ /**
2654
+ * Get the n-th internal subfile of an image. By default, the first is returned.
2655
+ *
2656
+ * @param {number} [index=0] the index of the image to return.
2657
+ * @returns {Promise<GeoTIFFImage>} the image at the given index
2658
+ */
2659
+ async getImage(index = 0) {
2660
+ return new geotiffimage_default(await this.requestIFD(index), this.littleEndian, this.cache, this.source);
2661
+ }
2662
+ /**
2663
+ * Returns the count of the internal subfiles.
2664
+ *
2665
+ * @returns {Promise<number>} the number of internal subfile images
2666
+ */
2667
+ async getImageCount() {
2668
+ let index = 0;
2669
+ let hasNext = true;
2670
+ while (hasNext) {
2671
+ try {
2672
+ await this.requestIFD(index);
2673
+ ++index;
2674
+ } catch (e) {
2675
+ if (e instanceof GeoTIFFImageIndexError) {
2676
+ hasNext = false;
2677
+ } else {
2678
+ throw e;
2679
+ }
2680
+ }
2681
+ }
2682
+ return index;
2683
+ }
2684
+ /**
2685
+ * Get the values of the COG ghost area as a parsed map.
2686
+ * See https://gdal.org/drivers/raster/cog.html#header-ghost-area for reference
2687
+ * @returns {Promise<Record<string, unknown>|null>} the parsed ghost area or null, if no such area was found
2688
+ */
2689
+ async getGhostValues() {
2690
+ const offset = this.bigTiff ? 16 : 8;
2691
+ if (this.ghostValues !== null) {
2692
+ return this.ghostValues;
2693
+ }
2694
+ const detectionString = "GDAL_STRUCTURAL_METADATA_SIZE=";
2695
+ const heuristicAreaSize = detectionString.length + 100;
2696
+ let slice = await this.getSlice(offset, heuristicAreaSize);
2697
+ if (detectionString === getValues2(slice, fieldTypes.ASCII, detectionString.length, offset)) {
2698
+ const valuesString = getValues2(slice, fieldTypes.ASCII, heuristicAreaSize, offset);
2699
+ const firstLine = valuesString.split("\n")[0];
2700
+ const metadataSize = Number(firstLine.split("=")[1].split(" ")[0]) + firstLine.length;
2701
+ if (metadataSize > heuristicAreaSize) {
2702
+ slice = await this.getSlice(offset, metadataSize);
2703
+ }
2704
+ const fullString = getValues2(slice, fieldTypes.ASCII, metadataSize, offset);
2705
+ const ghostValues = {};
2706
+ fullString.split("\n").filter((line) => line.length > 0).map((line) => line.split("=")).forEach(([key, value]) => {
2707
+ ghostValues[key] = value;
2708
+ });
2709
+ this.ghostValues = ghostValues;
2710
+ }
2711
+ return this.ghostValues;
2712
+ }
2713
+ /**
2714
+ * Parse a (Geo)TIFF file from the given source.
2715
+ *
2716
+ * @param {BaseSource} source The source of data to parse from.
2717
+ * @param {GeoTIFFOptions} [options] Additional options.
2718
+ * @param {AbortSignal} [signal] An AbortSignal that may be signalled if the request is
2719
+ * to be aborted
2720
+ */
2721
+ static async fromSource(source, options, signal) {
2722
+ const headerData = (await source.fetch([{ offset: 0, length: 1024 }], signal))[0];
2723
+ const dataView = new DataView64(headerData);
2724
+ const BOM = dataView.getUint16(0, false);
2725
+ let littleEndian;
2726
+ if (BOM === 18761) {
2727
+ littleEndian = true;
2728
+ } else if (BOM === 19789) {
2729
+ littleEndian = false;
2730
+ } else {
2731
+ throw new TypeError("Invalid byte order value.");
2732
+ }
2733
+ const magicNumber = dataView.getUint16(2, littleEndian);
2734
+ let bigTiff;
2735
+ if (magicNumber === 42) {
2736
+ bigTiff = false;
2737
+ } else if (magicNumber === 43) {
2738
+ bigTiff = true;
2739
+ const offsetByteSize = dataView.getUint16(4, littleEndian);
2740
+ if (offsetByteSize !== 8) {
2741
+ throw new Error("Unsupported offset byte-size.");
2742
+ }
2743
+ } else {
2744
+ throw new TypeError("Invalid magic number.");
2745
+ }
2746
+ const firstIFDOffset = bigTiff ? dataView.getUint64(8, littleEndian) : dataView.getUint32(4, littleEndian);
2747
+ return new _GeoTIFF(source, littleEndian, bigTiff, firstIFDOffset, options);
2748
+ }
2749
+ /**
2750
+ * Closes the underlying file buffer
2751
+ * N.B. After the GeoTIFF has been completely processed it needs
2752
+ * to be closed but only if it has been constructed from a file.
2753
+ */
2754
+ close() {
2755
+ if (typeof this.source.close === "function") {
2756
+ return this.source.close();
2757
+ }
2758
+ return false;
2759
+ }
2760
+ };
2761
+
2762
+ // ../plugins/general-raster/src/decode-tiff.ts
2763
+ var compressionNames = {
2764
+ 1: "none",
2765
+ 5: "LZW",
2766
+ 7: "JPEG",
2767
+ 8: "Deflate",
2768
+ 32946: "Deflate",
2769
+ 32773: "PackBits",
2770
+ 34887: "LERC",
2771
+ 5e4: "Zstandard",
2772
+ 50001: "WebP"
2773
+ };
2774
+ function invalid(message = "TIFF \u6587\u4EF6\u635F\u574F\u6216\u4F7F\u7528\u4E86\u4E0D\u652F\u6301\u7684\u53D8\u4F53\u3002") {
2775
+ throw new ViewerError("invalid-file", message);
2776
+ }
2777
+ function applyOrientation(source, width, height, orientation) {
2778
+ if (orientation === 1) return { rgba: source, width, height };
2779
+ const swapsAxes = orientation >= 5 && orientation <= 8;
2780
+ const outputWidth = swapsAxes ? height : width;
2781
+ const outputHeight = swapsAxes ? width : height;
2782
+ const output = new Uint8ClampedArray(source.length);
2783
+ for (let y = 0; y < height; y += 1) {
2784
+ for (let x = 0; x < width; x += 1) {
2785
+ let targetX;
2786
+ let targetY;
2787
+ switch (orientation) {
2788
+ case 2:
2789
+ targetX = width - 1 - x;
2790
+ targetY = y;
2791
+ break;
2792
+ case 3:
2793
+ targetX = width - 1 - x;
2794
+ targetY = height - 1 - y;
2795
+ break;
2796
+ case 4:
2797
+ targetX = x;
2798
+ targetY = height - 1 - y;
2799
+ break;
2800
+ case 5:
2801
+ targetX = y;
2802
+ targetY = x;
2803
+ break;
2804
+ case 6:
2805
+ targetX = height - 1 - y;
2806
+ targetY = x;
2807
+ break;
2808
+ case 7:
2809
+ targetX = height - 1 - y;
2810
+ targetY = width - 1 - x;
2811
+ break;
2812
+ case 8:
2813
+ targetX = y;
2814
+ targetY = width - 1 - x;
2815
+ break;
2816
+ default:
2817
+ targetX = x;
2818
+ targetY = y;
2819
+ }
2820
+ const sourceOffset = (y * width + x) * 4;
2821
+ const targetOffset = (targetY * outputWidth + targetX) * 4;
2822
+ output[targetOffset] = source[sourceOffset];
2823
+ output[targetOffset + 1] = source[sourceOffset + 1];
2824
+ output[targetOffset + 2] = source[sourceOffset + 2];
2825
+ output[targetOffset + 3] = source[sourceOffset + 3];
2826
+ }
2827
+ }
2828
+ return { rgba: output, width: outputWidth, height: outputHeight };
2829
+ }
2830
+ async function decodeTiffDocument(tiff, pageIndex, signal, big) {
2831
+ const pageCount = await tiff.getImageCount();
2832
+ if (pageCount < 1 || pageCount > MAX_TIFF_PAGES) {
2833
+ throw new ViewerError("resource-limit", `TIFF \u9875\u6570\u8D85\u8FC7 ${MAX_TIFF_PAGES} \u9875\u4E0A\u9650\u3002`);
2834
+ }
2835
+ if (!Number.isInteger(pageIndex) || pageIndex < 0 || pageIndex >= pageCount) invalid("TIFF \u9875\u7801\u65E0\u6548\u3002");
2836
+ const image = await tiff.getImage(pageIndex);
2837
+ const width = image.getWidth();
2838
+ const height = image.getHeight();
2839
+ const pixels = checkedPixelCount(width, height);
2840
+ const directory = image.getFileDirectory();
2841
+ const sampleFormatValue = await directory.loadValue("SampleFormat");
2842
+ const sampleFormats = sampleFormatValue == null ? [1] : Array.from(sampleFormatValue);
2843
+ if (sampleFormats.some((value) => value !== 1)) invalid("\u901A\u7528 TIFF \u67E5\u770B\u5668\u4E0D\u628A\u6709\u7B26\u53F7\u6216\u6D6E\u70B9\u6837\u672C\u8BEF\u4F5C\u666E\u901A\u989C\u8272\u56FE\u7247\u3002");
2844
+ const bitsValue = await directory.loadValue("BitsPerSample");
2845
+ const bits = bitsValue == null ? [8] : Array.from(bitsValue);
2846
+ if (bits.some((value) => value < 1 || value > 16)) invalid("\u5F53\u524D TIFF \u67E5\u770B\u5668\u53EA\u652F\u6301\u6BCF\u901A\u9053 1\u201316 bit \u7684\u6574\u6570\u6837\u672C\u3002");
2847
+ const bitDepth = Math.max(...bits);
2848
+ const rgb = await image.readRGB({ interleave: true, enableAlpha: true, signal });
2849
+ const channels = rgb.length / pixels;
2850
+ if (channels !== 3 && channels !== 4) invalid();
2851
+ const photometric = Number(await directory.loadValue("PhotometricInterpretation") ?? 1);
2852
+ const maximum = photometric === 2 ? 2 ** bitDepth - 1 : 255;
2853
+ const rgba = new Uint8ClampedArray(pixels * 4);
2854
+ const extraSamplesValue = await directory.loadValue("ExtraSamples");
2855
+ const extraSamples = extraSamplesValue == null ? [] : Array.from(extraSamplesValue);
2856
+ const associatedAlpha = channels === 4 && extraSamples[0] === 1;
2857
+ for (let pixel = 0; pixel < pixels; pixel += 1) {
2858
+ const input = pixel * channels;
2859
+ const output = pixel * 4;
2860
+ let red = Math.round(Number(rgb[input]) * 255 / maximum);
2861
+ let green = Math.round(Number(rgb[input + 1]) * 255 / maximum);
2862
+ let blue = Math.round(Number(rgb[input + 2]) * 255 / maximum);
2863
+ const alpha = channels === 4 ? Math.round(Number(rgb[input + 3]) * 255 / maximum) : 255;
2864
+ if (associatedAlpha && alpha > 0 && alpha < 255) {
2865
+ red = Math.min(255, Math.round(red * 255 / alpha));
2866
+ green = Math.min(255, Math.round(green * 255 / alpha));
2867
+ blue = Math.min(255, Math.round(blue * 255 / alpha));
2868
+ }
2869
+ rgba[output] = red;
2870
+ rgba[output + 1] = green;
2871
+ rgba[output + 2] = blue;
2872
+ rgba[output + 3] = alpha;
2873
+ }
2874
+ const orientationValue = Number(await directory.loadValue("Orientation") ?? 1);
2875
+ const orientation = orientationValue >= 1 && orientationValue <= 8 ? orientationValue : 1;
2876
+ const oriented = applyOrientation(rgba, width, height, orientation);
2877
+ const hasIcc = directory.hasTag("ICCProfile");
2878
+ const compression = Number(await directory.loadValue("Compression") ?? 1);
2879
+ return {
2880
+ width: oriented.width,
2881
+ height: oriented.height,
2882
+ rgba: oriented.rgba,
2883
+ format: big ? "BigTIFF" : "TIFF",
2884
+ bitDepth,
2885
+ hasAlpha: channels === 4,
2886
+ colorSpace: hasIcc ? "unknown" : "sRGB",
2887
+ orientation,
2888
+ orientationApplied: true,
2889
+ icc: hasIcc ? "preserved-not-applied" : "none",
2890
+ pageIndex,
2891
+ pageCount,
2892
+ tiled: image.isTiled,
2893
+ compression: compressionNames[compression] ?? `TIFF ${compression}`
2894
+ };
2895
+ }
2896
+
2897
+ // ../plugins/general-raster/src/tiff-metadata.ts
2898
+ function openTiffFromSource(source, signal) {
2899
+ const adapter = {
2900
+ fileSize: source.size,
2901
+ fetch: (slices, sliceSignal) => Promise.all(slices.map(async ({ offset, length }) => {
2902
+ const bytes = await source.read(offset, length, sliceSignal ?? signal);
2903
+ return bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
2904
+ })),
2905
+ close: async () => void 0
2906
+ };
2907
+ return GeoTIFF.fromSource(adapter, void 0, signal);
2908
+ }
2909
+ function toJson(value) {
2910
+ if (value === null || value === void 0) return null;
2911
+ if (typeof value === "number") return Number.isFinite(value) ? value : String(value);
2912
+ if (typeof value === "bigint") return value.toString();
2913
+ if (typeof value === "string" || typeof value === "boolean") return value;
2914
+ if (ArrayBuffer.isView(value) || Array.isArray(value)) return Array.from(value, toJson);
2915
+ if (typeof value === "object") return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, toJson(item)]));
2916
+ return String(value);
2917
+ }
2918
+ function formatValue(value) {
2919
+ if (value === null || value === void 0) return "";
2920
+ if (typeof value === "string") {
2921
+ const text = value.replace(/\0+$/, "").replace(/\s+/g, " ");
2922
+ return text.length > 200 ? `${text.slice(0, 200)}\u2026 (${text.length} chars)` : text;
2923
+ }
2924
+ if (value instanceof Uint8Array && value.length > 32) return `<binary ${value.length} bytes>`;
2925
+ if (ArrayBuffer.isView(value) || Array.isArray(value)) {
2926
+ const values2 = Array.from(value, String);
2927
+ return values2.length > 16 ? `${values2.slice(0, 16).join(", ")}, \u2026 (${values2.length} values)` : values2.join(", ");
2928
+ }
2929
+ return String(value);
2930
+ }
2931
+ var tagName = (tag) => typeof tag === "number" ? globals_exports.getTag(tag)?.name ?? `Tag ${tag}` : tag;
2932
+ async function tiffTagRows(image) {
2933
+ const directory = image.getFileDirectory();
2934
+ const rows = [];
2935
+ for (const [tag, value] of directory.actualizedFields) rows.push([tagName(tag), formatValue(value)]);
2936
+ for (const tag of directory.deferredFields.keys()) rows.push([tagName(tag), formatValue(await directory.loadValue(tag))]);
2937
+ for (const [tag, array] of directory.deferredArrays) rows.push([tagName(tag), `<${array.length} values>`]);
2938
+ return rows;
2939
+ }
2940
+ function tiffGeoMetadata(image) {
2941
+ let keys;
2942
+ try {
2943
+ keys = image.getGeoKeys();
2944
+ } catch {
2945
+ return void 0;
2946
+ }
2947
+ if (!keys) return void 0;
2948
+ const geo = { geoKeys: toJson(keys) };
2949
+ const epsg = [keys.ProjectedCSTypeGeoKey, keys.GeographicTypeGeoKey].find(
2950
+ (code) => typeof code === "number" && code > 0 && code !== 32767
2951
+ );
2952
+ if (epsg !== void 0) geo.crs = `EPSG:${epsg}`;
2953
+ try {
2954
+ geo.origin = toJson(image.getOrigin());
2955
+ geo.resolution = toJson(image.getResolution());
2956
+ geo.bounds = toJson(image.getBoundingBox());
2957
+ } catch {
2958
+ }
2959
+ return geo;
2960
+ }
2961
+ async function tiffPageInfo(image, format) {
2962
+ const directory = image.getFileDirectory();
2963
+ const bits = Array.from(await directory.loadValue("BitsPerSample") ?? [8]);
2964
+ const orientation = Number(await directory.loadValue("Orientation") ?? 1);
2965
+ const swap = orientation >= 5 && orientation <= 8;
2966
+ const compression = Number(await directory.loadValue("Compression") ?? 1);
2967
+ const info = {
2968
+ format,
2969
+ width: swap ? image.getHeight() : image.getWidth(),
2970
+ height: swap ? image.getWidth() : image.getHeight(),
2971
+ bitDepth: Math.max(...bits),
2972
+ samplesPerPixel: image.getSamplesPerPixel(),
2973
+ photometric: Number(await directory.loadValue("PhotometricInterpretation") ?? 1),
2974
+ compression: compressionNames[compression] ?? `TIFF ${compression}`,
2975
+ tiled: image.isTiled,
2976
+ orientation,
2977
+ iccProfile: directory.hasTag("ICCProfile")
2978
+ };
2979
+ const geo = tiffGeoMetadata(image);
2980
+ if (geo) info.geo = geo;
2981
+ return info;
2982
+ }
2983
+ export {
2984
+ decodeTiffDocument,
2985
+ openTiffFromSource,
2986
+ tiffGeoMetadata,
2987
+ tiffPageInfo,
2988
+ tiffTagRows,
2989
+ toJson
2990
+ };