OpenImageIO
 All Classes Files Friends Macros Pages
imagecache.h
Go to the documentation of this file.
1 /*
2  Copyright 2008 Larry Gritz and the other authors and contributors.
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
7  met:
8  * Redistributions of source code must retain the above copyright
9  notice, this list of conditions and the following disclaimer.
10  * Redistributions in binary form must reproduce the above copyright
11  notice, this list of conditions and the following disclaimer in the
12  documentation and/or other materials provided with the distribution.
13  * Neither the name of the software's owners nor the names of its
14  contributors may be used to endorse or promote products derived from
15  this software without specific prior written permission.
16  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28  (This is the Modified BSD License)
29 */
30 
31 
35 
36 
37 #ifndef OPENIMAGEIO_IMAGECACHE_H
38 #define OPENIMAGEIO_IMAGECACHE_H
39 
40 #include "ustring.h"
41 #include "imageio.h"
42 #include "version.h"
43 
44 
45 OIIO_NAMESPACE_ENTER
46 {
47 
48 namespace pvt {
49 // Forward declaration
50 class ImageCacheImpl;
51 };
52 
53 
54 
55 
60 class OIIO_API ImageCache {
61 public:
68  static ImageCache *create (bool shared=true);
69 
72  static void destroy (ImageCache * x);
73 
74  ImageCache (void) { }
75  virtual ~ImageCache () { }
76 
79  virtual void clear () = 0;
80 
102  virtual bool attribute (const std::string &name, TypeDesc type,
103  const void *val) = 0;
104  // Shortcuts for common types
105  virtual bool attribute (const std::string &name, int val) = 0;
106  virtual bool attribute (const std::string &name, float val) = 0;
107  virtual bool attribute (const std::string &name, double val) = 0;
108  virtual bool attribute (const std::string &name, const char *val) = 0;
109  virtual bool attribute (const std::string &name,
110  const std::string &val) = 0;
111 
113  virtual bool getattribute (const std::string &name, TypeDesc type,
114  void *val) = 0;
115  // Shortcuts for common types
116  virtual bool getattribute (const std::string &name, int &val) = 0;
117  virtual bool getattribute (const std::string &name, float &val) = 0;
118  virtual bool getattribute (const std::string &name, double &val) = 0;
119  virtual bool getattribute (const std::string &name, char **val) = 0;
120  virtual bool getattribute (const std::string &name, std::string &val) = 0;
121 
124  virtual std::string resolve_filename (const std::string &filename) const=0;
125 
130  virtual bool get_image_info (ustring filename, int subimage, int miplevel,
131  ustring dataname, TypeDesc datatype, void *data) = 0;
132 
134  bool get_image_info (ustring filename, ustring dataname,
135  TypeDesc datatype, void *data) {
136  return get_image_info (filename, 0, 0, dataname, datatype, data);
137  }
138 
145  virtual bool get_imagespec (ustring filename, ImageSpec &spec,
146  int subimage=0, int miplevel=0,
147  bool native=false) = 0;
148 
160  virtual const ImageSpec *imagespec (ustring filename, int subimage=0,
161  int miplevel=0, bool native=false) = 0;
162 
177  virtual bool get_pixels (ustring filename, int subimage, int miplevel,
178  int xbegin, int xend, int ybegin, int yend,
179  int zbegin, int zend,
180  TypeDesc format, void *result) = 0;
181 
199  virtual bool get_pixels (ustring filename,
200  int subimage, int miplevel, int xbegin, int xend,
201  int ybegin, int yend, int zbegin, int zend,
202  int chbegin, int chend, TypeDesc format, void *result,
203  stride_t xstride=AutoStride, stride_t ystride=AutoStride,
204  stride_t zstride=AutoStride) = 0;
205 
208  class Tile;
209 
217  virtual Tile * get_tile (ustring filename, int subimage, int miplevel,
218  int x, int y, int z) = 0;
219 
222  virtual void release_tile (Tile *tile) const = 0;
223 
228  virtual const void * tile_pixels (Tile *tile, TypeDesc &format) const = 0;
229 
234  virtual std::string geterror () const = 0;
235 
238  virtual std::string getstats (int level=1) const = 0;
239 
245  virtual void reset_stats () = 0;
246 
257  virtual void invalidate (ustring filename) = 0;
258 
268  virtual void invalidate_all (bool force=false) = 0;
269 
270 private:
271  // Make delete private and unimplemented in order to prevent apps
272  // from calling it. Instead, they should call ImageCache::destroy().
273  void operator delete (void * /*todel*/) { }
274 };
275 
276 
277 }
278 OIIO_NAMESPACE_EXIT
279 
280 #endif // OPENIMAGEIO_IMAGECACHE_H