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 => {
|
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 lut = [];
|
||||||
|
|
||||||
if (bits === 16) {
|
|
||||||
let j = 0;
|
|
||||||
for (let i = 0; i < numLutEntries; i++) {
|
for (let i = 0; i < numLutEntries; i++) {
|
||||||
lut[i] = (arraybuffer[j++] + arraybuffer[j++]) << 8;
|
lut[i] = data[i];
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (let i = 0; i < numLutEntries; i++) {
|
|
||||||
lut[i] = arraybuffer[i];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return lut;
|
return lut;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -51,10 +48,10 @@ function _getPaletteColor(paletteColorLookupTableData, lutDescriptor) {
|
|||||||
|
|
||||||
if (paletteColorLookupTableData.InlineBinary) {
|
if (paletteColorLookupTableData.InlineBinary) {
|
||||||
try {
|
try {
|
||||||
const arraybuffer = Uint8Array.from(atob(paletteColorLookupTableData.InlineBinary), c =>
|
const uint8Array = Uint8Array.from(atob(paletteColorLookupTableData.InlineBinary), c =>
|
||||||
c.charCodeAt(0)
|
c.charCodeAt(0)
|
||||||
);
|
);
|
||||||
return (paletteColorLookupTableData.palette = arrayBufferToPaletteColorLUT(arraybuffer));
|
return (paletteColorLookupTableData.palette = arrayBufferToPaletteColorLUT(uint8Array));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log("Couldn't decode", paletteColorLookupTableData.InlineBinary, e);
|
console.log("Couldn't decode", paletteColorLookupTableData.InlineBinary, e);
|
||||||
return undefined;
|
return undefined;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user