Skip to content

Commit

Permalink
fix: copy buffer to prevent oom in workers (#454)
Browse files Browse the repository at this point in the history
Large uncompressed multiframe data will send the full
arraybuffer in a typed view. For large uncompressed data
such as tomo these will result in OOM issues. This fix
pre-slices the typed array view so only used buffer
is sent via worker.postMessage.
  • Loading branch information
Ouwen authored Jun 14, 2023
1 parent 093db67 commit 2d947af
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/imageLoader/wadouri/getUncompressedImageFrame.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ function getUncompressedImageFrame(dataSet, frameIndex) {
}

return new Uint8Array(
dataSet.byteArray.buffer,
frameOffset,
pixelsPerFrame
dataSet.byteArray.buffer.slice(frameOffset, frameOffset + pixelsPerFrame)
);
} else if (bitsAllocated === 16) {
frameOffset = pixelDataOffset + frameIndex * pixelsPerFrame * 2;
Expand All @@ -64,9 +62,10 @@ function getUncompressedImageFrame(dataSet, frameIndex) {
}

return new Uint8Array(
dataSet.byteArray.buffer,
frameOffset,
pixelsPerFrame * 2
dataSet.byteArray.buffer.slice(
frameOffset,
frameOffset + pixelsPerFrame * 2
)
);
} else if (bitsAllocated === 1) {
frameOffset = pixelDataOffset + frameIndex * pixelsPerFrame * 0.125;
Expand All @@ -82,9 +81,10 @@ function getUncompressedImageFrame(dataSet, frameIndex) {
}

return new Uint8Array(
dataSet.byteArray.buffer,
frameOffset,
pixelsPerFrame * 4
dataSet.byteArray.buffer.slice(
frameOffset,
frameOffset + pixelsPerFrame * 4
)
);
}

Expand Down

0 comments on commit 2d947af

Please sign in to comment.