1.8
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
Image Class Reference

Raster image resource used for drawing or displaying. More...

Public Member Functions

 Image (cairo_surface_t *surface)
 
 Image (const std::string &uri, float hscale, float vscale)
 Construct a raster image from a URI with an optional scale. More...
 
 Image (const std::string &uri={}, float scale=1.0)
 Construct a raster image from a URI with an optional scale. More...
 
 Image (const unsigned char *data, size_t len)
 Construct a raster image from memory. More...
 
 Image (shared_cairo_surface_t surface)
 
EGT_NODISCARD Rect align (const Rect &bounding, const AlignFlags &align)
 Get the position and size of the image once aligned inside the bounding area. More...
 
void copy ()
 This function must be called any time the surface is going to be modified. More...
 
Image crop (const Rect &rect)
 
Image crop (const RectF &rect)
 
void deserialize (const std::string &name, const std::string &value, const Serializer::Attributes &attrs)
 Deserialized property. More...
 
EGT_NODISCARD bool empty () const
 Returns true if no internal surface is set. More...
 
EGT_NODISCARD DefaultDim height () const
 
EGT_NODISCARD float hscale () const
 Get the horizontal scale value. More...
 
bool keep_image_ratio () const
 Get the keep image ratio state. More...
 
void keep_image_ratio (bool enable)
 Enable/disable ratio preservation while scaling the image. More...
 
void load (const std::string &uri, float hscale=1.0, float vscale=1.0, bool approx=false)
 Load a new source image with an optional scale. More...
 
EGT_NODISCARD cairo_pattern_t * pattern () const
 Get internal pattern representation. More...
 
void reset_uri ()
 
void resize (const Size &size)
 Resize the image to the specified absolute size. More...
 
void scale (float hscale, float vscale, bool approximate=false)
 Scale the image. More...
 
void scale (float scale, bool approximate=false)
 Scale the image. More...
 
void serialize (const std::string &name, Serializer &serializer) const
 Serialize to the specified serializer. More...
 
EGT_NODISCARD Size size () const
 Get the absolute size of the image. More...
 
EGT_NODISCARD Size size_orig () const
 Get the original size of the image before any Image::resize() or Image::scale() calls. More...
 
EGT_NODISCARD shared_cairo_surface_t surface () const
 Get a reference to the internal image surface. More...
 
EGT_NODISCARD std::string uri () const
 
void uri (const std::string &uri)
 
EGT_NODISCARD float vscale () const
 Get the vertical scale value. More...
 
EGT_NODISCARD DefaultDim width () const
 

Protected Member Functions

void handle_surface_changed ()
 

Protected Attributes

float m_hscale {1.0}
 Horizontal scale value, compared to original. More...
 
bool m_keep_image_ratio {true}
 Keep the image ratio when the aligned with AlignFlag::expand. More...
 
Size m_orig_size
 Original image size. More...
 
shared_cairo_pattern_t m_pattern
 Internal pattern representation. More...
 
shared_cairo_surface_t m_surface
 Shared surface pointer. More...
 
shared_cairo_surface_t m_surface_local
 Local surface pointer. More...
 
std::string m_uri
 If a URI was used, the URI. More...
 
float m_vscale {1.0}
 Vertical scale value, compared to original. More...
 

Friends

class SvgImage
 

Detailed Description

Raster image resource used for drawing or displaying.

This class by default shares the internal surface pointer with anything else using the surface. To force this class to keep its own copy, call the copy() function.

Constructor & Destructor Documentation

◆ Image() [1/5]

Image ( const std::string &  uri = {},
float  scale = 1.0 
)

Construct a raster image from a URI with an optional scale.

Image image("file:image.png");
Image(const std::string &uri={}, float scale=1.0)
Construct a raster image from a URI with an optional scale.
Parameters
uriResource path.
See also
Resources
Parameters
scaleScale of the image, with 1.0 being 100%.

◆ Image() [2/5]

Image ( const std::string &  uri,
float  hscale,
float  vscale 
)

Construct a raster image from a URI with an optional scale.

Parameters
uriResource path.
See also
Resources
Parameters
hscaleHorizontal scale of the image, with 1.0 being 100%.
vscaleVertical scale of the image, with 1.0 being 100%.

◆ Image() [3/5]

Image ( const unsigned char *  data,
size_t  len 
)

Construct a raster image from memory.

Parameters
dataPointer to the data.
lenLength of the data.

◆ Image() [4/5]

Parameters
surfaceA pre-existing surface.

This takes a reference to the passed in image.

Todo:
This is a broken API. It's different from the constructor below. Need consistency.

◆ Image() [5/5]

Image ( cairo_surface_t *  surface)
Parameters
surfaceA pre-existing surface.

This will not own the passed in pointer or surface, and instead will make a copy of the surface.

Member Function Documentation

◆ align()

EGT_NODISCARD Rect align ( const Rect bounding,
const AlignFlags align 
)

Get the position and size of the image once aligned inside the bounding area.

◆ copy()

void copy ( )

This function must be called any time the surface is going to be modified.

It's safe to call this function when not necessary, and in any event it will ensure this Image contains a unique copy of the surface.

Todo:
Tricky API.

◆ crop() [1/2]

Image crop ( const Rect rect)
inline

◆ crop() [2/2]

Image crop ( const RectF rect)

◆ deserialize()

void deserialize ( const std::string &  name,
const std::string &  value,
const Serializer::Attributes attrs 
)

Deserialized property.

◆ empty()

EGT_NODISCARD bool empty ( ) const
inline

Returns true if no internal surface is set.

◆ handle_surface_changed()

void handle_surface_changed ( )
protected

◆ height()

EGT_NODISCARD DefaultDim height ( ) const
inline

◆ hscale()

EGT_NODISCARD float hscale ( ) const
inline

Get the horizontal scale value.

◆ keep_image_ratio() [1/2]

bool keep_image_ratio ( ) const
inline

Get the keep image ratio state.

◆ keep_image_ratio() [2/2]

void keep_image_ratio ( bool  enable)
inline

Enable/disable ratio preservation while scaling the image.

If enabled, the original image ratio won't be changed during the image auto scale operation. By default, set to true.

◆ load()

void load ( const std::string &  uri,
float  hscale = 1.0,
float  vscale = 1.0,
bool  approx = false 
)

Load a new source image with an optional scale.

Parameters
uriResource path.
See also
Resources
Parameters
hscaleHorizontal scale of the image, with 1.0 being 100%.
vscaleVertical scale of the image, with 1.0 being 100%.
approxApproximate the scale to increase image cache hit efficiency.

◆ pattern()

EGT_NODISCARD cairo_pattern_t* pattern ( ) const
inline

Get internal pattern representation.

◆ reset_uri()

void reset_uri ( )
inline

◆ resize()

void resize ( const Size size)
inline

Resize the image to the specified absolute size.

Parameters
sizeThe new size of the image.

◆ scale() [1/2]

void scale ( float  hscale,
float  vscale,
bool  approximate = false 
)

Scale the image.

Change the scale of the image, similar to calling Image::resize().

This scales relative to the original size of the image. Not the result of any subsequent Image::resize() or Image::scale() call.

Parameters
hscaleHorizontal scale of the image, with 1.0 being 100%.
vscaleVertical scale of the image, with 1.0 being 100%.
approximateApproximate the scale to increase image cache hit efficiency.

◆ scale() [2/2]

void scale ( float  scale,
bool  approximate = false 
)
inline

Scale the image.

See also
scale()

◆ serialize()

void serialize ( const std::string &  name,
Serializer serializer 
) const

Serialize to the specified serializer.

◆ size()

EGT_NODISCARD Size size ( ) const
inline

Get the absolute size of the image.

◆ size_orig()

EGT_NODISCARD Size size_orig ( ) const
inline

Get the original size of the image before any Image::resize() or Image::scale() calls.

◆ surface()

EGT_NODISCARD shared_cairo_surface_t surface ( ) const
inline

Get a reference to the internal image surface.

◆ uri() [1/2]

EGT_NODISCARD std::string uri ( ) const
inline

◆ uri() [2/2]

void uri ( const std::string &  uri)
inline

◆ vscale()

EGT_NODISCARD float vscale ( ) const
inline

Get the vertical scale value.

◆ width()

EGT_NODISCARD DefaultDim width ( ) const
inline

Friends And Related Function Documentation

◆ SvgImage

friend class SvgImage
friend

Member Data Documentation

◆ m_hscale

float m_hscale {1.0}
protected

Horizontal scale value, compared to original.

◆ m_keep_image_ratio

bool m_keep_image_ratio {true}
protected

Keep the image ratio when the aligned with AlignFlag::expand.

◆ m_orig_size

Size m_orig_size
protected

Original image size.

◆ m_pattern

shared_cairo_pattern_t m_pattern
mutableprotected

Internal pattern representation.

◆ m_surface

shared_cairo_surface_t m_surface
protected

Shared surface pointer.

◆ m_surface_local

shared_cairo_surface_t m_surface_local
protected

Local surface pointer.

◆ m_uri

std::string m_uri
protected

If a URI was used, the URI.

◆ m_vscale

float m_vscale {1.0}
protected

Vertical scale value, compared to original.