Skip to content
Permalink
Browse files

Start coding of 8bit png conversion

  • Loading branch information
mhugent authored and Marco Hugentobler committed Oct 2, 2012
1 parent 1549f09 commit 58c5e9d311bdd17efef57a1eda3b41d07671acc2
Showing with 41 additions and 1 deletion.
  1. +36 −1 src/mapserver/qgshttprequesthandler.cpp
  2. +5 −0 src/mapserver/qgshttprequesthandler.h
@@ -111,7 +111,9 @@ void QgsHttpRequestHandler::sendGetMapResponse( const QString& service, QImage*

if ( png8Bit )
{
QImage palettedImg = img->convertToFormat( QImage::Format_Indexed8, Qt::ColorOnly | Qt::ThresholdDither |
QVector<QRgb> colorTable;
medianCut( colorTable, 256, *img );
QImage palettedImg = img->convertToFormat( QImage::Format_Indexed8, colorTable, Qt::ColorOnly | Qt::ThresholdDither |
Qt::ThresholdAlphaDither | Qt::NoOpaqueDetection );
palettedImg.save( &buffer, "PNG", -1 );
}
@@ -469,3 +471,36 @@ QString QgsHttpRequestHandler::readPostBody() const
}
return inputString;
}

void QgsHttpRequestHandler::medianCut( QVector<QRgb>& colorTable, int nColors, const QImage& inputImage )
{
QHash<QRgb, int> inputColors;
imageColors( inputColors, inputImage );
//todo...
}

void QgsHttpRequestHandler::imageColors( QHash<QRgb, int>& colors, const QImage& image )
{
colors.clear();
int width = image.width();
int height = image.height();

QRgb currentColor;
QHash<QRgb, int>::iterator colorIt;
for ( int i = 0; i < height; ++i )
{
for ( int j = 0; j < width; ++j )
{
currentColor = image.pixel( j, i );
colorIt = colors.find( currentColor );
if ( colorIt == colors.end() )
{
colors.insert( currentColor, 1 );
}
else
{
colorIt.value()++;
}
}
}
}
@@ -19,6 +19,7 @@
#define QGSHTTPREQUESTHANDLER_H

#include "qgsrequesthandler.h"
#include <QColor>

/**Base class for request handler using HTTP.
It provides a method to send data to the client*/
@@ -47,6 +48,10 @@ class QgsHttpRequestHandler: public QgsRequestHandler
void requestStringToParameterMap( const QString& request, QMap<QString, QString>& parameters );
/**Read CONTENT_LENGTH characters from stdin*/
QString readPostBody() const;

private:
static void medianCut( QVector<QRgb>& colorTable, int nColors, const QImage& inputImage );
static void imageColors( QHash<QRgb, int>& colors, const QImage& image );
};

#endif

0 comments on commit 58c5e9d

Please sign in to comment.
You can’t perform that action at this time.