OGRE 14.3
Object-Oriented Graphics Rendering Engine
|
Class representing an image file. More...
#include <OgreImage.h>
Public Types | |
enum | Filter { FILTER_NEAREST , FILTER_LINEAR , FILTER_BILINEAR = FILTER_LINEAR } |
Public Member Functions | |
Image (const Image &img) | |
Copy-constructor - copies all the data from the target image. | |
Image (PixelFormat format=PF_UNKNOWN, uint32 width=0, uint32 height=0, uint32 depth=1, uchar *buffer=NULL, bool autoDelete=true) | |
Standard constructor. | |
~Image () | |
Standard destructor. | |
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 RGB channels, and the second image supplying the alpha channel (as luminance or separate alpha). | |
void | create (PixelFormat format, uint32 width, uint32 height, uint32 depth=1, uint32 numFaces=1, uint32 numMipMaps=0) |
allocates a buffer of given size if needed | |
DataStreamPtr | encode (const String &formatextension) |
Encode the image and return a stream to the data. | |
Image & | flipAroundX () |
Flips (mirrors) the image around the X-axis. | |
Image & | flipAroundY () |
Flips (mirrors) the image around the Y-axis. | |
void | freeMemory () |
Delete all the memory held by this image, if owned by this image (not dynamic) | |
uchar | getBPP () const |
Returns the number of bits per pixel. | |
ColourValue | getColourAt (uint32 x, uint32 y, uint32 z) const |
Get colour value from a certain location in the image. | |
uchar * | getData (uint32 x=0, uint32 y=0, uint32 z=0) |
Returns a pointer to the internal image buffer at the specified pixel location. | |
template<typename T > | |
T * | getData (uint32 x=0, uint32 y=0, uint32 z=0) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
const uchar * | getData (uint32 x=0, uint32 y=0, uint32 z=0) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
template<typename T > | |
const T * | getData (uint32 x=0, uint32 y=0, uint32 z=0) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
uint32 | getDepth (void) const |
Gets the depth of the image. | |
PixelFormat | getFormat () const |
Returns the image format. | |
bool | getHasAlpha () const |
Returns true if the image has an alpha component. | |
uint32 | getHeight (void) const |
Gets the height of the image in pixels. | |
uint32 | getNumFaces (void) const |
Get the number of faces of the image. | |
uint32 | getNumMipmaps () const |
Returns the number of mipmaps contained in the image. | |
PixelBox | getPixelBox (uint32 face=0, uint32 mipmap=0) const |
Get a PixelBox encapsulating the image data of a mipmap. | |
size_t | getRowSpan (void) const |
Gets the physical width in bytes of each row of pixels. | |
size_t | getSize () const |
Returns the size of the data buffer in bytes. | |
uint32 | getWidth (void) const |
Gets the width of the image in pixels. | |
bool | hasFlag (const ImageFlags imgFlag) const |
Returns true if the image has the appropriate flag set. | |
Image & | load (const DataStreamPtr &stream, String type=BLANKSTRING) |
Loads an image file from a stream. | |
Image & | load (const String &filename, const String &groupName) |
Loads an image file. | |
Image & | loadDynamicImage (uchar *data, uint32 width, uint32 height, PixelFormat format) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
Image & | loadDynamicImage (uchar *data, uint32 width, uint32 height, uint32 depth, PixelFormat format, bool autoDelete=false, uint32 numFaces=1, uint32 numMipMaps=0) |
Stores a pointer to raw data in memory. | |
Image & | loadRawData (const DataStreamPtr &stream, uint32 width, uint32 height, PixelFormat format) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
Image & | loadRawData (const DataStreamPtr &stream, uint32 width, uint32 height, uint32 depth, PixelFormat format, uint32 numFaces=1, uint32 numMipMaps=0) |
Loads raw data from a stream. | |
Image & | loadTwoImagesAsRGBA (const DataStreamPtr &rgbStream, const DataStreamPtr &alphaStream, PixelFormat format=PF_BYTE_RGBA, const String &rgbType=BLANKSTRING, const String &alphaType=BLANKSTRING) |
Utility method to combine 2 separate images into this one, with the first image source supplying the RGB channels, and the second image supplying the alpha channel (as luminance or separate alpha). | |
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 RGB channels, and the second image supplying the alpha channel (as luminance or separate alpha). | |
Image & | operator= (const Image &img) |
Assignment operator - copies all the data from the target image. | |
void | resize (ushort width, ushort height, Filter filter=FILTER_BILINEAR) |
Resize a 2D image, applying the appropriate filter. | |
void | save (const String &filename) |
Save the image as a file. | |
void | setColourAt (ColourValue const &cv, uint32 x, uint32 y, uint32 z) |
Set colour value at a certain location in the image. | |
void | setTo (const ColourValue &col) |
sets all pixels to the specified colour | |
Static Public Member Functions | |
static void | applyGamma (uchar *buffer, Real gamma, size_t size, uchar bpp) |
Does gamma adjustment. | |
static size_t | calculateSize (uint32 mipmaps, uint32 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. | |
static String | getFileExtFromMagic (DataStreamPtr stream) |
Static function to get an image type string from a stream via magic numbers. | |
static void | scale (const PixelBox &src, const PixelBox &dst, Filter filter=FILTER_BILINEAR) |
Scale a 1D, 2D or 3D image volume. | |
Class representing an image file.
The Image class usually holds uncompressed image data and is the only object that can be loaded in a texture. Image objects handle image data decoding themselves by the means of locating the correct Codec object for each data type.
Ogre::Image::Image | ( | PixelFormat | format = PF_UNKNOWN , |
uint32 | width = 0 , |
||
uint32 | height = 0 , |
||
uint32 | depth = 1 , |
||
uchar * | buffer = NULL , |
||
bool | autoDelete = true |
||
) |
Standard constructor.
allocates a buffer of given size if buffer pointer is NULL.
Copy-constructor - copies all the data from the target image.
Ogre::Image::~Image | ( | ) |
Standard destructor.
void Ogre::Image::create | ( | PixelFormat | format, |
uint32 | width, | ||
uint32 | height, | ||
uint32 | depth = 1 , |
||
uint32 | numFaces = 1 , |
||
uint32 | numMipMaps = 0 |
||
) |
allocates a buffer of given size if needed
Assignment operator - copies all the data from the target image.
void Ogre::Image::setTo | ( | const ColourValue & | col | ) |
sets all pixels to the specified colour
format conversion is performed as needed
Image & Ogre::Image::flipAroundY | ( | ) |
Flips (mirrors) the image around the Y-axis.
An example of an original and flipped image:
originalimg 00000000000 00000000000 00000000000 00000000000 00000000000 ------------> flip axis 00000000000 00000000000 00000000000 00000000000 00000000000 originalimg
Image & Ogre::Image::flipAroundX | ( | ) |
Flips (mirrors) the image around the X-axis.
An example of an original and flipped image:
flip axis | originalimg|gmilanigiro 00000000000|00000000000 00000000000|00000000000 00000000000|00000000000 00000000000|00000000000 00000000000|00000000000
Image & Ogre::Image::loadDynamicImage | ( | uchar * | data, |
uint32 | width, | ||
uint32 | height, | ||
uint32 | depth, | ||
PixelFormat | format, | ||
bool | autoDelete = false , |
||
uint32 | numFaces = 1 , |
||
uint32 | numMipMaps = 0 |
||
) |
Stores a pointer to raw data in memory.
The pixel format has to be specified.
This method loads an image into memory held in the object. The pixel format will be either greyscale or RGB with an optional Alpha component. The type can be determined by calling getFormat().
data | The data pointer |
width | Width of image |
height | Height of image |
depth | Image Depth (in 3d images, numbers of layers, otherwise 1) |
format | Pixel Format |
autoDelete | If memory associated with this buffer is to be destroyed with the Image object. Note: it's important that if you set this option to true, that you allocated the memory using OGRE_ALLOC_T with a category of MEMCATEGORY_GENERAL to ensure the freeing of memory matches up. |
numFaces | The number of faces the image data has inside (6 for cubemaps, 1 otherwise) |
numMipMaps | The number of mipmaps the image data has inside |
The size of the buffer must be numFaces * PixelUtil::getMemorySize(width, height, depth, format)
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Image & Ogre::Image::loadRawData | ( | const DataStreamPtr & | stream, |
uint32 | width, | ||
uint32 | height, | ||
uint32 | depth, | ||
PixelFormat | format, | ||
uint32 | numFaces = 1 , |
||
uint32 | numMipMaps = 0 |
||
) |
Loads raw data from a stream.
See the function loadDynamicImage for a description of the parameters.
The size of the buffer must be numFaces * PixelUtil::getMemorySize(width, height, depth, format)
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Loads an image file.
This method loads an image into memory. Any format for which an associated ImageCodec is registered can be loaded. This can include complex formats like DDS with embedded custom mipmaps, cube faces and volume textures. The type can be determined by calling getFormat().
filename | Name of an image file to load. |
groupName | Name of the resource group to search for the image |
Image & Ogre::Image::load | ( | const DataStreamPtr & | stream, |
String | type = BLANKSTRING |
||
) |
Loads an image file from a stream.
This method works in the same way as the filename-based load method except it loads the image from a DataStream object. This DataStream is expected to contain the encoded data as it would be held in a file. Any format for which an associated ImageCodec is registered can be loaded. This can include complex formats like DDS with embedded custom mipmaps, cube faces and volume textures. The type can be determined by calling getFormat().
stream | The source data. |
type | The type of the image. Used to decide what decompression codec to use. Can be left blank if the stream data includes a header to identify the data. |
Image & Ogre::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 RGB channels, and the second image supplying the alpha channel (as luminance or separate alpha).
rgbFilename | Filename of image supplying the RGB channels (any alpha is ignored) |
alphaFilename | Filename of image supplying the alpha channel. If a luminance image the single channel is used directly, if an RGB image then the values are converted to greyscale. |
groupName | The resource group from which to load the images |
format | The destination format |
Image & Ogre::Image::loadTwoImagesAsRGBA | ( | const DataStreamPtr & | rgbStream, |
const DataStreamPtr & | alphaStream, | ||
PixelFormat | format = PF_BYTE_RGBA , |
||
const String & | rgbType = BLANKSTRING , |
||
const String & | alphaType = BLANKSTRING |
||
) |
Utility method to combine 2 separate images into this one, with the first image source supplying the RGB channels, and the second image supplying the alpha channel (as luminance or separate alpha).
rgbStream | Stream of image supplying the RGB channels (any alpha is ignored) |
alphaStream | Stream of image supplying the alpha channel. If a luminance image the single channel is used directly, if an RGB image then the values are converted to greyscale. |
format | The destination format |
rgbType | The type of the RGB image. Used to decide what decompression codec to use. Can be left blank if the stream data includes a header to identify the data. |
alphaType | The type of the alpha image. Used to decide what decompression codec to use. Can be left blank if the stream data includes a header to identify the data. |
Image & Ogre::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 RGB channels, and the second image supplying the alpha channel (as luminance or separate alpha).
Save the image as a file.
Saving and loading are implemented by back end (sometimes third party) codecs. Implemented saving functionality is more limited than loading in some cases. Particularly DDS file format support is currently limited to true colour or single channel float32, square, power of two textures with no mipmaps. Volumetric support is currently limited to DDS files.
DataStreamPtr Ogre::Image::encode | ( | const String & | formatextension | ) |
Encode the image and return a stream to the data.
formatextension | An extension to identify the image format to encode into, e.g. "jpg" or "png" |
Returns a pointer to the internal image buffer at the specified pixel location.
Be careful with this method. You will almost certainly prefer to use getPixelBox, especially with complex images which include many faces or custom mipmaps.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
|
inline |
Returns the size of the data buffer in bytes.
|
inline |
Returns the number of mipmaps contained in the image.
|
inline |
Returns true if the image has the appropriate flag set.
Get the number of faces of the image.
This is usually 6 for a cubemap, and 1 for a normal image.
References Ogre::IF_CUBEMAP.
Gets the physical width in bytes of each row of pixels.
|
inline |
Returns the image format.
|
inline |
Returns the number of bits per pixel.
bool Ogre::Image::getHasAlpha | ( | ) | const |
Returns true if the image has an alpha component.
Does gamma adjustment.
ColourValue Ogre::Image::getColourAt | ( | uint32 | x, |
uint32 | y, | ||
uint32 | z | ||
) | const |
Get colour value from a certain location in the image.
The z coordinate is only valid for cubemaps and volume textures. This uses the first (largest) mipmap.
Set colour value at a certain location in the image.
The z coordinate is only valid for cubemaps and volume textures. This uses the first (largest) mipmap.
Get a PixelBox encapsulating the image data of a mipmap.
void Ogre::Image::freeMemory | ( | ) |
Delete all the memory held by this image, if owned by this image (not dynamic)
|
static |
Scale a 1D, 2D or 3D image volume.
src | PixelBox containing the source pointer, dimensions and format |
dst | PixelBox containing the destination pointer, dimensions and format |
filter | Which filter to use This function can do pixel format conversion in the process. |
void Ogre::Image::resize | ( | ushort | width, |
ushort | height, | ||
Filter | filter = FILTER_BILINEAR |
||
) |
Resize a 2D image, applying the appropriate filter.
|
static |
Static function to calculate size in bytes from the number of mipmaps, faces and the dimensions.
|
static |
Static function to get an image type string from a stream via magic numbers.