Skip to content

Commit ecf9267

Browse files
bgo#783835 - Don't divide by zero in box_blur_line() for gaussian blurs
We were making the decision to use box blurs, instead of a true Gaussian kernel, based on the size of *both* x and y dimensions. Do them individually instead.
1 parent 818ad22 commit ecf9267

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

Diff for: rsvg-filter.c

+20-9
Original file line numberDiff line numberDiff line change
@@ -1417,6 +1417,8 @@ box_blur_line (gint box_width, gint even_offset,
14171417
kernel; it's the pixel to remove from the accumulator. */
14181418
gint *ac; /* Accumulator for each channel */
14191419

1420+
g_assert (box_width > 0);
1421+
14201422
ac = g_new0 (gint, bpp);
14211423

14221424
/* The algorithm differs for even and odd-sized kernels.
@@ -1774,7 +1776,6 @@ gaussian_blur_surface (cairo_surface_t *in,
17741776
gdouble sx,
17751777
gdouble sy)
17761778
{
1777-
gboolean use_box_blur;
17781779
gint width, height;
17791780
cairo_format_t in_format, out_format;
17801781
gint in_stride;
@@ -1818,14 +1819,6 @@ gaussian_blur_surface (cairo_surface_t *in,
18181819
if (sy < 0.0)
18191820
sy = 0.0;
18201821

1821-
/* For small radiuses, use a true gaussian kernel; otherwise use three box blurs with
1822-
* clever offsets.
1823-
*/
1824-
if (sx < 10.0 && sy < 10.0)
1825-
use_box_blur = FALSE;
1826-
else
1827-
use_box_blur = TRUE;
1828-
18291822
/* Bail out by just copying? */
18301823
if ((sx == 0.0 && sy == 0.0)
18311824
|| sx > 1000 || sy > 1000) {
@@ -1845,6 +1838,15 @@ gaussian_blur_surface (cairo_surface_t *in,
18451838
int y;
18461839
guchar *row_buffer = NULL;
18471840
guchar *row1, *row2;
1841+
gboolean use_box_blur;
1842+
1843+
/* For small radiuses, use a true gaussian kernel; otherwise use three box blurs with
1844+
* clever offsets.
1845+
*/
1846+
if (sx < 10.0)
1847+
use_box_blur = FALSE;
1848+
else
1849+
use_box_blur = TRUE;
18481850

18491851
if (use_box_blur) {
18501852
box_width = compute_box_blur_width (sx);
@@ -1900,6 +1902,15 @@ gaussian_blur_surface (cairo_surface_t *in,
19001902
guchar *col_buffer;
19011903
guchar *col1, *col2;
19021904
int x;
1905+
gboolean use_box_blur;
1906+
1907+
/* For small radiuses, use a true gaussian kernel; otherwise use three box blurs with
1908+
* clever offsets.
1909+
*/
1910+
if (sy < 10.0)
1911+
use_box_blur = FALSE;
1912+
else
1913+
use_box_blur = TRUE;
19031914

19041915
/* twice the size so we can have the source pixels and the blurred pixels */
19051916
col_buffer = g_new0 (guchar, height * bpp * 2);

0 commit comments

Comments
 (0)