PATCH cairo-www: Convert A Couple Of C Source Files To Markdown Format
Lawrence D'Oliveiro <[email protected]>
| Newsgroups | gmane.comp.lib.cairo |
|---|---|
| Organization | Geek Central |
| Message-ID | <[email protected]> |
A couple of the wiki pages are actually C source files. When you follow the link in a browser, it may ask if you want to download them, rather than letting you view them. It seems to me better if these pages were in Markdown format, so they can be viewed directly in the browser, just like any of the other source code examples. -- cairo mailing list [email protected] http://lists.cairographics.org/mailman/listinfo/cairo
0001-convert-blur.c-to-markdown-format.patch
(text/x-patch, 10 KB)
From 5d5792a08bbd62537ccdbfb10773f9ece5b793a5 Mon Sep 17 00:00:00 2001 From: Lawrence D'Oliveiro <[email protected]> Date: Thu, 19 Nov 2015 23:37:20 +0000 Subject: [PATCH 1/2] convert blur.c to markdown format --- src/cookbook/blur.c | 139 ----------------------------------------------- src/cookbook/blur.c.mdwn | 139 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 139 insertions(+), 139 deletions(-) delete mode 100644 src/cookbook/blur.c create mode 100644 src/cookbook/blur.c.mdwn 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); + } -- 2.6.0
0002-convert-xcbsurface.c-to-markdown-format.patch
(text/x-patch, 9.5 KB)
From 8950af26dac41628b10fd2b99eaa708acfec75ca Mon Sep 17 00:00:00 2001 From: Lawrence D'Oliveiro <[email protected]> Date: Thu, 19 Nov 2015 23:37:49 +0000 Subject: [PATCH 2/2] convert xcbsurface.c to markdown format --- src/cookbook/xcbsurface.c | 122 ----------------------------------------- src/cookbook/xcbsurface.c.mdwn | 122 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 122 insertions(+), 122 deletions(-) delete mode 100644 src/cookbook/xcbsurface.c create mode 100644 src/cookbook/xcbsurface.c.mdwn 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 <[email protected]> - * - * 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 <[email protected]> + * + * 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; + } -- 2.6.0