@@ -429,6 +429,7 @@ class IndexedCS extends ColorSpace {
429429 constructor ( base , highVal , lookup ) {
430430 super ( "Indexed" , 1 ) ;
431431 this . base = base ;
432+ this . highVal = highVal ;
432433
433434 const length = base . numComps * ( highVal + 1 ) ;
434435 this . lookup = new Uint8Array ( length ) ;
@@ -452,9 +453,10 @@ class IndexedCS extends ColorSpace {
452453 'IndexedCS.getRgbItem: Unsupported "dest" type.'
453454 ) ;
454455 }
455- const numComps = this . base . numComps ;
456- const start = src [ srcOffset ] * numComps ;
457- this . base . getRgbBuffer ( this . lookup , start , 1 , dest , destOffset , 8 , 0 ) ;
456+ const { base, highVal, lookup } = this ;
457+ const start =
458+ MathClamp ( Math . round ( src [ srcOffset ] ) , 0 , highVal ) * base . numComps ;
459+ base . getRgbBuffer ( lookup , start , 1 , dest , destOffset , 8 , 0 ) ;
458460 }
459461
460462 getRgbBuffer ( src , srcOffset , count , dest , destOffset , bits , alpha01 ) {
@@ -464,13 +466,13 @@ class IndexedCS extends ColorSpace {
464466 'IndexedCS.getRgbBuffer: Unsupported "dest" type.'
465467 ) ;
466468 }
467- const base = this . base ;
468- const numComps = base . numComps ;
469+ const { base, highVal , lookup } = this ;
470+ const { numComps } = base ;
469471 const outputDelta = base . getOutputLength ( numComps , alpha01 ) ;
470- const lookup = this . lookup ;
471472
472473 for ( let i = 0 ; i < count ; ++ i ) {
473- const lookupPos = src [ srcOffset ++ ] * numComps ;
474+ const lookupPos =
475+ MathClamp ( Math . round ( src [ srcOffset ++ ] ) , 0 , highVal ) * numComps ;
474476 base . getRgbBuffer ( lookup , lookupPos , 1 , dest , destOffset , 8 , alpha01 ) ;
475477 destOffset += outputDelta ;
476478 }
0 commit comments