Rebel Fork Framework
Urho3D::Image Class Reference

Image resource. More...

#include <Urho3D/Resource/Image.h>

Inheritance diagram for Urho3D::Image:
Urho3D::Resource Urho3D::Object Urho3D::RefCounted

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 FileIdentifier &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 ea::string &fileName) const
 Save in BMP format. Return true if successful.
 
bool SavePNG (const ea::string &fileName) const
 Save in PNG format. Return true if successful.
 
bool SaveTGA (const ea::string &fileName) const
 Save in TGA format. Return true if successful.
 
bool SaveJPG (const ea::string &fileName, int quality) const
 Save in JPG format with specified quality. Return true if successful.
 
bool SaveDDS (const ea::string &fileName) const
 Save in DDS format. Only uncompressed RGBA images are supported. Return true if successful.
 
bool SaveWEBP (const ea::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.
 
TextureFormat GetGPUFormat () const
 Return internal GPU format corresponding to the Image format. Return unknown if there is no such format.
 
int GetWidth () const
 
int GetHeight () const
 
int GetDepth () const
 
IntVector3 GetSize () const
 Return size of the image.
 
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.
 
SharedPtr< ImageGetDecompressedImageLevel (unsigned index) const
 Return LOD of decompressed image in RGBA format.
 
SharedPtr< 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 (ea::vector< Image * > &levels)
 Get all stored mip levels starting from this.
 
void GetLevels (ea::vector< 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 FileIdentifier &fileName)
 Load resource from file.
 
void SetName (const ea::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.
 
void SetAbsoluteFileName (const ea::string &fileName)
 Set absolute file name.
 
const ea::string & GetName () const
 
StringHash GetNameHash () const
 Return name hash.
 
unsigned GetMemoryUse () const
 
unsigned GetUseTimer ()
 
AsyncLoadState GetAsyncLoadState () const
 Return the asynchronous loading state.
 
const ea::string & GetAbsoluteFileName () const
 Return absolute file name.
 
- 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 ea::string & GetTypeName () const =0
 
virtual const TypeInfoGetTypeInfo () const =0
 Return type info.
 
virtual bool IsInstanceOf (StringHash type) const =0
 Check whether current instance implements specified type.
 
virtual void OnEvent (Object *sender, StringHash eventType, VariantMap &eventData)
 Handle event.
 
virtual void SerializeInBlock (Archive &archive)
 Serialize content from/to archive. May throw ArchiveException.
 
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 SubscribeToEventManual (StringHash eventType, EventHandler *handler)
 Subscribe to an event that can be sent by any sender.
 
void SubscribeToEventManual (Object *sender, StringHash eventType, EventHandler *handler)
 Subscribe to a specific sender's event.
 
template<class T >
void SubscribeToEvent (StringHash eventType, T handler)
 Subscribe to an event that can be sent by any sender.
 
template<class T >
void SubscribeToEvent (Object *sender, StringHash eventType, T handler)
 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 ea::vector< StringHash > &exceptions)
 Unsubscribe from all events except those listed.
 
void UnsubscribeFromAllEventsExcept (const ea::vector< Object * > &exceptions)
 Unsubscribe from all events except those with listed senders.
 
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, const Args &... args)
 Send event with variadic parameter pairs to all subscribers. The parameters are (paramID, paramValue) pairs.
 
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 ea::string & GetCategory () const
 
void SendEvent (StringHash eventType, const VariantMap &eventData)
 Send event with parameters to all subscribers.
 
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.
 
int AddRef ()
 
int ReleaseRef ()
 
int Refs () const
 
int WeakRefs () const
 
RefCountRefCountPtr () const
 Return pointer to the reference count structure.
 
bool HasScriptObject () const
 Return true if script runtime object wrapping this native object exists.
 
bool IsScriptStrongRef () const
 Return true if script reference is strong.
 

Static Public Member Functions

static void RegisterObject (Context *context)
 
- Static Public Member Functions inherited from Urho3D::Resource
static ResourceLoadFromCache (Context *context, StringHash type, const ea::string &name)
 Load resource by reference.
 
- 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.
 
ea::shared_array< unsigned char > data_
 Pixel data.
 
SharedPtr< ImagenextLevel_
 Precalculated mip level image.
 
SharedPtr< ImagenextSibling_
 Next texture array or cube map image.
 

Additional Inherited Members

- Static Public Attributes inherited from Urho3D::Object
static constexpr ea::array< StringHash, 0 > TypeHierarchy {}
 
- Protected Attributes inherited from Urho3D::Object
WeakPtr< Contextcontext_
 Execution context.
 

Detailed Description

Image resource.

Member Function Documentation

◆ GetComponents()

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

Return number of color components.

◆ 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.

◆ 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.

◆ 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.

◆ 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.

◆ RegisterObject()

void Urho3D::Image::RegisterObject ( Context context)
static

Register object factory.

◆ Resize()

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

Resize image by bilinear resampling. Return true if successful.


The documentation for this class was generated from the following files: