GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
cairodriver/Raster.c
Go to the documentation of this file.
1 #include "cairodriver.h"
2 
3 static int src_t, src_b, src_l, src_r, src_w, src_h;
4 static int dst_t, dst_b, dst_l, dst_r, dst_w, dst_h;
5 
6 static cairo_surface_t *src_surf;
7 static unsigned char *src_data;
8 static int src_stride;
9 
10 static int masked;
11 
12 void Cairo_begin_scaled_raster(int mask, int s[2][2], int d[2][2])
13 {
14  G_debug(1, "Cairo_begin_scaled_raster: %d %d %d %d %d %d %d %d %d",
15  mask, s[0][0], s[0][1], s[1][0], s[1][1], d[0][0], d[0][1],
16  d[1][0], d[1][1]);
17 
18  masked = mask;
19 
20  /* TODO: are top and left swapped? */
21 
22  src_l = s[0][0];
23  src_r = s[0][1];
24  src_t = s[1][0];
25  src_b = s[1][1];
26 
27  src_w = src_r - src_l;
28  src_h = src_b - src_t;
29 
30  dst_l = d[0][0];
31  dst_r = d[0][1];
32  dst_t = d[1][0];
33  dst_b = d[1][1];
34 
35  dst_w = dst_r - dst_l;
36  dst_h = dst_b - dst_t;
37 
38  G_debug(1, " src (TBLR): %d %d %d %d, dst (TBLR) %d %d %d %d",
39  src_t, src_b, src_l, src_r, dst_t, dst_b, dst_l, dst_r);
40 
41  /* create source surface */
42  src_surf = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, src_w, src_h);
43  if (cairo_surface_status(src_surf) != CAIRO_STATUS_SUCCESS)
44  G_fatal_error("Cairo_begin_scaled_raster: Failed to create surface");
45 
46  src_data = cairo_image_surface_get_data(src_surf);
47  src_stride = cairo_image_surface_get_stride(src_surf);
48 }
49 
50 int Cairo_scaled_raster(int n, int row,
51  const unsigned char *red, const unsigned char *grn,
52  const unsigned char *blu, const unsigned char *nul)
53 {
54  unsigned int *dst =
55  (unsigned int *)(src_data + (row - src_t) * src_stride);
56  int i;
57 
58  G_debug(3, "Cairo_scaled_raster: %d %d", n, row);
59 
60  for (i = 0; i < n; i++) {
61  if (masked && nul && nul[i])
62  *dst++ = 0;
63  else {
64  unsigned int r = red[i];
65  unsigned int g = grn[i];
66  unsigned int b = blu[i];
67  unsigned int a = 0xFF;
68 
69  *dst++ = (a << 24) + (r << 16) + (g << 8) + (b << 0);
70  }
71  }
72 
73  return row + 1;
74 }
75 
77 {
78  G_debug(1, "Cairo_end_scaled_raster");
79 
80  /* paint source surface onto dstination (scaled) */
81  cairo_save(cairo);
82  cairo_translate(cairo, dst_l, dst_t);
83  cairo_scale(cairo, (double)dst_w / (double)src_w,
84  (double)dst_h / (double)src_h);
85  cairo_surface_mark_dirty(src_surf);
86  cairo_set_source_surface(cairo, src_surf, 0, 0);
87  cairo_paint(cairo);
88  cairo_restore(cairo);
89 
90  /* cleanup */
91  cairo_surface_destroy(src_surf);
92  modified = 1;
93 }
float b
Definition: named_colr.c:8
int modified
float r
Definition: named_colr.c:8
void Cairo_begin_scaled_raster(int, int[2][2], int[2][2])
cairo_t * cairo
float g
Definition: named_colr.c:8
int Cairo_scaled_raster(int, int, const unsigned char *, const unsigned char *, const unsigned char *, const unsigned char *)
void Cairo_end_scaled_raster(void)
int G_debug(int level, const char *msg,...)
Print debugging message.
Definition: gis/debug.c:51
int G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
int n
Definition: dataquad.c:291