@@ -115,33 +115,9 @@ void QgsHttpRequestHandler::sendGetMapResponse( const QString& service, QImage*
115
115
if ( png8Bit )
116
116
{
117
117
QVector<QRgb> colorTable;
118
- QHash<QRgb, int > colorIndexHash;
119
- medianCut ( colorTable, colorIndexHash, 256 , *img );
120
-
121
-
122
- QImage palettedImg ( img->size (), QImage::Format_Indexed8 );
123
- palettedImg.setColorTable ( colorTable );
124
-
125
- int h = img->height ();
126
- int w = img->width ();
127
-
128
- for ( int y = 0 ; y < h; ++y )
129
- {
130
- QRgb* src_pixels = ( QRgb * ) img->scanLine ( y );
131
- uchar* dest_pixels = ( uchar * ) palettedImg.scanLine ( y );
132
-
133
- for ( int x = 0 ; x < w; ++x )
134
- {
135
- int src_pixel = src_pixels[x];
136
- int value = colorIndexHash.value ( src_pixel, -1 );
137
- if ( value == -1 )
138
- {
139
- continue ;
140
- }
141
- dest_pixels[x] = ( uchar ) value;
142
- }
143
- }
144
-
118
+ medianCut ( colorTable, 256 , *img );
119
+ QImage palettedImg = img->convertToFormat ( QImage::Format_Indexed8, colorTable, Qt::ColorOnly | Qt::ThresholdDither |
120
+ Qt::ThresholdAlphaDither | Qt::NoOpaqueDetection );
145
121
palettedImg.save ( &buffer, " PNG" , -1 );
146
122
}
147
123
else if ( png16Bit )
@@ -526,7 +502,7 @@ QString QgsHttpRequestHandler::readPostBody() const
526
502
return inputString;
527
503
}
528
504
529
- void QgsHttpRequestHandler::medianCut ( QVector<QRgb>& colorTable, QHash<QRgb, int >& colorIndexHash, int nColors, const QImage& inputImage )
505
+ void QgsHttpRequestHandler::medianCut ( QVector<QRgb>& colorTable, int nColors, const QImage& inputImage )
530
506
{
531
507
QHash<QRgb, int > inputColors;
532
508
imageColors ( inputColors, inputImage );
@@ -595,7 +571,7 @@ void QgsHttpRequestHandler::medianCut( QVector<QRgb>& colorTable, QHash<QRgb, in
595
571
QgsColorBoxMap::const_iterator colorBoxIt = colorBoxMap.constBegin ();
596
572
for ( ; colorBoxIt != colorBoxMap.constEnd (); ++colorBoxIt )
597
573
{
598
- colorTable[index ] = boxColor ( colorBoxIt.value (), colorBoxIt.key (), index , colorIndexHash );
574
+ colorTable[index ] = boxColor ( colorBoxIt.value (), colorBoxIt.key () );
599
575
++index ;
600
576
}
601
577
}
@@ -789,7 +765,7 @@ bool QgsHttpRequestHandler::alphaCompare( const QPair<QRgb, int>& c1, const QPai
789
765
return qAlpha ( c1.first ) < qAlpha ( c2.first );
790
766
}
791
767
792
- QRgb QgsHttpRequestHandler::boxColor ( const QgsColorBox& box, int boxPixels, int colorMapIndex, QHash<QRgb, int >& colorIndexHash )
768
+ QRgb QgsHttpRequestHandler::boxColor ( const QgsColorBox& box, int boxPixels )
793
769
{
794
770
double avRed = 0 ;
795
771
double avGreen = 0 ;
@@ -810,8 +786,6 @@ QRgb QgsHttpRequestHandler::boxColor( const QgsColorBox& box, int boxPixels, int
810
786
avGreen += ( qGreen ( currentColor ) * weight );
811
787
avBlue += ( qBlue ( currentColor ) * weight );
812
788
avAlpha += ( qAlpha ( currentColor ) * weight );
813
- // allow faster lookup in image conversion
814
- colorIndexHash.insert ( currentColor, colorMapIndex );
815
789
}
816
790
817
791
return qRgba ( avRed, avGreen, avBlue, avAlpha );
0 commit comments