Skip to content

Commit

Permalink
Update GilbertCurve.java
Browse files Browse the repository at this point in the history
  • Loading branch information
mcychan authored Nov 15, 2023
1 parent a79d0b7 commit 78c445f
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/nQuant/j2se/GilbertCurve.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private GilbertCurve(final int width, final int height, final int[] pixels, fina
this.saliencies = saliencies;
boolean hasAlpha = weight < 0;
weight = Math.abs(weight);
margin = weight < .003 ? 12 : 6;
margin = weight < .0025 ? 12 : 6;
sortedByYDiff = palette.length >= 128 && (hasAlpha ? weight < .18 : weight >= .04);
errorq = sortedByYDiff ? new PriorityQueue<>(new Comparator<ErrorBox>() {

Expand All @@ -70,9 +70,10 @@ 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;
ditherMax = (hasAlpha || DITHER_MAX > 9) ? (byte) BitmapUtilities.sqr(Math.sqrt(DITHER_MAX) + edge) : DITHER_MAX;
final int density = palette.length > 16 ? 3200 : 1500;
if(palette.length / weight > 5000 && (weight > .045 || (weight > .01 && palette.length <= 64)))
ditherMax = (byte) BitmapUtilities.sqr(5 + edge);
else if(palette.length / weight < 3200 && palette.length >= 16 && palette.length < 256)
else if(palette.length / weight < density && palette.length >= 16 && palette.length < 256)
ditherMax = (byte) BitmapUtilities.sqr(5 + edge);
thresold = DITHER_MAX > 9 ? -112 : -64;
weights = new float[0];
Expand Down

0 comments on commit 78c445f

Please sign in to comment.