Skip to content

Commit

Permalink
fixes ninepatch test
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickfav committed Mar 3, 2017
1 parent cb1f5f2 commit 20af54f
Show file tree
Hide file tree
Showing 10 changed files with 417 additions and 409 deletions.
18 changes: 9 additions & 9 deletions src/main/java/at/favre/tools/dconvert/arg/EScalingAlgorithm.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import at.favre.tools.dconvert.converters.scaling.NaiveGraphics2dAlgorithm;
import at.favre.tools.dconvert.converters.scaling.ProgressiveAlgorithm;
import at.favre.tools.dconvert.converters.scaling.ResambleAlgorithm;
import at.favre.tools.dconvert.converters.scaling.ResampleAlgorithm;
import at.favre.tools.dconvert.converters.scaling.ScaleAlgorithm;
import com.mortennobel.imagescaling.ResampleFilters;

Expand All @@ -16,14 +16,14 @@
*/
public enum EScalingAlgorithm {

LANCZOS1(new ResambleAlgorithm(new ResambleAlgorithm.LanczosFilter(1)), "lanczos1", new Type[]{Type.DOWNSCALING, Type.UPSCALING}, false),
LANCZOS2(new ResambleAlgorithm(new ResambleAlgorithm.LanczosFilter(2)), "lanczos2", new Type[]{Type.DOWNSCALING, Type.UPSCALING}, true),
LANCZOS3(new ResambleAlgorithm(new ResambleAlgorithm.LanczosFilter(3)), "lanczos3", new Type[]{Type.DOWNSCALING, Type.UPSCALING}, true),
LANCZOS4(new ResambleAlgorithm(new ResambleAlgorithm.LanczosFilter(4)), "lanczos4", new Type[]{Type.DOWNSCALING, Type.UPSCALING}, false),
LANCZOS5(new ResambleAlgorithm(new ResambleAlgorithm.LanczosFilter(5)), "lanczos5", new Type[]{Type.DOWNSCALING, Type.UPSCALING}, false),
MITCHELL(new ResambleAlgorithm(ResampleFilters.getMitchellFilter()), "mitchell", new Type[]{Type.DOWNSCALING, Type.UPSCALING}, true),
BSPLINE(new ResambleAlgorithm(ResampleFilters.getBSplineFilter()), "bspline", new Type[]{Type.DOWNSCALING, Type.UPSCALING}, false),
HERMITE(new ResambleAlgorithm(ResampleFilters.getHermiteFilter()), "hermite", new Type[]{Type.DOWNSCALING, Type.UPSCALING}, false),
LANCZOS1(new ResampleAlgorithm(new ResampleAlgorithm.LanczosFilter(1)), "lanczos1", new Type[]{Type.DOWNSCALING, Type.UPSCALING}, false),
LANCZOS2(new ResampleAlgorithm(new ResampleAlgorithm.LanczosFilter(2)), "lanczos2", new Type[]{Type.DOWNSCALING, Type.UPSCALING}, true),
LANCZOS3(new ResampleAlgorithm(new ResampleAlgorithm.LanczosFilter(3)), "lanczos3", new Type[]{Type.DOWNSCALING, Type.UPSCALING}, true),
LANCZOS4(new ResampleAlgorithm(new ResampleAlgorithm.LanczosFilter(4)), "lanczos4", new Type[]{Type.DOWNSCALING, Type.UPSCALING}, false),
LANCZOS5(new ResampleAlgorithm(new ResampleAlgorithm.LanczosFilter(5)), "lanczos5", new Type[]{Type.DOWNSCALING, Type.UPSCALING}, false),
MITCHELL(new ResampleAlgorithm(ResampleFilters.getMitchellFilter()), "mitchell", new Type[]{Type.DOWNSCALING, Type.UPSCALING}, true),
BSPLINE(new ResampleAlgorithm(ResampleFilters.getBSplineFilter()), "bspline", new Type[]{Type.DOWNSCALING, Type.UPSCALING}, false),
HERMITE(new ResampleAlgorithm(ResampleFilters.getHermiteFilter()), "hermite", new Type[]{Type.DOWNSCALING, Type.UPSCALING}, false),
NEAREST_NEIGHBOR(new NaiveGraphics2dAlgorithm(RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR), "nearestNeighbor", new Type[]{Type.DOWNSCALING, Type.UPSCALING}, true),
BILINEAR_PROGRESSIVE(new ProgressiveAlgorithm(ProgressiveAlgorithm.Type.NOBEL_BILINEAR), "bilinearProgressive", new Type[]{Type.DOWNSCALING}, true),
BICUBIC_PROGRESSIVE(new ProgressiveAlgorithm(ProgressiveAlgorithm.Type.NOBEL_BICUBUC), "bicubicProgressive", new Type[]{Type.DOWNSCALING}, true),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public Result convert(File srcImage, Arguments args) {

return new Result(log.toString(), allResultingFiles);
} catch (Exception e) {
e.printStackTrace();
return new Result(null, e, Collections.emptyList());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private BufferedImage scaleProgressiveLanczos(BufferedImage imageToScale, int ds
if (dstWidth < (imageToScale.getWidth() / 2) && dstHeight < (imageToScale.getHeight() / 2)) {
return new ThumbnailnatorProgressiveAlgorithm(RenderingHints.VALUE_INTERPOLATION_BILINEAR).scale(imageToScale, dstWidth, dstHeight);
} else {
return new ResambleAlgorithm(new ResambleAlgorithm.LanczosFilter(radius)).scale(imageToScale, dstWidth, dstHeight);
return new ResampleAlgorithm(new ResampleAlgorithm.LanczosFilter(radius)).scale(imageToScale, dstWidth, dstHeight);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
import java.awt.image.BufferedImage;

/**
* Wrapper for Resamble Algos from Nobel's Lib
* Wrapper for Resample Algos from Nobel's Lib
*/
public class ResambleAlgorithm implements ScaleAlgorithm {
public class ResampleAlgorithm implements ScaleAlgorithm {
private ResampleFilter filter;

public ResambleAlgorithm(ResampleFilter filter) {
public ResampleAlgorithm(ResampleFilter filter) {
this.filter = filter;
}

Expand Down Expand Up @@ -61,15 +61,15 @@ public String getName() {

@Override
public String toString() {
return "ResambleAlgorithm[" + filter.getName() + ']';
return "ResampleAlgorithm[" + filter.getName() + ']';
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

ResambleAlgorithm that = (ResambleAlgorithm) o;
ResampleAlgorithm that = (ResampleAlgorithm) o;

return filter != null ? filter.equals(that.filter) : that.filter == null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package at.favre.tools.dconvert.util;

import at.favre.tools.dconvert.converters.scaling.ScaleAlgorithm;
import at.favre.tools.dconvert.converters.scaling.ThumbnailnatorProgressiveAlgorithm;
import at.favre.tools.dconvert.exceptions.NinePatchException;

import java.awt.*;
Expand All @@ -33,6 +34,7 @@
public class NinePatchScaler {

private ScaleAlgorithm algorithm;
private ScaleAlgorithm borderScalerAlgorithm = new ThumbnailnatorProgressiveAlgorithm(RenderingHints.VALUE_INTERPOLATION_BILINEAR);

public BufferedImage scale(BufferedImage inputImage, Dimension dimensions, ScaleAlgorithm algorithm) throws NinePatchException {
this.algorithm = algorithm;
Expand Down Expand Up @@ -121,7 +123,7 @@ private BufferedImage generateBordersImage(BufferedImage source, int trimedWidth
private BufferedImage resizeBorder(final BufferedImage border, int targetWidth, int targetHeight) {
if (targetWidth > border.getWidth()
|| targetHeight > border.getHeight()) {
BufferedImage endImage = algorithm.scale(border, targetWidth, targetHeight);
BufferedImage endImage = borderScalerAlgorithm.scale(border, targetWidth, targetHeight);
this.enforceBorderColors(endImage);
return endImage;
}
Expand Down
Binary file added src/main/resources/img/ninepatch_account.9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/img/ninepatch_bubble.9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 20af54f

Please sign in to comment.