]> git.sesse.net Git - kdenlive/commitdiff
Color Picker: Fix miscalculations when picking average color
authorTill Theato <root@ttill.de>
Sun, 1 Aug 2010 20:38:46 +0000 (20:38 +0000)
committerTill Theato <root@ttill.de>
Sun, 1 Aug 2010 20:38:46 +0000 (20:38 +0000)
svn path=/trunk/kdenlive/; revision=4679

src/colorpickerwidget.cpp

index 44ae3f0c12658b7893e70efc5cdb4ffe54d877f4..4932e61daf27b75f4035ddb34cd7f7319820e117 100644 (file)
@@ -92,10 +92,17 @@ ColorPickerWidget::~ColorPickerWidget()
 QColor ColorPickerWidget::averagePickedColor(const QPoint pos)
 {
     int size = m_size->value();
-    int x0 = qMax(0, pos.x() - size / 2); 
+    int x0 = qMax(0, pos.x() - size / 2);
     int y0 = qMax(0, pos.y() - size / 2);
     int x1 = qMin(qApp->desktop()->geometry().width(), pos.x() + size / 2);
     int y1 = qMin(qApp->desktop()->geometry().height(), pos.y() + size / 2);
+
+    // take care of loss when dividing odd sizes
+    if (size % 2 != 0) {
+        ++x1;
+        ++y1;
+    }
+
     int numPixel = (x1 - x0) * (y1 - y0);
 
     int sumR = 0;
@@ -118,8 +125,8 @@ QColor ColorPickerWidget::averagePickedColor(const QPoint pos)
     m_image = QPixmap::grabWindow(desktop->winId(), x0, y0, x1 - x0, y1 - y0).toImage();
 #endif
 
-    for (int i = x0; i <= x1; ++i) {
-        for (int j = y0; j <= y1; ++j) {
+    for (int i = x0; i < x1; ++i) {
+        for (int j = y0; j < y1; ++j) {
             QColor color;
             color = grabColor(QPoint(i - x0, j - y0), false);
             sumR += color.red();