summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSøren Sandmann Pedersen <sandmann@redhat.com>2008-10-06 19:17:06 -0400
committerSøren Sandmann Pedersen <sandmann@redhat.com>2008-10-06 19:17:06 -0400
commit0e663ca0f24a1c9938d7d502434214c2d3374d2a (patch)
tree8fcd54797c34711f3daf6e113153d263f31583fc
parent9b71284f70d2e6b668b997039bda36ad0ba52f07 (diff)
Add Gaussian 5x5 blur
-rw-r--r--downscaling.c54
-rw-r--r--downscaling.ui4
2 files changed, 54 insertions, 4 deletions
diff --git a/downscaling.c b/downscaling.c
index 9a0723b..d0dd3b9 100644
--- a/downscaling.c
+++ b/downscaling.c
@@ -235,10 +235,60 @@ typedef struct
set_filter_func_t set_filter;
} filter_t;
+static pixman_fixed_16_16_t *
+create_gaussian_kernel (int r, int *n_params)
+{
+ pixman_fixed_16_16_t *params;
+ double sigma = r / 2.0;
+ int i, j;
+
+ *n_params = 2 * r + 1;
+ *n_params *= *n_params;
+ *n_params += 2;
+
+ params = g_malloc (*n_params * sizeof (pixman_fixed_16_16_t));
+
+ for (i = -r; i <= r; i++)
+ {
+ for (j = -r; j <= r; j++)
+ {
+ int idx = (i + r) * (2 * r + 1) + j + r + 2;
+
+ double v = (1 / (2 * G_PI * sigma * sigma)) * exp (-(j * j + i * i) / (2 * sigma * sigma));
+
+ g_assert (idx < n_params);
+
+ params[idx] = _cairo_fixed_16_16_from_double (v);
+
+#if 0
+ g_print ("%f ", v);
+#endif
+ }
+
+#if 0
+ g_print ("\n");
+#endif
+ }
+
+ return params;
+}
+
static void
-set_lanczos (pixman_image_t *image, int w, int h)
+set_gaussian (pixman_image_t *image, int w, int h)
{
+ int n_params;
+
+#define RAD 5
+
+ pixman_fixed_16_16_t *params =
+ create_gaussian_kernel (RAD, &n_params);
+
+ params[0] = (RAD * 2 + 1) << 16;
+ params[1] = (RAD * 2 + 1) << 16;
+ pixman_image_set_filter (image, PIXMAN_FILTER_CONVOLUTION, params, n_params);
+
+ g_free (params);
}
static void
@@ -257,7 +307,7 @@ static const filter_t filters[] =
{
{ "nearest", set_nearest },
{ "bilinear", set_bilinear },
- { "lanczos", set_bilinear /* FIXME */ },
+ { "gaussian", set_gaussian /* FIXME */ },
{ NULL },
};
diff --git a/downscaling.ui b/downscaling.ui
index f0a3e2b..397d6a1 100644
--- a/downscaling.ui
+++ b/downscaling.ui
@@ -79,10 +79,10 @@ const char *uidef =
" </packing>" \
" </child>" \
" <child>" \
-" <object class=\"GtkRadioButton\" id=\"lanczos\">" \
+" <object class=\"GtkRadioButton\" id=\"gaussian\">" \
" <property name=\"visible\">True</property>" \
" <property name=\"can_focus\">True</property>" \
-" <property name=\"label\" translatable=\"yes\">Lanczos</property>" \
+" <property name=\"label\" translatable=\"yes\">Gaussian 11 x 11</property>" \
" <property name=\"active\">True</property>" \
" <property name=\"draw_indicator\">True</property>" \
" <property name=\"group\">nearest</property>" \