r_raster.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. #include <grass/config.h>
  2. #include <errno.h>
  3. #include <signal.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include <unistd.h>
  8. #include <grass/gis.h>
  9. #include <grass/glocale.h>
  10. #include <grass/raster.h>
  11. #include "driver.h"
  12. extern const struct driver *PNG_Driver(void);
  13. extern const struct driver *PS_Driver(void);
  14. extern const struct driver *HTML_Driver(void);
  15. #ifdef USE_CAIRO
  16. extern const struct driver *Cairo_Driver(void);
  17. #endif
  18. static void init(void)
  19. {
  20. const char *fenc = getenv("GRASS_ENCODING");
  21. const char *font = getenv("GRASS_FONT");
  22. const char *line_width = getenv("GRASS_LINE_WIDTH");
  23. const char *text_size = getenv("GRASS_TEXT_SIZE");
  24. const char *frame = getenv("GRASS_FRAME");
  25. R_font(font ? font : "romans");
  26. if (fenc)
  27. R_encoding(fenc);
  28. if (line_width)
  29. R_line_width(atof(line_width));
  30. if (text_size) {
  31. double s = atof(text_size);
  32. R_text_size(s, s);
  33. }
  34. R_text_rotation(0);
  35. if (frame) {
  36. double t, b, l, r;
  37. sscanf(frame, "%lf,%lf,%lf,%lf", &t, &b, &l, &r);
  38. R_set_window(t, b, l, r);
  39. }
  40. }
  41. int R_open_driver(void)
  42. {
  43. const char *p = getenv("GRASS_RENDER_IMMEDIATE");
  44. const struct driver *drv =
  45. (p && G_strcasecmp(p, "PNG") == 0) ? PNG_Driver() :
  46. (p && G_strcasecmp(p, "PS") == 0) ? PS_Driver() :
  47. (p && G_strcasecmp(p, "HTML") == 0) ? HTML_Driver() :
  48. #ifdef USE_CAIRO
  49. (p && G_strcasecmp(p, "cairo") == 0) ? Cairo_Driver() :
  50. Cairo_Driver();
  51. #else
  52. PNG_Driver();
  53. #endif
  54. LIB_init(drv);
  55. init();
  56. return 0;
  57. }
  58. void R_close_driver(void)
  59. {
  60. const char *cmd = getenv("GRASS_NOTIFY");
  61. COM_Graph_close();
  62. if (cmd)
  63. system(cmd);
  64. }
  65. /*!
  66. * \brief select standard color
  67. *
  68. * Selects the
  69. * standard <b>color</b> to be used in subsequent draw commands. The
  70. * <b>color</b> value is best retrieved using <i>D_translate_color.</i>
  71. * See Display_Graphics_Library.
  72. *
  73. * \param index
  74. * \return void
  75. */
  76. void R_standard_color(int index)
  77. {
  78. COM_Standard_color(index);
  79. }
  80. /*!
  81. * \brief select color
  82. *
  83. * When in
  84. * float mode (see <i>R_color_table_float</i>), this call selects the color
  85. * most closely matched to the <b>red, grn</b>, and <b>blue</b> intensities
  86. * requested. These values must be in the range of 0-255.
  87. *
  88. * \param red
  89. * \param grn
  90. * \param blue
  91. * \return void
  92. */
  93. void R_RGB_color(int red, int grn, int blu)
  94. {
  95. COM_Color_RGB(red, grn, blu);
  96. }
  97. /*!
  98. * \brief change the width of line
  99. *
  100. * Changes the <b>width</b> of line to be used in subsequent draw commands.
  101. *
  102. * \param width
  103. * \return void
  104. */
  105. void R_line_width(double width)
  106. {
  107. COM_Line_width(width);
  108. }
  109. /*!
  110. * \brief erase screen
  111. *
  112. * Erases the entire screen to black.
  113. *
  114. * \param void
  115. * \return void
  116. */
  117. void R_erase(void)
  118. {
  119. COM_Erase();
  120. }
  121. /*!
  122. * \brief move current location
  123. *
  124. * Move the current location to the absolute screen coordinate <b>x,y.</b>
  125. * Nothing is drawn on the screen.
  126. *
  127. * \param x
  128. * \param y
  129. * \return void
  130. */
  131. void R_pos_abs(double x, double y)
  132. {
  133. COM_Pos_abs(x, y);
  134. }
  135. /*!
  136. * \brief fill a box
  137. *
  138. * A box is drawn in the current color using the coordinates <b>x1,y1</b> and
  139. * <b>x2,y2</b> as opposite corners of the box. The current location is undefined
  140. * afterwards
  141. *
  142. * \param x1
  143. * \param y1
  144. * \param x2
  145. * \param y2
  146. * \return void
  147. */
  148. void R_box_abs(double x1, double y1, double x2, double y2)
  149. {
  150. COM_Box_abs(x1, y1, x2, y2);
  151. }
  152. /*!
  153. * \brief set text size
  154. *
  155. * Sets text pixel width and height to <b>width</b> and <b>height.</b>
  156. *
  157. * \param width
  158. * \param height
  159. * \return void
  160. */
  161. void R_text_size(double width, double height)
  162. {
  163. COM_Text_size(width, height);
  164. }
  165. void R_text_rotation(double rotation)
  166. {
  167. COM_Text_rotation(rotation);
  168. }
  169. /*!
  170. * \brief set clipping frame
  171. *
  172. * Subsequent drawing operations will be clipped to the screen frame
  173. * defined by <b>top, bottom, left, right.</b>
  174. *
  175. * \param t top
  176. * \param b bottom
  177. * \param l left
  178. * \param r right
  179. * \return void
  180. */
  181. void R_set_window(double t, double b, double l, double r)
  182. {
  183. COM_Set_window(t, b, l, r);
  184. }
  185. /*!
  186. * \brief get clipping frame
  187. *
  188. * Retrieve clipping frame
  189. *
  190. * \param t top
  191. * \param b bottom
  192. * \param l left
  193. * \param r right
  194. * \return void
  195. */
  196. void R_get_window(double *t, double *b, double *l, double *r)
  197. {
  198. return COM_Get_window(t, b, l, r);
  199. }
  200. /*!
  201. * \brief write text
  202. *
  203. * Writes <b>text</b> in the current color and font, at the current text
  204. * width and height, starting at the current screen location.
  205. *
  206. * \param sometext
  207. * \return void
  208. */
  209. void R_text(const char *text)
  210. {
  211. COM_Text(text);
  212. }
  213. /*!
  214. * \brief get text extents
  215. *
  216. * The extent of the area enclosing the <b>text</b>
  217. * is returned in the integer pointers <b>top, bottom, left</b>, and
  218. * <b>right.</b> No text is actually drawn. This is useful for capturing the
  219. * text extent so that the text location can be prepared with proper background
  220. * or border.
  221. *
  222. * \param sometext
  223. * \param t top
  224. * \param b bottom
  225. * \param l left
  226. * \param r right
  227. * \return void
  228. */
  229. void R_get_text_box(const char *text, double *t, double *b, double *l, double *r)
  230. {
  231. COM_Get_text_box(text, t, b, l, r);
  232. }
  233. /*!
  234. * \brief choose font
  235. *
  236. * Set current font to <b>font name</b>.
  237. *
  238. * \param name
  239. * \return void
  240. */
  241. void R_font(const char *name)
  242. {
  243. COM_Set_font(name);
  244. }
  245. void R_encoding(const char *name)
  246. {
  247. COM_Set_encoding(name);
  248. }
  249. void R_font_list(char ***list, int *count)
  250. {
  251. COM_Font_list(list, count);
  252. }
  253. void R_font_info(char ***list, int *count)
  254. {
  255. COM_Font_info(list, count);
  256. }
  257. void R_begin_scaled_raster(int mask, int src[2][2], double dst[2][2])
  258. {
  259. COM_begin_raster(mask, src, dst);
  260. }
  261. int R_scaled_raster(int n, int row,
  262. const unsigned char *red, const unsigned char *grn,
  263. const unsigned char *blu, const unsigned char *nul)
  264. {
  265. return COM_raster(n, row, red, grn, blu, nul);
  266. }
  267. void R_end_scaled_raster(void)
  268. {
  269. COM_end_raster();
  270. }
  271. void R_bitmap(int ncols, int nrows, int threshold, const unsigned char *buf)
  272. {
  273. COM_Bitmap(ncols, nrows, threshold, buf);
  274. }
  275. void R_begin(void)
  276. {
  277. COM_Begin();
  278. }
  279. void R_move(double x, double y)
  280. {
  281. COM_Move(x, y);
  282. }
  283. void R_cont(double x, double y)
  284. {
  285. COM_Cont(x, y);
  286. }
  287. void R_close(void)
  288. {
  289. COM_Close();
  290. }
  291. void R_stroke(void)
  292. {
  293. COM_Stroke();
  294. }
  295. void R_fill(void)
  296. {
  297. COM_Fill();
  298. }
  299. void R_point(double x, double y)
  300. {
  301. COM_Point(x, y);
  302. }