forked from 4lex4/scantailor-advanced
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImageMetadataLoader.h
92 lines (73 loc) · 3.27 KB
/
ImageMetadataLoader.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
Scan Tailor - Interactive post-processing tool for scanned pages.
Copyright (C) 2007-2008 Joseph Artsimovich <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef IMAGEMETADATALOADER_H_
#define IMAGEMETADATALOADER_H_
#include <vector>
#include "VirtualFunction.h"
#include "intrusive_ptr.h"
#include "ref_countable.h"
class QString;
class QIODevice;
class ImageMetadata;
class ImageMetadataLoader : public ref_countable {
public:
enum Status {
LOADED, /**< Loaded successfully */
NO_IMAGES, /**< File contained no images. */
FORMAT_NOT_RECOGNIZED, /**< File format not recognized. */
GENERIC_ERROR /**< Some other error has occured. */
};
/**
* \brief Registers a loader for a particular image format.
*
* This function may not be called before main() or after additional
* threads have been created.
*/
static void registerLoader(intrusive_ptr<ImageMetadataLoader> loader);
template <typename OutFunc>
static Status load(QIODevice& io_device, OutFunc out);
template <typename OutFunc>
static Status load(const QString& file_path, OutFunc out);
protected:
~ImageMetadataLoader() override = default;
/**
* \brief Loads metadata from a particular image format.
*
* This function must be reentrant, as it may be called from multiple
* threads at the same time.
*
* \param io_device The I/O device to read from. Usually a QFile.
* In case FORMAT_NO_RECOGNIZED is returned, the implementation
* must leave \p io_device in its original state.
* \param out A callback functional object that will be called to handle
* the image metadata. If there are multiple images (pages) in
* the file, this object will be called multiple times.
*/
virtual Status loadMetadata(QIODevice& io_device, const VirtualFunction<void, const ImageMetadata&>& out) = 0;
private:
static Status loadImpl(QIODevice& io_device, const VirtualFunction<void, const ImageMetadata&>& out);
static Status loadImpl(const QString& file_path, const VirtualFunction<void, const ImageMetadata&>& out);
typedef std::vector<intrusive_ptr<ImageMetadataLoader>> LoaderList;
static LoaderList m_sLoaders;
};
template <typename Callable>
ImageMetadataLoader::Status ImageMetadataLoader::load(QIODevice& io_device, Callable out) {
return loadImpl(io_device, ProxyFunction<Callable, void, const ImageMetadata&>(out));
}
template <typename Callable>
ImageMetadataLoader::Status ImageMetadataLoader::load(const QString& file_path, Callable out) {
return loadImpl(file_path, ProxyFunction<Callable, void, const ImageMetadata&>(out));
}
#endif // ifndef IMAGEMETADATALOADER_H_