Skip to content

Commit d145841

Browse files
authored
Add files via upload
1 parent 682092d commit d145841

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

nQuant.Master/GilbertCurve.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ private GilbertCurve(int width, int height, int[] pixels, Color[] palette, int[]
8888
beta = .55f;
8989
else if (palette.Length > 16 && palette.Length <= 32 && weight < .005)
9090
beta += (float)(.05 + weight * palette.Length);
91-
}
91+
}
9292
else
9393
beta *= .95f;
9494

@@ -230,7 +230,7 @@ private void DiffusePixel(int x, int y)
230230
if (saliencies != null && dither && !sortedByYDiff && (!m_hasAlpha || pixel.A < a_pix))
231231
{
232232
if ((palette.Length >= 256 && saliencies[bidx] > .99f) || (m_hasAlpha && (pixel.A - a_pix) < (.5 * margin)))
233-
qPixels[bidx] = ditherable.DitherColorIndex(palette, c2.ToArgb(), bidx);
233+
qPixels[bidx] = ditherable.DitherColorIndex(palette, c2.ToArgb(), bidx);
234234
else
235235
qPixels[bidx] = DitherPixel(x, y, c2, beta);
236236
}
@@ -266,6 +266,7 @@ private void DiffusePixel(int x, int y)
266266
var denoise = palette.Length > 2;
267267
var diffuse = BlueNoise.TELL_BLUE_NOISE[bidx & 4095] > thresold;
268268
error.yDiff = sortedByYDiff ? CIELABConvertor.Y_Diff(pixel, c2) : 1;
269+
var illusion = !diffuse && BlueNoise.TELL_BLUE_NOISE[(int)(error.yDiff * 4096) & 4095] > thresold;
269270

270271
var unaccepted = false;
271272
var errLength = denoise ? error.Length - 1 : 0;
@@ -285,8 +286,10 @@ private void DiffusePixel(int x, int y)
285286

286287
if (diffuse)
287288
error[j] = (float)Math.Tanh(error[j] / maxErr * 20) * (ditherMax - 1);
289+
else if (illusion)
290+
error[j] = (float)(error[j] / maxErr * error.yDiff) * (ditherMax - 1);
288291
else
289-
unaccepted = true;
292+
error[j] /= (float)(1 + Math.Sqrt(ditherMax));
290293
}
291294

292295
if (sortedByYDiff && saliencies == null && Math.Abs(error[j]) >= DITHER_MAX)

0 commit comments

Comments
 (0)