21 #define MAX_IMAGE_SIZE 32767 23 static int src_t, src_b, src_l, src_r, src_w, src_h;
24 static int dst_t, dst_b, dst_l, dst_r, dst_w, dst_h;
28 static cairo_surface_t *src_surf;
29 static unsigned char *src_data;
30 static int src_stride, ca_row;
34 static double scale(
double k,
int src_0,
int src_1,
int dst_0,
int dst_1)
36 return dst_0 + (double) (k - src_0) * (dst_1 - dst_0) / (src_1 - src_0);
39 static int scale_fwd_y(
int sy)
41 return (
int)floor(scale(sy, src_t, src_b, dst_t, dst_b) + 0.5);
44 static int scale_rev_x(
int dx)
46 return (
int)floor(scale(dx + 0.5, dst_l, dst_r, src_l, src_r));
49 static int next_row(
int sy,
int dy)
54 int y = scale_fwd_y(sy);
74 cairo_status_t status;
83 src_w = src_r - src_l;
84 src_h = src_b - src_t;
86 dst_l = (int) floor(d[0][0] + 0.5);
87 dst_r = (int) floor(d[0][1] + 0.5);
88 dst_t = (int) floor(d[1][0] + 0.5);
89 dst_b = (int) floor(d[1][1] + 0.5);
91 dst_w = dst_r - dst_l;
92 dst_h = dst_b - dst_t;
94 G_debug(1,
"Cairo_begin_raster(): masked=%d, src_lrtb=%d %d %d %d -> w/h=%d %d, " 95 "dst_lrtb=%d %d %d %d -> w/h=%d %d",
96 masked, src_l, src_r, src_t, src_b, src_w, src_h,
97 dst_l, dst_r, dst_t, dst_b, dst_w, dst_h);
100 src_surf = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
ca.
width,
ca.
height);
101 status = cairo_surface_status(src_surf);
102 if (status != CAIRO_STATUS_SUCCESS)
104 _(
"Failed to create cairo surface"),
108 src_data = cairo_image_surface_get_data(src_surf);
109 src_stride = cairo_image_surface_get_stride(src_surf);
113 trans =
G_malloc(dst_w *
sizeof(
int));
114 for (i = 0; i < dst_w; i++)
115 trans[i] = scale_rev_x(dst_l + i);
128 const unsigned char *red,
const unsigned char *grn,
129 const unsigned char *blu,
const unsigned char *nul)
131 int d_y0 = scale_fwd_y(row + 0);
132 int d_y1 = scale_fwd_y(row + 1);
133 int d_rows = d_y1 - d_y0;
134 int x0 =
MAX(0 - dst_l, 0);
136 int y0 =
MAX(0 - d_y0, 0);
141 return next_row(row, d_y1);
143 G_debug(3,
"Cairo_raster(): n=%d row=%d", n, row);
145 for (x = x0; x < x1; x++) {
150 if (masked && nul && nul[j])
153 unsigned int r = red[j];
154 unsigned int g = grn[j];
155 unsigned int b = blu[j];
156 unsigned int a = 0xFF;
157 c = (a << 24) + (r << 16) + (g << 8) + (b << 0);
160 for (y = y0; y < y1; y++) {
162 *(
unsigned int *)(src_data + yy * src_stride + xx * 4) = c;
169 return next_row(row, d_y1);
177 G_debug(1,
"Cairo_end_raster()");
183 cairo_surface_mark_dirty(src_surf);
184 cairo_set_source_surface(
cairo, src_surf, 0, 0);
185 cairo_pattern_set_filter(cairo_get_source(
cairo), CAIRO_FILTER_NEAREST);
187 cairo_restore(
cairo);
191 cairo_surface_destroy(src_surf);
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
void Cairo_begin_raster(int mask, int s[2][2], double d[2][2])
Start drawing raster.
void G_free(void *)
Free allocated memory.
int Cairo_raster(int n, int row, const unsigned char *red, const unsigned char *grn, const unsigned char *blu, const unsigned char *nul)
Draw raster row.
void Cairo_end_raster(void)
Finish drawing raster.
GRASS cairo display driver - header file.
int G_debug(int, const char *,...) __attribute__((format(printf