Skip to content

Commit

Permalink
fix #8, fix #9, 0.4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
asiekierka committed Dec 19, 2020
1 parent 8359077 commit ae8a815
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

group 'pl.asie.zima'
version '0.4.1'
version '0.4.2'

repositories {
mavenCentral()
Expand Down
4 changes: 4 additions & 0 deletions docs/changelog/0.4.2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Bugs fixed:

* [#9] Broken optimization code (regression in 0.4.1)
* [#8] Profiles not loading their custom element selection. (regression in 0.4.0)
18 changes: 15 additions & 3 deletions src/main/java/pl/asie/zima/image/ImageConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.IntPredicate;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
Expand Down Expand Up @@ -85,6 +87,7 @@ public Pair<Board, BufferedImage> convert(BufferedImage inputImage, ImageConvert

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

Stream<ElementResult> proposals = null;
allowedElements.add(rule.getElement());
switch (rule.getStrategy()) {
case EMPTY:
proposals = Stream.of(emptyResult);
Expand Down Expand Up @@ -266,8 +270,10 @@ public Pair<Board, BufferedImage> convert(BufferedImage inputImage, ImageConvert
}
}

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

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

if ((element.getCharacter() == 219 || ((color >> 4) == (color & 0x0F))) && canTrustSolids) {
if (color == 0x00) {
board.setElement(x + ix, y + iy, emptyResult.getElement());
board.setColor(x + ix, y + iy, 0x0F);
} else if ((element.getCharacter() == 219 || ((color >> 4) == (color & 0x0F))) && canTrustSolids) {
if ((color & 0x0F) == 0x00) {
board.setElement(x + ix, y + iy, emptyResult.getElement());
board.setColor(x + ix, y + iy, 0x0F);
} else {
board.setColor(x + ix, y + iy, color & 0x0F);
if (solidElement != null && (colorCheck == null || colorCheck.test(color & 0x0F))) {
board.setElement(x + ix, y + iy, solidElement);
board.setColor(x + ix, y + iy, color & 0x0F);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ public void setSettings(ZimaProfileSettings settings) {
boolean found = false;
int emptyIndex = -1;
Set<ElementRule> settingsElementSet = new HashSet<>(settings.getAllowedElements());
for (int i = 0; i < rulesetOptions.size(); i++) {
for (int i = 0; i < rulesetOptions.get(platform).size(); i++) {
ImageConverterRuleset ruleset = rulesetOptions.get(platform).get(i).getSecond();
if (ruleset != null) {
Set<ElementRule> rulesElementSet = new HashSet<>(ruleset.getRules());
Expand Down

0 comments on commit ae8a815

Please sign in to comment.