Skip to content

Commit ae8a815

Browse files
committed
fix #8, fix #9, 0.4.2
1 parent 8359077 commit ae8a815

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66
}
77

88
group 'pl.asie.zima'
9-
version '0.4.1'
9+
version '0.4.2'
1010

1111
repositories {
1212
mavenCentral()

docs/changelog/0.4.2.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Bugs fixed:
2+
3+
* [#9] Broken optimization code (regression in 0.4.1)
4+
* [#8] Profiles not loading their custom element selection. (regression in 0.4.0)

src/main/java/pl/asie/zima/image/ImageConverter.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@
3434
import java.io.IOException;
3535
import java.util.ArrayList;
3636
import java.util.Comparator;
37+
import java.util.HashSet;
3738
import java.util.LinkedHashMap;
3839
import java.util.List;
3940
import java.util.Map;
41+
import java.util.Set;
4042
import java.util.function.IntPredicate;
4143
import java.util.stream.Collectors;
4244
import java.util.stream.IntStream;
@@ -85,6 +87,7 @@ public Pair<Board, BufferedImage> convert(BufferedImage inputImage, ImageConvert
8587

8688
List<Triplet<Coord2D, ElementResult, Float>> statfulStrategies = new ArrayList<>();
8789
Map<ElementRule, List<ElementResult>> ruleResultMap = new LinkedHashMap<>();
90+
Set<Element> allowedElements = new HashSet<>();
8891
ElementResult[] previewResults = new ElementResult[width * height];
8992
float[] previewMse = new float[width * height];
9093
final int progressSize = width * height;
@@ -97,6 +100,7 @@ public Pair<Board, BufferedImage> convert(BufferedImage inputImage, ImageConvert
97100
}
98101

99102
Stream<ElementResult> proposals = null;
103+
allowedElements.add(rule.getElement());
100104
switch (rule.getStrategy()) {
101105
case EMPTY:
102106
proposals = Stream.of(emptyResult);
@@ -266,8 +270,10 @@ public Pair<Board, BufferedImage> convert(BufferedImage inputImage, ImageConvert
266270
}
267271
}
268272

269-
// improve compression by pushing some elements to their more optimal forms
273+
// compression pass
270274
boolean canTrustSolids = visual.isCharFull(219);
275+
Element solidElement = platform.getLibrary().byInternalName("SOLID");
276+
if (!allowedElements.contains(solidElement)) solidElement = null;
271277

272278
for (int iy = 0; iy < height; iy++) {
273279
for (int ix = 0; ix < width; ix++) {
@@ -282,12 +288,18 @@ public Pair<Board, BufferedImage> convert(BufferedImage inputImage, ImageConvert
282288
continue;
283289
}
284290

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) {
286295
if ((color & 0x0F) == 0x00) {
287296
board.setElement(x + ix, y + iy, emptyResult.getElement());
288297
board.setColor(x + ix, y + iy, 0x0F);
289298
} 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+
}
291303
}
292304
}
293305
}

src/main/java/pl/asie/zima/image/gui/ZimaFrontendSwing.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ public void setSettings(ZimaProfileSettings settings) {
889889
boolean found = false;
890890
int emptyIndex = -1;
891891
Set<ElementRule> settingsElementSet = new HashSet<>(settings.getAllowedElements());
892-
for (int i = 0; i < rulesetOptions.size(); i++) {
892+
for (int i = 0; i < rulesetOptions.get(platform).size(); i++) {
893893
ImageConverterRuleset ruleset = rulesetOptions.get(platform).get(i).getSecond();
894894
if (ruleset != null) {
895895
Set<ElementRule> rulesElementSet = new HashSet<>(ruleset.getRules());

0 commit comments

Comments
 (0)