GRASS Programmer's Manual
6.4.2(2012)
|
00001 00015 #include <grass/glocale.h> 00016 00017 #include "cairodriver.h" 00018 00026 void Cairo_draw_bitmap(int ncols, int nrows, int threshold, 00027 const unsigned char *buf) 00028 { 00029 cairo_surface_t *surf; 00030 int stride; 00031 unsigned char *data; 00032 int i; 00033 00034 G_debug(1, "Cairo_draw_bitmap: %d %d %d", ncols, nrows, threshold); 00035 00036 #if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1,5,8) 00037 stride = cairo_format_stride_for_width(CAIRO_FORMAT_A8, ncols); 00038 #else 00039 #define MULTIPLE 4 00040 stride = (ncols + (MULTIPLE - 1)) / MULTIPLE * MULTIPLE; 00041 #endif 00042 data = malloc(stride * nrows); 00043 surf = cairo_image_surface_create_for_data(data, CAIRO_FORMAT_A8, ncols, 00044 nrows, stride); 00045 00046 if (cairo_surface_status(surf) != CAIRO_STATUS_SUCCESS) 00047 G_fatal_error(_("Cairo_draw_bitmap: Failed to create source")); 00048 00049 for (i = 0; i < nrows; i++) 00050 memcpy(&data[i * stride], &buf[i * ncols], ncols); 00051 00052 cairo_mask_surface(cairo, surf, cur_x, cur_y); 00053 00054 cairo_surface_destroy(surf); 00055 modified = 1; 00056 }