GRASS Programmer's Manual  6.4.2(2012)
 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_mask_surface(cairo, surf, cur_x, cur_y);
53 
54  cairo_surface_destroy(surf);
55  modified = 1;
56 }