Spinning Topp Logo BlackTopp Studios
inc
image.h
1 // © Copyright 2010 - 2016 BlackTopp Studios Inc.
2 /* This file is part of The Mezzanine Engine.
3 
4  The Mezzanine Engine is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  The Mezzanine Engine is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>.
16 */
17 /* The original authors have included a copy of the license specified above in the
18  'Docs' folder. See 'gpl.txt'
19 */
20 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
21  Build professional software and charge for their product.
22 
23  However there are some practical restrictions, so if your project involves
24  any of the following you should contact us and we will try to work something
25  out:
26  - DRM or Copy Protection of any kind(except Copyrights)
27  - Software Patents You Do Not Wish to Freely License
28  - Any Kind of Linking to Non-GPL licensed Works
29  - Are Currently In Violation of Another Copyright Holder's GPL License
30  - If You want to change our code and not add a few hundred MB of stuff to
31  your distribution
32 
33  These and other limitations could cause serious legal problems if you ignore
34  them, so it is best to simply contact us or the Free Software Foundation, if
35  you have any questions.
36 
37  Joseph Toppi - toppij@gmail.com
38  John Blackwood - makoenergy02@gmail.com
39 */
40 
41 #ifndef _graphicsimage_h
42 #define _graphicsimage_h
43 
44 #include "datatypes.h"
45 #include "colourvalue.h"
46 #include "Graphics/graphicsenumerations.h"
47 
48 
49 namespace Ogre
50 {
51  class Image;
52 }//Ogre
53 
54 namespace Mezzanine
55 {
56  namespace Graphics
57  {
58  class InternalImageData;
59  ///////////////////////////////////////////////////////////////////////////////
60  /// @brief This class represents an image loaded into system memory.
61  /// @details
62  ///////////////////////////////////////
64  {
65  protected:
66  /// @internal
67  /// @brief A pointer to the internal implementation of the Image.
69  public:
70  /// @brief Blank, no-init constructor.
71  Image();
72  /// @brief Resource constructor.
73  /// @param ResourceName The name of the resource to be loaded.
74  /// @param ResourceGroup The name of the group the resource is located in.
75  Image(const String& ResourceName, const String& ResourceGroup);
76  /// @brief 2D image buffer constructor.
77  /// @param Data The buffer to load the image from.
78  /// @param Width The width of the image to be loaded.
79  /// @param Height The height of the image to be loaded.
80  /// @param Format The pixel format of the buffer being loaded.
81  /// @param AutoDelete Whether or not this image owns the buffer, allowing it to delete the buffer when it is done.
82  /// @param NumFaces The number of faces that exist for the image.
83  /// @param NumMipMaps The number of mipmaps that exist for the image.
84  Image(UInt8* Data, const UInt32 Width, const UInt32 Height, const Graphics::PixelFormat Format, const Boole AutoDelete = false, const Whole NumFaces = 1, const UInt8 NumMipMaps = 0);
85  /// @brief 3D image buffer constructor.
86  /// @param Data The buffer to load the image from.
87  /// @param Width The width of the image to be loaded.
88  /// @param Height The height of the image to be loaded.
89  /// @param Depth The depth of the image to be loaded.
90  /// @param Format The pixel format of the buffer being loaded.
91  /// @param AutoDelete Whether or not this image owns the buffer, allowing it to delete the buffer when it is done.
92  /// @param NumFaces The number of faces that exist for the image.
93  /// @param NumMipMaps The number of mipmaps that exist for the image.
94  Image(UInt8* Data, const UInt32 Width, const UInt32 Height, const UInt32 Depth, const Graphics::PixelFormat Format, const Boole AutoDelete = false, const Whole NumFaces = 1, const UInt8 NumMipMaps = 0);
95  /// @brief Class Destructor.
96  ~Image();
97 
98  ///////////////////////////////////////////////////////////////////////////////
99  // Utility Methods
100 
101  /// @brief Gets the width of this image in pixels.
102  /// @return Returns a UInt32 representing the size of this image on the X axis.
103  UInt32 GetWidth() const;
104  /// @brief Gets the height of this image in pixels.
105  /// @return Returns a UInt32 representing the size of this image on the Y axis.
106  UInt32 GetHeight() const;
107  /// @brief Gets the depth of this image in pixels.
108  /// @return Returns a UInt32 representing the size of this image on the Z axis.
109  UInt32 GetDepth() const;
110  /// @brief Gets the pixel format of this image.
111  /// @return Returns a PixelFormat enum value representing how the bits of this image are layed out.
112  Graphics::PixelFormat GetFormat() const;
113  /// @brief Gets the number of bits allocated for each pixel in this image.
114  /// @return Returns a UInt8 containing the size of each pixel in bits.
115  UInt8 GetBitsPerPixel() const;
116  /// @brief Gets the number of faces for thie image.
117  /// @remarks Generally this will either be 1 for a normal image, or 6 for a cubemap.
118  /// @return Returns a Whole representing the number of faces this image has.
119  Whole GetNumFaces() const;
120  /// @brief Gets the number of MipMaps that exist for this image.
121  /// @return Returns the number of MipMaps this image has.
122  Whole GetNumMipMaps() const;
123 
124  /// @brief Gets the raw image data.
125  /// @return Returns a pointer to the array storing the raw data for this image.
126  UInt8* GetImageData();
127  /// @brief Gets the raw image data.
128  /// @return Returns a const pointer to the array storing the raw data for this image.
129  const UInt8* GetImageData() const;
130  /// @brief Gets the size of this image.
131  /// @return Returns a Whole representing the total size of this image in bytes.
132  Whole GetSize() const;
133  /// @brief Gets the size of a row of pixels in this image.
134  /// @return Returns a Whole representing the byte size of a row of pixels in this image.
135  Whole GetRowSpan() const;
136 
137  /// @brief Reverses the order of each pixel on the X axis.
138  /// @return Returns a reference to this.
139  Image& FlipAroundXAxis();
140  /// @brief Reverses the order of each pixel on the Y axis.
141  /// @return Returns a reference to this.
142  Image& FlipAroundYAxis();
143 
144  /// @brief Sets the colour of an individual pixel in this image.
145  /// @param X The X position of the pixel to alter.
146  /// @param Y The Y position of the pixel to alter.
147  /// @param Z The Z position of the pixel to alter.
148  /// @param Colour The colour to set for the pixel at the specified position.
149  void SetColourAt(const Whole X, const Whole Y, const Whole Z, const ColourValue& Colour);
150  /// @brief Gets the colour of an individual pixel in this image.
151  /// @param X The X position of the pixel to retrieve.
152  /// @param Y The Y position of the pixel to retrieve.
153  /// @param Z The Z position of the pixel to retrieve.
154  /// @return Returns a ColourValue containing the colour of the pixel at the specified position.
155  ColourValue GetColourAt(const Whole X, const Whole Y, const Whole Z) const;
156 
157  ///////////////////////////////////////////////////////////////////////////////
158  // Initialize Methods
159 
160  /// @brief Loads an image from a buffer.
161  /// @param Data The buffer to load the image from.
162  /// @param Width The width of the image to be loaded.
163  /// @param Height The height of the image to be loaded.
164  /// @param Format The pixel format of the buffer being loaded.
165  /// @param AutoDelete Whether or not this image owns the buffer, allowing it to delete the buffer when it is done.
166  /// @param NumFaces The number of faces that exist for the image.
167  /// @param NumMipMaps The number of mipmaps that exist for the image.
168  /// @return Returns a reference to this.
169  Image& Initialize(UInt8* Data, const UInt32 Width, const UInt32 Height, const Graphics::PixelFormat Format, const Boole AutoDelete = false, const Whole NumFaces = 1, const UInt8 NumMipMaps = 0);
170  /// @brief Loads an image from a buffer.
171  /// @param Data The buffer to load the image from.
172  /// @param Width The width of the image to be loaded.
173  /// @param Height The height of the image to be loaded.
174  /// @param Depth The depth of the image to be loaded.
175  /// @param Format The pixel format of the buffer being loaded.
176  /// @param AutoDelete Whether or not this image owns the buffer, allowing it to delete the buffer when it is done.
177  /// @param NumFaces The number of faces that exist for the image.
178  /// @param NumMipMaps The number of mipmaps that exist for the image.
179  /// @return Returns a reference to this.
180  Image& Initialize(UInt8* Data, const UInt32 Width, const UInt32 Height, const UInt32 Depth, const Graphics::PixelFormat Format, const Boole AutoDelete = false, const Whole NumFaces = 1, const UInt8 NumMipMaps = 0);
181 
182  ///////////////////////////////////////////////////////////////////////////////
183  // Loading Methods
184 
185  /// @brief Loads an image.
186  /// @param ResourceName The name of the resource to be loaded.
187  /// @param ResourceGroup The name of the group the resource is located in.
188  /// @return Returns a reference to this.
189  Image& Load(const String& ResourceName, const String& ResourceGroup);
190  /// @brief Loads an image from the disk.
191  /// @param FilePathAndName The full path and filename of the image to be read.
192  /// @return Returns a reference to this.
193  Image& Load(const String& FilePathAndName);
194 
195  /// @brief Loads an image from an input stream.
196  /// @param Stream A pointer to the stream to load this image from.
197  /// @param ExtensionHint The extension (not including the period) that this stream should be read as. Can be blank to auto-detect.
198  /// @return Returns a reference to this.
199  Image& Load(std::istream* Stream, const String& ExtensionHint = "");
200 
201  ///////////////////////////////////////////////////////////////////////////////
202  // Saving Methods
203 
204  /// @brief Writes this image to the asset group.
205  /// @remarks This method will infer the encoding from the provided file extension which needs to be included in the FileName parameter. Check the ImageFileFormat enum
206  /// for details on which formats/extensions have write support. Also keep in mind that different file formats have support for different pixel formats. Ensure you are
207  /// encoding to something that can support the currently set pixel format otherwise you risk generating a corrupted image.
208  /// @param FileName The name of the file to save this as.
209  /// @param GroupName The name of the asset group to save this to.
210  /// @return Returns a reference to this.
211  Image& Save(const String& FileName, const String& GroupName);
212  /// @brief Writes this image to the disk.
213  /// @remarks This method will infer the encoding from the provided file extension which needs to be included in the FileName parameter. Check the ImageFileFormat enum
214  /// for details on which formats/extensions have write support. Also keep in mind that different file formats have support for different pixel formats. Ensure you are
215  /// encoding to something that can support the currently set pixel format otherwise you risk generating a corrupted image. @n @n
216  /// This method also completely bypasses the bulk of the Mezzanine resource system and writes directly to the filesystem. Use with care.
217  /// @param FilePathAndName The full path and filename of the image to be written.
218  /// @return Returns a reference to this.
219  Image& Save(const String& FilePathAndName);
220 
221  /// @brief Writes this image in a final serializable form to an output stream.
222  /// @remarks Keep in mind that different file formats have support for different pixel formats. Ensure you are encoding to something that can support the currently set
223  /// pixel format otherwise you risk generating a corrupted image.
224  /// @param Format The ImageFileFormat to encode the image with.
225  /// @param Stream A pointer to the stream to save this image to.
226  /// @return Returns a reference to this.
227  Image& Save(const Graphics::ImageFileFormat Format, std::ostream* Stream);
228  /// @brief Writes this image in a final serializable form to an output stream.
229  /// @remarks This method will infer the encoding from the provided file extension. Keep in mind that different file formats have support for different pixel formats.
230  /// Ensure you are encoding to something that can support the currently set pixel format otherwise you risk generating a corrupted image.
231  /// @param Extension A string containing the extension to encode to (not including the period).
232  /// @param Stream A pointer to the stream to save this image to.
233  /// @return Returns a reference to this.
234  Image& Save(const String& Extension, std::ostream* Stream);
235 
236  ///////////////////////////////////////////////////////////////////////////////
237  // Internal Methods
238 
239  /// @internal
240  /// @brief Gets the internal Image this class is based on.
241  /// @return Returns a reference to the internal image class.
242  Ogre::Image& _GetInternalImage() const;
243  };//Image
244  }//Graphics
245 }//Mezzanine
246 
247 #endif
bool Boole
Generally acts a single bit, true or false.
Definition: datatypes.h:173
All the definitions for datatypes as well as some basic conversion functions are defined here...
uint8_t UInt8
An 8-bit unsigned integer.
Definition: datatypes.h:118
This is a simple class for holding 4 reals representing the colour any give object or lightsource can...
Definition: colourvalue.h:64
This class is used to store the internal structures needed by the Image class.
Definition: image.cpp:61
uint32_t UInt32
An 32-bit unsigned integer.
Definition: datatypes.h:126
ProcessDepth Depth
The current process depth as interpretted by Main.
Definition: mezztest.cpp:82
This class represents an image loaded into system memory.
Definition: image.h:63
PixelFormat
This is used to describe how bits are arraged for each pixel in an image.
InternalImageData * IID
A pointer to the internal implementation of the Image.
Definition: image.h:68
#define MEZZ_LIB
Some platforms require special decorations to denote what is exported/imported in a share library...
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
unsigned long Whole
Whole is an unsigned integer, it will be at least 32bits in size.
Definition: datatypes.h:151
ImageFileFormat
This enum describes the various file formats for images supported by the Mezzanine.
std::string String
A datatype used to a series of characters.
Definition: datatypes.h:159