Skip to content

Commit 5358b43

Browse files
authored
Add files via upload
1 parent 1da5fa2 commit 5358b43

3 files changed

Lines changed: 5 additions & 22 deletions

File tree

nQuant.Master/GilbertCurve.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ private int DitherPixel(int x, int y, Color c2, float beta)
133133
if (palette.Length < 3 || margin > 6) {
134134
var delta = (weight > .0015 && weight < .0025) ? beta : Math.PI;
135135
if (palette.Length > 4 && (CIELABConvertor.Y_Diff(pixel, c2) > (delta * acceptedDiff) || CIELABConvertor.U_Diff(pixel, c2) < (margin * acceptedDiff))) {
136-
var kappa = saliencies[bidx] < .4f ? beta * .4f * saliencies[bidx] : beta * .4f / saliencies[bidx];
137-
var c1 = saliencies[bidx] < .4f ? pixel : Color.FromArgb(a_pix, r_pix, g_pix, b_pix);
136+
var kappa = saliencies[bidx] < .4f ? beta * .4f / saliencies[bidx] : beta * .4f / saliencies[bidx];
137+
var c1 = saliencies[bidx] < .6f ? pixel : Color.FromArgb(a_pix, r_pix, g_pix, b_pix);
138138
c2 = BlueNoise.Diffuse(c1, palette[qPixelIndex], kappa, strength, x, y);
139139
}
140140
}

nQuant.Master/PnnLABQuantizer.cs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ private void Find_nn(Pnnbin[] bins, int idx, bool texicab)
126126
protected override QuanFn GetQuanFn(int nMaxColors, short quan_rt) {
127127
if (quan_rt > 0) {
128128
if (quan_rt > 1)
129-
return cnt => (int) Math.Pow(cnt, .75);
129+
return cnt => (float) Math.Pow(cnt, .75);
130130
if (nMaxColors < 64)
131-
return cnt => (int)Math.Sqrt(cnt);
131+
return cnt => (float)Math.Sqrt(cnt);
132132

133133
return cnt => (float)Math.Sqrt(cnt);
134134
}
@@ -630,7 +630,7 @@ internal Bitmap QuantizeImage(int[] pixels, int bitmapWidth, int nMaxColors, boo
630630
var bitmapHeight = pixels.Length / bitmapWidth;
631631

632632
var dest = new Bitmap(bitmapWidth, bitmapHeight, pixelFormat);
633-
if(m_palette == null) {
633+
if (m_palette == null) {
634634
var palettes = dest.Palette.Entries;
635635
if (palettes.Length != nMaxColors)
636636
palettes = new Color[nMaxColors];
@@ -655,15 +655,6 @@ internal Bitmap QuantizeImage(int[] pixels, int bitmapWidth, int nMaxColors, boo
655655

656656
var qPixels = Dither(pixels, m_palette, bitmapWidth, bitmapHeight, dither);
657657

658-
if (HasAlpha && nMaxColors <= 256)
659-
{
660-
var k = qPixels[m_transparentPixelIndex];
661-
if (nMaxColors > 2)
662-
m_palette[k] = m_transparentColor;
663-
else if (m_palette[k] != m_transparentColor)
664-
BitmapUtilities.Swap(ref m_palette[0], ref m_palette[1]);
665-
}
666-
667658
if (nMaxColors > 256)
668659
return BitmapUtilities.ProcessImagePixels(dest, qPixels, hasSemiTransparency, m_transparentPixelIndex);
669660

nQuant.Master/PnnQuantizer.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -475,14 +475,6 @@ public Bitmap QuantizeImage(Bitmap source, PixelFormat pixelFormat, int nMaxColo
475475

476476
var qPixels = Dither(pixels, m_palette, bitmapWidth, bitmapHeight, dither);
477477

478-
if (HasAlpha && nMaxColors <= 256)
479-
{
480-
var k = qPixels[m_transparentPixelIndex];
481-
if (nMaxColors > 2)
482-
m_palette[k] = m_transparentColor;
483-
else if (m_palette[k] != m_transparentColor)
484-
BitmapUtilities.Swap(ref m_palette[0], ref m_palette[1]);
485-
}
486478
closestMap.Clear();
487479
nearestMap.Clear();
488480

0 commit comments

Comments
 (0)