Skip to content

Commit 3a27411

Browse files
mhugentMarco Hugentobler
authored and
Marco Hugentobler
committedOct 2, 2012
More color quantisation
1 parent 58c5e9d commit 3a27411

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed
 

‎src/mapserver/qgshttprequesthandler.cpp

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,42 @@ void QgsHttpRequestHandler::medianCut( QVector<QRgb>& colorTable, int nColors, c
476476
{
477477
QHash<QRgb, int> inputColors;
478478
imageColors( inputColors, inputImage );
479-
//todo...
479+
480+
//create first box
481+
QgsColorBox firstBox; //QList< QPair<QRgb, int> >
482+
int firstBoxPixelSum = 0;
483+
QHash<QRgb, int>::const_iterator inputColorIt = inputColors.constBegin();
484+
for ( ; inputColorIt != inputColors.constEnd(); ++inputColorIt )
485+
{
486+
firstBox.push_back( qMakePair( inputColorIt.key(), inputColorIt.value() ) );
487+
firstBoxPixelSum += inputColorIt.value();
488+
}
489+
490+
QgsColorBoxMap colorBoxMap; //QMultiMap< int, ColorBox >
491+
QMap<int, QgsColorBox>::iterator colorBoxMapIt;
492+
493+
494+
//split boxes until number of boxes == nColors or all the boxes have color count 1
495+
while ( colorBoxMap.size() < nColors )
496+
{
497+
//start at the end of colorBoxMap and pick the first entry with number of colors < 1
498+
colorBoxMapIt = colorBoxMap.end();
499+
while ( true )
500+
{
501+
--colorBoxMapIt;
502+
if ( colorBoxMapIt.value().size() > 1 )
503+
{
504+
splitColorBox( colorBoxMapIt.value(), colorBoxMap, colorBoxMapIt );
505+
continue;
506+
}
507+
if ( colorBoxMapIt == colorBoxMap.begin() )
508+
{
509+
break;
510+
}
511+
}
512+
}
513+
514+
//todo: evaluate the colors of the final boxes
480515
}
481516

482517
void QgsHttpRequestHandler::imageColors( QHash<QRgb, int>& colors, const QImage& image )
@@ -504,3 +539,12 @@ void QgsHttpRequestHandler::imageColors( QHash<QRgb, int>& colors, const QImage&
504539
}
505540
}
506541
}
542+
543+
void QgsHttpRequestHandler::splitColorBox( QgsColorBox& colorBox, QgsColorBoxMap& colorBoxMap,
544+
QMap<int, QgsColorBox>::iterator colorBoxMapIt )
545+
{
546+
//todo: a,r,g,b ranges
547+
//sort color box for a/r/g/b
548+
//get median
549+
//do split: replace old color box, insert new one
550+
}

‎src/mapserver/qgshttprequesthandler.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020

2121
#include "qgsrequesthandler.h"
2222
#include <QColor>
23+
#include <QPair>
24+
25+
typedef QList< QPair<QRgb, int> > QgsColorBox; //Color / number of pixels
26+
typedef QMultiMap< int, QgsColorBox > QgsColorBoxMap; // sum of pixels / color box
2327

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

5763
#endif

0 commit comments

Comments
 (0)
Please sign in to comment.