Skip to content

Commit

Permalink
More color quantisation
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 58c5e9d commit 3a27411
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
46 changes: 45 additions & 1 deletion src/mapserver/qgshttprequesthandler.cpp
Expand Up @@ -476,7 +476,42 @@ void QgsHttpRequestHandler::medianCut( QVector<QRgb>& colorTable, int nColors, c
{
QHash<QRgb, int> inputColors;
imageColors( inputColors, inputImage );
//todo...

//create first box
QgsColorBox firstBox; //QList< QPair<QRgb, int> >
int firstBoxPixelSum = 0;
QHash<QRgb, int>::const_iterator inputColorIt = inputColors.constBegin();
for ( ; inputColorIt != inputColors.constEnd(); ++inputColorIt )
{
firstBox.push_back( qMakePair( inputColorIt.key(), inputColorIt.value() ) );
firstBoxPixelSum += inputColorIt.value();
}

QgsColorBoxMap colorBoxMap; //QMultiMap< int, ColorBox >
QMap<int, QgsColorBox>::iterator colorBoxMapIt;


//split boxes until number of boxes == nColors or all the boxes have color count 1
while ( colorBoxMap.size() < nColors )
{
//start at the end of colorBoxMap and pick the first entry with number of colors < 1
colorBoxMapIt = colorBoxMap.end();
while ( true )
{
--colorBoxMapIt;
if ( colorBoxMapIt.value().size() > 1 )
{
splitColorBox( colorBoxMapIt.value(), colorBoxMap, colorBoxMapIt );
continue;
}
if ( colorBoxMapIt == colorBoxMap.begin() )
{
break;
}
}
}

//todo: evaluate the colors of the final boxes
}

void QgsHttpRequestHandler::imageColors( QHash<QRgb, int>& colors, const QImage& image )
Expand Down Expand Up @@ -504,3 +539,12 @@ void QgsHttpRequestHandler::imageColors( QHash<QRgb, int>& colors, const QImage&
}
}
}

void QgsHttpRequestHandler::splitColorBox( QgsColorBox& colorBox, QgsColorBoxMap& colorBoxMap,
QMap<int, QgsColorBox>::iterator colorBoxMapIt )
{
//todo: a,r,g,b ranges
//sort color box for a/r/g/b
//get median
//do split: replace old color box, insert new one
}
6 changes: 6 additions & 0 deletions src/mapserver/qgshttprequesthandler.h
Expand Up @@ -20,6 +20,10 @@

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

typedef QList< QPair<QRgb, int> > QgsColorBox; //Color / number of pixels
typedef QMultiMap< int, QgsColorBox > QgsColorBoxMap; // sum of pixels / color box

/**Base class for request handler using HTTP.
It provides a method to send data to the client*/
Expand Down Expand Up @@ -52,6 +56,8 @@ class QgsHttpRequestHandler: public QgsRequestHandler
private:
static void medianCut( QVector<QRgb>& colorTable, int nColors, const QImage& inputImage );
static void imageColors( QHash<QRgb, int>& colors, const QImage& image );
static void splitColorBox( QgsColorBox& colorBox, QgsColorBoxMap& colorBoxMap,
QMap<int, QgsColorBox>::iterator colorBoxMapIt );
};

#endif

0 comments on commit 3a27411

Please sign in to comment.