Skip to content

Commit

Permalink
Merge pull request #3656 from cwisniew/fix-3652
Browse files Browse the repository at this point in the history
Fix scaling issues
  • Loading branch information
Phergus authored Sep 22, 2022
2 parents e0c302b + d01e652 commit 8ed1001
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 47 deletions.
7 changes: 4 additions & 3 deletions src/main/java/net/rptools/lib/image/ImageUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -437,8 +437,8 @@ public static Image resizeImage(Image image) {

public static Image resizeImage(Image image, int w, int h) {
// Default to 30x30 w/h not passed
// TODO: CDW return image.getScaledInstance(w, h, Image.SCALE_SMOOTH);
ResampleOp resampleOp = new ResampleOp(w, h);
ResampleOp resampleOp =
new ResampleOp(w, h, AppPreferences.getRenderQuality().getResampleOpFilter());
if (image instanceof BufferedImage) {
return resampleOp.filter((BufferedImage) image, null);
} else {
Expand Down Expand Up @@ -472,7 +472,8 @@ public static ImageIcon scaleImage(ImageIcon icon, int w, int h) {
* @return The scaled BufferedImage
*/
public static BufferedImage scaleBufferedImage(BufferedImage image, int width, int height) {
ResampleOp resampleOp = new ResampleOp(width, height, ResampleOp.FILTER_LANCZOS);
ResampleOp resampleOp =
new ResampleOp(width, height, AppPreferences.getRenderQuality().getResampleOpFilter());
return resampleOp.filter(image, null);
}
}
11 changes: 10 additions & 1 deletion src/main/java/net/rptools/maptool/client/AppPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package net.rptools.maptool.client;

import com.twelvemonkeys.image.ResampleOp;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
Expand Down Expand Up @@ -498,7 +499,7 @@ public static int getHaloLineWidth() {

private static final String KEY_RENDER_QUALITY = "renderScaleQuality";

private static final RenderQuality DEFAULT_RENDER_QUALITY = RenderQuality.HIGH;
private static final RenderQuality DEFAULT_RENDER_QUALITY = RenderQuality.MEDIUM;

public enum RenderQuality {
LOW,
Expand Down Expand Up @@ -546,6 +547,14 @@ public void setShrinkRenderingHints(Graphics2D d) {
}
}
}

public int getResampleOpFilter() {
return switch (this) {
case LOW -> ResampleOp.FILTER_POINT;
case MEDIUM -> ResampleOp.FILTER_TRIANGLE;
case HIGH -> ResampleOp.FILTER_QUADRATIC;
};
}
}

public static void setRenderQuality(RenderQuality quality) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2935,9 +2935,6 @@ protected void renderTokens(Graphics2D g, List<Token> tokenList, PlayerView view
protected void renderTokens(
Graphics2D g, List<Token> tokenList, PlayerView view, boolean figuresOnly) {
Graphics2D clippedG = g;
clippedG.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
clippedG.setRenderingHint(
RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);

boolean isGMView = view.isGMView(); // speed things up

Expand All @@ -2951,6 +2948,7 @@ protected void renderTokens(
Area visibleArea = new Area(g.getClipBounds());
visibleArea.intersect(visibleScreenArea);
clippedG.setClip(new GeneralPath(visibleArea));
AppPreferences.getRenderQuality().setRenderingHints(clippedG);
}
timer.stop("createClip");

Expand Down Expand Up @@ -3147,11 +3145,13 @@ protected void renderTokens(

// create a per token Graphics object - normally clipped, unless always visible
Area tokenCellArea = zone.getGrid().getTokenCellArea(tokenBounds);
Graphics2D tokenG =
(Graphics2D)
(isTokenInNeedOfClipping(token, tokenCellArea, isGMView)
? clippedG.create()
: g.create());
Graphics2D tokenG;
if (isTokenInNeedOfClipping(token, tokenCellArea, isGMView)) {
tokenG = (Graphics2D) clippedG.create();
} else {
tokenG = (Graphics2D) g.create();
AppPreferences.getRenderQuality().setRenderingHints(tokenG);
}

// Previous path
timer.start("renderTokens:ShowPath");
Expand Down
Loading

0 comments on commit 8ed1001

Please sign in to comment.