@pmndrs/vdb 0.1.0 → 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.
- package/CHANGELOG.md +592 -2
- package/README.md +85 -37
- package/THIRD_PARTY_NOTICES.md +197 -29
- package/dist/core/compute/atlas.d.ts +10 -2
- package/dist/core/compute/atlas.js +6 -1
- package/dist/core/compute/atlas.js.map +1 -1
- package/dist/core/compute/index.d.ts +3 -3
- package/dist/core/compute/index.js +2 -2
- package/dist/core/compute/index.js.map +1 -1
- package/dist/core/compute/majorant-build.d.ts +45 -0
- package/dist/core/compute/majorant-build.js +193 -0
- package/dist/core/compute/majorant-build.js.map +1 -0
- package/dist/core/compute/multi-scale.d.ts +155 -0
- package/dist/core/compute/multi-scale.js +684 -0
- package/dist/core/compute/multi-scale.js.map +1 -0
- package/dist/core/compute/pyramid.d.ts +22 -7
- package/dist/core/compute/pyramid.js +22 -9
- package/dist/core/compute/pyramid.js.map +1 -1
- package/dist/core/compute/shared.d.ts +1 -0
- package/dist/core/compute/shared.js.map +1 -1
- package/dist/core/compute/stats.d.ts +10 -3
- package/dist/core/compute/stats.js +6 -1
- package/dist/core/compute/stats.js.map +1 -1
- package/dist/core/compute/value-transform.d.ts +8 -1
- package/dist/core/compute/value-transform.js +9 -3
- package/dist/core/compute/value-transform.js.map +1 -1
- package/dist/core/errors.d.ts +10 -0
- package/dist/core/errors.js +8 -0
- package/dist/core/errors.js.map +1 -1
- package/dist/core/frame/emission.d.ts +85 -0
- package/dist/core/frame/emission.js +422 -0
- package/dist/core/frame/emission.js.map +1 -0
- package/dist/core/frame/environment.d.ts +47 -0
- package/dist/core/frame/environment.js +178 -0
- package/dist/core/frame/environment.js.map +1 -0
- package/dist/core/frame/index.d.ts +39 -0
- package/dist/core/frame/index.js +27 -0
- package/dist/core/frame/index.js.map +1 -0
- package/dist/core/frame/kernels.d.ts +115 -0
- package/dist/core/frame/kernels.js +496 -0
- package/dist/core/frame/kernels.js.map +1 -0
- package/dist/core/frame/limits.d.ts +67 -0
- package/dist/core/frame/limits.js +109 -0
- package/dist/core/frame/limits.js.map +1 -0
- package/dist/core/frame/phase.d.ts +17 -0
- package/dist/core/frame/phase.js +53 -0
- package/dist/core/frame/phase.js.map +1 -0
- package/dist/core/frame/pipelines.d.ts +49 -0
- package/dist/core/frame/pipelines.js +147 -0
- package/dist/core/frame/pipelines.js.map +1 -0
- package/dist/core/frame/renderer.d.ts +122 -0
- package/dist/core/frame/renderer.js +1712 -0
- package/dist/core/frame/renderer.js.map +1 -0
- package/dist/core/frame/resources.d.ts +71 -0
- package/dist/core/frame/resources.js +100 -0
- package/dist/core/frame/resources.js.map +1 -0
- package/dist/core/frame/scattering.d.ts +97 -0
- package/dist/core/frame/scattering.js +332 -0
- package/dist/core/frame/scattering.js.map +1 -0
- package/dist/core/frame/settings.d.ts +243 -0
- package/dist/core/frame/settings.js +67 -0
- package/dist/core/frame/settings.js.map +1 -0
- package/dist/core/frame/shadows.d.ts +55 -0
- package/dist/core/frame/shadows.js +460 -0
- package/dist/core/frame/shadows.js.map +1 -0
- package/dist/core/frame/types.d.ts +415 -0
- package/dist/core/frame/types.js +49 -0
- package/dist/core/frame/types.js.map +1 -0
- package/dist/core/frame/uniforms.d.ts +105 -0
- package/dist/core/frame/uniforms.js +276 -0
- package/dist/core/frame/uniforms.js.map +1 -0
- package/dist/core/frame/wgsl/chunks.d.ts +4 -0
- package/dist/core/frame/wgsl/chunks.js +728 -0
- package/dist/core/frame/wgsl/chunks.js.map +1 -0
- package/dist/core/frame/wgsl/emission.d.ts +82 -0
- package/dist/core/frame/wgsl/emission.js +353 -0
- package/dist/core/frame/wgsl/emission.js.map +1 -0
- package/dist/core/frame/wgsl/environment.d.ts +42 -0
- package/dist/core/frame/wgsl/environment.js +711 -0
- package/dist/core/frame/wgsl/environment.js.map +1 -0
- package/dist/core/frame/wgsl/gather.d.ts +55 -0
- package/dist/core/frame/wgsl/gather.js +850 -0
- package/dist/core/frame/wgsl/gather.js.map +1 -0
- package/dist/core/frame/wgsl/integrate.d.ts +78 -0
- package/dist/core/frame/wgsl/integrate.js +213 -0
- package/dist/core/frame/wgsl/integrate.js.map +1 -0
- package/dist/core/frame/wgsl/lighting.d.ts +103 -0
- package/dist/core/frame/wgsl/lighting.js +1636 -0
- package/dist/core/frame/wgsl/lighting.js.map +1 -0
- package/dist/core/frame/wgsl/occluders.d.ts +20 -0
- package/dist/core/frame/wgsl/occluders.js +95 -0
- package/dist/core/frame/wgsl/occluders.js.map +1 -0
- package/dist/core/frame/wgsl/resolve.d.ts +19 -0
- package/dist/core/frame/wgsl/resolve.js +205 -0
- package/dist/core/frame/wgsl/resolve.js.map +1 -0
- package/dist/core/frame/wgsl/shadows.d.ts +35 -0
- package/dist/core/frame/wgsl/shadows.js +328 -0
- package/dist/core/frame/wgsl/shadows.js.map +1 -0
- package/dist/core/half.d.ts +11 -0
- package/dist/core/half.js +22 -0
- package/dist/core/half.js.map +1 -0
- package/dist/core/index.d.ts +25 -3
- package/dist/core/index.js +23 -4
- package/dist/core/index.js.map +1 -1
- package/dist/core/internal.d.ts +17 -1
- package/dist/core/internal.js +18 -1
- package/dist/core/internal.js.map +1 -1
- package/dist/core/pool/image-header.d.ts +13 -2
- package/dist/core/pool/image-header.js +24 -5
- package/dist/core/pool/image-header.js.map +1 -1
- package/dist/core/pool/layout.d.ts +35 -1
- package/dist/core/pool/layout.js +51 -2
- package/dist/core/pool/layout.js.map +1 -1
- package/dist/core/pool/limits.d.ts +1 -0
- package/dist/core/pool/limits.js +1 -0
- package/dist/core/pool/limits.js.map +1 -1
- package/dist/core/pool/pool.d.ts +120 -15
- package/dist/core/pool/pool.js +255 -24
- package/dist/core/pool/pool.js.map +1 -1
- package/dist/core/reference/index.d.ts +6 -0
- package/dist/core/reference/index.js +7 -0
- package/dist/core/reference/index.js.map +1 -0
- package/dist/core/reference/renderer.d.ts +105 -0
- package/dist/core/reference/renderer.js +474 -0
- package/dist/core/reference/renderer.js.map +1 -0
- package/dist/core/reference/wgsl.d.ts +65 -0
- package/dist/core/reference/wgsl.js +803 -0
- package/dist/core/reference/wgsl.js.map +1 -0
- package/dist/{three → core}/sequence.d.ts +32 -2
- package/dist/{three → core}/sequence.js +24 -2
- package/dist/core/sequence.js.map +1 -0
- package/dist/core/source/brick-cache.d.ts +165 -0
- package/dist/core/source/brick-cache.js +627 -0
- package/dist/core/source/brick-cache.js.map +1 -0
- package/dist/core/source/dense-fill.d.ts +53 -0
- package/dist/core/source/dense-fill.js +377 -0
- package/dist/core/source/dense-fill.js.map +1 -0
- package/dist/core/source/dense.d.ts +33 -2
- package/dist/core/source/dense.js +121 -24
- package/dist/core/source/dense.js.map +1 -1
- package/dist/core/source/sparse-wgsl.d.ts +92 -0
- package/dist/core/source/sparse-wgsl.js +481 -0
- package/dist/core/source/sparse-wgsl.js.map +1 -0
- package/dist/core/source/sparse.d.ts +192 -0
- package/dist/core/source/sparse.js +762 -0
- package/dist/core/source/sparse.js.map +1 -0
- package/dist/core/source/types.d.ts +59 -2
- package/dist/core/source/types.js.map +1 -1
- package/dist/core/surface/index.d.ts +10 -0
- package/dist/core/surface/index.js +9 -0
- package/dist/core/surface/index.js.map +1 -0
- package/dist/core/surface/level-set-pass.d.ts +140 -0
- package/dist/core/surface/level-set-pass.js +291 -0
- package/dist/core/surface/level-set-pass.js.map +1 -0
- package/dist/core/surface/level-set-wgsl.d.ts +46 -0
- package/dist/core/surface/level-set-wgsl.js +99 -0
- package/dist/core/surface/level-set-wgsl.js.map +1 -0
- package/dist/core/surface/points.d.ts +109 -0
- package/dist/core/surface/points.js +226 -0
- package/dist/core/surface/points.js.map +1 -0
- package/dist/core/types.d.ts +12 -3
- package/dist/core/types.js +6 -2
- package/dist/core/types.js.map +1 -1
- package/dist/core/wgsl/api.d.ts +29 -5
- package/dist/core/wgsl/api.js +110 -27
- package/dist/core/wgsl/api.js.map +1 -1
- package/dist/core/wgsl/generate.d.ts +8 -0
- package/dist/core/wgsl/generate.js +195 -22
- package/dist/core/wgsl/generate.js.map +1 -1
- package/dist/core/wgsl/lean.d.ts +50 -0
- package/dist/core/wgsl/lean.js +327 -0
- package/dist/core/wgsl/lean.js.map +1 -0
- package/dist/core/wgsl/level-set.d.ts +5 -1
- package/dist/core/wgsl/level-set.js +11 -5
- package/dist/core/wgsl/level-set.js.map +1 -1
- package/dist/core/wgsl/majorant.d.ts +62 -0
- package/dist/core/wgsl/majorant.js +381 -0
- package/dist/core/wgsl/majorant.js.map +1 -0
- package/dist/core/wgsl/pnanovdb.chunks.generated.d.ts +2 -2
- package/dist/core/wgsl/pnanovdb.chunks.generated.js +15 -12
- package/dist/core/wgsl/pnanovdb.chunks.generated.js.map +1 -1
- package/dist/core/wgsl/types.d.ts +97 -3
- package/dist/core/wgsl/types.js.map +1 -1
- package/dist/three/coarse-first.d.ts +53 -8
- package/dist/three/coarse-first.js +24 -6
- package/dist/three/coarse-first.js.map +1 -1
- package/dist/three/compute.d.ts +12 -2
- package/dist/three/compute.js +16 -6
- package/dist/three/compute.js.map +1 -1
- package/dist/three/device.d.ts +7 -0
- package/dist/three/device.js +3 -0
- package/dist/three/device.js.map +1 -1
- package/dist/three/frame/core-environment.d.ts +38 -0
- package/dist/three/frame/core-environment.js +154 -0
- package/dist/three/frame/core-environment.js.map +1 -0
- package/dist/three/frame/core-integrate-material.d.ts +34 -0
- package/dist/three/frame/core-integrate-material.js +162 -0
- package/dist/three/frame/core-integrate-material.js.map +1 -0
- package/dist/three/frame/core-occluders.d.ts +53 -0
- package/dist/three/frame/core-occluders.js +193 -0
- package/dist/three/frame/core-occluders.js.map +1 -0
- package/dist/three/frame/core-structs.d.ts +34 -0
- package/dist/three/frame/core-structs.js +61 -0
- package/dist/three/frame/core-structs.js.map +1 -0
- package/dist/three/frame/core-textures.d.ts +41 -0
- package/dist/three/frame/core-textures.js +114 -0
- package/dist/three/frame/core-textures.js.map +1 -0
- package/dist/three/frame/emission-light.d.ts +64 -114
- package/dist/three/frame/emission-light.js +188 -567
- package/dist/three/frame/emission-light.js.map +1 -1
- package/dist/three/frame/index.d.ts +11 -31
- package/dist/three/frame/index.js +9 -29
- package/dist/three/frame/index.js.map +1 -1
- package/dist/three/frame/medium.d.ts +12 -0
- package/dist/three/frame/medium.js.map +1 -1
- package/dist/three/frame/renderer.d.ts +58 -454
- package/dist/three/frame/renderer.js +409 -1427
- package/dist/three/frame/renderer.js.map +1 -1
- package/dist/three/frame/spectrum.d.ts +0 -14
- package/dist/three/frame/spectrum.js +2 -23
- package/dist/three/frame/spectrum.js.map +1 -1
- package/dist/three/frame/three-internals.d.ts +3 -8
- package/dist/three/frame/three-internals.js +13 -11
- package/dist/three/frame/three-internals.js.map +1 -1
- package/dist/three/frame/volume-shadows.d.ts +93 -107
- package/dist/three/frame/volume-shadows.js +278 -631
- package/dist/three/frame/volume-shadows.js.map +1 -1
- package/dist/three/frame/volume.d.ts +91 -33
- package/dist/three/frame/volume.js +63 -51
- package/dist/three/frame/volume.js.map +1 -1
- package/dist/three/grid-node.d.ts +34 -1
- package/dist/three/grid-node.js +36 -1
- package/dist/three/grid-node.js.map +1 -1
- package/dist/three/index.d.ts +20 -11
- package/dist/three/index.js +21 -12
- package/dist/three/index.js.map +1 -1
- package/dist/three/internal.d.ts +14 -8
- package/dist/three/internal.js +11 -7
- package/dist/three/internal.js.map +1 -1
- package/dist/three/level-set-material.d.ts +81 -8
- package/dist/three/level-set-material.js +162 -125
- package/dist/three/level-set-material.js.map +1 -1
- package/dist/three/level-set-physical-material.d.ts +154 -0
- package/dist/three/level-set-physical-material.js +253 -0
- package/dist/three/level-set-physical-material.js.map +1 -0
- package/dist/three/level-set-velocity.d.ts +94 -0
- package/dist/three/level-set-velocity.js +208 -0
- package/dist/three/level-set-velocity.js.map +1 -0
- package/dist/three/material.d.ts +141 -11
- package/dist/three/material.js +161 -18
- package/dist/three/material.js.map +1 -1
- package/dist/three/points.d.ts +60 -4
- package/dist/three/points.js +140 -9
- package/dist/three/points.js.map +1 -1
- package/dist/three/sparse-source.d.ts +49 -117
- package/dist/three/sparse-source.js +109 -580
- package/dist/three/sparse-source.js.map +1 -1
- package/dist/three/volume-source.d.ts +11 -156
- package/dist/three/volume-source.js +29 -272
- package/dist/three/volume-source.js.map +1 -1
- package/dist/tools/cpu/brick-atlas.d.ts +36 -0
- package/dist/tools/cpu/brick-atlas.js +129 -0
- package/dist/tools/cpu/brick-atlas.js.map +1 -0
- package/dist/tools/cpu/compute.d.ts +23 -4
- package/dist/tools/cpu/compute.js +35 -14
- package/dist/tools/cpu/compute.js.map +1 -1
- package/dist/tools/cpu/lean-reads.d.ts +81 -0
- package/dist/tools/cpu/lean-reads.js +262 -0
- package/dist/tools/cpu/lean-reads.js.map +1 -0
- package/dist/tools/cpu/level-set.d.ts +42 -3
- package/dist/tools/cpu/level-set.js +59 -7
- package/dist/tools/cpu/level-set.js.map +1 -1
- package/dist/tools/cpu/majorant.d.ts +265 -0
- package/dist/tools/cpu/majorant.js +541 -0
- package/dist/tools/cpu/majorant.js.map +1 -0
- package/dist/tools/cpu/march.d.ts +93 -2
- package/dist/tools/cpu/march.js +165 -14
- package/dist/tools/cpu/march.js.map +1 -1
- package/dist/tools/cpu/mesh-decimate.d.ts +124 -0
- package/dist/tools/cpu/mesh-decimate.js +1225 -0
- package/dist/tools/cpu/mesh-decimate.js.map +1 -0
- package/dist/tools/cpu/points.d.ts +29 -0
- package/dist/tools/cpu/points.js +38 -0
- package/dist/tools/cpu/points.js.map +1 -0
- package/dist/tools/cpu/read-value.d.ts +19 -6
- package/dist/tools/cpu/read-value.js +32 -17
- package/dist/tools/cpu/read-value.js.map +1 -1
- package/dist/tools/cpu/sample-trilinear.d.ts +17 -4
- package/dist/tools/cpu/sample-trilinear.js +19 -7
- package/dist/tools/cpu/sample-trilinear.js.map +1 -1
- package/dist/tools/cpu/stride-tables.d.ts +2 -2
- package/dist/tools/cpu/stride-tables.generated.d.ts +6 -5
- package/dist/tools/cpu/stride-tables.generated.js +7 -6
- package/dist/tools/cpu/stride-tables.generated.js.map +1 -1
- package/dist/tools/cpu/stride-tables.js +1 -1
- package/dist/tools/cpu/stride-tables.js.map +1 -1
- package/dist/tools/cpu/surface-nets.d.ts +90 -0
- package/dist/tools/cpu/surface-nets.js +597 -0
- package/dist/tools/cpu/surface-nets.js.map +1 -0
- package/dist/tools/errors.d.ts +9 -0
- package/dist/tools/errors.js +9 -0
- package/dist/tools/errors.js.map +1 -1
- package/dist/tools/frame/ambient.d.ts +98 -0
- package/dist/tools/frame/ambient.js +274 -0
- package/dist/tools/frame/ambient.js.map +1 -0
- package/dist/tools/frame/blackbody.d.ts +15 -0
- package/dist/tools/frame/blackbody.js +35 -0
- package/dist/tools/frame/blackbody.js.map +1 -1
- package/dist/tools/frame/brick-cache.d.ts +165 -0
- package/dist/tools/frame/brick-cache.js +326 -0
- package/dist/tools/frame/brick-cache.js.map +1 -0
- package/dist/tools/frame/emission.d.ts +9 -0
- package/dist/tools/frame/emission.js +9 -1
- package/dist/tools/frame/emission.js.map +1 -1
- package/dist/tools/frame/environment-gpu.d.ts +111 -0
- package/dist/tools/frame/environment-gpu.js +280 -0
- package/dist/tools/frame/environment-gpu.js.map +1 -0
- package/dist/tools/frame/environment.d.ts +3 -2
- package/dist/tools/frame/environment.js +8 -4
- package/dist/tools/frame/environment.js.map +1 -1
- package/dist/tools/frame/froxel.d.ts +58 -0
- package/dist/tools/frame/froxel.js +115 -0
- package/dist/tools/frame/froxel.js.map +1 -0
- package/dist/tools/frame/grid.d.ts +90 -0
- package/dist/tools/frame/grid.js +112 -13
- package/dist/tools/frame/grid.js.map +1 -1
- package/dist/tools/frame/index.d.ts +14 -0
- package/dist/tools/frame/index.js +45 -4
- package/dist/tools/frame/index.js.map +1 -1
- package/dist/tools/frame/medium.d.ts +16 -0
- package/dist/tools/frame/medium.js +3 -1
- package/dist/tools/frame/medium.js.map +1 -1
- package/dist/tools/frame/mie.d.ts +9 -0
- package/dist/tools/frame/mie.js +18 -0
- package/dist/tools/frame/mie.js.map +1 -1
- package/dist/tools/frame/mlp-nn.d.ts +36 -0
- package/dist/tools/frame/mlp-nn.js +159 -0
- package/dist/tools/frame/mlp-nn.js.map +1 -0
- package/dist/tools/frame/mlp-tza.d.ts +29 -0
- package/dist/tools/frame/mlp-tza.js +186 -0
- package/dist/tools/frame/mlp-tza.js.map +1 -0
- package/dist/tools/frame/mlp.d.ts +183 -0
- package/dist/tools/frame/mlp.js +434 -0
- package/dist/tools/frame/mlp.js.map +1 -0
- package/dist/tools/frame/ms-exit.d.ts +42 -0
- package/dist/tools/frame/ms-exit.js +90 -0
- package/dist/tools/frame/ms-exit.js.map +1 -0
- package/dist/tools/frame/multi-scale.d.ts +152 -0
- package/dist/tools/frame/multi-scale.js +302 -0
- package/dist/tools/frame/multi-scale.js.map +1 -0
- package/dist/tools/frame/neural-weights.d.ts +6 -5
- package/dist/tools/frame/neural-weights.js +234 -235
- package/dist/tools/frame/neural-weights.js.map +1 -1
- package/dist/tools/frame/neural.js +1 -1
- package/dist/tools/frame/neural.js.map +1 -1
- package/dist/tools/frame/occluders.d.ts +51 -0
- package/dist/tools/frame/occluders.js +72 -0
- package/dist/tools/frame/occluders.js.map +1 -0
- package/dist/tools/frame/pyramid-layout.d.ts +17 -0
- package/dist/tools/frame/pyramid-layout.js +47 -0
- package/dist/tools/frame/pyramid-layout.js.map +1 -1
- package/dist/tools/frame/shadows.d.ts +110 -0
- package/dist/tools/frame/shadows.js +286 -0
- package/dist/tools/frame/shadows.js.map +1 -1
- package/dist/tools/frame/sparse.d.ts +82 -0
- package/dist/tools/frame/sparse.js +242 -1
- package/dist/tools/frame/sparse.js.map +1 -1
- package/dist/tools/frame/spectral-stack.d.ts +159 -0
- package/dist/tools/frame/spectral-stack.js +391 -0
- package/dist/tools/frame/spectral-stack.js.map +1 -0
- package/dist/tools/frame/spectral.d.ts +21 -2
- package/dist/tools/frame/spectral.js +30 -8
- package/dist/tools/frame/spectral.js.map +1 -1
- package/dist/tools/frame/stack.d.ts +115 -0
- package/dist/tools/frame/stack.js +290 -0
- package/dist/tools/frame/stack.js.map +1 -0
- package/dist/tools/frame/view.d.ts +131 -0
- package/dist/tools/frame/view.js +337 -0
- package/dist/tools/frame/view.js.map +1 -0
- package/dist/tools/index.d.ts +66 -15
- package/dist/tools/index.js +55 -11
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/internal.d.ts +58 -17
- package/dist/tools/internal.js +65 -11
- package/dist/tools/internal.js.map +1 -1
- package/dist/tools/nanovdb/build-from-vdb.d.ts +11 -2
- package/dist/tools/nanovdb/build-from-vdb.js +10 -2
- package/dist/tools/nanovdb/build-from-vdb.js.map +1 -1
- package/dist/tools/nanovdb/bytes.d.ts +17 -4
- package/dist/tools/nanovdb/bytes.js +46 -3
- package/dist/tools/nanovdb/bytes.js.map +1 -1
- package/dist/tools/nanovdb/coarse-first.d.ts +19 -3
- package/dist/tools/nanovdb/coarse-first.js +7 -1
- package/dist/tools/nanovdb/coarse-first.js.map +1 -1
- package/dist/tools/nanovdb/half.d.ts +22 -0
- package/dist/tools/nanovdb/half.js +73 -0
- package/dist/tools/nanovdb/half.js.map +1 -0
- package/dist/tools/nanovdb/index.d.ts +3 -1
- package/dist/tools/nanovdb/index.js +2 -1
- package/dist/tools/nanovdb/index.js.map +1 -1
- package/dist/tools/nanovdb/inspect.d.ts +10 -1
- package/dist/tools/nanovdb/inspect.js +8 -1
- package/dist/tools/nanovdb/inspect.js.map +1 -1
- package/dist/tools/nanovdb/leaf-codec.d.ts +35 -1
- package/dist/tools/nanovdb/leaf-codec.js +40 -4
- package/dist/tools/nanovdb/leaf-codec.js.map +1 -1
- package/dist/tools/nanovdb/quantize.d.ts +39 -10
- package/dist/tools/nanovdb/quantize.js +96 -44
- package/dist/tools/nanovdb/quantize.js.map +1 -1
- package/dist/tools/nanovdb/resample.d.ts +20 -3
- package/dist/tools/nanovdb/resample.js +20 -7
- package/dist/tools/nanovdb/resample.js.map +1 -1
- package/dist/tools/nanovdb/serialize.d.ts +34 -3
- package/dist/tools/nanovdb/serialize.js +51 -7
- package/dist/tools/nanovdb/serialize.js.map +1 -1
- package/dist/tools/nanovdb/stats.d.ts +34 -5
- package/dist/tools/nanovdb/stats.js +87 -11
- package/dist/tools/nanovdb/stats.js.map +1 -1
- package/dist/tools/nanovdb/transform.d.ts +4 -0
- package/dist/tools/nanovdb/transform.js +3 -0
- package/dist/tools/nanovdb/transform.js.map +1 -1
- package/dist/tools/nanovdb/tree.d.ts +14 -3
- package/dist/tools/nanovdb/tree.js +25 -13
- package/dist/tools/nanovdb/tree.js.map +1 -1
- package/dist/tools/nanovdb/write-nvdb.d.ts +47 -12
- package/dist/tools/nanovdb/write-nvdb.js +108 -28
- package/dist/tools/nanovdb/write-nvdb.js.map +1 -1
- package/dist/tools/nvdb-file.d.ts +77 -7
- package/dist/tools/nvdb-file.js +177 -20
- package/dist/tools/nvdb-file.js.map +1 -1
- package/dist/tools/nvdb-stream.d.ts +23 -7
- package/dist/tools/nvdb-stream.js +78 -34
- package/dist/tools/nvdb-stream.js.map +1 -1
- package/dist/tools/reference/analytic.d.ts +41 -0
- package/dist/tools/reference/analytic.js +95 -0
- package/dist/tools/reference/analytic.js.map +1 -0
- package/dist/tools/reference/environment.d.ts +62 -0
- package/dist/tools/reference/environment.js +154 -0
- package/dist/tools/reference/environment.js.map +1 -0
- package/dist/tools/reference/index.d.ts +12 -0
- package/dist/tools/reference/index.js +13 -0
- package/dist/tools/reference/index.js.map +1 -0
- package/dist/tools/reference/media.d.ts +14 -0
- package/dist/tools/reference/media.js +30 -0
- package/dist/tools/reference/media.js.map +1 -0
- package/dist/tools/reference/rng.d.ts +20 -0
- package/dist/tools/reference/rng.js +30 -0
- package/dist/tools/reference/rng.js.map +1 -0
- package/dist/tools/reference/scene.d.ts +312 -0
- package/dist/tools/reference/scene.js +169 -0
- package/dist/tools/reference/scene.js.map +1 -0
- package/dist/tools/reference/tables.d.ts +98 -0
- package/dist/tools/reference/tables.js +264 -0
- package/dist/tools/reference/tables.js.map +1 -0
- package/dist/tools/reference/trace.d.ts +160 -0
- package/dist/tools/reference/trace.js +497 -0
- package/dist/tools/reference/trace.js.map +1 -0
- package/dist/tools/vdb/blosc-write.d.ts +43 -0
- package/dist/tools/vdb/blosc-write.js +197 -0
- package/dist/tools/vdb/blosc-write.js.map +1 -0
- package/dist/tools/vdb/blosc.d.ts +35 -5
- package/dist/tools/vdb/blosc.js +82 -26
- package/dist/tools/vdb/blosc.js.map +1 -1
- package/dist/tools/vdb/blosclz.d.ts +33 -0
- package/dist/tools/vdb/blosclz.js +112 -0
- package/dist/tools/vdb/blosclz.js.map +1 -0
- package/dist/tools/vdb/byte-reader.d.ts +13 -3
- package/dist/tools/vdb/byte-reader.js +26 -4
- package/dist/tools/vdb/byte-reader.js.map +1 -1
- package/dist/tools/vdb/compression.d.ts +13 -5
- package/dist/tools/vdb/compression.js +13 -2
- package/dist/tools/vdb/compression.js.map +1 -1
- package/dist/tools/vdb/grid.js +8 -2
- package/dist/tools/vdb/grid.js.map +1 -1
- package/dist/tools/vdb/index.d.ts +2 -1
- package/dist/tools/vdb/index.js.map +1 -1
- package/dist/tools/vdb/lz4.d.ts +30 -0
- package/dist/tools/vdb/lz4.js +228 -0
- package/dist/tools/vdb/lz4.js.map +1 -0
- package/dist/tools/vdb/metadata.js +1 -1
- package/dist/tools/vdb/metadata.js.map +1 -1
- package/dist/tools/vdb/parse.d.ts +24 -2
- package/dist/tools/vdb/parse.js +102 -32
- package/dist/tools/vdb/parse.js.map +1 -1
- package/dist/tools/vdb/point-render-data.d.ts +49 -1
- package/dist/tools/vdb/point-render-data.js +91 -11
- package/dist/tools/vdb/point-render-data.js.map +1 -1
- package/dist/tools/vdb/points.d.ts +26 -0
- package/dist/tools/vdb/points.js +46 -5
- package/dist/tools/vdb/points.js.map +1 -1
- package/dist/tools/vdb/types.d.ts +59 -2
- package/dist/tools/vdb/types.js.map +1 -1
- package/dist/tools/wvdb/bake.d.ts +38 -9
- package/dist/tools/wvdb/bake.js +63 -13
- package/dist/tools/wvdb/bake.js.map +1 -1
- package/dist/tools/wvdb/dense.d.ts +80 -1
- package/dist/tools/wvdb/dense.js +67 -8
- package/dist/tools/wvdb/dense.js.map +1 -1
- package/dist/tools/wvdb/format.d.ts +59 -0
- package/dist/tools/wvdb/format.js +3 -0
- package/dist/tools/wvdb/format.js.map +1 -1
- package/dist/tools/wvdb/index.d.ts +1 -0
- package/dist/tools/wvdb/index.js +1 -0
- package/dist/tools/wvdb/index.js.map +1 -1
- package/dist/tools/wvdb/level-set.d.ts +10 -2
- package/dist/tools/wvdb/level-set.js.map +1 -1
- package/dist/tools/wvdb/nanovdb.d.ts +6 -1
- package/dist/tools/wvdb/nanovdb.js +5 -1
- package/dist/tools/wvdb/nanovdb.js.map +1 -1
- package/dist/tools/wvdb/partial.d.ts +74 -0
- package/dist/tools/wvdb/partial.js +233 -0
- package/dist/tools/wvdb/partial.js.map +1 -0
- package/dist/tools/wvdb/read.d.ts +77 -1
- package/dist/tools/wvdb/read.js +30 -7
- package/dist/tools/wvdb/read.js.map +1 -1
- package/dist/tools/wvdb/write.d.ts +23 -1
- package/dist/tools/wvdb/write.js +8 -1
- package/dist/tools/wvdb/write.js.map +1 -1
- package/package.json +2 -1
- package/vendor/VENDOR.md +21 -6
- package/vendor/pnanovdb.wgsl +52 -14
- package/dist/three/frame/blackbody.d.ts +0 -42
- package/dist/three/frame/blackbody.js +0 -74
- package/dist/three/frame/blackbody.js.map +0 -1
- package/dist/three/frame/chunks.d.ts +0 -157
- package/dist/three/frame/chunks.js +0 -559
- package/dist/three/frame/chunks.js.map +0 -1
- package/dist/three/frame/density-material.d.ts +0 -53
- package/dist/three/frame/density-material.js +0 -353
- package/dist/three/frame/density-material.js.map +0 -1
- package/dist/three/frame/environment-grid-material.d.ts +0 -21
- package/dist/three/frame/environment-grid-material.js +0 -184
- package/dist/three/frame/environment-grid-material.js.map +0 -1
- package/dist/three/frame/environment-material.d.ts +0 -22
- package/dist/three/frame/environment-material.js +0 -87
- package/dist/three/frame/environment-material.js.map +0 -1
- package/dist/three/frame/grid-mip-material.d.ts +0 -12
- package/dist/three/frame/grid-mip-material.js +0 -61
- package/dist/three/frame/grid-mip-material.js.map +0 -1
- package/dist/three/frame/inject-material.d.ts +0 -56
- package/dist/three/frame/inject-material.js +0 -424
- package/dist/three/frame/inject-material.js.map +0 -1
- package/dist/three/frame/integrate-material.d.ts +0 -26
- package/dist/three/frame/integrate-material.js +0 -198
- package/dist/three/frame/integrate-material.js.map +0 -1
- package/dist/three/frame/layout.d.ts +0 -34
- package/dist/three/frame/layout.js +0 -48
- package/dist/three/frame/layout.js.map +0 -1
- package/dist/three/frame/lighting-material.d.ts +0 -41
- package/dist/three/frame/lighting-material.js +0 -257
- package/dist/three/frame/lighting-material.js.map +0 -1
- package/dist/three/frame/lights.d.ts +0 -11
- package/dist/three/frame/lights.js +0 -16
- package/dist/three/frame/lights.js.map +0 -1
- package/dist/three/frame/neural.d.ts +0 -14
- package/dist/three/frame/neural.js +0 -105
- package/dist/three/frame/neural.js.map +0 -1
- package/dist/three/frame/phase.d.ts +0 -44
- package/dist/three/frame/phase.js +0 -80
- package/dist/three/frame/phase.js.map +0 -1
- package/dist/three/frame/shadow-density-material.d.ts +0 -30
- package/dist/three/frame/shadow-density-material.js +0 -123
- package/dist/three/frame/shadow-density-material.js.map +0 -1
- package/dist/three/frame/temporal-material.d.ts +0 -29
- package/dist/three/frame/temporal-material.js +0 -152
- package/dist/three/frame/temporal-material.js.map +0 -1
- package/dist/three/frame/transmittance-material.d.ts +0 -31
- package/dist/three/frame/transmittance-material.js +0 -315
- package/dist/three/frame/transmittance-material.js.map +0 -1
- package/dist/three/frame/view.d.ts +0 -103
- package/dist/three/frame/view.js +0 -296
- package/dist/three/frame/view.js.map +0 -1
- package/dist/three/frame/volume-shadow-material.d.ts +0 -36
- package/dist/three/frame/volume-shadow-material.js +0 -128
- package/dist/three/frame/volume-shadow-material.js.map +0 -1
- package/dist/three/sequence.js.map +0 -1
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* blosc-write.ts — a Blosc1 frame writer with the LZ4 codec (K7.C1), for `writeNvdb({ codec: 'blosc' })`.
|
|
3
|
+
* The reader is `decompressBlosc` in `blosc.ts`.
|
|
4
|
+
*
|
|
5
|
+
* Ported from the compression half of the Blosc OpenVDB v14.0.0 vendors
|
|
6
|
+
* (`ext/blosc/openvdb/ext/blosc/vdb_blosc.c`, c-blosc 1.21.6 cut down to LZ4: `blosc_compress_ctx`,
|
|
7
|
+
* `compute_blocksize`, `write_compression_header`, `serial_blosc`, `blosc_c`, `shuffle_block`):
|
|
8
|
+
*
|
|
9
|
+
* Blosc - Blocked Shuffling and Compression Library
|
|
10
|
+
* Copyright (c) 2009-2018 Francesc Alted <francesc@blosc.org>
|
|
11
|
+
* Copyright (c) 2019-present Blosc Development Team <blosc@blosc.org>
|
|
12
|
+
* License: BSD 3-Clause (see THIRD_PARTY_NOTICES.md)
|
|
13
|
+
*
|
|
14
|
+
* Same block size rule (a forced block size is enlarged by `typesize` for split codecs, so NanoVDB's
|
|
15
|
+
* requested 256 KiB is a 1 MiB block of four 256 KiB byte planes), same splits, same per-split output
|
|
16
|
+
* budget (`maxout`), same fallbacks (a split LZ4 can't shrink is stored raw; a frame that doesn't fit
|
|
17
|
+
* `destSize` becomes a memcpy'd frame). With `compressLz4Block` matching native LZ4 byte for byte, a frame
|
|
18
|
+
* equals native's for the same input and options (DIVERGES V164). One thread (as NanoVDB asks for).
|
|
19
|
+
*/
|
|
20
|
+
/** `NANOVDB_BLOSC_MAX_BUFFERSIZE` (INT_MAX - 16). */
|
|
21
|
+
export declare const BLOSC_MAX_BUFFERSIZE: number;
|
|
22
|
+
/** Options of {@link compressBlosc}; the defaults are NanoVDB's `io::Internal::write`. */
|
|
23
|
+
export interface BloscCompressOptions {
|
|
24
|
+
/** 0–9; 0 stores a memcpy'd frame. Default 9 (LZ4 acceleration `10 − clevel`). */
|
|
25
|
+
clevel?: number;
|
|
26
|
+
/** Byte shuffle. Default true. */
|
|
27
|
+
shuffle?: boolean;
|
|
28
|
+
/** Element size for the shuffle and the splits, 1–255 (larger is treated as 1). Default 4. */
|
|
29
|
+
typesize?: number;
|
|
30
|
+
/** Requested block size (0: Blosc chooses from `clevel`). Default 2^18, NanoVDB's. */
|
|
31
|
+
blocksize?: number;
|
|
32
|
+
/** Capacity of the output, as the `destsize` passed to Blosc. Default `src.length + 16` (NanoVDB's). */
|
|
33
|
+
destSize?: number;
|
|
34
|
+
}
|
|
35
|
+
/** `shuffle_block`: byte `j` of element `i` goes to `j * elements + i`; a partial element's bytes stay at the end. */
|
|
36
|
+
export declare function shuffleBytes(src: Uint8Array, dest: Uint8Array, typesize: number): void;
|
|
37
|
+
/**
|
|
38
|
+
* Compresses `src` into one Blosc1 frame (LZ4 codec) as `blosc_compress_ctx(clevel, shuffle, typesize,
|
|
39
|
+
* src.length, src, dest, destSize, "lz4", blocksize, 1)` from OpenVDB v14's Blosc does, and returns the
|
|
40
|
+
* frame (exactly its `cbytes` long), or `null` when Blosc returns 0 (the frame can't fit `destSize`).
|
|
41
|
+
* Throws a `RangeError` on options Blosc rejects (a negative return there).
|
|
42
|
+
*/
|
|
43
|
+
export declare function compressBlosc(src: Uint8Array, opts?: BloscCompressOptions): Uint8Array | null;
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* blosc-write.ts — a Blosc1 frame writer with the LZ4 codec (K7.C1), for `writeNvdb({ codec: 'blosc' })`.
|
|
3
|
+
* The reader is `decompressBlosc` in `blosc.ts`.
|
|
4
|
+
*
|
|
5
|
+
* Ported from the compression half of the Blosc OpenVDB v14.0.0 vendors
|
|
6
|
+
* (`ext/blosc/openvdb/ext/blosc/vdb_blosc.c`, c-blosc 1.21.6 cut down to LZ4: `blosc_compress_ctx`,
|
|
7
|
+
* `compute_blocksize`, `write_compression_header`, `serial_blosc`, `blosc_c`, `shuffle_block`):
|
|
8
|
+
*
|
|
9
|
+
* Blosc - Blocked Shuffling and Compression Library
|
|
10
|
+
* Copyright (c) 2009-2018 Francesc Alted <francesc@blosc.org>
|
|
11
|
+
* Copyright (c) 2019-present Blosc Development Team <blosc@blosc.org>
|
|
12
|
+
* License: BSD 3-Clause (see THIRD_PARTY_NOTICES.md)
|
|
13
|
+
*
|
|
14
|
+
* Same block size rule (a forced block size is enlarged by `typesize` for split codecs, so NanoVDB's
|
|
15
|
+
* requested 256 KiB is a 1 MiB block of four 256 KiB byte planes), same splits, same per-split output
|
|
16
|
+
* budget (`maxout`), same fallbacks (a split LZ4 can't shrink is stored raw; a frame that doesn't fit
|
|
17
|
+
* `destSize` becomes a memcpy'd frame). With `compressLz4Block` matching native LZ4 byte for byte, a frame
|
|
18
|
+
* equals native's for the same input and options (DIVERGES V164). One thread (as NanoVDB asks for).
|
|
19
|
+
*/
|
|
20
|
+
import { compressLz4Block } from "./lz4.js";
|
|
21
|
+
const HEADER_SIZE = 16;
|
|
22
|
+
/** `BLOSC_VERSION_FORMAT`. */
|
|
23
|
+
const VERSION_FORMAT = 2;
|
|
24
|
+
/** `BLOSC_LZ4_VERSION_FORMAT`. */
|
|
25
|
+
const LZ4_VERSION_FORMAT = 1;
|
|
26
|
+
const FLAG_SHUFFLE = 0x01;
|
|
27
|
+
const FLAG_MEMCPYED = 0x02;
|
|
28
|
+
const LZ4_FORMAT = 1;
|
|
29
|
+
const MIN_BUFFERSIZE = 128;
|
|
30
|
+
const MAX_SPLITS = 16;
|
|
31
|
+
const L1 = 32 * 1024;
|
|
32
|
+
const MAX_TYPESIZE = 255;
|
|
33
|
+
/** `NANOVDB_BLOSC_MAX_BUFFERSIZE` (INT_MAX - 16). */
|
|
34
|
+
export const BLOSC_MAX_BUFFERSIZE = 0x7fffffff - HEADER_SIZE;
|
|
35
|
+
function splitBlock(typesize, blocksize) {
|
|
36
|
+
return typesize <= MAX_SPLITS && Math.floor(blocksize / typesize) >= MIN_BUFFERSIZE;
|
|
37
|
+
}
|
|
38
|
+
/** `compute_blocksize`. */
|
|
39
|
+
function computeBlocksize(clevel, typesize, nbytes, forced) {
|
|
40
|
+
if (nbytes < typesize)
|
|
41
|
+
return 1;
|
|
42
|
+
let blocksize = nbytes;
|
|
43
|
+
if (forced) {
|
|
44
|
+
blocksize = Math.max(forced, MIN_BUFFERSIZE);
|
|
45
|
+
}
|
|
46
|
+
else if (nbytes >= L1) {
|
|
47
|
+
blocksize = L1;
|
|
48
|
+
if (clevel === 0)
|
|
49
|
+
blocksize /= 4;
|
|
50
|
+
else if (clevel === 1)
|
|
51
|
+
blocksize /= 2;
|
|
52
|
+
else if (clevel === 3)
|
|
53
|
+
blocksize *= 2;
|
|
54
|
+
else if (clevel === 4 || clevel === 5)
|
|
55
|
+
blocksize *= 4;
|
|
56
|
+
else if (clevel >= 6)
|
|
57
|
+
blocksize *= 8;
|
|
58
|
+
}
|
|
59
|
+
if (clevel > 0 && splitBlock(typesize, blocksize)) {
|
|
60
|
+
if (blocksize > 1 << 18)
|
|
61
|
+
blocksize = 1 << 18;
|
|
62
|
+
blocksize *= typesize;
|
|
63
|
+
if (blocksize < 1 << 16)
|
|
64
|
+
blocksize = 1 << 16;
|
|
65
|
+
if (blocksize > 1024 * 1024)
|
|
66
|
+
blocksize = 1024 * 1024;
|
|
67
|
+
}
|
|
68
|
+
if (blocksize > nbytes)
|
|
69
|
+
blocksize = nbytes;
|
|
70
|
+
if (blocksize > typesize)
|
|
71
|
+
blocksize = Math.floor(blocksize / typesize) * typesize;
|
|
72
|
+
return blocksize;
|
|
73
|
+
}
|
|
74
|
+
/** `shuffle_block`: byte `j` of element `i` goes to `j * elements + i`; a partial element's bytes stay at the end. */
|
|
75
|
+
export function shuffleBytes(src, dest, typesize) {
|
|
76
|
+
const n = src.length;
|
|
77
|
+
const elements = Math.floor(n / typesize);
|
|
78
|
+
for (let j = 0; j < typesize; j++) {
|
|
79
|
+
const row = j * elements;
|
|
80
|
+
for (let i = 0; i < elements; i++)
|
|
81
|
+
dest[row + i] = src[i * typesize + j];
|
|
82
|
+
}
|
|
83
|
+
const tail = elements * typesize;
|
|
84
|
+
dest.set(src.subarray(tail, n), tail);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Compresses `src` into one Blosc1 frame (LZ4 codec) as `blosc_compress_ctx(clevel, shuffle, typesize,
|
|
88
|
+
* src.length, src, dest, destSize, "lz4", blocksize, 1)` from OpenVDB v14's Blosc does, and returns the
|
|
89
|
+
* frame (exactly its `cbytes` long), or `null` when Blosc returns 0 (the frame can't fit `destSize`).
|
|
90
|
+
* Throws a `RangeError` on options Blosc rejects (a negative return there).
|
|
91
|
+
*/
|
|
92
|
+
export function compressBlosc(src, opts = {}) {
|
|
93
|
+
const clevel = opts.clevel ?? 9;
|
|
94
|
+
const doShuffle = opts.shuffle ?? true;
|
|
95
|
+
let typesize = opts.typesize ?? 4;
|
|
96
|
+
const forced = opts.blocksize ?? 1 << 18;
|
|
97
|
+
const nbytes = src.length;
|
|
98
|
+
const destSize = opts.destSize ?? nbytes + HEADER_SIZE;
|
|
99
|
+
if (!Number.isInteger(clevel) || clevel < 0 || clevel > 9)
|
|
100
|
+
throw new RangeError(`blosc clevel must be 0-9, got ${clevel}`);
|
|
101
|
+
if (!Number.isInteger(typesize) || typesize < 1)
|
|
102
|
+
throw new RangeError(`blosc typesize must be a positive integer, got ${typesize}`);
|
|
103
|
+
if (!Number.isInteger(forced) || forced < 0)
|
|
104
|
+
throw new RangeError(`blosc blocksize must be a non-negative integer, got ${forced}`);
|
|
105
|
+
if (!Number.isInteger(destSize) || destSize < 0)
|
|
106
|
+
throw new RangeError(`blosc destSize must be a non-negative integer`);
|
|
107
|
+
// initialize_context_compression: size limits return 0 (no frame).
|
|
108
|
+
if (nbytes > BLOSC_MAX_BUFFERSIZE || destSize < HEADER_SIZE)
|
|
109
|
+
return null;
|
|
110
|
+
if (typesize > MAX_TYPESIZE)
|
|
111
|
+
typesize = 1;
|
|
112
|
+
const blocksize = computeBlocksize(clevel, typesize, nbytes, forced);
|
|
113
|
+
const leftover = nbytes % blocksize;
|
|
114
|
+
const nblocks = Math.floor(nbytes / blocksize) + (leftover > 0 ? 1 : 0);
|
|
115
|
+
// write_compression_header.
|
|
116
|
+
// Room for the block-start table even when `destSize` is smaller (Blosc writes it before it finds the frame
|
|
117
|
+
// can't fit, past its buffer; here it lands in scratch and the call returns null).
|
|
118
|
+
const dest = new Uint8Array(Math.max(HEADER_SIZE + 4 * nblocks, Math.min(destSize, nbytes + HEADER_SIZE + 4 * nblocks + 4 * nblocks * MAX_SPLITS + 64)));
|
|
119
|
+
const view = new DataView(dest.buffer);
|
|
120
|
+
let flags = 0;
|
|
121
|
+
let outBytes = HEADER_SIZE + 4 * nblocks;
|
|
122
|
+
if (clevel === 0 || nbytes < MIN_BUFFERSIZE) {
|
|
123
|
+
flags |= FLAG_MEMCPYED;
|
|
124
|
+
outBytes = HEADER_SIZE;
|
|
125
|
+
}
|
|
126
|
+
if (doShuffle)
|
|
127
|
+
flags |= FLAG_SHUFFLE;
|
|
128
|
+
if (!splitBlock(typesize, blocksize))
|
|
129
|
+
flags |= 0x10;
|
|
130
|
+
flags |= LZ4_FORMAT << 5;
|
|
131
|
+
// blosc_compress_context.
|
|
132
|
+
if (flags & FLAG_MEMCPYED && nbytes + HEADER_SIZE > destSize)
|
|
133
|
+
return null;
|
|
134
|
+
let ntbytes = flags & FLAG_MEMCPYED ? -1 : compressBlocks(src, dest, view, flags, typesize, blocksize, nblocks, leftover, clevel, outBytes, destSize);
|
|
135
|
+
if (ntbytes === 0 && nbytes + HEADER_SIZE <= destSize)
|
|
136
|
+
flags |= FLAG_MEMCPYED;
|
|
137
|
+
if (flags & FLAG_MEMCPYED && ntbytes <= 0) {
|
|
138
|
+
if (nbytes + HEADER_SIZE > dest.length)
|
|
139
|
+
return null;
|
|
140
|
+
dest.set(src, HEADER_SIZE);
|
|
141
|
+
ntbytes = HEADER_SIZE + nbytes;
|
|
142
|
+
}
|
|
143
|
+
if (ntbytes <= 0)
|
|
144
|
+
return null;
|
|
145
|
+
dest[0] = VERSION_FORMAT;
|
|
146
|
+
dest[1] = LZ4_VERSION_FORMAT;
|
|
147
|
+
dest[2] = flags;
|
|
148
|
+
dest[3] = typesize;
|
|
149
|
+
view.setInt32(4, nbytes, true);
|
|
150
|
+
view.setInt32(8, blocksize, true);
|
|
151
|
+
view.setInt32(12, ntbytes, true);
|
|
152
|
+
return dest.slice(0, ntbytes);
|
|
153
|
+
}
|
|
154
|
+
/** `serial_blosc` (compression, not memcpy'd): the bytes written, or 0 when the frame overruns `maxbytes`. */
|
|
155
|
+
function compressBlocks(src, dest, view, flags, typesize, blocksize, nblocks, leftover, clevel, start, maxbytes) {
|
|
156
|
+
const tmp = new Uint8Array(blocksize);
|
|
157
|
+
const doShuffle = (flags & FLAG_SHUFFLE) !== 0 && typesize > 1;
|
|
158
|
+
const dontSplit = (flags & 0x10) !== 0;
|
|
159
|
+
const accel = 10 - clevel;
|
|
160
|
+
let ntbytes = start;
|
|
161
|
+
for (let j = 0; j < nblocks; j++) {
|
|
162
|
+
view.setInt32(HEADER_SIZE + 4 * j, ntbytes, true);
|
|
163
|
+
const isLeftover = j === nblocks - 1 && leftover > 0;
|
|
164
|
+
const bsize = isLeftover ? leftover : blocksize;
|
|
165
|
+
const block = src.subarray(j * blocksize, j * blocksize + bsize);
|
|
166
|
+
let data = block;
|
|
167
|
+
if (doShuffle) {
|
|
168
|
+
shuffleBytes(block, tmp.subarray(0, bsize), typesize);
|
|
169
|
+
data = tmp.subarray(0, bsize);
|
|
170
|
+
}
|
|
171
|
+
// blosc_c.
|
|
172
|
+
const nsplits = !dontSplit && !isLeftover ? typesize : 1;
|
|
173
|
+
const neblock = Math.floor(bsize / nsplits);
|
|
174
|
+
for (let s = 0; s < nsplits; s++) {
|
|
175
|
+
const sizeAt = ntbytes;
|
|
176
|
+
ntbytes += 4;
|
|
177
|
+
let maxout = neblock;
|
|
178
|
+
if (ntbytes + maxout > maxbytes) {
|
|
179
|
+
maxout = maxbytes - ntbytes;
|
|
180
|
+
if (maxout <= 0)
|
|
181
|
+
return 0;
|
|
182
|
+
}
|
|
183
|
+
const part = data.subarray(s * neblock, (s + 1) * neblock);
|
|
184
|
+
let cbytes = compressLz4Block(part, dest.subarray(ntbytes, ntbytes + maxout), accel);
|
|
185
|
+
if (cbytes === 0 || cbytes === neblock) {
|
|
186
|
+
if (ntbytes + neblock > maxbytes)
|
|
187
|
+
return 0;
|
|
188
|
+
dest.set(part, ntbytes);
|
|
189
|
+
cbytes = neblock;
|
|
190
|
+
}
|
|
191
|
+
view.setInt32(sizeAt, cbytes, true);
|
|
192
|
+
ntbytes += cbytes;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return ntbytes;
|
|
196
|
+
}
|
|
197
|
+
//# sourceMappingURL=blosc-write.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blosc-write.js","sourceRoot":"","sources":["../../../src/tools/vdb/blosc-write.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE5C,MAAM,WAAW,GAAG,EAAE,CAAC;AACvB,8BAA8B;AAC9B,MAAM,cAAc,GAAG,CAAC,CAAC;AACzB,kCAAkC;AAClC,MAAM,kBAAkB,GAAG,CAAC,CAAC;AAC7B,MAAM,YAAY,GAAG,IAAI,CAAC;AAC1B,MAAM,aAAa,GAAG,IAAI,CAAC;AAC3B,MAAM,UAAU,GAAG,CAAC,CAAC;AACrB,MAAM,cAAc,GAAG,GAAG,CAAC;AAC3B,MAAM,UAAU,GAAG,EAAE,CAAC;AACtB,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AACrB,MAAM,YAAY,GAAG,GAAG,CAAC;AACzB,qDAAqD;AACrD,MAAM,CAAC,MAAM,oBAAoB,GAAG,UAAU,GAAG,WAAW,CAAC;AAgB7D,SAAS,UAAU,CAAC,QAAgB,EA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AAI,MAAM,IAAI,CAAC;oBAAE,OAAO,CAAC,CAAC;YAC5B,CAAC;YACD,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC;YAC3D,IAAI,MAAM,GAAG,gBAAgB,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAAC,EAAE,KAAK,CAAC,CAAC;YACrF,IAAI,MAAM,KAAK,CAAC,IAAI,MAAM,KAAK,OAAO,EAAE,CAAC;gBACvC,IAAI,OAAO,GAAG,OAAO,GAAG,QAAQ;oBAAE,OAAO,CAAC,CAAC;gBAC3C,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;gBACxB,MAAM,GAAG,OAAO,CAAC;YACnB,CAAC;YACD,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;YACpC,OAAO,IAAI,MAAM,CAAC;QACpB,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["/**\n * blosc-write.ts — a Blosc1 frame writer with the LZ4 codec (K7.C1), for `writeNvdb({ codec: 'blosc' })`.\n * The reader is `decompressBlosc` in `blosc.ts`.\n *\n * Ported from the compression half of the Blosc OpenVDB v14.0.0 vendors\n * (`ext/blosc/openvdb/ext/blosc/vdb_blosc.c`, c-blosc 1.21.6 cut down to LZ4: `blosc_compress_ctx`,\n * `compute_blocksize`, `write_compression_header`, `serial_blosc`, `blosc_c`, `shuffle_block`):\n *\n * Blosc - Blocked Shuffling and Compression Library\n * Copyright (c) 2009-2018 Francesc Alted <francesc@blosc.org>\n * Copyright (c) 2019-present Blosc Development Team <blosc@blosc.org>\n * License: BSD 3-Clause (see THIRD_PARTY_NOTICES.md)\n *\n * Same block size rule (a forced block size is enlarged by `typesize` for split codecs, so NanoVDB's\n * requested 256 KiB is a 1 MiB block of four 256 KiB byte planes), same splits, same per-split output\n * budget (`maxout`), same fallbacks (a split LZ4 can't shrink is stored raw; a frame that doesn't fit\n * `destSize` becomes a memcpy'd frame). With `compressLz4Block` matching native LZ4 byte for byte, a frame\n * equals native's for the same input and options (DIVERGES V164). One thread (as NanoVDB asks for).\n */\n\nimport { compressLz4Block } from \"./lz4.js\";\n\nconst HEADER_SIZE = 16;\n/** `BLOSC_VERSION_FORMAT`. */\nconst VERSION_FORMAT = 2;\n/** `BLOSC_LZ4_VERSION_FORMAT`. */\nconst LZ4_VERSION_FORMAT = 1;\nconst FLAG_SHUFFLE = 0x01;\nconst FLAG_MEMCPYED = 0x02;\nconst LZ4_FORMAT = 1;\nconst MIN_BUFFERSIZE = 128;\nconst MAX_SPLITS = 16;\nconst L1 = 32 * 1024;\nconst MAX_TYPESIZE = 255;\n/** `NANOVDB_BLOSC_MAX_BUFFERSIZE` (INT_MAX - 16). */\nexport const BLOSC_MAX_BUFFERSIZE = 0x7fffffff - HEADER_SIZE;\n\n/** Options of {@link compressBlosc}; the defaults are NanoVDB's `io::Internal::write`. */\nexport interface BloscCompressOptions {\n /** 0–9; 0 stores a memcpy'd frame. Default 9 (LZ4 acceleration `10 − clevel`). */\n clevel?: number;\n /** Byte shuffle. Default true. */\n shuffle?: boolean;\n /** Element size for the shuffle and the splits, 1–255 (larger is treated as 1). Default 4. */\n typesize?: number;\n /** Requested block size (0: Blosc chooses from `clevel`). Default 2^18, NanoVDB's. */\n blocksize?: number;\n /** Capacity of the output, as the `destsize` passed to Blosc. Default `src.length + 16` (NanoVDB's). */\n destSize?: number;\n}\n\nfunction splitBlock(typesize: number, blocksize: number): boolean {\n return typesize <= MAX_SPLITS && Math.floor(blocksize / typesize) >= MIN_BUFFERSIZE;\n}\n\n/** `compute_blocksize`. */\nfunction computeBlocksize(clevel: number, typesize: number, nbytes: number, forced: number): number {\n if (nbytes < typesize) return 1;\n let blocksize = nbytes;\n if (forced) {\n blocksize = Math.max(forced, MIN_BUFFERSIZE);\n } else if (nbytes >= L1) {\n blocksize = L1;\n if (clevel === 0) blocksize /= 4;\n else if (clevel === 1) blocksize /= 2;\n else if (clevel === 3) blocksize *= 2;\n else if (clevel === 4 || clevel === 5) blocksize *= 4;\n else if (clevel >= 6) blocksize *= 8;\n }\n if (clevel > 0 && splitBlock(typesize, blocksize)) {\n if (blocksize > 1 << 18) blocksize = 1 << 18;\n blocksize *= typesize;\n if (blocksize < 1 << 16) blocksize = 1 << 16;\n if (blocksize > 1024 * 1024) blocksize = 1024 * 1024;\n }\n if (blocksize > nbytes) blocksize = nbytes;\n if (blocksize > typesize) blocksize = Math.floor(blocksize / typesize) * typesize;\n return blocksize;\n}\n\n/** `shuffle_block`: byte `j` of element `i` goes to `j * elements + i`; a partial element's bytes stay at the end. */\nexport function shuffleBytes(src: Uint8Array, dest: Uint8Array, typesize: number): void {\n const n = src.length;\n const elements = Math.floor(n / typesize);\n for (let j = 0; j < typesize; j++) {\n const row = j * elements;\n for (let i = 0; i < elements; i++) dest[row + i] = src[i * typesize + j]!;\n }\n const tail = elements * typesize;\n dest.set(src.subarray(tail, n), tail);\n}\n\n/**\n * Compresses `src` into one Blosc1 frame (LZ4 codec) as `blosc_compress_ctx(clevel, shuffle, typesize,\n * src.length, src, dest, destSize, \"lz4\", blocksize, 1)` from OpenVDB v14's Blosc does, and returns the\n * frame (exactly its `cbytes` long), or `null` when Blosc returns 0 (the frame can't fit `destSize`).\n * Throws a `RangeError` on options Blosc rejects (a negative return there).\n */\nexport function compressBlosc(src: Uint8Array, opts: BloscCompressOptions = {}): Uint8Array | null {\n const clevel = opts.clevel ?? 9;\n const doShuffle = opts.shuffle ?? true;\n let typesize = opts.typesize ?? 4;\n const forced = opts.blocksize ?? 1 << 18;\n const nbytes = src.length;\n const destSize = opts.destSize ?? nbytes + HEADER_SIZE;\n if (!Number.isInteger(clevel) || clevel < 0 || clevel > 9) throw new RangeError(`blosc clevel must be 0-9, got ${clevel}`);\n if (!Number.isInteger(typesize) || typesize < 1) throw new RangeError(`blosc typesize must be a positive integer, got ${typesize}`);\n if (!Number.isInteger(forced) || forced < 0) throw new RangeError(`blosc blocksize must be a non-negative integer, got ${forced}`);\n if (!Number.isInteger(destSize) || destSize < 0) throw new RangeError(`blosc destSize must be a non-negative integer`);\n // initialize_context_compression: size limits return 0 (no frame).\n if (nbytes > BLOSC_MAX_BUFFERSIZE || destSize < HEADER_SIZE) return null;\n if (typesize > MAX_TYPESIZE) typesize = 1;\n\n const blocksize = computeBlocksize(clevel, typesize, nbytes, forced);\n const leftover = nbytes % blocksize;\n const nblocks = Math.floor(nbytes / blocksize) + (leftover > 0 ? 1 : 0);\n\n // write_compression_header.\n // Room for the block-start table even when `destSize` is smaller (Blosc writes it before it finds the frame\n // can't fit, past its buffer; here it lands in scratch and the call returns null).\n const dest = new Uint8Array(\n Math.max(HEADER_SIZE + 4 * nblocks, Math.min(destSize, nbytes + HEADER_SIZE + 4 * nblocks + 4 * nblocks * MAX_SPLITS + 64)),\n );\n const view = new DataView(dest.buffer);\n let flags = 0;\n let outBytes = HEADER_SIZE + 4 * nblocks;\n if (clevel === 0 || nbytes < MIN_BUFFERSIZE) {\n flags |= FLAG_MEMCPYED;\n outBytes = HEADER_SIZE;\n }\n if (doShuffle) flags |= FLAG_SHUFFLE;\n if (!splitBlock(typesize, blocksize)) flags |= 0x10;\n flags |= LZ4_FORMAT << 5;\n\n // blosc_compress_context.\n if (flags & FLAG_MEMCPYED && nbytes + HEADER_SIZE > destSize) return null;\n let ntbytes = flags & FLAG_MEMCPYED ? -1 : compressBlocks(src, dest, view, flags, typesize, blocksize, nblocks, leftover, clevel, outBytes, destSize);\n if (ntbytes === 0 && nbytes + HEADER_SIZE <= destSize) flags |= FLAG_MEMCPYED;\n if (flags & FLAG_MEMCPYED && ntbytes <= 0) {\n if (nbytes + HEADER_SIZE > dest.length) return null;\n dest.set(src, HEADER_SIZE);\n ntbytes = HEADER_SIZE + nbytes;\n }\n if (ntbytes <= 0) return null;\n\n dest[0] = VERSION_FORMAT;\n dest[1] = LZ4_VERSION_FORMAT;\n dest[2] = flags;\n dest[3] = typesize;\n view.setInt32(4, nbytes, true);\n view.setInt32(8, blocksize, true);\n view.setInt32(12, ntbytes, true);\n return dest.slice(0, ntbytes);\n}\n\n/** `serial_blosc` (compression, not memcpy'd): the bytes written, or 0 when the frame overruns `maxbytes`. */\nfunction compressBlocks(\n src: Uint8Array,\n dest: Uint8Array,\n view: DataView,\n flags: number,\n typesize: number,\n blocksize: number,\n nblocks: number,\n leftover: number,\n clevel: number,\n start: number,\n maxbytes: number,\n): number {\n const tmp = new Uint8Array(blocksize);\n const doShuffle = (flags & FLAG_SHUFFLE) !== 0 && typesize > 1;\n const dontSplit = (flags & 0x10) !== 0;\n const accel = 10 - clevel;\n let ntbytes = start;\n for (let j = 0; j < nblocks; j++) {\n view.setInt32(HEADER_SIZE + 4 * j, ntbytes, true);\n const isLeftover = j === nblocks - 1 && leftover > 0;\n const bsize = isLeftover ? leftover : blocksize;\n const block = src.subarray(j * blocksize, j * blocksize + bsize);\n let data = block;\n if (doShuffle) {\n shuffleBytes(block, tmp.subarray(0, bsize), typesize);\n data = tmp.subarray(0, bsize);\n }\n // blosc_c.\n const nsplits = !dontSplit && !isLeftover ? typesize : 1;\n const neblock = Math.floor(bsize / nsplits);\n for (let s = 0; s < nsplits; s++) {\n const sizeAt = ntbytes;\n ntbytes += 4;\n let maxout = neblock;\n if (ntbytes + maxout > maxbytes) {\n maxout = maxbytes - ntbytes;\n if (maxout <= 0) return 0;\n }\n const part = data.subarray(s * neblock, (s + 1) * neblock);\n let cbytes = compressLz4Block(part, dest.subarray(ntbytes, ntbytes + maxout), accel);\n if (cbytes === 0 || cbytes === neblock) {\n if (ntbytes + neblock > maxbytes) return 0;\n dest.set(part, ntbytes);\n cbytes = neblock;\n }\n view.setInt32(sizeAt, cbytes, true);\n ntbytes += cbytes;\n }\n }\n return ntbytes;\n}\n"]}
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* blosc.ts — a pure-TS decoder for the Blosc1 frames OpenVDB
|
|
2
|
+
* blosc.ts — a pure-TS decoder for the Blosc1 frames OpenVDB and NanoVDB write.
|
|
3
3
|
*
|
|
4
4
|
* OpenVDB (`io/Compression.cc`, `bloscToStream`) compresses each node's value
|
|
5
5
|
* buffer with `blosc_compress_ctx(clevel 9, byte shuffle, typesize
|
|
6
6
|
* sizeof(ValueType), ..., "lz4", blocksize = whole buffer)`, writing the
|
|
7
7
|
* compressed byte count as an i64 followed by one Blosc1 frame. The
|
|
8
8
|
* openvdb.org `bunny_cloud.vdb` and `explosion.vdb` samples are stored this
|
|
9
|
-
* way.
|
|
10
|
-
* `
|
|
11
|
-
*
|
|
9
|
+
* way. NanoVDB's `Codec::BLOSC` `.nvdb` grids are LZ4 frames too
|
|
10
|
+
* (`io::Internal::write`: clevel 9, byte shuffle, typesize 4, 256 KiB
|
|
11
|
+
* blocks), and NVIDIA Warp writes `.nvdb` grids with python-blosc's defaults,
|
|
12
|
+
* BloscLZ (K7.C; the stream decoder is `blosclz.ts`). This decoder covers
|
|
13
|
+
* those frames, plus the `zlib` codec and memcpy'd frames for safety; other
|
|
14
|
+
* codecs (Snappy, Zstd) and bit-shuffle throw `VDBUnsupportedError`.
|
|
12
15
|
*
|
|
13
16
|
* Frame layout (c-blosc 1.x `blosc.c`, format version 2):
|
|
14
17
|
*
|
|
@@ -24,14 +27,33 @@
|
|
|
24
27
|
* else 1), each an i32 compressed size and its bytes. A
|
|
25
28
|
* stream whose size equals its uncompressed size is stored raw.
|
|
26
29
|
*
|
|
27
|
-
* Derived from the format description above, not from any third-party code
|
|
30
|
+
* Derived from the format description above, not from any third-party code
|
|
31
|
+
* (the BloscLZ stream decoder in `blosclz.ts` is a port; see its header). The
|
|
32
|
+
* BloscLZ checks follow the Blosc that OpenVDB v14.0.0 vendors (`vdb_blosc.c`,
|
|
33
|
+
* `validate_decompress_format`): a BloscLZ frame must carry stream format 1.
|
|
28
34
|
*/
|
|
35
|
+
/** Bytes of a Blosc1 frame header. */
|
|
36
|
+
export declare const BLOSC_HEADER_SIZE = 16;
|
|
29
37
|
export interface BloscLimits {
|
|
30
38
|
/** Largest uncompressed size the caller will accept; checked before allocating. */
|
|
31
39
|
maxBytes?: number;
|
|
32
40
|
/** The frame's required `cbytes` header field (what the enclosing format says it stored). */
|
|
33
41
|
expectedCbytes?: number;
|
|
34
42
|
}
|
|
43
|
+
/** The 16-byte Blosc1 frame header. */
|
|
44
|
+
export interface BloscHeader {
|
|
45
|
+
version: number;
|
|
46
|
+
versionlz: number;
|
|
47
|
+
flags: number;
|
|
48
|
+
typesize: number;
|
|
49
|
+
/** Uncompressed bytes. */
|
|
50
|
+
nbytes: number;
|
|
51
|
+
blocksize: number;
|
|
52
|
+
/** Bytes of the whole frame, header included. */
|
|
53
|
+
cbytes: number;
|
|
54
|
+
}
|
|
55
|
+
/** Reads a Blosc1 frame header (the first 16 bytes) without validating it. */
|
|
56
|
+
export declare function readBloscHeader(frame: Uint8Array): BloscHeader;
|
|
35
57
|
/**
|
|
36
58
|
* Decompresses one Blosc1 frame and returns its `nbytes` uncompressed bytes.
|
|
37
59
|
*
|
|
@@ -40,6 +62,14 @@ export interface BloscLimits {
|
|
|
40
62
|
* c-blosc's `blosc_run_decompression_with_context` and `blosc_d` checks.
|
|
41
63
|
*/
|
|
42
64
|
export declare function decompressBlosc(frame: Uint8Array, limits?: BloscLimits): Uint8Array;
|
|
65
|
+
/**
|
|
66
|
+
* Decompresses one Blosc1 frame into the start of `dest` and returns its
|
|
67
|
+
* `nbytes`. `dest.length` is the output cap (a frame claiming more is
|
|
68
|
+
* rejected before anything is decoded); the checks are those of
|
|
69
|
+
* {@link decompressBlosc}, and the only allocation is the unshuffle scratch
|
|
70
|
+
* (one block, never larger than the output).
|
|
71
|
+
*/
|
|
72
|
+
export declare function decompressBloscInto(frame: Uint8Array, dest: Uint8Array, expectedCbytes?: number): number;
|
|
43
73
|
/**
|
|
44
74
|
* Reverses Blosc's byte shuffle: the shuffled block stores byte `i` of every
|
|
45
75
|
* element together (`src[i * count + j]` is byte `i` of element `j`); trailing
|
package/dist/tools/vdb/blosc.js
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* blosc.ts — a pure-TS decoder for the Blosc1 frames OpenVDB
|
|
2
|
+
* blosc.ts — a pure-TS decoder for the Blosc1 frames OpenVDB and NanoVDB write.
|
|
3
3
|
*
|
|
4
4
|
* OpenVDB (`io/Compression.cc`, `bloscToStream`) compresses each node's value
|
|
5
5
|
* buffer with `blosc_compress_ctx(clevel 9, byte shuffle, typesize
|
|
6
6
|
* sizeof(ValueType), ..., "lz4", blocksize = whole buffer)`, writing the
|
|
7
7
|
* compressed byte count as an i64 followed by one Blosc1 frame. The
|
|
8
8
|
* openvdb.org `bunny_cloud.vdb` and `explosion.vdb` samples are stored this
|
|
9
|
-
* way.
|
|
10
|
-
* `
|
|
11
|
-
*
|
|
9
|
+
* way. NanoVDB's `Codec::BLOSC` `.nvdb` grids are LZ4 frames too
|
|
10
|
+
* (`io::Internal::write`: clevel 9, byte shuffle, typesize 4, 256 KiB
|
|
11
|
+
* blocks), and NVIDIA Warp writes `.nvdb` grids with python-blosc's defaults,
|
|
12
|
+
* BloscLZ (K7.C; the stream decoder is `blosclz.ts`). This decoder covers
|
|
13
|
+
* those frames, plus the `zlib` codec and memcpy'd frames for safety; other
|
|
14
|
+
* codecs (Snappy, Zstd) and bit-shuffle throw `VDBUnsupportedError`.
|
|
12
15
|
*
|
|
13
16
|
* Frame layout (c-blosc 1.x `blosc.c`, format version 2):
|
|
14
17
|
*
|
|
@@ -24,8 +27,12 @@
|
|
|
24
27
|
* else 1), each an i32 compressed size and its bytes. A
|
|
25
28
|
* stream whose size equals its uncompressed size is stored raw.
|
|
26
29
|
*
|
|
27
|
-
* Derived from the format description above, not from any third-party code
|
|
30
|
+
* Derived from the format description above, not from any third-party code
|
|
31
|
+
* (the BloscLZ stream decoder in `blosclz.ts` is a port; see its header). The
|
|
32
|
+
* BloscLZ checks follow the Blosc that OpenVDB v14.0.0 vendors (`vdb_blosc.c`,
|
|
33
|
+
* `validate_decompress_format`): a BloscLZ frame must carry stream format 1.
|
|
28
34
|
*/
|
|
35
|
+
import { decompressBloscLzBlock } from "./blosclz.js";
|
|
29
36
|
import { VdbFormatError, VDBUnsupportedError } from "./errors.js";
|
|
30
37
|
import { inflateZlib } from "./inflate.js";
|
|
31
38
|
const HEADER_SIZE = 16;
|
|
@@ -37,10 +44,31 @@ const FLAG_DONT_SPLIT = 0x10;
|
|
|
37
44
|
const MAX_SPLITS = 16;
|
|
38
45
|
const MIN_BUFFERSIZE = 128;
|
|
39
46
|
const CODEC_NAMES = ["BloscLZ", "LZ4", "Snappy", "zlib", "Zstd"];
|
|
47
|
+
const CODEC_BLOSCLZ = 0;
|
|
40
48
|
const CODEC_LZ4 = 1;
|
|
41
49
|
const CODEC_ZLIB = 3;
|
|
50
|
+
/** `BLOSC_BLOSCLZ_VERSION_FORMAT`: the only BloscLZ stream format c-blosc 1.x writes and reads. */
|
|
51
|
+
const BLOSCLZ_VERSION_FORMAT = 1;
|
|
42
52
|
/** Default output cap when a caller does not know the expected size (1 GiB). */
|
|
43
53
|
const DEFAULT_MAX_BYTES = 1 << 30;
|
|
54
|
+
/** Bytes of a Blosc1 frame header. */
|
|
55
|
+
export const BLOSC_HEADER_SIZE = HEADER_SIZE;
|
|
56
|
+
/** Reads a Blosc1 frame header (the first 16 bytes) without validating it. */
|
|
57
|
+
export function readBloscHeader(frame) {
|
|
58
|
+
if (frame.length < HEADER_SIZE) {
|
|
59
|
+
throw new VdbFormatError(`blosc frame is ${frame.length} bytes, shorter than its ${HEADER_SIZE}-byte header`);
|
|
60
|
+
}
|
|
61
|
+
const view = new DataView(frame.buffer, frame.byteOffset, frame.byteLength);
|
|
62
|
+
return {
|
|
63
|
+
version: frame[0],
|
|
64
|
+
versionlz: frame[1],
|
|
65
|
+
flags: frame[2],
|
|
66
|
+
typesize: frame[3],
|
|
67
|
+
nbytes: view.getUint32(4, true),
|
|
68
|
+
blocksize: view.getUint32(8, true),
|
|
69
|
+
cbytes: view.getUint32(12, true),
|
|
70
|
+
};
|
|
71
|
+
}
|
|
44
72
|
/**
|
|
45
73
|
* Decompresses one Blosc1 frame and returns its `nbytes` uncompressed bytes.
|
|
46
74
|
*
|
|
@@ -49,17 +77,37 @@ const DEFAULT_MAX_BYTES = 1 << 30;
|
|
|
49
77
|
* c-blosc's `blosc_run_decompression_with_context` and `blosc_d` checks.
|
|
50
78
|
*/
|
|
51
79
|
export function decompressBlosc(frame, limits = {}) {
|
|
52
|
-
const
|
|
53
|
-
if (
|
|
54
|
-
|
|
80
|
+
const header = checkBloscHeader(frame, limits.maxBytes ?? DEFAULT_MAX_BYTES, limits.expectedCbytes);
|
|
81
|
+
if (header.nbytes === 0)
|
|
82
|
+
return new Uint8Array(0);
|
|
83
|
+
if (header.flags & FLAG_MEMCPYED)
|
|
84
|
+
return frame.slice(HEADER_SIZE, HEADER_SIZE + header.nbytes);
|
|
85
|
+
const out = new Uint8Array(header.nbytes);
|
|
86
|
+
decodeBlocks(frame, header, out);
|
|
87
|
+
return out;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Decompresses one Blosc1 frame into the start of `dest` and returns its
|
|
91
|
+
* `nbytes`. `dest.length` is the output cap (a frame claiming more is
|
|
92
|
+
* rejected before anything is decoded); the checks are those of
|
|
93
|
+
* {@link decompressBlosc}, and the only allocation is the unshuffle scratch
|
|
94
|
+
* (one block, never larger than the output).
|
|
95
|
+
*/
|
|
96
|
+
export function decompressBloscInto(frame, dest, expectedCbytes) {
|
|
97
|
+
const header = checkBloscHeader(frame, dest.length, expectedCbytes);
|
|
98
|
+
if (header.nbytes === 0)
|
|
99
|
+
return 0;
|
|
100
|
+
if (header.flags & FLAG_MEMCPYED) {
|
|
101
|
+
dest.set(frame.subarray(HEADER_SIZE, HEADER_SIZE + header.nbytes));
|
|
102
|
+
return header.nbytes;
|
|
55
103
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const
|
|
62
|
-
const cbytes =
|
|
104
|
+
decodeBlocks(frame, header, dest.subarray(0, header.nbytes));
|
|
105
|
+
return header.nbytes;
|
|
106
|
+
}
|
|
107
|
+
/** Validates a frame header against the output cap and the stored byte count. */
|
|
108
|
+
function checkBloscHeader(frame, maxBytes, expectedCbytes) {
|
|
109
|
+
const header = readBloscHeader(frame);
|
|
110
|
+
const { version, versionlz, flags, typesize, nbytes, blocksize, cbytes } = header;
|
|
63
111
|
if (version === 0 || version > 2) {
|
|
64
112
|
throw new VDBUnsupportedError(`blosc frame format version ${version} (only Blosc1, versions 1-2, is supported)`);
|
|
65
113
|
}
|
|
@@ -68,11 +116,11 @@ export function decompressBlosc(frame, limits = {}) {
|
|
|
68
116
|
if (cbytes < HEADER_SIZE || cbytes > frame.length) {
|
|
69
117
|
throw new VdbFormatError(`blosc header field cbytes=${cbytes} is outside the ${frame.length}-byte frame`);
|
|
70
118
|
}
|
|
71
|
-
if (
|
|
72
|
-
throw new VdbFormatError(`blosc header field cbytes=${cbytes} does not match the ${
|
|
119
|
+
if (expectedCbytes !== undefined && cbytes !== expectedCbytes) {
|
|
120
|
+
throw new VdbFormatError(`blosc header field cbytes=${cbytes} does not match the ${expectedCbytes} compressed bytes stored`);
|
|
73
121
|
}
|
|
74
122
|
if (nbytes === 0)
|
|
75
|
-
return
|
|
123
|
+
return header;
|
|
76
124
|
if (nbytes > maxBytes) {
|
|
77
125
|
throw new VdbFormatError(`blosc header field nbytes=${nbytes} exceeds the expected ${maxBytes}-byte output`);
|
|
78
126
|
}
|
|
@@ -85,21 +133,30 @@ export function decompressBlosc(frame, limits = {}) {
|
|
|
85
133
|
if (nbytes + HEADER_SIZE !== cbytes) {
|
|
86
134
|
throw new VdbFormatError(`memcpy'd blosc frame: cbytes=${cbytes} != nbytes(${nbytes}) + ${HEADER_SIZE}`);
|
|
87
135
|
}
|
|
88
|
-
return
|
|
136
|
+
return header;
|
|
89
137
|
}
|
|
90
138
|
if (flags & FLAG_BITSHUFFLE) {
|
|
91
139
|
throw new VDBUnsupportedError("blosc bit-shuffle is not supported (OpenVDB writes byte shuffle)");
|
|
92
140
|
}
|
|
93
141
|
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)`);
|
|
142
|
+
if (codec !== CODEC_LZ4 && codec !== CODEC_ZLIB && codec !== CODEC_BLOSCLZ) {
|
|
143
|
+
throw new VDBUnsupportedError(`blosc codec ${CODEC_NAMES[codec] ?? `#${codec}`} is not supported (LZ4, BloscLZ and zlib are; OpenVDB writes LZ4)`);
|
|
96
144
|
}
|
|
145
|
+
if (codec === CODEC_BLOSCLZ && versionlz !== BLOSCLZ_VERSION_FORMAT) {
|
|
146
|
+
throw new VDBUnsupportedError(`BloscLZ stream format version ${versionlz} (only version ${BLOSCLZ_VERSION_FORMAT} exists)`);
|
|
147
|
+
}
|
|
148
|
+
return header;
|
|
149
|
+
}
|
|
150
|
+
/** Decodes every block of a compressed (not memcpy'd) frame into `out`, which is exactly `nbytes` long. */
|
|
151
|
+
function decodeBlocks(frame, header, out) {
|
|
152
|
+
const { flags, typesize, nbytes, blocksize, cbytes } = header;
|
|
153
|
+
const view = new DataView(frame.buffer, frame.byteOffset, frame.byteLength);
|
|
154
|
+
const codec = (flags >> 5) & 0x7;
|
|
97
155
|
const nblocks = Math.ceil(nbytes / blocksize);
|
|
98
156
|
const tableEnd = HEADER_SIZE + 4 * nblocks;
|
|
99
157
|
if (tableEnd > cbytes) {
|
|
100
158
|
throw new VdbFormatError(`blosc block-start table (${nblocks} blocks) does not fit in cbytes=${cbytes}`);
|
|
101
159
|
}
|
|
102
|
-
const out = new Uint8Array(nbytes);
|
|
103
160
|
const shuffle = (flags & FLAG_SHUFFLE) !== 0 && typesize > 1;
|
|
104
161
|
const dontSplit = (flags & FLAG_DONT_SPLIT) !== 0;
|
|
105
162
|
// Never larger than the output: blocksize <= maxBytes, and a block never exceeds nbytes.
|
|
@@ -137,10 +194,10 @@ export function decompressBlosc(frame, limits = {}) {
|
|
|
137
194
|
if (csize === neblock) {
|
|
138
195
|
part.set(src);
|
|
139
196
|
}
|
|
140
|
-
else if (codec === CODEC_LZ4) {
|
|
141
|
-
const written = decompressLz4Block(src, part);
|
|
197
|
+
else if (codec === CODEC_LZ4 || codec === CODEC_BLOSCLZ) {
|
|
198
|
+
const written = codec === CODEC_LZ4 ? decompressLz4Block(src, part) : decompressBloscLzBlock(src, part);
|
|
142
199
|
if (written !== neblock) {
|
|
143
|
-
throw new VdbFormatError(
|
|
200
|
+
throw new VdbFormatError(`${CODEC_NAMES[codec]} stream decoded to ${written} bytes, expected ${neblock}`);
|
|
144
201
|
}
|
|
145
202
|
}
|
|
146
203
|
else {
|
|
@@ -155,7 +212,6 @@ export function decompressBlosc(frame, limits = {}) {
|
|
|
155
212
|
if (scratch)
|
|
156
213
|
unshuffle(scratch.subarray(0, bsize), dest, typesize);
|
|
157
214
|
}
|
|
158
|
-
return out;
|
|
159
215
|
}
|
|
160
216
|
/**
|
|
161
217
|
* Reverses Blosc's byte shuffle: the shuffled block stores byte `i` of every
|
|
@@ -1 +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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CAAC;QAExG,IAAI,QAAQ,GAAG,KAAK,GAAG,GAAG,CAAC;QAC3B,IAAI,QAAQ,KAAK,EAAE,EAAE,CAAC;YACpB,IAAI,IAAY,CAAC;YACjB,GAAG,CAAC;gBACF,IAAI,EAAE,IAAI,GAAG;oBAAE,MAAM,IAAI,cAAc,CAAC,sCAAsC,CAAC,CAAC;gBAChF,IAAI,GAAG,GAAG,CAAC,EAAE,EAAE,CAAE,CAAC;gBAClB,QAAQ,IAAI,IAAI,CAAC;YACnB,CAAC,QAAQ,IAAI,KAAK,GAAG,EAAE;QACzB,CAAC;QACD,QAAQ,IAAI,CAAC,CAAC;QACd,IAAI,EAAE,GAAG,QAAQ,GAAG,IAAI,CAAC,MAAM;YAAE,MAAM,IAAI,cAAc,CAAC,gCAAgC,CAAC,CAAC;QAC5F,iFAAiF;QACjF,IAAI,IAAI,GAAG,EAAE,GAAG,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"]}
|
|
1
|
+
{"version":3,"file":"blosc.js","sourceRoot":"","sources":["../../../src/tools/vdb/blosc.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AACtD,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,EA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AE,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 and NanoVDB write.\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. NanoVDB's `Codec::BLOSC` `.nvdb` grids are LZ4 frames too\n * (`io::Internal::write`: clevel 9, byte shuffle, typesize 4, 256 KiB\n * blocks), and NVIDIA Warp writes `.nvdb` grids with python-blosc's defaults,\n * BloscLZ (K7.C; the stream decoder is `blosclz.ts`). This decoder covers\n * those frames, plus the `zlib` codec and memcpy'd frames for safety; other\n * codecs (Snappy, 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 * (the BloscLZ stream decoder in `blosclz.ts` is a port; see its header). The\n * BloscLZ checks follow the Blosc that OpenVDB v14.0.0 vendors (`vdb_blosc.c`,\n * `validate_decompress_format`): a BloscLZ frame must carry stream format 1.\n */\n\nimport { decompressBloscLzBlock } from \"./blosclz.js\";\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_BLOSCLZ = 0;\nconst CODEC_LZ4 = 1;\nconst CODEC_ZLIB = 3;\n/** `BLOSC_BLOSCLZ_VERSION_FORMAT`: the only BloscLZ stream format c-blosc 1.x writes and reads. */\nconst BLOSCLZ_VERSION_FORMAT = 1;\n\n/** Default output cap when a caller does not know the expected size (1 GiB). */\nconst DEFAULT_MAX_BYTES = 1 << 30;\n\n/** Bytes of a Blosc1 frame header. */\nexport const BLOSC_HEADER_SIZE = HEADER_SIZE;\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/** The 16-byte Blosc1 frame header. */\nexport interface BloscHeader {\n version: number;\n versionlz: number;\n flags: number;\n typesize: number;\n /** Uncompressed bytes. */\n nbytes: number;\n blocksize: number;\n /** Bytes of the whole frame, header included. */\n cbytes: number;\n}\n\n/** Reads a Blosc1 frame header (the first 16 bytes) without validating it. */\nexport function readBloscHeader(frame: Uint8Array): BloscHeader {\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 return {\n version: frame[0]!,\n versionlz: frame[1]!,\n flags: frame[2]!,\n typesize: frame[3]!,\n nbytes: view.getUint32(4, true),\n blocksize: view.getUint32(8, true),\n cbytes: view.getUint32(12, true),\n };\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 header = checkBloscHeader(frame, limits.maxBytes ?? DEFAULT_MAX_BYTES, limits.expectedCbytes);\n if (header.nbytes === 0) return new Uint8Array(0);\n if (header.flags & FLAG_MEMCPYED) return frame.slice(HEADER_SIZE, HEADER_SIZE + header.nbytes);\n const out = new Uint8Array(header.nbytes);\n decodeBlocks(frame, header, out);\n return out;\n}\n\n/**\n * Decompresses one Blosc1 frame into the start of `dest` and returns its\n * `nbytes`. `dest.length` is the output cap (a frame claiming more is\n * rejected before anything is decoded); the checks are those of\n * {@link decompressBlosc}, and the only allocation is the unshuffle scratch\n * (one block, never larger than the output).\n */\nexport function decompressBloscInto(frame: Uint8Array, dest: Uint8Array, expectedCbytes?: number): number {\n const header = checkBloscHeader(frame, dest.length, expectedCbytes);\n if (header.nbytes === 0) return 0;\n if (header.flags & FLAG_MEMCPYED) {\n dest.set(frame.subarray(HEADER_SIZE, HEADER_SIZE + header.nbytes));\n return header.nbytes;\n }\n decodeBlocks(frame, header, dest.subarray(0, header.nbytes));\n return header.nbytes;\n}\n\n/** Validates a frame header against the output cap and the stored byte count. */\nfunction checkBloscHeader(frame: Uint8Array, maxBytes: number, expectedCbytes: number | undefined): BloscHeader {\n const header = readBloscHeader(frame);\n const { version, versionlz, flags, typesize, nbytes, blocksize, cbytes } = header;\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 (expectedCbytes !== undefined && cbytes !== expectedCbytes) {\n throw new VdbFormatError(`blosc header field cbytes=${cbytes} does not match the ${expectedCbytes} compressed bytes stored`);\n }\n if (nbytes === 0) return header;\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 header;\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 && codec !== CODEC_BLOSCLZ) {\n throw new VDBUnsupportedError(\n `blosc codec ${CODEC_NAMES[codec] ?? `#${codec}`} is not supported (LZ4, BloscLZ and zlib are; OpenVDB writes LZ4)`,\n );\n }\n if (codec === CODEC_BLOSCLZ && versionlz !== BLOSCLZ_VERSION_FORMAT) {\n throw new VDBUnsupportedError(`BloscLZ stream format version ${versionlz} (only version ${BLOSCLZ_VERSION_FORMAT} exists)`);\n }\n return header;\n}\n\n/** Decodes every block of a compressed (not memcpy'd) frame into `out`, which is exactly `nbytes` long. */\nfunction decodeBlocks(frame: Uint8Array, header: BloscHeader, out: Uint8Array): void {\n const { flags, typesize, nbytes, blocksize, cbytes } = header;\n const view = new DataView(frame.buffer, frame.byteOffset, frame.byteLength);\n const codec = (flags >> 5) & 0x7;\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 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 || codec === CODEC_BLOSCLZ) {\n const written = codec === CODEC_LZ4 ? decompressLz4Block(src, part) : decompressBloscLzBlock(src, part);\n if (written !== neblock) {\n throw new VdbFormatError(`${CODEC_NAMES[codec]} 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}\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"]}
|