~ubuntu-branches/ubuntu/precise/gwenview/precise-proposed

« back to all changes in this revision

Viewing changes to tests/manual/imageloadbench.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2011-12-15 14:17:54 UTC
  • mto: This revision was merged to the branch mainline in revision 12.
  • Revision ID: package-import@ubuntu.com-20111215141754-z043hyx69dulbggf
Tags: upstream-4.7.90
ImportĀ upstreamĀ versionĀ 4.7.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <QBuffer>
 
2
#include <QCoreApplication>
 
3
#include <QDebug>
 
4
#include <QFile>
 
5
#include <QImage>
 
6
#include <QImageReader>
 
7
#include <QTime>
 
8
 
 
9
#include <lib/imageformats/imageformats.h>
 
10
 
 
11
const int ITERATIONS = 2;
 
12
const QSize SCALED_SIZE(1280, 800);
 
13
 
 
14
static void bench(QIODevice* device, const QString& outputName)
 
15
{
 
16
    QTime chrono;
 
17
    chrono.start();
 
18
    for (int iteration = 0; iteration < ITERATIONS; ++iteration) {
 
19
        qDebug() << "Iteration:" << iteration;
 
20
 
 
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();
 
28
 
 
29
        if (iteration == ITERATIONS - 1) {
 
30
            qDebug() << "time:" << chrono.elapsed();
 
31
            img.save(outputName, "png");
 
32
        }
 
33
    }
 
34
}
 
35
 
 
36
int main(int argc, char** argv)
 
37
{
 
38
    QCoreApplication app(argc, argv);
 
39
    if (argc != 2) {
 
40
        qDebug() << "Usage: imageloadbench <file.jpg>";
 
41
        return 1;
 
42
    }
 
43
 
 
44
    QString fileName = QString::fromUtf8(argv[1]);
 
45
 
 
46
    QFile file(fileName);
 
47
    if (!file.open(QIODevice::ReadOnly)) {
 
48
        qDebug() << QString("Could not open '%1'").arg(fileName);
 
49
        return 2;
 
50
    }
 
51
    QByteArray data = file.readAll();
 
52
    QBuffer buffer(&data);
 
53
 
 
54
    qDebug() << "Using Qt loader";
 
55
    bench(&buffer, "qt.png");
 
56
    Gwenview::ImageFormats::registerPlugins();
 
57
    qDebug() << "Using Gwenview loader";
 
58
    bench(&buffer, "gv.png");
 
59
 
 
60
    return 0;
 
61
}