@@ -320,7 +320,8 @@ <h1 class="page-title">Source: color.js</h1>
320320 const startpoint = lut[offset - 1]
321321 const step = (endpoint - startpoint) / (length - 1)
322322 for (let j = 0; j < length; j++) {
323- lut[offset + j] = startpoint + Math.round(j * step)
323+ const value = startpoint + Math.round(j * step)
324+ lut[offset + j] = value
324325 }
325326 offset += length
326327 } else if (opcode === 2) {
@@ -396,17 +397,23 @@ <h1 class="page-title">Source: color.js</h1>
396397 )
397398 }
398399
399- if (this[_attrs].bitsPerEntry === 16) {
400+ const maxValues = [
401+ Math.max(...redLUT),
402+ Math.max(...greenLUT),
403+ Math.max(...blueLUT)
404+ ]
405+ const maxInput = Math.max(...maxValues)
406+ const maxOutput = 255
407+ if (this[_attrs].bitsPerEntry === 16 && maxInput > 255) {
400408 /*
401409 * Only palettes with 256 entries and 8 bit per entry are supported for
402410 * display. Therefore, data need to rescaled and resampled.
403411 */
404- const maxInput = Math.pow(2, 16) - 1
405- const maxOutput = Math.pow(2, 8) - 1
406- const steps = Math.pow(2, 16) / Math.pow(2, 8)
407- this[_attrs].data = new Array(steps)
408- for (let i = 0; i < steps; i++) {
409- const j = i * steps
412+ const n = 256
413+ const step = this[_attrs].numberOfEntries / n
414+ this[_attrs].data = new Array(n)
415+ for (let i = 0; i < n; i++) {
416+ const j = i * step
410417 this[_attrs].data[i] = [
411418 Math.round(rescale(redLUT[j], 0, maxInput, 0, maxOutput)),
412419 Math.round(rescale(greenLUT[j], 0, maxInput, 0, maxOutput)),
@@ -416,11 +423,7 @@ <h1 class="page-title">Source: color.js</h1>
416423 } else {
417424 this[_attrs].data = new Array(this[_attrs].numberOfEntries)
418425 for (let i = 0; i < this[_attrs].numberOfEntries; i++) {
419- this[_attrs].data[i] = [
420- redLUT[i],
421- greenLUT[i],
422- blueLUT[i]
423- ]
426+ this[_attrs].data[i] = [redLUT[i], greenLUT[i], blueLUT[i]]
424427 }
425428 }
426429 }
@@ -459,7 +462,7 @@ <h2><a href="index.html">Home</a></h2><h3>Namespaces</h3><ul><li><a href="annota
459462< br class ="clear ">
460463
461464< footer >
462- Documentation generated by < a href ="https://github.com/jsdoc/jsdoc "> JSDoc 3.6.10</ a > on Mon May 16 2022 08:28:05 GMT-0400 (Eastern Daylight Time)
465+ Documentation generated by < a href ="https://github.com/jsdoc/jsdoc "> JSDoc 3.6.10</ a > on Mon May 16 2022 17:56:50 GMT-0400 (Eastern Daylight Time)
463466</ footer >
464467
465468< script > prettyPrint ( ) ; </ script >
0 commit comments