/*
7 * Krzysztof KosiĆski <tweenk.pl@gmail.com>
9 * Copyright (C) 2010 Authors
10 * Released under GNU GPL v2+, read the file
'COPYING' for more information.
13#ifndef SEEN_INKSCAPE_DISPLAY_CAIRO_UTILS_H
14#define SEEN_INKSCAPE_DISPLAY_CAIRO_UTILS_H
17#include <cairomm/cairomm.h>
56 guchar
const *
pixels()
const;
61 guchar
const *
getMimeData(gsize &
len, std::string &mimetype)
const;
143const guchar*
pixbuf_to_png(guchar
const**rows, guchar* px,
int nrows,
int ncols,
int stride,
int color_type,
int bit_depth);
154 const guint32 temp = alpha * color + 128;
155 return (temp + (temp >> 8)) >> 8;
162 return (255 * color + alpha/2) / alpha;
171#define EXTRACT_ARGB32(px,a,r,g,b) \
172 guint32 a, r, g, b; \
173 a = ((px) & 0xff000000) >> 24; \
174 r = ((px) & 0x00ff0000) >> 16; \
175 g = ((px) & 0x0000ff00) >> 8; \
176 b = ((px) & 0x000000ff);
178#define ASSEMBLE_ARGB32(px,a,r,g,b) \
179 guint32 px = (a << 24) | (r << 16) | (g << 8) | b;
185 return pow( (
c+0.055)/1.055, 2.4 );
197 a = ((px) & 0xff000000) >> 24;
198 r = ((px) & 0x00ff0000) >> 16;
199 g = ((px) & 0x0000ff00) >> 8;
200 b = ((px) & 0x000000ff);
205 r = ((px) & 0x00ff0000) >> 16;
206 g = ((px) & 0x0000ff00) >> 8;
207 b = ((px) & 0x000000ff);
212 return (a << 24) | (r << 16) | (g << 8) | b;
cairo_pattern_t * ink_cairo_pattern_create(Inkscape::Colors::Color const &color, double opacity=1.0)
SPColorInterpolation get_cairo_surface_ci(cairo_surface_t *surface)
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 bot...
SPBlendMode ink_cairo_operator_to_css_blend(cairo_operator_t cairo_operator)
void ink_cairo_set_source_rgba32(Cairo::RefPtr< Cairo::Context > ctx, guint32 rgba)
void copy_cairo_surface_ci(cairo_surface_t *in, cairo_surface_t *out)
void convert_pixels_pixbuf_to_argb32(guchar *data, int w, int h, int rs)
Convert pixel data from GdkPixbuf format to ARGB.
G_GNUC_CONST guint32 premul_alpha(const guint32 color, const guint32 alpha)
Colors::Color ink_cairo_surface_average_color(cairo_surface_t *surface, cairo_surface_t *mask=nullptr)
Get the average color from the given surface.
void ink_matrix_to_2geom(Geom::Affine &, cairo_matrix_t const &)
G_GNUC_CONST guint32 rgba_from_argb32(guint32 in)
Convert a pixel in 0xAARRGGBB format to 0xRRGGBBAA format.
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_surface_t * ink_cairo_extract_alpha(cairo_surface_t *s)
Extract the alpha channel into a new surface.
int ink_cairo_surface_srgb_to_linear(cairo_surface_t *surface)
cairo_surface_t * ink_cairo_surface_create_same_size(cairo_surface_t *s, cairo_content_t c)
cairo_operator_t ink_css_blend_to_cairo_operator(SPBlendMode blend_mode)
double srgb_to_linear(const double c)
cairo_surface_t * ink_cairo_surface_create_identical(cairo_surface_t *s)
Create a surface that differs only in pixel content.
G_GNUC_CONST guint32 argb32_from_rgba(guint32 in)
Convert a pixel in 0xRRGGBBAA format to Cairo ARGB32 format.
cairo_pattern_t * ink_cairo_pattern_create_checkerboard(guint32 rgba=0xC4C4C4FF, bool use_alpha=false)
void ink_cairo_transform(cairo_t *ct, Geom::Affine const &m)
cairo_surface_t * ink_cairo_surface_copy(cairo_surface_t *s)
Create an exact copy of a surface.
void set_cairo_surface_ci(cairo_surface_t *surface, SPColorInterpolation cif)
Set the color_interpolation_value for a Cairo surface.
void ink_cairo_pattern_set_matrix(cairo_pattern_t *cp, Geom::Affine const &m)
G_GNUC_CONST guint32 unpremul_alpha(const guint32 color, const guint32 alpha)
void ink_cairo_pixbuf_cleanup(unsigned char *, void *)
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,...
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_pattern_set_dither(cairo_pattern_t *pattern, bool enabled)
int ink_cairo_surface_get_width(cairo_surface_t *surface)
Return width in pixels.
std::optional< Geom::PathVector > extract_pathvector_from_cairo(cairo_t *ct)
void ink_cairo_surface_blit(cairo_surface_t *src, cairo_surface_t *dest)
int ink_cairo_surface_get_height(cairo_surface_t *surface)
Return height in pixels.
void ink_cairo_pattern_add_color_stop(cairo_pattern_t *ptn, double offset, Inkscape::Colors::Color const &color, double opacity=1.0)
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.
void ink_cairo_set_hairline(cairo_t *ct)
G_GNUC_CONST guint32 argb32_from_pixbuf(guint32 in)
guint32 ink_cairo_pattern_get_argb32(cairo_pattern_t *pattern)
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.
void convert_cairo_surface_ci(cairo_surface_t *surface, SPColorInterpolation cif)
G_GNUC_CONST guint32 pixbuf_from_argb32(guint32 in, guint32 bgcolor=0)
Convert one pixel from ARGB to GdkPixbuf format.
struct _GdkPixbuf GdkPixbuf
void ink_matrix_to_cairo(cairo_matrix_t &, Geom::Affine const &)
cairo_surface_t * ink_cairo_surface_create_output(cairo_surface_t *image, cairo_surface_t *bg)
GdkPixbuf * ink_pixbuf_create_from_cairo_surface(cairo_surface_t *s)
Converts the Cairo surface to a GdkPixbuf pixel format, without allocating extra memory.
Cairo::RefPtr< Cairo::ImageSurface > surface
3x3 matrix representing an affine transformation.
Axis aligned, non-empty, generic rectangle.
Axis-aligned rectangle that can be empty.
Axis aligned, non-empty rectangle.
Class to hold image data for raster images.
guchar const * getMimeData(gsize &len, std::string &mimetype) const
Retrieves the original compressed data for the surface, if any.
static GdkPixbuf * apply_embedded_orientation(GdkPixbuf *buf)
Pixbuf * cropTo(const Geom::IntRect &area) const
Create a new Pixbuf with the image cropped to the given area.
std::string const & originalPath() const
void _ensurePixelsPixbuf()
PixelFormat _pixel_format
guchar const * pixels() const
Cairo::RefPtr< Cairo::Surface > getSurface()
GdkPixbuf * getPixbufRaw() const
void ensurePixelFormat(PixelFormat fmt)
Convert the internal pixel format between CAIRO and GDK formats.
cairo_surface_t * getSurfaceRaw()
Converts the pixbuf to Cairo pixel format and returns an image surface which can be used as a source.
static Pixbuf * create_from_file(std::string const &fn, double svgddpi=0)
static void ensure_argb32(GdkPixbuf *pb)
Converts GdkPixbuf's data to premultiplied ARGB.
static Geom::Affine get_embedded_orientation(GdkPixbuf *buf)
Gets any available orientation data and returns it as an affine.
static void ensure_pixbuf(GdkPixbuf *pb)
Converts GdkPixbuf's data back to its native format.
void _setMimeData(guchar *data, gsize len, Glib::ustring const &format)
cairo_surface_t * _surface
static Pixbuf * create_from_buffer(std::string const &, double svgddpi=0, std::string const &fn="")
static Pixbuf * create_from_data_uri(gchar const *uri, double svgdpi=0)
time_t modificationTime() const
PixelFormat pixelFormat() const
void _ensurePixelsARGB32()
vector< vpsc::Rectangle * > rs
_cairo_pattern cairo_pattern_t
struct _cairo_surface cairo_surface_t
Contains forward declarations of 2geom types.
std::unique_ptr< Magick::Image > image
void ExtractARGB32(guint32 px, guint32 &a, guint32 &r, guint32 &g, guint &b)
void ExtractRGB32(guint32 px, guint32 &r, guint32 &g, guint &b)
guint AssembleARGB32(guint32 a, guint32 r, guint32 g, guint32 b)
Helper class to stream background task notifications as a series of messages.
SPStyle - a style object for SPItem objects.