Inkscape
Vector Graphics Editor
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages Concepts
cairo-utils.cpp File Reference

Go to the source code of this file.

Namespaces

namespace  Inkscape
 Helper class to stream background task notifications as a series of messages.
 

Functions

static bool Inkscape::_workaround_issue_70__gdk_pixbuf_loader_write (GdkPixbufLoader *loader, guchar *decoded, gsize decoded_len, GError **error)
 Incremental file read introduced to workaround https://gitlab.gnome.org/GNOME/gdk-pixbuf/issues/70.
 
static void feed_curve_to_cairo (cairo_t *cr, Geom::Curve const &c, Geom::Affine const &trans, Geom::Rect const &view, bool optimize_stroke)
 
static void feed_path_to_cairo (cairo_t *ct, Geom::Path const &path)
 Feeds path-creating calls to the cairo context translating them from the Path.
 
static void feed_path_to_cairo (cairo_t *ct, Geom::Path const &path, Geom::Affine trans, Geom::OptRect area, bool optimize_stroke, double stroke_width)
 Feeds path-creating calls to the cairo context translating them from the Path, with the given transform and shift.
 
void feed_pathvector_to_cairo (cairo_t *ct, Geom::PathVector const &pathv, Geom::Affine trans, Geom::OptRect area, bool optimize_stroke, double stroke_width)
 Feeds path-creating calls to the cairo context translating them from the PathVector, with the given transform and shift One must have done cairo_new_path(ct); before calling this function.
 
void feed_pathvector_to_cairo (cairo_t *ct, Geom::PathVector const &pathv)
 Feeds path-creating calls to the cairo context translating them from the PathVector One must have done cairo_new_path(ct); before calling this function.
 
std::optional< Geom::PathVectorextract_pathvector_from_cairo (cairo_t *ct)
 
SPColorInterpolation get_cairo_surface_ci (cairo_surface_t *surface)
 
void set_cairo_surface_ci (cairo_surface_t *surface, SPColorInterpolation ci)
 Set the color_interpolation_value for a Cairo surface.
 
void copy_cairo_surface_ci (cairo_surface_t *in, cairo_surface_t *out)
 
void ink_cairo_set_source_rgba32 (cairo_t *ct, guint32 rgba)
 
void ink_cairo_set_source_rgba32 (Cairo::RefPtr< Cairo::Context > ctx, guint32 rgba)
 
void ink_cairo_set_source_rgba32 (Cairo::Context &ctx, guint32 rgba)
 
void ink_cairo_set_source_color (Cairo::RefPtr< Cairo::Context > ctx, Inkscape::Colors::Color const &color, double opacity)
 The following functions interact between Inkscape color model, and cairo surface rendering.
 
void ink_cairo_set_source_color (cairo_t *ctx, Inkscape::Colors::Color const &color, double opacity)
 
void ink_cairo_pattern_add_color_stop (cairo_pattern_t *ptn, double offset, Inkscape::Colors::Color const &color, double opacity)
 
cairo_pattern_tink_cairo_pattern_create (Inkscape::Colors::Color const &color, double opacity)
 
void ink_matrix_to_2geom (Geom::Affine &m, cairo_matrix_t const &cm)
 
void ink_matrix_to_cairo (cairo_matrix_t &cm, Geom::Affine const &m)
 
Geom::Affine ink_matrix_to_2geom (cairo_matrix_t const &cairo_matrix)
 
void ink_cairo_transform (cairo_t *ct, Geom::Affine const &m)
 
void ink_cairo_pattern_set_matrix (cairo_pattern_t *cp, Geom::Affine const &m)
 
void ink_cairo_set_hairline (cairo_t *ct)
 
void ink_cairo_pattern_set_dither (cairo_pattern_t *pattern, bool enabled)
 
cairo_surface_tink_cairo_surface_copy (cairo_surface_t *s)
 Create an exact copy of a surface.
 
Cairo::RefPtr< Cairo::ImageSurface > ink_cairo_surface_copy (Cairo::RefPtr< Cairo::ImageSurface > surface)
 Create an exact copy of an image surface.
 
cairo_surface_tink_cairo_surface_create_identical (cairo_surface_t *s)
 Create a surface that differs only in pixel content.
 
cairo_surface_tink_cairo_surface_create_same_size (cairo_surface_t *s, cairo_content_t c)
 
cairo_surface_tink_cairo_extract_alpha (cairo_surface_t *s)
 Extract the alpha channel into a new surface.
 
cairo_surface_tink_cairo_surface_create_output (cairo_surface_t *image, cairo_surface_t *bg)
 
void ink_cairo_surface_blit (cairo_surface_t *src, cairo_surface_t *dest)
 
int ink_cairo_surface_get_width (cairo_surface_t *surface)
 Return width in pixels.
 
int ink_cairo_surface_get_height (cairo_surface_t *surface)
 Return height in pixels.
 
static double ink_cairo_surface_average_color_internal (cairo_surface_t *surface, cairo_surface_t *mask, double &rf, double &gf, double &bf, double &af)
 
guint32 ink_cairo_pattern_get_argb32 (cairo_pattern_t *pattern)
 
Colors::Color ink_cairo_surface_average_color (cairo_surface_t *surface, cairo_surface_t *mask)
 Get the average color from the given surface.
 
static guint32 srgb_to_linear (const guint32 c, const guint32 a)
 
static guint32 linear_to_srgb (const guint32 c, const guint32 a)
 
static uint32_t srgb_to_linear_argb32 (uint32_t in)
 
int ink_cairo_surface_srgb_to_linear (cairo_surface_t *surface)
 
static uint32_t linear_to_srgb_argb32 (uint32_t in)
 
SPBlendMode ink_cairo_operator_to_css_blend (cairo_operator_t cairo_operator)
 
cairo_operator_t ink_css_blend_to_cairo_operator (SPBlendMode css_blend)
 
int ink_cairo_surface_linear_to_srgb (cairo_surface_t *surface)
 
Cairo::RefPtr< Cairo::Pattern > ink_cairo_pattern_create_slanting_stripes (uint32_t color)
 
cairo_pattern_tink_cairo_pattern_create_checkerboard (guint32 rgba, bool use_alpha)
 
void ink_cairo_draw_drop_shadow (const Cairo::RefPtr< Cairo::Context > &ctx, const Geom::Rect &rect, double size, guint32 color, double color_alpha)
 Draw drop shadow around the 'rect' with given 'size' and 'color'; shadow extends to the right and bottom of rect.
 
GdkPixbufink_pixbuf_create_from_cairo_surface (cairo_surface_t *s)
 Converts the Cairo surface to a GdkPixbuf pixel format, without allocating extra memory.
 
void ink_cairo_pixbuf_cleanup (guchar *, void *data)
 Cleanup function for GdkPixbuf.
 
guint32 argb32_from_pixbuf (guint32 c)
 
guint32 pixbuf_from_argb32 (guint32 c, guint32 bgcolor)
 Convert one pixel from ARGB to GdkPixbuf format.
 
void convert_pixels_pixbuf_to_argb32 (guchar *data, int w, int h, int stride)
 Convert pixel data from GdkPixbuf format to ARGB.
 
void convert_pixels_argb32_to_pixbuf (guchar *data, int w, int h, int stride, guint32 bgcolor)
 Convert pixel data from ARGB to GdkPixbuf format.
 
guint32 argb32_from_rgba (guint32 in)
 Convert a pixel in 0xRRGGBBAA format to Cairo ARGB32 format.
 
guint32 rgba_from_argb32 (guint32 c)
 Convert one pixel from ARGB to GdkPixbuf format.
 
static constexpr uint16_t get_luminance (uint32_t r, uint32_t g, uint32_t b)
 
const guchar * pixbuf_to_png (guchar const **rows, guchar *px, int num_rows, int num_cols, int stride, int color_type, int bit_depth)
 Converts a pixbuf to a PNG data structure.
 

Variables

static cairo_user_data_key_t ink_color_interpolation_key
 Key for cairo_surface_t to keep track of current color interpolation value Only the address of the structure is used, it is never initialized.
 

Function Documentation

◆ argb32_from_pixbuf()

guint32 argb32_from_pixbuf ( guint32  c)

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

References c, and premul_alpha().

Referenced by convert_pixels_pixbuf_to_argb32().

◆ argb32_from_rgba()

guint32 argb32_from_rgba ( guint32  in)

Convert a pixel in 0xRRGGBBAA format to Cairo ARGB32 format.

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

References premul_alpha().

◆ convert_pixels_argb32_to_pixbuf()

void convert_pixels_argb32_to_pixbuf ( guchar *  data,
int  w,
int  h,
int  stride,
guint32  bgcolor 
)

Convert pixel data from ARGB to GdkPixbuf format.

This will convert pixel data from GdkPixbuf format to Cairo's native pixel format. This involves premultiplying alpha and shuffling around the channels.

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

References data, pixbuf_from_argb32(), stride, and w.

Referenced by Inkscape::Pixbuf::ensure_pixbuf(), ink_pixbuf_create_from_cairo_surface(), and sp_export_get_rows().

◆ convert_pixels_pixbuf_to_argb32()

void convert_pixels_pixbuf_to_argb32 ( guchar *  data,
int  w,
int  h,
int  stride 
)

Convert pixel data from GdkPixbuf format to ARGB.

This will convert pixel data from GdkPixbuf format to Cairo's native pixel format. This involves premultiplying alpha and shuffling around the channels. Pixbuf data must have an alpha channel, otherwise the results are undefined (usually a segfault).

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

References argb32_from_pixbuf(), data, stride, and w.

Referenced by Inkscape::Pixbuf::ensure_argb32().

◆ copy_cairo_surface_ci()

◆ extract_pathvector_from_cairo()

std::optional< Geom::PathVector > extract_pathvector_from_cairo ( cairo_t ct)

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

References end, and Geom::Point::length().

Referenced by Inkscape::Extension::Internal::SvgBuilder::_renderText().

◆ feed_curve_to_cairo()

◆ feed_path_to_cairo() [1/2]

static void feed_path_to_cairo ( cairo_t ct,
Geom::Path const &  path 
)
static

Feeds path-creating calls to the cairo context translating them from the Path.

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

References Geom::Path::begin(), cairo_move_to(), Geom::Path::closed(), Geom::Path::empty(), Geom::Path::end_open(), feed_curve_to_cairo(), Geom::identity(), and Geom::Path::initialPoint().

Referenced by feed_pathvector_to_cairo(), and feed_pathvector_to_cairo().

◆ feed_path_to_cairo() [2/2]

static void feed_path_to_cairo ( cairo_t ct,
Geom::Path const &  path,
Geom::Affine  trans,
Geom::OptRect  area,
bool  optimize_stroke,
double  stroke_width 
)
static

Feeds path-creating calls to the cairo context translating them from the Path, with the given transform and shift.

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

References Geom::Path::begin(), cairo_line_to(), cairo_move_to(), Geom::Path::closed(), Geom::Path::empty(), Geom::Path::end_open(), Geom::GenericRect< C >::expandBy(), feed_curve_to_cairo(), Geom::Path::initialPoint(), and shift().

◆ feed_pathvector_to_cairo() [1/2]

void feed_pathvector_to_cairo ( cairo_t ct,
Geom::PathVector const &  pathv 
)

Feeds path-creating calls to the cairo context translating them from the PathVector One must have done cairo_new_path(ct); before calling this function.

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

References Geom::PathVector::empty(), and feed_path_to_cairo().

◆ feed_pathvector_to_cairo() [2/2]

void feed_pathvector_to_cairo ( cairo_t ct,
Geom::PathVector const &  pathv,
Geom::Affine  trans,
Geom::OptRect  area,
bool  optimize_stroke,
double  stroke_width 
)

Feeds path-creating calls to the cairo context translating them from the PathVector, with the given transform and shift One must have done cairo_new_path(ct); before calling this function.

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

References Geom::PathVector::empty(), and feed_path_to_cairo().

Referenced by Inkscape::CanvasItemBpath::_render(), Inkscape::Extension::Internal::CairoRenderContext::addPathVector(), Inkscape::DrawingContext::path(), and SvgFont::render_glyph_path().

◆ get_cairo_surface_ci()

SPColorInterpolation get_cairo_surface_ci ( cairo_surface_t surface)

◆ get_luminance()

static constexpr uint16_t get_luminance ( uint32_t  r,
uint32_t  g,
uint32_t  b 
)
staticconstexpr

◆ ink_cairo_draw_drop_shadow()

void ink_cairo_draw_drop_shadow ( const Cairo::RefPtr< Cairo::Context > &  ctx,
const Geom::Rect rect,
double  size,
guint32  color,
double  color_alpha 
)

Draw drop shadow around the 'rect' with given 'size' and 'color'; shadow extends to the right and bottom of rect.

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

References Geom::GenericRect< C >::corner(), corners, Geom::GenericRect< C >::height(), N, size, SP_RGBA32_B_F(), SP_RGBA32_G_F(), SP_RGBA32_R_F(), Geom::GenericRect< C >::width(), Geom::X, and Geom::Y.

Referenced by Inkscape::CanvasItemRect::_render(), Inkscape::UI::Dialog::add_shadow(), and Inkscape::UI::Widget::PageSizePreview::draw_func().

◆ ink_cairo_extract_alpha()

cairo_surface_t * ink_cairo_extract_alpha ( cairo_surface_t s)

Extract the alpha channel into a new surface.

Creates a surface with a content type of CAIRO_CONTENT_ALPHA that contains the alpha values of pixels from s.

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

References ink_cairo_surface_create_same_size().

Referenced by Inkscape::Filters::FilterSlot::getcairo().

◆ ink_cairo_operator_to_css_blend()

◆ ink_cairo_pattern_add_color_stop()

◆ ink_cairo_pattern_create()

◆ ink_cairo_pattern_create_checkerboard()

◆ ink_cairo_pattern_create_slanting_stripes()

Cairo::RefPtr< Cairo::Pattern > ink_cairo_pattern_create_slanting_stripes ( uint32_t  color)

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

References ink_cairo_set_source_rgba32(), surface, and width.

Referenced by get_cached_pattern().

◆ ink_cairo_pattern_get_argb32()

guint32 ink_cairo_pattern_get_argb32 ( cairo_pattern_t pattern)

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

References SP_RGBA32_F_COMPOSE(), and surface.

◆ ink_cairo_pattern_set_dither()

void ink_cairo_pattern_set_dither ( cairo_pattern_t pattern,
bool  enabled 
)

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

◆ ink_cairo_pattern_set_matrix()

◆ ink_cairo_pixbuf_cleanup()

void ink_cairo_pixbuf_cleanup ( guchar *  ,
void *  data 
)

Cleanup function for GdkPixbuf.

This function should be passed as the GdkPixbufDestroyNotify parameter to gdk_pixbuf_new_from_data when creating a GdkPixbuf backed by a Cairo surface.

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

References data, and surface.

Referenced by ink_pixbuf_create_from_cairo_surface().

◆ ink_cairo_set_hairline()

void ink_cairo_set_hairline ( cairo_t ct)

◆ ink_cairo_set_source_color() [1/2]

void ink_cairo_set_source_color ( Cairo::RefPtr< Cairo::Context >  ctx,
Inkscape::Colors::Color const &  color,
double  opacity 
)

◆ ink_cairo_set_source_color() [2/2]

void ink_cairo_set_source_color ( cairo_t ctx,
Inkscape::Colors::Color const &  color,
double  opacity 
)

◆ ink_cairo_set_source_rgba32() [1/3]

void ink_cairo_set_source_rgba32 ( Cairo::Context &  ctx,
guint32  rgba 
)

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

References SP_RGBA32_A_F(), SP_RGBA32_B_F(), SP_RGBA32_G_F(), and SP_RGBA32_R_F().

◆ ink_cairo_set_source_rgba32() [2/3]

void ink_cairo_set_source_rgba32 ( Cairo::RefPtr< Cairo::Context >  ctx,
guint32  rgba 
)

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

References SP_RGBA32_A_F(), SP_RGBA32_B_F(), SP_RGBA32_G_F(), and SP_RGBA32_R_F().

◆ ink_cairo_set_source_rgba32() [3/3]

◆ ink_cairo_surface_average_color()

Colors::Color ink_cairo_surface_average_color ( cairo_surface_t surface,
cairo_surface_t mask 
)

Get the average color from the given surface.

  • surface - The cairo surface to get data from.
  • masked - If true, ignores any truely invisible pixels.

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

References ink_cairo_surface_average_color_internal(), and surface.

Referenced by Inkscape::Drawing::averageColor(), Inkscape::Drawing::averageColor(), SPMeshNodeArray::color_pick(), Inkscape::UI::Dialog::ColorItem::getColor(), and Inkscape::UI::Dialog::CloneTiler::trace_pick().

◆ ink_cairo_surface_average_color_internal()

static double ink_cairo_surface_average_color_internal ( cairo_surface_t surface,
cairo_surface_t mask,
double &  rf,
double &  gf,
double &  bf,
double &  af 
)
static

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

References data, height, surface, and width.

Referenced by ink_cairo_surface_average_color().

◆ ink_cairo_surface_blit()

◆ ink_cairo_surface_copy() [1/2]

Cairo::RefPtr< Cairo::ImageSurface > ink_cairo_surface_copy ( Cairo::RefPtr< Cairo::ImageSurface >  surface)

Create an exact copy of an image surface.

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

References height, stride, surface, and width.

◆ ink_cairo_surface_copy() [2/2]

cairo_surface_t * ink_cairo_surface_copy ( cairo_surface_t s)

Create an exact copy of a surface.

Creates a surface that has the same type, content type, dimensions and contents as the specified surface.

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

References ink_cairo_surface_create_identical(), and stride.

Referenced by Inkscape::DrawingCache::_dumpCache(), and Inkscape::Filters::FilterGaussian::render_cairo().

◆ ink_cairo_surface_create_identical()

◆ ink_cairo_surface_create_output()

◆ ink_cairo_surface_create_same_size()

◆ ink_cairo_surface_get_height()

int ink_cairo_surface_get_height ( cairo_surface_t surface)

Return height in pixels.

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

References surface.

Referenced by ink_cairo_surface_create_same_size(), and Inkscape::Filters::FilterGaussian::render_cairo().

◆ ink_cairo_surface_get_width()

int ink_cairo_surface_get_width ( cairo_surface_t surface)

Return width in pixels.

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

References surface.

Referenced by ink_cairo_surface_create_same_size(), and Inkscape::Filters::FilterGaussian::render_cairo().

◆ ink_cairo_surface_linear_to_srgb()

int ink_cairo_surface_linear_to_srgb ( cairo_surface_t surface)

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

References height, ink_cairo_surface_filter(), linear_to_srgb_argb32(), surface, and width.

Referenced by set_cairo_surface_ci().

◆ ink_cairo_surface_srgb_to_linear()

int ink_cairo_surface_srgb_to_linear ( cairo_surface_t surface)

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

References height, ink_cairo_surface_filter(), srgb_to_linear_argb32(), surface, and width.

Referenced by set_cairo_surface_ci().

◆ ink_cairo_transform()

◆ ink_css_blend_to_cairo_operator()

◆ ink_matrix_to_2geom() [1/2]

Geom::Affine ink_matrix_to_2geom ( cairo_matrix_t const &  cairo_matrix)

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

References ink_matrix_to_2geom(), and result.

◆ ink_matrix_to_2geom() [2/2]

void ink_matrix_to_2geom ( Geom::Affine m,
cairo_matrix_t const &  cm 
)

◆ ink_matrix_to_cairo()

◆ ink_pixbuf_create_from_cairo_surface()

GdkPixbuf * ink_pixbuf_create_from_cairo_surface ( cairo_surface_t s)

Converts the Cairo surface to a GdkPixbuf pixel format, without allocating extra memory.

This function is intended mainly for creating previews displayed by GTK. For loading images for display on the canvas, use the Inkscape::Pixbuf object.

The returned GdkPixbuf takes ownership of the passed surface reference, so it should NOT be freed after calling this function.

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

References convert_pixels_argb32_to_pixbuf(), ink_cairo_pixbuf_cleanup(), rs, and w.

Referenced by Inkscape::UI::Widget::draw_circle(), render_pixbuf(), and sp_gradient_to_pixbuf().

◆ linear_to_srgb()

static guint32 linear_to_srgb ( const guint32  c,
const guint32  a 
)
static

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

References c, premul_alpha(), and unpremul_alpha().

Referenced by linear_to_srgb_argb32().

◆ linear_to_srgb_argb32()

static uint32_t linear_to_srgb_argb32 ( uint32_t  in)
static

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

References linear_to_srgb().

Referenced by ink_cairo_surface_linear_to_srgb().

◆ pixbuf_from_argb32()

guint32 pixbuf_from_argb32 ( guint32  c,
guint32  bgcolor 
)

Convert one pixel from ARGB to GdkPixbuf format.

Parameters
cARGB color
bgcolorColor to use if c.alpha is zero (bgcolor.alpha is ignored)

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

References c, and unpremul_alpha().

Referenced by convert_pixels_argb32_to_pixbuf().

◆ pixbuf_to_png()

const guchar * pixbuf_to_png ( guchar const **  rows,
guchar *  px,
int  num_rows,
int  num_cols,
int  stride,
int  color_type,
int  bit_depth 
)

Converts a pixbuf to a PNG data structure.

For 8-but RGBA png, this is like copying.

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

References get_luminance(), and stride.

Referenced by sp_export_get_rows().

◆ rgba_from_argb32()

guint32 rgba_from_argb32 ( guint32  c)

Convert one pixel from ARGB to GdkPixbuf format.

Convert a pixel in 0xAARRGGBB format to 0xRRGGBBAA format.

Parameters
cRGBA color

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

References c, and unpremul_alpha().

◆ set_cairo_surface_ci()

◆ srgb_to_linear()

◆ srgb_to_linear_argb32()

static uint32_t srgb_to_linear_argb32 ( uint32_t  in)
static

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

References srgb_to_linear().

Referenced by ink_cairo_surface_srgb_to_linear().

Variable Documentation

◆ ink_color_interpolation_key

cairo_user_data_key_t ink_color_interpolation_key
static

Key for cairo_surface_t to keep track of current color interpolation value Only the address of the structure is used, it is never initialized.

See: http://www.cairographics.org/manual/cairo-Types.html#cairo-user-data-key-t

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

Referenced by copy_cairo_surface_ci(), get_cairo_surface_ci(), ink_cairo_surface_create_identical(), and set_cairo_surface_ci().