|
@@ -69,33 +69,12 @@ export async function readDsn6Header(file: FileHandle): Promise<{ header: Dsn6He
|
|
|
return { header, littleEndian }
|
|
|
}
|
|
|
|
|
|
-async function parseInternal(file: FileHandle, size: number, ctx: RuntimeContext): Promise<Dsn6File> {
|
|
|
- await ctx.update({ message: 'Parsing DSN6/BRIX file...' });
|
|
|
-
|
|
|
- const { header, littleEndian } = await readDsn6Header(file)
|
|
|
- const { divisor, summand } = header
|
|
|
-
|
|
|
- const { buffer, bytesRead } = await file.readBuffer(dsn6HeaderSize, size - dsn6HeaderSize)
|
|
|
+export async function parseDsn6Values(header: Dsn6Header, source: Uint8Array, target: Float32Array) {
|
|
|
+ const { divisor, summand, xExtent, yExtent, zExtent } = header
|
|
|
|
|
|
- const xBlocks = Math.ceil(header.xExtent / 8)
|
|
|
- const yBlocks = Math.ceil(header.yExtent / 8)
|
|
|
- const zBlocks = Math.ceil(header.zExtent / 8)
|
|
|
- const valueCount = header.xExtent * header.yExtent * header.zExtent
|
|
|
-
|
|
|
- const count = xBlocks * 8 * yBlocks * 8 * zBlocks * 8
|
|
|
- const elementByteSize = 1
|
|
|
- const byteCount = count * elementByteSize
|
|
|
-
|
|
|
- if (byteCount !== bytesRead) {
|
|
|
- console.warn(`byteCount ${byteCount} and bytesRead ${bytesRead} differ`)
|
|
|
- }
|
|
|
-
|
|
|
- const values = new Float32Array(valueCount)
|
|
|
-
|
|
|
- if (!littleEndian) {
|
|
|
- // even though the values are one byte they need to be swapped like they are 2
|
|
|
- SimpleBuffer.flipByteOrderInPlace2(buffer.buffer)
|
|
|
- }
|
|
|
+ const xBlocks = Math.ceil(xExtent / 8)
|
|
|
+ const yBlocks = Math.ceil(yExtent / 8)
|
|
|
+ const zBlocks = Math.ceil(zExtent / 8)
|
|
|
|
|
|
let offset = 0
|
|
|
// loop over blocks
|
|
@@ -110,9 +89,9 @@ async function parseInternal(file: FileHandle, size: number, ctx: RuntimeContext
|
|
|
for (let i = 0; i < 8; ++i) {
|
|
|
const x = 8 * xx + i
|
|
|
// check if remaining slice-part contains values
|
|
|
- if (x < header.xExtent && y < header.yExtent && z < header.zExtent) {
|
|
|
- const idx = ((((x * header.yExtent) + y) * header.zExtent) + z)
|
|
|
- values[idx] = (buffer[offset] - summand) / divisor
|
|
|
+ if (x < xExtent && y < yExtent && z < zExtent) {
|
|
|
+ const idx = ((((x * yExtent) + y) * zExtent) + z)
|
|
|
+ target[idx] = (source[offset] - summand) / divisor
|
|
|
++offset
|
|
|
} else {
|
|
|
offset += 8 - i
|
|
@@ -124,6 +103,37 @@ async function parseInternal(file: FileHandle, size: number, ctx: RuntimeContext
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+}
|
|
|
+
|
|
|
+async function parseInternal(file: FileHandle, size: number, ctx: RuntimeContext): Promise<Dsn6File> {
|
|
|
+ await ctx.update({ message: 'Parsing DSN6/BRIX file...' });
|
|
|
+
|
|
|
+ const { header, littleEndian } = await readDsn6Header(file)
|
|
|
+ const { xExtent, yExtent, zExtent } = header
|
|
|
+
|
|
|
+ const { buffer, bytesRead } = await file.readBuffer(dsn6HeaderSize, size - dsn6HeaderSize)
|
|
|
+
|
|
|
+ const xBlocks = Math.ceil(xExtent / 8)
|
|
|
+ const yBlocks = Math.ceil(yExtent / 8)
|
|
|
+ const zBlocks = Math.ceil(zExtent / 8)
|
|
|
+ const valueCount = xExtent * yExtent * zExtent
|
|
|
+
|
|
|
+ const count = xBlocks * 8 * yBlocks * 8 * zBlocks * 8
|
|
|
+ const elementByteSize = 1
|
|
|
+ const byteCount = count * elementByteSize
|
|
|
+
|
|
|
+ if (byteCount !== bytesRead) {
|
|
|
+ console.warn(`byteCount ${byteCount} and bytesRead ${bytesRead} differ`)
|
|
|
+ }
|
|
|
+
|
|
|
+ const values = new Float32Array(valueCount)
|
|
|
+
|
|
|
+ if (!littleEndian) {
|
|
|
+ // even though the values are one byte they need to be swapped like they are 2
|
|
|
+ SimpleBuffer.flipByteOrderInPlace2(buffer.buffer)
|
|
|
+ }
|
|
|
+
|
|
|
+ await parseDsn6Values(header, buffer, values)
|
|
|
|
|
|
const result: Dsn6File = { header, values };
|
|
|
return result;
|