@@ -111,7 +111,9 @@ void QgsHttpRequestHandler::sendGetMapResponse( const QString& service, QImage*
111
111
112
112
if ( png8Bit )
113
113
{
114
- QImage palettedImg = img->convertToFormat ( QImage::Format_Indexed8, Qt::ColorOnly | Qt::ThresholdDither |
114
+ QVector<QRgb> colorTable;
115
+ medianCut ( colorTable, 256 , *img );
116
+ QImage palettedImg = img->convertToFormat ( QImage::Format_Indexed8, colorTable, Qt::ColorOnly | Qt::ThresholdDither |
115
117
Qt::ThresholdAlphaDither | Qt::NoOpaqueDetection );
116
118
palettedImg.save ( &buffer, " PNG" , -1 );
117
119
}
@@ -469,3 +471,36 @@ QString QgsHttpRequestHandler::readPostBody() const
469
471
}
470
472
return inputString;
471
473
}
474
+
475
+ void QgsHttpRequestHandler::medianCut ( QVector<QRgb>& colorTable, int nColors, const QImage& inputImage )
476
+ {
477
+ QHash<QRgb, int > inputColors;
478
+ imageColors ( inputColors, inputImage );
479
+ // todo...
480
+ }
481
+
482
+ void QgsHttpRequestHandler::imageColors ( QHash<QRgb, int >& colors, const QImage& image )
483
+ {
484
+ colors.clear ();
485
+ int width = image.width ();
486
+ int height = image.height ();
487
+
488
+ QRgb currentColor;
489
+ QHash<QRgb, int >::iterator colorIt;
490
+ for ( int i = 0 ; i < height; ++i )
491
+ {
492
+ for ( int j = 0 ; j < width; ++j )
493
+ {
494
+ currentColor = image.pixel ( j, i );
495
+ colorIt = colors.find ( currentColor );
496
+ if ( colorIt == colors.end () )
497
+ {
498
+ colors.insert ( currentColor, 1 );
499
+ }
500
+ else
501
+ {
502
+ colorIt.value ()++;
503
+ }
504
+ }
505
+ }
506
+ }
0 commit comments