Image resource. More...

#include <Urho3D/Resource/Image.h>

Inheritance diagram for Urho3D::Image:
[legend]
Collaboration diagram for Urho3D::Image:
[legend]

Public Member Functions

 Image (Context *context)
 Construct empty.
 
 ~Image () override
 Destruct.
 
bool BeginLoad (Deserializer &source) override
 Load resource from stream. May be called from a worker thread. Return true if successful.
 
bool Save (Serializer &dest) const override
 Save the image to a stream. Regardless of original format, the image is saved as png. Compressed image data is not supported. Return true if successful.
 
bool SaveFile (const String &fileName) const override
 Save the image to a file. Format of the image is determined by file extension. JPG is saved with maximum quality.
 
bool SetSize (int width, int height, unsigned components)
 Set 2D size and number of color components. Old image data will be destroyed and new data is undefined. Return true if successful.
 
bool SetSize (int width, int height, int depth, unsigned components)
 Set 3D size and number of color components. Old image data will be destroyed and new data is undefined. Return true if successful.
 
void SetData (const unsigned char *pixelData)
 Set new image data.
 
void SetPixel (int x, int y, const Color &color)
 Set a 2D pixel.
 
void SetPixel (int x, int y, int z, const Color &color)
 Set a 3D pixel.
 
void SetPixelInt (int x, int y, unsigned uintColor)
 Set a 2D pixel with an integer color. R component is in the 8 lowest bits.
 
void SetPixelInt (int x, int y, int z, unsigned uintColor)
 Set a 3D pixel with an integer color. R component is in the 8 lowest bits.
 
bool LoadColorLUT (Deserializer &source)
 Load as color LUT. Return true if successful.
 
bool FlipHorizontal ()
 Flip image horizontally. Return true if successful.
 
bool FlipVertical ()
 Flip image vertically. Return true if successful.
 
bool Resize (int width, int height)
 Resize image by bilinear resampling. Return true if successful. More...
 
void Clear (const Color &color)
 Clear the image with a color.
 
void ClearInt (unsigned uintColor)
 Clear the image with an integer color. R component is in the 8 lowest bits.
 
bool SaveBMP (const String &fileName) const
 Save in BMP format. Return true if successful.
 
bool SavePNG (const String &fileName) const
 Save in PNG format. Return true if successful.
 
bool SaveTGA (const String &fileName) const
 Save in TGA format. Return true if successful.
 
bool SaveJPG (const String &fileName, int quality) const
 Save in JPG format with specified quality. Return true if successful.
 
bool SaveDDS (const String &fileName) const
 Save in DDS format. Only uncompressed RGBA images are supported. Return true if successful.
 
bool SaveWEBP (const String &fileName, float compression=0.0f) const
 Save in WebP format with minimum (fastest) or specified compression. Return true if successful. Fails always if WebP support is not compiled in.
 
bool IsCubemap () const
 
bool IsArray () const
 
bool IsSRGB () const
 
Color GetPixel (int x, int y) const
 Return a 2D pixel color.
 
Color GetPixel (int x, int y, int z) const
 Return a 3D pixel color.
 
unsigned GetPixelInt (int x, int y) const
 Return a 2D pixel integer color. R component is in the 8 lowest bits.
 
unsigned GetPixelInt (int x, int y, int z) const
 Return a 3D pixel integer color. R component is in the 8 lowest bits.
 
Color GetPixelBilinear (float x, float y) const
 Return a bilinearly sampled 2D pixel color. X and Y have the range 0-1.
 
Color GetPixelTrilinear (float x, float y, float z) const
 Return a trilinearly sampled 3D pixel color. X, Y and Z have the range 0-1.
 
int GetWidth () const
 
int GetHeight () const
 
int GetDepth () const
 
unsigned GetComponents () const
 
unsigned char * GetData () const
 Return pixel data.
 
bool IsCompressed () const
 
CompressedFormat GetCompressedFormat () const
 
unsigned GetNumCompressedLevels () const
 
SharedPtr< ImageGetNextLevel () const
 Return next mip level by bilinear filtering. Note that if the image is already 1x1x1, will keep returning an image of that size.
 
SharedPtr< ImageGetNextSibling () const
 Return the next sibling image of an array or cubemap.
 
SharedPtr< ImageConvertToRGBA () const
 Return image converted to 4-component (RGBA) to circumvent modern rendering API's not supporting e.g. the luminance-alpha format.
 
CompressedLevel GetCompressedLevel (unsigned index) const
 Return a compressed mip level.
 
SharedPtr< ImageGetDecompressedImage () const
 Return decompressed image data in RGBA format.
 
ImageGetSubimage (const IntRect &rect) const
 Return subimage from the image by the defined rect or null if failed. 3D images are not supported. You must free the subimage yourself.
 
SDL_Surface * GetSDLSurface (const IntRect &rect=IntRect::ZERO) const
 Return an SDL surface from the image, or null if failed. Only RGB images are supported. Specify rect to only return partial image. You must free the surface yourself.
 
void PrecalculateLevels ()
 Precalculate the mip levels. Used by asynchronous texture loading.
 
bool HasAlphaChannel () const
 
bool SetSubimage (const Image *image, const IntRect &rect)
 Copy contents of the image into the defined rect, scaling if necessary. This image should already be large enough to include the rect. Compressed and 3D images are not supported.
 
void CleanupLevels ()
 Clean up the mip levels.
 
void GetLevels (PODVector< Image * > &levels)
 Get all stored mip levels starting from this.
 
void GetLevels (PODVector< const Image * > &levels) const
 Get all stored mip levels starting from this.
 
- Public Member Functions inherited from Urho3D::Resource
 Resource (Context *context)
 Construct.
 
bool Load (Deserializer &source)
 Load resource synchronously. Call both BeginLoad() & EndLoad() and return true if both succeeded.
 
virtual bool EndLoad ()
 Finish resource loading. Always called from the main thread. Return true if successful.
 
bool LoadFile (const String &fileName)
 
void SetName (const String &name)
 
void SetMemoryUse (unsigned size)
 Set memory use in bytes, possibly approximate.
 
void ResetUseTimer ()
 Reset last used timer.
 
void SetAsyncLoadState (AsyncLoadState newState)
 Set the asynchronous loading state. Called by ResourceCache. Resources in the middle of asynchronous loading are not normally returned to user.
 
const StringGetName () const
 
StringHash GetNameHash () const
 Return name hash.
 
unsigned GetMemoryUse () const
 
unsigned GetUseTimer ()
 
AsyncLoadState GetAsyncLoadState () const
 Return the asynchronous loading state.
 
- Public Member Functions inherited from Urho3D::Object
 Object (Context *context)
 Construct.
 
 ~Object () override
 Destruct. Clean up self from event sender & receiver structures.
 
virtual StringHash GetType () const =0
 
virtual const StringGetTypeName () const =0
 
virtual const TypeInfoGetTypeInfo () const =0
 Return type info.
 
virtual void OnEvent (Object *sender, StringHash eventType, VariantMap &eventData)
 Handle event.
 
bool IsInstanceOf (StringHash type) const
 Check current instance is type of specified type.
 
bool IsInstanceOf (const TypeInfo *typeInfo) const
 Check current instance is type of specified type.
 
template<typename T >
bool IsInstanceOf () const
 Check current instance is type of specified class.
 
template<typename T >
T * Cast ()
 Cast the object to specified most derived class.
 
template<typename T >
const T * Cast () const
 Cast the object to specified most derived class.
 
void SubscribeToEvent (StringHash eventType, EventHandler *handler)
 Subscribe to an event that can be sent by any sender.
 
void SubscribeToEvent (Object *sender, StringHash eventType, EventHandler *handler)
 Subscribe to a specific sender's event.
 
void SubscribeToEvent (StringHash eventType, const std::function< void(StringHash, VariantMap &)> &function, void *userData=nullptr)
 Subscribe to an event that can be sent by any sender.
 
void SubscribeToEvent (Object *sender, StringHash eventType, const std::function< void(StringHash, VariantMap &)> &function, void *userData=nullptr)
 Subscribe to a specific sender's event.
 
void UnsubscribeFromEvent (StringHash eventType)
 Unsubscribe from an event.
 
void UnsubscribeFromEvent (Object *sender, StringHash eventType)
 Unsubscribe from a specific sender's event.
 
void UnsubscribeFromEvents (Object *sender)
 Unsubscribe from a specific sender's events.
 
void UnsubscribeFromAllEvents ()
 Unsubscribe from all events.
 
void UnsubscribeFromAllEventsExcept (const PODVector< StringHash > &exceptions, bool onlyUserData)
 Unsubscribe from all events except those listed, and optionally only those with userdata (script registered events).
 
void SendEvent (StringHash eventType)
 Send event to all subscribers.
 
void SendEvent (StringHash eventType, VariantMap &eventData)
 Send event with parameters to all subscribers.
 
VariantMapGetEventDataMap () const
 Return a preallocated map for event data. Used for optimization to avoid constant re-allocation of event data maps.
 
template<typename... Args>
void SendEvent (StringHash eventType, Args... args)
 Send event with variadic parameter pairs to all subscribers. The parameter pairs is a list of paramID and paramValue separated by comma, one pair after another.
 
ContextGetContext () const
 Return execution context.
 
const VariantGetGlobalVar (StringHash key) const
 
const VariantMapGetGlobalVars () const
 
void SetGlobalVar (StringHash key, const Variant &value)
 
ObjectGetSubsystem (StringHash type) const
 Return subsystem by type.
 
ObjectGetEventSender () const
 Return active event sender. Null outside event handling.
 
EventHandlerGetEventHandler () const
 Return active event handler. Null outside event handling.
 
bool HasSubscribedToEvent (StringHash eventType) const
 Return whether has subscribed to an event without specific sender.
 
bool HasSubscribedToEvent (Object *sender, StringHash eventType) const
 Return whether has subscribed to a specific sender's event.
 
bool HasEventHandlers () const
 Return whether has subscribed to any event.
 
template<class T >
T * GetSubsystem () const
 Template version of returning a subsystem.
 
const StringGetCategory () const
 
void SetBlockEvents (bool block)
 Block object from sending and receiving events.
 
bool GetBlockEvents () const
 Return sending and receiving events blocking status.
 
- Public Member Functions inherited from Urho3D::RefCounted
 RefCounted ()
 Construct. Allocate the reference count structure and set an initial self weak reference.
 
virtual ~RefCounted ()
 Destruct. Mark as expired and also delete the reference count structure if no outside weak references exist.
 
 RefCounted (const RefCounted &rhs)=delete
 Prevent copy construction.
 
RefCountedoperator= (const RefCounted &rhs)=delete
 Prevent assignment.
 
void AddRef ()
 Increment reference count. Can also be called outside of a SharedPtr for traditional reference counting.
 
void ReleaseRef ()
 Decrement reference count and delete self if no more references. Can also be called outside of a SharedPtr for traditional reference counting.
 
int Refs () const
 
int WeakRefs () const
 
RefCountRefCountPtr ()
 Return pointer to the reference count structure.
 

Static Public Member Functions

static void RegisterObject (Context *context)
 Register object factory.
 
- Static Public Member Functions inherited from Urho3D::Object
static const TypeInfoGetTypeInfoStatic ()
 Return type info static.
 

Private Member Functions

 URHO3D_OBJECT (Image, Resource)
 

Static Private Member Functions

static unsigned char * GetImageData (Deserializer &source, int &width, int &height, unsigned &components)
 Decode an image using stb_image.
 
static void FreeImageData (unsigned char *pixelData)
 Free an image file's pixel data.
 

Private Attributes

int width_ {}
 Width.
 
int height_ {}
 Height.
 
int depth_ {}
 Depth.
 
unsigned components_ {}
 Number of color components.
 
unsigned numCompressedLevels_ {}
 Number of compressed mip levels.
 
bool cubemap_ {}
 Cubemap status if DDS.
 
bool array_ {}
 Texture array status if DDS.
 
bool sRGB_ {}
 Data is sRGB.
 
CompressedFormat compressedFormat_ {CF_NONE}
 Compressed format.
 
SharedArrayPtr< unsigned char > data_
 Pixel data.
 
SharedPtr< ImagenextLevel_
 Precalculated mip level image.
 
SharedPtr< ImagenextSibling_
 Next texture array or cube map image.
 

Additional Inherited Members

- Protected Attributes inherited from Urho3D::Object
Contextcontext_
 Execution context.
 

Detailed Description

Image resource.

Member Function Documentation

◆ GetComponents()

unsigned Urho3D::Image::GetComponents ( ) const
inline

Return number of color components.

Here is the caller graph for this function:

◆ GetCompressedFormat()

CompressedFormat Urho3D::Image::GetCompressedFormat ( ) const
inline

Return compressed format.

◆ GetDepth()

int Urho3D::Image::GetDepth ( ) const
inline

Return depth.

◆ GetHeight()

int Urho3D::Image::GetHeight ( ) const
inline

Return height.

Here is the caller graph for this function:

◆ GetNumCompressedLevels()

unsigned Urho3D::Image::GetNumCompressedLevels ( ) const
inline

Return number of compressed mip levels. Returns 0 if the image is has not been loaded from a source file containing multiple mip levels.

◆ GetWidth()

int Urho3D::Image::GetWidth ( ) const
inline

Return width.

Here is the caller graph for this function:

◆ HasAlphaChannel()

bool Urho3D::Image::HasAlphaChannel ( ) const

Whether this texture has an alpha channel.

◆ IsArray()

bool Urho3D::Image::IsArray ( ) const
inline

Whether this texture has been detected as a volume, only relevant for DDS.

◆ IsCompressed()

bool Urho3D::Image::IsCompressed ( ) const
inline

Return whether is compressed.

Here is the caller graph for this function:

◆ IsCubemap()

bool Urho3D::Image::IsCubemap ( ) const
inline

Whether this texture is detected as a cubemap, only relevant for DDS.

◆ IsSRGB()

bool Urho3D::Image::IsSRGB ( ) const
inline

Whether this texture is in sRGB, only relevant for DDS.

◆ Resize()

bool Urho3D::Image::Resize ( int  width,
int  height 
)

Resize image by bilinear resampling. Return true if successful.

Todo:
Reducing image size does not sample all needed pixels
Here is the call graph for this function:

The documentation for this class was generated from the following files:
  • Source/Urho3D/Resource/Image.h
  • Source/Urho3D/Resource/Image.cpp