fix warning
[kdegraphics.git] / gwenview / tests / imageloadbench.cpp
blob595c9fc9c62ad8902825b4fe2719c9e0fa968d57
1 #include <QBuffer>
2 #include <QCoreApplication>
3 #include <QDebug>
4 #include <QFile>
5 #include <QImage>
6 #include <QImageReader>
7 #include <QTime>
9 #include <lib/imageformats/imageformats.h>
11 const int ITERATIONS = 2;
12 const QSize SCALED_SIZE(1280, 800);
15 static void bench(QIODevice* device, const QString& outputName) {
16 QTime chrono;
17 chrono.start();
18 for (int iteration=0; iteration<ITERATIONS; ++iteration) {
19 qDebug() << "Iteration:" << iteration;
21 device->open(QIODevice::ReadOnly);
22 QImageReader reader(device);
23 QSize size = reader.size();
24 size.scale(SCALED_SIZE, Qt::KeepAspectRatio);
25 reader.setScaledSize(size);
26 QImage img = reader.read();
27 device->close();
29 if (iteration == ITERATIONS - 1) {
30 qDebug() << "time:" << chrono.elapsed();
31 img.save(outputName, "png");
37 int main(int argc, char** argv) {
38 QCoreApplication app(argc, argv);
39 if (argc != 2) {
40 qDebug() << "Usage: imageloadbench <file.jpg>";
41 return 1;
44 QString fileName = QString::fromUtf8(argv[1]);
46 QFile file(fileName);
47 if (!file.open(QIODevice::ReadOnly)) {
48 qDebug() << QString("Could not open '%1'").arg(fileName);
49 return 2;
51 QByteArray data = file.readAll();
52 QBuffer buffer(&data);
54 qDebug() << "Using Qt loader";
55 bench(&buffer, "qt.png");
56 Gwenview::ImageFormats::registerPlugins();
57 qDebug() << "Using Gwenview loader";
58 bench(&buffer, "gv.png");
60 return 0;