[cairo-commit] [cairo-www] 3 commits - src/cookbook src/samples src/todo.mdwn
Nis Martensen
nmartensen at freedesktop.org
Sun Nov 22 12:48:12 PST 2015
src/cookbook/blur.c | 139 ---------------------------------------
src/cookbook/blur.c.mdwn | 139 +++++++++++++++++++++++++++++++++++++++
src/cookbook/xcbsurface.c | 122 ----------------------------------
src/cookbook/xcbsurface.c.mdwn | 122 ++++++++++++++++++++++++++++++++++
src/samples/curve_rectangle.mdwn | 2
src/todo.mdwn | 4 -
6 files changed, 264 insertions(+), 264 deletions(-)
New commits:
commit 93a1eba5b16f33d42d51f5c42ee795ad63f37a31
Author: Lawrence D'Oliveiro <ldo at geek-central.gen.nz>
Date: Sun Nov 22 21:36:51 2015 +1300
replace some links internal to wiki with wikilinks
diff --git a/src/samples/curve_rectangle.mdwn b/src/samples/curve_rectangle.mdwn
index dbf7366..94b851d 100644
--- a/src/samples/curve_rectangle.mdwn
+++ b/src/samples/curve_rectangle.mdwn
@@ -1,4 +1,4 @@
-Unless you know what you are doing, you should probably use [rounded rectangle](/samples/rounded_rectangle) instead.
+Unless you know what you are doing, you should probably use [[rounded rectangle|rounded_rectangle]] instead.
<div class="tutright">[[!img "curve_rectangle.png" link="no"]]</div>
/* a custom shape that could be wrapped in a function */
diff --git a/src/todo.mdwn b/src/todo.mdwn
index 23daaac..398f8bd 100644
--- a/src/todo.mdwn
+++ b/src/todo.mdwn
@@ -94,7 +94,7 @@ Changes that add new API (API changes/removals will not be considered)
* Add projective transform, which is already in pixman. Currently only affine matrix transformations are supported.
-Further comparison of cairo with other vector graphics languages, and in particular features that cairo lacks, can be found in [missing](/missing).
+Further comparison of cairo with other vector graphics languages, and in particular features that cairo lacks, can be found in [[missing]].
Performance improvements
@@ -155,7 +155,7 @@ Performance improvements
A list of pixman projects (a core component for Cairo) is available [here](http://people.freedesktop.org/~sandmann/pixman-projects.html).
-[A list of known performance issues with Cairo](/slow/)
+[[A list of known performance issues with Cairo|slow]]
Other fixes
-----------
commit 6f162fd91be93a2866ef16f09f6c20b7b1febd5e
Author: Lawrence D'Oliveiro <ldo at geek-central.gen.nz>
Date: Thu Nov 19 23:37:49 2015 +0000
convert xcbsurface.c to markdown format
diff --git a/src/cookbook/xcbsurface.c b/src/cookbook/xcbsurface.c
deleted file mode 100644
index 9ea0126..0000000
--- a/src/cookbook/xcbsurface.c
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * Copyright © 2015 Uli Schlachter <psychon at znc.in>
- *
- * Permission to use, copy, modify, distribute, and sell this software and its
- * documentation for any purpose is hereby granted without fee, provided that
- * the above copyright notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting documentation, and
- * that the name of the copyright holders not be used in advertising or
- * publicity pertaining to distribution of the software without specific,
- * written prior permission. The copyright holders make no representations
- * about the suitability of this software for any purpose. It is provided "as
- * is" without express or implied warranty.
- *
- * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
- * OF THIS SOFTWARE.
- *
- * find_visual() is adapted from draw_find_visual() from the Awesome
- * window manager (http://awesome.naquadah.org).
- */
-
-#include <xcb/xcb.h>
-#include <cairo-xcb.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-static xcb_visualtype_t *find_visual(xcb_connection_t *c, xcb_visualid_t visual)
-{
- xcb_screen_iterator_t screen_iter = xcb_setup_roots_iterator(xcb_get_setup(c));
-
- for (; screen_iter.rem; xcb_screen_next(&screen_iter)) {
- xcb_depth_iterator_t depth_iter = xcb_screen_allowed_depths_iterator(screen_iter.data);
- for (; depth_iter.rem; xcb_depth_next(&depth_iter)) {
- xcb_visualtype_iterator_t visual_iter = xcb_depth_visuals_iterator(depth_iter.data);
- for (; visual_iter.rem; xcb_visualtype_next(&visual_iter))
- if (visual == visual_iter.data->visual_id)
- return visual_iter.data;
- }
- }
-
- return NULL;
-}
-
-int main()
-{
- xcb_connection_t *c;
- xcb_screen_t *screen;
- xcb_window_t window;
- uint32_t mask[2];
- xcb_visualtype_t *visual;
- xcb_generic_event_t *event;
- cairo_surface_t *surface;
- cairo_t *cr;
-
- c = xcb_connect(NULL, NULL);
- if (xcb_connection_has_error(c)) {
- fprintf(stderr, "Could not connect to X11 server");
- return 1;
- }
-
- mask[0] = 1;
- mask[1] = XCB_EVENT_MASK_EXPOSURE;
- screen = xcb_setup_roots_iterator(xcb_get_setup(c)).data;
- window = xcb_generate_id(c);
- xcb_create_window(c, XCB_COPY_FROM_PARENT, window, screen->root,
- 20, 20, 150, 150, 0,
- XCB_WINDOW_CLASS_INPUT_OUTPUT,
- screen->root_visual,
- XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK,
- mask);
- xcb_map_window(c, window);
-
- visual = find_visual(c, screen->root_visual);
- if (visual == NULL) {
- fprintf(stderr, "Some weird internal error...?!");
- xcb_disconnect(c);
- return 1;
- }
- surface = cairo_xcb_surface_create(c, window, visual, 150, 150);
- cr = cairo_create(surface);
-
- xcb_flush(c);
- while ((event = xcb_wait_for_event(c))) {
- switch (event->response_type & ~0x80) {
- case XCB_EXPOSE:
- /* Avoid extra redraws by checking if this is
- * the last expose event in the sequence
- */
- if (((xcb_expose_event_t *) event)->count != 0)
- break;
-
- cairo_set_source_rgb(cr, 0, 1, 0);
- cairo_paint(cr);
-
- cairo_set_source_rgb(cr, 1, 0, 0);
- cairo_move_to(cr, 0, 0);
- cairo_line_to(cr, 150, 0);
- cairo_line_to(cr, 150, 150);
- cairo_close_path(cr);
- cairo_fill(cr);
-
- cairo_set_source_rgb(cr, 0, 0, 1);
- cairo_set_line_width(cr, 20);
- cairo_move_to(cr, 0, 150);
- cairo_line_to(cr, 150, 0);
- cairo_stroke(cr);
-
- cairo_surface_flush(surface);
- break;
- }
- free(event);
- xcb_flush(c);
- }
- cairo_surface_finish(surface);
- cairo_surface_destroy(surface);
- xcb_disconnect(c);
- return 0;
-}
diff --git a/src/cookbook/xcbsurface.c.mdwn b/src/cookbook/xcbsurface.c.mdwn
new file mode 100644
index 0000000..7807a0a
--- /dev/null
+++ b/src/cookbook/xcbsurface.c.mdwn
@@ -0,0 +1,122 @@
+ /*
+ * Copyright © 2015 Uli Schlachter <psychon at znc.in>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission. The copyright holders make no representations
+ * about the suitability of this software for any purpose. It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ *
+ * find_visual() is adapted from draw_find_visual() from the Awesome
+ * window manager (http://awesome.naquadah.org).
+ */
+
+ #include <xcb/xcb.h>
+ #include <cairo-xcb.h>
+ #include <stdio.h>
+ #include <stdlib.h>
+
+ static xcb_visualtype_t *find_visual(xcb_connection_t *c, xcb_visualid_t visual)
+ {
+ xcb_screen_iterator_t screen_iter = xcb_setup_roots_iterator(xcb_get_setup(c));
+
+ for (; screen_iter.rem; xcb_screen_next(&screen_iter)) {
+ xcb_depth_iterator_t depth_iter = xcb_screen_allowed_depths_iterator(screen_iter.data);
+ for (; depth_iter.rem; xcb_depth_next(&depth_iter)) {
+ xcb_visualtype_iterator_t visual_iter = xcb_depth_visuals_iterator(depth_iter.data);
+ for (; visual_iter.rem; xcb_visualtype_next(&visual_iter))
+ if (visual == visual_iter.data->visual_id)
+ return visual_iter.data;
+ }
+ }
+
+ return NULL;
+ }
+
+ int main()
+ {
+ xcb_connection_t *c;
+ xcb_screen_t *screen;
+ xcb_window_t window;
+ uint32_t mask[2];
+ xcb_visualtype_t *visual;
+ xcb_generic_event_t *event;
+ cairo_surface_t *surface;
+ cairo_t *cr;
+
+ c = xcb_connect(NULL, NULL);
+ if (xcb_connection_has_error(c)) {
+ fprintf(stderr, "Could not connect to X11 server");
+ return 1;
+ }
+
+ mask[0] = 1;
+ mask[1] = XCB_EVENT_MASK_EXPOSURE;
+ screen = xcb_setup_roots_iterator(xcb_get_setup(c)).data;
+ window = xcb_generate_id(c);
+ xcb_create_window(c, XCB_COPY_FROM_PARENT, window, screen->root,
+ 20, 20, 150, 150, 0,
+ XCB_WINDOW_CLASS_INPUT_OUTPUT,
+ screen->root_visual,
+ XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK,
+ mask);
+ xcb_map_window(c, window);
+
+ visual = find_visual(c, screen->root_visual);
+ if (visual == NULL) {
+ fprintf(stderr, "Some weird internal error...?!");
+ xcb_disconnect(c);
+ return 1;
+ }
+ surface = cairo_xcb_surface_create(c, window, visual, 150, 150);
+ cr = cairo_create(surface);
+
+ xcb_flush(c);
+ while ((event = xcb_wait_for_event(c))) {
+ switch (event->response_type & ~0x80) {
+ case XCB_EXPOSE:
+ /* Avoid extra redraws by checking if this is
+ * the last expose event in the sequence
+ */
+ if (((xcb_expose_event_t *) event)->count != 0)
+ break;
+
+ cairo_set_source_rgb(cr, 0, 1, 0);
+ cairo_paint(cr);
+
+ cairo_set_source_rgb(cr, 1, 0, 0);
+ cairo_move_to(cr, 0, 0);
+ cairo_line_to(cr, 150, 0);
+ cairo_line_to(cr, 150, 150);
+ cairo_close_path(cr);
+ cairo_fill(cr);
+
+ cairo_set_source_rgb(cr, 0, 0, 1);
+ cairo_set_line_width(cr, 20);
+ cairo_move_to(cr, 0, 150);
+ cairo_line_to(cr, 150, 0);
+ cairo_stroke(cr);
+
+ cairo_surface_flush(surface);
+ break;
+ }
+ free(event);
+ xcb_flush(c);
+ }
+ cairo_surface_finish(surface);
+ cairo_surface_destroy(surface);
+ xcb_disconnect(c);
+ return 0;
+ }
commit 735e8269bd29b1c2a69a4f78b4a161210731416f
Author: Lawrence D'Oliveiro <ldo at geek-central.gen.nz>
Date: Thu Nov 19 23:37:20 2015 +0000
convert blur.c to markdown format
diff --git a/src/cookbook/blur.c b/src/cookbook/blur.c
deleted file mode 100644
index 1ed8798..0000000
--- a/src/cookbook/blur.c
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * Copyright © 2008 Kristian Høgsberg
- * Copyright © 2009 Chris Wilson
- *
- * Permission to use, copy, modify, distribute, and sell this software and its
- * documentation for any purpose is hereby granted without fee, provided that
- * the above copyright notice appear in all copies and that both that copyright
- * notice and this permission notice appear in supporting documentation, and
- * that the name of the copyright holders not be used in advertising or
- * publicity pertaining to distribution of the software without specific,
- * written prior permission. The copyright holders make no representations
- * about the suitability of this software for any purpose. It is provided "as
- * is" without express or implied warranty.
- *
- * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
- * OF THIS SOFTWARE.
- */
-
-#include <math.h>
-#include <stdint.h>
-
-#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
-
-/* Performs a simple 2D Gaussian blur of radius @radius on surface @surface. */
-void
-blur_image_surface (cairo_surface_t *surface, int radius)
-{
- cairo_surface_t *tmp;
- int width, height;
- int src_stride, dst_stride;
- int x, y, z, w;
- uint8_t *src, *dst;
- uint32_t *s, *d, a, p;
- int i, j, k;
- uint8_t kernel[17];
- const int size = ARRAY_LENGTH (kernel);
- const int half = size / 2;
-
- if (cairo_surface_status (surface))
- return;
-
- width = cairo_image_surface_get_width (surface);
- height = cairo_image_surface_get_height (surface);
-
- switch (cairo_image_surface_get_format (surface)) {
- case CAIRO_FORMAT_A1:
- default:
- /* Don't even think about it! */
- return;
-
- case CAIRO_FORMAT_A8:
- /* Handle a8 surfaces by effectively unrolling the loops by a
- * factor of 4 - this is safe since we know that stride has to be a
- * multiple of uint32_t. */
- width /= 4;
- break;
-
- case CAIRO_FORMAT_RGB24:
- case CAIRO_FORMAT_ARGB32:
- break;
- }
-
- tmp = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
- if (cairo_surface_status (tmp))
- return;
-
- src = cairo_image_surface_get_data (surface);
- src_stride = cairo_image_surface_get_stride (surface);
-
- dst = cairo_image_surface_get_data (tmp);
- dst_stride = cairo_image_surface_get_stride (tmp);
-
- a = 0;
- for (i = 0; i < size; i++) {
- double f = i - half;
- a += kernel[i] = exp (- f * f / 30.0) * 80;
- }
-
- /* Horizontally blur from surface -> tmp */
- for (i = 0; i < height; i++) {
- s = (uint32_t *) (src + i * src_stride);
- d = (uint32_t *) (dst + i * dst_stride);
- for (j = 0; j < width; j++) {
- if (radius < j && j < width - radius) {
- d[j] = s[j];
- continue;
- }
-
- x = y = z = w = 0;
- for (k = 0; k < size; k++) {
- if (j - half + k < 0 || j - half + k >= width)
- continue;
-
- p = s[j - half + k];
-
- x += ((p >> 24) & 0xff) * kernel[k];
- y += ((p >> 16) & 0xff) * kernel[k];
- z += ((p >> 8) & 0xff) * kernel[k];
- w += ((p >> 0) & 0xff) * kernel[k];
- }
- d[j] = (x / a << 24) | (y / a << 16) | (z / a << 8) | w / a;
- }
- }
-
- /* Then vertically blur from tmp -> surface */
- for (i = 0; i < height; i++) {
- s = (uint32_t *) (dst + i * dst_stride);
- d = (uint32_t *) (src + i * src_stride);
- for (j = 0; j < width; j++) {
- if (radius <= i && i < height - radius) {
- d[j] = s[j];
- continue;
- }
-
- x = y = z = w = 0;
- for (k = 0; k < size; k++) {
- if (i - half + k < 0 || i - half + k >= height)
- continue;
-
- s = (uint32_t *) (dst + (i - half + k) * dst_stride);
- p = s[j];
-
- x += ((p >> 24) & 0xff) * kernel[k];
- y += ((p >> 16) & 0xff) * kernel[k];
- z += ((p >> 8) & 0xff) * kernel[k];
- w += ((p >> 0) & 0xff) * kernel[k];
- }
- d[j] = (x / a << 24) | (y / a << 16) | (z / a << 8) | w / a;
- }
- }
-
- cairo_surface_destroy (tmp);
- cairo_surface_mark_dirty (surface);
-}
diff --git a/src/cookbook/blur.c.mdwn b/src/cookbook/blur.c.mdwn
new file mode 100644
index 0000000..904efab
--- /dev/null
+++ b/src/cookbook/blur.c.mdwn
@@ -0,0 +1,139 @@
+ /*
+ * Copyright © 2008 Kristian Høgsberg
+ * Copyright © 2009 Chris Wilson
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission. The copyright holders make no representations
+ * about the suitability of this software for any purpose. It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
+
+ #include <math.h>
+ #include <stdint.h>
+
+ #define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
+
+ /* Performs a simple 2D Gaussian blur of radius @radius on surface @surface. */
+ void
+ blur_image_surface (cairo_surface_t *surface, int radius)
+ {
+ cairo_surface_t *tmp;
+ int width, height;
+ int src_stride, dst_stride;
+ int x, y, z, w;
+ uint8_t *src, *dst;
+ uint32_t *s, *d, a, p;
+ int i, j, k;
+ uint8_t kernel[17];
+ const int size = ARRAY_LENGTH (kernel);
+ const int half = size / 2;
+
+ if (cairo_surface_status (surface))
+ return;
+
+ width = cairo_image_surface_get_width (surface);
+ height = cairo_image_surface_get_height (surface);
+
+ switch (cairo_image_surface_get_format (surface)) {
+ case CAIRO_FORMAT_A1:
+ default:
+ /* Don't even think about it! */
+ return;
+
+ case CAIRO_FORMAT_A8:
+ /* Handle a8 surfaces by effectively unrolling the loops by a
+ * factor of 4 - this is safe since we know that stride has to be a
+ * multiple of uint32_t. */
+ width /= 4;
+ break;
+
+ case CAIRO_FORMAT_RGB24:
+ case CAIRO_FORMAT_ARGB32:
+ break;
+ }
+
+ tmp = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
+ if (cairo_surface_status (tmp))
+ return;
+
+ src = cairo_image_surface_get_data (surface);
+ src_stride = cairo_image_surface_get_stride (surface);
+
+ dst = cairo_image_surface_get_data (tmp);
+ dst_stride = cairo_image_surface_get_stride (tmp);
+
+ a = 0;
+ for (i = 0; i < size; i++) {
+ double f = i - half;
+ a += kernel[i] = exp (- f * f / 30.0) * 80;
+ }
+
+ /* Horizontally blur from surface -> tmp */
+ for (i = 0; i < height; i++) {
+ s = (uint32_t *) (src + i * src_stride);
+ d = (uint32_t *) (dst + i * dst_stride);
+ for (j = 0; j < width; j++) {
+ if (radius < j && j < width - radius) {
+ d[j] = s[j];
+ continue;
+ }
+
+ x = y = z = w = 0;
+ for (k = 0; k < size; k++) {
+ if (j - half + k < 0 || j - half + k >= width)
+ continue;
+
+ p = s[j - half + k];
+
+ x += ((p >> 24) & 0xff) * kernel[k];
+ y += ((p >> 16) & 0xff) * kernel[k];
+ z += ((p >> 8) & 0xff) * kernel[k];
+ w += ((p >> 0) & 0xff) * kernel[k];
+ }
+ d[j] = (x / a << 24) | (y / a << 16) | (z / a << 8) | w / a;
+ }
+ }
+
+ /* Then vertically blur from tmp -> surface */
+ for (i = 0; i < height; i++) {
+ s = (uint32_t *) (dst + i * dst_stride);
+ d = (uint32_t *) (src + i * src_stride);
+ for (j = 0; j < width; j++) {
+ if (radius <= i && i < height - radius) {
+ d[j] = s[j];
+ continue;
+ }
+
+ x = y = z = w = 0;
+ for (k = 0; k < size; k++) {
+ if (i - half + k < 0 || i - half + k >= height)
+ continue;
+
+ s = (uint32_t *) (dst + (i - half + k) * dst_stride);
+ p = s[j];
+
+ x += ((p >> 24) & 0xff) * kernel[k];
+ y += ((p >> 16) & 0xff) * kernel[k];
+ z += ((p >> 8) & 0xff) * kernel[k];
+ w += ((p >> 0) & 0xff) * kernel[k];
+ }
+ d[j] = (x / a << 24) | (y / a << 16) | (z / a << 8) | w / a;
+ }
+ }
+
+ cairo_surface_destroy (tmp);
+ cairo_surface_mark_dirty (surface);
+ }
More information about the cairo-commit
mailing list