Skip to content
Permalink
Browse files

More color quantisation

  • Loading branch information
mhugent authored and Marco Hugentobler committed Oct 2, 2012
1 parent 58c5e9d commit 3a274113aea4eb0a67c898fc6abf10ec1f67cb1c
Showing with 51 additions and 1 deletion.
  1. +45 −1 src/mapserver/qgshttprequesthandler.cpp
  2. +6 −0 src/mapserver/qgshttprequesthandler.h
@@ -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 )
@@ -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
}
@@ -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*/
@@ -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.
You can’t perform that action at this time.