@pmndrs/vdb 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +727 -0
- package/LICENSE +21 -0
- package/README.md +496 -2
- package/THIRD_PARTY_NOTICES.md +315 -0
- package/dist/core/compute/atlas.d.ts +102 -0
- package/dist/core/compute/atlas.js +103 -0
- package/dist/core/compute/atlas.js.map +1 -0
- package/dist/core/compute/index.d.ts +13 -0
- package/dist/core/compute/index.js +9 -0
- package/dist/core/compute/index.js.map +1 -0
- 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 +120 -0
- package/dist/core/compute/pyramid.js +468 -0
- package/dist/core/compute/pyramid.js.map +1 -0
- package/dist/core/compute/shared.d.ts +116 -0
- package/dist/core/compute/shared.js +211 -0
- package/dist/core/compute/shared.js.map +1 -0
- package/dist/core/compute/stats.d.ts +78 -0
- package/dist/core/compute/stats.js +193 -0
- package/dist/core/compute/stats.js.map +1 -0
- package/dist/core/compute/value-transform.d.ts +30 -0
- package/dist/core/compute/value-transform.js +64 -0
- package/dist/core/compute/value-transform.js.map +1 -0
- package/dist/core/errors.d.ts +21 -0
- package/dist/core/errors.js +17 -0
- package/dist/core/errors.js.map +1 -0
- 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 +52 -0
- package/dist/core/index.js +46 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/internal.d.ts +31 -0
- package/dist/core/internal.js +32 -0
- package/dist/core/internal.js.map +1 -0
- package/dist/core/pool/affine.d.ts +34 -0
- package/dist/core/pool/affine.js +100 -0
- package/dist/core/pool/affine.js.map +1 -0
- package/dist/core/pool/allocator.d.ts +32 -0
- package/dist/core/pool/allocator.js +81 -0
- package/dist/core/pool/allocator.js.map +1 -0
- package/dist/core/pool/image-header.d.ts +93 -0
- package/dist/core/pool/image-header.js +194 -0
- package/dist/core/pool/image-header.js.map +1 -0
- package/dist/core/pool/layout.d.ts +198 -0
- package/dist/core/pool/layout.js +316 -0
- package/dist/core/pool/layout.js.map +1 -0
- package/dist/core/pool/limits.d.ts +41 -0
- package/dist/core/pool/limits.js +80 -0
- package/dist/core/pool/limits.js.map +1 -0
- package/dist/core/pool/pool.d.ts +384 -0
- package/dist/core/pool/pool.js +1184 -0
- package/dist/core/pool/pool.js.map +1 -0
- 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/core/sequence.d.ts +347 -0
- package/dist/core/sequence.js +548 -0
- 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 +50 -0
- package/dist/core/source/dense.js +384 -0
- package/dist/core/source/dense.js.map +1 -0
- 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 +120 -0
- package/dist/core/source/types.js +9 -0
- package/dist/core/source/types.js.map +1 -0
- 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 +37 -0
- package/dist/core/types.js +32 -0
- package/dist/core/types.js.map +1 -0
- package/dist/core/wgsl/api.d.ts +65 -0
- package/dist/core/wgsl/api.js +546 -0
- package/dist/core/wgsl/api.js.map +1 -0
- package/dist/core/wgsl/generate.d.ts +90 -0
- package/dist/core/wgsl/generate.js +678 -0
- package/dist/core/wgsl/generate.js.map +1 -0
- 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 +58 -0
- package/dist/core/wgsl/level-set.js +200 -0
- package/dist/core/wgsl/level-set.js.map +1 -0
- 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 +14 -0
- package/dist/core/wgsl/pnanovdb.chunks.generated.js +333 -0
- package/dist/core/wgsl/pnanovdb.chunks.generated.js.map +1 -0
- package/dist/core/wgsl/reserved.d.ts +9 -0
- package/dist/core/wgsl/reserved.js +26 -0
- package/dist/core/wgsl/reserved.js.map +1 -0
- package/dist/core/wgsl/types.d.ts +198 -0
- package/dist/core/wgsl/types.js +2 -0
- package/dist/core/wgsl/types.js.map +1 -0
- package/dist/three/coarse-first.d.ts +207 -0
- package/dist/three/coarse-first.js +205 -0
- package/dist/three/coarse-first.js.map +1 -0
- package/dist/three/compute.d.ts +73 -0
- package/dist/three/compute.js +66 -0
- package/dist/three/compute.js.map +1 -0
- package/dist/three/device.d.ts +66 -0
- package/dist/three/device.js +62 -0
- package/dist/three/device.js.map +1 -0
- 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 +117 -0
- package/dist/three/frame/emission-light.js +276 -0
- package/dist/three/frame/emission-light.js.map +1 -0
- package/dist/three/frame/index.d.ts +19 -0
- package/dist/three/frame/index.js +15 -0
- package/dist/three/frame/index.js.map +1 -0
- package/dist/three/frame/medium.d.ts +33 -0
- package/dist/three/frame/medium.js +29 -0
- package/dist/three/frame/medium.js.map +1 -0
- package/dist/three/frame/renderer.d.ts +97 -0
- package/dist/three/frame/renderer.js +480 -0
- package/dist/three/frame/renderer.js.map +1 -0
- package/dist/three/frame/spectrum.d.ts +4 -0
- package/dist/three/frame/spectrum.js +15 -0
- package/dist/three/frame/spectrum.js.map +1 -0
- package/dist/three/frame/three-internals.d.ts +60 -0
- package/dist/three/frame/three-internals.js +152 -0
- package/dist/three/frame/three-internals.js.map +1 -0
- package/dist/three/frame/volume-shadows.d.ts +139 -0
- package/dist/three/frame/volume-shadows.js +403 -0
- package/dist/three/frame/volume-shadows.js.map +1 -0
- package/dist/three/frame/volume.d.ts +230 -0
- package/dist/three/frame/volume.js +268 -0
- package/dist/three/frame/volume.js.map +1 -0
- package/dist/three/grid-node.d.ts +229 -0
- package/dist/three/grid-node.js +545 -0
- package/dist/three/grid-node.js.map +1 -0
- package/dist/three/index.d.ts +52 -0
- package/dist/three/index.js +58 -0
- package/dist/three/index.js.map +1 -0
- package/dist/three/internal.d.ts +20 -0
- package/dist/three/internal.js +18 -0
- package/dist/three/internal.js.map +1 -0
- package/dist/three/level-set-material.d.ts +185 -0
- package/dist/three/level-set-material.js +241 -0
- package/dist/three/level-set-material.js.map +1 -0
- 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 +324 -0
- package/dist/three/material.js +502 -0
- package/dist/three/material.js.map +1 -0
- package/dist/three/points.d.ts +140 -0
- package/dist/three/points.js +261 -0
- package/dist/three/points.js.map +1 -0
- package/dist/three/sparse-source.d.ts +165 -0
- package/dist/three/sparse-source.js +405 -0
- package/dist/three/sparse-source.js.map +1 -0
- package/dist/three/volume-source.d.ts +22 -0
- package/dist/three/volume-source.js +110 -0
- package/dist/three/volume-source.js.map +1 -0
- 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 +116 -0
- package/dist/tools/cpu/compute.js +239 -0
- package/dist/tools/cpu/compute.js.map +1 -0
- 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 +111 -0
- package/dist/tools/cpu/level-set.js +313 -0
- package/dist/tools/cpu/level-set.js.map +1 -0
- 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 +297 -0
- package/dist/tools/cpu/march.js +726 -0
- package/dist/tools/cpu/march.js.map +1 -0
- 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/probe-coords.d.ts +70 -0
- package/dist/tools/cpu/probe-coords.js +116 -0
- package/dist/tools/cpu/probe-coords.js.map +1 -0
- package/dist/tools/cpu/read-value.d.ts +44 -0
- package/dist/tools/cpu/read-value.js +351 -0
- package/dist/tools/cpu/read-value.js.map +1 -0
- package/dist/tools/cpu/sample-trilinear.d.ts +43 -0
- package/dist/tools/cpu/sample-trilinear.js +168 -0
- package/dist/tools/cpu/sample-trilinear.js.map +1 -0
- package/dist/tools/cpu/stride-tables.d.ts +56 -0
- package/dist/tools/cpu/stride-tables.generated.d.ts +1059 -0
- package/dist/tools/cpu/stride-tables.generated.js +1267 -0
- package/dist/tools/cpu/stride-tables.generated.js.map +1 -0
- package/dist/tools/cpu/stride-tables.js +78 -0
- package/dist/tools/cpu/stride-tables.js.map +1 -0
- 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 +66 -0
- package/dist/tools/errors.js +67 -0
- package/dist/tools/errors.js.map +1 -0
- 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 +57 -0
- package/dist/tools/frame/blackbody.js +151 -0
- package/dist/tools/frame/blackbody.js.map +1 -0
- 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 +137 -0
- package/dist/tools/frame/emission.js +290 -0
- package/dist/tools/frame/emission.js.map +1 -0
- 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 +106 -0
- package/dist/tools/frame/environment.js +272 -0
- package/dist/tools/frame/environment.js.map +1 -0
- 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 +392 -0
- package/dist/tools/frame/grid.js +802 -0
- package/dist/tools/frame/grid.js.map +1 -0
- package/dist/tools/frame/index.d.ts +150 -0
- package/dist/tools/frame/index.js +389 -0
- package/dist/tools/frame/index.js.map +1 -0
- package/dist/tools/frame/medium.d.ts +77 -0
- package/dist/tools/frame/medium.js +101 -0
- package/dist/tools/frame/medium.js.map +1 -0
- package/dist/tools/frame/mie-table.d.ts +6 -0
- package/dist/tools/frame/mie-table.js +16 -0
- package/dist/tools/frame/mie-table.js.map +1 -0
- package/dist/tools/frame/mie.d.ts +63 -0
- package/dist/tools/frame/mie.js +194 -0
- package/dist/tools/frame/mie.js.map +1 -0
- 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 +10 -0
- package/dist/tools/frame/neural-weights.js +244 -0
- package/dist/tools/frame/neural-weights.js.map +1 -0
- package/dist/tools/frame/neural.d.ts +80 -0
- package/dist/tools/frame/neural.js +150 -0
- package/dist/tools/frame/neural.js.map +1 -0
- 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 +55 -0
- package/dist/tools/frame/pyramid-layout.js +100 -0
- package/dist/tools/frame/pyramid-layout.js.map +1 -0
- package/dist/tools/frame/shadows.d.ts +190 -0
- package/dist/tools/frame/shadows.js +468 -0
- package/dist/tools/frame/shadows.js.map +1 -0
- package/dist/tools/frame/sparse.d.ts +147 -0
- package/dist/tools/frame/sparse.js +432 -0
- package/dist/tools/frame/sparse.js.map +1 -0
- 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 +222 -0
- package/dist/tools/frame/spectral.js +572 -0
- package/dist/tools/frame/spectral.js.map +1 -0
- 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 +157 -0
- package/dist/tools/index.js +132 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/internal.d.ts +87 -0
- package/dist/tools/internal.js +85 -0
- package/dist/tools/internal.js.map +1 -0
- package/dist/tools/nanovdb/build-from-vdb.d.ts +59 -0
- package/dist/tools/nanovdb/build-from-vdb.js +100 -0
- package/dist/tools/nanovdb/build-from-vdb.js.map +1 -0
- package/dist/tools/nanovdb/bytes.d.ts +233 -0
- package/dist/tools/nanovdb/bytes.js +388 -0
- package/dist/tools/nanovdb/bytes.js.map +1 -0
- package/dist/tools/nanovdb/coarse-first.d.ts +78 -0
- package/dist/tools/nanovdb/coarse-first.js +92 -0
- package/dist/tools/nanovdb/coarse-first.js.map +1 -0
- 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 +34 -0
- package/dist/tools/nanovdb/index.js +25 -0
- package/dist/tools/nanovdb/index.js.map +1 -0
- package/dist/tools/nanovdb/inspect.d.ts +33 -0
- package/dist/tools/nanovdb/inspect.js +70 -0
- package/dist/tools/nanovdb/inspect.js.map +1 -0
- package/dist/tools/nanovdb/leaf-codec.d.ts +119 -0
- package/dist/tools/nanovdb/leaf-codec.js +356 -0
- package/dist/tools/nanovdb/leaf-codec.js.map +1 -0
- package/dist/tools/nanovdb/quantize.d.ts +72 -0
- package/dist/tools/nanovdb/quantize.js +329 -0
- package/dist/tools/nanovdb/quantize.js.map +1 -0
- package/dist/tools/nanovdb/resample.d.ts +177 -0
- package/dist/tools/nanovdb/resample.js +692 -0
- package/dist/tools/nanovdb/resample.js.map +1 -0
- package/dist/tools/nanovdb/serialize.d.ts +176 -0
- package/dist/tools/nanovdb/serialize.js +439 -0
- package/dist/tools/nanovdb/serialize.js.map +1 -0
- package/dist/tools/nanovdb/stats.d.ts +87 -0
- package/dist/tools/nanovdb/stats.js +225 -0
- package/dist/tools/nanovdb/stats.js.map +1 -0
- package/dist/tools/nanovdb/transform.d.ts +30 -0
- package/dist/tools/nanovdb/transform.js +94 -0
- package/dist/tools/nanovdb/transform.js.map +1 -0
- package/dist/tools/nanovdb/tree.d.ts +186 -0
- package/dist/tools/nanovdb/tree.js +530 -0
- package/dist/tools/nanovdb/tree.js.map +1 -0
- package/dist/tools/nanovdb/write-nvdb.d.ts +74 -0
- package/dist/tools/nanovdb/write-nvdb.js +290 -0
- package/dist/tools/nanovdb/write-nvdb.js.map +1 -0
- package/dist/tools/nvdb-file.d.ts +265 -0
- package/dist/tools/nvdb-file.js +763 -0
- package/dist/tools/nvdb-file.js.map +1 -0
- package/dist/tools/nvdb-stream.d.ts +154 -0
- package/dist/tools/nvdb-stream.js +409 -0
- package/dist/tools/nvdb-stream.js.map +1 -0
- 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/bit-utils.d.ts +20 -0
- package/dist/tools/vdb/bit-utils.js +42 -0
- package/dist/tools/vdb/bit-utils.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 +86 -0
- package/dist/tools/vdb/blosc.js +287 -0
- package/dist/tools/vdb/blosc.js.map +1 -0
- 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 +50 -0
- package/dist/tools/vdb/byte-reader.js +161 -0
- package/dist/tools/vdb/byte-reader.js.map +1 -0
- package/dist/tools/vdb/compression.d.ts +81 -0
- package/dist/tools/vdb/compression.js +260 -0
- package/dist/tools/vdb/compression.js.map +1 -0
- package/dist/tools/vdb/errors.d.ts +10 -0
- package/dist/tools/vdb/errors.js +11 -0
- package/dist/tools/vdb/errors.js.map +1 -0
- package/dist/tools/vdb/grid.d.ts +37 -0
- package/dist/tools/vdb/grid.js +153 -0
- package/dist/tools/vdb/grid.js.map +1 -0
- package/dist/tools/vdb/half-float.d.ts +9 -0
- package/dist/tools/vdb/half-float.js +24 -0
- package/dist/tools/vdb/half-float.js.map +1 -0
- package/dist/tools/vdb/index.d.ts +4 -0
- package/dist/tools/vdb/index.js +3 -0
- package/dist/tools/vdb/index.js.map +1 -0
- package/dist/tools/vdb/inflate.d.ts +24 -0
- package/dist/tools/vdb/inflate.js +334 -0
- package/dist/tools/vdb/inflate.js.map +1 -0
- 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.d.ts +17 -0
- package/dist/tools/vdb/metadata.js +72 -0
- package/dist/tools/vdb/metadata.js.map +1 -0
- package/dist/tools/vdb/parse.d.ts +47 -0
- package/dist/tools/vdb/parse.js +241 -0
- package/dist/tools/vdb/parse.js.map +1 -0
- package/dist/tools/vdb/point-render-data.d.ts +79 -0
- package/dist/tools/vdb/point-render-data.js +137 -0
- package/dist/tools/vdb/point-render-data.js.map +1 -0
- package/dist/tools/vdb/points.d.ts +186 -0
- package/dist/tools/vdb/points.js +835 -0
- package/dist/tools/vdb/points.js.map +1 -0
- package/dist/tools/vdb/transform.d.ts +23 -0
- package/dist/tools/vdb/transform.js +54 -0
- package/dist/tools/vdb/transform.js.map +1 -0
- package/dist/tools/vdb/tree.d.ts +111 -0
- package/dist/tools/vdb/tree.js +228 -0
- package/dist/tools/vdb/tree.js.map +1 -0
- package/dist/tools/vdb/types.d.ts +195 -0
- package/dist/tools/vdb/types.js +3 -0
- package/dist/tools/vdb/types.js.map +1 -0
- package/dist/tools/wvdb/bake.d.ts +145 -0
- package/dist/tools/wvdb/bake.js +361 -0
- package/dist/tools/wvdb/bake.js.map +1 -0
- package/dist/tools/wvdb/dense.d.ts +191 -0
- package/dist/tools/wvdb/dense.js +368 -0
- package/dist/tools/wvdb/dense.js.map +1 -0
- package/dist/tools/wvdb/format.d.ts +220 -0
- package/dist/tools/wvdb/format.js +306 -0
- package/dist/tools/wvdb/format.js.map +1 -0
- package/dist/tools/wvdb/index.d.ts +14 -0
- package/dist/tools/wvdb/index.js +15 -0
- package/dist/tools/wvdb/index.js.map +1 -0
- package/dist/tools/wvdb/level-set.d.ts +56 -0
- package/dist/tools/wvdb/level-set.js +153 -0
- package/dist/tools/wvdb/level-set.js.map +1 -0
- package/dist/tools/wvdb/nanovdb.d.ts +59 -0
- package/dist/tools/wvdb/nanovdb.js +64 -0
- package/dist/tools/wvdb/nanovdb.js.map +1 -0
- 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 +336 -0
- package/dist/tools/wvdb/read.js +766 -0
- package/dist/tools/wvdb/read.js.map +1 -0
- package/dist/tools/wvdb/sha256.d.ts +7 -0
- package/dist/tools/wvdb/sha256.js +76 -0
- package/dist/tools/wvdb/sha256.js.map +1 -0
- package/dist/tools/wvdb/write.d.ts +149 -0
- package/dist/tools/wvdb/write.js +403 -0
- package/dist/tools/wvdb/write.js.map +1 -0
- package/package.json +83 -4
- package/vendor/LICENSE +201 -0
- package/vendor/NOTICE +19 -0
- package/vendor/VENDOR.md +100 -0
- package/vendor/pnanovdb.wgsl +1577 -0
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* blosc.ts — a pure-TS decoder for the Blosc1 frames OpenVDB and NanoVDB write.
|
|
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. 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`.
|
|
15
|
+
*
|
|
16
|
+
* Frame layout (c-blosc 1.x `blosc.c`, format version 2):
|
|
17
|
+
*
|
|
18
|
+
* [0] version [1] versionlz [2] flags [3] typesize
|
|
19
|
+
* [4..8) nbytes (uncompressed) [8..12) blocksize [12..16) cbytes (whole frame)
|
|
20
|
+
* flags: 0x01 byte shuffle, 0x02 memcpy'd, 0x04 bit shuffle,
|
|
21
|
+
* 0x10 blocks not split, bits 5-7 codec (0 BloscLZ, 1 LZ4/LZ4HC,
|
|
22
|
+
* 2 Snappy, 3 zlib, 4 Zstd)
|
|
23
|
+
* memcpy'd: nbytes raw bytes follow the header.
|
|
24
|
+
* otherwise: nblocks i32 block starts (absolute frame offsets); each block
|
|
25
|
+
* holds `nsplits` streams (typesize streams when split -- flag bit 4 clear,
|
|
26
|
+
* typesize <= 16, block has >= 128 elements, not the short last block --
|
|
27
|
+
* else 1), each an i32 compressed size and its bytes. A
|
|
28
|
+
* stream whose size equals its uncompressed size is stored raw.
|
|
29
|
+
*
|
|
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.
|
|
34
|
+
*/
|
|
35
|
+
import { decompressBloscLzBlock } from "./blosclz.js";
|
|
36
|
+
import { VdbFormatError, VDBUnsupportedError } from "./errors.js";
|
|
37
|
+
import { inflateZlib } from "./inflate.js";
|
|
38
|
+
const HEADER_SIZE = 16;
|
|
39
|
+
const FLAG_SHUFFLE = 0x01;
|
|
40
|
+
const FLAG_MEMCPYED = 0x02;
|
|
41
|
+
const FLAG_BITSHUFFLE = 0x04;
|
|
42
|
+
const FLAG_DONT_SPLIT = 0x10;
|
|
43
|
+
/** c-blosc `MAX_SPLITS` / `MIN_BUFFERSIZE`. */
|
|
44
|
+
const MAX_SPLITS = 16;
|
|
45
|
+
const MIN_BUFFERSIZE = 128;
|
|
46
|
+
const CODEC_NAMES = ["BloscLZ", "LZ4", "Snappy", "zlib", "Zstd"];
|
|
47
|
+
const CODEC_BLOSCLZ = 0;
|
|
48
|
+
const CODEC_LZ4 = 1;
|
|
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;
|
|
52
|
+
/** Default output cap when a caller does not know the expected size (1 GiB). */
|
|
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
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Decompresses one Blosc1 frame and returns its `nbytes` uncompressed bytes.
|
|
74
|
+
*
|
|
75
|
+
* The frame is untrusted: every header field is validated against `maxBytes`
|
|
76
|
+
* (and the frame's own `cbytes`) before any allocation or read, mirroring
|
|
77
|
+
* c-blosc's `blosc_run_decompression_with_context` and `blosc_d` checks.
|
|
78
|
+
*/
|
|
79
|
+
export function decompressBlosc(frame, limits = {}) {
|
|
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;
|
|
103
|
+
}
|
|
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;
|
|
111
|
+
if (version === 0 || version > 2) {
|
|
112
|
+
throw new VDBUnsupportedError(`blosc frame format version ${version} (only Blosc1, versions 1-2, is supported)`);
|
|
113
|
+
}
|
|
114
|
+
if (flags & 0x08)
|
|
115
|
+
throw new VDBUnsupportedError("blosc frame has compressor flags from a future version");
|
|
116
|
+
if (cbytes < HEADER_SIZE || cbytes > frame.length) {
|
|
117
|
+
throw new VdbFormatError(`blosc header field cbytes=${cbytes} is outside the ${frame.length}-byte frame`);
|
|
118
|
+
}
|
|
119
|
+
if (expectedCbytes !== undefined && cbytes !== expectedCbytes) {
|
|
120
|
+
throw new VdbFormatError(`blosc header field cbytes=${cbytes} does not match the ${expectedCbytes} compressed bytes stored`);
|
|
121
|
+
}
|
|
122
|
+
if (nbytes === 0)
|
|
123
|
+
return header;
|
|
124
|
+
if (nbytes > maxBytes) {
|
|
125
|
+
throw new VdbFormatError(`blosc header field nbytes=${nbytes} exceeds the expected ${maxBytes}-byte output`);
|
|
126
|
+
}
|
|
127
|
+
if (blocksize === 0 || blocksize > maxBytes) {
|
|
128
|
+
throw new VdbFormatError(`blosc header field blocksize=${blocksize} is zero or exceeds the expected ${maxBytes}-byte output`);
|
|
129
|
+
}
|
|
130
|
+
if (typesize === 0)
|
|
131
|
+
throw new VdbFormatError("blosc header field typesize is zero");
|
|
132
|
+
if (flags & FLAG_MEMCPYED) {
|
|
133
|
+
if (nbytes + HEADER_SIZE !== cbytes) {
|
|
134
|
+
throw new VdbFormatError(`memcpy'd blosc frame: cbytes=${cbytes} != nbytes(${nbytes}) + ${HEADER_SIZE}`);
|
|
135
|
+
}
|
|
136
|
+
return header;
|
|
137
|
+
}
|
|
138
|
+
if (flags & FLAG_BITSHUFFLE) {
|
|
139
|
+
throw new VDBUnsupportedError("blosc bit-shuffle is not supported (OpenVDB writes byte shuffle)");
|
|
140
|
+
}
|
|
141
|
+
const codec = (flags >> 5) & 0x7;
|
|
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)`);
|
|
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;
|
|
155
|
+
const nblocks = Math.ceil(nbytes / blocksize);
|
|
156
|
+
const tableEnd = HEADER_SIZE + 4 * nblocks;
|
|
157
|
+
if (tableEnd > cbytes) {
|
|
158
|
+
throw new VdbFormatError(`blosc block-start table (${nblocks} blocks) does not fit in cbytes=${cbytes}`);
|
|
159
|
+
}
|
|
160
|
+
const shuffle = (flags & FLAG_SHUFFLE) !== 0 && typesize > 1;
|
|
161
|
+
const dontSplit = (flags & FLAG_DONT_SPLIT) !== 0;
|
|
162
|
+
// Never larger than the output: blocksize <= maxBytes, and a block never exceeds nbytes.
|
|
163
|
+
const scratch = shuffle ? new Uint8Array(Math.min(blocksize, nbytes)) : null;
|
|
164
|
+
for (let b = 0; b < nblocks; b++) {
|
|
165
|
+
const bstart = view.getInt32(HEADER_SIZE + 4 * b, true);
|
|
166
|
+
if (bstart < tableEnd || bstart + 4 > cbytes) {
|
|
167
|
+
throw new VdbFormatError(`blosc block-start[${b}]=${bstart} is outside [${tableEnd}, ${cbytes - 4}]`);
|
|
168
|
+
}
|
|
169
|
+
const leftover = b === nblocks - 1 && nbytes % blocksize !== 0;
|
|
170
|
+
const bsize = leftover ? nbytes % blocksize : blocksize;
|
|
171
|
+
// c-blosc blosc_d: split only if the frame allows it, typesize <= MAX_SPLITS (16),
|
|
172
|
+
// the block holds >= MIN_BUFFERSIZE (128) elements, and it is not the leftover block.
|
|
173
|
+
// Frames from before the dont-split flag (c-blosc < 1.14) follow the same rule.
|
|
174
|
+
const nsplits = !dontSplit && typesize <= MAX_SPLITS && Math.floor(bsize / typesize) >= MIN_BUFFERSIZE && !leftover
|
|
175
|
+
? typesize
|
|
176
|
+
: 1;
|
|
177
|
+
const neblock = bsize / nsplits;
|
|
178
|
+
if (!Number.isInteger(neblock)) {
|
|
179
|
+
throw new VdbFormatError(`blosc block ${b} of ${bsize} bytes does not divide into ${nsplits} splits`);
|
|
180
|
+
}
|
|
181
|
+
const dest = out.subarray(b * blocksize, b * blocksize + bsize);
|
|
182
|
+
const target = scratch ? scratch.subarray(0, bsize) : dest;
|
|
183
|
+
let p = bstart;
|
|
184
|
+
for (let s = 0; s < nsplits; s++) {
|
|
185
|
+
if (p + 4 > cbytes)
|
|
186
|
+
throw new VdbFormatError(`blosc block ${b} stream ${s} size field is outside cbytes=${cbytes}`);
|
|
187
|
+
const csize = view.getInt32(p, true);
|
|
188
|
+
p += 4;
|
|
189
|
+
if (csize < 0 || csize > cbytes - p) {
|
|
190
|
+
throw new VdbFormatError(`blosc stream size ${csize} (block ${b}, stream ${s}) runs past cbytes=${cbytes}`);
|
|
191
|
+
}
|
|
192
|
+
const src = frame.subarray(p, p + csize);
|
|
193
|
+
const part = target.subarray(s * neblock, (s + 1) * neblock);
|
|
194
|
+
if (csize === neblock) {
|
|
195
|
+
part.set(src);
|
|
196
|
+
}
|
|
197
|
+
else if (codec === CODEC_LZ4 || codec === CODEC_BLOSCLZ) {
|
|
198
|
+
const written = codec === CODEC_LZ4 ? decompressLz4Block(src, part) : decompressBloscLzBlock(src, part);
|
|
199
|
+
if (written !== neblock) {
|
|
200
|
+
throw new VdbFormatError(`${CODEC_NAMES[codec]} stream decoded to ${written} bytes, expected ${neblock}`);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
const inflated = inflateZlib(src, neblock);
|
|
205
|
+
if (inflated.length !== neblock) {
|
|
206
|
+
throw new VdbFormatError(`zlib stream decoded to ${inflated.length} bytes, expected ${neblock}`);
|
|
207
|
+
}
|
|
208
|
+
part.set(inflated);
|
|
209
|
+
}
|
|
210
|
+
p += csize;
|
|
211
|
+
}
|
|
212
|
+
if (scratch)
|
|
213
|
+
unshuffle(scratch.subarray(0, bsize), dest, typesize);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Reverses Blosc's byte shuffle: the shuffled block stores byte `i` of every
|
|
218
|
+
* element together (`src[i * count + j]` is byte `i` of element `j`); trailing
|
|
219
|
+
* bytes that do not fill a whole element are stored unshuffled at the end.
|
|
220
|
+
*/
|
|
221
|
+
export function unshuffle(src, dest, typesize) {
|
|
222
|
+
const count = Math.floor(src.length / typesize);
|
|
223
|
+
for (let j = 0; j < count; j++) {
|
|
224
|
+
for (let i = 0; i < typesize; i++)
|
|
225
|
+
dest[j * typesize + i] = src[i * count + j];
|
|
226
|
+
}
|
|
227
|
+
const tail = count * typesize;
|
|
228
|
+
dest.set(src.subarray(tail), tail);
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Decodes one raw LZ4 block (no frame header) into `dest`, returning the
|
|
232
|
+
* number of bytes written. Each sequence is a token (high nibble literal
|
|
233
|
+
* length, low nibble match length - 4, 15 meaning "more bytes follow, each
|
|
234
|
+
* added, until one is < 255"), the literals, then a 2-byte little-endian
|
|
235
|
+
* match offset and the match; the last sequence carries literals only.
|
|
236
|
+
*/
|
|
237
|
+
export function decompressLz4Block(src, dest) {
|
|
238
|
+
let ip = 0;
|
|
239
|
+
let op = 0;
|
|
240
|
+
const end = src.length;
|
|
241
|
+
while (ip < end) {
|
|
242
|
+
const token = src[ip++];
|
|
243
|
+
let litLen = token >>> 4;
|
|
244
|
+
if (litLen === 15) {
|
|
245
|
+
let byte;
|
|
246
|
+
do {
|
|
247
|
+
if (ip >= end)
|
|
248
|
+
throw new VdbFormatError("LZ4 literal length runs past the input");
|
|
249
|
+
byte = src[ip++];
|
|
250
|
+
litLen += byte;
|
|
251
|
+
} while (byte === 255);
|
|
252
|
+
}
|
|
253
|
+
if (ip + litLen > end || op + litLen > dest.length) {
|
|
254
|
+
throw new VdbFormatError("LZ4 literals run past the input or output");
|
|
255
|
+
}
|
|
256
|
+
dest.set(src.subarray(ip, ip + litLen), op);
|
|
257
|
+
ip += litLen;
|
|
258
|
+
op += litLen;
|
|
259
|
+
if (ip === end)
|
|
260
|
+
break; // last sequence: literals only
|
|
261
|
+
if (ip + 2 > end)
|
|
262
|
+
throw new VdbFormatError("LZ4 match offset is truncated");
|
|
263
|
+
const offset = src[ip] | (src[ip + 1] << 8);
|
|
264
|
+
ip += 2;
|
|
265
|
+
if (offset === 0 || offset > op)
|
|
266
|
+
throw new VdbFormatError(`LZ4 match offset ${offset} is out of range`);
|
|
267
|
+
let matchLen = token & 0xf;
|
|
268
|
+
if (matchLen === 15) {
|
|
269
|
+
let byte;
|
|
270
|
+
do {
|
|
271
|
+
if (ip >= end)
|
|
272
|
+
throw new VdbFormatError("LZ4 match length runs past the input");
|
|
273
|
+
byte = src[ip++];
|
|
274
|
+
matchLen += byte;
|
|
275
|
+
} while (byte === 255);
|
|
276
|
+
}
|
|
277
|
+
matchLen += 4;
|
|
278
|
+
if (op + matchLen > dest.length)
|
|
279
|
+
throw new VdbFormatError("LZ4 match runs past the output");
|
|
280
|
+
// Byte-by-byte: a match may overlap the bytes it is producing (offset < length).
|
|
281
|
+
let from = op - offset;
|
|
282
|
+
for (let k = 0; k < matchLen; k++)
|
|
283
|
+
dest[op++] = dest[from++];
|
|
284
|
+
}
|
|
285
|
+
return op;
|
|
286
|
+
}
|
|
287
|
+
//# sourceMappingURL=blosc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AACjE,MAAM,aAAa,GAAG,CAAC,CAAC;AACxB,MAAM,SAAS,GAAG,CAAC,CAAC;AACpB,MAAM,UAAU,GAAG,CAAC,CAAC;AACrB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B 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"]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* blosclz.ts — the BloscLZ block decoder, for Blosc1 frames whose codec is BloscLZ (K7.C).
|
|
3
|
+
*
|
|
4
|
+
* NVIDIA Warp writes `.nvdb` grids with python-blosc's defaults (BloscLZ), and NanoVDB 14 reads them
|
|
5
|
+
* (OpenVDB v14.0.0 CHANGES: "Read BloscLZ-compressed .nvdb files written by Warp"). The `.vdb` writers
|
|
6
|
+
* use LZ4; this decoder is read-only, like OpenVDB's.
|
|
7
|
+
*
|
|
8
|
+
* Ported from the decoder OpenVDB v14.0.0 vendors (`ext/blosc/openvdb/ext/blosc/blosclz.c`, "Decoder
|
|
9
|
+
* extracted from c-blosc v1.21.6 (BloscLZ 2.5.1)", bounds checked before any read or write), which is
|
|
10
|
+
* BSD-3-Clause and based on FastLZ (MIT):
|
|
11
|
+
*
|
|
12
|
+
* Blosc - Blocked Shuffling and Compression Library
|
|
13
|
+
* Copyright (c) 2009-2018 Francesc Alted <francesc@blosc.org>
|
|
14
|
+
* Copyright (c) 2019-present Blosc Development Team <blosc@blosc.org>
|
|
15
|
+
* License: BSD 3-Clause (see THIRD_PARTY_NOTICES.md)
|
|
16
|
+
*
|
|
17
|
+
* FastLZ - Byte-aligned LZ77 compression library
|
|
18
|
+
* Copyright (C) 2005-2020 Ariya Hidayat <ariya.hidayat@gmail.com>
|
|
19
|
+
* License: MIT (see THIRD_PARTY_NOTICES.md)
|
|
20
|
+
*
|
|
21
|
+
* Stream format: the first byte's low 5 bits are a literal run (`ctrl & 31`). Each later control byte
|
|
22
|
+
* is a literal run of `ctrl + 1` bytes when `ctrl < 32`, else a match: length `(ctrl >> 5) + 2`
|
|
23
|
+
* (`ctrl >> 5 == 7` adds following bytes until one is not 255), distance `((ctrl & 31) << 8) + next
|
|
24
|
+
* byte + 1`, and the all-ones 13-bit distance (8191) escapes to a 16-bit big-endian distance + 8191.
|
|
25
|
+
* Every failure the C decoder reports by returning 0 throws a `VdbFormatError` here. DIVERGES V68:
|
|
26
|
+
* same behaviour; the C code's 8-byte wild copy becomes a byte loop.
|
|
27
|
+
*/
|
|
28
|
+
/**
|
|
29
|
+
* Decodes one BloscLZ stream (one Blosc split) into `dest`, returning the bytes written. Never reads
|
|
30
|
+
* past `src` or writes past `dest`. As in c-blosc, a stream that ends right after a match header stops
|
|
31
|
+
* there without copying that match (encoders always end on literals).
|
|
32
|
+
*/
|
|
33
|
+
export declare function decompressBloscLzBlock(src: Uint8Array, dest: Uint8Array): number;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* blosclz.ts — the BloscLZ block decoder, for Blosc1 frames whose codec is BloscLZ (K7.C).
|
|
3
|
+
*
|
|
4
|
+
* NVIDIA Warp writes `.nvdb` grids with python-blosc's defaults (BloscLZ), and NanoVDB 14 reads them
|
|
5
|
+
* (OpenVDB v14.0.0 CHANGES: "Read BloscLZ-compressed .nvdb files written by Warp"). The `.vdb` writers
|
|
6
|
+
* use LZ4; this decoder is read-only, like OpenVDB's.
|
|
7
|
+
*
|
|
8
|
+
* Ported from the decoder OpenVDB v14.0.0 vendors (`ext/blosc/openvdb/ext/blosc/blosclz.c`, "Decoder
|
|
9
|
+
* extracted from c-blosc v1.21.6 (BloscLZ 2.5.1)", bounds checked before any read or write), which is
|
|
10
|
+
* BSD-3-Clause and based on FastLZ (MIT):
|
|
11
|
+
*
|
|
12
|
+
* Blosc - Blocked Shuffling and Compression Library
|
|
13
|
+
* Copyright (c) 2009-2018 Francesc Alted <francesc@blosc.org>
|
|
14
|
+
* Copyright (c) 2019-present Blosc Development Team <blosc@blosc.org>
|
|
15
|
+
* License: BSD 3-Clause (see THIRD_PARTY_NOTICES.md)
|
|
16
|
+
*
|
|
17
|
+
* FastLZ - Byte-aligned LZ77 compression library
|
|
18
|
+
* Copyright (C) 2005-2020 Ariya Hidayat <ariya.hidayat@gmail.com>
|
|
19
|
+
* License: MIT (see THIRD_PARTY_NOTICES.md)
|
|
20
|
+
*
|
|
21
|
+
* Stream format: the first byte's low 5 bits are a literal run (`ctrl & 31`). Each later control byte
|
|
22
|
+
* is a literal run of `ctrl + 1` bytes when `ctrl < 32`, else a match: length `(ctrl >> 5) + 2`
|
|
23
|
+
* (`ctrl >> 5 == 7` adds following bytes until one is not 255), distance `((ctrl & 31) << 8) + next
|
|
24
|
+
* byte + 1`, and the all-ones 13-bit distance (8191) escapes to a 16-bit big-endian distance + 8191.
|
|
25
|
+
* Every failure the C decoder reports by returning 0 throws a `VdbFormatError` here. DIVERGES V68:
|
|
26
|
+
* same behaviour; the C code's 8-byte wild copy becomes a byte loop.
|
|
27
|
+
*/
|
|
28
|
+
import { VdbFormatError } from "./errors.js";
|
|
29
|
+
/** BloscLZ's longest 13-bit match distance (`MAX_DISTANCE`). */
|
|
30
|
+
const MAX_DISTANCE = 8191;
|
|
31
|
+
function fail(why) {
|
|
32
|
+
throw new VdbFormatError(`BloscLZ stream ${why}`);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Decodes one BloscLZ stream (one Blosc split) into `dest`, returning the bytes written. Never reads
|
|
36
|
+
* past `src` or writes past `dest`. As in c-blosc, a stream that ends right after a match header stops
|
|
37
|
+
* there without copying that match (encoders always end on literals).
|
|
38
|
+
*/
|
|
39
|
+
export function decompressBloscLzBlock(src, dest) {
|
|
40
|
+
const ipLimit = src.length;
|
|
41
|
+
const opLimit = dest.length;
|
|
42
|
+
if (ipLimit <= 0 || opLimit <= 0)
|
|
43
|
+
fail("is empty");
|
|
44
|
+
let ip = 0;
|
|
45
|
+
let op = 0;
|
|
46
|
+
let ctrl = src[ip++] & 31;
|
|
47
|
+
for (;;) {
|
|
48
|
+
if (ctrl >= 32) {
|
|
49
|
+
// Match.
|
|
50
|
+
let len = (ctrl >> 5) - 1;
|
|
51
|
+
let ofs = (ctrl & 31) << 8;
|
|
52
|
+
let code;
|
|
53
|
+
if (len === 7 - 1) {
|
|
54
|
+
do {
|
|
55
|
+
if (ipLimit - ip < 2)
|
|
56
|
+
fail("match length runs past the input");
|
|
57
|
+
code = src[ip++];
|
|
58
|
+
if (opLimit - op < len + code + 3)
|
|
59
|
+
fail("match runs past the output");
|
|
60
|
+
len += code;
|
|
61
|
+
} while (code === 255);
|
|
62
|
+
}
|
|
63
|
+
else if (ipLimit - ip < 2) {
|
|
64
|
+
fail("match distance is truncated");
|
|
65
|
+
}
|
|
66
|
+
code = src[ip++];
|
|
67
|
+
len += 3;
|
|
68
|
+
ofs += code;
|
|
69
|
+
// 16-bit distance escape.
|
|
70
|
+
if (code === 255 && ofs === (31 << 8) + 255) {
|
|
71
|
+
if (ipLimit - ip < 2)
|
|
72
|
+
fail("16-bit match distance is truncated");
|
|
73
|
+
ofs = (src[ip] << 8) + src[ip + 1] + MAX_DISTANCE;
|
|
74
|
+
ip += 2;
|
|
75
|
+
}
|
|
76
|
+
if (len > opLimit - op)
|
|
77
|
+
fail("match runs past the output");
|
|
78
|
+
if (ofs >= op)
|
|
79
|
+
fail(`match distance ${ofs + 1} reaches before the start of the output (at ${op})`);
|
|
80
|
+
if (ip >= ipLimit)
|
|
81
|
+
break;
|
|
82
|
+
ctrl = src[ip++];
|
|
83
|
+
let ref = op - ofs - 1;
|
|
84
|
+
if (ofs === 0) {
|
|
85
|
+
// A run of the previous byte.
|
|
86
|
+
dest.fill(dest[ref], op, op + len);
|
|
87
|
+
op += len;
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
// Byte by byte: the match may overlap the bytes it produces.
|
|
91
|
+
for (; len > 0; --len)
|
|
92
|
+
dest[op++] = dest[ref++];
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
// Literal run.
|
|
97
|
+
ctrl++;
|
|
98
|
+
if (ctrl > opLimit - op)
|
|
99
|
+
fail("literal run runs past the output");
|
|
100
|
+
if (ctrl > ipLimit - ip)
|
|
101
|
+
fail("literal run runs past the input");
|
|
102
|
+
dest.set(src.subarray(ip, ip + ctrl), op);
|
|
103
|
+
op += ctrl;
|
|
104
|
+
ip += ctrl;
|
|
105
|
+
if (ip >= ipLimit)
|
|
106
|
+
break;
|
|
107
|
+
ctrl = src[ip++];
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return op;
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=blosclz.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blosclz.js","sourceRoot":"","sources":["../../../src/tools/vdb/blosclz.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,gEAAgE;AAChE,MAAM,YAAY,GAAG,IAAI,CAAC;AAE1B,SAAS,IAAI,CAAC,GAAW;IACvB,MAAM,IAAI,cAAc,CAAC,kBAAkB,GAAG,EAAE,CAAC,CAAC;AACpD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,sBAAsB,CAAC,GAAe,EAAE,IAAgB;IACtE,MAAM,OAAO,GAAG,GAAG,CAAC,MAAM,CAAC;IAC3B,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC;IAC5B,IAAI,OAAO,IAAI,CAAC,IAAI,OAAO,I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,EAAE,CAAC,CAAC;YAC1C,EAAE,IAAI,IAAI,CAAC;YACX,EAAE,IAAI,IAAI,CAAC;YACX,IAAI,EAAE,IAAI,OAAO;gBAAE,MAAM;YACzB,IAAI,GAAG,GAAG,CAAC,EAAE,EAAE,CAAE,CAAC;QACpB,CAAC;IACH,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC","sourcesContent":["/**\n * blosclz.ts — the BloscLZ block decoder, for Blosc1 frames whose codec is BloscLZ (K7.C).\n *\n * NVIDIA Warp writes `.nvdb` grids with python-blosc's defaults (BloscLZ), and NanoVDB 14 reads them\n * (OpenVDB v14.0.0 CHANGES: \"Read BloscLZ-compressed .nvdb files written by Warp\"). The `.vdb` writers\n * use LZ4; this decoder is read-only, like OpenVDB's.\n *\n * Ported from the decoder OpenVDB v14.0.0 vendors (`ext/blosc/openvdb/ext/blosc/blosclz.c`, \"Decoder\n * extracted from c-blosc v1.21.6 (BloscLZ 2.5.1)\", bounds checked before any read or write), which is\n * BSD-3-Clause and based on FastLZ (MIT):\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 * FastLZ - Byte-aligned LZ77 compression library\n * Copyright (C) 2005-2020 Ariya Hidayat <ariya.hidayat@gmail.com>\n * License: MIT (see THIRD_PARTY_NOTICES.md)\n *\n * Stream format: the first byte's low 5 bits are a literal run (`ctrl & 31`). Each later control byte\n * is a literal run of `ctrl + 1` bytes when `ctrl < 32`, else a match: length `(ctrl >> 5) + 2`\n * (`ctrl >> 5 == 7` adds following bytes until one is not 255), distance `((ctrl & 31) << 8) + next\n * byte + 1`, and the all-ones 13-bit distance (8191) escapes to a 16-bit big-endian distance + 8191.\n * Every failure the C decoder reports by returning 0 throws a `VdbFormatError` here. DIVERGES V68:\n * same behaviour; the C code's 8-byte wild copy becomes a byte loop.\n */\n\nimport { VdbFormatError } from \"./errors.js\";\n\n/** BloscLZ's longest 13-bit match distance (`MAX_DISTANCE`). */\nconst MAX_DISTANCE = 8191;\n\nfunction fail(why: string): never {\n throw new VdbFormatError(`BloscLZ stream ${why}`);\n}\n\n/**\n * Decodes one BloscLZ stream (one Blosc split) into `dest`, returning the bytes written. Never reads\n * past `src` or writes past `dest`. As in c-blosc, a stream that ends right after a match header stops\n * there without copying that match (encoders always end on literals).\n */\nexport function decompressBloscLzBlock(src: Uint8Array, dest: Uint8Array): number {\n const ipLimit = src.length;\n const opLimit = dest.length;\n if (ipLimit <= 0 || opLimit <= 0) fail(\"is empty\");\n let ip = 0;\n let op = 0;\n let ctrl = src[ip++]! & 31;\n\n for (;;) {\n if (ctrl >= 32) {\n // Match.\n let len = (ctrl >> 5) - 1;\n let ofs = (ctrl & 31) << 8;\n let code: number;\n if (len === 7 - 1) {\n do {\n if (ipLimit - ip < 2) fail(\"match length runs past the input\");\n code = src[ip++]!;\n if (opLimit - op < len + code + 3) fail(\"match runs past the output\");\n len += code;\n } while (code === 255);\n } else if (ipLimit - ip < 2) {\n fail(\"match distance is truncated\");\n }\n code = src[ip++]!;\n len += 3;\n ofs += code;\n // 16-bit distance escape.\n if (code === 255 && ofs === (31 << 8) + 255) {\n if (ipLimit - ip < 2) fail(\"16-bit match distance is truncated\");\n ofs = (src[ip]! << 8) + src[ip + 1]! + MAX_DISTANCE;\n ip += 2;\n }\n if (len > opLimit - op) fail(\"match runs past the output\");\n if (ofs >= op) fail(`match distance ${ofs + 1} reaches before the start of the output (at ${op})`);\n if (ip >= ipLimit) break;\n ctrl = src[ip++]!;\n\n let ref = op - ofs - 1;\n if (ofs === 0) {\n // A run of the previous byte.\n dest.fill(dest[ref]!, op, op + len);\n op += len;\n } else {\n // Byte by byte: the match may overlap the bytes it produces.\n for (; len > 0; --len) dest[op++] = dest[ref++]!;\n }\n } else {\n // Literal run.\n ctrl++;\n if (ctrl > opLimit - op) fail(\"literal run runs past the output\");\n if (ctrl > ipLimit - ip) fail(\"literal run runs past the input\");\n dest.set(src.subarray(ip, ip + ctrl), op);\n op += ctrl;\n ip += ctrl;\n if (ip >= ipLimit) break;\n ctrl = src[ip++]!;\n }\n }\n return op;\n}\n"]}
|
|
@@ -0,0 +1,50 @@
|
|
|
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 bytes (no terminator). OpenVDB writes `std::string` bytes as they are, so
|
|
7
|
+
* names and string metadata are UTF-8 in practice; {@link ByteReader.string} decodes UTF-8 and
|
|
8
|
+
* falls back to latin1 for bytes that are not valid UTF-8 (K7.17, his VDB-173).
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* UTF-8 when the bytes are valid UTF-8, else latin1 (one char per byte, never fails). ASCII
|
|
12
|
+
* decodes the same either way. A hostile length costs one native decode pass that stops at
|
|
13
|
+
* the first invalid byte, plus the chunked latin1 pass: linear, no per-byte JS loop (K7.17).
|
|
14
|
+
*/
|
|
15
|
+
export declare function decodeVdbString(raw: Uint8Array): string;
|
|
16
|
+
export declare class ByteReader {
|
|
17
|
+
private readonly view;
|
|
18
|
+
private readonly bytes;
|
|
19
|
+
pos: number;
|
|
20
|
+
constructor(buffer: ArrayBuffer);
|
|
21
|
+
get length(): number;
|
|
22
|
+
private need;
|
|
23
|
+
seek(pos: number): void;
|
|
24
|
+
skip(count: number): void;
|
|
25
|
+
u8(): number;
|
|
26
|
+
bool(): boolean;
|
|
27
|
+
u16(): number;
|
|
28
|
+
i32(): number;
|
|
29
|
+
u32(): number;
|
|
30
|
+
u64(): bigint;
|
|
31
|
+
/** u64 narrowed to `number` — safe for stream offsets/counts on real files
|
|
32
|
+
* (well under 2^53), throws rather than silently truncating otherwise. */
|
|
33
|
+
u64AsNumber(): number;
|
|
34
|
+
f32(): number;
|
|
35
|
+
f64(): number;
|
|
36
|
+
f16AsF32(halfToFloat: (h: number) => number): number;
|
|
37
|
+
bytes_(count: number): Uint8Array;
|
|
38
|
+
/** u32 length prefix + that many bytes (VDB's `readString`), as UTF-8 with a latin1 fallback. */
|
|
39
|
+
string(): string;
|
|
40
|
+
/** Fixed-length string (no length prefix): `string` metadata values, as UTF-8 with a latin1 fallback. */
|
|
41
|
+
textOf(len: number): string;
|
|
42
|
+
/** Fixed-length ASCII string (no length prefix), one char per byte: the UUID. */
|
|
43
|
+
fixedString(len: number): string;
|
|
44
|
+
vec3i(): [number, number, number];
|
|
45
|
+
vec3d(): [number, number, number];
|
|
46
|
+
/** Reads `bitCount` mask bits as `bitCount/32` little-endian u32 words.
|
|
47
|
+
* (On disk these are u64 LE words; splitting each into two u32 LE words
|
|
48
|
+
* preserves bit-for-bit ordinal position — see bit-utils.ts.) */
|
|
49
|
+
maskWords(bitCount: number): Uint32Array;
|
|
50
|
+
}
|