Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
cairo-utils.h File Reference

Cairo integration helpers. More...

Go to the source code of this file.

Classes

class  Inkscape::Pixbuf
 Class to hold image data for raster images. More...
 

Namespaces

namespace  Inkscape
 Helper class to stream background task notifications as a series of messages.
 
namespace  Inkscape::Colors
 A set of useful color modifying functions which do not fit as generic methods on the color class itself but which are used in various places.
 
namespace  Inkscape::Display
 Rendering-related code.
 

Typedefs

typedef struct _GdkPixbuf GdkPixbuf
 

Functions

void ink_cairo_pixbuf_cleanup (unsigned char *, void *)
 
SPColorInterpolation get_cairo_surface_ci (cairo_surface_t *surface)
 
void set_cairo_surface_ci (cairo_surface_t *surface, SPColorInterpolation cif)
 Set the color_interpolation_value for a Cairo surface.
 
void copy_cairo_surface_ci (cairo_surface_t *in, cairo_surface_t *out)
 
void convert_cairo_surface_ci (cairo_surface_t *surface, SPColorInterpolation cif)
 
cairo_pattern_tink_cairo_pattern_create (Inkscape::Colors::Color const &color, double opacity=1.0)
 
void ink_cairo_pattern_add_color_stop (cairo_pattern_t *ptn, double offset, Inkscape::Colors::Color const &color, double opacity=1.0)
 
void ink_cairo_set_source_color (Cairo::RefPtr< Cairo::Context > ctx, Inkscape::Colors::Color const &color, double opacity=1.0)
 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 &c, double opacity=1.0)
 
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_rgba32 (cairo_t *ctx, guint32 rgba)
 
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)
 
void ink_matrix_to_2geom (Geom::Affine &, cairo_matrix_t const &)
 
Geom::Affine ink_matrix_to_2geom (cairo_matrix_t const &cairo_matrix)
 
void ink_matrix_to_cairo (cairo_matrix_t &, Geom::Affine const &)
 
cairo_operator_t ink_css_blend_to_cairo_operator (SPBlendMode blend_mode)
 
SPBlendMode ink_cairo_operator_to_css_blend (cairo_operator_t cairo_operator)
 
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.
 
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=nullptr)
 Get the average color from the given surface.
 
double srgb_to_linear (const double c)
 
int ink_cairo_surface_srgb_to_linear (cairo_surface_t *surface)
 
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=0xC4C4C4FF, bool use_alpha=false)
 
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 convert_pixels_pixbuf_to_argb32 (guchar *data, int w, int h, int rs)
 Convert pixel data from GdkPixbuf format to ARGB.
 
void convert_pixels_argb32_to_pixbuf (guchar *data, int w, int h, int rs, guint32 bgcolor=0)
 Convert pixel data from ARGB to GdkPixbuf format.
 
G_GNUC_CONST guint32 argb32_from_pixbuf (guint32 in)
 
G_GNUC_CONST guint32 pixbuf_from_argb32 (guint32 in, guint32 bgcolor=0)
 Convert one pixel from ARGB to GdkPixbuf format.
 
const guchar * pixbuf_to_png (guchar const **rows, guchar *px, int nrows, int ncols, int stride, int color_type, int bit_depth)
 Converts a pixbuf to a PNG data structure.
 
G_GNUC_CONST guint32 argb32_from_rgba (guint32 in)
 Convert a pixel in 0xRRGGBBAA format to Cairo ARGB32 format.
 
G_GNUC_CONST guint32 rgba_from_argb32 (guint32 in)
 Convert a pixel in 0xAARRGGBB format to 0xRRGGBBAA format.
 
G_GNUC_CONST guint32 premul_alpha (const guint32 color, const guint32 alpha)
 
G_GNUC_CONST guint32 unpremul_alpha (const guint32 color, const guint32 alpha)
 
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)
 
void Inkscape::Display::ExtractARGB32 (guint32 px, guint32 &a, guint32 &r, guint32 &g, guint &b)
 
void Inkscape::Display::ExtractRGB32 (guint32 px, guint32 &r, guint32 &g, guint &b)
 
guint Inkscape::Display::AssembleARGB32 (guint32 a, guint32 r, guint32 g, guint32 b)
 

Detailed Description

Cairo integration helpers.

Definition in file cairo-utils.h.

Typedef Documentation

◆ GdkPixbuf

typedef struct _GdkPixbuf GdkPixbuf

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

Function Documentation

◆ argb32_from_pixbuf()

G_GNUC_CONST guint32 argb32_from_pixbuf ( guint32  in)

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

References c, and premul_alpha().

Referenced by convert_pixels_pixbuf_to_argb32().

◆ argb32_from_rgba()

G_GNUC_CONST guint32 argb32_from_rgba ( guint32  in)

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

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

References premul_alpha().

◆ convert_cairo_surface_ci()

void convert_cairo_surface_ci ( cairo_surface_t surface,
SPColorInterpolation  cif 
)

◆ 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 1744 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 1723 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 870 of file cairo-utils.cpp.

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

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

◆ 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 852 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 837 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)

◆ 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 1523 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 1142 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()

cairo_pattern_t * ink_cairo_pattern_create ( Inkscape::Colors::Color const &  color,
double  opacity = 1.0 
)

◆ 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 1469 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 1261 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 1050 of file cairo-utils.cpp.

◆ ink_cairo_pattern_set_matrix()

◆ ink_cairo_pixbuf_cleanup()

void ink_cairo_pixbuf_cleanup ( unsigned char *  ,
void *   
)

◆ 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 &  c,
double  opacity = 1.0 
)

◆ ink_cairo_set_source_rgba32() [1/3]

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

Definition at line 965 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 959 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 1289 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_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 1090 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 1063 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 1213 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 1201 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 1458 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 1346 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 1014 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()

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

◆ 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 1616 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().

◆ pixbuf_from_argb32()

G_GNUC_CONST 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 1688 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 1814 of file cairo-utils.cpp.

References get_luminance(), and stride.

Referenced by sp_export_get_rows().

◆ premul_alpha()

G_GNUC_CONST guint32 premul_alpha ( const guint32  color,
const guint32  alpha 
)
inline

◆ rgba_from_argb32()

G_GNUC_CONST guint32 rgba_from_argb32 ( guint32  c)

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

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

Parameters
cRGBA color

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

References c, and unpremul_alpha().

◆ set_cairo_surface_ci()

◆ srgb_to_linear()

double srgb_to_linear ( const double  c)
inline

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

References c.

◆ unpremul_alpha()