GRASS GIS 7 Programmer's Manual  7.5.svn(2018)-r72100
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
cairodriver/draw_bitmap.c
Go to the documentation of this file.
1 /*!
2  \file lib/cairodriver/draw_bitmap.c
3 
4  \brief GRASS cairo display driver - draw bitmap
5 
6  (C) 2007-2008 by Lars Ahlzen and the GRASS Development Team
7 
8  This program is free software under the GNU General Public License
9  (>=v2). Read the file COPYING that comes with GRASS for details.
10 
11  \author Lars Ahlzen <lars ahlzen.com> (original contibutor)
12  \author Glynn Clements
13 */
14 
15 #include <grass/glocale.h>
16 
17 #include "cairodriver.h"
18 
19 /*!
20  \brief Draw bitmap
21 
22  \param ncols,nrows number of columns and rows
23  \param threshold threshold value
24  \param buf data buffer
25 */
26 void Cairo_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_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(
44  data, CAIRO_FORMAT_A8, ncols, nrows, stride);
45 
46  if (cairo_surface_status(surf) != CAIRO_STATUS_SUCCESS)
47  G_fatal_error(_("Cairo_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  ca.modified = 1;
57 }
58 
void Cairo_Bitmap(int, int, int, const unsigned char *)
Draw bitmap.
double cur_y
Definition: driver/init.c:33
double cur_x
Definition: driver/init.c:32
struct cairo_state ca
void G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
Definition: gis/error.c:159
void * malloc(YYSIZE_T)
cairo_t * cairo
int G_debug(int level, const char *msg,...)
Print debugging message.
Definition: debug.c:65
GRASS cairo display driver - header file.
#define _(str)
Definition: glocale.h:13