1 /**********************************************\
2 *
3 *  Simple Viewer GL edition
4 *  by Andrey A. Ugolnik
5 *  http://www.ugolnik.info
6 *  andrey@ugolnik.info
7 *
8 \**********************************************/
9 
10 #pragma once
11 
12 #include "formats/format.h"
13 #include "common/bitmap_description.h"
14 
15 #include <memory>
16 #include <thread>
17 
18 class iCallbacks;
19 struct sConfig;
20 
21 enum class eImageType
22 {
23 #if defined(IMLIB2_SUPPORT)
24     COMMON,
25 #endif
26 #if defined(OPENEXR_SUPPORT)
27     EXR,
28 #endif
29     JPG,
30 #if defined(JPEG2000_SUPPORT)
31     JP2,
32 #endif
33     PSD,
34     EPS,
35     PNG,
36 #if defined(GIF_SUPPORT)
37     GIF,
38 #endif
39     ICO,
40     ICNS,
41 #if defined(TIFF_SUPPORT)
42     TIF,
43 #endif
44     XWD,
45     XPM,
46     DDS,
47     RAW,
48     AGE,
49     PNM,
50     PVR,
51     SCR,
52     TGA,
53     BMP,
54     XCF,
55     SVG,
56 #if defined(WEBP_SUPPORT)
57     WEBP,
58 #endif
59 
60     NOTAVAILABLE,
61 
62     COUNT
63 };
64 
65 class cImageLoader final
66 {
67 public:
68     explicit cImageLoader(const sConfig* config, iCallbacks* callbacks);
69     ~cImageLoader();
70 
71     void loadImage(const char* path);
72     void loadSubImage(unsigned subImage);
73     bool isLoaded() const;
74 
75     enum class Mode
76     {
77         Image,
78         SubImage
79     };
getMode()80     Mode getMode() const
81     {
82         return m_mode;
83     }
84 
85     const char* getImageType() const;
86 
getDescription()87     const sBitmapDescription& getDescription() const
88     {
89         return m_desc;
90     }
91 
92 private:
93     cFormat* createLoader(eImageType type) const;
94     cFormat* getLoader(eImageType type) const;
95 
96     void stop();
97     void clear();
98     eImageType getType(const char* name);
99     void load(const char* path);
100 
101 private:
102     const sConfig* m_config;
103     iCallbacks* m_callbacks;
104 
105     Mode m_mode = Mode::Image;
106     std::thread m_loader;
107     cFormat* m_image = nullptr;
108     mutable std::unique_ptr<cFormat> m_formats[(unsigned)eImageType::COUNT];
109     sBitmapDescription m_desc;
110 };
111