[goffice] GOPattern: optimize a bit.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [goffice] GOPattern: optimize a bit.
- Date: Thu, 2 Apr 2015 22:05:37 +0000 (UTC)
commit 2700783d93b54f1ff24d0eb3d13fcca484a69ff9
Author: Morten Welinder <terra gnome org>
Date: Thu Apr 2 18:05:37 2015 -0400
GOPattern: optimize a bit.
ChangeLog | 5 +++++
goffice/utils/go-pattern.c | 39 +++++++++++++++++++++++++--------------
2 files changed, 30 insertions(+), 14 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 64bfcda..efc52da 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2015-04-02 Morten Welinder <terra gnome org>
+
+ * goffice/utils/go-pattern.c (go_pattern_create_cairo_pattern): Do
+ 2 colour translations instead of 64.
+
2015-04-01 Jean Brefort <jean brefort normalesup org>
* goffice/graph/gog-renderer.c (_get_marker_surface),
diff --git a/goffice/utils/go-pattern.c b/goffice/utils/go-pattern.c
index e192ac0..d9d9918 100644
--- a/goffice/utils/go-pattern.c
+++ b/goffice/utils/go-pattern.c
@@ -256,6 +256,20 @@ go_pattern_get_svg_path (GOPattern const *pattern, double *width, double *height
return svg_path;
}
+
+static void
+color_to_data (GOColor color, unsigned char data[4])
+{
+ guint8 a = GO_COLOR_UINT_A (color);
+#define MULT(d,c,a) G_STMT_START { unsigned int t = c * a + 0x7f; d = ((t >> 8) + t) >> 8; } G_STMT_END
+ data[3] = a;
+ MULT (data[0], GO_COLOR_UINT_B (color), a);
+ MULT (data[1], GO_COLOR_UINT_G (color), a);
+ MULT (data[2], GO_COLOR_UINT_R (color), a);
+#undef MULT
+}
+
+
#define SVG_PATTERN_SCALE 2.0
/**
@@ -313,9 +327,10 @@ go_pattern_create_cairo_pattern (GOPattern const *pattern, cairo_t *cr)
cairo_surface_destroy (cr_surface);
#endif
} else {
- unsigned int stride, i, j, t;
+ unsigned int stride, i, j;
unsigned char *iter;
guint8 const *pattern_data;
+ unsigned char data_fore[4], data_back[4];
pattern_data = go_pattern_get_pattern (pattern);
@@ -324,21 +339,17 @@ go_pattern_create_cairo_pattern (GOPattern const *pattern, cairo_t *cr)
stride = cairo_image_surface_get_stride (cr_surface);
iter = cairo_image_surface_get_data (cr_surface);
-#define MULT(d,c,a,t) G_STMT_START { t = c * a + 0x7f; d = ((t >> 8) + t) >> 8; } G_STMT_END
-
- if (iter != NULL) {
- for (i = 0; i < 8; i++) {
- for (j = 0; j < 8; j++) {
- color = pattern_data[i] & (1 << j) ? pattern->fore : pattern->back;
- iter[3] = GO_COLOR_UINT_A (color);
- MULT (iter[0], GO_COLOR_UINT_B (color), iter[3], t);
- MULT (iter[1], GO_COLOR_UINT_G (color), iter[3], t);
- MULT (iter[2], GO_COLOR_UINT_R (color), iter[3], t);
- iter += 4;
- }
- iter += stride - 32;
+ color_to_data (pattern->fore, data_fore);
+ color_to_data (pattern->back, data_back);
+
+ for (i = 0; i < 8; i++) {
+ for (j = 0; j < 8; j++) {
+ memcpy (iter, (pattern_data[i] & (1 << j)) ? data_fore : data_back, 4);
+ iter += 4;
}
+ iter += stride - 32;
}
+
cairo_surface_mark_dirty (cr_surface);
cr_pattern = cairo_pattern_create_for_surface (cr_surface);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]