Skip to content
Open
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions packages/core/src/utilities/windowLevel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ function toLowHighRange(
lower: number;
upper: number;
} {
// LINEAR formula produces lower === upper when WW <= 1 because (WW-1)
// becomes 0. Fall back to LINEAR_EXACT to avoid division by zero. See #2706.
if (windowWidth <= 1 && voiLUTFunction === VOILUTFunctionType.LINEAR) {
voiLUTFunction = VOILUTFunctionType.LINEAR_EXACT;
}

// Note: The SIGMOID function is currently treated the same as LINEAR
// because we don't have a good way to define "bounds" for it.
// Remove or statement when fixed
Expand Down
14 changes: 14 additions & 0 deletions packages/dicomImageLoader/src/decodeImageFrameWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,20 @@ function _handlePreScaleSetup(
const scalingParameters = options.preScale.scalingParameters;
_validateScalingParameters(scalingParameters);

// Force Float32Array when scaling parameters are non-integer to avoid
// getPixelDataTypeFromMinMax selecting Uint8Array (Number.isInteger(1.0)
// is true in JS, so scaled min/max can appear integer even when values
// between them are fractional). See #2706.
const hasFloatRescale = Object.values(scalingParameters).some(
(v) => typeof v === 'number' && !Number.isInteger(v)
);

if (hasFloatRescale) {
const typedArray = new Float32Array(imageFrame.pixelData.length);
typedArray.set(imageFrame.pixelData, 0);
return typedArray;
}

const scaledValues = _calculateScaledMinMax(
minBeforeScale,
maxBeforeScale,
Expand Down
6 changes: 6 additions & 0 deletions packages/dicomImageLoader/src/imageLoader/setPixelDataType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ import getPixelDataTypeFromMinMax from '../shared/getPixelDataTypeFromMinMax';
* min and max values
*/
function setPixelDataType(imageFrame) {
// Skip re-typing if already Float32Array to prevent downgrading to
// Uint8Array via getPixelDataTypeFromMinMax. See #2706.
if (imageFrame.pixelData instanceof Float32Array) {
return;
}

const minValue = imageFrame.smallestPixelValue;
const maxValue = imageFrame.largestPixelValue;

Expand Down