1 | // Aseprite |
---|---|
2 | // Copyright (C) 2021 Igara Studio S.A. |
3 | // Copyright (C) 2001-2017 David Capello |
4 | // |
5 | // This program is distributed under the terms of |
6 | // the End-User License Agreement for Aseprite. |
7 | |
8 | #ifdef HAVE_CONFIG_H |
9 | #include "config.h" |
10 | #endif |
11 | |
12 | #include "app/file/file_formats_manager.h" |
13 | |
14 | #include "app/file/file_format.h" |
15 | #include "app/file/format_options.h" |
16 | #include "base/string.h" |
17 | #include "dio/detect_format.h" |
18 | |
19 | #include <algorithm> |
20 | #include <cstring> |
21 | |
22 | namespace app { |
23 | |
24 | extern FileFormat* CreateAseFormat(); |
25 | extern FileFormat* CreateBmpFormat(); |
26 | extern FileFormat* CreateCssFormat(); |
27 | extern FileFormat* CreateFliFormat(); |
28 | extern FileFormat* CreateGifFormat(); |
29 | extern FileFormat* CreateIcoFormat(); |
30 | extern FileFormat* CreateJpegFormat(); |
31 | extern FileFormat* CreatePcxFormat(); |
32 | extern FileFormat* CreatePngFormat(); |
33 | extern FileFormat* CreateSvgFormat(); |
34 | extern FileFormat* CreateTgaFormat(); |
35 | |
36 | #ifdef ENABLE_PSD |
37 | extern FileFormat* CreatePsdFormat(); |
38 | #endif |
39 | |
40 | #ifdef ENABLE_WEBP |
41 | extern FileFormat* CreateWebPFormat(); |
42 | #endif |
43 | |
44 | static FileFormatsManager* singleton = NULL; |
45 | |
46 | // static |
47 | FileFormatsManager* FileFormatsManager::instance() |
48 | { |
49 | if (!singleton) |
50 | singleton = new FileFormatsManager; |
51 | return singleton; |
52 | } |
53 | |
54 | // static |
55 | void FileFormatsManager::destroyInstance() |
56 | { |
57 | delete singleton; |
58 | singleton = NULL; |
59 | } |
60 | |
61 | FileFormatsManager::FileFormatsManager() |
62 | { |
63 | // The first format is the default image format in FileSelector |
64 | registerFormat(CreateAseFormat()); |
65 | registerFormat(CreateBmpFormat()); |
66 | registerFormat(CreateCssFormat()); |
67 | registerFormat(CreateFliFormat()); |
68 | registerFormat(CreateGifFormat()); |
69 | registerFormat(CreateIcoFormat()); |
70 | registerFormat(CreateJpegFormat()); |
71 | registerFormat(CreatePcxFormat()); |
72 | registerFormat(CreatePngFormat()); |
73 | |
74 | #ifdef ENABLE_PSD |
75 | registerFormat(CreatePsdFormat()); |
76 | #endif |
77 | |
78 | registerFormat(CreateSvgFormat()); |
79 | registerFormat(CreateTgaFormat()); |
80 | |
81 | #ifdef ENABLE_WEBP |
82 | registerFormat(CreateWebPFormat()); |
83 | #endif |
84 | } |
85 | |
86 | FileFormatsManager::~FileFormatsManager() |
87 | { |
88 | FileFormatsList::iterator end = this->end(); |
89 | for (FileFormatsList::iterator it = begin(); it != end; ++it) { |
90 | delete (*it); // delete the FileFormat |
91 | } |
92 | } |
93 | |
94 | void FileFormatsManager::registerFormat(FileFormat* fileFormat) |
95 | { |
96 | m_formats.push_back(fileFormat); |
97 | } |
98 | |
99 | FileFormatsList::iterator FileFormatsManager::begin() |
100 | { |
101 | return m_formats.begin(); |
102 | } |
103 | |
104 | FileFormatsList::iterator FileFormatsManager::end() |
105 | { |
106 | return m_formats.end(); |
107 | } |
108 | |
109 | FileFormat* FileFormatsManager::getFileFormat(const dio::FileFormat dioFormat) const |
110 | { |
111 | for (FileFormat* ff : m_formats) |
112 | if (ff->dioFormat() == dioFormat) |
113 | return ff; |
114 | return nullptr; |
115 | } |
116 | |
117 | } // namespace app |
118 |