@@ -9,7 +9,6 @@ Copyright (c) 2021 - 2025 Miller Cy Chan
99
1010#include < memory>
1111#include < list>
12- #include < algorithm>
1312
1413namespace Peano
1514{
@@ -49,7 +48,6 @@ namespace Peano
4948 GetColorIndexFn m_getColorIndexFn;
5049 list<ErrorBox> errorq;
5150 vector<float > m_weights;
52- unsigned short * m_lookup;
5351 static BYTE DITHER_MAX = 9 , ditherMax;
5452 static int margin, thresold;
5553 static const float BLOCK_SIZE = 343 .0f ;
@@ -164,10 +162,7 @@ namespace Peano
164162 if (beta > 1 && CIELABConvertor::Y_Diff (pixel, c2) > DITHER_MAX )
165163 c2 = Color::MakeARGB (a_pix, r_pix, g_pix, b_pix);
166164
167- int offset = m_getColorIndexFn (c2);
168- if (!m_lookup[offset])
169- m_lookup[offset] = m_ditherFn (m_pPalette, m_nMaxColor, c2.GetValue (), bidx) + 1 ;
170- return m_lookup[offset] - 1 ;
165+ return m_ditherFn (m_pPalette, m_nMaxColor, c2.GetValue (), bidx);
171166 }
172167
173168 void diffusePixel (int x, int y)
@@ -204,10 +199,7 @@ namespace Peano
204199 }
205200 else if (m_nMaxColor <= 32 && a_pix > 0xF0 )
206201 {
207- int offset = m_getColorIndexFn (c2);
208- if (!m_lookup[offset])
209- m_lookup[offset] = m_ditherFn (m_pPalette, m_nMaxColor, c2.GetValue (), bidx) + 1 ;
210- qPixelIndex = m_lookup[offset] - 1 ;
202+ qPixelIndex = m_ditherFn (m_pPalette, m_nMaxColor, c2.GetValue (), bidx);
211203
212204 int acceptedDiff = max (2 , m_nMaxColor - margin);
213205 if (m_saliencies != nullptr && (CIELABConvertor::Y_Diff (pixel, c2) > acceptedDiff || CIELABConvertor::U_Diff (pixel, c2) > (2 * acceptedDiff))) {
@@ -370,16 +362,16 @@ namespace Peano
370362 beta += .1f ;
371363 if (m_nMaxColor >= 64 && (weight > .012 && weight < .0125 ) || (weight > .025 && weight < .03 ))
372364 beta *= 2 ;
365+ else if (m_nMaxColor > 32 && m_nMaxColor < 64 && weight < .015 )
366+ beta = .55f ;
373367 }
374368 else
375369 beta *= .95f ;
376370
377371 if (m_nMaxColor > 64 || (m_nMaxColor > 4 && weight > .02 ))
378372 beta *= .4f ;
379373 if (m_nMaxColor > 64 && weight < .02 )
380- beta = .2f ;
381- else if (m_nMaxColor > 32 && m_nMaxColor < 64 && weight < .015 )
382- beta = .55f ;
374+ beta = .2f ;
383375
384376 DITHER_MAX = weight < .015 ? (weight > .0025 ) ? (BYTE )25 : 16 : 9 ;
385377 auto edge = m_hasAlpha ? 1 : exp (weight) + .25 ;
@@ -391,8 +383,6 @@ namespace Peano
391383 else if (weight < .03 && m_nMaxColor / weight < density && m_nMaxColor >= 16 && m_nMaxColor < 256 )
392384 ditherMax = (BYTE )sqr (5 + edge);
393385 thresold = DITHER_MAX > 9 ? -112 : -64 ;
394- auto pLookup = make_unique<unsigned short []>(USHRT_MAX + 1 );
395- m_lookup = pLookup.get ();
396386
397387 if (!sortedByYDiff)
398388 initWeights (DITHER_MAX );
0 commit comments