Skip to content

Commit 320d48c

Browse files
authored
Add files via upload
1 parent 9b89498 commit 320d48c

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

nQuant.Master/GilbertCurve.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,20 @@ private void DiffusePixel(int x, int y)
230230
else
231231
error[j] /= (float)(1 + Math.Sqrt(ditherMax));
232232
}
233+
234+
if (sortedByYDiff && saliencies == null && Math.Abs(error[j]) >= DITHER_MAX)
235+
unaccepted = true;
233236
}
234237

235238
if (unaccepted) {
236-
qPixels[bidx] = DitherPixel(x, y, c2, 1.25f);
239+
if (saliencies != null)
240+
qPixels[bidx] = DitherPixel(x, y, c2, 1.25f);
241+
else if (CIELABConvertor.Y_Diff(pixel, c2) > 3 && CIELABConvertor.U_Diff(pixel, c2) > 3) {
242+
var strength = 1 / 3f;
243+
c2 = BlueNoise.Diffuse(pixel, palette[qPixels[bidx]], strength, strength, x, y);
244+
qPixels[bidx] = ditherable.DitherColorIndex(palette, c2.ToArgb(), bidx);
245+
}
246+
237247
if (palette.Length > 256) {
238248
c2 = palette[qPixels[bidx]];
239249
qPixels[bidx] = (short)ditherable.GetColorIndex(c2.ToArgb());
@@ -255,7 +265,7 @@ private void Generate2d(int x, int y, int ax, int ay, int bx, int by) {
255265

256266
if (h == 1) {
257267
for (int i = 0; i < w; ++i){
258-
DiffusePixel(x, y);
268+
DiffusePixel(x, y);
259269
x += dax;
260270
y += day;
261271
}
@@ -264,7 +274,7 @@ private void Generate2d(int x, int y, int ax, int ay, int bx, int by) {
264274

265275
if (w == 1) {
266276
for (int i = 0; i < h; ++i){
267-
DiffusePixel(x, y);
277+
DiffusePixel(x, y);
268278
x += dbx;
269279
y += dby;
270280
}

0 commit comments

Comments
 (0)