From 590a3ea6951070651d5e6a4ffe19d89cb21bea42 Mon Sep 17 00:00:00 2001 From: Miller Cy Chan Date: Thu, 6 Feb 2025 14:23:16 +0800 Subject: [PATCH] Add files via upload --- src/nQuant/j2se/GilbertCurve.java | 4 ++-- src/nQuant/j2se/PnnLABQuantizer.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/nQuant/j2se/GilbertCurve.java b/src/nQuant/j2se/GilbertCurve.java index 0b762de..4f26a13 100644 --- a/src/nQuant/j2se/GilbertCurve.java +++ b/src/nQuant/j2se/GilbertCurve.java @@ -56,9 +56,9 @@ private GilbertCurve(final int width, final int height, final int[] pixels, fina this.ditherable = ditherable; this.saliencies = saliencies; boolean hasAlpha = weight < 0; - sortedByYDiff = palette.length >= 128 && (hasAlpha ? weight < .18 : weight >= .052); weight = Math.abs(weight); margin = weight < .0025 ? 12 : weight < .004 ? 8 : 6; + sortedByYDiff = palette.length >= 128 && (hasAlpha ? weight < .18 : weight >= .052); beta = palette.length > 8 ? palette.length > 24 ? .25f : .7f : 1; if(palette.length > 64 || weight > .02) beta *= .4f; @@ -74,7 +74,7 @@ public int compare(ErrorBox o1, ErrorBox o2) { DITHER_MAX = weight < .01 ? (weight > .0025) ? (byte) 25 : 16 : 9; double edge = hasAlpha ? 1 : Math.exp(weight) - .25; - double deviation = weight > .0025 ? -.25 : 1; + double deviation = !hasAlpha && weight > .0025 ? -.25 : 1; ditherMax = (hasAlpha || DITHER_MAX > 9) ? (byte) BitmapUtilities.sqr(Math.sqrt(DITHER_MAX) + edge * deviation) : DITHER_MAX; final int density = palette.length > 16 ? 3200 : 1500; if(palette.length / weight > 5000 && (weight > .045 || (weight > .01 && palette.length <= 64))) diff --git a/src/nQuant/j2se/PnnLABQuantizer.java b/src/nQuant/j2se/PnnLABQuantizer.java index 83f8bca..8baa262 100644 --- a/src/nQuant/j2se/PnnLABQuantizer.java +++ b/src/nQuant/j2se/PnnLABQuantizer.java @@ -531,7 +531,7 @@ protected short[] dither(Color[] palette, int width, int height, boolean dither) if(hasSemiTransparency) weight *= -1; - if(dither && saliencies == null && weight < .052) { + if(dither && !hasSemiTransparency && saliencies == null && weight < .052) { saliencies = new float[pixels.length]; float saliencyBase = .1f;