Skip to content

Commit

Permalink
zima 0.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
asiekierka committed Oct 23, 2021
1 parent d323964 commit 6bc8c97
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 10 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.6.0'
version '0.7.0'

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

* Added experimental "GMse" converter algorithm.
* Added "Toggle all" button to the Elements tab.

Bugs fixed:

* Fixed performance regression from zima 0.6.0.
3 changes: 2 additions & 1 deletion docs/changelog/versions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
0.4.2
0.5.0
0.5.1
0.6.0
0.6.0
0.7.0
11 changes: 5 additions & 6 deletions src/main/java/pl/asie/zima/image/GmseImageMseCalculator.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import pl.asie.libzzt.TextVisualData;
import pl.asie.zima.util.ColorUtils;
import pl.asie.zima.util.DebugUtils;
import pl.asie.zima.util.Gaussian2DKernel;

import java.awt.image.BufferedImage;
Expand Down Expand Up @@ -108,8 +107,6 @@ public GaussianCharCache(TextVisualData visual, int radius, float sigma) {
float[] data = this.cache.get(entries.getKey());
Arrays.fill(data, entries.getValue());
}

DebugUtils.print1DArray(this.cache.get(178), visual.getCharWidth());
}

public float[] getGaussian(int chr) {
Expand All @@ -123,12 +120,14 @@ public float[] getGaussian(int chr) {
private final float contrastReduction;
private final boolean blinkingDisabled;

public GmseImageMseCalculator(TextVisualData visual, boolean blinkingDisabled, float contrastReduction) {
public GmseImageMseCalculator(TextVisualData visual, boolean blinkingDisabled, float contrastReduction, float accurateApproximate) {
this.visual = visual;
this.gaussCache = new GaussianCharCache(visual, 3, 1.5f);
this.mixCache = new ColorMixCache(visual, 256);
this.contrastReduction = contrastReduction;
this.blinkingDisabled = blinkingDisabled;

float size = 0.05f + (accurateApproximate * 1.45f);
this.gaussCache = new GaussianCharCache(visual, 3, size);
this.mixCache = new ColorMixCache(visual, 256);
}

@Override
Expand Down
36 changes: 36 additions & 0 deletions src/main/java/pl/asie/zima/image/ImageConverterType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Copyright (c) 2020, 2021 Adrian Siekierka
*
* This file is part of zima.
*
* zima is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* zima is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with zima. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.asie.zima.image;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public enum ImageConverterType {
TRIX("Trix"),
GMSE("GMse (Experimental)");

private final String name;

@Override
public String toString() {
return name;
}
}
12 changes: 10 additions & 2 deletions src/main/java/pl/asie/zima/image/gui/ZimaConversionProfile.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public class ZimaConversionProfile {
public static final Property<Integer> STAT_CYCLE = Property.create("output.statCycle", 0);
public static final Property<Integer> MAX_STAT_COUNT = Property.create("converter.maxStatCount", 150);
public static final Property<Integer> MAX_BOARD_SIZE = Property.create("converter.maxBoardSize", 20002);

public static final Property<ImageConverterType> IMAGE_CONVERTER_TYPE = Property.create("converter.type", ImageConverterType.TRIX, MSE_CALCULATOR);
public static final Property<Float> TRIX_CONTRAST_REDUCTION = Property.create("converter.trix.contrastReduction", 0.0035f, MSE_CALCULATOR);
public static final Property<Float> TRIX_ACCURATE_APPROXIMATE = Property.create("converter.trix.accurateApproximate", 0.45f, MSE_CALCULATOR);

Expand Down Expand Up @@ -188,8 +190,14 @@ public Pair<ImageConverter.Result, BufferedImage> convert(BufferedImage input, P
this.renderer = new TextVisualRenderer(properties.get(VISUAL_DATA), properties.get(PLATFORM));
}
if (localHolder.isAffected(MSE_CALCULATOR) || this.mseCalculator == null) {
this.mseCalculator = new TrixImageMseCalculator(properties.get(VISUAL_DATA), properties.get(BLINKING_DISABLED), properties.get(TRIX_CONTRAST_REDUCTION), properties.get(TRIX_ACCURATE_APPROXIMATE));
//this.mseCalculator = new GmseImageMseCalculator(properties.get(VISUAL_DATA), properties.get(BLINKING_DISABLED), properties.get(TRIX_CONTRAST_REDUCTION));
switch (properties.get(IMAGE_CONVERTER_TYPE)) {
case TRIX:
this.mseCalculator = new TrixImageMseCalculator(properties.get(VISUAL_DATA), properties.get(BLINKING_DISABLED), properties.get(TRIX_CONTRAST_REDUCTION), properties.get(TRIX_ACCURATE_APPROXIMATE));
break;
case GMSE:
this.mseCalculator = new GmseImageMseCalculator(properties.get(VISUAL_DATA), properties.get(BLINKING_DISABLED), properties.get(TRIX_CONTRAST_REDUCTION), properties.get(TRIX_ACCURATE_APPROXIMATE));
break;
}
localHolder.affect(IMAGE_CONVERTER);
}
if (localHolder.isAffected(IMAGE_CONVERTER) || this.converter == null) {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/pl/asie/zima/image/gui/ZimaFrontendSwing.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ Platform.MEGAZEUX, new ImageConverterRuleset(List.of())
);
private Map<ElementRule, JCheckBox> rulesetBoxEdit = new HashMap<>();
private ImageConverterRuleset customRuleset;
private JComboBox<ImageConverterType> converterTypeEdit;
private JSlider contrastReductionEdit;
private JButton contrastReductionReset;
private JSlider accurateApproximateEdit;
Expand Down Expand Up @@ -297,6 +298,9 @@ public ZimaFrontendSwing(byte[] defaultCharset, int[] defaultPalette, String zim
bindPropertyInt(this.profile.getProperties(), ZimaConversionProfile.MAX_BOARD_SIZE, this.maxBoardSizeEdit);
this.profile.getProperties().addChangeListener(ZimaConversionProfile.PLATFORM, (k, v) -> this.maxBoardSizeEdit.setModel(boardSizeModel(((Number) this.maxBoardSizeEdit.getValue()).intValue())));

appendTabRow(this.optionsBoardPanel, gbc, "Conversion algorithm", this.converterTypeEdit = createEnumComboBox(ImageConverterType.class));
bindPropertyEnum(this.profile.getProperties(), ZimaConversionProfile.IMAGE_CONVERTER_TYPE, this.converterTypeEdit);

appendTabRow(this.optionsBoardPanel, gbc, "Accurate/Approximate",
this.accurateApproximateEdit = new JSlider(JSlider.HORIZONTAL, 0, 1000, 0),
this.accurateApproximateReset = new JButton("Reset"));
Expand Down

0 comments on commit 6bc8c97

Please sign in to comment.