@@ -91,12 +91,10 @@ function toNumberArray(arr) {
9191
9292class PDFFunction {
9393 static getSampleArray ( size , outputSize , bps , stream ) {
94- let i , ii ;
95- let length = 1 ;
96- for ( i = 0 , ii = size . length ; i < ii ; i ++ ) {
97- length *= size [ i ] ;
94+ let length = outputSize ;
95+ for ( const s of size ) {
96+ length *= s ;
9897 }
99- length *= outputSize ;
10098
10199 const array = new Array ( length ) ;
102100 let codeSize = 0 ;
@@ -106,7 +104,7 @@ class PDFFunction {
106104
107105 const strBytes = stream . getBytes ( ( length * bps + 7 ) / 8 ) ;
108106 let strIdx = 0 ;
109- for ( i = 0 ; i < length ; i ++ ) {
107+ for ( let i = 0 ; i < length ; i ++ ) {
110108 while ( codeSize < bps ) {
111109 codeBuf <<= 8 ;
112110 codeBuf |= strBytes [ strIdx ++ ] ;
@@ -330,14 +328,8 @@ class PDFFunction {
330328 }
331329
332330 // encode value into domain of function
333- let dmin = domain [ 0 ] ;
334- if ( i > 0 ) {
335- dmin = bounds [ i - 1 ] ;
336- }
337- let dmax = domain [ 1 ] ;
338- if ( i < bounds . length ) {
339- dmax = bounds [ i ] ;
340- }
331+ const dmin = i > 0 ? bounds [ i - 1 ] : domain [ 0 ] ;
332+ const dmax = i < length ? bounds [ i ] : domain [ 1 ] ;
341333
342334 const rmin = encode [ 2 * i ] ;
343335 const rmax = encode [ 2 * i + 1 ] ;
@@ -414,17 +406,11 @@ class PDFFunction {
414406 const stack = evaluator . execute ( input ) ;
415407 const stackIndex = stack . length - numOutputs ;
416408 for ( i = 0 ; i < numOutputs ; i ++ ) {
417- value = stack [ stackIndex + i ] ;
418- let bound = range [ i * 2 ] ;
419- if ( value < bound ) {
420- value = bound ;
421- } else {
422- bound = range [ i * 2 + 1 ] ;
423- if ( value > bound ) {
424- value = bound ;
425- }
426- }
427- output [ i ] = value ;
409+ output [ i ] = MathClamp (
410+ stack [ stackIndex + i ] ,
411+ range [ i * 2 ] ,
412+ range [ i * 2 + 1 ]
413+ ) ;
428414 }
429415 if ( cache_available > 0 ) {
430416 cache_available -- ;
0 commit comments