vsgXchange  1.0.2
VulkanSceneGraph 3rd party data integration library
images.h
1 #pragma once
2 
3 /* <editor-fold desc="MIT License">
4 
5 Copyright(c) 2021 Robert Osfield
6 
7 Permission is hereby granted, free of charge, to any person obtaining a copy of
8 this software and associated documentation files (the "Software"), to deal in
9 the Software without restriction, including without limitation the rights to
10 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 the Software, and to permit persons to whom the Software is furnished to do so,
12 subject to the following conditions:
13 
14 The above copyright notice and this permission notice shimages be included in images
15 copies or substantial portions of the Software.
16 
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 
24 </editor-fold> */
25 
26 #include <vsg/io/ReaderWriter.h>
27 #include <vsgXchange/Version.h>
28 
29 #include <memory>
30 #include <unordered_set>
31 
32 namespace vsgXchange
33 {
36  class VSGXCHANGE_DECLSPEC images : public vsg::Inherit<vsg::CompositeReaderWriter, images>
37  {
38  public:
39  images();
40  };
41 
43  class VSGXCHANGE_DECLSPEC stbi : public vsg::Inherit<vsg::ReaderWriter, stbi>
44  {
45  public:
46  stbi();
47 
48  vsg::ref_ptr<vsg::Object> read(const vsg::Path& filename, vsg::ref_ptr<const vsg::Options> options = {}) const override;
49  vsg::ref_ptr<vsg::Object> read(std::istream& fin, vsg::ref_ptr<const vsg::Options> options = {}) const override;
50  vsg::ref_ptr<vsg::Object> read(const uint8_t* ptr, size_t size, vsg::ref_ptr<const vsg::Options> options = {}) const override;
51  bool write(const vsg::Object* object, const vsg::Path& filename, vsg::ref_ptr<const vsg::Options> = {}) const override;
52  bool write(const vsg::Object* object, std::ostream& stream, vsg::ref_ptr<const vsg::Options> = {}) const override;
53 
54  bool getFeatures(Features& features) const override;
55 
56  // vsg::Options::setValue(str, value) suppoorted options:
57  static constexpr const char* jpeg_quality = "jpeg_quality";
58 
59  bool readOptions(vsg::Options& options, vsg::CommandLine& arguments) const override;
60 
61  private:
62  std::set<vsg::Path> _supportedExtensions;
63  };
64 
66  class VSGXCHANGE_DECLSPEC dds : public vsg::Inherit<vsg::ReaderWriter, dds>
67  {
68  public:
69  dds();
70 
71  vsg::ref_ptr<vsg::Object> read(const vsg::Path& filename, vsg::ref_ptr<const vsg::Options> options = {}) const override;
72  vsg::ref_ptr<vsg::Object> read(std::istream& fin, vsg::ref_ptr<const vsg::Options> options = {}) const override;
73  vsg::ref_ptr<vsg::Object> read(const uint8_t* ptr, size_t size, vsg::ref_ptr<const vsg::Options> options = {}) const override;
74 
75  bool getFeatures(Features& features) const override;
76 
77  private:
78  std::set<vsg::Path> _supportedExtensions;
79  };
80 
82  class VSGXCHANGE_DECLSPEC ktx : public vsg::Inherit<vsg::ReaderWriter, ktx>
83  {
84  public:
85  ktx();
86 
87  vsg::ref_ptr<vsg::Object> read(const vsg::Path& filename, vsg::ref_ptr<const vsg::Options> options = {}) const override;
88  vsg::ref_ptr<vsg::Object> read(std::istream& fin, vsg::ref_ptr<const vsg::Options> options = {}) const override;
89  vsg::ref_ptr<vsg::Object> read(const uint8_t* ptr, size_t size, vsg::ref_ptr<const vsg::Options> options = {}) const override;
90 
91  bool getFeatures(Features& features) const override;
92 
93  private:
94  std::set<vsg::Path> _supportedExtensions;
95  };
96 
98  class openexr : public vsg::Inherit<vsg::ReaderWriter, openexr>
99  {
100  public:
101  openexr();
102 
103  vsg::ref_ptr<vsg::Object> read(const vsg::Path& filename, vsg::ref_ptr<const vsg::Options> options = {}) const override;
104  vsg::ref_ptr<vsg::Object> read(std::istream& fin, vsg::ref_ptr<const vsg::Options> options = {}) const override;
105  vsg::ref_ptr<vsg::Object> read(const uint8_t* ptr, size_t size, vsg::ref_ptr<const vsg::Options> options = {}) const override;
106 
107  bool write(const vsg::Object* object, const vsg::Path& filename, vsg::ref_ptr<const vsg::Options> = {}) const override;
108  bool write(const vsg::Object* object, std::ostream& fout, vsg::ref_ptr<const vsg::Options> = {}) const override;
109 
110  bool getFeatures(Features& features) const override;
111 
112  private:
113  std::set<vsg::Path> _supportedExtensions;
114  };
115 
116 } // namespace vsgXchange
117 
118 EVSG_type_name(vsgXchange::images);
119 EVSG_type_name(vsgXchange::stbi);
120 EVSG_type_name(vsgXchange::dds);
121 EVSG_type_name(vsgXchange::ktx);
122 EVSG_type_name(vsgXchange::openexr);
add dds support using local build of tinydds.
Definition: images.h:67
Definition: images.h:37
add ktx using using local build of libktx
Definition: images.h:83
optional .exr support using OpenEXR library
Definition: images.h:99
add png, jpeg and gif support using local build of stbi.
Definition: images.h:44