GRASS GIS 8 Programmer's Manual  8.5.0dev(2024)-3f124c5c78
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 contributor)
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, const unsigned char *buf)
27 {
28  cairo_surface_t *surf;
29  int stride;
30  unsigned char *data;
31  int i;
32 
33  G_debug(1, "Cairo_Bitmap: %d %d %d", ncols, nrows, threshold);
34 
35 #if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 5, 8)
36  stride = cairo_format_stride_for_width(CAIRO_FORMAT_A8, ncols);
37 #else
38 #define MULTIPLE 4
39  stride = (ncols + (MULTIPLE - 1)) / MULTIPLE * MULTIPLE;
40 #endif
41  data = malloc(stride * nrows);
42  surf = cairo_image_surface_create_for_data(data, CAIRO_FORMAT_A8, ncols,
43  nrows, stride);
44 
45  if (cairo_surface_status(surf) != CAIRO_STATUS_SUCCESS)
46  G_fatal_error(_("Cairo_Bitmap: Failed to create source"));
47 
48  for (i = 0; i < nrows; i++)
49  memcpy(&data[i * stride], &buf[i * ncols], ncols);
50 
51  cairo_surface_mark_dirty(surf);
52  cairo_mask_surface(cairo, surf, cur_x, cur_y);
53 
54  cairo_surface_destroy(surf);
55  ca.modified = 1;
56 }
void Cairo_Bitmap(int ncols, int nrows, int threshold, const unsigned char *buf)
Draw bitmap.
GRASS cairo display driver - header file.
struct cairo_state ca
cairo_t * cairo
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
int G_debug(int, const char *,...) __attribute__((format(printf
double cur_x
Definition: driver/init.c:32
double cur_y
Definition: driver/init.c:33
#define _(str)
Definition: glocale.h:10
void * malloc(YYSIZE_T)