[sapwood] remove code duplication across the cropping code
- From: Sven Herzberg <herzi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [sapwood] remove code duplication across the cropping code
- Date: Fri, 13 Aug 2010 11:40:36 +0000 (UTC)
commit 667efa14d1a429a0d769d7e8ca9478e9fa8d97d2
Author: Sven Herzberg <herzi gnome-de org>
Date: Fri Aug 13 10:29:56 2010 +0200
remove code duplication across the cropping code
* engine/sapwood-pixmap.c: remove the code duplication across the
cropping code
engine/sapwood-pixmap.c | 105 ++++++++++++++++++++++------------------------
1 files changed, 50 insertions(+), 55 deletions(-)
---
diff --git a/engine/sapwood-pixmap.c b/engine/sapwood-pixmap.c
index f06c0fb..3bccb3b 100644
--- a/engine/sapwood-pixmap.c
+++ b/engine/sapwood-pixmap.c
@@ -386,46 +386,40 @@ sapwood_pixmap_render_rects_internal (SapwoodPixmap* self,
}
static void
-sapwood_crop_pixmap (cairo_surface_t* surface,
- cairo_surface_t* mask,
- int requested_width,
- int requested_height,
- int original_width,
- int original_height)
+sapwood_crop_single_dimension (cairo_surface_t* surface,
+ int x,
+ int y,
+ int width,
+ int height,
+ int displace_x,
+ int displace_y)
{
cairo_t* cr = cairo_create (surface);
-
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
+ cairo_set_source_surface (cr, surface, displace_x, displace_y);
+ cairo_rectangle (cr, x, y, width, height);
+ cairo_fill (cr);
+ cairo_destroy (cr);
+}
+
+static void
+sapwood_crop_single_surface (cairo_surface_t* surface,
+ int requested_width,
+ int requested_height,
+ int original_width,
+ int original_height)
+{
+ cairo_t* cr = cairo_create (surface);
- /* crop horizontally */
if (requested_width < original_width)
{
- int left = requested_width / 2;
- int right = requested_width - left;
-
- /* left -- remains as it is */
-
- /* right */
- cairo_save (cr);
- cairo_set_source_surface (cr, surface, -(original_width - requested_width), 0);
- cairo_rectangle (cr, left, 0, right, MAX (original_height, requested_height));
- cairo_clip (cr);
-
- cairo_paint (cr);
-
- if (mask)
- {
- cairo_t* tmp_cr = cairo_create (mask);
-
- /* adjust the bitmap */
- cairo_set_source_surface (tmp_cr, cairo_get_target (tmp_cr), -(original_width - requested_width), 0);
- cairo_set_operator (tmp_cr, CAIRO_OPERATOR_SOURCE);
- cairo_rectangle (tmp_cr, left, 0, right, MAX (original_height, requested_height));
- cairo_fill (tmp_cr);
+ int left = requested_width / 2;
+ int right = requested_width - left;
- cairo_destroy (tmp_cr);
- }
- cairo_restore (cr);
+ sapwood_crop_single_dimension (surface,
+ left, 0,
+ right, MAX (original_height, requested_height),
+ requested_width - original_width, 0);
}
if (requested_height < original_height)
@@ -433,32 +427,33 @@ sapwood_crop_pixmap (cairo_surface_t* surface,
int top = requested_height / 2;
int bottom = requested_height - top;
- /* top -- remains as it is */
-
- /* bottom */
- cairo_save (cr);
- cairo_set_source_surface (cr, surface, 0, -(original_height - requested_height));
- cairo_rectangle (cr, 0, top, MAX (original_width, requested_width), bottom);
- cairo_clip (cr);
-
- cairo_paint (cr);
+ sapwood_crop_single_dimension (surface,
+ 0, top,
+ MAX (original_width, requested_width), bottom,
+ 0, requested_height - original_height);
+ }
- if (mask)
- {
- cairo_t* tmp_cr = cairo_create (mask);
+ cairo_destroy (cr);
+}
- /* adjust the bitmap */
- cairo_set_source_surface (tmp_cr, cairo_get_target (tmp_cr), 0, -(original_height - requested_height));
- cairo_set_operator (tmp_cr, CAIRO_OPERATOR_SOURCE);
- cairo_rectangle (tmp_cr, 0, top, MAX (original_width, requested_width), bottom);
- cairo_fill (tmp_cr);
+static void /* FIXME: consider renaming to sapwood_crop_surfaces() */
+sapwood_crop_pixmap (cairo_surface_t* surface,
+ cairo_surface_t* mask,
+ int requested_width,
+ int requested_height,
+ int original_width,
+ int original_height)
+{
+ sapwood_crop_single_surface (surface,
+ requested_width, requested_height,
+ original_width, original_height);
- cairo_destroy (tmp_cr);
- }
- cairo_restore (cr);
+ if (mask)
+ {
+ sapwood_crop_single_surface (mask,
+ requested_width, requested_height,
+ original_width, original_height);
}
-
- cairo_destroy (cr);
}
void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]