Skip to content

Commit bfdc62e

Browse files
authored
feat: add 16 bit data type scale under a decode flag (#501)
* feat: add 16 bit data type scale under a decode flag * fix linter
1 parent df47a2a commit bfdc62e

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

src/imageLoader/createImage.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ function createImage(imageId, pixelData, transferSyntax, options = {}) {
142142
);
143143

144144
const { decodeConfig } = getOptions();
145-
const { convertFloatPixelDataToInt } = decodeConfig;
145+
const { convertFloatPixelDataToInt, use16BitDataType } = decodeConfig;
146146

147147
return new Promise((resolve, reject) => {
148148
// eslint-disable-next-line complexity
@@ -173,9 +173,12 @@ function createImage(imageId, pixelData, transferSyntax, options = {}) {
173173
case 'Uint8Array':
174174
TypedArrayConstructor = Uint8Array;
175175
break;
176-
case 'Uint16Array':
176+
case use16BitDataType && 'Uint16Array':
177177
TypedArrayConstructor = Uint16Array;
178178
break;
179+
case use16BitDataType && 'Int16Array':
180+
TypedArrayConstructor = Int16Array;
181+
break;
179182
case 'Float32Array':
180183
TypedArrayConstructor = Float32Array;
181184
break;

src/imageLoader/internal/options.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ let options = {
1414
strict: false,
1515
decodeConfig: {
1616
convertFloatPixelDataToInt: true,
17+
use16BitDataType: false,
1718
},
1819
};
1920

src/shared/decodeImageFrame.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,18 @@ function decodeImageFrame(
140140

141141
decodePromise
142142
.then((imageFrame) => {
143-
callbackFn(postProcessDecodedPixels(imageFrame, options, start));
143+
callbackFn(
144+
postProcessDecodedPixels(imageFrame, options, start, decodeConfig)
145+
);
144146
})
145147
.catch((err) => {
146148
throw err;
147149
});
148150
}
149151

150-
function postProcessDecodedPixels(imageFrame, options, start) {
152+
function postProcessDecodedPixels(imageFrame, options, start, decodeConfig) {
153+
const { use16BitDataType } = decodeConfig;
154+
151155
const shouldShift =
152156
imageFrame.pixelRepresentation !== undefined &&
153157
imageFrame.pixelRepresentation === 1;
@@ -191,9 +195,12 @@ function postProcessDecodedPixels(imageFrame, options, start) {
191195
case 'Uint8Array':
192196
TypedArrayConstructor = Uint8Array;
193197
break;
194-
case 'Uint16Array':
198+
case use16BitDataType && 'Uint16Array':
195199
TypedArrayConstructor = Uint16Array;
196200
break;
201+
case use16BitDataType && 'Int16Array':
202+
TypedArrayConstructor = Int16Array;
203+
break;
197204
case 'Float32Array':
198205
TypedArrayConstructor = Float32Array;
199206
break;

0 commit comments

Comments
 (0)