mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
Added qt screenshot test
Former-commit-id: c28e098ded780a6597952c83007fea1fe8da36fa
This commit is contained in:
parent
6b63b57f17
commit
5f457fd9e3
@ -6,15 +6,67 @@
|
||||
#include <QApplication>
|
||||
#include <QDesktopWidget>
|
||||
#include <QPixmap>
|
||||
#include <Qfile>
|
||||
#include <QRgb>
|
||||
|
||||
#include <QElapsedTimer>
|
||||
|
||||
// Utils includes
|
||||
#include <utils/Image.h>
|
||||
#include <utils/ColorRgb.h>
|
||||
|
||||
void createScreenshot(const int cropHorizontal, const int cropVertical, const int decimation, Image<ColorRgb> & 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<qImage.height(); ++y)
|
||||
{
|
||||
for (int x=0; x<qImage.width(); ++x)
|
||||
{
|
||||
// Get the pixel at [x;y] (format int32 #AARRGGBB)
|
||||
const QRgb inPixel = qImage.pixel(x,y);
|
||||
|
||||
// Copy the color channels into the output pixel
|
||||
ColorRgb & outPixel = image(x,y);
|
||||
outPixel.red = (inPixel & 0x00ff0000) >> 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<ColorRgb> screenshot(64,64);
|
||||
|
||||
std::cout << "Grabbed image: [" << originalPixmap.width() << "; " << originalPixmap.height() << "]" << std::endl;
|
||||
int loopCnt = 100;
|
||||
timer.start();
|
||||
for (int i=0; i<loopCnt; ++i)
|
||||
{
|
||||
createScreenshot(0,0, decimation, screenshot);
|
||||
}
|
||||
std::cout << "Time required for single screenshot: " << timer.elapsed()/loopCnt << "ms" << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ void foo_1(int pixelDecimation)
|
||||
// Cleanup allocated resources of the X11 grab
|
||||
XDestroyImage(xImage);
|
||||
|
||||
std::cout << "Time required: " << timer.elapsed() << " us" << std::endl;
|
||||
std::cout << "Time required: " << timer.elapsed() << " ms" << std::endl;
|
||||
|
||||
XCloseDisplay(x11Display);
|
||||
}
|
||||
@ -125,7 +125,7 @@ void foo_2(int pixelDecimation)
|
||||
XDestroyImage(xImage);
|
||||
}
|
||||
}
|
||||
std::cout << "Time required: " << timer.elapsed() << " us" << std::endl;
|
||||
std::cout << "Time required: " << timer.elapsed() << " ms" << std::endl;
|
||||
|
||||
|
||||
XCloseDisplay(x11Display);
|
||||
|
Loading…
Reference in New Issue
Block a user