From 5f457fd9e3eb32b1beebc26921e4963e1935742c Mon Sep 17 00:00:00 2001 From: "T. van der Zwan" Date: Thu, 6 Mar 2014 21:01:14 +0100 Subject: [PATCH] Added qt screenshot test Former-commit-id: c28e098ded780a6597952c83007fea1fe8da36fa --- test/TestQtScreenshot.cpp | 56 +++++++++++++++++++++++++++++++++++-- test/TestX11Performance.cpp | 4 +-- 2 files changed, 56 insertions(+), 4 deletions(-) diff --git a/test/TestQtScreenshot.cpp b/test/TestQtScreenshot.cpp index 27e03b0f..d2bed9e7 100644 --- a/test/TestQtScreenshot.cpp +++ b/test/TestQtScreenshot.cpp @@ -6,15 +6,67 @@ #include #include #include +#include +#include + +#include + +// Utils includes +#include +#include + +void createScreenshot(const int cropHorizontal, const int cropVertical, const int decimation, Image & image) +{ + // Create the full size screenshot + const QRect screenSize = QApplication::desktop()->screenGeometry(); + const int croppedWidth = screenSize.width() - 2*cropVertical; + const int croppedHeight = screenSize.height() - 2*cropHorizontal; + const QPixmap fullSizeScreenshot = QPixmap::grabWindow(QApplication::desktop()->winId(), cropVertical, cropHorizontal, croppedWidth, croppedHeight); + + // Scale the screenshot to the required size + const int width = fullSizeScreenshot.width()/decimation; + const int height = fullSizeScreenshot.height()/decimation; + const QPixmap scaledScreenshot = fullSizeScreenshot.scaled(width, height, Qt::IgnoreAspectRatio, Qt::FastTransformation); + + // Convert the QPixmap to QImage in order to get out RGB values + const QImage qImage = scaledScreenshot.toImage(); + + // Make sure that the output image has the right size + image.resize(width, height); + + // Copy the data into the output image + for (int y=0; y> 16; + outPixel.green = (inPixel & 0x0000ff00) >> 8; + outPixel.blue = (inPixel & 0x000000ff); + } + } +} int main(int argc, char** argv) { + int decimation = 10; QApplication app(argc, argv); + QElapsedTimer timer; - QPixmap originalPixmap = QPixmap::grabWindow(QApplication::desktop()->winId()); + Image screenshot(64,64); - std::cout << "Grabbed image: [" << originalPixmap.width() << "; " << originalPixmap.height() << "]" << std::endl; + int loopCnt = 100; + timer.start(); + for (int i=0; i