@@ -439,7 +439,7 @@ namespace PnnLABQuant
439439 Color c2 (pPalette[i]);
440440 getLab (c2, lab2);
441441
442- auto curdist = 0. 0 ;
442+ auto curdist = hasSemiTransparency ? sqr (c2. GetA () - c. GetA ()) / exp ( 1.5 ) : 0 ;
443443 if (abs (lab2.L - lab1.L ) < nMaxColors || saliencies[pos] < .2 || saliencies[pos] > .8 ) {
444444 curdist += sqr (lab2.L - lab1.L );
445445 if (curdist > mindist)
@@ -551,7 +551,8 @@ namespace PnnLABQuant
551551 idx = 0 ;
552552
553553 auto MAX_ERR = nMaxColors;
554- if (closest[idx + 2 ] >= MAX_ERR || (hasAlpha () && closest[idx] == 0 ))
554+ Color pixel (pPalette[closest[idx]]);
555+ if (closest[idx + 2 ] >= MAX_ERR || closest[idx] == 0 || pixel.GetA () < c.GetA ())
555556 return nearestColorIndex (pPalette, nMaxColors, argb, pos);
556557 return closest[idx];
557558 }
@@ -562,7 +563,6 @@ namespace PnnLABQuant
562563 return closestColorIndex (pPalette, nMaxColors, argb, pos);
563564 };
564565
565-
566566 if (dither)
567567 return dither_image (pixels, pPalette, nMaxColors, NearestColorIndex, hasSemiTransparency, m_transparentPixelIndex, qPixels, width, height);
568568
@@ -625,7 +625,7 @@ namespace PnnLABQuant
625625 return GetARGBIndex (c, hasSemiTransparency, hasAlpha ());
626626 };
627627 auto NearestColorIndex = [this , nMaxColors](const ARGB * pPalette, const UINT nMaxColors, ARGB argb, const UINT pos) -> unsigned short {
628- if (hasAlpha () || nMaxColors <= 4 )
628+ if (nMaxColors <= 4 )
629629 return nearestColorIndex (pPalette, nMaxColors, argb, pos);
630630 if (IsGA () && nMaxColors < 16 )
631631 return hybridColorIndex (pPalette, nMaxColors, argb, pos);
0 commit comments