fix(rendering): Fix palette color LUT conversion causing black images (#5509)
The palette color LUT was incorrectly handling 16 bit entries, and didn't work for both array buffers and typed arrays.
This commit is contained in:
parent
66e6d73ad6
commit
ffd9ec3273
@ -30,18 +30,15 @@ function _getPaletteColor(paletteColorLookupTableData, lutDescriptor) {
|
||||
}
|
||||
|
||||
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 = [];
|
||||
|
||||
if (bits === 16) {
|
||||
let j = 0;
|
||||
for (let i = 0; i < numLutEntries; i++) {
|
||||
lut[i] = (arraybuffer[j++] + arraybuffer[j++]) << 8;
|
||||
}
|
||||
} else {
|
||||
for (let i = 0; i < numLutEntries; i++) {
|
||||
lut[i] = arraybuffer[i];
|
||||
}
|
||||
for (let i = 0; i < numLutEntries; i++) {
|
||||
lut[i] = data[i];
|
||||
}
|
||||
|
||||
return lut;
|
||||
};
|
||||
|
||||
@ -51,10 +48,10 @@ function _getPaletteColor(paletteColorLookupTableData, lutDescriptor) {
|
||||
|
||||
if (paletteColorLookupTableData.InlineBinary) {
|
||||
try {
|
||||
const arraybuffer = Uint8Array.from(atob(paletteColorLookupTableData.InlineBinary), c =>
|
||||
const uint8Array = Uint8Array.from(atob(paletteColorLookupTableData.InlineBinary), c =>
|
||||
c.charCodeAt(0)
|
||||
);
|
||||
return (paletteColorLookupTableData.palette = arrayBufferToPaletteColorLUT(arraybuffer));
|
||||
return (paletteColorLookupTableData.palette = arrayBufferToPaletteColorLUT(uint8Array));
|
||||
} catch (e) {
|
||||
console.log("Couldn't decode", paletteColorLookupTableData.InlineBinary, e);
|
||||
return undefined;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user