From 4ef1ebe0528d9744d6b3db39576ce10f2e451819 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Fri, 17 May 2019 21:11:45 +0700 Subject: [PATCH] Fix JDK8 patch --- jdk8.patch | 95 ++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 67 insertions(+), 28 deletions(-) diff --git a/jdk8.patch b/jdk8.patch index bfa0fb41..1e73b961 100644 --- a/jdk8.patch +++ b/jdk8.patch @@ -210,47 +210,84 @@ index da5c7a68..a1c25903 100644 // BEGIN COLOR diff --git a/source/net/filebot/ResourceManager.java b/source/net/filebot/ResourceManager.java -index 7e393cac..5eb3dadd 100644 +index 4aec2ab8..eb200e57 100644 --- a/source/net/filebot/ResourceManager.java +++ b/source/net/filebot/ResourceManager.java @@ -5,7 +5,6 @@ import static java.util.stream.Collectors.*; + import java.awt.GraphicsEnvironment; import java.awt.Image; - import java.awt.Toolkit; -import java.awt.image.BaseMultiResolutionImage; import java.awt.image.BufferedImage; import java.net.URL; import java.util.ArrayList; -@@ -56,22 +55,7 @@ public final class ResourceManager { +@@ -62,58 +61,14 @@ public final class ResourceManager { private static Image getMultiResolutionImage(URL[] resource) { try { +- // Load multi-resolution images only if necessary +- if (PRIMARY_SCALE_FACTOR == 1) { +- return ImageIO.read(resource[0]); +- } +- - List image = new ArrayList(resource.length); - for (URL r : resource) { - image.add(ImageIO.read(r)); - } - -- // Windows 10: use @2x image for non-integer scale factors 1.25 / 1.5 / 1.75 -- if (PRIMARY_SCALE_FACTOR != 1 && PRIMARY_SCALE_FACTOR != 2) { -- BufferedImage hidpi = image.get(image.size() - 1); -- if (PRIMARY_SCALE_FACTOR < 2) { -- image.add(1, scale(PRIMARY_SCALE_FACTOR, hidpi)); -- } else { -- image.add(scale(PRIMARY_SCALE_FACTOR, hidpi)); -- } +- // Windows 10: use down-scaled @2x image for non-integer scale factors 1.25 / 1.5 / 1.75 +- if (PRIMARY_SCALE_FACTOR > 1 && PRIMARY_SCALE_FACTOR < 2 && image.size() > 1) { +- image.add(1, scale(PRIMARY_SCALE_FACTOR / 2, image.get(1))); +- } else if (PRIMARY_SCALE_FACTOR > 2) { +- image.add(scale(PRIMARY_SCALE_FACTOR / 2, image.get(1))); - } - -- return new BaseMultiResolutionImage(image.toArray(new Image[0])); +- return new BaseMultiResolutionImage(image.toArray(Image[]::new)); + return ImageIO.read(resource[0]); } catch (Exception e) { throw new RuntimeException(e); } + } + + public static Image getMultiResolutionImage(BufferedImage baseImage, double baseScale) { +- if (PRIMARY_SCALE_FACTOR == 1 && baseScale == 1) { +- return baseImage; +- } +- +- List image = new ArrayList(3); +- image.add(baseImage); +- +- // use down-scaled @2x image as @1x base image +- if (baseScale > 1) { +- image.add(0, scale(1 / baseScale, baseImage)); +- } +- +- // Windows 10: use down-scaled @2x image for non-integer scale factors 1.25 / 1.5 / 1.75 +- if (PRIMARY_SCALE_FACTOR > 1 && PRIMARY_SCALE_FACTOR < baseScale) { +- image.add(1, scale(PRIMARY_SCALE_FACTOR / baseScale, baseImage)); +- } else if (PRIMARY_SCALE_FACTOR > baseScale) { +- image.add(scale(PRIMARY_SCALE_FACTOR / baseScale, baseImage)); +- } +- +- return new BaseMultiResolutionImage(image.toArray(Image[]::new)); +- } +- +- private static final double PRIMARY_SCALE_FACTOR = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().getDefaultTransform().getScaleX(); +- +- private static BufferedImage scale(double scale, BufferedImage image) { +- int w = (int) (scale * image.getWidth()); +- int h = (int) (scale * image.getHeight()); +- return Scalr.resize(image, Method.ULTRA_QUALITY, Mode.FIT_TO_WIDTH, w, h, Scalr.OP_ANTIALIAS); ++ return baseImage; + } + + } diff --git a/source/net/filebot/ThumbnailServices.java b/source/net/filebot/ThumbnailServices.java -index 515f71f2..1aab0ffd 100644 +index f7241bd2..fae11e64 100644 --- a/source/net/filebot/ThumbnailServices.java +++ b/source/net/filebot/ThumbnailServices.java -@@ -7,10 +7,6 @@ import static net.filebot.util.RegularExpressions.*; - +@@ -10,10 +10,6 @@ import java.awt.image.BufferedImage; + import java.io.ByteArrayInputStream; import java.net.URI; import java.net.URL; -import java.net.http.HttpClient; @@ -260,7 +297,17 @@ index 515f71f2..1aab0ffd 100644 import java.nio.ByteBuffer; import java.util.HashMap; import java.util.List; -@@ -55,34 +51,7 @@ public enum ThumbnailServices implements ThumbnailProvider { +@@ -62,9 +58,6 @@ public enum ThumbnailServices implements ThumbnailProvider { + + private final Resource> index = Resource.lazy(this::getIndex); + +- // shared HTTP Client instance for all thumbnail requests +- private static final Resource http = Resource.lazy(HttpClient::newHttpClient); +- + public byte[][] getThumbnails(int[] ids, ResolutionVariant variant) throws Exception { + Cache cache = getCache(variant); + byte[][] response = new byte[ids.length][]; +@@ -72,34 +65,7 @@ public enum ThumbnailServices implements ThumbnailProvider { synchronized (index) { // check cache for (int i = 0; i < response.length; i++) { @@ -272,10 +319,10 @@ index 515f71f2..1aab0ffd 100644 - - for (int i = 0; i < response.length; i++) { - if (response[i] == null && index.get().contains(ids[i])) { -- URI r = URI.create(getResource(ids[i] + ".png")); -- request[i] = http.get().sendAsync(HttpRequest.newBuilder(r).build(), BodyHandlers.ofByteArray()); +- String resource = getThumbnailResource(ids[i], variant); +- request[i] = http.get().sendAsync(HttpRequest.newBuilder(URI.create(resource)).build(), BodyHandlers.ofByteArray()); - -- debug.fine(format("Request %s", r)); +- debug.fine(format("Request %s", resource)); - } - } - @@ -292,18 +339,10 @@ index 515f71f2..1aab0ffd 100644 - debug.warning(e::toString); - } - } -+ response[i] = cache.bytes(ids[i], k -> new URL(getResource(ids[k] + ".png"))).expire(Cache.ONE_MONTH).get(); ++ response[i] = cache.bytes(ids[i], id -> new URL(getThumbnailResource(id, ResolutionVariant.NORMAL))).expire(Cache.ONE_MONTH).get(); } return response; -@@ -108,7 +77,4 @@ public enum ThumbnailServices implements ThumbnailProvider { - return icons; - } - -- // shared HTTP Client instance for all thumbnail requests -- private static final Resource http = Resource.lazy(HttpClient::newHttpClient); -- - } diff --git a/source/net/filebot/UserFiles.java b/source/net/filebot/UserFiles.java index bb0f65de..25b687ab 100644 --- a/source/net/filebot/UserFiles.java