35template <PreserveAlphaMode preserve_alpha>
38 ConvolveMatrix(
cairo_surface_t *s,
int targetX,
int targetY,
int orderX,
int orderY,
39 double divisor,
double bias, std::vector<double>
const &kernel)
41 , _kernel(kernel.size())
48 for (
unsigned i = 0; i < _kernel.size(); ++i) {
49 _kernel[i] = kernel[i] / divisor;
53 std::reverse(_kernel.begin(), _kernel.end());
56 guint32 operator()(
int x,
int y)
const
58 int startx = std::max(0, x - _targetX);
59 int starty = std::max(0, y - _targetY);
60 int endx = std::min(
_w, startx + _orderX);
61 int endy = std::min(
_h, starty + _orderY);
62 int limitx = endx - startx;
63 int limity = endy - starty;
64 double suma = 0.0, sumr = 0.0, sumg = 0.0, sumb = 0.0;
66 for (
int i = 0; i < limity; ++i) {
67 for (
int j = 0; j < limitx; ++j) {
69 double coeff = _kernel[i * _orderX + j];
70 EXTRACT_ARGB32(px, a,r,g,b)
90 ASSEMBLE_ARGB32(pxout, ao,ro,go,bo);
95 std::vector<double> _kernel;
96 int _targetX, _targetY, _orderX, _orderY;
102 static bool bias_warning =
false;
103 static bool edge_warning =
false;
106 g_warning(
"Empty kernel!");
109 if (targetX<0 || targetX>=
orderX || targetY<0 || targetY>=
orderY) {
110 g_warning(
"Invalid target!");
127 if (
bias != 0 && !bias_warning) {
128 g_warning(
"It is unknown whether Inkscape's implementation of bias in feConvolveMatrix is correct!");
139 g_warning(
"Inkscape only supports edgeMode=\"none\" (and a filter uses a different one)!");
168 cairo_surface_destroy(out);
Cairo software blending templates.
G_GNUC_CONST gint32 pxclamp(gint32 v, gint32 low, gint32 high)
void ink_cairo_surface_synthesize(cairo_surface_t *out, cairo_rectangle_t const &out_area, Synth &&synth)
Synthesize surface pixels based on their position.
cairo_surface_t * ink_cairo_surface_create_identical(cairo_surface_t *s)
Create a surface that differs only in pixel content.
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.
Axis aligned, non-empty, generic rectangle.
void setMin(CPoint const &p)
Set the upper left point of the rectangle.
void setMax(CPoint const &p)
Set the lower right point of the rectangle.
CPoint min() const
Get the corner of the rectangle with smallest coordinate values.
CPoint max() const
Get the corner of the rectangle with largest coordinate values.
Two-dimensional point with integer coordinates.
void set_targetY(int coord)
void render_cairo(FilterSlot &slot) const override
void set_divisor(double d)
FilterConvolveMatrixEdgeMode edgeMode
double complexity(Geom::Affine const &ctm) const override
void set_preserveAlpha(bool pa)
void set_edgeMode(FilterConvolveMatrixEdgeMode mode)
void set_kernelMatrix(std::vector< gdouble > km)
~FilterConvolveMatrix() override
void set_targetX(int coord)
std::vector< double > kernelMatrix
void area_enlarge(Geom::IntRect &area, Geom::Affine const &trans) const override
void set_orderY(int coord)
void set_orderX(int coord)
SPColorInterpolation color_interpolation
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
FilterConvolveMatrixEdgeMode
@ CONVOLVEMATRIX_EDGEMODE_NONE
Helper class to stream background task notifications as a series of messages.
Definition of functions needed by several filters.
guint32 alphaAt(int x, int y) const
guint32 pixelAt(int x, int y) const