Skip to content

Commit 8b1d033

Browse files
committed
Revert "WMS server: even more performant png8 conversion"
This reverts commit 8990b66.
1 parent 040dac7 commit 8b1d033

File tree

2 files changed

+8
-34
lines changed

2 files changed

+8
-34
lines changed

src/mapserver/qgshttprequesthandler.cpp

+6-32
Original file line numberDiff line numberDiff line change
@@ -115,33 +115,9 @@ void QgsHttpRequestHandler::sendGetMapResponse( const QString& service, QImage*
115115
if ( png8Bit )
116116
{
117117
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 );
145121
palettedImg.save( &buffer, "PNG", -1 );
146122
}
147123
else if ( png16Bit )
@@ -526,7 +502,7 @@ QString QgsHttpRequestHandler::readPostBody() const
526502
return inputString;
527503
}
528504

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 )
530506
{
531507
QHash<QRgb, int> inputColors;
532508
imageColors( inputColors, inputImage );
@@ -595,7 +571,7 @@ void QgsHttpRequestHandler::medianCut( QVector<QRgb>& colorTable, QHash<QRgb, in
595571
QgsColorBoxMap::const_iterator colorBoxIt = colorBoxMap.constBegin();
596572
for ( ; colorBoxIt != colorBoxMap.constEnd(); ++colorBoxIt )
597573
{
598-
colorTable[index] = boxColor( colorBoxIt.value(), colorBoxIt.key(), index, colorIndexHash );
574+
colorTable[index] = boxColor( colorBoxIt.value(), colorBoxIt.key() );
599575
++index;
600576
}
601577
}
@@ -789,7 +765,7 @@ bool QgsHttpRequestHandler::alphaCompare( const QPair<QRgb, int>& c1, const QPai
789765
return qAlpha( c1.first ) < qAlpha( c2.first );
790766
}
791767

792-
QRgb QgsHttpRequestHandler::boxColor( const QgsColorBox& box, int boxPixels, int colorMapIndex, QHash<QRgb, int>& colorIndexHash )
768+
QRgb QgsHttpRequestHandler::boxColor( const QgsColorBox& box, int boxPixels )
793769
{
794770
double avRed = 0;
795771
double avGreen = 0;
@@ -810,8 +786,6 @@ QRgb QgsHttpRequestHandler::boxColor( const QgsColorBox& box, int boxPixels, int
810786
avGreen += ( qGreen( currentColor ) * weight );
811787
avBlue += ( qBlue( currentColor ) * weight );
812788
avAlpha += ( qAlpha( currentColor ) * weight );
813-
//allow faster lookup in image conversion
814-
colorIndexHash.insert( currentColor, colorMapIndex );
815789
}
816790

817791
return qRgba( avRed, avGreen, avBlue, avAlpha );

src/mapserver/qgshttprequesthandler.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class QgsHttpRequestHandler: public QgsRequestHandler
5555
QString readPostBody() const;
5656

5757
private:
58-
static void medianCut( QVector<QRgb>& colorTable, QHash<QRgb, int>& colorIndexHash, int nColors, const QImage& inputImage );
58+
static void medianCut( QVector<QRgb>& colorTable, int nColors, const QImage& inputImage );
5959
static void imageColors( QHash<QRgb, int>& colors, const QImage& image );
6060
static void splitColorBox( QgsColorBox& colorBox, QgsColorBoxMap& colorBoxMap,
6161
QMap<int, QgsColorBox>::iterator colorBoxMapIt );
@@ -65,7 +65,7 @@ class QgsHttpRequestHandler: public QgsRequestHandler
6565
static bool blueCompare( const QPair<QRgb, int>& c1, const QPair<QRgb, int>& c2 );
6666
static bool alphaCompare( const QPair<QRgb, int>& c1, const QPair<QRgb, int>& c2 );
6767
/**Calculates a representative color for a box (pixel weighted average)*/
68-
static QRgb boxColor( const QgsColorBox& box, int boxPixels, int colorMapIndex, QHash<QRgb, int>& colorIndexHash );
68+
static QRgb boxColor( const QgsColorBox& box, int boxPixels );
6969
};
7070

7171
#endif

0 commit comments

Comments
 (0)