Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
mcychan authored Feb 3, 2025
1 parent 048eefd commit 3a47ffb
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions nQuant.Master/GilbertCurve.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private void DitherPixel(int x, int y)
int a_pix = (int)Math.Min(Byte.MaxValue, Math.Max(error[3], 0.0));

Color c2 = Color.FromArgb(a_pix, r_pix, g_pix, b_pix);
if (saliencies != null && (palette.Length < 3|| margin > 6))
if (saliencies != null)
{
var strength = 1 / 3f;
var beta = palette.Length > 8 ? .7f : 1;
Expand All @@ -124,11 +124,15 @@ private void DitherPixel(int x, int y)
else if (palette.Length <= 8 || CIELABConvertor.Y_Diff(pixel, c2) < (2 * acceptedDiff))
c2 = BlueNoise.Diffuse(pixel, palette[qPixels[bidx]], beta * .5f / saliencies[bidx], strength, x, y);

if (palette.Length > 8 && (CIELABConvertor.Y_Diff(pixel, c2) > (beta * acceptedDiff) || CIELABConvertor.U_Diff(pixel, c2) < (2 * acceptedDiff))) {
var kappa = saliencies[bidx] < .25f ? beta * .4f * saliencies[bidx] : beta * .4f / saliencies[bidx];
var c1 = Color.FromArgb(a_pix, r_pix, g_pix, b_pix);
c2 = BlueNoise.Diffuse(c1, palette[qPixels[bidx]], kappa, strength, x, y);
if (palette.Length < 3|| margin > 6) {
if (palette.Length > 8 && (CIELABConvertor.Y_Diff(pixel, c2) > (beta * acceptedDiff) || CIELABConvertor.U_Diff(pixel, c2) < (2 * acceptedDiff))) {
var kappa = saliencies[bidx] < .25f ? beta * .4f * saliencies[bidx] : beta * .4f / saliencies[bidx];
var c1 = Color.FromArgb(a_pix, r_pix, g_pix, b_pix);
c2 = BlueNoise.Diffuse(c1, palette[qPixels[bidx]], kappa, strength, x, y);
}
}
else if (palette.Length > 8 && (CIELABConvertor.Y_Diff(pixel, c2) > (beta * acceptedDiff) || CIELABConvertor.U_Diff(pixel, c2) < acceptedDiff))
c2 = Color.FromArgb(a_pix, r_pix, g_pix, b_pix);

int offset = ditherable.GetColorIndex(c2.ToArgb());
if (lookup[offset] == 0)
Expand Down

0 comments on commit 3a47ffb

Please sign in to comment.