From f892c9510eb5c79e1b9f1a86777db626c2d72576 Mon Sep 17 00:00:00 2001 From: ivan tkachenko Date: Mon, 8 Aug 2022 18:00:49 +0300 Subject: [PATCH] effects/colorpicker: Fix off-by-one error during coordinates conversion Due to this bug color picker used to not only select one pixel higher than it should (which is quite negligible), but also returned garbage value for the topmost row of pixels (when you push the cursor against the top edge of the screen). FIXED-IN: 5.24.7, 5.25.5, 5.26 --- src/effects/colorpicker/colorpicker.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/effects/colorpicker/colorpicker.cpp b/src/effects/colorpicker/colorpicker.cpp index d0b66c46b0..dd99229723 100644 --- a/src/effects/colorpicker/colorpicker.cpp +++ b/src/effects/colorpicker/colorpicker.cpp @@ -57,10 +57,11 @@ void ColorPickerEffect::paintScreen(int mask, const QRegion ®ion, ScreenPaint const QRect geo = effects->renderTargetRect(); if (m_scheduledPosition != QPoint(-1, -1) && geo.contains(m_scheduledPosition)) { uint8_t data[4]; + constexpr GLsizei PIXEL_SIZE = 1; const QPoint screenPosition(m_scheduledPosition.x() - geo.x(), m_scheduledPosition.y() - geo.y()); - const QPoint texturePosition(screenPosition.x() * effects->renderTargetScale(), (geo.height() - screenPosition.y()) * effects->renderTargetScale()); + const QPoint texturePosition(screenPosition.x() * effects->renderTargetScale(), (geo.height() - screenPosition.y() - PIXEL_SIZE) * effects->renderTargetScale()); - glReadnPixels(texturePosition.x(), texturePosition.y(), 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, 4, data); + glReadnPixels(texturePosition.x(), texturePosition.y(), PIXEL_SIZE, PIXEL_SIZE, GL_RGBA, GL_UNSIGNED_BYTE, 4, data); QDBusConnection::sessionBus().send(m_replyMessage.createReply(QColor(data[0], data[1], data[2]))); m_picking = false; m_scheduledPosition = QPoint(-1, -1);