Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
nr-filter-blend.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
/*
5 * "This filter composites two objects together using commonly used
6 * imaging software blending modes. It performs a pixel-wise combination
7 * of two input images."
8 * http://www.w3.org/TR/SVG11/filters.html#feBlend
9 *
10 * Authors:
11 * Niko Kiirala <niko@kiirala.com>
12 * Jasper van de Gronde <th.v.d.gronde@hccnet.nl>
13 * Krzysztof KosiƄski <tweenk.pl@gmail.com>
14 *
15 * Copyright (C) 2007-2008 authors
16 *
17 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
18 */
19
20#include <glibmm.h>
22#include "display/cairo-utils.h"
27
28namespace Inkscape {
29namespace Filters {
30
31std::set<SPBlendMode> const FilterBlend::_valid_modes {
32 // clang-format off
41 // clang-format on
42 };
43
49
51
52static inline cairo_operator_t get_cairo_op(SPBlendMode _blend_mode)
53{
54 switch (_blend_mode) {
56 return CAIRO_OPERATOR_MULTIPLY;
58 return CAIRO_OPERATOR_SCREEN;
60 return CAIRO_OPERATOR_DARKEN;
62 return CAIRO_OPERATOR_LIGHTEN;
63 // New in CSS Compositing and Blending Level 1
65 return CAIRO_OPERATOR_OVERLAY;
67 return CAIRO_OPERATOR_COLOR_DODGE;
69 return CAIRO_OPERATOR_COLOR_BURN;
71 return CAIRO_OPERATOR_HARD_LIGHT;
73 return CAIRO_OPERATOR_SOFT_LIGHT;
75 return CAIRO_OPERATOR_DIFFERENCE;
77 return CAIRO_OPERATOR_EXCLUSION;
79 return CAIRO_OPERATOR_HSL_HUE;
81 return CAIRO_OPERATOR_HSL_SATURATION;
83 return CAIRO_OPERATOR_HSL_COLOR;
85 return CAIRO_OPERATOR_HSL_LUMINOSITY;
86
88 default:
89 return CAIRO_OPERATOR_OVER;
90 }
91}
92
94{
95 cairo_surface_t *input1 = slot.getcairo(_input);
96 cairo_surface_t *input2 = slot.getcairo(_input2);
97
98 // We may need to transform input surface to correct color interpolation space. The input surface
99 // might be used as input to another primitive but it is likely that all the primitives in a given
100 // filter use the same color interpolation space so we don't copy the input before converting.
103
104 // input2 is the "background" image
105 // out should be ARGB32 if any of the inputs is ARGB32
108
109 ink_cairo_surface_blit(input2, out);
110 cairo_t *out_ct = cairo_create(out);
111 cairo_set_source_surface(out_ct, input1, 0, 0);
112
113 // All of the blend modes are implemented in Cairo as of 1.10.
114 // For a detailed description, see:
115 // http://cairographics.org/operators/
116 cairo_set_operator(out_ct, get_cairo_op(_blend_mode));
117
118 cairo_paint(out_ct);
119 cairo_destroy(out_ct);
120
121 slot.set(_output, out);
122 cairo_surface_destroy(out);
123}
124
126{
127 // blend is a per-pixel primitive and is immutable under transformations
128 return true;
129}
130
132{
133 return 1.1;
134}
135
141
143{
144 _input = slot;
145}
146
147void FilterBlend::set_input(int input, int slot)
148{
149 if (input == 0) _input = slot;
150 if (input == 1) _input2 = slot;
151}
152
154{
155 if (_valid_modes.count(mode)) {
157 }
158}
159
160} /* namespace Filters */
161} /* namespace Inkscape */
162
163/*
164 Local Variables:
165 mode:c++
166 c-file-style:"stroustrup"
167 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
168 indent-tabs-mode:nil
169 fill-column:99
170 End:
171*/
172// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
Cairo software blending templates.
void ink_cairo_surface_blit(cairo_surface_t *src, cairo_surface_t *dest)
cairo_surface_t * ink_cairo_surface_create_output(cairo_surface_t *image, cairo_surface_t *bg)
void set_cairo_surface_ci(cairo_surface_t *surface, SPColorInterpolation ci)
Set the color_interpolation_value for a Cairo surface.
Cairo integration helpers.
3x3 matrix representing an affine transformation.
Definition affine.h:70
void set_mode(SPBlendMode mode)
double complexity(Geom::Affine const &ctm) const override
bool uses_background() const override
void set_input(int slot) override
Sets the input slot number 'slot' to be used as input in rendering filter primitive 'primitive' For f...
bool can_handle_affine(Geom::Affine const &) const override
Indicate whether the filter primitive can handle the given affine.
static const std::set< SPBlendMode > _valid_modes
void render_cairo(FilterSlot &slot) const override
cairo_surface_t * getcairo(int slot)
Returns the pixblock in specified slot.
void set(int slot, cairo_surface_t *s)
Sets or re-sets the pixblock associated with given slot.
struct _cairo_surface cairo_surface_t
static cairo_operator_t get_cairo_op(SPBlendMode _blend_mode)
Helper class to stream background task notifications as a series of messages.
TODO: insert short description here.
int mode
struct _cairo cairo_t
Definition path-cairo.h:16
SPBlendMode
@ SP_CSS_BLEND_LUMINOSITY
@ SP_CSS_BLEND_DARKEN
@ SP_CSS_BLEND_LIGHTEN
@ SP_CSS_BLEND_DIFFERENCE
@ SP_CSS_BLEND_COLORBURN
@ SP_CSS_BLEND_HARDLIGHT
@ SP_CSS_BLEND_EXCLUSION
@ SP_CSS_BLEND_COLORDODGE
@ SP_CSS_BLEND_SOFTLIGHT
@ SP_CSS_BLEND_SATURATION
@ SP_CSS_BLEND_SCREEN
@ SP_CSS_BLEND_OVERLAY
@ SP_CSS_BLEND_NORMAL
@ SP_CSS_BLEND_HUE
@ SP_CSS_BLEND_COLOR
@ SP_CSS_BLEND_MULTIPLY