1/* -*- C++ -*-
2 This file is part of ThreadWeaver.
3
4 SPDX-FileCopyrightText: 2005-2014 Mirko Boehm <mirko@kde.org>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7*/
8
9#ifndef IMAGE_H
10#define IMAGE_H
11
12#include <QAtomicInt>
13#include <QCoreApplication>
14#include <QImage>
15#include <QReadWriteLock>
16
17#include "Progress.h"
18
19class Model;
20
21/** @brief Image loads an image from a path, and then calculates and saves a thumbnail for it. */
22class Image
23{
24 Q_DECLARE_TR_FUNCTIONS(Image)
25
26public:
27 enum Steps {
28 Step_NotStarted,
29 Step_LoadFile,
30 Step_LoadImage,
31 Step_ComputeThumbNail,
32 Step_SaveThumbNail,
33 Step_NumberOfSteps = Step_SaveThumbNail,
34 Step_Complete = Step_SaveThumbNail,
35 };
36
37 Image(const QString inputFileName = QString(), const QString outputFileName = QString(), Model *model = nullptr, int id = 0);
38 Progress progress() const;
39 QString description() const;
40 QString details() const;
41 QString details2() const;
42 int processingOrder() const;
43
44 const QString inputFileName() const;
45 const QString outputFileName() const;
46 QImage thumbNail() const;
47
48 void loadFile();
49 void loadImage();
50 void computeThumbNail();
51 void saveThumbNail();
52
53 static const int ThumbHeight;
54 static const int ThumbWidth;
55
56private:
57 void announceProgress(Steps step);
58 void error(Steps step, const QString &message);
59
60 QString m_inputFileName;
61 QString m_outputFileName;
62 QString m_description;
63 QString m_details;
64 QString m_details2;
65 QAtomicInt m_progress;
66 QAtomicInt m_failedStep;
67 QAtomicInt m_processingOrder;
68
69 QByteArray m_imageData;
70 QImage m_image;
71 QImage m_thumbnail;
72 Model *m_model;
73 int m_id;
74
75 static QReadWriteLock Lock;
76 static int ProcessingOrder;
77};
78
79Q_DECLARE_METATYPE(Image)
80Q_DECLARE_METATYPE(const Image *)
81
82#endif // IMAGE_H
83

source code of threadweaver/examples/ThumbNailer/Image.h