Geogram  Version 1.9.1-rc
A programming library of geometric algorithms
image_library.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2000-2022 Inria
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  * * Neither the name of the ALICE Project-Team nor the names of its
14  * contributors may be used to endorse or promote products derived from this
15  * software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  *
29  * Contact: Bruno Levy
30  *
31  * https://www.inria.fr/fr/bruno-levy
32  *
33  * Inria,
34  * Domaine de Voluceau,
35  * 78150 Le Chesnay - Rocquencourt
36  * FRANCE
37  *
38  */
39 
40 #ifndef H_OGF_IMAGE_TYPES_IMAGE_LIBRARY_H
41 #define H_OGF_IMAGE_TYPES_IMAGE_LIBRARY_H
42 
43 #include <geogram/basic/common.h>
44 #include <geogram/image/image.h>
46 
48 
49 #include <string>
50 #include <map>
51 
57 namespace GEO {
58 
59 //_________________________________________________________
60 
61  class ImageSerializer;
62  class Image;
63 
68  class GEOGRAM_API ImageLibrary : public Environment {
69  public:
70 
76 
83  static void initialize();
84 
91  static void terminate();
92 
103  const std::string& extension, ImageSerializer* serializer
104  );
105 
114  const std::string& extension
115  ) const;
116 
126  bool bind_image(const std::string& name, Image* image);
127 
135  bool unbind_image(const std::string& name);
136 
144  Image* resolve_image(const std::string& name) const;
145 
153  Image* load_image(const std::string& file_name);
154 
163  bool save_image(const std::string& file_name, Image* image);
164 
171 
179  const std::string& name, std::string& value
180  ) const override;
181 
186  const std::string& name, const std::string& value
187  ) override;
188 
189  protected:
190  ImageLibrary();
191  ~ImageLibrary() override;
192  friend class World;
193 
194  private:
195  static ImageLibrary* instance_;
196  std::map<std::string, ImageSerializer_var> image_serializers_;
197  std::map<std::string, Image_var> images_;
198  };
199 
200 //_________________________________________________________
201 
206  template <class T> class geo_declare_image_serializer {
207  public:
220  extension, new T
221  );
222  }
223  };
224 
225 //_________________________________________________________
226 
227 }
228 #endif
Application environment.
Definition: environment.h:211
Manages the ImageSerializer repository and the named images.
Definition: image_library.h:68
bool set_local_value(const std::string &name, const std::string &value) override
Sets a variable value locally.
static ImageLibrary * instance()
Gets the instance.
static void terminate()
Terminates the ImageLibrary instance.
bool get_local_value(const std::string &name, std::string &value) const override
Retrieves a variable value locally.
bool unbind_image(const std::string &name)
Unbinds a named image.
Image * load_image(const std::string &file_name)
Loads an image from a file.
bool bind_image(const std::string &name, Image *image)
Binds an image with a name.
Image * resolve_image(const std::string &name) const
Finds an image by name.
bool save_image(const std::string &file_name, Image *image)
Saves an image into a file.
bool bind_image_serializer(const std::string &extension, ImageSerializer *serializer)
Binds an ImageSerializer.
void copy_image_to_clipboard(Image *image)
Copies an image to the clipboard of the operating system.
ImageSerializer * resolve_image_serializer(const std::string &extension) const
Finds an ImageSerializer by extension.
static void initialize()
Initializes the ImageLibrary instance.
Loads and saves images.
An image.
Definition: image.h:59
Declares an image serializer for a given extension.
geo_declare_image_serializer(const std::string &extension)
Declares an image serializer for a given extension.
Provides a mechanism to store global variables, retrieve them by their names and attach observers to ...
Common include file, providing basic definitions. Should be included before anything else by all head...
Class to draw triangles in an image.
std::string extension(const std::string &path)
Gets a path extension.
Global Vorpaline namespace.
Definition: basic.h:55