GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
cairodriver/Draw_bitmap.c
Go to the documentation of this file.
1 
15 #include <grass/glocale.h>
16 
17 #include "cairodriver.h"
18 
26 void Cairo_draw_bitmap(int ncols, int nrows, int threshold,
27  const unsigned char *buf)
28 {
29  cairo_surface_t *surf;
30  int stride;
31  unsigned char *data;
32  int i;
33 
34  G_debug(1, "Cairo_draw_bitmap: %d %d %d", ncols, nrows, threshold);
35 
36 #if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1,5,8)
37  stride = cairo_format_stride_for_width(CAIRO_FORMAT_A8, ncols);
38 #else
39 #define MULTIPLE 4
40  stride = (ncols + (MULTIPLE - 1)) / MULTIPLE * MULTIPLE;
41 #endif
42  data = malloc(stride * nrows);
43  surf = cairo_image_surface_create_for_data(data, CAIRO_FORMAT_A8, ncols,
44  nrows, stride);
45 
46  if (cairo_surface_status(surf) != CAIRO_STATUS_SUCCESS)
47  G_fatal_error(_("Cairo_draw_bitmap: Failed to create source"));
48 
49  for (i = 0; i < nrows; i++)
50  memcpy(&data[i * stride], &buf[i * ncols], ncols);
51 
52  cairo_surface_mark_dirty(surf);
53  cairo_mask_surface(cairo, surf, cur_x, cur_y);
54 
55  cairo_surface_destroy(surf);
56  modified = 1;
57 }
int cur_y
Definition: driver/init.c:38
int modified
int stride
tuple data
void * malloc(YYSIZE_T)
cairo_t * cairo
char buf[GNAME_MAX+sizeof(G3D_DIRECTORY)+2]
Definition: g3drange.c:62
int cur_x
Definition: driver/init.c:37
int G_debug(int level, const char *msg,...)
Print debugging message.
Definition: gis/debug.c:51
void Cairo_draw_bitmap(int, int, int, const unsigned char *)
Draw bitmap.
int G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.