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
This commit is contained in:
ivan tkachenko 2022-08-08 18:00:49 +03:00
parent 2fa4a4c4e9
commit f892c9510e
No known key found for this signature in database
GPG key ID: AF72731B7C654CB3

View file

@ -57,10 +57,11 @@ void ColorPickerEffect::paintScreen(int mask, const QRegion &region, 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);