@@ -36,7 +36,7 @@ public void Start(Scene scene, File Input, Path Output, SortingMode sorting) {
3636 });
3737 int pixelAmount = (int ) (Files .size (Input .toPath ()) / 3 );
3838 // byte[] InputBytes = Files.readAllBytes(Input.toPath()); too much ram
39- System .out .println (pixelAmount );
39+ // System.out.println(pixelAmount);
4040 int dimension = (int ) Math .ceil (Math .sqrt (pixelAmount ));
4141 BufferedImage BI = new BufferedImage (dimension , dimension , BufferedImage .TYPE_INT_RGB );
4242 File outFile = Output .toFile ();
@@ -80,10 +80,13 @@ public void Start(Scene scene, File Input, Path Output, SortingMode sorting) {
8080 int lastColor = 0 ;
8181 int currentColor = 0 ;
8282
83+ int passes = 1000 ;
84+
8385 switch (sorting ) {
8486 case SortingMode .brightness :
8587 for (int col = 0 ; col < BI .getWidth (); col ++) {
86- for (int i = 0 ; i < 200 ; i ++) {
88+ for (int i = 0 ; i < passes ; i ++) {
89+ convRef [0 ].addLog ("Sorting pass" , i * col , passes * BI .getWidth ());
8790 for (int y = 1 ; y < BI .getHeight (); y ++) {
8891 lastColor = currentColor ;
8992 currentColor = BI .getRGB (col , y );
@@ -107,7 +110,8 @@ public void Start(Scene scene, File Input, Path Output, SortingMode sorting) {
107110
108111 case SortingMode .red :
109112 for (int col = 0 ; col < BI .getWidth (); col ++) {
110- for (int i = 0 ; i < 200 ; i ++) {
113+ for (int i = 0 ; i < passes ; i ++) {
114+ convRef [0 ].addLog ("Sorting pass" , i * col , passes * BI .getWidth ());
111115 for (int y = 1 ; y < BI .getHeight (); y ++) {
112116 lastColor = currentColor ;
113117 currentColor = BI .getRGB (col , y );
@@ -127,7 +131,8 @@ public void Start(Scene scene, File Input, Path Output, SortingMode sorting) {
127131
128132 case SortingMode .green :
129133 for (int col = 0 ; col < BI .getWidth (); col ++) {
130- for (int i = 0 ; i < 200 ; i ++) {
134+ for (int i = 0 ; i < passes ; i ++) {
135+ convRef [0 ].addLog ("Sorting pass" , i * col , passes * BI .getWidth ());
131136 for (int y = 1 ; y < BI .getHeight (); y ++) {
132137 lastColor = currentColor ;
133138 currentColor = BI .getRGB (col , y );
@@ -147,7 +152,8 @@ public void Start(Scene scene, File Input, Path Output, SortingMode sorting) {
147152
148153 case SortingMode .blue :
149154 for (int col = 0 ; col < BI .getWidth (); col ++) {
150- for (int i = 0 ; i < 200 ; i ++) {
155+ for (int i = 0 ; i < passes ; i ++) {
156+ convRef [0 ].addLog ("Sorting pass" , i * col , passes * BI .getWidth ());
151157 for (int y = 1 ; y < BI .getHeight (); y ++) {
152158 lastColor = currentColor ;
153159 currentColor = BI .getRGB (col , y );
@@ -165,6 +171,37 @@ public void Start(Scene scene, File Input, Path Output, SortingMode sorting) {
165171 }
166172 break ;
167173
174+ case SortingMode .hue :
175+ for (int col = 0 ; col < BI .getWidth (); col ++) {
176+ for (int i = 0 ; i < passes ; i ++) {
177+ convRef [0 ].addLog ("Sorting pass" , i * col , passes * BI .getWidth ());
178+ for (int y = 1 ; y < BI .getHeight (); y ++) {
179+ lastColor = currentColor ;
180+ currentColor = BI .getRGB (col , y );
181+
182+ int r = (currentColor >> 16 ) & 0xFF ;
183+ int g = (currentColor >> 8 ) & 0xFF ;
184+ int b = currentColor & 0xFF ;
185+
186+ int re = (lastColor >> 16 ) & 0xFF ;
187+ int gr = (lastColor >> 8 ) & 0xFF ;
188+ int bl = lastColor & 0xFF ;
189+
190+ float [] currentHSB = Color .RGBtoHSB (r , g , b , null );
191+ float currenthue = currentHSB [0 ]; // 0.0 to 1.0
192+
193+ float [] lastHSB = Color .RGBtoHSB (re , gr , bl , null );
194+ float lasthue = lastHSB [0 ]; // 0.0 to 1.0
195+
196+ if ((currenthue ) < (lasthue )) {
197+ BI .setRGB (col , y , lastColor );
198+ BI .setRGB (col , y - 1 , currentColor );
199+ }
200+ }
201+ }
202+ }
203+ break ;
204+
168205 default :
169206 break ;
170207 }
0 commit comments