OgreImage.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4  (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2013 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 #ifndef _Image_H__
29 #define _Image_H__
30 
31 #include "OgrePrerequisites.h"
32 #include "OgreCommon.h"
33 #include "OgrePixelFormat.h"
34 #include "OgreDataStream.h"
35 
36 namespace Ogre {
45  {
46  IF_COMPRESSED = 0x00000001,
47  IF_CUBEMAP = 0x00000002,
48  IF_3D_TEXTURE = 0x00000004
49  };
61  class _OgreExport Image : public ImageAlloc
62  {
63  public:
64  typedef Ogre::Box Box;
65  typedef Ogre::Rect Rect;
66  public:
69  Image();
72  Image( const Image &img );
73 
76  virtual ~Image();
77 
80  Image & operator = ( const Image & img );
81 
102 
118 
165  Image& loadDynamicImage( uchar* data, uint32 width, uint32 height,
166  uint32 depth,
167  PixelFormat format, bool autoDelete = false,
168  size_t numFaces = 1, uint8 numMipMaps = 0);
169 
206  uint32 height, PixelFormat format)
207  {
208  return loadDynamicImage(data, width, height, 1, format);
209  }
230  DataStreamPtr& stream,
231  uint32 width, uint32 height, uint32 depth,
232  PixelFormat format,
233  size_t numFaces = 1, size_t numMipMaps = 0);
254  DataStreamPtr& stream,
255  uint32 width, uint32 height,
256  PixelFormat format )
257  {
258  return loadRawData(stream, width, height, 1, format);
259  }
260 
276  Image & load( const String& filename, const String& groupName );
277 
298  Image & load(DataStreamPtr& stream, const String& type = StringUtil::BLANK );
299 
310  Image & loadTwoImagesAsRGBA(const String& rgbFilename, const String& alphaFilename,
311  const String& groupName, PixelFormat format = PF_BYTE_RGBA);
312 
329  const String& rgbType = StringUtil::BLANK, const String& alphaType = StringUtil::BLANK);
330 
340  Image & combineTwoImagesAsRGBA(const Image& rgb, const Image& alpha, PixelFormat format = PF_BYTE_RGBA);
341 
342 
352  void save(const String& filename);
353 
358  DataStreamPtr encode(const String& formatextension);
359 
366  uchar* getData(void);
367 
374  const uchar * getData() const;
375 
378  size_t getSize() const;
379 
383 
386  bool hasFlag(const ImageFlags imgFlag) const;
387 
390  uint32 getWidth(void) const;
391 
394  uint32 getHeight(void) const;
395 
398  uint32 getDepth(void) const;
399 
403  size_t getNumFaces(void) const;
404 
407  size_t getRowSpan(void) const;
408 
412 
415  uchar getBPP() const;
416 
419  bool getHasAlpha() const;
420 
426  static void applyGamma( uchar *buffer, Real gamma, size_t size, uchar bpp );
427 
433  ColourValue getColourAt(size_t x, size_t y, size_t z) const;
434 
440  void setColourAt(ColourValue const &cv, size_t x, size_t y, size_t z);
441 
445  PixelBox getPixelBox(size_t face = 0, size_t mipmap = 0) const;
446 
448  void freeMemory();
449 
450  enum Filter
451  {
457  FILTER_BICUBIC
458  };
466  static void scale(const PixelBox &src, const PixelBox &dst, Filter filter = FILTER_BILINEAR);
467 
469  void resize(ushort width, ushort height, Filter filter = FILTER_BILINEAR);
470 
472  static size_t calculateSize(size_t mipmaps, size_t faces, uint32 width, uint32 height, uint32 depth, PixelFormat format);
473 
476 
477  protected:
485  size_t mBufSize;
489  int mFlags;
490 
493 
497 
500  };
501 
504 
508 } // namespace
509 
510 #endif
Ogre::Image::getColourAt
ColourValue getColourAt(size_t x, size_t y, size_t z) const
Get colour value from a certain location in the image.
Ogre::Image::mBuffer
uchar * mBuffer
Definition: OgreImage.h:496
Ogre::Image::calculateSize
static size_t calculateSize(size_t mipmaps, size_t faces, uint32 width, uint32 height, uint32 depth, PixelFormat format)
Static function to calculate size in bytes from the number of mipmaps, faces and the dimensions.
Ogre::Image::getFormat
PixelFormat getFormat() const
Returns the image format.
Ogre::Image::encode
DataStreamPtr encode(const String &formatextension)
Encode the image and return a stream to the data.
Ogre::Image::FILTER_TRIANGLE
@ FILTER_TRIANGLE
Definition: OgreImage.h:456
Ogre::AllocatedObject
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
Definition: OgreMemoryAllocatedObject.h:59
Ogre
Definition: OgreAndroidLogListener.h:35
OgrePixelFormat.h
Ogre::Image::mHeight
uint32 mHeight
The height of the image in pixels.
Definition: OgreImage.h:481
Ogre::Image::Image
Image()
Standard constructor.
Ogre::Image::FILTER_LINEAR
@ FILTER_LINEAR
Definition: OgreImage.h:453
Ogre::ushort
unsigned short ushort
Definition: OgrePrerequisites.h:113
Ogre::ImageFlags
ImageFlags
Definition: OgreImage.h:45
Ogre::Image::Filter
Filter
Definition: OgreImage.h:451
Ogre::Image::getRowSpan
size_t getRowSpan(void) const
Gets the physical width in bytes of each row of pixels.
Ogre::Image::load
Image & load(DataStreamPtr &stream, const String &type=StringUtil::BLANK)
Loads an image file from a stream.
Ogre::Image::FILTER_BOX
@ FILTER_BOX
Definition: OgreImage.h:455
Ogre::IF_3D_TEXTURE
@ IF_3D_TEXTURE
Definition: OgreImage.h:48
Ogre::PF_BYTE_RGBA
@ PF_BYTE_RGBA
4 byte pixel format, 1 byte for red, 1 byte for green, 1 byte for blue, and one byte for alpha
Definition: OgrePixelFormat.h:105
Ogre::Image
Class representing an image file.
Definition: OgreImage.h:62
Ogre::Image::loadTwoImagesAsRGBA
Image & loadTwoImagesAsRGBA(DataStreamPtr &rgbStream, DataStreamPtr &alphaStream, PixelFormat format=PF_BYTE_RGBA, const String &rgbType=StringUtil::BLANK, const String &alphaType=StringUtil::BLANK)
Utility method to combine 2 separate images into this one, with the first image source supplying the ...
Ogre::TRect< long >
Ogre::Image::loadDynamicImage
Image & loadDynamicImage(uchar *data, uint32 width, uint32 height, uint32 depth, PixelFormat format, bool autoDelete=false, size_t numFaces=1, uint8 numMipMaps=0)
Stores a pointer to raw data in memory.
Ogre::Image::getWidth
uint32 getWidth(void) const
Gets the width of the image in pixels.
Ogre::Image::combineTwoImagesAsRGBA
Image & combineTwoImagesAsRGBA(const Image &rgb, const Image &alpha, PixelFormat format=PF_BYTE_RGBA)
Utility method to combine 2 separate images into this one, with the first image source supplying the ...
Ogre::Image::mAutoDelete
bool mAutoDelete
A bool to determine if we delete the buffer or the calling app does.
Definition: OgreImage.h:499
Ogre::uint32
unsigned int uint32
Definition: OgrePlatform.h:359
Ogre::Image::getDepth
uint32 getDepth(void) const
Gets the depth of the image.
Ogre::String
_StringBase String
Definition: OgrePrerequisites.h:439
Ogre::Image::getData
const uchar * getData() const
Returns a const pointer to the internal image buffer.
Ogre::Image::mBufSize
size_t mBufSize
The size of the image buffer.
Definition: OgreImage.h:485
Ogre::Image::mFormat
PixelFormat mFormat
The pixel format of the image.
Definition: OgreImage.h:492
Ogre::Image::getNumMipmaps
uint8 getNumMipmaps() const
Returns the number of mipmaps contained in the image.
Ogre::Image::getSize
size_t getSize() const
Returns the size of the data buffer.
Ogre::Image::getData
uchar * getData(void)
Returns a pointer to the internal image buffer.
Ogre::Image::resize
void resize(ushort width, ushort height, Filter filter=FILTER_BILINEAR)
Resize a 2D image, applying the appropriate filter.
Ogre::Image::setColourAt
void setColourAt(ColourValue const &cv, size_t x, size_t y, size_t z)
Set colour value at a certain location in the image.
Ogre::StringUtil::BLANK
static const String BLANK
Constant blank string, useful for returning by ref where local does not exist.
Definition: OgreString.h:196
Ogre::vector::type
std::vector< T, A > type
Definition: OgrePrerequisites.h:494
Ogre::Image::applyGamma
static void applyGamma(uchar *buffer, Real gamma, size_t size, uchar bpp)
Does gamma adjustment.
Ogre::Image::FILTER_NEAREST
@ FILTER_NEAREST
Definition: OgreImage.h:452
Ogre::PixelFormat
PixelFormat
The pixel format used for images, textures, and render surfaces.
Definition: OgrePixelFormat.h:44
Ogre::Image::Image
Image(const Image &img)
Copy-constructor - copies all the data from the target image.
Ogre::Image::mWidth
uint32 mWidth
The width of the image in pixels.
Definition: OgreImage.h:479
Ogre::Image::getFileExtFromMagic
static String getFileExtFromMagic(DataStreamPtr stream)
Static function to get an image type string from a stream via magic numbers.
OgrePrerequisites.h
Ogre::ConstImagePtrList
vector< const Image * >::type ConstImagePtrList
Definition: OgreImage.h:503
Ogre::uchar
unsigned char uchar
In order to avoid finger-aches :)
Definition: OgrePrerequisites.h:112
Ogre::Image::getHasAlpha
bool getHasAlpha() const
Returns true if the image has an alpha component.
Ogre::Image::getBPP
uchar getBPP() const
Returns the number of bits per pixel.
Ogre::Image::save
void save(const String &filename)
Save the image as a file.
_OgreExport
#define _OgreExport
Definition: OgrePlatform.h:257
Ogre::Box
Structure used to define a box in a 3-D integer space.
Definition: OgreCommon.h:660
OgreCommon.h
Ogre::Image::loadRawData
Image & loadRawData(DataStreamPtr &stream, uint32 width, uint32 height, uint32 depth, PixelFormat format, size_t numFaces=1, size_t numMipMaps=0)
Loads raw data from a stream.
Ogre::Image::scale
static void scale(const PixelBox &src, const PixelBox &dst, Filter filter=FILTER_BILINEAR)
Scale a 1D, 2D or 3D image volume.
Ogre::Image::loadDynamicImage
Image & loadDynamicImage(uchar *data, uint32 width, uint32 height, PixelFormat format)
Stores a pointer to raw data in memory.
Definition: OgreImage.h:205
Ogre::Image::~Image
virtual ~Image()
Standard destructor.
Ogre::SharedPtr< DataStream >
Ogre::uint8
unsigned char uint8
Definition: OgrePlatform.h:361
Ogre::Image::FILTER_BILINEAR
@ FILTER_BILINEAR
Definition: OgreImage.h:454
Ogre::IF_CUBEMAP
@ IF_CUBEMAP
Definition: OgreImage.h:47
Ogre::ImagePtrList
vector< Image * >::type ImagePtrList
Definition: OgreImage.h:502
Ogre::ColourValue
Class representing colour.
Definition: OgreColourValue.h:58
Ogre::IF_COMPRESSED
@ IF_COMPRESSED
Definition: OgreImage.h:46
Ogre::PixelBox
A primitive describing a volume (3D), image (2D) or line (1D) of pixels in memory.
Definition: OgrePixelFormat.h:304
Ogre::Image::loadTwoImagesAsRGBA
Image & loadTwoImagesAsRGBA(const String &rgbFilename, const String &alphaFilename, const String &groupName, PixelFormat format=PF_BYTE_RGBA)
Utility method to combine 2 separate images into this one, with the first image source supplying the ...
Ogre::Image::mNumMipmaps
uint8 mNumMipmaps
The number of mipmaps the image contains.
Definition: OgreImage.h:487
Ogre::Image::load
Image & load(const String &filename, const String &groupName)
Loads an image file.
Ogre::Image::Rect
Ogre::Rect Rect
Definition: OgreImage.h:65
Ogre::Image::flipAroundY
Image & flipAroundY()
Flips (mirrors) the image around the Y-axis.
Ogre::Real
float Real
Software floating point type.
Definition: OgrePrerequisites.h:70
Ogre::Image::getPixelBox
PixelBox getPixelBox(size_t face=0, size_t mipmap=0) const
Get a PixelBox encapsulating the image data of a mipmap.
Ogre::Image::hasFlag
bool hasFlag(const ImageFlags imgFlag) const
Returns true if the image has the appropriate flag set.
Ogre::Image::freeMemory
void freeMemory()
Delete all the memory held by this image, if owned by this image (not dynamic)
Ogre::Image::mPixelSize
uchar mPixelSize
The number of bytes per pixel.
Definition: OgreImage.h:495
Ogre::Image::getNumFaces
size_t getNumFaces(void) const
Get the number of faces of the image.
Ogre::Image::getHeight
uint32 getHeight(void) const
Gets the height of the image in pixels.
Ogre::Image::mFlags
int mFlags
Image specific flags.
Definition: OgreImage.h:489
Ogre::Image::mDepth
uint32 mDepth
The depth of the image.
Definition: OgreImage.h:483
Ogre::Image::Box
Ogre::Box Box
Definition: OgreImage.h:64
Ogre::Image::loadRawData
Image & loadRawData(DataStreamPtr &stream, uint32 width, uint32 height, PixelFormat format)
Loads raw data from a stream.
Definition: OgreImage.h:253
OgreDataStream.h
Ogre::Image::flipAroundX
Image & flipAroundX()
Flips (mirrors) the image around the X-axis.

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.