summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSøren Sandmann Pedersen <sandmann@redhat.com>2008-10-06 20:12:12 -0400
committerSøren Sandmann Pedersen <sandmann@redhat.com>2008-10-06 20:12:12 -0400
commitcf760a1f37bb91435d252cd776f556081268932a (patch)
treedee90a36ac3da0e7e9e2001f0f5178f8d86fc91d
parentb278f6d14672ca825527051e908f7f0be81a0d75 (diff)
Implement box filter
-rw-r--r--downscaling.c33
1 files changed, 32 insertions, 1 deletions
diff --git a/downscaling.c b/downscaling.c
index 1d96fe6..2dadb09 100644
--- a/downscaling.c
+++ b/downscaling.c
@@ -313,7 +313,38 @@ set_lanczos (pixman_image_t *image, int w, int h, double scale)
static void
set_box (pixman_image_t *image, int w, int h, double scale)
{
- g_error ("Box filter is not implemented yet");
+ if (scale < 1.0)
+ {
+ int size = (1.0 / scale + 0.5);
+ int n_params = size * size + 2;
+ pixman_fixed_16_16_t *params = g_malloc (n_params * sizeof (pixman_fixed_16_16_t));
+ int i, j;
+
+ params[0] = size << 16;
+ params[1] = size << 16;
+
+ g_print ("size of box: %d\n", size);
+
+ for (i = 0; i < size; ++i)
+ {
+ for (j = 0; j < size; ++j)
+ {
+ int idx = i * size + j + 2;
+
+ g_assert (idx < n_params);
+
+ params[idx] = _cairo_fixed_16_16_from_double (1.0 / (size * size));
+ }
+ }
+
+ pixman_image_set_filter (image, PIXMAN_FILTER_CONVOLUTION, params, n_params);
+
+ g_free (params);
+ }
+ else
+ {
+ pixman_image_set_filter (image, PIXMAN_FILTER_NEAREST, NULL, 0);
+ }
}
static void