Visualization Library 2.0.0-b3

A lightweight C++ OpenGL middleware for 2D/3D graphics

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
ioPNG.hpp
Go to the documentation of this file.
1 /**************************************************************************************/
2 /* */
3 /* Visualization Library */
4 /* http://visualizationlibrary.org */
5 /* */
6 /* Copyright (c) 2005-2017, Michele Bosi */
7 /* All rights reserved. */
8 /* */
9 /* Redistribution and use in source and binary forms, with or without modification, */
10 /* are permitted provided that the following conditions are met: */
11 /* */
12 /* - Redistributions of source code must retain the above copyright notice, this */
13 /* list of conditions and the following disclaimer. */
14 /* */
15 /* - Redistributions in binary form must reproduce the above copyright notice, this */
16 /* list of conditions and the following disclaimer in the documentation and/or */
17 /* other materials provided with the distribution. */
18 /* */
19 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND */
20 /* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */
21 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
22 /* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR */
23 /* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
24 /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
25 /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
26 /* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
27 /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
28 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
29 /* */
30 /**************************************************************************************/
31 
32 #if !defined(ioPNG_INCLUDE_ONCE)
33 #define ioPNG_INCLUDE_ONCE
34 
37 #include <vlCore/Image.hpp>
38 
39 namespace vl
40 {
41  class VirtualFile;
42  class String;
43  class Image;
44 
45  VLCORE_EXPORT ref<Image> loadPNG(VirtualFile* file);
46  VLCORE_EXPORT ref<Image> loadPNG(const String& path);
47  VLCORE_EXPORT bool isPNG(VirtualFile* file);
48  VLCORE_EXPORT bool savePNG(const Image* src, const String& path, int compression = 6);
49  VLCORE_EXPORT bool savePNG(const Image* src, VirtualFile* file, int compression = 6);
50 
51  //---------------------------------------------------------------------------
52  // LoadWriterPNG
53  //---------------------------------------------------------------------------
58  {
60 
61  public:
63  {
64  VL_DEBUG_SET_OBJECT_NAME()
65  }
66 
68  {
70  ref<Image> img = loadPNG(path);
71  if (img)
72  res_db->resources().push_back(img);
73  return res_db;
74  }
75 
77  {
79  ref<Image> img = loadPNG(file);
80  if (img)
81  res_db->resources().push_back(img);
82  return res_db;
83  }
84 
85  bool writeResource(const String& path, ResourceDatabase* resource) const
86  {
87  bool ok = true;
88  for(unsigned i=0; i<resource->count<Image>(); ++i)
89  ok &= savePNG(resource->get<Image>(i), path, compression());
90  return ok;
91  }
92 
93  bool writeResource(VirtualFile* file, ResourceDatabase* resource) const
94  {
95  bool ok = true;
96  for(unsigned i=0; i<resource->count<Image>(); ++i)
97  ok &= savePNG(resource->get<Image>(i), file, compression());
98  return ok;
99  }
100 
101  int compression() const { return mCompression; }
104 
105  protected:
107  };
108 }
109 
110 #endif
An abstract class representing a file.
Definition: VirtualFile.hpp:60
The String class implements an advanced UTF16 (Unicode BMP) string manipulation engine.
Definition: String.hpp:62
ref< ResourceDatabase > loadResource(const String &path) const
Definition: ioPNG.hpp:67
size_t count() const
Don&#39;t use inside loops! Counts the number object of the specified type.
#define VL_INSTRUMENT_CLASS(ClassName, BaseClass)
Definition: TypeInfo.hpp:122
Visualization Library main namespace.
The LoadWriterPNG class is a ResourceLoadWriter capable of reading PNG files.
Definition: ioPNG.hpp:57
VLCORE_EXPORT bool savePNG(const Image *src, const String &path, int compression=6)
Definition: ioPNG.cpp:396
void get(std::vector< ref< T > > &resources, bool clear_vector=true)
Returns all the objects of the specified type in the given vector.
void setCompression(int compression)
Sets the compression level used when saving a file. Should be between 0 and 9.
Definition: ioPNG.hpp:103
VLCORE_EXPORT bool isPNG(VirtualFile *file)
Definition: ioPNG.cpp:379
ref< ResourceDatabase > loadResource(VirtualFile *file) const
Definition: ioPNG.hpp:76
int compression() const
Definition: ioPNG.hpp:101
Implements a generic 1d, 2d, 3d and cubemap image that can have mipmaps.
Definition: Image.hpp:54
The ref<> class is used to reference-count an Object.
Definition: Object.hpp:55
VLCORE_EXPORT ref< Image > loadPNG(VirtualFile *file)
Definition: ioPNG.cpp:81
The ResourceLoadWriter class is an abstract class used to implement read/write support for one or mor...
The ResourceDatabase class contains and manipulates a set of resources.
bool writeResource(const String &path, ResourceDatabase *resource) const
Definition: ioPNG.hpp:85
bool writeResource(VirtualFile *file, ResourceDatabase *resource) const
Definition: ioPNG.hpp:93