Skip to content

Commit

Permalink
fix: data type view after scaling (#509)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ouwen authored Feb 15, 2023
1 parent 0d3eabf commit 9cb6213
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/imageLoader/createImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,17 @@ function convertToIntPixelData(floatPixelData) {
* can transfer array buffers but not typed arrays
* @param imageFrame
*/
function setPixelDataType(imageFrame) {
function setPixelDataType(imageFrame, preScale) {
const isScaled = preScale?.scaled;
const scalingParmeters = preScale?.scalingParameters;
const rescaleSlope = scalingParmeters?.rescaleSlope;
const rescaleIntercept = scalingParmeters?.rescaleIntercept;
const isNegative = rescaleSlope < 0 || rescaleIntercept < 0;

if (imageFrame.bitsAllocated === 32) {
imageFrame.pixelData = new Float32Array(imageFrame.pixelData);
} else if (imageFrame.bitsAllocated === 16) {
if (imageFrame.pixelRepresentation === 0) {
if (imageFrame.pixelRepresentation === 0 && !(isScaled && isNegative)) {
imageFrame.pixelData = new Uint16Array(imageFrame.pixelData);
} else {
imageFrame.pixelData = new Int16Array(imageFrame.pixelData);
Expand Down Expand Up @@ -219,7 +225,7 @@ function createImage(imageId, pixelData, transferSyntax, options = {}) {
}

if (!alreadyTyped) {
setPixelDataType(imageFrame);
setPixelDataType(imageFrame, imageFrame.preScale);
}

const imagePlaneModule =
Expand Down

0 comments on commit 9cb6213

Please sign in to comment.