34
34
import java .io .IOException ;
35
35
import java .util .ArrayList ;
36
36
import java .util .Comparator ;
37
+ import java .util .HashSet ;
37
38
import java .util .LinkedHashMap ;
38
39
import java .util .List ;
39
40
import java .util .Map ;
41
+ import java .util .Set ;
40
42
import java .util .function .IntPredicate ;
41
43
import java .util .stream .Collectors ;
42
44
import java .util .stream .IntStream ;
@@ -85,6 +87,7 @@ public Pair<Board, BufferedImage> convert(BufferedImage inputImage, ImageConvert
85
87
86
88
List <Triplet <Coord2D , ElementResult , Float >> statfulStrategies = new ArrayList <>();
87
89
Map <ElementRule , List <ElementResult >> ruleResultMap = new LinkedHashMap <>();
90
+ Set <Element > allowedElements = new HashSet <>();
88
91
ElementResult [] previewResults = new ElementResult [width * height ];
89
92
float [] previewMse = new float [width * height ];
90
93
final int progressSize = width * height ;
@@ -97,6 +100,7 @@ public Pair<Board, BufferedImage> convert(BufferedImage inputImage, ImageConvert
97
100
}
98
101
99
102
Stream <ElementResult > proposals = null ;
103
+ allowedElements .add (rule .getElement ());
100
104
switch (rule .getStrategy ()) {
101
105
case EMPTY :
102
106
proposals = Stream .of (emptyResult );
@@ -266,8 +270,10 @@ public Pair<Board, BufferedImage> convert(BufferedImage inputImage, ImageConvert
266
270
}
267
271
}
268
272
269
- // improve compression by pushing some elements to their more optimal forms
273
+ // compression pass
270
274
boolean canTrustSolids = visual .isCharFull (219 );
275
+ Element solidElement = platform .getLibrary ().byInternalName ("SOLID" );
276
+ if (!allowedElements .contains (solidElement )) solidElement = null ;
271
277
272
278
for (int iy = 0 ; iy < height ; iy ++) {
273
279
for (int ix = 0 ; ix < width ; ix ++) {
@@ -282,12 +288,18 @@ public Pair<Board, BufferedImage> convert(BufferedImage inputImage, ImageConvert
282
288
continue ;
283
289
}
284
290
285
- if ((element .getCharacter () == 219 || ((color >> 4 ) == (color & 0x0F ))) && canTrustSolids ) {
291
+ if (color == 0x00 ) {
292
+ board .setElement (x + ix , y + iy , emptyResult .getElement ());
293
+ board .setColor (x + ix , y + iy , 0x0F );
294
+ } else if ((element .getCharacter () == 219 || ((color >> 4 ) == (color & 0x0F ))) && canTrustSolids ) {
286
295
if ((color & 0x0F ) == 0x00 ) {
287
296
board .setElement (x + ix , y + iy , emptyResult .getElement ());
288
297
board .setColor (x + ix , y + iy , 0x0F );
289
298
} else {
290
- board .setColor (x + ix , y + iy , color & 0x0F );
299
+ if (solidElement != null && (colorCheck == null || colorCheck .test (color & 0x0F ))) {
300
+ board .setElement (x + ix , y + iy , solidElement );
301
+ board .setColor (x + ix , y + iy , color & 0x0F );
302
+ }
291
303
}
292
304
}
293
305
}
0 commit comments