Image resource. More...

#include <Image.h>

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

Public Member Functions

 Image (Context *context)
 Construct empty.
 
virtual ~Image ()
 Destruct.
 
virtual bool BeginLoad (Deserializer &source)
 Load resource from stream. May be called from a worker thread. Return true if successful.
 
virtual bool Save (Serializer &dest) const
 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 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 compression quality. Return true if successful.
 
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
 Return width.
 
int GetHeight () const
 Return height.
 
int GetDepth () const
 Return depth.
 
unsigned GetComponents () const
 Return number of color components.
 
unsigned char * GetData () const
 Return pixel data.
 
bool IsCompressed () const
 Return whether is compressed.
 
CompressedFormat GetCompressedFormat () const
 Return compressed format.
 
unsigned GetNumCompressedLevels () const
 Return number of compressed mip levels.
 
SharedPtr< ImageGetNextLevel () const
 Return next mip level by bilinear filtering.
 
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.
 
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.
 
- 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.
 
void SetName (const String &name)
 Set 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
 Return name.
 
StringHash GetNameHash () const
 Return name hash.
 
unsigned GetMemoryUse () const
 Return memory use in bytes, possibly approximate.
 
unsigned GetUseTimer ()
 Return time since last use in milliseconds. If referred to elsewhere than in the resource cache, returns always zero.
 
AsyncLoadState GetAsyncLoadState () const
 Return the asynchronous loading state.
 
- Public Member Functions inherited from Urho3D::Object
 Object (Context *context)
 Construct.
 
virtual ~Object ()
 Destruct. Clean up self from event sender & receiver structures.
 
virtual Urho3D::StringHash GetType () const =0
 Return type hash.
 
virtual Urho3D::StringHash GetBaseType () const =0
 Return base class type hash.
 
virtual const Urho3D::StringGetTypeName () const =0
 Return type name.
 
virtual void OnEvent (Object *sender, StringHash eventType, VariantMap &eventData)
 Handle event.
 
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 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. More...
 
VariantMapGetEventDataMap () const
 Return a preallocated map for event data. Used for optimization to avoid constant re-allocation of event data maps.
 
ContextGetContext () const
 Return execution context.
 
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
 Return object category. Categories are (optionally) registered along with the object factory. Return an empty string if the object category is not registered.
 
- 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.
 
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
 Return reference count.
 
int WeakRefs () const
 Return weak reference count.
 
RefCountRefCountPtr ()
 Return pointer to the reference count structure.
 

Static Public Member Functions

static void RegisterObject (Context *context)
 Register object factory.
 

Private Member Functions

 OBJECT (Image)
 

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.
 
CompressedFormat compressedFormat_
 Compressed format.
 
SharedArrayPtr< unsigned char > data_
 Pixel data.
 
SharedPtr< ImagenextLevel_
 Precalculated mip level image.
 

Additional Inherited Members

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

Detailed Description

Image resource.

Member Function Documentation

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:
  • /home/travis/build/urho3d/Urho3D/Source/Urho3D/Resource/Image.h
  • /home/travis/build/urho3d/Urho3D/Source/Urho3D/Resource/Image.cpp