fix: use bit-appropriate array for palette lookup tables (#1698)

Co-authored-by: Sanders DeNardi <sdenardi@summusglobal.com>
This commit is contained in:
Sanders DeNardi 2020-05-04 04:13:04 -04:00 committed by GitHub
parent 256563d7ee
commit 7033886697
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -115,23 +115,15 @@ function _getPaletteColor(server, paletteColorLookupTableData, lutDescriptor) {
const numLutEntries = lutDescriptor[0];
const bits = lutDescriptor[2];
const readUInt16 = (byteArray, position) => {
return byteArray[position] + byteArray[position + 1] * 256;
};
const arrayBufferToPaletteColorLUT = arraybuffer => {
const byteArray = new Uint8Array(arraybuffer);
const byteArray = bits === 16 ?
new Uint16Array(arraybuffer) :
new Uint8Array(arraybuffer);
const lut = [];
if (bits === 16) {
for (let i = 0; i < numLutEntries; i++) {
lut[i] = readUInt16(byteArray, i * 2);
}
} else {
for (let i = 0; i < numLutEntries; i++) {
lut[i] = byteArray[i];
}
}
return lut;
};