Skip to content

Commit

Permalink
feat: add 16 bit data type scale under a decode flag (#501)
Browse files Browse the repository at this point in the history
* feat: add 16 bit data type scale under a decode flag

* fix linter
  • Loading branch information
sedghi committed Dec 21, 2022
1 parent 28fec2f commit 1b47073
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
7 changes: 5 additions & 2 deletions packages/dicomImageLoader/src/imageLoader/createImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ function createImage(imageId, pixelData, transferSyntax, options = {}) {
);

const { decodeConfig } = getOptions();
const { convertFloatPixelDataToInt } = decodeConfig;
const { convertFloatPixelDataToInt, use16BitDataType } = decodeConfig;

return new Promise((resolve, reject) => {
// eslint-disable-next-line complexity
Expand Down Expand Up @@ -173,9 +173,12 @@ function createImage(imageId, pixelData, transferSyntax, options = {}) {
case 'Uint8Array':
TypedArrayConstructor = Uint8Array;
break;
case 'Uint16Array':
case use16BitDataType && 'Uint16Array':
TypedArrayConstructor = Uint16Array;
break;
case use16BitDataType && 'Int16Array':
TypedArrayConstructor = Int16Array;
break;
case 'Float32Array':
TypedArrayConstructor = Float32Array;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ let options = {
strict: false,
decodeConfig: {
convertFloatPixelDataToInt: true,
use16BitDataType: false,
},
};

Expand Down
13 changes: 10 additions & 3 deletions packages/dicomImageLoader/src/shared/decodeImageFrame.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,18 @@ function decodeImageFrame(

decodePromise
.then((imageFrame) => {
callbackFn(postProcessDecodedPixels(imageFrame, options, start));
callbackFn(
postProcessDecodedPixels(imageFrame, options, start, decodeConfig)
);
})
.catch((err) => {
throw err;
});
}

function postProcessDecodedPixels(imageFrame, options, start) {
function postProcessDecodedPixels(imageFrame, options, start, decodeConfig) {
const { use16BitDataType } = decodeConfig;

const shouldShift =
imageFrame.pixelRepresentation !== undefined &&
imageFrame.pixelRepresentation === 1;
Expand Down Expand Up @@ -191,9 +195,12 @@ function postProcessDecodedPixels(imageFrame, options, start) {
case 'Uint8Array':
TypedArrayConstructor = Uint8Array;
break;
case 'Uint16Array':
case use16BitDataType && 'Uint16Array':
TypedArrayConstructor = Uint16Array;
break;
case use16BitDataType && 'Int16Array':
TypedArrayConstructor = Int16Array;
break;
case 'Float32Array':
TypedArrayConstructor = Float32Array;
break;
Expand Down

0 comments on commit 1b47073

Please sign in to comment.