-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
feature: support OPM with palette color LUT #5522
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
b246a48
4c4980c
658177e
f20abde
8163ffa
961b21b
5758d8c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
|
||
| 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); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
|
||
| // Apply Orthanc shift logic | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Palette Color Retrieval Breaks 8-bit CompatibilityThe
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tunglt1810 please check this
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @IbrahimCSAE , |
||
| } | ||
|
|
||
| return lut; | ||
|
|
@@ -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); | ||
|
|
@@ -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`); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest isTwoByte = bits > 8