31 unsigned limit = std::min(
static_cast<size_t>(20),
values.size());
32 for (
unsigned i = 0; i <
limit; ++i) {
39 for (
unsigned i =
limit; i < 20; ++i) {
40 _v[i] = (i % 6 == 0) ? 255 : 0;
46 EXTRACT_ARGB32(in, a, r, g, b)
55 gint32 ro = r*_v[0] + g*_v[1] + b*_v[2] + a*_v[3] + _v[4];
56 gint32 go = r*_v[5] + g*_v[6] + b*_v[7] + a*_v[8] + _v[9];
57 gint32 bo = r*_v[10] + g*_v[11] + b*_v[12] + a*_v[13] + _v[14];
58 gint32 ao = r*_v[15] + g*_v[16] + b*_v[17] + a*_v[18] + _v[19];
59 ro = (
pxclamp(ro, 0, 255*255) + 127) / 255;
60 go = (
pxclamp(go, 0, 255*255) + 127) / 255;
61 bo = (
pxclamp(bo, 0, 255*255) + 127) / 255;
62 ao = (
pxclamp(ao, 0, 255*255) + 127) / 255;
68 ASSEMBLE_ARGB32(pxout, ao, ro, go, bo)
72struct ColorMatrixSaturate
74 ColorMatrixSaturate(
double v_in)
77 double v = std::clamp(v_in, 0.0, 1.0);
78 _v[0] = 0.213+0.787*v; _v[1] = 0.715-0.715*v; _v[2] = 0.072-0.072*v;
79 _v[3] = 0.213-0.213*v; _v[4] = 0.715+0.285*v; _v[5] = 0.072-0.072*v;
80 _v[6] = 0.213-0.213*v; _v[7] = 0.715-0.715*v; _v[8] = 0.072+0.928*v;
85 EXTRACT_ARGB32(in, a, r, g, b)
89 guint32 ro = r*_v[0] + g*_v[1] + b*_v[2] + 0.5;
90 guint32 go = r*_v[3] + g*_v[4] + b*_v[5] + 0.5;
91 guint32 bo = r*_v[6] + g*_v[7] + b*_v[8] + 0.5;
93 ASSEMBLE_ARGB32(pxout, a, ro, go, bo)
101struct ColorMatrixHueRotate
103 ColorMatrixHueRotate(
double v)
105 double sinhue, coshue;
108 _v[0] = std::round((0.213 +0.787*coshue -0.213*sinhue)*255);
109 _v[1] = std::round((0.715 -0.715*coshue -0.715*sinhue)*255);
110 _v[2] = std::round((0.072 -0.072*coshue +0.928*sinhue)*255);
112 _v[3] = std::round((0.213 -0.213*coshue +0.143*sinhue)*255);
113 _v[4] = std::round((0.715 +0.285*coshue +0.140*sinhue)*255);
114 _v[5] = std::round((0.072 -0.072*coshue -0.283*sinhue)*255);
116 _v[6] = std::round((0.213 -0.213*coshue -0.787*sinhue)*255);
117 _v[7] = std::round((0.715 -0.715*coshue +0.715*sinhue)*255);
118 _v[8] = std::round((0.072 +0.928*coshue +0.072*sinhue)*255);
123 EXTRACT_ARGB32(in, a, r, g, b)
125 gint32 ro = r*_v[0] + g*_v[1] + b*_v[2];
126 gint32 go = r*_v[3] + g*_v[4] + b*_v[5];
127 gint32 bo = r*_v[6] + g*_v[7] + b*_v[8];
128 ro = (
pxclamp(ro, 0, maxpx) + 127) / 255;
129 go = (
pxclamp(go, 0, maxpx) + 127) / 255;
130 bo = (
pxclamp(bo, 0, maxpx) + 127) / 255;
132 ASSEMBLE_ARGB32(pxout, a, ro, go, bo)
140struct ColorMatrixLuminanceToAlpha
145 EXTRACT_ARGB32(in, a, r, g, b)
152 guint32 ao = r*54 + g*182 + b*18;
153 return ((ao + 127) / 255) << 24;
194 cairo_surface_destroy(out);
Cairo software blending templates.
G_GNUC_CONST gint32 pxclamp(gint32 v, gint32 low, gint32 high)
void ink_cairo_surface_filter(cairo_surface_t *in, cairo_surface_t *out, Filter &&filter)
cairo_surface_t * ink_cairo_surface_create_same_size(cairo_surface_t *s, cairo_content_t c)
void set_cairo_surface_ci(cairo_surface_t *surface, SPColorInterpolation ci)
Set the color_interpolation_value for a Cairo surface.
Cairo integration helpers.
G_GNUC_CONST guint32 premul_alpha(const guint32 color, const guint32 alpha)
G_GNUC_CONST guint32 unpremul_alpha(const guint32 color, const guint32 alpha)
3x3 matrix representing an affine transformation.
bool can_handle_affine(Geom::Affine const &) const override
Indicate whether the filter primitive can handle the given affine.
std::vector< double > values
virtual void set_values(std::vector< double > const &values)
virtual void set_type(FilterColorMatrixType type)
FilterColorMatrixType type
double complexity(Geom::Affine const &ctm) const override
virtual void set_value(double value)
void render_cairo(FilterSlot &slot) const override
~FilterColorMatrix() override
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
Low level math functions and compatibility wrappers.
void sincos(double angle, double &sin_, double &cos_)
Simultaneously compute a sine and a cosine of the same angle.
@ COLORMATRIX_LUMINANCETOALPHA
Helper class to stream background task notifications as a series of messages.
ColorMatrixMatrix(std::vector< double > const &values)
guint32 operator()(guint32 in) const