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]
ioTGA.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(ioTGA_INCLUDE_ONCE)
33 #define ioTGA_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> loadTGA(VirtualFile* file);
46  VLCORE_EXPORT ref<Image> loadTGA(const String& path);
47  VLCORE_EXPORT bool isTGA(VirtualFile* file);
48  VLCORE_EXPORT bool saveTGA(const Image* src, const String& path);
49  VLCORE_EXPORT bool saveTGA(const Image* src, VirtualFile* file);
50 
51  //---------------------------------------------------------------------------
52  // LoadWriterTGA
53  //---------------------------------------------------------------------------
58  {
60 
61  public:
62  LoadWriterTGA(): ResourceLoadWriter("|tga|", "|tga|")
63  {
64  VL_DEBUG_SET_OBJECT_NAME()
65  }
66 
68  {
70  ref<Image> img = loadTGA(path);
71  if (img)
72  res_db->resources().push_back(img);
73  return res_db;
74  }
75 
77  {
79  ref<Image> img = loadTGA(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 &= saveTGA(resource->get<Image>(i), path);
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 &= saveTGA(resource->get<Image>(i), file);
98  return ok;
99  }
100  };
101 }
102 
103 #endif
VLCORE_EXPORT bool isTGA(VirtualFile *file)
A TGA file is accepted only if it has a &#39;TGA&#39; extension.
Definition: ioTGA.cpp:480
An abstract class representing a file.
Definition: VirtualFile.hpp:60
The LoadWriterTGA class is a ResourceLoadWriter capable of reading TGA files.
Definition: ioTGA.hpp:57
The String class implements an advanced UTF16 (Unicode BMP) string manipulation engine.
Definition: String.hpp:62
VLCORE_EXPORT ref< Image > loadTGA(VirtualFile *file)
Definition: ioTGA.cpp:100
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.
bool writeResource(VirtualFile *file, ResourceDatabase *resource) const
Definition: ioTGA.hpp:93
void get(std::vector< ref< T > > &resources, bool clear_vector=true)
Returns all the objects of the specified type in the given vector.
ref< ResourceDatabase > loadResource(const String &path) const
Definition: ioTGA.hpp:67
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
The ResourceLoadWriter class is an abstract class used to implement read/write support for one or mor...
bool writeResource(const String &path, ResourceDatabase *resource) const
Definition: ioTGA.hpp:85
VLCORE_EXPORT bool saveTGA(const Image *src, const String &path)
Definition: ioTGA.cpp:401
The ResourceDatabase class contains and manipulates a set of resources.
ref< ResourceDatabase > loadResource(VirtualFile *file) const
Definition: ioTGA.hpp:76