Skip to content

Commit

Permalink
Start coding of 8bit png conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent authored and Marco Hugentobler committed Oct 2, 2012
1 parent 1549f09 commit 58c5e9d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
37 changes: 36 additions & 1 deletion src/mapserver/qgshttprequesthandler.cpp
Expand Up @@ -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 );
}
Expand Down Expand Up @@ -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()++;
}
}
}
}
5 changes: 5 additions & 0 deletions src/mapserver/qgshttprequesthandler.h
Expand Up @@ -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*/
Expand Down Expand Up @@ -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.