plugins/screenshot: Snap pixel grid for rectangular screenshots
To prevent blurring with fractional scaling
This commit is contained in:
parent
f4232bc391
commit
202356ba89
1 changed files with 9 additions and 3 deletions
|
@ -83,6 +83,12 @@ static void convertFromGLImage(QImage &img, int w, int h, const OutputTransform
|
|||
img = img.transformed(matrix.toTransform());
|
||||
}
|
||||
|
||||
static QRectF roundedRect(const QRect &rect, qreal scale)
|
||||
{
|
||||
const QRect scaled = snapToPixelGrid(scaledRect(rect, scale));
|
||||
return scaledRect(scaled, 1.0 / scale);
|
||||
}
|
||||
|
||||
bool ScreenShotEffect::supported()
|
||||
{
|
||||
return effects->isOpenGLCompositing();
|
||||
|
@ -313,13 +319,13 @@ bool ScreenShotEffect::takeScreenShot(const RenderTarget &renderTarget, const Re
|
|||
}
|
||||
|
||||
const QImage snapshot = blitScreenshot(renderTarget, viewport, sourceRect, sourceDevicePixelRatio);
|
||||
const QRect nativeArea(screenshot->area.topLeft(),
|
||||
screenshot->area.size() * screenshot->result.devicePixelRatio());
|
||||
const QSize nativeAreaSize = snapToPixelGrid(scaledRect(screenshot->area, screenshot->result.devicePixelRatio())).size();
|
||||
const QRect nativeArea(screenshot->area.topLeft(), nativeAreaSize);
|
||||
|
||||
QPainter painter(&screenshot->result);
|
||||
painter.setRenderHint(QPainter::SmoothPixmapTransform);
|
||||
painter.setWindow(nativeArea);
|
||||
painter.drawImage(sourceRect, snapshot);
|
||||
painter.drawImage(roundedRect(sourceRect, sourceDevicePixelRatio), snapshot);
|
||||
painter.end();
|
||||
|
||||
if (screenshot->screens.isEmpty()) {
|
||||
|
|
Loading…
Reference in a new issue