Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
Inkscape::Pixbuf Class Reference

Class to hold image data for raster images. More...

#include <cairo-utils.h>

Public Types

enum  PixelFormat { PF_CAIRO = 1 , PF_GDK = 2 , PF_LAST }
 

Public Member Functions

 Pixbuf (cairo_surface_t *s)
 Create a pixbuf from a Cairo surface.
 
 Pixbuf (GdkPixbuf *pb)
 Create a pixbuf from a GdkPixbuf.
 
 Pixbuf (Inkscape::Pixbuf const &other)
 
 ~Pixbuf ()
 
PixbufcropTo (const Geom::IntRect &area) const
 Create a new Pixbuf with the image cropped to the given area.
 
GdkPixbufgetPixbufRaw (bool convert_format=true)
 Converts the pixbuf to GdkPixbuf pixel format.
 
GdkPixbufgetPixbufRaw () const
 
cairo_surface_tgetSurfaceRaw ()
 Converts the pixbuf to Cairo pixel format and returns an image surface which can be used as a source.
 
cairo_surface_tgetSurfaceRaw () const
 
Cairo::RefPtr< Cairo::Surface > getSurface ()
 
int width () const
 
int height () const
 
int rowstride () const
 
guchar const * pixels () const
 
guchar * pixels ()
 
void markDirty ()
 
bool hasMimeData () const
 
guchar const * getMimeData (gsize &len, std::string &mimetype) const
 Retrieves the original compressed data for the surface, if any.
 
std::string const & originalPath () const
 
time_t modificationTime () const
 
PixelFormat pixelFormat () const
 
void ensurePixelFormat (PixelFormat fmt)
 Convert the internal pixel format between CAIRO and GDK formats.
 

Static Public Member Functions

static void ensure_pixbuf (GdkPixbuf *pb)
 Converts GdkPixbuf's data back to its native format.
 
static void ensure_argb32 (GdkPixbuf *pb)
 Converts GdkPixbuf's data to premultiplied ARGB.
 
static Pixbufcreate_from_data_uri (gchar const *uri, double svgdpi=0)
 
static Pixbufcreate_from_file (std::string const &fn, double svgddpi=0)
 
static Pixbufcreate_from_buffer (std::string const &, double svgddpi=0, std::string const &fn="")
 

Private Member Functions

void _ensurePixelsARGB32 ()
 
void _ensurePixelsPixbuf ()
 
void _forceAlpha ()
 
void _setMimeData (guchar *data, gsize len, Glib::ustring const &format)
 

Static Private Member Functions

static Pixbufcreate_from_buffer (gchar *&&, gsize, double svgddpi=0, std::string const &fn="")
 
static Geom::Affine get_embedded_orientation (GdkPixbuf *buf)
 Gets any available orientation data and returns it as an affine.
 
static GdkPixbufapply_embedded_orientation (GdkPixbuf *buf)
 

Private Attributes

GdkPixbuf_pixbuf
 
cairo_surface_t_surface
 
time_t _mod_time
 
std::string _path
 
PixelFormat _pixel_format
 
bool _cairo_store
 

Detailed Description

Class to hold image data for raster images.

Allows easy interoperation with GdkPixbuf and Cairo.

Definition at line 31 of file cairo-utils.h.

Member Enumeration Documentation

◆ PixelFormat

Enumerator
PF_CAIRO 
PF_GDK 
PF_LAST 

Definition at line 33 of file cairo-utils.h.

Constructor & Destructor Documentation

◆ Pixbuf() [1/3]

Inkscape::Pixbuf::Pixbuf ( cairo_surface_t s)
explicit

Create a pixbuf from a Cairo surface.

The constructor takes ownership of the passed surface, so it should not be destroyed.

Definition at line 89 of file cairo-utils.cpp.

◆ Pixbuf() [2/3]

Inkscape::Pixbuf::Pixbuf ( GdkPixbuf pb)
explicit

Create a pixbuf from a GdkPixbuf.

The constructor takes ownership of the passed GdkPixbuf reference, so it should not be unrefed.

Definition at line 104 of file cairo-utils.cpp.

References _forceAlpha(), _pixbuf, and _surface.

◆ Pixbuf() [3/3]

Inkscape::Pixbuf::Pixbuf ( Inkscape::Pixbuf const &  other)

Definition at line 117 of file cairo-utils.cpp.

◆ ~Pixbuf()

Inkscape::Pixbuf::~Pixbuf ( )

Definition at line 128 of file cairo-utils.cpp.

References _cairo_store, _pixbuf, and _surface.

Member Function Documentation

◆ _ensurePixelsARGB32()

void Inkscape::Pixbuf::_ensurePixelsARGB32 ( )
private

◆ _ensurePixelsPixbuf()

void Inkscape::Pixbuf::_ensurePixelsPixbuf ( )
private

◆ _forceAlpha()

void Inkscape::Pixbuf::_forceAlpha ( )
private

Definition at line 567 of file cairo-utils.cpp.

References _pixbuf.

Referenced by Pixbuf().

◆ _setMimeData()

void Inkscape::Pixbuf::_setMimeData ( guchar *  data,
gsize  len,
Glib::ustring const &  format 
)
private

Definition at line 576 of file cairo-utils.cpp.

References _surface, data, and len.

Referenced by create_from_buffer(), and create_from_data_uri().

◆ apply_embedded_orientation()

GdkPixbuf * Inkscape::Pixbuf::apply_embedded_orientation ( GdkPixbuf buf)
staticprivate

Definition at line 306 of file cairo-utils.cpp.

References buf.

Referenced by create_from_buffer(), and create_from_data_uri().

◆ create_from_buffer() [1/2]

Pixbuf * Inkscape::Pixbuf::create_from_buffer ( gchar *&&  data,
gsize  len,
double  svgddpi = 0,
std::string const &  fn = "" 
)
staticprivate

◆ create_from_buffer() [2/2]

Pixbuf * Inkscape::Pixbuf::create_from_buffer ( std::string const &  buffer,
double  svgddpi = 0,
std::string const &  fn = "" 
)
static

◆ create_from_data_uri()

◆ create_from_file()

Pixbuf * Inkscape::Pixbuf::create_from_file ( std::string const &  fn,
double  svgddpi = 0 
)
static

◆ cropTo()

Pixbuf * Inkscape::Pixbuf::cropTo ( const Geom::IntRect area) const

◆ ensure_argb32()

void Inkscape::Pixbuf::ensure_argb32 ( GdkPixbuf pb)
static

Converts GdkPixbuf's data to premultiplied ARGB.

This function will convert a GdkPixbuf in place into Cairo's native pixel format. Note that this is a hack intended to save memory. When the pixbuf is in Cairo's format, using it with GTK will result in corrupted drawings.

Definition at line 619 of file cairo-utils.cpp.

References convert_pixels_pixbuf_to_argb32().

Referenced by ensurePixelFormat().

◆ ensure_pixbuf()

void Inkscape::Pixbuf::ensure_pixbuf ( GdkPixbuf pb)
static

Converts GdkPixbuf's data back to its native format.

Once this is done, the pixbuf can be used with GTK again.

Definition at line 632 of file cairo-utils.cpp.

References convert_pixels_argb32_to_pixbuf().

Referenced by cropTo(), and ensurePixelFormat().

◆ ensurePixelFormat()

void Inkscape::Pixbuf::ensurePixelFormat ( PixelFormat  fmt)

Convert the internal pixel format between CAIRO and GDK formats.

Definition at line 600 of file cairo-utils.cpp.

References _pixbuf, _pixel_format, ensure_argb32(), ensure_pixbuf(), fmt, PF_CAIRO, and PF_GDK.

Referenced by getPixbufRaw(), getSurfaceRaw(), and SPImage::update().

◆ get_embedded_orientation()

Geom::Affine Inkscape::Pixbuf::get_embedded_orientation ( GdkPixbuf buf)
staticprivate

Gets any available orientation data and returns it as an affine.

Definition at line 317 of file cairo-utils.cpp.

References buf, and Geom::identity().

Referenced by create_from_buffer(), and create_from_data_uri().

◆ getMimeData()

guchar const * Inkscape::Pixbuf::getMimeData ( gsize &  len,
std::string &  mimetype 
) const

Retrieves the original compressed data for the surface, if any.

The returned data belongs to the object and should not be freed.

Definition at line 527 of file cairo-utils.cpp.

References _surface, data, and len.

Referenced by sp_embed_image().

◆ getPixbufRaw() [1/2]

GdkPixbuf * Inkscape::Pixbuf::getPixbufRaw ( ) const

Definition at line 476 of file cairo-utils.cpp.

References _pixbuf, _pixel_format, and PF_GDK.

◆ getPixbufRaw() [2/2]

GdkPixbuf * Inkscape::Pixbuf::getPixbufRaw ( bool  convert_format = true)

Converts the pixbuf to GdkPixbuf pixel format.

The returned pixbuf can be used e.g. in calls to gdk_pixbuf_save().

Definition at line 468 of file cairo-utils.cpp.

References _pixbuf, ensurePixelFormat(), and PF_GDK.

Referenced by create_from_buffer(), create_from_data_uri(), and sp_embed_image().

◆ getSurface()

Cairo::RefPtr< Cairo::Surface > Inkscape::Pixbuf::getSurface ( )

Definition at line 520 of file cairo-utils.cpp.

References getSurfaceRaw().

◆ getSurfaceRaw() [1/2]

cairo_surface_t * Inkscape::Pixbuf::getSurfaceRaw ( )

Converts the pixbuf to Cairo pixel format and returns an image surface which can be used as a source.

The returned surface is owned by the GdkPixbuf and should not be freed. Calling this function causes the pixbuf to be unsuitable for use with GTK drawing functions until ensurePixelFormat(Pixbuf::PIXEL_FORMAT_PIXBUF) is called.

Definition at line 490 of file cairo-utils.cpp.

References _surface, ensurePixelFormat(), and PF_CAIRO.

Referenced by getSurface(), Inkscape::Extension::Internal::PdfBuilder::DrawContext::paint_item_to_raster(), and Inkscape::Extension::Internal::CairoRenderContext::renderImage().

◆ getSurfaceRaw() [2/2]

cairo_surface_t * Inkscape::Pixbuf::getSurfaceRaw ( ) const

Definition at line 496 of file cairo-utils.cpp.

References _pixel_format, _surface, and PF_CAIRO.

◆ hasMimeData()

bool Inkscape::Pixbuf::hasMimeData ( ) const

◆ height()

int Inkscape::Pixbuf::height ( ) const

◆ markDirty()

void Inkscape::Pixbuf::markDirty ( )

Definition at line 563 of file cairo-utils.cpp.

References _surface.

◆ modificationTime()

time_t Inkscape::Pixbuf::modificationTime ( ) const
inline

Definition at line 63 of file cairo-utils.h.

References _mod_time.

◆ originalPath()

std::string const & Inkscape::Pixbuf::originalPath ( ) const
inline

Definition at line 62 of file cairo-utils.h.

References _path.

◆ pixelFormat()

◆ pixels() [1/2]

guchar * Inkscape::Pixbuf::pixels ( )

Definition at line 560 of file cairo-utils.cpp.

References _pixbuf.

◆ pixels() [2/2]

◆ rowstride()

int Inkscape::Pixbuf::rowstride ( ) const

Definition at line 554 of file cairo-utils.cpp.

References _pixbuf.

◆ width()

int Inkscape::Pixbuf::width ( ) const

Member Data Documentation

◆ _cairo_store

bool Inkscape::Pixbuf::_cairo_store
private

Definition at line 89 of file cairo-utils.h.

Referenced by ~Pixbuf().

◆ _mod_time

time_t Inkscape::Pixbuf::_mod_time
private

Definition at line 86 of file cairo-utils.h.

Referenced by create_from_file(), and modificationTime().

◆ _path

std::string Inkscape::Pixbuf::_path
private

Definition at line 87 of file cairo-utils.h.

Referenced by create_from_buffer(), and originalPath().

◆ _pixbuf

GdkPixbuf* Inkscape::Pixbuf::_pixbuf
private

◆ _pixel_format

PixelFormat Inkscape::Pixbuf::_pixel_format
private

Definition at line 88 of file cairo-utils.h.

Referenced by cropTo(), ensurePixelFormat(), getPixbufRaw(), getSurfaceRaw(), and pixelFormat().

◆ _surface

cairo_surface_t* Inkscape::Pixbuf::_surface
private

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