Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions src/las/point-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,15 @@ export async function decompressChunk(
const LazPerf = await getLazPerf(suppliedLazPerf)
const outBuffer = new Uint8Array(pointCount * pointDataRecordLength)

const blobPointer = LazPerf._malloc(compressed.byteLength)
const dataPointer = LazPerf._malloc(pointDataRecordLength)
const decoder = new LazPerf.ChunkDecoder()
let blobPointer = 0
let dataPointer = 0
let decoder: InstanceType<typeof LazPerf.ChunkDecoder> | undefined

try {
blobPointer = LazPerf._malloc(compressed.byteLength)
dataPointer = LazPerf._malloc(pointDataRecordLength)
decoder = new LazPerf.ChunkDecoder()

LazPerf.HEAPU8.set(
new Uint8Array(
compressed.buffer,
Expand All @@ -59,7 +63,7 @@ export async function decompressChunk(
} finally {
LazPerf._free(blobPointer)
LazPerf._free(dataPointer)
decoder.delete()
decoder?.delete()
}

return outBuffer
Expand All @@ -74,10 +78,15 @@ export async function decompressFile(
const { pointCount, pointDataRecordLength } = header
const outBuffer = new Uint8Array(pointCount * pointDataRecordLength)

const blobPointer = LazPerf._malloc(file.byteLength)
const dataPointer = LazPerf._malloc(pointDataRecordLength)
const reader = new LazPerf.LASZip()
let blobPointer = 0
let dataPointer = 0
let reader: InstanceType<typeof LazPerf.LASZip> | undefined

try {
blobPointer = LazPerf._malloc(file.byteLength)
dataPointer = LazPerf._malloc(pointDataRecordLength)
reader = new LazPerf.LASZip()

LazPerf.HEAPU8.set(
new Uint8Array(file.buffer, file.byteOffset, file.byteLength),
blobPointer,
Expand All @@ -98,7 +107,9 @@ export async function decompressFile(
)
}
} finally {
reader.delete()
LazPerf._free(blobPointer)
LazPerf._free(dataPointer)
reader?.delete()
}

return outBuffer
Expand Down
Loading