@@ -58,36 +58,41 @@ class Palette {
5858 return pal ;
5959 }
6060
61+
6162 /**
6263 Read a palette from an image pixels
6364 **/
64- public static function fromPixelsRect (pixels : hxd. Pixels , x : Int , y : Int , wid : Int , hei : Int , eachColorSizePx = 1 , allowDuplicates = false ) : Palette {
65- x = M .iclamp (x , 0 , pixels .width );
66- y = M .iclamp (y , 0 , pixels .height );
67- wid = M .iclamp (wid , 0 , pixels .width - x );
68- hei = M .iclamp (hei , 0 , pixels .height - y );
65+ public static function fromPixelsRect (pixels : hxd. Pixels , fromX : Int , fromY : Int , wid : Int , hei : Int , eachColorSizePx = 1 , allowDuplicates = false ) : Palette {
66+ fromX = M .iclamp (fromX , 0 , pixels .width - 1 );
67+ fromY = M .iclamp (fromY , 0 , pixels .height - 1 );
68+ wid = M .iclamp (wid , 0 , pixels .width - fromX );
69+ hei = M .iclamp (hei , 0 , pixels .height - fromY );
6970
7071 if ( wid == 0 || hei == 0 )
7172 return new Palette ();
7273
7374 var pal = new Palette ();
7475 var knowns = new Map ();
75- while ( y < hei ) {
76- var c = new Col ( pixels .getPixel (x ,y ) ).withoutAlpha ();
76+ var offX = 0 ;
77+ var offY = 0 ;
78+ while ( offY < hei ) {
79+ var c = new Col ( pixels .getPixel (fromX + offX , fromY + offY ) ).withoutAlpha ();
7780 if ( allowDuplicates || ! knowns .exists (c ) ) {
7881 pal .addColor (c );
7982 if ( ! allowDuplicates )
8083 knowns .set (c ,true );
8184 }
82- x + = eachColorSizePx ;
83- if ( x >= wid ) {
84- x = 0 ;
85- y + = eachColorSizePx ;
85+
86+ offX + = eachColorSizePx ;
87+ if ( offX >= wid ) {
88+ offX = 0 ;
89+ offY + = eachColorSizePx ;
8690 }
8791 }
8892 return pal ;
8993 }
9094
95+
9196 /** Read palette from an Aseprite image **/
9297 #if heaps_aseprite
9398 public static function fromAseprite (ase : aseprite. Aseprite ) : Palette {
0 commit comments