@@ -476,7 +476,42 @@ void QgsHttpRequestHandler::medianCut( QVector<QRgb>& colorTable, int nColors, c
476
476
{
477
477
QHash<QRgb, int > inputColors;
478
478
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
480
515
}
481
516
482
517
void QgsHttpRequestHandler::imageColors ( QHash<QRgb, int >& colors, const QImage& image )
@@ -504,3 +539,12 @@ void QgsHttpRequestHandler::imageColors( QHash<QRgb, int>& colors, const QImage&
504
539
}
505
540
}
506
541
}
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
+ }
0 commit comments