Geoinformatica  0.90
backend.h
Go to the documentation of this file.
1 #ifndef RAL_BACKEND_H
2 #define RAL_BACKEND_H
3 
8 GDALColorEntry RAL_CALL ral_hsv2rgb(GDALColorEntry hsv);
9 
10 #define RAL_PIXELSIZE 4
11 #define RAL_PIXBUF_PIXELSIZE 3
12 
19 typedef struct {
20 
22  unsigned char *image;
23 
26 
28  guchar *pixbuf;
29 
31  GdkPixbufDestroyNotify destroy_fn;
32 
34  GdkColorspace colorspace;
35 
37  gboolean has_alpha;
38 
40  int rowstride;
41 
44 
46  int N;
48  int M;
49 
52 
54  double pixel_size;
55 
56 } ral_pixbuf;
57 
59 
60 ral_pixbuf_handle RAL_CALL ral_pixbuf_create(int width, int height,
61  double minX, double maxY, double pixel_size,
62  GDALColorEntry background);
63 
64 ral_pixbuf_handle RAL_CALL ral_pixbuf_create_from_grid(ral_grid *gd);
65 
66 void RAL_CALL ral_pixbuf_destroy(ral_pixbuf **pb);
67 
68 int RAL_CALL ral_cairo_to_pixbuf(ral_pixbuf *pb);
69 
70 #ifdef RAL_HAVE_GDK_PIXBUF
71 typedef GdkPixbuf *GdkPixbufH;
72 GdkPixbufH RAL_CALL ral_gdk_pixbuf(ral_pixbuf *pb);
73 #endif
74 
75 #define RAL_PIXBUF_INDEX(pb,i,j) (i)*(pb)->image_rowstride+(j)*RAL_PIXELSIZE
76 
77 #define RAL_PIXBUF_SET_PIXEL(pb,i,j,R,G,B) \
78  { (pb->image)[RAL_PIXBUF_INDEX(pb,i,j)+3] = 255; \
79  (pb->image)[RAL_PIXBUF_INDEX(pb,i,j)+2] = (R); \
80  (pb->image)[RAL_PIXBUF_INDEX(pb,i,j)+1] = (G); \
81  (pb->image)[RAL_PIXBUF_INDEX(pb,i,j)+0] = (B); }
82 
83 #define RAL_PIXBUF_SET_PIXEL_COLOR(pb,i,j,c) \
84  { (pb->image)[RAL_PIXBUF_INDEX(pb,i,j)+3] = 255; \
85  (pb->image)[RAL_PIXBUF_INDEX(pb,i,j)+2] = \
86  min(max(((255-((c).c4))*(pb->image)[RAL_PIXBUF_INDEX(pb,i,j)+2]+((c).c4)*((c).c1))/255,0),255); \
87  (pb->image)[RAL_PIXBUF_INDEX(pb,i,j)+1] = \
88  min(max(((255-((c).c4))*(pb->image)[RAL_PIXBUF_INDEX(pb,i,j)+1]+((c).c4)*((c).c2))/255,0),255); \
89  (pb->image)[RAL_PIXBUF_INDEX(pb,i,j)+0] = \
90  min(max(((255-((c).c4))*(pb->image)[RAL_PIXBUF_INDEX(pb,i,j)+0]+((c).c4)*((c).c3))/255,0),255);}
91 
92 #define RAL_PIXBUF_SET_PIXEL_COLOR_TEST(pb,i,j,c) \
93  if ((i) >= 0 AND (i) < (pb)->M AND (j) >= 0 AND (j) < (pb)->N) \
94  RAL_PIXBUF_SET_PIXEL_COLOR((pb),(i),(j),(c))
95 
96 #define RAL_PIXBUF_ASSIGN_PIXEL_COLOR(pb, pixel, color) RAL_PIXBUF_SET_PIXEL_COLOR(pb,pixel.i,pixel.j,color)
97 
98 #define RAL_PIXBUF_GET_PIXEL_COLOR(pb, pixel, color) \
99  {(color).c1 = (pb->image)[RAL_PIXBUF_INDEX(pb, (pixel).i, (pixel).j)+2]; \
100  (color).c2 = (pb->image)[RAL_PIXBUF_INDEX(pb, (pixel).i, (pixel).j)+1]; \
101  (color).c3 = (pb->image)[RAL_PIXBUF_INDEX(pb, (pixel).i, (pixel).j)+0];}
102 
104 #define RAL_PBi2GDi(pb, i, gd) (floor((((gd)->world.max.y - \
105  (pb->world.max.y - (double)(i)*pb->pixel_size)))/(gd)->cell_size))
106 
108 #define RAL_PBj2GDj(pb, j, gd) (floor(((pb->world.min.x + \
109  (double)(j)*pb->pixel_size) - (gd)->world.min.x)/(gd)->cell_size))
110 
112 #define RAL_GDi2PBi(gd, i, pb) \
113  (floor((pb->world.max.y - (gd)->world.max.y + (gd)->cell_size * ((double)(i)+0.5))/pb->pixel_size))
114 
116 #define RAL_GDj2PBj(gd, j, pb) \
117  (floor(((gd)->world.min.x - pb->world.min.x + (gd)->cell_size * ((double)(j)+0.5))/pb->pixel_size))
118 
120 #define RAL_PIXEL2CELL(pixel, gd, cell) \
121  (cell).i = RAL_PBi2GDi(pb, (pixel).i, (gd)); \
122  (cell).j = RAL_PBj2GDj(pb, (pixel).j, (gd))
123 
124 int RAL_CALL ral_render_integer_grid(ral_pixbuf *pb, ral_integer_grid_layer *l);
125 int RAL_CALL ral_render_real_grid(ral_pixbuf *pb, ral_real_grid_layer *l);
126 
127 int RAL_CALL ral_render_rectangles(ral_pixbuf *pb, ral_geometry *g, int symbol_size, GDALColorEntry color);
128 int RAL_CALL ral_render_crosses(ral_pixbuf *pb, ral_geometry *g, int symbol_size, GDALColorEntry color);
129 int RAL_CALL ral_render_dots(ral_pixbuf *pb, ral_geometry *g, int r, GDALColorEntry color);
130 
131 int RAL_CALL ral_render_polylines(ral_pixbuf *pb, ral_geometry *g, GDALColorEntry color);
132 
133 int RAL_CALL ral_render_polygons(ral_pixbuf *pb, ral_geometry *g, GDALColorEntry color);
134 
136 typedef struct {
139  ral_double_range bound;
140  double delta_x;
141  double delta_y;
142  double k;
144 
145 #define RAL_INTERPOLATOR_SETUP(interpolator, x_range, y_range) \
146  (interpolator).x.min = (x_range).min; \
147  (interpolator).x.max = (x_range).max; \
148  (interpolator).y.min = (y_range).min; \
149  (interpolator).y.max = (y_range).max; \
150  (interpolator).delta_x = (interpolator).x.max - (interpolator).x.min; \
151  (interpolator).delta_y = (interpolator).y.max - (interpolator).y.min; \
152  (interpolator).bound.min = min((interpolator).y.max, (interpolator).y.min); \
153  (interpolator).bound.max = max((interpolator).y.max, (interpolator).y.min); \
154  (interpolator).k = (interpolator).delta_x == 0 ? 0 : (interpolator).delta_y / (interpolator).delta_x;
155 
156 #define RAL_INTERPOLATE(interpolator, x_value) \
157  max(min((interpolator).y.min + (interpolator).k*((x_value) - (interpolator).x.min), \
158  (interpolator).bound.max), (interpolator).bound.min)
159 
160 #ifdef RAL_HAVE_GDAL
161 
162 typedef struct {
163  OGRFeatureH feature;
164  OGRGeometryH geometry;
165  int destroy_geometry;
167  ral_geometry *ral_geom;
168  int render_as;
170  OGRFieldType color_field_type;
171  ral_interpolator nv2c; /* from the value in the field to a color */
172  GDALColorEntry color;
173  ral_interpolator nv2ss;
174 } ral_feature;
175 
176 #define RAL_FEATURE_SET_COLOR(feature, c1_value, c2_value, c3_value, c4_value) { \
177  (feature).color.c1 = (c1_value); \
178  (feature).color.c2 = (c2_value); \
179  (feature).color.c3 = (c3_value); \
180  (feature).color.c4 = (c4_value);} \
181 
182 int RAL_CALL ral_render_feature(ral_pixbuf *pb, ral_feature *feature, ral_visual *visual);
183 
184 int RAL_CALL ral_render_visual_layer(ral_pixbuf *pb, ral_visual_layer *l);
185 
186 int RAL_CALL ral_render_visual_feature_table(ral_pixbuf *pb, ral_visual_feature_table *t);
187 
189 int RAL_CALL ral_get_field_type(OGRLayerH layer, int field, OGRFieldType *field_type);
190 #endif
191 
192 #endif
an OGRLayerH and visualization information
Definition: visual.h:271
OGRFieldType symbol_size_field_type
Definition: backend.h:169
int image_rowstride
Definition: backend.h:25
GdkColorspace colorspace
Definition: backend.h:34
rectangular grid of integer or real values for geospatial data
Definition: grid.h:166
double pixel_size
Definition: backend.h:54
visualization information
Definition: visual.h:235
unsigned char * image
Definition: backend.h:22
GdkPixbufDestroyNotify destroy_fn
Definition: backend.h:31
int bits_per_sample
Definition: backend.h:43
int RAL_CALL ral_get_field_type(OGRLayerH layer, int field, OGRFieldType *field_type)
gboolean has_alpha
Definition: backend.h:37
linear interpolation made easier
Definition: backend.h:136
int rowstride
Definition: backend.h:40
int N
Definition: backend.h:46
a range defined by two real numbers
Definition: visual.h:15
an array of points, which represent a simple geometry
Definition: vector.h:97
a RAL_REAL grid and visualization information
Definition: visual.h:193
a cairo image canvas and a gdk style pixbuf
Definition: backend.h:19
an array of ral_visual_features
Definition: visual.h:288
two points: SW and NE corners
Definition: vector.h:27
ral_rectangle world
Definition: backend.h:51
a RAL_INTEGER grid and visualization information
Definition: visual.h:162
int geometry_type
Definition: backend.h:166
int M
Definition: backend.h:48
guchar * pixbuf
Definition: backend.h:28