Skip to content

Commit

Permalink
fix(cornerstoneWadoImageLoader):Load the palette color from a promise
Browse files Browse the repository at this point in the history
Note there is a performance issue in this build - it wasn't introduced
by these changes, but it 5-10 times slower than earlier versions (not
sure how early to go to have it fast - was using 4.0.4
  • Loading branch information
wayfarer3130 committed Mar 7, 2022
1 parent a3b35b8 commit 8ba0b46
Show file tree
Hide file tree
Showing 5 changed files with 209 additions and 205 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
},
"dependencies": {
"@cornerstonejs/codec-charls": "^0.1.1",
"@cornerstonejs/codec-libjpeg-turbo-12bit": "^0.2.0",
"@cornerstonejs/codec-libjpeg-turbo-8bit": "^0.0.7",
"@cornerstonejs/codec-openjpeg": "^0.1.0",
"dicom-parser": "^1.8.9",
Expand Down
19 changes: 14 additions & 5 deletions src/imageLoader/colorSpaceConverters/convertPALETTECOLOR.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,21 @@ function convertLUTto8Bit(lut, shift) {
*
* @param {ImageFrame} imageFrame
* @param {Uint8ClampedArray} rgbaBuffer
* @returns {void}
* @returns {rgbaBuffer} as async function
*/
export default function (imageFrame, rgbaBuffer) {
export default async function (imageFrame, rgbaBuffer) {
const numPixels = imageFrame.columns * imageFrame.rows;
const pixelData = imageFrame.pixelData;
const rData = imageFrame.redPaletteColorLookupTableData;
const gData = imageFrame.greenPaletteColorLookupTableData;
const bData = imageFrame.bluePaletteColorLookupTableData;
const [rData, gData, bData] = await Promise.all([
imageFrame.redPaletteColorLookupTableData,
imageFrame.greenPaletteColorLookupTableData,
imageFrame.bluePaletteColorLookupTableData,
]);

if (!rData || !gData || !bData) {
throw new Error(`Palette data not found in ${imageFrame}`);
}

const len = imageFrame.redPaletteColorLookupTableData.length;

let palIndex = 0;
Expand Down Expand Up @@ -54,4 +61,6 @@ export default function (imageFrame, rgbaBuffer) {
rgbaBuffer[rgbaIndex++] = bDataCleaned[value];
rgbaBuffer[rgbaIndex++] = 255;
}

return rgbaBuffer;
}
2 changes: 1 addition & 1 deletion src/imageLoader/convertColorSpace.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default function convertColorSpace(imageFrame, imageData) {
} else if (imageFrame.photometricInterpretation === 'YBR_ICT') {
convertRGB(imageFrame, rgbaBuffer);
} else if (imageFrame.photometricInterpretation === 'PALETTE COLOR') {
convertPALETTECOLOR(imageFrame, rgbaBuffer);
return convertPALETTECOLOR(imageFrame, rgbaBuffer);
} else if (imageFrame.photometricInterpretation === 'YBR_FULL_422') {
convertYBRFull422ByPixel(imageFrame.pixelData, rgbaBuffer);
} else if (imageFrame.photometricInterpretation === 'YBR_FULL') {
Expand Down
Loading

0 comments on commit 8ba0b46

Please sign in to comment.