Skip to content

Commit

Permalink
Speed up MegaZeux image conversion by ~6%
Browse files Browse the repository at this point in the history
  • Loading branch information
asiekierka committed Feb 9, 2022
1 parent a8b219e commit d86b93f
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/main/java/pl/asie/zima/image/ImageConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,25 @@ private Pair<Result, BufferedImage> convertBoardless(BufferedImage inputImage, i
ElementResult emptyResult = null;
BufferedImage preview = null;

int acceptedChars = 0;
for (int ich = 0; ich < 256; ich++) {
if (fast && (ich != 32 && ich != 176 && ich != 177 && ich != 178 && ich != 219)) continue;
if (charCheck != null && !charCheck.test(ich)) continue;
for (int ico = 0; ico < 256; ico++) {
if (colorCheck != null && !colorCheck.test(ico)) continue;

// if BG == FG, we only need one char
if (((ico >> 4) == (ico & 15)) && acceptedChars >= 1) {
continue;
}

ElementResult result = new ElementResult(null, false, false, ich, ico);
if (emptyResult == null) {
emptyResult = result;
}
rules.add(result);
}
acceptedChars++;
}

if (emptyResult == null) {
Expand Down

0 comments on commit d86b93f

Please sign in to comment.