Skip to content

Commit

Permalink
fix: rework decode config to be passed to the workers (cornerstonejs#503
Browse files Browse the repository at this point in the history
)
  • Loading branch information
sedghi committed Dec 21, 2022
1 parent ed4de89 commit e4e2be3
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 25 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 @@ -133,15 +133,18 @@ function createImage(imageId, pixelData, transferSyntax, options = {}) {
};
}
}

const { decodeConfig } = getOptions();

const decodePromise = decodeImageFrame(
imageFrame,
transferSyntax,
pixelData,
canvas,
options
options,
decodeConfig
);

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

return new Promise((resolve, reject) => {
Expand Down
124 changes: 108 additions & 16 deletions packages/dicomImageLoader/src/imageLoader/decodeImageFrame.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ import { inflateRaw } from 'pako/lib/inflate.js';

window.pako = { inflateRaw };

function processDecodeTask(imageFrame, transferSyntax, pixelData, options) {
function processDecodeTask(
imageFrame,
transferSyntax,
pixelData,
options,
decodeConfig
) {
const priority = options.priority || undefined;
const transferList = options.transferPixelData
? [pixelData.buffer]
Expand All @@ -21,6 +27,7 @@ function processDecodeTask(imageFrame, transferSyntax, pixelData, options) {
transferSyntax,
pixelData,
options,
decodeConfig,
},
priority,
transferList
Expand All @@ -32,24 +39,55 @@ function decodeImageFrame(
transferSyntax,
pixelData,
canvas,
options = {}
options = {},
decodeConfig
) {
switch (transferSyntax) {
case '1.2.840.10008.1.2':
// Implicit VR Little Endian
return processDecodeTask(imageFrame, transferSyntax, pixelData, options);
return processDecodeTask(
imageFrame,
transferSyntax,
pixelData,
options,
decodeConfig
);
case '1.2.840.10008.1.2.1':
// Explicit VR Little Endian
return processDecodeTask(imageFrame, transferSyntax, pixelData, options);
return processDecodeTask(
imageFrame,
transferSyntax,
pixelData,
options,
decodeConfig
);
case '1.2.840.10008.1.2.2':
// Explicit VR Big Endian (retired)
return processDecodeTask(imageFrame, transferSyntax, pixelData, options);
return processDecodeTask(
imageFrame,
transferSyntax,
pixelData,
options,
decodeConfig
);
case '1.2.840.10008.1.2.1.99':
// Deflate transfer syntax (deflated by dicomParser)
return processDecodeTask(imageFrame, transferSyntax, pixelData, options);
return processDecodeTask(
imageFrame,
transferSyntax,
pixelData,
options,
decodeConfig
);
case '1.2.840.10008.1.2.5':
// RLE Lossless
return processDecodeTask(imageFrame, transferSyntax, pixelData, options);
return processDecodeTask(
imageFrame,
transferSyntax,
pixelData,
options,
decodeConfig
);
case '1.2.840.10008.1.2.4.50':
// JPEG Baseline lossy process 1 (8 bit)

Expand All @@ -62,32 +100,86 @@ function decodeImageFrame(
return decodeJPEGBaseline8BitColor(imageFrame, pixelData, canvas);
}

return processDecodeTask(imageFrame, transferSyntax, pixelData, options);
return processDecodeTask(
imageFrame,
transferSyntax,
pixelData,
options,
decodeConfig
);
case '1.2.840.10008.1.2.4.51':
// JPEG Baseline lossy process 2 & 4 (12 bit)
return processDecodeTask(imageFrame, transferSyntax, pixelData, options);
return processDecodeTask(
imageFrame,
transferSyntax,
pixelData,
options,
decodeConfig
);
case '1.2.840.10008.1.2.4.57':
// JPEG Lossless, Nonhierarchical (Processes 14)
return processDecodeTask(imageFrame, transferSyntax, pixelData, options);
return processDecodeTask(
imageFrame,
transferSyntax,
pixelData,
options,
decodeConfig
);
case '1.2.840.10008.1.2.4.70':
// JPEG Lossless, Nonhierarchical (Processes 14 [Selection 1])
return processDecodeTask(imageFrame, transferSyntax, pixelData, options);
return processDecodeTask(
imageFrame,
transferSyntax,
pixelData,
options,
decodeConfig
);
case '1.2.840.10008.1.2.4.80':
// JPEG-LS Lossless Image Compression
return processDecodeTask(imageFrame, transferSyntax, pixelData, options);
return processDecodeTask(
imageFrame,
transferSyntax,
pixelData,
options,
decodeConfig
);
case '1.2.840.10008.1.2.4.81':
// JPEG-LS Lossy (Near-Lossless) Image Compression
return processDecodeTask(imageFrame, transferSyntax, pixelData, options);
return processDecodeTask(
imageFrame,
transferSyntax,
pixelData,
options,
decodeConfig
);
case '1.2.840.10008.1.2.4.90':
// JPEG 2000 Lossless
return processDecodeTask(imageFrame, transferSyntax, pixelData, options);
return processDecodeTask(
imageFrame,
transferSyntax,
pixelData,
options,
decodeConfig
);
case '1.2.840.10008.1.2.4.91':
// JPEG 2000 Lossy
return processDecodeTask(imageFrame, transferSyntax, pixelData, options);
return processDecodeTask(
imageFrame,
transferSyntax,
pixelData,
options,
decodeConfig
);

case '3.2.840.10008.1.2.4.96':
// HTJ2K
return processDecodeTask(imageFrame, transferSyntax, pixelData, options);
return processDecodeTask(
imageFrame,
transferSyntax,
pixelData,
options,
decodeConfig
);
}

/* Don't know if these work...
Expand Down
11 changes: 5 additions & 6 deletions packages/dicomImageLoader/src/shared/decodeImageFrame.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import decodeJPEGLS from './decoders/decodeJPEGLS.js';
import decodeJPEG2000 from './decoders/decodeJPEG2000.js';
import decodeHTJ2K from './decoders/decodeHTJ2K.js';
import scaleArray from './scaling/scaleArray.js';
import { getOptions } from '../imageLoader/internal/options.js';

function decodeImageFrame(
imageFrame,
Expand Down Expand Up @@ -141,17 +140,17 @@ 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) {
const {
decodeConfig: { use16BitDataType },
} = getOptions();
function postProcessDecodedPixels(imageFrame, options, start, decodeConfig) {
const { use16BitDataType } = decodeConfig || {};

const shouldShift =
imageFrame.pixelRepresentation !== undefined &&
Expand Down
4 changes: 3 additions & 1 deletion packages/dicomImageLoader/src/webWorker/decodeTask.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ function handler(data, doneCallback) {
data.data.imageFrame,
data.data.transferSyntax,
pixelData,
decodeConfig.decodeTask,
// decodeTask are webworker specific, but decodeConfig are the configs
// that are passed in from the user. We need to merge them together
Object.assign(decodeConfig.decodeTask, data.data.decodeConfig),
data.data.options,
finishedCallback
);
Expand Down

0 comments on commit e4e2be3

Please sign in to comment.