@@ -136,26 +136,26 @@ namespace helpers {
136136 if ( sx < 0 ) continue ;
137137 if ( sx >= clipWSrc ) break ;
138138 const dx = x + xDst ;
139-
139+
140140 // ดึง column ส่วนที่ต้องการจาก src (offset ySrc)
141141 if ( sx !== curSx ) fximgGetRows ( src , sx , srcRow , safeSrcH ) , curSx = sx ;
142142 fximgGetRows ( dst , dx , dstRow , safeDstH ) ;
143-
143+
144144 for ( let y = 0 ; y < clipHDst ; y ++ ) {
145145 const sy = ( ( y * scaleY ) | 0 ) + ySrc ;
146146 if ( sy < 0 ) continue ;
147147 if ( sy >= clipHSrc ) break ;
148148 const dy = y + yDst ;
149149 const newPixel = srcRow [ sy ] ; // pixel จาก src (หลัง shift ySrc แล้ว)
150-
150+
151151 if ( transparent && newPixel < 1 ) continue ;
152-
152+
153153 const oldPixel = dstRow [ dy ] ;
154154 if ( oldPixel === newPixel ) continue ;
155155 dstRow [ dy ] = newPixel ;
156156 rowChange = true , anyChange = true ;
157157 }
158-
158+
159159 if ( ! rowChange ) continue ;
160160 fximgSetRows ( dst , dx , dstRow , safeDstH ) ;
161161
@@ -269,13 +269,13 @@ namespace helpers {
269269 if ( width < 1 || height < 1 ) return ;
270270 color &= 0xF ;
271271 idx *= w ;
272-
272+
273273 const sx = Math . clamp ( 0 , w - 1 , x ) ;
274274 const ex = Math . clamp ( 0 , w - 1 , x + width - 1 ) ;
275275 const sy = Math . clamp ( 0 , h - 1 , y ) ;
276276 const ey = Math . clamp ( 0 , h - 1 , y + height - 1 ) ;
277277 if ( sx > ex || sy > ey ) return ;
278-
278+
279279 const buf = pins . createBuffer ( h ) ;
280280 for ( let cx = sx ; cx <= ex ; cx ++ ) {
281281 fximgGetRows ( fxpic , cx + idx , buf , h ) ;
@@ -412,6 +412,7 @@ namespace helpers {
412412 buf . fill ( color , Math . max ( offset , 0 ) , ( dy << 1 ) + Math . min ( offset , 0 ) ) ;
413413 fximg . setRows ( fxpic , x , buf , h ) ;
414414 }
415+
415416 }
416417
417418 // 12. drawImage (ไม่ transparent)
@@ -430,26 +431,26 @@ namespace helpers {
430431 const sh = fximgHeightOf ( from ) ;
431432 const tw = fximgWidthOf ( to )
432433 const th = fximgHeightOf ( to ) ;
433-
434+
434435 const rowFrom = pins . createBuffer ( sh ) ;
435436 const rowTo = pins . createBuffer ( th ) ;
436437 for ( let sx = 0 ; sx < sw ; sx ++ ) {
437438 let tx = dx + sx ;
438439 if ( tx < 0 ) continue ;
439440 if ( tx >= tw ) break ;
440-
441+
441442 fximgGetRows ( from , sx , rowFrom , sh ) ;
442443 fximgGetRows ( to , tx , rowTo , th ) ;
443-
444+
444445 const dyPos = Math . max ( dy , 0 ) ;
445446 const dyNeg = Math . min ( dy , 0 ) ;
446-
447+
447448 const tmpRow = pins . createBuffer ( sh + dyNeg ) ;
448449 if ( dyNeg < 0 ) rowFrom . shift ( Math . abs ( dyNeg ) )
449450 tmpRow . write ( dyPos , rowFrom ) ;
450-
451+
451452 if ( transparent ) for ( let i = 0 ; i < ( sh + dyNeg ) ; i ++ ) if ( tmpRow [ i ] < 1 ) tmpRow [ i ] = rowTo [ dyPos + i ] ;
452-
453+
453454 rowTo . write ( dyPos , tmpRow ) ;
454455 fximgSetRows ( to , tx , rowTo , th ) ;
455456 }
@@ -703,27 +704,27 @@ namespace helpers {
703704 let v = [ new pt2 ( x0 , y0 ) , new pt2 ( x1 , y1 ) , new pt2 ( x2 , y2 ) ] ;
704705 if ( fximgIsOutOfAreas ( v , w , h ) ) return ;
705706 idx *= w ;
706-
707+
707708 // ------------------- Sort vertices by y (top -> bottom) -------------------
708-
709+
709710 let tmp = - 1 ;
710711 //Sort points so that x0 <= x1 <= x2
711712 if ( x1 < x0 ) tmp = x0 , x0 = x1 , x1 = tmp , tmp = y0 , y0 = y1 , y1 = tmp ; //[x0, y0, x1, y1] = [x1, y1, x0, y0];
712713 if ( x2 < x0 ) tmp = x2 , x2 = x0 , x0 = tmp , tmp = y2 , y2 = y0 , y0 = tmp ; //[x2, y2, x0, y0] = [x0, y0, x2, y2];
713714 if ( x2 < x1 ) tmp = x2 , x2 = x1 , x1 = tmp , tmp = y2 , y2 = y1 , y1 = tmp ; //[x2, y2, x1, y1] = [x1, y1, x2, y2];
714-
715+
715716 //Compute the x coordinates of the triangles edges
716717 let y012 = interpolate ( x0 , y0 , x1 , y1 , w , h ) . concat ( interpolate ( x1 , y1 , x2 , y2 , w , h ) ) ;
717718 let y02 = interpolate ( x0 , y0 , x2 , y2 , w , h ) ;
718-
719+
719720 if ( y012 . length < 1 || y02 . length < 1 ) return ;
720-
721+
721722 //Ensure the arrays are the correct length
722723 if ( y012 . length > y02 . length )
723724 y012 . pop ( ) ;
724725 else if ( y012 . length < y02 . length )
725726 y02 . pop ( ) ;
726-
727+
727728 //Determine which is left and which is right
728729 let yts : number [ ] = [ ] ;
729730 let ybs : number [ ] = [ ] ;
@@ -736,9 +737,9 @@ namespace helpers {
736737 else
737738 yts = y012 ,
738739 ybs = y02 ;
739-
740+
740741 const buf = pins . createBuffer ( h ) ;
741-
742+
742743 //Draw em
743744 //TODO: just write to the buffer with fill; place any bitwise operations for dithering patterns thusly
744745 const drawX = ( x : number , xi : number ) => {
@@ -750,7 +751,7 @@ namespace helpers {
750751 buf . fill ( color , Math . max ( yt , 0 ) , fillSize ) ;
751752 fximgSetRows ( fxpic , x , buf , h ) ;
752753 }
753-
754+
754755 for ( let x = x0 , xi = 0 ; x <= x2 ; x ++ , xi ++ ) {
755756 drawX ( x , xi ) ;
756757 drawX ( ++ x , ++ xi ) ;
@@ -857,29 +858,29 @@ namespace helpers {
857858 const toW = fximgWidthOf ( to ) ;
858859 const toH = fximgHeightOf ( to ) ;
859860 // ถ้าใช้ dstTotalW แบบเดิม → const toTotalW = toW * fximgLengthOf(to); แต่ polymesh ไม่ใช้ เลยข้าม
860-
861+
861862 const fromRowBuf = pins . createBuffer ( h ) ;
862863 //const emptyHash = fromRowBuf.hash(0xffff) & 0xffff;
863-
864+
864865 const wInv = 1 / w ;
865866 const hInv = 1 / h ;
866-
867+
867868 const pqu = new pt2_2 (
868869 ( x1 - x0 ) ,
869870 ( y1 - y0 ) ,
870871 ( x2 - x3 ) ,
871872 ( y2 - y3 )
872873 ) ;
873-
874+
874875 for ( let sx = 0 ; sx < w ; sx ++ ) {
875876 const ix = center ? fximgZigzet ( 0 , w - 1 , sx ) : sx ;
876877 fximgGetRows ( from , w - ix - 1 , fromRowBuf , h ) ; // ใช้ w - ix -1 เหมือน polymesh (reverse ถ้า center)
877-
878+
878879 //if (fromRowBuf.hash(0xffff) === emptyHash) continue;
879-
880+
880881 const u0 = ( ix * wInv ) ;
881882 const u1 = ( ( ix + 1 ) * wInv ) ;
882-
883+
883884 const qu = new pt2_4 (
884885 x0 + pqu . x0 * u0 ,
885886 y0 + pqu . y0 * u0 ,
@@ -890,23 +891,23 @@ namespace helpers {
890891 x3 + pqu . x1 * u1 ,
891892 y3 + pqu . y1 * u1
892893 ) ;
893-
894+
894895 const pqv = new pt2_2 (
895896 ( qu . x1 - qu . x0 ) ,
896897 ( qu . y1 - qu . y0 ) ,
897898 ( qu . x3 - qu . x2 ) ,
898899 ( qu . y3 - qu . y2 )
899900 ) ;
900-
901+
901902 for ( let sy = 0 ; sy < h ; sy ++ ) {
902903 const iy = center ? fximgZigzet ( 0 , h - 1 , sy ) : sy ;
903-
904+
904905 const color = fromRowBuf [ iy ] ; // pixel แถวบนสุดหลัง shift
905906 if ( transparent && color < 1 ) continue ; // transparent
906-
907+
907908 const v0 = ( iy * hInv ) ;
908909 const v1 = ( ( iy + 1 ) * hInv ) ;
909-
910+
910911 const qv = new pt2_4 (
911912 ( qu . x0 + pqv . x0 * v0 ) | 0 ,
912913 ( qu . y0 + pqv . y0 * v0 ) | 0 ,
@@ -917,16 +918,16 @@ namespace helpers {
917918 ( qu . x2 + pqv . x1 * v1 ) | 0 ,
918919 ( qu . y2 + pqv . y1 * v1 ) | 0
919920 ) ;
920-
921+
921922 // Skip ถ้าทั้ง quad ออกนอกจอ (เหมือน polymesh)
922923 if ( qv . toArr . every ( pt =>
923924 pt . x < 0 || pt . x >= toW || pt . y < 0 || pt . y >= toH
924925 ) ) continue ;
925-
926+
926927 // Stamp ด้วย 2 triangle (สไตล์ polymesh)
927928 fximgFillTriangle ( to , qv . x1 , qv . y1 , qv . x0 , qv . y0 , qv . x3 , qv . y3 , color ) ;
928929 fximgFillTriangle ( to , qv . x2 , qv . y2 , qv . x0 , qv . y0 , qv . x3 , qv . y3 , color ) ;
929-
930+
930931 // หรือถ้าอยากใช้ polygon4 เดิม (อาจแก้ gap ได้ดีกว่าในบางเคส)
931932 // fximgFillPolygon4(to, qv.x1, qv.y1, qv.x0, qv.y0, qv.x2, qv.y2, qv.x3, qv.y3, color);
932933 }
0 commit comments