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
1 change: 1 addition & 0 deletions extensions/default/src/getSopClassHandlerModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ const sopClassUids = [
sopClassDictionary.RTImageStorage,
sopClassDictionary.EnhancedUSVolumeStorage,
sopClassDictionary.RTDoseStorage,
sopClassDictionary.CornealTopographyMapStorage
];

function getSopClassHandlerModule(appContextParam) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,28 @@ function _getPaletteColor(paletteColorLookupTableData, lutDescriptor) {
return undefined;
}

const arrayBufferToPaletteColorLUT = arraybuffer => {
const arrayBufferToPaletteColorLUT = (arraybuffer) => {
// Handle both ArrayBuffer and TypedArray inputs
const buffer = arraybuffer.buffer || arraybuffer;
const data = bits === 16 ? new Uint16Array(buffer) : new Uint8Array(buffer);
const lut = [];
// const data = bits === 16 ? new Uint16Array(buffer) : new Uint8Array(buffer);

const view = new DataView(buffer);
const offsetBits = bits - 8;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest isTwoByte = bits > 8


const lut = new Uint8Array(numLutEntries);

// Extract LUT values (always read as 16-bit)
for (let i = 0; i < numLutEntries; i++) {
lut[i] = data[i];
// Read 16-bit value (LUT is always 16-bit)
const lutValue16 = view.getUint16(i * 2, true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to PS3.3 C.8.17.14.1.6 Bits Allocated, Bits Stored, and High Bit
you can have either 8 or 16 bit data. Please ensure that 8 bit data is handled.


// Apply Orthanc shift logic
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be orthanc specific - either reference the DICOM standard or specify that this is the format for sop class ...

if (offsetBits >= 0) {
lut[i] = (lutValue16 >> offsetBits) & 0xff;
} else {
// If bitsPerEntry < 8, shift left
lut[i] = (lutValue16 << Math.abs(offsetBits)) & 0xff;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is a shift needed? offsetBits will be 0 for this case, so
lut[i] = lutValue16 && 0xff;
should be sufficient.

}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Palette Color Retrieval Breaks 8-bit Compatibility

The _getPaletteColor function now always reads palette data as 16-bit values, assuming the buffer is sized accordingly. This differs from the previous logic that handled both 8-bit and 16-bit data based on the bits parameter. For 8-bit palette data, this can cause buffer overruns and incorrect interpretation, impacting backward compatibility.

Fix in Cursor Fix in Web

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tunglt1810 please check this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @IbrahimCSAE ,
If you have another testcase, can you share it. So I can test this logic.

}

return lut;
Expand All @@ -48,9 +62,7 @@ function _getPaletteColor(paletteColorLookupTableData, lutDescriptor) {

if (paletteColorLookupTableData.InlineBinary) {
try {
const uint8Array = Uint8Array.from(atob(paletteColorLookupTableData.InlineBinary), c =>
c.charCodeAt(0)
);
const uint8Array = Uint8Array.from(atob(paletteColorLookupTableData.InlineBinary), (c) => c.charCodeAt(0));
return (paletteColorLookupTableData.palette = arrayBufferToPaletteColorLUT(uint8Array));
} catch (e) {
console.log("Couldn't decode", paletteColorLookupTableData.InlineBinary, e);
Expand All @@ -61,7 +73,7 @@ function _getPaletteColor(paletteColorLookupTableData, lutDescriptor) {
if (paletteColorLookupTableData.retrieveBulkData) {
return paletteColorLookupTableData
.retrieveBulkData()
.then(val => (paletteColorLookupTableData.palette = arrayBufferToPaletteColorLUT(val)));
.then((val) => (paletteColorLookupTableData.palette = arrayBufferToPaletteColorLUT(val)));
}

console.error(`No data found for ${paletteColorLookupTableData} palette`);
Expand Down