GRASS GIS 7 Programmer's Manual
7.8.4(2020)-exported
|
Go to the documentation of this file.
17 #if CAIRO_HAS_PS_SURFACE
20 #if CAIRO_HAS_PDF_SURFACE
21 #include <cairo-pdf.h>
23 #if CAIRO_HAS_SVG_SURFACE
24 #include <cairo-svg.h>
26 #if CAIRO_HAS_XLIB_XRENDER_SURFACE
27 #include <cairo-xlib.h>
28 #include <cairo-xlib-xrender.h>
34 #include <sys/types.h>
39 #include <grass/colors.h>
40 #include <grass/glocale.h>
48 static void init_cairo(
void);
49 static int ends_with(
const char *
string,
const char *suffix);
50 static void map_file(
void);
52 static void init_xlib(
void)
54 #if CAIRO_HAS_XLIB_XRENDER_SURFACE
63 cairo_surface_t *s1, *s2;
65 ca.dpy = XOpenDisplay(
NULL);
69 p = getenv(
"GRASS_RENDER_CAIRO_SCREEN");
70 if (!p || sscanf(p,
"%i", &scrn) != 1) {
71 G_debug(1,
"cairo: GRASS_RENDER_CAIRO_SCREEN=%s", p);
72 scrn = DefaultScreen(
ca.dpy);
75 p = getenv(
"GRASS_RENDER_CAIRO_VISUAL");
76 if (!p || sscanf(p,
"%li", &xid) != 1) {
77 G_debug(1,
"cairo: GRASS_RENDER_CAIRO_VISUAL=%s", p);
78 xid = DefaultVisual(
ca.dpy, scrn)->visualid;
83 vinfo = XGetVisualInfo(
ca.dpy, VisualIDMask|VisualScreenMask, &templ, &
count);
86 visual = vinfo[0].visual;
88 ca.screen = ScreenOfDisplay(
ca.dpy, scrn);
89 pix = XCreatePixmap(
ca.dpy, RootWindow(
ca.dpy, scrn), 1, 1, vinfo[0].depth);
90 s1 = cairo_xlib_surface_create(
ca.dpy, pix, visual, 1, 1);
91 s2 = cairo_surface_create_similar(s1, CAIRO_CONTENT_COLOR_ALPHA, 1, 1);
92 ca.format = cairo_xlib_surface_get_xrender_format(s2);
93 ca.depth = cairo_xlib_surface_get_depth(s2);
94 cairo_surface_destroy(s2);
95 cairo_surface_destroy(s1);
96 XFreePixmap(
ca.dpy, pix);
99 ca.win = XCreatePixmap(
100 ca.dpy, RootWindow(
ca.dpy, scrn),
105 static void fini_xlib(
void)
107 #if CAIRO_HAS_XLIB_XRENDER_SURFACE
108 XSetCloseDownMode(
ca.dpy, RetainTemporary);
109 XCloseDisplay(
ca.dpy);
113 static void init_file(
void)
127 p = getenv(
"GRASS_RENDER_FILE");
128 if (!p || strlen(p) == 0)
130 G_debug(1,
"cairo: GRASS_RENDER_FILE=%s", p);
139 #if CAIRO_HAS_PNG_FUNCTIONS
143 #if CAIRO_HAS_PDF_SURFACE
147 #if CAIRO_HAS_PS_SURFACE
151 #if CAIRO_HAS_SVG_SURFACE
155 #if CAIRO_HAS_XLIB_XRENDER_SURFACE
174 p = getenv(
"GRASS_RENDER_FILE_MAPPED");
175 do_map = p && strcmp(p,
"TRUE") == 0 && ends_with(
ca.
file_name,
".bmp");
176 G_debug(1,
"cairo: GRASS_RENDER_FILE_MAPPED=%d", do_map);
178 p = getenv(
"GRASS_RENDER_FILE_READ");
179 do_read = p && strcmp(p,
"TRUE") == 0;
180 G_debug(1,
"cairo: GRASS_RENDER_FILE_READ=%d", do_read);
183 do_read = do_map = 0;
195 if (do_read && do_map)
198 #if CAIRO_HAS_XLIB_XRENDER_SURFACE
214 if (!do_read && !is_vector) {
238 cairo_antialias_t antialias;
241 G_gisinit(
"Cairo driver");
244 p = getenv(
"GRASS_RENDER_BACKGROUNDCOLOR");
246 unsigned int red, green, blue;
248 if (sscanf(p,
"%02x%02x%02x", &red, &green, &blue) == 3 ||
249 G_str_to_color(p, (
int *)&red, (
int *)&green, (
int *)&blue) == 1) {
256 G_debug(1,
"cairo: GRASS_RENDER_BACKGROUNDCOLOR=%s", p);
262 p = getenv(
"GRASS_RENDER_TRANSPARENT");
263 if (p && strcmp(p,
"TRUE") == 0)
267 G_debug(1,
"cairo: GRASS_RENDER_TRANSPARENT=%s", p ? p :
"FALSE");
269 antialias = CAIRO_ANTIALIAS_DEFAULT;
270 p = getenv(
"GRASS_RENDER_ANTIALIAS");
272 antialias = CAIRO_ANTIALIAS_DEFAULT;
274 antialias = CAIRO_ANTIALIAS_NONE;
276 antialias = CAIRO_ANTIALIAS_GRAY;
278 antialias = CAIRO_ANTIALIAS_SUBPIXEL;
279 G_debug(1,
"cairo: GRASS_RENDER_ANTIALIAS=%s", p ? p :
"FALSE");
283 cairo_set_antialias(
cairo, antialias);
303 G_debug(1,
"Cairo_Graph_close");
305 #if CAIRO_HAS_XLIB_XRENDER_SURFACE
307 XFlush(cairo_xlib_surface_get_display(
surface));
315 cairo_destroy(
cairo);
319 cairo_surface_destroy(
surface);
323 #if CAIRO_HAS_XLIB_XRENDER_SURFACE
329 static void init_cairo(
void)
339 (cairo_surface_t *) cairo_image_surface_create_for_data(
342 #if CAIRO_HAS_PDF_SURFACE
345 (cairo_surface_t *) cairo_pdf_surface_create(
349 #if CAIRO_HAS_PS_SURFACE
352 (cairo_surface_t *) cairo_ps_surface_create(
356 #if CAIRO_HAS_SVG_SURFACE
359 (cairo_surface_t *) cairo_svg_surface_create(
363 #if CAIRO_HAS_XLIB_XRENDER_SURFACE
366 (cairo_surface_t *) cairo_xlib_surface_create_with_xrender_format(
375 if (cairo_surface_status(
surface) != CAIRO_STATUS_SUCCESS)
382 static int ends_with(
const char *
string,
const char *suffix)
384 if (strlen(
string) < strlen(suffix))
388 string + strlen(
string) - strlen(suffix)) == 0;
391 static void map_file(
void)
402 ptr = mmap(
NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, (off_t) 0);
403 if (ptr == MAP_FAILED)
407 cairo_destroy(
cairo);
408 cairo_surface_destroy(
surface);
N_array_2d * N_read_rast_to_array_2d(char *name, N_array_2d *array)
Read a raster map into a N_array_2d structure.
FCELL N_get_array_2d_f_value(N_array_2d *data, int col, int row)
Returns the value of type FCELL at position col, row.
void N_put_array_3d_d_value(N_array_3d *data, int col, int row, int depth, double value)
Writes a double value to the N_array_3d struct at position col, row, depth.
void N_print_array_2d(N_array_2d *data)
Write info and content of the N_array_2d struct to stdout.
N_array_2d * N_math_array_2d(N_array_2d *a, N_array_2d *b, N_array_2d *result, int type)
Perform calculations with two input arrays, the result is written to a third array.
N_data_star * N_create_5star(double C, double W, double E, double N, double S, double V)
allocate and initialize a 5 point star data structure
void Cairo_Erase(void)
Erase screen.
Geometric information about the structured grid.
int G_strcasecmp(const char *x, const char *y)
String compare ignoring case (upper or lower)
N_data_star * N_alloc_7star(void)
allocate a 7 point star data structure
void G_verbose_message(const char *msg,...)
Print a message to stderr but only if module is in verbose mode.
#define DEFAULT_FILE_NAME
N_les_callback_2d * N_alloc_les_callback_2d(void)
Allocate the structure holding the callback function.
void N_put_array_3d_value(N_array_3d *data, int col, int row, int depth, char *value)
This function writes a value to the N_array_3d data at position col, row, depth.
N_data_star * N_alloc_5star(void)
allocate a 5 point star data structure
callback structure for 2d matrix assembling
N_data_star * N_create_9star(double C, double W, double E, double N, double S, double NW, double SW, double NE, double SE, double V)
allocate and initialize a 9 point star data structure
int N_convert_array_3d_null_to_zero(N_array_3d *a)
Convert all null values to zero values.
void N_free_array_2d(N_array_2d *data)
Release the memory of a N_array_2d structure.
void N_put_array_2d_c_value(N_array_2d *data, int col, int row, CELL value)
Writes a CELL value to the N_array_2d struct at position col, row.
double N_norm_array_2d(N_array_2d *a, N_array_2d *b, int type)
Calculate the norm of the two input arrays.
void G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
void N_copy_array_3d(N_array_3d *source, N_array_3d *target)
Copy the source N_array_3d struct to the target N_array_3d struct.
N_les_callback_3d * N_alloc_les_callback_3d(void)
Allocate the structure holding the callback function.
int G_str_to_color(const char *str, int *red, int *grn, int *blu)
Parse color string and set red,green,blue.
void Cairo_Graph_close(void)
Close driver.
N_geom_data * N_init_geom_data_2d(struct Cell_head *region, N_geom_data *geodata)
Initiate a pde geometry data structure with a 2d region.
void N_print_array_3d(N_array_3d *data)
Write info and content of the array data to stdout.
void N_copy_array_2d(N_array_2d *source, N_array_2d *target)
Copy the source N_array_2d struct to the target N_array_2d struct.
N_les * N_assemble_les_3d(int les_type, N_geom_data *geom, N_array_3d *status, N_array_3d *start_val, void *data, N_les_callback_3d *call)
Assemble a linear equation system (les) based on 3d location data (g3d) active cells.
void N_free_array_3d(N_array_3d *data)
Release the memory of a N_array_3d.
int N_get_array_3d_type(N_array_3d *array)
Return the data type of the N_array_3d.
float N_get_array_3d_f_value(N_array_3d *data, int col, int row, int depth)
This function returns the value of type float at position col, row, depth.
void N_put_array_2d_f_value(N_array_2d *data, int col, int row, FCELL value)
Writes a FCELL value to the N_array_2d struct at position col, row.
double N_get_array_3d_d_value(N_array_3d *data, int col, int row, int depth)
This function returns the value of type float at position col, row, depth.
N_array_3d * N_math_array_3d(N_array_3d *a, N_array_3d *b, N_array_3d *result, int type)
Perform calculations with two input arrays, the result is written to a third array.
void N_set_les_callback_2d_func(N_les_callback_2d *data, N_data_star *(*callback_func_2d)())
Set the callback function which is called while assembling the les in 2d.
void N_get_array_3d_value(N_array_3d *data, int col, int row, int depth, void *value)
This function writes the value of N_array_3d data at position col, row, depth to the variable value.
N_data_star * N_create_7star(double C, double W, double E, double N, double S, double T, double B, double V)
allocate and initialize a 7 point star data structure
void N_put_array_3d_f_value(N_array_3d *data, int col, int row, int depth, float value)
This function writes a float value to the N_array_3d data at position col, row, depth.
void G_free(void *buf)
Free allocated memory.
void cairo_read_xid(void)
This data structure contains all data needed to compute the groundwater mass balance in two dimension...
int N_convert_array_2d_null_to_zero(N_array_2d *a)
Convert all null values to zero values.
N_data_star * N_callback_template_3d(void *data, N_geom_data *geom, int col, int row, int depth)
A callback template creates a 7 point star structure.
N_data_star * N_alloc_9star(void)
allocate a 9 point star data structure
Matrix entries for a mass balance 5/7/9 star system.
CELL N_get_array_2d_c_value(N_array_2d *data, int col, int row)
Returns the value of type CELL at position col, row.
int main(int argc, char *argv[])
void cairo_read_image(void)
void N_write_array_2d_to_rast(N_array_2d *array, char *name)
Write a N_array_2d struct to a raster map.
double N_norm_array_3d(N_array_3d *a, N_array_3d *b, int type)
Calculate the norm of the two input arrays.
void N_set_les_callback_3d_func(N_les_callback_3d *data, N_data_star *(*callback_func_3d)())
Set the callback function which is called while assembling the les in 3d.
callback structure for 3d matrix assembling
N_data_star * N_callback_gwflow_2d(void *gwdata, N_geom_data *geom, int col, int row)
This callback function creates the mass balance of a 5 point star.
void G_get_set_window(struct Cell_head *window)
Get the current working window (region)
GRASS cairo display driver - header file.
void cairo_write_image(void)
N_array_3d * N_read_rast3d_to_array_3d(char *name, N_array_3d *array, int mask)
Read a volume map into a N_array_3d structure.
int G_debug(int level, const char *msg,...)
Print debugging message.
int N_get_array_2d_type(N_array_2d *array)
Return the data type of the N_array_2d struct.
void N_put_array_2d_value(N_array_2d *data, int col, int row, char *value)
Writes a value to the N_array_2d struct at position col, row.
cairo_surface_t * surface
void N_free_geom_data(N_geom_data *geom)
Release memory of a pde geometry data structure.
N_gwflow_data2d * N_alloc_gwflow_data2d(int cols, int rows, int river, int drain)
Alllocate memory for the groundwater calculation data structure in 2 dimensions.
void N_write_array_3d_to_rast3d(N_array_3d *array, char *name, int mask)
Write a N_array_3d struct to a volume map.
N_data_star * N_callback_template_2d(void *data, N_geom_data *geom, int col, int row)
A callback template creates a 9 point star structure.
N_array_3d * N_alloc_array_3d(int cols, int rows, int depths, int offset, int type)
Allocate memory for a N_array_3d data structure.
void N_free_les(N_les *les)
Release the memory of the linear equation system.
void N_free_gwflow_data2d(N_gwflow_data2d *data)
Release the memory of the groundwater flow data structure in two dimensions.
int Cairo_Graph_set(void)
Initialize driver.
N_array_2d * N_alloc_array_2d(int cols, int rows, int offset, int type)
Allocate memory for a N_array_2d data structure.
void N_put_array_2d_d_value(N_array_2d *data, int col, int row, DCELL value)
Writes a DCELL value to the N_array_2d struct at position col, row.
The linear equation system (les) structure.
N_les * N_assemble_les_2d(int les_type, N_geom_data *geom, N_array_2d *status, N_array_2d *start_val, void *data, N_les_callback_2d *call)
Assemble a linear equation system (les) based on 2d location data (raster) and active cells.
DCELL N_get_array_2d_d_value(N_array_2d *data, int col, int row)
Returns the value of type DCELL at position col, row.
void N_get_array_2d_value(N_array_2d *data, int col, int row, void *value)
Write the value of the N_array_2d struct at position col, row to value.
const char * Cairo_Graph_get_file(void)
Get render file.