@pmndrs/vdb 0.0.0-stage → 0.1.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 (390) hide show
  1. package/CHANGELOG.md +137 -0
  2. package/LICENSE +21 -0
  3. package/README.md +448 -2
  4. package/THIRD_PARTY_NOTICES.md +147 -0
  5. package/dist/core/compute/atlas.d.ts +94 -0
  6. package/dist/core/compute/atlas.js +98 -0
  7. package/dist/core/compute/atlas.js.map +1 -0
  8. package/dist/core/compute/index.d.ts +13 -0
  9. package/dist/core/compute/index.js +9 -0
  10. package/dist/core/compute/index.js.map +1 -0
  11. package/dist/core/compute/pyramid.d.ts +105 -0
  12. package/dist/core/compute/pyramid.js +455 -0
  13. package/dist/core/compute/pyramid.js.map +1 -0
  14. package/dist/core/compute/shared.d.ts +115 -0
  15. package/dist/core/compute/shared.js +211 -0
  16. package/dist/core/compute/shared.js.map +1 -0
  17. package/dist/core/compute/stats.d.ts +71 -0
  18. package/dist/core/compute/stats.js +188 -0
  19. package/dist/core/compute/stats.js.map +1 -0
  20. package/dist/core/compute/value-transform.d.ts +23 -0
  21. package/dist/core/compute/value-transform.js +58 -0
  22. package/dist/core/compute/value-transform.js.map +1 -0
  23. package/dist/core/errors.d.ts +11 -0
  24. package/dist/core/errors.js +9 -0
  25. package/dist/core/errors.js.map +1 -0
  26. package/dist/core/index.d.ts +30 -0
  27. package/dist/core/index.js +27 -0
  28. package/dist/core/index.js.map +1 -0
  29. package/dist/core/internal.d.ts +15 -0
  30. package/dist/core/internal.js +15 -0
  31. package/dist/core/internal.js.map +1 -0
  32. package/dist/core/pool/affine.d.ts +34 -0
  33. package/dist/core/pool/affine.js +100 -0
  34. package/dist/core/pool/affine.js.map +1 -0
  35. package/dist/core/pool/allocator.d.ts +32 -0
  36. package/dist/core/pool/allocator.js +81 -0
  37. package/dist/core/pool/allocator.js.map +1 -0
  38. package/dist/core/pool/image-header.d.ts +82 -0
  39. package/dist/core/pool/image-header.js +175 -0
  40. package/dist/core/pool/image-header.js.map +1 -0
  41. package/dist/core/pool/layout.d.ts +164 -0
  42. package/dist/core/pool/layout.js +267 -0
  43. package/dist/core/pool/layout.js.map +1 -0
  44. package/dist/core/pool/limits.d.ts +40 -0
  45. package/dist/core/pool/limits.js +79 -0
  46. package/dist/core/pool/limits.js.map +1 -0
  47. package/dist/core/pool/pool.d.ts +279 -0
  48. package/dist/core/pool/pool.js +953 -0
  49. package/dist/core/pool/pool.js.map +1 -0
  50. package/dist/core/source/dense.d.ts +19 -0
  51. package/dist/core/source/dense.js +287 -0
  52. package/dist/core/source/dense.js.map +1 -0
  53. package/dist/core/source/types.d.ts +63 -0
  54. package/dist/core/source/types.js +9 -0
  55. package/dist/core/source/types.js.map +1 -0
  56. package/dist/core/types.d.ts +28 -0
  57. package/dist/core/types.js +28 -0
  58. package/dist/core/types.js.map +1 -0
  59. package/dist/core/wgsl/api.d.ts +41 -0
  60. package/dist/core/wgsl/api.js +463 -0
  61. package/dist/core/wgsl/api.js.map +1 -0
  62. package/dist/core/wgsl/generate.d.ts +82 -0
  63. package/dist/core/wgsl/generate.js +505 -0
  64. package/dist/core/wgsl/generate.js.map +1 -0
  65. package/dist/core/wgsl/level-set.d.ts +54 -0
  66. package/dist/core/wgsl/level-set.js +194 -0
  67. package/dist/core/wgsl/level-set.js.map +1 -0
  68. package/dist/core/wgsl/pnanovdb.chunks.generated.d.ts +14 -0
  69. package/dist/core/wgsl/pnanovdb.chunks.generated.js +330 -0
  70. package/dist/core/wgsl/pnanovdb.chunks.generated.js.map +1 -0
  71. package/dist/core/wgsl/reserved.d.ts +9 -0
  72. package/dist/core/wgsl/reserved.js +26 -0
  73. package/dist/core/wgsl/reserved.js.map +1 -0
  74. package/dist/core/wgsl/types.d.ts +104 -0
  75. package/dist/core/wgsl/types.js +2 -0
  76. package/dist/core/wgsl/types.js.map +1 -0
  77. package/dist/three/coarse-first.d.ts +162 -0
  78. package/dist/three/coarse-first.js +187 -0
  79. package/dist/three/coarse-first.js.map +1 -0
  80. package/dist/three/compute.d.ts +63 -0
  81. package/dist/three/compute.js +56 -0
  82. package/dist/three/compute.js.map +1 -0
  83. package/dist/three/device.d.ts +59 -0
  84. package/dist/three/device.js +59 -0
  85. package/dist/three/device.js.map +1 -0
  86. package/dist/three/frame/blackbody.d.ts +42 -0
  87. package/dist/three/frame/blackbody.js +74 -0
  88. package/dist/three/frame/blackbody.js.map +1 -0
  89. package/dist/three/frame/chunks.d.ts +157 -0
  90. package/dist/three/frame/chunks.js +559 -0
  91. package/dist/three/frame/chunks.js.map +1 -0
  92. package/dist/three/frame/density-material.d.ts +53 -0
  93. package/dist/three/frame/density-material.js +353 -0
  94. package/dist/three/frame/density-material.js.map +1 -0
  95. package/dist/three/frame/emission-light.d.ts +167 -0
  96. package/dist/three/frame/emission-light.js +655 -0
  97. package/dist/three/frame/emission-light.js.map +1 -0
  98. package/dist/three/frame/environment-grid-material.d.ts +21 -0
  99. package/dist/three/frame/environment-grid-material.js +184 -0
  100. package/dist/three/frame/environment-grid-material.js.map +1 -0
  101. package/dist/three/frame/environment-material.d.ts +22 -0
  102. package/dist/three/frame/environment-material.js +87 -0
  103. package/dist/three/frame/environment-material.js.map +1 -0
  104. package/dist/three/frame/grid-mip-material.d.ts +12 -0
  105. package/dist/three/frame/grid-mip-material.js +61 -0
  106. package/dist/three/frame/grid-mip-material.js.map +1 -0
  107. package/dist/three/frame/index.d.ts +39 -0
  108. package/dist/three/frame/index.js +35 -0
  109. package/dist/three/frame/index.js.map +1 -0
  110. package/dist/three/frame/inject-material.d.ts +56 -0
  111. package/dist/three/frame/inject-material.js +424 -0
  112. package/dist/three/frame/inject-material.js.map +1 -0
  113. package/dist/three/frame/integrate-material.d.ts +26 -0
  114. package/dist/three/frame/integrate-material.js +198 -0
  115. package/dist/three/frame/integrate-material.js.map +1 -0
  116. package/dist/three/frame/layout.d.ts +34 -0
  117. package/dist/three/frame/layout.js +48 -0
  118. package/dist/three/frame/layout.js.map +1 -0
  119. package/dist/three/frame/lighting-material.d.ts +41 -0
  120. package/dist/three/frame/lighting-material.js +257 -0
  121. package/dist/three/frame/lighting-material.js.map +1 -0
  122. package/dist/three/frame/lights.d.ts +11 -0
  123. package/dist/three/frame/lights.js +16 -0
  124. package/dist/three/frame/lights.js.map +1 -0
  125. package/dist/three/frame/medium.d.ts +21 -0
  126. package/dist/three/frame/medium.js +29 -0
  127. package/dist/three/frame/medium.js.map +1 -0
  128. package/dist/three/frame/neural.d.ts +14 -0
  129. package/dist/three/frame/neural.js +105 -0
  130. package/dist/three/frame/neural.js.map +1 -0
  131. package/dist/three/frame/phase.d.ts +44 -0
  132. package/dist/three/frame/phase.js +80 -0
  133. package/dist/three/frame/phase.js.map +1 -0
  134. package/dist/three/frame/renderer.d.ts +493 -0
  135. package/dist/three/frame/renderer.js +1498 -0
  136. package/dist/three/frame/renderer.js.map +1 -0
  137. package/dist/three/frame/shadow-density-material.d.ts +30 -0
  138. package/dist/three/frame/shadow-density-material.js +123 -0
  139. package/dist/three/frame/shadow-density-material.js.map +1 -0
  140. package/dist/three/frame/spectrum.d.ts +18 -0
  141. package/dist/three/frame/spectrum.js +36 -0
  142. package/dist/three/frame/spectrum.js.map +1 -0
  143. package/dist/three/frame/temporal-material.d.ts +29 -0
  144. package/dist/three/frame/temporal-material.js +152 -0
  145. package/dist/three/frame/temporal-material.js.map +1 -0
  146. package/dist/three/frame/three-internals.d.ts +65 -0
  147. package/dist/three/frame/three-internals.js +150 -0
  148. package/dist/three/frame/three-internals.js.map +1 -0
  149. package/dist/three/frame/transmittance-material.d.ts +31 -0
  150. package/dist/three/frame/transmittance-material.js +315 -0
  151. package/dist/three/frame/transmittance-material.js.map +1 -0
  152. package/dist/three/frame/view.d.ts +103 -0
  153. package/dist/three/frame/view.js +296 -0
  154. package/dist/three/frame/view.js.map +1 -0
  155. package/dist/three/frame/volume-shadow-material.d.ts +36 -0
  156. package/dist/three/frame/volume-shadow-material.js +128 -0
  157. package/dist/three/frame/volume-shadow-material.js.map +1 -0
  158. package/dist/three/frame/volume-shadows.d.ts +153 -0
  159. package/dist/three/frame/volume-shadows.js +756 -0
  160. package/dist/three/frame/volume-shadows.js.map +1 -0
  161. package/dist/three/frame/volume.d.ts +172 -0
  162. package/dist/three/frame/volume.js +256 -0
  163. package/dist/three/frame/volume.js.map +1 -0
  164. package/dist/three/grid-node.d.ts +196 -0
  165. package/dist/three/grid-node.js +510 -0
  166. package/dist/three/grid-node.js.map +1 -0
  167. package/dist/three/index.d.ts +43 -0
  168. package/dist/three/index.js +49 -0
  169. package/dist/three/index.js.map +1 -0
  170. package/dist/three/internal.d.ts +14 -0
  171. package/dist/three/internal.js +14 -0
  172. package/dist/three/internal.js.map +1 -0
  173. package/dist/three/level-set-material.d.ts +112 -0
  174. package/dist/three/level-set-material.js +204 -0
  175. package/dist/three/level-set-material.js.map +1 -0
  176. package/dist/three/material.d.ts +194 -0
  177. package/dist/three/material.js +359 -0
  178. package/dist/three/material.js.map +1 -0
  179. package/dist/three/points.d.ts +84 -0
  180. package/dist/three/points.js +130 -0
  181. package/dist/three/points.js.map +1 -0
  182. package/dist/three/sequence.d.ts +317 -0
  183. package/dist/three/sequence.js +526 -0
  184. package/dist/three/sequence.js.map +1 -0
  185. package/dist/three/sparse-source.d.ts +233 -0
  186. package/dist/three/sparse-source.js +876 -0
  187. package/dist/three/sparse-source.js.map +1 -0
  188. package/dist/three/volume-source.d.ts +167 -0
  189. package/dist/three/volume-source.js +353 -0
  190. package/dist/three/volume-source.js.map +1 -0
  191. package/dist/tools/cpu/compute.d.ts +97 -0
  192. package/dist/tools/cpu/compute.js +218 -0
  193. package/dist/tools/cpu/compute.js.map +1 -0
  194. package/dist/tools/cpu/level-set.d.ts +72 -0
  195. package/dist/tools/cpu/level-set.js +261 -0
  196. package/dist/tools/cpu/level-set.js.map +1 -0
  197. package/dist/tools/cpu/march.d.ts +206 -0
  198. package/dist/tools/cpu/march.js +575 -0
  199. package/dist/tools/cpu/march.js.map +1 -0
  200. package/dist/tools/cpu/probe-coords.d.ts +70 -0
  201. package/dist/tools/cpu/probe-coords.js +116 -0
  202. package/dist/tools/cpu/probe-coords.js.map +1 -0
  203. package/dist/tools/cpu/read-value.d.ts +31 -0
  204. package/dist/tools/cpu/read-value.js +336 -0
  205. package/dist/tools/cpu/read-value.js.map +1 -0
  206. package/dist/tools/cpu/sample-trilinear.d.ts +30 -0
  207. package/dist/tools/cpu/sample-trilinear.js +156 -0
  208. package/dist/tools/cpu/sample-trilinear.js.map +1 -0
  209. package/dist/tools/cpu/stride-tables.d.ts +56 -0
  210. package/dist/tools/cpu/stride-tables.generated.d.ts +1058 -0
  211. package/dist/tools/cpu/stride-tables.generated.js +1266 -0
  212. package/dist/tools/cpu/stride-tables.generated.js.map +1 -0
  213. package/dist/tools/cpu/stride-tables.js +78 -0
  214. package/dist/tools/cpu/stride-tables.js.map +1 -0
  215. package/dist/tools/errors.d.ts +57 -0
  216. package/dist/tools/errors.js +58 -0
  217. package/dist/tools/errors.js.map +1 -0
  218. package/dist/tools/frame/blackbody.d.ts +42 -0
  219. package/dist/tools/frame/blackbody.js +116 -0
  220. package/dist/tools/frame/blackbody.js.map +1 -0
  221. package/dist/tools/frame/emission.d.ts +128 -0
  222. package/dist/tools/frame/emission.js +282 -0
  223. package/dist/tools/frame/emission.js.map +1 -0
  224. package/dist/tools/frame/environment.d.ts +105 -0
  225. package/dist/tools/frame/environment.js +268 -0
  226. package/dist/tools/frame/environment.js.map +1 -0
  227. package/dist/tools/frame/grid.d.ts +302 -0
  228. package/dist/tools/frame/grid.js +703 -0
  229. package/dist/tools/frame/grid.js.map +1 -0
  230. package/dist/tools/frame/index.d.ts +136 -0
  231. package/dist/tools/frame/index.js +348 -0
  232. package/dist/tools/frame/index.js.map +1 -0
  233. package/dist/tools/frame/medium.d.ts +61 -0
  234. package/dist/tools/frame/medium.js +99 -0
  235. package/dist/tools/frame/medium.js.map +1 -0
  236. package/dist/tools/frame/mie-table.d.ts +6 -0
  237. package/dist/tools/frame/mie-table.js +16 -0
  238. package/dist/tools/frame/mie-table.js.map +1 -0
  239. package/dist/tools/frame/mie.d.ts +54 -0
  240. package/dist/tools/frame/mie.js +176 -0
  241. package/dist/tools/frame/mie.js.map +1 -0
  242. package/dist/tools/frame/neural-weights.d.ts +9 -0
  243. package/dist/tools/frame/neural-weights.js +245 -0
  244. package/dist/tools/frame/neural-weights.js.map +1 -0
  245. package/dist/tools/frame/neural.d.ts +80 -0
  246. package/dist/tools/frame/neural.js +150 -0
  247. package/dist/tools/frame/neural.js.map +1 -0
  248. package/dist/tools/frame/pyramid-layout.d.ts +38 -0
  249. package/dist/tools/frame/pyramid-layout.js +53 -0
  250. package/dist/tools/frame/pyramid-layout.js.map +1 -0
  251. package/dist/tools/frame/shadows.d.ts +80 -0
  252. package/dist/tools/frame/shadows.js +182 -0
  253. package/dist/tools/frame/shadows.js.map +1 -0
  254. package/dist/tools/frame/sparse.d.ts +65 -0
  255. package/dist/tools/frame/sparse.js +191 -0
  256. package/dist/tools/frame/sparse.js.map +1 -0
  257. package/dist/tools/frame/spectral.d.ts +203 -0
  258. package/dist/tools/frame/spectral.js +550 -0
  259. package/dist/tools/frame/spectral.js.map +1 -0
  260. package/dist/tools/index.d.ts +106 -0
  261. package/dist/tools/index.js +88 -0
  262. package/dist/tools/index.js.map +1 -0
  263. package/dist/tools/internal.d.ts +46 -0
  264. package/dist/tools/internal.js +31 -0
  265. package/dist/tools/internal.js.map +1 -0
  266. package/dist/tools/nanovdb/build-from-vdb.d.ts +50 -0
  267. package/dist/tools/nanovdb/build-from-vdb.js +92 -0
  268. package/dist/tools/nanovdb/build-from-vdb.js.map +1 -0
  269. package/dist/tools/nanovdb/bytes.d.ts +220 -0
  270. package/dist/tools/nanovdb/bytes.js +345 -0
  271. package/dist/tools/nanovdb/bytes.js.map +1 -0
  272. package/dist/tools/nanovdb/coarse-first.d.ts +62 -0
  273. package/dist/tools/nanovdb/coarse-first.js +86 -0
  274. package/dist/tools/nanovdb/coarse-first.js.map +1 -0
  275. package/dist/tools/nanovdb/index.d.ts +32 -0
  276. package/dist/tools/nanovdb/index.js +24 -0
  277. package/dist/tools/nanovdb/index.js.map +1 -0
  278. package/dist/tools/nanovdb/inspect.d.ts +24 -0
  279. package/dist/tools/nanovdb/inspect.js +63 -0
  280. package/dist/tools/nanovdb/inspect.js.map +1 -0
  281. package/dist/tools/nanovdb/leaf-codec.d.ts +85 -0
  282. package/dist/tools/nanovdb/leaf-codec.js +320 -0
  283. package/dist/tools/nanovdb/leaf-codec.js.map +1 -0
  284. package/dist/tools/nanovdb/quantize.d.ts +43 -0
  285. package/dist/tools/nanovdb/quantize.js +277 -0
  286. package/dist/tools/nanovdb/quantize.js.map +1 -0
  287. package/dist/tools/nanovdb/resample.d.ts +160 -0
  288. package/dist/tools/nanovdb/resample.js +679 -0
  289. package/dist/tools/nanovdb/resample.js.map +1 -0
  290. package/dist/tools/nanovdb/serialize.d.ts +145 -0
  291. package/dist/tools/nanovdb/serialize.js +395 -0
  292. package/dist/tools/nanovdb/serialize.js.map +1 -0
  293. package/dist/tools/nanovdb/stats.d.ts +58 -0
  294. package/dist/tools/nanovdb/stats.js +149 -0
  295. package/dist/tools/nanovdb/stats.js.map +1 -0
  296. package/dist/tools/nanovdb/transform.d.ts +26 -0
  297. package/dist/tools/nanovdb/transform.js +91 -0
  298. package/dist/tools/nanovdb/transform.js.map +1 -0
  299. package/dist/tools/nanovdb/tree.d.ts +175 -0
  300. package/dist/tools/nanovdb/tree.js +518 -0
  301. package/dist/tools/nanovdb/tree.js.map +1 -0
  302. package/dist/tools/nanovdb/write-nvdb.d.ts +39 -0
  303. package/dist/tools/nanovdb/write-nvdb.js +210 -0
  304. package/dist/tools/nanovdb/write-nvdb.js.map +1 -0
  305. package/dist/tools/nvdb-file.d.ts +195 -0
  306. package/dist/tools/nvdb-file.js +606 -0
  307. package/dist/tools/nvdb-file.js.map +1 -0
  308. package/dist/tools/nvdb-stream.d.ts +138 -0
  309. package/dist/tools/nvdb-stream.js +365 -0
  310. package/dist/tools/nvdb-stream.js.map +1 -0
  311. package/dist/tools/vdb/bit-utils.d.ts +20 -0
  312. package/dist/tools/vdb/bit-utils.js +42 -0
  313. package/dist/tools/vdb/bit-utils.js.map +1 -0
  314. package/dist/tools/vdb/blosc.d.ts +56 -0
  315. package/dist/tools/vdb/blosc.js +231 -0
  316. package/dist/tools/vdb/blosc.js.map +1 -0
  317. package/dist/tools/vdb/byte-reader.d.ts +40 -0
  318. package/dist/tools/vdb/byte-reader.js +139 -0
  319. package/dist/tools/vdb/byte-reader.js.map +1 -0
  320. package/dist/tools/vdb/compression.d.ts +73 -0
  321. package/dist/tools/vdb/compression.js +249 -0
  322. package/dist/tools/vdb/compression.js.map +1 -0
  323. package/dist/tools/vdb/errors.d.ts +10 -0
  324. package/dist/tools/vdb/errors.js +11 -0
  325. package/dist/tools/vdb/errors.js.map +1 -0
  326. package/dist/tools/vdb/grid.d.ts +37 -0
  327. package/dist/tools/vdb/grid.js +147 -0
  328. package/dist/tools/vdb/grid.js.map +1 -0
  329. package/dist/tools/vdb/half-float.d.ts +9 -0
  330. package/dist/tools/vdb/half-float.js +24 -0
  331. package/dist/tools/vdb/half-float.js.map +1 -0
  332. package/dist/tools/vdb/index.d.ts +3 -0
  333. package/dist/tools/vdb/index.js +3 -0
  334. package/dist/tools/vdb/index.js.map +1 -0
  335. package/dist/tools/vdb/inflate.d.ts +24 -0
  336. package/dist/tools/vdb/inflate.js +334 -0
  337. package/dist/tools/vdb/inflate.js.map +1 -0
  338. package/dist/tools/vdb/metadata.d.ts +17 -0
  339. package/dist/tools/vdb/metadata.js +72 -0
  340. package/dist/tools/vdb/metadata.js.map +1 -0
  341. package/dist/tools/vdb/parse.d.ts +25 -0
  342. package/dist/tools/vdb/parse.js +171 -0
  343. package/dist/tools/vdb/parse.js.map +1 -0
  344. package/dist/tools/vdb/point-render-data.d.ts +31 -0
  345. package/dist/tools/vdb/point-render-data.js +57 -0
  346. package/dist/tools/vdb/point-render-data.js.map +1 -0
  347. package/dist/tools/vdb/points.d.ts +160 -0
  348. package/dist/tools/vdb/points.js +794 -0
  349. package/dist/tools/vdb/points.js.map +1 -0
  350. package/dist/tools/vdb/transform.d.ts +23 -0
  351. package/dist/tools/vdb/transform.js +54 -0
  352. package/dist/tools/vdb/transform.js.map +1 -0
  353. package/dist/tools/vdb/tree.d.ts +111 -0
  354. package/dist/tools/vdb/tree.js +228 -0
  355. package/dist/tools/vdb/tree.js.map +1 -0
  356. package/dist/tools/vdb/types.d.ts +138 -0
  357. package/dist/tools/vdb/types.js +3 -0
  358. package/dist/tools/vdb/types.js.map +1 -0
  359. package/dist/tools/wvdb/bake.d.ts +116 -0
  360. package/dist/tools/wvdb/bake.js +311 -0
  361. package/dist/tools/wvdb/bake.js.map +1 -0
  362. package/dist/tools/wvdb/dense.d.ts +112 -0
  363. package/dist/tools/wvdb/dense.js +309 -0
  364. package/dist/tools/wvdb/dense.js.map +1 -0
  365. package/dist/tools/wvdb/format.d.ts +161 -0
  366. package/dist/tools/wvdb/format.js +303 -0
  367. package/dist/tools/wvdb/format.js.map +1 -0
  368. package/dist/tools/wvdb/index.d.ts +13 -0
  369. package/dist/tools/wvdb/index.js +14 -0
  370. package/dist/tools/wvdb/index.js.map +1 -0
  371. package/dist/tools/wvdb/level-set.d.ts +48 -0
  372. package/dist/tools/wvdb/level-set.js +153 -0
  373. package/dist/tools/wvdb/level-set.js.map +1 -0
  374. package/dist/tools/wvdb/nanovdb.d.ts +54 -0
  375. package/dist/tools/wvdb/nanovdb.js +60 -0
  376. package/dist/tools/wvdb/nanovdb.js.map +1 -0
  377. package/dist/tools/wvdb/read.d.ts +260 -0
  378. package/dist/tools/wvdb/read.js +743 -0
  379. package/dist/tools/wvdb/read.js.map +1 -0
  380. package/dist/tools/wvdb/sha256.d.ts +7 -0
  381. package/dist/tools/wvdb/sha256.js +76 -0
  382. package/dist/tools/wvdb/sha256.js.map +1 -0
  383. package/dist/tools/wvdb/write.d.ts +127 -0
  384. package/dist/tools/wvdb/write.js +396 -0
  385. package/dist/tools/wvdb/write.js.map +1 -0
  386. package/package.json +82 -4
  387. package/vendor/LICENSE +201 -0
  388. package/vendor/NOTICE +19 -0
  389. package/vendor/VENDOR.md +85 -0
  390. package/vendor/pnanovdb.wgsl +1539 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nvdb-stream.js","sourceRoot":"","sources":["../../src/tools/nvdb-stream.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClF,OAAO,EACL,SAAS,EACT,gBAAgB,EAChB,kBAAkB,EAClB,cAAc,EACd,kBAAkB,EAClB,aAAa,EACb,gBAAgB,EAChB,aAAa,EACb,YAAY,EACZ,cAAc,EACd,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EAChB,gBAAgB,GAGjB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,eAAe,EAAE,CAAC;AAiC3B;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,QAA2D;IAC5F,MAAM,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;IAC1D,IAAI,QAAQ,KAAK,IAAI,IAAI,QAAQ,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,QAAQ,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,KAAK,UAAU;QAAE,OAAO,IAAI,CAAC;IAC7G,MAAM,GAAG,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;IACnD,IAAI,GAAG,KAAK,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;QAAE,OAAO,IAAI,CAAC;IAC3D,MAAM,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;IAC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C,CAAC,CAAC,EAAE,GAAG,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;QACvG,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC;IACvB,CAAC;IACD,MAAM,MAAM,GAAG,IAAI,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAC7C,IAAI,OAAQ,MAAqC,CAAC,SAAS,KAAK,UAAU,EAAE,CAAC;QAC3E,MAAM,CAAC,GAAI,MAAqC,CAAC,SAAS,EAAE,CAAC;QAC7D,IAAI,QAAQ,GAAG,KAAK,CAAC;QACrB,IAAI,CAAC;YACH,SAAS,CAAC;gBACR,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC;gBACvC,IAAI,IAAI;oBAAE,MAAM;gBAChB,KAAK,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAC5B,CAAC;YACD,QAAQ,GAAG,IAAI,CAAC;YAChB,MAAM,CAAC,GAAG,EAAE,CAAC;QACf,CAAC;gBAAS,CAAC;YACT,IAAI,CAAC,QAAQ;gBAAE,MAAM,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;YACvD,CAAC,CAAC,WAAW,EAAE,CAAC;QAClB,CAAC;QACD,OAAO;IACT,CAAC;IACD,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,MAAmC;QAAE,KAAK,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACzF,MAAM,CAAC,GAAG,EAAE,CAAC;AACf,CAAC","sourcesContent":["/**\n * `NvdbStreamReader` (K4.16): read a `.nvdb` file from pushed bytes and emit\n * each grid as soon as its data is complete, so a coarse preview written first\n * (docs/dev/design/K4-5-coarse-first.md, option a) can be drawn while the full\n * grid is still downloading.\n *\n * const reader = new NvdbStreamReader();\n * for await (const chunk of response.body) for (const g of reader.push(chunk)) show(g);\n * reader.end(); // throws if the stream stopped mid-grid\n *\n * The framing is NanoVDB's `io::Segment` (IO.h; see `nvdb-file.ts`): a 16-byte\n * FileHeader, then a 176-byte FileMetaData + name per grid, then each grid's\n * data (the image for codec NONE; a u64 size + zlib stream for codec ZIP). A\n * file is one or more segments. Every size the reader allocates is declared\n * up front, so it checks each one before allocating:\n *\n * - `gridSize` must be a safe integer, at least a GridData header, and at most\n * `maxGridBytes` (default 1 GiB);\n * - a ZIP payload must be at most zlib's `compressBound(gridSize)` (+64), and\n * inflates into gridSize + 1 bytes at most (`inflateZipGrid`);\n * - a grid name is at most `maxNameBytes` (default 64 KiB).\n *\n * Memory: the reader holds the current segment's metadata and the grid it is\n * filling, never the whole file. Emitted images are handed off (a fresh buffer\n * per grid, 4-byte aligned, so `image` is a zero-copy `Uint32Array`).\n *\n * Errors are `NvdbFormatError` (a `VDBToolsError`) for malformed or\n * truncated data and `VDBUnsupportedError` for valid data out of scope\n * (BLOSC, a raw `NanoVDB1` grid buffer, unsupported grid types). After an\n * error the reader is failed: every later `push` rethrows it.\n */\n\nimport { NvdbFormatError, VDBToolsError, VDBUnsupportedError } from \"./errors.js\";\nimport {\n NvdbCodec,\n FILE_HEADER_SIZE,\n FILE_METADATA_SIZE,\n GRID_DATA_SIZE,\n assertSafeGridSize,\n decodeCString,\n finishGridRecord,\n gridClassName,\n gridTypeName,\n inflateZipGrid,\n isFileHeaderMagic,\n readFileHeader,\n readFileMetaData,\n validateGridType,\n type NvdbGridMetadata,\n type ParsedFileMetaData,\n} from \"./nvdb-file.js\";\n\nexport { NvdbFormatError };\n\nexport interface NvdbStreamReaderOptions {\n /** Largest `gridSize` (decoded image bytes) the reader allocates. Default 1 GiB. */\n maxGridBytes?: number;\n /** Largest grid name (FileMetaData.nameSize). Default 64 KiB. */\n maxNameBytes?: number;\n /**\n * The whole stream's size in bytes when the caller knows it (a Response's\n * Content-Length: see {@link nvdbResponseLength}). Takes precedence over the\n * size derived from the grids' FileMetaData.\n */\n bytesTotal?: number;\n /** Called after every `push` with the progress so far (not inside the push's error handling). */\n onProgress?: (progress: NvdbProgress) => void;\n}\n\n/** Download progress of an {@link NvdbStreamReader}. */\nexport interface NvdbProgress {\n /** File bytes pushed so far (what the reader consumed; decoded bytes if the transport decompresses). */\n bytesReceived: number;\n /**\n * The expected total, or null while unknown: the `bytesTotal` option when\n * given, else the end of the latest segment whose FileMetaData have all\n * arrived (header + every grid's metadata, name and `fileSize`). That is\n * exact for a one-segment file and a lower bound while a later segment is\n * still ahead. Null until the first segment's metadata is in.\n */\n bytesTotal: number | null;\n /** Grids emitted so far. */\n gridsEmitted: number;\n}\n\n/**\n * The byte length of a `fetch` Response's body when the header says so: its\n * Content-Length, unless a Content-Encoding makes the (decoded) bytes the\n * reader sees differ from it. Null when unknown.\n */\nexport function nvdbResponseLength(response: { headers: { get(name: string): string | null } }): number | null {\n const encoding = response.headers.get(\"content-encoding\");\n if (encoding !== null && encoding.trim() !== \"\" && encoding.trim().toLowerCase() !== \"identity\") return null;\n const raw = response.headers.get(\"content-length\");\n if (raw === null || !/^\\d+$/.test(raw.trim())) return null;\n const n = Number(raw);\n return Number.isSafeInteger(n) ? n : null;\n}\n\n/** One grid, emitted by {@link NvdbStreamReader.push} as soon as its data is complete. */\nexport interface NvdbStreamGrid {\n /** Grid number in the file (counted across segments). */\n index: number;\n metadata: NvdbGridMetadata;\n /** The decoded grid image (zero-copy view of a buffer of its own). */\n image: Uint32Array;\n /** File bytes pushed when this grid completed (the end of its data). */\n bytesReceived: number;\n /** The expected file size when this grid completed, or null if unknown (see {@link NvdbProgress.bytesTotal}). */\n bytesTotal: number | null;\n /** The preview level from a `<name>.lod<N>` name, or null for a full grid. */\n lod: number | null;\n /** The name without its `.lod<N>` suffix (the full grid's name). */\n baseName: string;\n}\n\nconst DEFAULT_MAX_GRID_BYTES = 1 << 30;\nconst DEFAULT_MAX_NAME_BYTES = 1 << 16;\nconst ZIP_PREFIX = 8;\n\n/** zlib's `compressBound` (the largest `compress()` output for `n` input bytes), plus slack. */\nfunction zipBound(n: number): number {\n return n + Math.floor(n / 4096) + Math.floor(n / 16384) + Math.floor(n / 33554432) + 13 + 64;\n}\n\nconst LOD_SUFFIX = /^(.*)\\.lod(\\d+)$/;\n\n/** The preview name for `name` at `resolution`: `<name>.lod<resolution>` (K4.5). */\nexport function nvdbLodName(name: string, resolution: number): string {\n if (!Number.isInteger(resolution) || resolution < 1) {\n throw new VDBToolsError(\"VDB_BAD_OPTION\", `nvdbLodName: resolution must be a positive integer, got ${resolution}`);\n }\n return `${name}.lod${resolution}`;\n}\n\n/** Splits a `<name>.lod<N>` preview name; a full grid's name gives `lod: null`. */\nexport function parseNvdbLodName(name: string): { baseName: string; lod: number | null } {\n const m = LOD_SUFFIX.exec(name);\n return m ? { baseName: m[1]!, lod: Number(m[2]) } : { baseName: name, lod: null };\n}\n\ntype Phase = \"header\" | \"meta\" | \"name\" | \"zipPrefix\" | \"grid\";\n\ninterface PendingGrid {\n meta: ParsedFileMetaData;\n name: string;\n}\n\n/**\n * Push-based `.nvdb` reader: `push(chunk)` returns the grids that chunk\n * completed. Call `end()` when the stream ends to detect truncation.\n */\nexport class NvdbStreamReader {\n readonly #maxGridBytes: number;\n readonly #maxNameBytes: number;\n readonly #onProgress: ((progress: NvdbProgress) => void) | undefined;\n readonly #declaredTotal: number | null;\n #segmentStart = 0;\n #knownEnd: number | null = null;\n\n /** Small fixed-size fields (FileHeader, FileMetaData, ZIP prefix) and names. */\n #scratch = new Uint8Array(FILE_METADATA_SIZE);\n /** The buffer being filled (scratch or a grid payload) and how far. */\n #target: Uint8Array;\n #filled = 0;\n\n #phase: Phase = \"header\";\n #codec: NvdbCodec = NvdbCodec.NONE;\n #segmentGrids = 0;\n #pending: PendingGrid[] = [];\n #nextMeta: ParsedFileMetaData | null = null;\n #gridInSegment = 0;\n #received = 0;\n #segments = 0;\n #emitted = 0;\n #failed: Error | null = null;\n readonly #grids: NvdbGridMetadata[] = [];\n\n constructor(options: NvdbStreamReaderOptions = {}) {\n this.#maxGridBytes = options.maxGridBytes ?? DEFAULT_MAX_GRID_BYTES;\n this.#maxNameBytes = options.maxNameBytes ?? DEFAULT_MAX_NAME_BYTES;\n if (!Number.isSafeInteger(this.#maxGridBytes) || this.#maxGridBytes < GRID_DATA_SIZE) {\n throw new VDBToolsError(\"VDB_BAD_OPTION\", `NvdbStreamReader: maxGridBytes must be an integer >= ${GRID_DATA_SIZE}`);\n }\n if (!Number.isSafeInteger(this.#maxNameBytes) || this.#maxNameBytes < 1) {\n throw new VDBToolsError(\"VDB_BAD_OPTION\", \"NvdbStreamReader: maxNameBytes must be a positive integer\");\n }\n this.#onProgress = options.onProgress;\n this.#declaredTotal = options.bytesTotal ?? null;\n if (this.#declaredTotal !== null && (!Number.isSafeInteger(this.#declaredTotal) || this.#declaredTotal < 0)) {\n throw new VDBToolsError(\"VDB_BAD_OPTION\", \"NvdbStreamReader: bytesTotal must be a non-negative integer\");\n }\n this.#target = this.#scratch.subarray(0, FILE_HEADER_SIZE);\n }\n\n /** The expected file size in bytes, or null while unknown (see {@link NvdbProgress.bytesTotal}). */\n get bytesTotal(): number | null {\n return this.#declaredTotal ?? this.#knownEnd;\n }\n\n /** Progress so far. */\n get progress(): NvdbProgress {\n return { bytesReceived: this.#received, bytesTotal: this.bytesTotal, gridsEmitted: this.#emitted };\n }\n\n /** File bytes pushed so far. */\n get bytesReceived(): number {\n return this.#received;\n }\n\n /** Grids emitted so far. */\n get gridsEmitted(): number {\n return this.#emitted;\n }\n\n /**\n * Metadata of every grid whose FileMetaData has arrived, in file order,\n * including grids whose data has not (a segment lists all its grids before\n * any data, so the full grid's `gridByteSize` is known before its preview\n * is emitted). Names are as stored; see {@link parseNvdbLodName}.\n */\n get grids(): readonly NvdbGridMetadata[] {\n return this.#grids;\n }\n\n /** True between segments: every grid announced so far has been emitted. */\n get atBoundary(): boolean {\n return this.#phase === \"header\" && this.#filled === 0 && this.#segments > 0;\n }\n\n /** Pushes the next bytes of the file; returns the grids they completed, in order. */\n push(chunk: Uint8Array): NvdbStreamGrid[] {\n if (this.#failed) throw this.#failed;\n const out: NvdbStreamGrid[] = [];\n try {\n let at = 0;\n while (at < chunk.byteLength) {\n const take = Math.min(chunk.byteLength - at, this.#target.byteLength - this.#filled);\n this.#target.set(chunk.subarray(at, at + take), this.#filled);\n this.#filled += take;\n at += take;\n this.#received += take;\n if (this.#filled === this.#target.byteLength) this.#advance(out);\n }\n // A zero-length target (an empty name) completes without bytes.\n while (this.#target.byteLength === 0 && this.#filled === 0 && this.#phase !== \"header\") this.#advance(out);\n } catch (err) {\n this.#failed = err instanceof VDBToolsError ? err : new NvdbFormatError((err as Error).message);\n throw this.#failed;\n }\n if (this.#onProgress && chunk.byteLength > 0) this.#onProgress(this.progress);\n return out;\n }\n\n /** Declares the end of the stream; throws `NvdbFormatError` if it stopped inside a segment. */\n end(): void {\n if (this.#failed) throw this.#failed;\n if (this.atBoundary) return;\n this.#failed = new NvdbFormatError(\n `the stream ended after ${this.#received} bytes, in the ${this.#describe()}; the file is truncated.`,\n );\n throw this.#failed;\n }\n\n #describe(): string {\n const grid = this.#segmentFirst() + this.#gridInSegment;\n switch (this.#phase) {\n case \"header\":\n return `FileHeader, ${this.#filled} of ${FILE_HEADER_SIZE} bytes`;\n case \"meta\":\n return `FileMetaData of grid #${this.#grids.length}, ${this.#filled} of ${FILE_METADATA_SIZE} bytes`;\n case \"name\":\n return `name of grid #${this.#grids.length}`;\n case \"zipPrefix\":\n return `ZIP size prefix of grid #${grid}`;\n case \"grid\":\n return `data of grid #${grid}, ${this.#filled} of ${this.#target.byteLength} bytes`;\n }\n }\n\n #segmentFirst(): number {\n return this.#grids.length - this.#segmentGrids;\n }\n\n #expect(phase: Phase, target: Uint8Array): void {\n this.#phase = phase;\n this.#target = target;\n this.#filled = 0;\n }\n\n #advance(out: NvdbStreamGrid[]): void {\n switch (this.#phase) {\n case \"header\": {\n const magic = String.fromCharCode(...this.#scratch.subarray(0, 8));\n if (!isFileHeaderMagic(magic)) {\n if (magic === \"NanoVDB1\") {\n throw new VDBUnsupportedError(\n \".nvdb stream: this is a raw NanoVDB grid buffer (magic NanoVDB1), not a segment file; read it whole with NvdbFile.fromArrayBuffer.\",\n );\n }\n throw new NvdbFormatError(\n `expected a NanoVDB FileHeader (magic NanoVDB2 or NanoVDB0) at byte ${this.#received - FILE_HEADER_SIZE}, found \"${magic.replace(/[^\\x20-\\x7e]/g, \"?\")}\".`,\n );\n }\n const view = new DataView(this.#scratch.buffer, 0, FILE_HEADER_SIZE);\n let header: { gridCount: number; codec: NvdbCodec };\n try {\n header = readFileHeader(view, 0);\n } catch (err) {\n const msg = (err as Error).message;\n if (/BLOSC/.test(msg)) throw new VDBUnsupportedError(msg);\n throw new NvdbFormatError(msg);\n }\n if (header.gridCount === 0) throw new NvdbFormatError(`segment #${this.#segments} declares 0 grids.`);\n this.#codec = header.codec;\n this.#segmentGrids = header.gridCount;\n this.#segments++;\n this.#segmentStart = this.#received - FILE_HEADER_SIZE;\n this.#pending = [];\n this.#gridInSegment = 0;\n this.#expect(\"meta\", this.#scratch.subarray(0, FILE_METADATA_SIZE));\n return;\n }\n case \"meta\": {\n const i = this.#grids.length;\n const meta = readFileMetaData(new DataView(this.#scratch.buffer, 0, FILE_METADATA_SIZE), 0);\n assertSafeGridSize(meta.gridSize, `grid #${i}'s FileMetaData.gridSize`);\n if (meta.gridSize < GRID_DATA_SIZE) {\n throw new NvdbFormatError(`grid #${i} declares gridSize ${meta.gridSize}, smaller than a ${GRID_DATA_SIZE}-byte GridData header.`);\n }\n if (meta.gridSize > this.#maxGridBytes) {\n throw new NvdbFormatError(\n `grid #${i} declares gridSize ${meta.gridSize} bytes, over maxGridBytes (${this.#maxGridBytes}); raise the option if the file is trusted.`,\n );\n }\n if (meta.nameSize > this.#maxNameBytes) {\n throw new NvdbFormatError(`grid #${i} declares a ${meta.nameSize}-byte name, over maxNameBytes (${this.#maxNameBytes}).`);\n }\n this.#nextMeta = meta;\n this.#expect(\"name\", meta.nameSize <= this.#scratch.byteLength ? this.#scratch.subarray(0, meta.nameSize) : new Uint8Array(meta.nameSize));\n return;\n }\n case \"name\": {\n const meta = this.#nextMeta!;\n const name = decodeCString(this.#target);\n const gridType = gridTypeName(meta.gridTypeId);\n try {\n validateGridType(gridType, name);\n } catch (err) {\n throw new VDBUnsupportedError((err as Error).message);\n }\n this.#pending.push({ meta, name });\n this.#grids.push({\n name,\n gridType,\n gridClass: gridClassName(meta.gridClassId),\n worldBBox: meta.worldBBox,\n indexBBox: meta.indexBBox,\n voxelSize: meta.voxelSize,\n voxelCount: meta.voxelCount,\n gridByteSize: meta.gridSize,\n });\n this.#nextMeta = null;\n if (this.#pending.length < this.#segmentGrids) this.#expect(\"meta\", this.#scratch.subarray(0, FILE_METADATA_SIZE));\n else {\n let end = this.#segmentStart + FILE_HEADER_SIZE;\n for (const g of this.#pending) end += FILE_METADATA_SIZE + g.meta.nameSize + g.meta.fileSize;\n this.#knownEnd = Number.isSafeInteger(end) ? end : null;\n this.#startGrid();\n }\n return;\n }\n case \"zipPrefix\": {\n const { meta, name } = this.#pending[this.#gridInSegment]!;\n const size = Number(new DataView(this.#scratch.buffer, 0, ZIP_PREFIX).getBigUint64(0, true));\n const bound = zipBound(meta.gridSize);\n if (!Number.isSafeInteger(size) || size < 1 || size > bound) {\n throw new NvdbFormatError(\n `grid #${this.#segmentFirst() + this.#gridInSegment} (\"${name}\") declares a ${size}-byte ZIP payload for a ` +\n `${meta.gridSize}-byte grid (zlib's bound is ${bound}).`,\n );\n }\n this.#expect(\"grid\", new Uint8Array(size));\n return;\n }\n case \"grid\": {\n const k = this.#gridInSegment;\n const index = this.#segmentFirst() + k;\n const { meta, name } = this.#pending[k]!;\n const bytes = this.#codec === NvdbCodec.ZIP ? inflateZipGrid(this.#target, meta.gridSize, index, name) : this.#target;\n const record = finishGridRecord(meta, name, index, bytes);\n this.#grids[index] = record.metadata;\n const { baseName, lod } = parseNvdbLodName(name);\n out.push({ index, metadata: record.metadata, image: record.image, bytesReceived: this.#received, bytesTotal: this.bytesTotal, lod, baseName });\n this.#emitted++;\n this.#gridInSegment++;\n if (this.#gridInSegment < this.#segmentGrids) this.#startGrid();\n else {\n this.#pending = [];\n this.#expect(\"header\", this.#scratch.subarray(0, FILE_HEADER_SIZE));\n }\n return;\n }\n }\n }\n\n #startGrid(): void {\n const { meta } = this.#pending[this.#gridInSegment]!;\n if (this.#codec === NvdbCodec.ZIP) this.#expect(\"zipPrefix\", this.#scratch.subarray(0, ZIP_PREFIX));\n else this.#expect(\"grid\", new Uint8Array(meta.gridSize));\n }\n}\n\n/** What {@link readNvdbStream} reads: a `fetch` Response (its Content-Length feeds `bytesTotal`), its body, or chunks. */\nexport type NvdbStreamSource =\n | { body: ReadableStream<Uint8Array> | null; headers: { get(name: string): string | null } }\n | ReadableStream<Uint8Array>\n | AsyncIterable<Uint8Array>;\n\nfunction isResponse(source: NvdbStreamSource): source is Extract<NvdbStreamSource, { headers: unknown }> {\n return typeof (source as { headers?: unknown }).headers === \"object\" && \"body\" in source;\n}\n\n/**\n * Reads a byte stream (a `fetch` Response or body, or any async iterable of chunks) through\n * an {@link NvdbStreamReader}, yielding each grid as it completes. Stops\n * reading (and cancels the stream) when the consumer breaks out of the loop.\n */\nexport async function* readNvdbStream(\n source: NvdbStreamSource,\n options: NvdbStreamReaderOptions = {},\n): AsyncGenerator<NvdbStreamGrid, void, undefined> {\n if (isResponse(source)) {\n const len = nvdbResponseLength(source);\n if (source.body === null) throw new NvdbFormatError(\"readNvdbStream: the response has no body.\");\n options = len !== null && options.bytesTotal === undefined ? { ...options, bytesTotal: len } : options;\n source = source.body;\n }\n const reader = new NvdbStreamReader(options);\n if (typeof (source as ReadableStream<Uint8Array>).getReader === \"function\") {\n const r = (source as ReadableStream<Uint8Array>).getReader();\n let finished = false;\n try {\n for (;;) {\n const { done, value } = await r.read();\n if (done) break;\n yield* reader.push(value);\n }\n finished = true;\n reader.end();\n } finally {\n if (!finished) await r.cancel().catch(() => undefined);\n r.releaseLock();\n }\n return;\n }\n for await (const chunk of source as AsyncIterable<Uint8Array>) yield* reader.push(chunk);\n reader.end();\n}\n"]}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * bit-utils.ts — bit-mask helpers shared by tree/compression code.
3
+ *
4
+ * OpenVDB node masks (child mask, value mask, selection mask) are serialized
5
+ * as arrays of 64-bit words, LSB-first within each word. We store them as
6
+ * `Uint32Array` instead of pairs of `bigint`s: splitting each on-disk u64 LE
7
+ * word into two u32 LE words preserves bit-for-bit ordinal position (word
8
+ * `i`'s bit `b` covers the same logical slot either way), and plain 32-bit
9
+ * ops are both faster and simpler in JS than `bigint` bit-twiddling.
10
+ */
11
+ /** Population count (number of set bits) of a 32-bit unsigned integer. */
12
+ export declare function popcount32(x: number): number;
13
+ /** Whether bit `index` is set in a mask stored as 32-bit words. */
14
+ export declare function testBit(words: Uint32Array, index: number): boolean;
15
+ /** Total number of set bits across every word (i.e. `countOn()`). */
16
+ export declare function countBits(words: Uint32Array): number;
17
+ /** Total number of unset bits across `bitCount` logical bits. */
18
+ export declare function countZeroBits(words: Uint32Array, bitCount: number): number;
19
+ /** Indices (ascending) of every set bit, 0..bitCount-1. */
20
+ export declare function iterOnes(words: Uint32Array, bitCount: number): Iterable<number>;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * bit-utils.ts — bit-mask helpers shared by tree/compression code.
3
+ *
4
+ * OpenVDB node masks (child mask, value mask, selection mask) are serialized
5
+ * as arrays of 64-bit words, LSB-first within each word. We store them as
6
+ * `Uint32Array` instead of pairs of `bigint`s: splitting each on-disk u64 LE
7
+ * word into two u32 LE words preserves bit-for-bit ordinal position (word
8
+ * `i`'s bit `b` covers the same logical slot either way), and plain 32-bit
9
+ * ops are both faster and simpler in JS than `bigint` bit-twiddling.
10
+ */
11
+ /** Population count (number of set bits) of a 32-bit unsigned integer. */
12
+ export function popcount32(x) {
13
+ let v = x >>> 0;
14
+ v = v - ((v >>> 1) & 0x55555555);
15
+ v = (v & 0x33333333) + ((v >>> 2) & 0x33333333);
16
+ v = (v + (v >>> 4)) & 0x0f0f0f0f;
17
+ return (v * 0x01010101) >>> 24;
18
+ }
19
+ /** Whether bit `index` is set in a mask stored as 32-bit words. */
20
+ export function testBit(words, index) {
21
+ const word = words[index >>> 5] ?? 0;
22
+ return ((word >>> (index & 31)) & 1) !== 0;
23
+ }
24
+ /** Total number of set bits across every word (i.e. `countOn()`). */
25
+ export function countBits(words) {
26
+ let total = 0;
27
+ for (let i = 0; i < words.length; i++)
28
+ total += popcount32(words[i]);
29
+ return total;
30
+ }
31
+ /** Total number of unset bits across `bitCount` logical bits. */
32
+ export function countZeroBits(words, bitCount) {
33
+ return bitCount - countBits(words);
34
+ }
35
+ /** Indices (ascending) of every set bit, 0..bitCount-1. */
36
+ export function* iterOnes(words, bitCount) {
37
+ for (let i = 0; i < bitCount; i++) {
38
+ if (testBit(words, i))
39
+ yield i;
40
+ }
41
+ }
42
+ //# sourceMappingURL=bit-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bit-utils.js","sourceRoot":"","sources":["../../../src/tools/vdb/bit-utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,0EAA0E;AAC1E,MAAM,UAAU,UAAU,CAAC,CAAS;IAClC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAChB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC;IACjC,CAAC,GAAG,CAAC,CAAC,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC;IAChD,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC;IACjC,OAAO,CAAC,CAAC,GAAG,UAAU,CAAC,KAAK,EAAE,CAAC;AACjC,CAAC;AAED,mEAAmE;AACnE,MAAM,UAAU,OAAO,CAAC,KAAkB,EAAE,KAAa;IACvD,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC;IACrC,OAAO,CAAC,CAAC,IAAI,KAAK,CAAC,KAAK,GAAG,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;AAC7C,CAAC;AAED,qEAAqE;AACrE,MAAM,UAAU,SAAS,CAAC,KAAkB;IAC1C,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE;QAAE,KAAK,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC,CAAE,CAAC,CAAC;IACtE,OAAO,KAAK,CAAC;AACf,CAAC;AAED,iEAAiE;AACjE,MAAM,UAAU,aAAa,CAAC,KAAkB,EAAE,QAAgB;IAChE,OAAO,QAAQ,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;AACrC,CAAC;AAED,2DAA2D;AAC3D,MAAM,SAAS,CAAC,CAAC,QAAQ,CAAC,KAAkB,EAAE,QAAgB;IAC5D,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,EAAE,CAAC,EAAE,EAAE,CAAC;QAClC,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;YAAE,MAAM,CAAC,CAAC;IACjC,CAAC;AACH,CAAC","sourcesContent":["/**\n * bit-utils.ts — bit-mask helpers shared by tree/compression code.\n *\n * OpenVDB node masks (child mask, value mask, selection mask) are serialized\n * as arrays of 64-bit words, LSB-first within each word. We store them as\n * `Uint32Array` instead of pairs of `bigint`s: splitting each on-disk u64 LE\n * word into two u32 LE words preserves bit-for-bit ordinal position (word\n * `i`'s bit `b` covers the same logical slot either way), and plain 32-bit\n * ops are both faster and simpler in JS than `bigint` bit-twiddling.\n */\n\n/** Population count (number of set bits) of a 32-bit unsigned integer. */\nexport function popcount32(x: number): number {\n let v = x >>> 0;\n v = v - ((v >>> 1) & 0x55555555);\n v = (v & 0x33333333) + ((v >>> 2) & 0x33333333);\n v = (v + (v >>> 4)) & 0x0f0f0f0f;\n return (v * 0x01010101) >>> 24;\n}\n\n/** Whether bit `index` is set in a mask stored as 32-bit words. */\nexport function testBit(words: Uint32Array, index: number): boolean {\n const word = words[index >>> 5] ?? 0;\n return ((word >>> (index & 31)) & 1) !== 0;\n}\n\n/** Total number of set bits across every word (i.e. `countOn()`). */\nexport function countBits(words: Uint32Array): number {\n let total = 0;\n for (let i = 0; i < words.length; i++) total += popcount32(words[i]!);\n return total;\n}\n\n/** Total number of unset bits across `bitCount` logical bits. */\nexport function countZeroBits(words: Uint32Array, bitCount: number): number {\n return bitCount - countBits(words);\n}\n\n/** Indices (ascending) of every set bit, 0..bitCount-1. */\nexport function* iterOnes(words: Uint32Array, bitCount: number): Iterable<number> {\n for (let i = 0; i < bitCount; i++) {\n if (testBit(words, i)) yield i;\n }\n}\n"]}
@@ -0,0 +1,56 @@
1
+ /**
2
+ * blosc.ts — a pure-TS decoder for the Blosc1 frames OpenVDB writes.
3
+ *
4
+ * OpenVDB (`io/Compression.cc`, `bloscToStream`) compresses each node's value
5
+ * buffer with `blosc_compress_ctx(clevel 9, byte shuffle, typesize
6
+ * sizeof(ValueType), ..., "lz4", blocksize = whole buffer)`, writing the
7
+ * compressed byte count as an i64 followed by one Blosc1 frame. The
8
+ * openvdb.org `bunny_cloud.vdb` and `explosion.vdb` samples are stored this
9
+ * way. This decoder covers the frames that writer produces, plus the
10
+ * `zlib` codec and memcpy'd frames for safety; other codecs (BloscLZ, Snappy,
11
+ * Zstd) and bit-shuffle throw `VDBUnsupportedError`.
12
+ *
13
+ * Frame layout (c-blosc 1.x `blosc.c`, format version 2):
14
+ *
15
+ * [0] version [1] versionlz [2] flags [3] typesize
16
+ * [4..8) nbytes (uncompressed) [8..12) blocksize [12..16) cbytes (whole frame)
17
+ * flags: 0x01 byte shuffle, 0x02 memcpy'd, 0x04 bit shuffle,
18
+ * 0x10 blocks not split, bits 5-7 codec (0 BloscLZ, 1 LZ4/LZ4HC,
19
+ * 2 Snappy, 3 zlib, 4 Zstd)
20
+ * memcpy'd: nbytes raw bytes follow the header.
21
+ * otherwise: nblocks i32 block starts (absolute frame offsets); each block
22
+ * holds `nsplits` streams (typesize streams when split -- flag bit 4 clear,
23
+ * typesize <= 16, block has >= 128 elements, not the short last block --
24
+ * else 1), each an i32 compressed size and its bytes. A
25
+ * stream whose size equals its uncompressed size is stored raw.
26
+ *
27
+ * Derived from the format description above, not from any third-party code.
28
+ */
29
+ export interface BloscLimits {
30
+ /** Largest uncompressed size the caller will accept; checked before allocating. */
31
+ maxBytes?: number;
32
+ /** The frame's required `cbytes` header field (what the enclosing format says it stored). */
33
+ expectedCbytes?: number;
34
+ }
35
+ /**
36
+ * Decompresses one Blosc1 frame and returns its `nbytes` uncompressed bytes.
37
+ *
38
+ * The frame is untrusted: every header field is validated against `maxBytes`
39
+ * (and the frame's own `cbytes`) before any allocation or read, mirroring
40
+ * c-blosc's `blosc_run_decompression_with_context` and `blosc_d` checks.
41
+ */
42
+ export declare function decompressBlosc(frame: Uint8Array, limits?: BloscLimits): Uint8Array;
43
+ /**
44
+ * Reverses Blosc's byte shuffle: the shuffled block stores byte `i` of every
45
+ * element together (`src[i * count + j]` is byte `i` of element `j`); trailing
46
+ * bytes that do not fill a whole element are stored unshuffled at the end.
47
+ */
48
+ export declare function unshuffle(src: Uint8Array, dest: Uint8Array, typesize: number): void;
49
+ /**
50
+ * Decodes one raw LZ4 block (no frame header) into `dest`, returning the
51
+ * number of bytes written. Each sequence is a token (high nibble literal
52
+ * length, low nibble match length - 4, 15 meaning "more bytes follow, each
53
+ * added, until one is < 255"), the literals, then a 2-byte little-endian
54
+ * match offset and the match; the last sequence carries literals only.
55
+ */
56
+ export declare function decompressLz4Block(src: Uint8Array, dest: Uint8Array): number;
@@ -0,0 +1,231 @@
1
+ /**
2
+ * blosc.ts — a pure-TS decoder for the Blosc1 frames OpenVDB writes.
3
+ *
4
+ * OpenVDB (`io/Compression.cc`, `bloscToStream`) compresses each node's value
5
+ * buffer with `blosc_compress_ctx(clevel 9, byte shuffle, typesize
6
+ * sizeof(ValueType), ..., "lz4", blocksize = whole buffer)`, writing the
7
+ * compressed byte count as an i64 followed by one Blosc1 frame. The
8
+ * openvdb.org `bunny_cloud.vdb` and `explosion.vdb` samples are stored this
9
+ * way. This decoder covers the frames that writer produces, plus the
10
+ * `zlib` codec and memcpy'd frames for safety; other codecs (BloscLZ, Snappy,
11
+ * Zstd) and bit-shuffle throw `VDBUnsupportedError`.
12
+ *
13
+ * Frame layout (c-blosc 1.x `blosc.c`, format version 2):
14
+ *
15
+ * [0] version [1] versionlz [2] flags [3] typesize
16
+ * [4..8) nbytes (uncompressed) [8..12) blocksize [12..16) cbytes (whole frame)
17
+ * flags: 0x01 byte shuffle, 0x02 memcpy'd, 0x04 bit shuffle,
18
+ * 0x10 blocks not split, bits 5-7 codec (0 BloscLZ, 1 LZ4/LZ4HC,
19
+ * 2 Snappy, 3 zlib, 4 Zstd)
20
+ * memcpy'd: nbytes raw bytes follow the header.
21
+ * otherwise: nblocks i32 block starts (absolute frame offsets); each block
22
+ * holds `nsplits` streams (typesize streams when split -- flag bit 4 clear,
23
+ * typesize <= 16, block has >= 128 elements, not the short last block --
24
+ * else 1), each an i32 compressed size and its bytes. A
25
+ * stream whose size equals its uncompressed size is stored raw.
26
+ *
27
+ * Derived from the format description above, not from any third-party code.
28
+ */
29
+ import { VdbFormatError, VDBUnsupportedError } from "./errors.js";
30
+ import { inflateZlib } from "./inflate.js";
31
+ const HEADER_SIZE = 16;
32
+ const FLAG_SHUFFLE = 0x01;
33
+ const FLAG_MEMCPYED = 0x02;
34
+ const FLAG_BITSHUFFLE = 0x04;
35
+ const FLAG_DONT_SPLIT = 0x10;
36
+ /** c-blosc `MAX_SPLITS` / `MIN_BUFFERSIZE`. */
37
+ const MAX_SPLITS = 16;
38
+ const MIN_BUFFERSIZE = 128;
39
+ const CODEC_NAMES = ["BloscLZ", "LZ4", "Snappy", "zlib", "Zstd"];
40
+ const CODEC_LZ4 = 1;
41
+ const CODEC_ZLIB = 3;
42
+ /** Default output cap when a caller does not know the expected size (1 GiB). */
43
+ const DEFAULT_MAX_BYTES = 1 << 30;
44
+ /**
45
+ * Decompresses one Blosc1 frame and returns its `nbytes` uncompressed bytes.
46
+ *
47
+ * The frame is untrusted: every header field is validated against `maxBytes`
48
+ * (and the frame's own `cbytes`) before any allocation or read, mirroring
49
+ * c-blosc's `blosc_run_decompression_with_context` and `blosc_d` checks.
50
+ */
51
+ export function decompressBlosc(frame, limits = {}) {
52
+ const maxBytes = limits.maxBytes ?? DEFAULT_MAX_BYTES;
53
+ if (frame.length < HEADER_SIZE) {
54
+ throw new VdbFormatError(`blosc frame is ${frame.length} bytes, shorter than its ${HEADER_SIZE}-byte header`);
55
+ }
56
+ const view = new DataView(frame.buffer, frame.byteOffset, frame.byteLength);
57
+ const version = frame[0];
58
+ const flags = frame[2];
59
+ const typesize = frame[3];
60
+ const nbytes = view.getUint32(4, true);
61
+ const blocksize = view.getUint32(8, true);
62
+ const cbytes = view.getUint32(12, true);
63
+ if (version === 0 || version > 2) {
64
+ throw new VDBUnsupportedError(`blosc frame format version ${version} (only Blosc1, versions 1-2, is supported)`);
65
+ }
66
+ if (flags & 0x08)
67
+ throw new VDBUnsupportedError("blosc frame has compressor flags from a future version");
68
+ if (cbytes < HEADER_SIZE || cbytes > frame.length) {
69
+ throw new VdbFormatError(`blosc header field cbytes=${cbytes} is outside the ${frame.length}-byte frame`);
70
+ }
71
+ if (limits.expectedCbytes !== undefined && cbytes !== limits.expectedCbytes) {
72
+ throw new VdbFormatError(`blosc header field cbytes=${cbytes} does not match the ${limits.expectedCbytes} compressed bytes stored`);
73
+ }
74
+ if (nbytes === 0)
75
+ return new Uint8Array(0);
76
+ if (nbytes > maxBytes) {
77
+ throw new VdbFormatError(`blosc header field nbytes=${nbytes} exceeds the expected ${maxBytes}-byte output`);
78
+ }
79
+ if (blocksize === 0 || blocksize > maxBytes) {
80
+ throw new VdbFormatError(`blosc header field blocksize=${blocksize} is zero or exceeds the expected ${maxBytes}-byte output`);
81
+ }
82
+ if (typesize === 0)
83
+ throw new VdbFormatError("blosc header field typesize is zero");
84
+ if (flags & FLAG_MEMCPYED) {
85
+ if (nbytes + HEADER_SIZE !== cbytes) {
86
+ throw new VdbFormatError(`memcpy'd blosc frame: cbytes=${cbytes} != nbytes(${nbytes}) + ${HEADER_SIZE}`);
87
+ }
88
+ return frame.slice(HEADER_SIZE, HEADER_SIZE + nbytes);
89
+ }
90
+ if (flags & FLAG_BITSHUFFLE) {
91
+ throw new VDBUnsupportedError("blosc bit-shuffle is not supported (OpenVDB writes byte shuffle)");
92
+ }
93
+ const codec = (flags >> 5) & 0x7;
94
+ if (codec !== CODEC_LZ4 && codec !== CODEC_ZLIB) {
95
+ throw new VDBUnsupportedError(`blosc codec ${CODEC_NAMES[codec] ?? `#${codec}`} is not supported (LZ4 and zlib are; OpenVDB writes LZ4)`);
96
+ }
97
+ const nblocks = Math.ceil(nbytes / blocksize);
98
+ const tableEnd = HEADER_SIZE + 4 * nblocks;
99
+ if (tableEnd > cbytes) {
100
+ throw new VdbFormatError(`blosc block-start table (${nblocks} blocks) does not fit in cbytes=${cbytes}`);
101
+ }
102
+ const out = new Uint8Array(nbytes);
103
+ const shuffle = (flags & FLAG_SHUFFLE) !== 0 && typesize > 1;
104
+ const dontSplit = (flags & FLAG_DONT_SPLIT) !== 0;
105
+ // Never larger than the output: blocksize <= maxBytes, and a block never exceeds nbytes.
106
+ const scratch = shuffle ? new Uint8Array(Math.min(blocksize, nbytes)) : null;
107
+ for (let b = 0; b < nblocks; b++) {
108
+ const bstart = view.getInt32(HEADER_SIZE + 4 * b, true);
109
+ if (bstart < tableEnd || bstart + 4 > cbytes) {
110
+ throw new VdbFormatError(`blosc block-start[${b}]=${bstart} is outside [${tableEnd}, ${cbytes - 4}]`);
111
+ }
112
+ const leftover = b === nblocks - 1 && nbytes % blocksize !== 0;
113
+ const bsize = leftover ? nbytes % blocksize : blocksize;
114
+ // c-blosc blosc_d: split only if the frame allows it, typesize <= MAX_SPLITS (16),
115
+ // the block holds >= MIN_BUFFERSIZE (128) elements, and it is not the leftover block.
116
+ // Frames from before the dont-split flag (c-blosc < 1.14) follow the same rule.
117
+ const nsplits = !dontSplit && typesize <= MAX_SPLITS && Math.floor(bsize / typesize) >= MIN_BUFFERSIZE && !leftover
118
+ ? typesize
119
+ : 1;
120
+ const neblock = bsize / nsplits;
121
+ if (!Number.isInteger(neblock)) {
122
+ throw new VdbFormatError(`blosc block ${b} of ${bsize} bytes does not divide into ${nsplits} splits`);
123
+ }
124
+ const dest = out.subarray(b * blocksize, b * blocksize + bsize);
125
+ const target = scratch ? scratch.subarray(0, bsize) : dest;
126
+ let p = bstart;
127
+ for (let s = 0; s < nsplits; s++) {
128
+ if (p + 4 > cbytes)
129
+ throw new VdbFormatError(`blosc block ${b} stream ${s} size field is outside cbytes=${cbytes}`);
130
+ const csize = view.getInt32(p, true);
131
+ p += 4;
132
+ if (csize < 0 || csize > cbytes - p) {
133
+ throw new VdbFormatError(`blosc stream size ${csize} (block ${b}, stream ${s}) runs past cbytes=${cbytes}`);
134
+ }
135
+ const src = frame.subarray(p, p + csize);
136
+ const part = target.subarray(s * neblock, (s + 1) * neblock);
137
+ if (csize === neblock) {
138
+ part.set(src);
139
+ }
140
+ else if (codec === CODEC_LZ4) {
141
+ const written = decompressLz4Block(src, part);
142
+ if (written !== neblock) {
143
+ throw new VdbFormatError(`LZ4 stream decoded to ${written} bytes, expected ${neblock}`);
144
+ }
145
+ }
146
+ else {
147
+ const inflated = inflateZlib(src, neblock);
148
+ if (inflated.length !== neblock) {
149
+ throw new VdbFormatError(`zlib stream decoded to ${inflated.length} bytes, expected ${neblock}`);
150
+ }
151
+ part.set(inflated);
152
+ }
153
+ p += csize;
154
+ }
155
+ if (scratch)
156
+ unshuffle(scratch.subarray(0, bsize), dest, typesize);
157
+ }
158
+ return out;
159
+ }
160
+ /**
161
+ * Reverses Blosc's byte shuffle: the shuffled block stores byte `i` of every
162
+ * element together (`src[i * count + j]` is byte `i` of element `j`); trailing
163
+ * bytes that do not fill a whole element are stored unshuffled at the end.
164
+ */
165
+ export function unshuffle(src, dest, typesize) {
166
+ const count = Math.floor(src.length / typesize);
167
+ for (let j = 0; j < count; j++) {
168
+ for (let i = 0; i < typesize; i++)
169
+ dest[j * typesize + i] = src[i * count + j];
170
+ }
171
+ const tail = count * typesize;
172
+ dest.set(src.subarray(tail), tail);
173
+ }
174
+ /**
175
+ * Decodes one raw LZ4 block (no frame header) into `dest`, returning the
176
+ * number of bytes written. Each sequence is a token (high nibble literal
177
+ * length, low nibble match length - 4, 15 meaning "more bytes follow, each
178
+ * added, until one is < 255"), the literals, then a 2-byte little-endian
179
+ * match offset and the match; the last sequence carries literals only.
180
+ */
181
+ export function decompressLz4Block(src, dest) {
182
+ let ip = 0;
183
+ let op = 0;
184
+ const end = src.length;
185
+ while (ip < end) {
186
+ const token = src[ip++];
187
+ let litLen = token >>> 4;
188
+ if (litLen === 15) {
189
+ let byte;
190
+ do {
191
+ if (ip >= end)
192
+ throw new VdbFormatError("LZ4 literal length runs past the input");
193
+ byte = src[ip++];
194
+ litLen += byte;
195
+ } while (byte === 255);
196
+ }
197
+ if (ip + litLen > end || op + litLen > dest.length) {
198
+ throw new VdbFormatError("LZ4 literals run past the input or output");
199
+ }
200
+ dest.set(src.subarray(ip, ip + litLen), op);
201
+ ip += litLen;
202
+ op += litLen;
203
+ if (ip === end)
204
+ break; // last sequence: literals only
205
+ if (ip + 2 > end)
206
+ throw new VdbFormatError("LZ4 match offset is truncated");
207
+ const offset = src[ip] | (src[ip + 1] << 8);
208
+ ip += 2;
209
+ if (offset === 0 || offset > op)
210
+ throw new VdbFormatError(`LZ4 match offset ${offset} is out of range`);
211
+ let matchLen = token & 0xf;
212
+ if (matchLen === 15) {
213
+ let byte;
214
+ do {
215
+ if (ip >= end)
216
+ throw new VdbFormatError("LZ4 match length runs past the input");
217
+ byte = src[ip++];
218
+ matchLen += byte;
219
+ } while (byte === 255);
220
+ }
221
+ matchLen += 4;
222
+ if (op + matchLen > dest.length)
223
+ throw new VdbFormatError("LZ4 match runs past the output");
224
+ // Byte-by-byte: a match may overlap the bytes it is producing (offset < length).
225
+ let from = op - offset;
226
+ for (let k = 0; k < matchLen; k++)
227
+ dest[op++] = dest[from++];
228
+ }
229
+ return op;
230
+ }
231
+ //# sourceMappingURL=blosc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"blosc.js","sourceRoot":"","sources":["../../../src/tools/vdb/blosc.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,MAAM,WAAW,GAAG,EAAE,CAAC;AACvB,MAAM,YAAY,GAAG,IAAI,CAAC;AAC1B,MAAM,aAAa,GAAG,IAAI,CAAC;AAC3B,MAAM,eAAe,GAAG,IAAI,CAAC;AAC7B,MAAM,eAAe,GAAG,IAAI,CAAC;AAC7B,+CAA+C;AAC/C,MAAM,UAAU,GAAG,EAAE,CAAC;AACtB,MAAM,cAAc,GAAG,GAAG,CAAC;AAE3B,MAAM,WAAW,GAAG,CAAC,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AACjE,MAAM,SAAS,GAAG,CAAC,CAAC;AACpB,MAAM,UAAU,GAAG,CAAC,CAAC;AAErB,gFAAgF;AAChF,MAAM,iBAAiB,GAAG,CAAC,IAAI,EAAE,CAAC;AASlC;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAAC,KAAiB,EAAE,SAAsB,EAAE;IACzE,MAAM,QA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AG,MAAM,CAAC;QACvB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,EAAE,CAAC,EAAE;YAAE,IAAI,CAAC,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC,IAAI,EAAE,CAAE,CAAC;IAChE,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC","sourcesContent":["/**\n * blosc.ts — a pure-TS decoder for the Blosc1 frames OpenVDB writes.\n *\n * OpenVDB (`io/Compression.cc`, `bloscToStream`) compresses each node's value\n * buffer with `blosc_compress_ctx(clevel 9, byte shuffle, typesize\n * sizeof(ValueType), ..., \"lz4\", blocksize = whole buffer)`, writing the\n * compressed byte count as an i64 followed by one Blosc1 frame. The\n * openvdb.org `bunny_cloud.vdb` and `explosion.vdb` samples are stored this\n * way. This decoder covers the frames that writer produces, plus the\n * `zlib` codec and memcpy'd frames for safety; other codecs (BloscLZ, Snappy,\n * Zstd) and bit-shuffle throw `VDBUnsupportedError`.\n *\n * Frame layout (c-blosc 1.x `blosc.c`, format version 2):\n *\n * [0] version [1] versionlz [2] flags [3] typesize\n * [4..8) nbytes (uncompressed) [8..12) blocksize [12..16) cbytes (whole frame)\n * flags: 0x01 byte shuffle, 0x02 memcpy'd, 0x04 bit shuffle,\n * 0x10 blocks not split, bits 5-7 codec (0 BloscLZ, 1 LZ4/LZ4HC,\n * 2 Snappy, 3 zlib, 4 Zstd)\n * memcpy'd: nbytes raw bytes follow the header.\n * otherwise: nblocks i32 block starts (absolute frame offsets); each block\n * holds `nsplits` streams (typesize streams when split -- flag bit 4 clear,\n * typesize <= 16, block has >= 128 elements, not the short last block --\n * else 1), each an i32 compressed size and its bytes. A\n * stream whose size equals its uncompressed size is stored raw.\n *\n * Derived from the format description above, not from any third-party code.\n */\n\nimport { VdbFormatError, VDBUnsupportedError } from \"./errors.js\";\nimport { inflateZlib } from \"./inflate.js\";\n\nconst HEADER_SIZE = 16;\nconst FLAG_SHUFFLE = 0x01;\nconst FLAG_MEMCPYED = 0x02;\nconst FLAG_BITSHUFFLE = 0x04;\nconst FLAG_DONT_SPLIT = 0x10;\n/** c-blosc `MAX_SPLITS` / `MIN_BUFFERSIZE`. */\nconst MAX_SPLITS = 16;\nconst MIN_BUFFERSIZE = 128;\n\nconst CODEC_NAMES = [\"BloscLZ\", \"LZ4\", \"Snappy\", \"zlib\", \"Zstd\"];\nconst CODEC_LZ4 = 1;\nconst CODEC_ZLIB = 3;\n\n/** Default output cap when a caller does not know the expected size (1 GiB). */\nconst DEFAULT_MAX_BYTES = 1 << 30;\n\nexport interface BloscLimits {\n /** Largest uncompressed size the caller will accept; checked before allocating. */\n maxBytes?: number;\n /** The frame's required `cbytes` header field (what the enclosing format says it stored). */\n expectedCbytes?: number;\n}\n\n/**\n * Decompresses one Blosc1 frame and returns its `nbytes` uncompressed bytes.\n *\n * The frame is untrusted: every header field is validated against `maxBytes`\n * (and the frame's own `cbytes`) before any allocation or read, mirroring\n * c-blosc's `blosc_run_decompression_with_context` and `blosc_d` checks.\n */\nexport function decompressBlosc(frame: Uint8Array, limits: BloscLimits = {}): Uint8Array {\n const maxBytes = limits.maxBytes ?? DEFAULT_MAX_BYTES;\n if (frame.length < HEADER_SIZE) {\n throw new VdbFormatError(`blosc frame is ${frame.length} bytes, shorter than its ${HEADER_SIZE}-byte header`);\n }\n const view = new DataView(frame.buffer, frame.byteOffset, frame.byteLength);\n const version = frame[0]!;\n const flags = frame[2]!;\n const typesize = frame[3]!;\n const nbytes = view.getUint32(4, true);\n const blocksize = view.getUint32(8, true);\n const cbytes = view.getUint32(12, true);\n if (version === 0 || version > 2) {\n throw new VDBUnsupportedError(`blosc frame format version ${version} (only Blosc1, versions 1-2, is supported)`);\n }\n if (flags & 0x08) throw new VDBUnsupportedError(\"blosc frame has compressor flags from a future version\");\n if (cbytes < HEADER_SIZE || cbytes > frame.length) {\n throw new VdbFormatError(`blosc header field cbytes=${cbytes} is outside the ${frame.length}-byte frame`);\n }\n if (limits.expectedCbytes !== undefined && cbytes !== limits.expectedCbytes) {\n throw new VdbFormatError(\n `blosc header field cbytes=${cbytes} does not match the ${limits.expectedCbytes} compressed bytes stored`,\n );\n }\n if (nbytes === 0) return new Uint8Array(0);\n if (nbytes > maxBytes) {\n throw new VdbFormatError(`blosc header field nbytes=${nbytes} exceeds the expected ${maxBytes}-byte output`);\n }\n if (blocksize === 0 || blocksize > maxBytes) {\n throw new VdbFormatError(`blosc header field blocksize=${blocksize} is zero or exceeds the expected ${maxBytes}-byte output`);\n }\n if (typesize === 0) throw new VdbFormatError(\"blosc header field typesize is zero\");\n\n if (flags & FLAG_MEMCPYED) {\n if (nbytes + HEADER_SIZE !== cbytes) {\n throw new VdbFormatError(`memcpy'd blosc frame: cbytes=${cbytes} != nbytes(${nbytes}) + ${HEADER_SIZE}`);\n }\n return frame.slice(HEADER_SIZE, HEADER_SIZE + nbytes);\n }\n\n if (flags & FLAG_BITSHUFFLE) {\n throw new VDBUnsupportedError(\"blosc bit-shuffle is not supported (OpenVDB writes byte shuffle)\");\n }\n const codec = (flags >> 5) & 0x7;\n if (codec !== CODEC_LZ4 && codec !== CODEC_ZLIB) {\n throw new VDBUnsupportedError(\n `blosc codec ${CODEC_NAMES[codec] ?? `#${codec}`} is not supported (LZ4 and zlib are; OpenVDB writes LZ4)`,\n );\n }\n\n const nblocks = Math.ceil(nbytes / blocksize);\n const tableEnd = HEADER_SIZE + 4 * nblocks;\n if (tableEnd > cbytes) {\n throw new VdbFormatError(`blosc block-start table (${nblocks} blocks) does not fit in cbytes=${cbytes}`);\n }\n\n const out = new Uint8Array(nbytes);\n const shuffle = (flags & FLAG_SHUFFLE) !== 0 && typesize > 1;\n const dontSplit = (flags & FLAG_DONT_SPLIT) !== 0;\n // Never larger than the output: blocksize <= maxBytes, and a block never exceeds nbytes.\n const scratch = shuffle ? new Uint8Array(Math.min(blocksize, nbytes)) : null;\n\n for (let b = 0; b < nblocks; b++) {\n const bstart = view.getInt32(HEADER_SIZE + 4 * b, true);\n if (bstart < tableEnd || bstart + 4 > cbytes) {\n throw new VdbFormatError(`blosc block-start[${b}]=${bstart} is outside [${tableEnd}, ${cbytes - 4}]`);\n }\n const leftover = b === nblocks - 1 && nbytes % blocksize !== 0;\n const bsize = leftover ? nbytes % blocksize : blocksize;\n // c-blosc blosc_d: split only if the frame allows it, typesize <= MAX_SPLITS (16),\n // the block holds >= MIN_BUFFERSIZE (128) elements, and it is not the leftover block.\n // Frames from before the dont-split flag (c-blosc < 1.14) follow the same rule.\n const nsplits =\n !dontSplit && typesize <= MAX_SPLITS && Math.floor(bsize / typesize) >= MIN_BUFFERSIZE && !leftover\n ? typesize\n : 1;\n const neblock = bsize / nsplits;\n if (!Number.isInteger(neblock)) {\n throw new VdbFormatError(`blosc block ${b} of ${bsize} bytes does not divide into ${nsplits} splits`);\n }\n const dest = out.subarray(b * blocksize, b * blocksize + bsize);\n const target = scratch ? scratch.subarray(0, bsize) : dest;\n\n let p = bstart;\n for (let s = 0; s < nsplits; s++) {\n if (p + 4 > cbytes) throw new VdbFormatError(`blosc block ${b} stream ${s} size field is outside cbytes=${cbytes}`);\n const csize = view.getInt32(p, true);\n p += 4;\n if (csize < 0 || csize > cbytes - p) {\n throw new VdbFormatError(`blosc stream size ${csize} (block ${b}, stream ${s}) runs past cbytes=${cbytes}`);\n }\n const src = frame.subarray(p, p + csize);\n const part = target.subarray(s * neblock, (s + 1) * neblock);\n if (csize === neblock) {\n part.set(src);\n } else if (codec === CODEC_LZ4) {\n const written = decompressLz4Block(src, part);\n if (written !== neblock) {\n throw new VdbFormatError(`LZ4 stream decoded to ${written} bytes, expected ${neblock}`);\n }\n } else {\n const inflated = inflateZlib(src, neblock);\n if (inflated.length !== neblock) {\n throw new VdbFormatError(`zlib stream decoded to ${inflated.length} bytes, expected ${neblock}`);\n }\n part.set(inflated);\n }\n p += csize;\n }\n\n if (scratch) unshuffle(scratch.subarray(0, bsize), dest, typesize);\n }\n return out;\n}\n\n/**\n * Reverses Blosc's byte shuffle: the shuffled block stores byte `i` of every\n * element together (`src[i * count + j]` is byte `i` of element `j`); trailing\n * bytes that do not fill a whole element are stored unshuffled at the end.\n */\nexport function unshuffle(src: Uint8Array, dest: Uint8Array, typesize: number): void {\n const count = Math.floor(src.length / typesize);\n for (let j = 0; j < count; j++) {\n for (let i = 0; i < typesize; i++) dest[j * typesize + i] = src[i * count + j]!;\n }\n const tail = count * typesize;\n dest.set(src.subarray(tail), tail);\n}\n\n/**\n * Decodes one raw LZ4 block (no frame header) into `dest`, returning the\n * number of bytes written. Each sequence is a token (high nibble literal\n * length, low nibble match length - 4, 15 meaning \"more bytes follow, each\n * added, until one is < 255\"), the literals, then a 2-byte little-endian\n * match offset and the match; the last sequence carries literals only.\n */\nexport function decompressLz4Block(src: Uint8Array, dest: Uint8Array): number {\n let ip = 0;\n let op = 0;\n const end = src.length;\n while (ip < end) {\n const token = src[ip++]!;\n\n let litLen = token >>> 4;\n if (litLen === 15) {\n let byte: number;\n do {\n if (ip >= end) throw new VdbFormatError(\"LZ4 literal length runs past the input\");\n byte = src[ip++]!;\n litLen += byte;\n } while (byte === 255);\n }\n if (ip + litLen > end || op + litLen > dest.length) {\n throw new VdbFormatError(\"LZ4 literals run past the input or output\");\n }\n dest.set(src.subarray(ip, ip + litLen), op);\n ip += litLen;\n op += litLen;\n if (ip === end) break; // last sequence: literals only\n\n if (ip + 2 > end) throw new VdbFormatError(\"LZ4 match offset is truncated\");\n const offset = src[ip]! | (src[ip + 1]! << 8);\n ip += 2;\n if (offset === 0 || offset > op) throw new VdbFormatError(`LZ4 match offset ${offset} is out of range`);\n\n let matchLen = token & 0xf;\n if (matchLen === 15) {\n let byte: number;\n do {\n if (ip >= end) throw new VdbFormatError(\"LZ4 match length runs past the input\");\n byte = src[ip++]!;\n matchLen += byte;\n } while (byte === 255);\n }\n matchLen += 4;\n if (op + matchLen > dest.length) throw new VdbFormatError(\"LZ4 match runs past the output\");\n // Byte-by-byte: a match may overlap the bytes it is producing (offset < length).\n let from = op - offset;\n for (let k = 0; k < matchLen; k++) dest[op++] = dest[from++]!;\n }\n return op;\n}\n"]}
@@ -0,0 +1,40 @@
1
+ /**
2
+ * byte-reader.ts — a seekable little-endian cursor over a `.vdb` buffer.
3
+ *
4
+ * All primitive VDB stream fields (per the `OpenVDBReader`/`vdb-rs` format
5
+ * facts, docs/archive/handoffs and docs/archive/v1/DECISIONS.md D3) are little-endian; strings are a
6
+ * u32 length prefix + raw ASCII bytes (no terminator).
7
+ */
8
+ export declare class ByteReader {
9
+ private readonly view;
10
+ private readonly bytes;
11
+ pos: number;
12
+ constructor(buffer: ArrayBuffer);
13
+ get length(): number;
14
+ private need;
15
+ seek(pos: number): void;
16
+ skip(count: number): void;
17
+ u8(): number;
18
+ bool(): boolean;
19
+ u16(): number;
20
+ i32(): number;
21
+ u32(): number;
22
+ u64(): bigint;
23
+ /** u64 narrowed to `number` — safe for stream offsets/counts on real files
24
+ * (well under 2^53), throws rather than silently truncating otherwise. */
25
+ u64AsNumber(): number;
26
+ f32(): number;
27
+ f64(): number;
28
+ f16AsF32(halfToFloat: (h: number) => number): number;
29
+ bytes_(count: number): Uint8Array;
30
+ /** u32 length prefix + that many raw ASCII bytes (VDB's `readString`). */
31
+ string(): string;
32
+ /** Fixed-length ASCII string (no length prefix) — used for the UUID. */
33
+ fixedString(len: number): string;
34
+ vec3i(): [number, number, number];
35
+ vec3d(): [number, number, number];
36
+ /** Reads `bitCount` mask bits as `bitCount/32` little-endian u32 words.
37
+ * (On disk these are u64 LE words; splitting each into two u32 LE words
38
+ * preserves bit-for-bit ordinal position — see bit-utils.ts.) */
39
+ maskWords(bitCount: number): Uint32Array;
40
+ }