@@ -126,11 +126,11 @@ namespace PnnLABQuant
126126 return [](const float & cnt) { return (float )(int )pow (cnt, 0.75 ); };
127127 if (nMaxColors < 64 )
128128 return [](const float & cnt) {
129- return (float )(int )_sqrt (cnt);
129+ return (float )(int )_sqrt (cnt);
130130 };
131131 return [](const float & cnt) {
132132 return (float )_sqrt (cnt);
133- };
133+ };
134134 }
135135 return [](const float & cnt) { return cnt; };
136136 }
@@ -159,7 +159,7 @@ namespace PnnLABQuant
159159 tb.Ac += lab1.A ;
160160 tb.Bc += lab1.B ;
161161 tb.cnt += 1.0 ;
162- if (!saliencies.empty ())
162+ if (!saliencies.empty ())
163163 saliencies[i] = saliencyBase + (1 - saliencyBase) * lab1.L / 100 .0f * lab1.alpha / 255 .0f ;
164164 }
165165
@@ -184,7 +184,7 @@ namespace PnnLABQuant
184184 quan_rt = -1 ;
185185
186186 weight = min (0.9 , nMaxColors * 1.0 / maxbins);
187- if ((nMaxColors < 16 && weight < .0075 ) || weight < .001 || (weight > .0014 && weight < .0022 ))
187+ if ((nMaxColors < 16 && weight < .0075 ) || weight < .001 || (weight > .0015 && weight < .0022 ))
188188 quan_rt = 2 ;
189189 if (weight < (isGA ? .03 : .04 ) && PG < 1 && PG >= coeffs[0 ][1 ]) {
190190 if (nMaxColors >= 64 )
@@ -223,9 +223,9 @@ namespace PnnLABQuant
223223 }
224224 bins[j].cnt = quanFn (bins[j].cnt );
225225
226- const bool texicab = proportional > . 025 ;
227-
228- if (!isGA) {
226+ const bool texicab = quan_rt < 2 ;
227+
228+ if (!isGA) {
229229 if (hasSemiTransparency)
230230 ratio = .5 ;
231231 else if (quan_rt != 0 && nMaxColors < 64 ) {
@@ -246,7 +246,7 @@ namespace PnnLABQuant
246246 ratio = min (1.0 , 1 - 1.0 / proportional);
247247 else
248248 ratio = min (1.0 , max (.98 , 1 - weight * .7 ));
249-
249+
250250 if (!hasSemiTransparency && quan_rt < 0 )
251251 ratio = min (1.0 , weight * exp (1.947 ));
252252 }
@@ -280,14 +280,14 @@ namespace PnnLABQuant
280280 /* Use heap to find which bins to merge */
281281 for (;;) {
282282 auto & tb = bins[b1 = heap[1 ]]; /* One with least error */
283- /* Is stored error up to date? */
283+ /* Is stored error up to date? */
284284 if ((tb.tm >= tb.mtm ) && (bins[tb.nn ].mtm <= tb.tm ))
285285 break ;
286286 if (tb.mtm == USHRT_MAX ) /* Deleted node */
287287 b1 = heap[1 ] = heap[heap[0 ]--];
288288 else /* Too old error value */
289289 {
290- find_nn (bins.data (), b1, texicab && proportional < 1 );
290+ find_nn (bins.data (), b1, texicab);
291291 tb.tm = i;
292292 }
293293 /* Push slot down */
@@ -350,7 +350,7 @@ namespace PnnLABQuant
350350 double mindist = 1e100 ;
351351 CIELABConvertor::Lab lab1, lab2;
352352 getLab (c, lab1);
353-
353+
354354 for (UINT i = k; i < nMaxColors; ++i) {
355355 Color c2 (pPalette[i]);
356356 auto curdist = hasSemiTransparency ? sqr (c2.GetA () - c.GetA ()) / exp (1.5 ) : 0 ;
@@ -434,7 +434,7 @@ namespace PnnLABQuant
434434 double mindist = 1e100 ;
435435 CIELABConvertor::Lab lab1, lab2;
436436 getLab (c, lab1);
437-
437+
438438 for (UINT i = k; i < nMaxColors; ++i) {
439439 Color c2 (pPalette[i]);
440440 getLab (c2, lab2);
@@ -496,7 +496,7 @@ namespace PnnLABQuant
496496
497497 for (UINT k = 0 ; k < nMaxColors; ++k) {
498498 Color c2 (pPalette[k]);
499-
499+
500500 auto err = PR * (1 - ratio) * sqr (c2.GetR () - c.GetR ());
501501 if (err >= closest[3 ])
502502 continue ;
@@ -516,11 +516,11 @@ namespace PnnLABQuant
516516 err += ratio * sqr (coeffs[i][0 ] * (c2.GetR () - c.GetR ()));
517517 if (err >= closest[3 ])
518518 break ;
519-
519+
520520 err += ratio * sqr (coeffs[i][1 ] * (c2.GetG () - c.GetG ()));
521521 if (err >= closest[3 ])
522522 break ;
523-
523+
524524 err += ratio * sqr (coeffs[i][2 ] * (c2.GetB () - c.GetB ()));
525525 if (err >= closest[3 ])
526526 break ;
@@ -560,9 +560,9 @@ namespace PnnLABQuant
560560 {
561561 auto NearestColorIndex = [this , nMaxColors](const ARGB * pPalette, const UINT nMaxColors, ARGB argb, const UINT pos) -> unsigned short {
562562 return closestColorIndex (pPalette, nMaxColors, argb, pos);
563- };
563+ };
564+
564565
565-
566566 if (dither)
567567 return dither_image (pixels, pPalette, nMaxColors, NearestColorIndex, hasSemiTransparency, m_transparentPixelIndex, qPixels, width, height);
568568
@@ -588,7 +588,7 @@ namespace PnnLABQuant
588588 bool PnnLABQuantizer::hasAlpha () const {
589589 return m_transparentPixelIndex >= 0 ;
590590 }
591-
591+
592592 void PnnLABQuantizer::setRatio (double ratioX, double ratioY) {
593593 ratio = min (1.0 , ratioX);
594594 this ->ratioY = min (1.0 , ratioY);
@@ -623,14 +623,14 @@ namespace PnnLABQuant
623623
624624 auto GetColorIndex = [&](const Color& c) -> int {
625625 return GetARGBIndex (c, hasSemiTransparency, hasAlpha ());
626- };
626+ };
627627 auto NearestColorIndex = [this , nMaxColors](const ARGB * pPalette, const UINT nMaxColors, ARGB argb, const UINT pos) -> unsigned short {
628628 if (hasAlpha () || nMaxColors <= 4 )
629629 return nearestColorIndex (pPalette, nMaxColors, argb, pos);
630630 if (IsGA () && nMaxColors < 16 )
631631 return hybridColorIndex (pPalette, nMaxColors, argb, pos);
632632 return closestColorIndex (pPalette, nMaxColors, argb, pos);
633- };
633+ };
634634
635635 const auto bitmapHeight = pixels.size () / bitmapWidth;
636636
@@ -686,7 +686,7 @@ namespace PnnLABQuant
686686 else if (pPalette[k] != m_transparentColor)
687687 swap (pPalette[0 ], pPalette[1 ]);
688688 }
689-
689+
690690 const auto & pPal = pPalette;
691691 return QuantizeImageByPal (pixels, bitmapWidth, pPal, pDest, nMaxColors, dither);
692692 }
@@ -695,18 +695,18 @@ namespace PnnLABQuant
695695 {
696696 const auto bitmapWidth = pSource->GetWidth ();
697697 const auto bitmapHeight = pSource->GetHeight ();
698- const auto area = (size_t ) (bitmapWidth * bitmapHeight);
698+ const auto area = (size_t )(bitmapWidth * bitmapHeight);
699699
700700 vector<ARGB > pixels (area);
701701 int semiTransCount = 0 ;
702702 grabPixels (pSource, pixels, nMaxColors, hasSemiTransparency);
703-
703+
704704 if (nMaxColors > 256 ) {
705705 auto pPalettes = make_unique<ARGB []>(nMaxColors);
706706 auto pPalette = pPalettes.get ();
707707 return QuantizeImage (pixels, bitmapWidth, pPalette, pDest, nMaxColors, dither);
708708 }
709-
709+
710710 auto pPaletteBytes = make_unique<BYTE []>(sizeof (ColorPalette) + nMaxColors * sizeof (ARGB ));
711711 auto pPalette = (ColorPalette*)pPaletteBytes.get ();
712712 pPalette->Count = nMaxColors;
0 commit comments