raster.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  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. int t = R_screen_top();
  23. int b = R_screen_bot();
  24. int l = R_screen_left();
  25. int r = R_screen_rite();
  26. R_font(font ? font : "romans");
  27. if (fenc)
  28. R_charset(fenc);
  29. R_set_window(t, b, l, r);
  30. }
  31. int R_open_driver(void)
  32. {
  33. const char *p = getenv("GRASS_RENDER_IMMEDIATE");
  34. const struct driver *drv =
  35. (p && G_strcasecmp(p, "PS") == 0) ? PS_Driver() :
  36. (p && G_strcasecmp(p, "HTML") == 0) ? HTML_Driver() :
  37. #ifdef USE_CAIRO
  38. (p && G_strcasecmp(p, "cairo") == 0) ? Cairo_Driver() :
  39. #endif
  40. PNG_Driver();
  41. LIB_init(drv, 0, NULL);
  42. init();
  43. COM_Client_Open();
  44. return 0;
  45. }
  46. void R__open_quiet(void)
  47. {
  48. }
  49. void R_stabilize(void)
  50. {
  51. COM_Respond();
  52. }
  53. void R_close_driver(void)
  54. {
  55. R_stabilize();
  56. COM_Client_Close();
  57. }
  58. void R_flush(void)
  59. {
  60. R_stabilize();
  61. }
  62. /*!
  63. * \brief screen left edge
  64. *
  65. * Returns the coordinate of the left edge of the screen.
  66. *
  67. * \param void
  68. * \return int
  69. */
  70. int R_screen_left(void)
  71. {
  72. int l;
  73. COM_Screen_left(&l);
  74. return l;
  75. }
  76. /*!
  77. * \brief screen right edge
  78. *
  79. * Returns the coordinate of the right edge of the screen.
  80. *
  81. * \param void
  82. * \return int
  83. */
  84. int R_screen_rite(void)
  85. {
  86. int r;
  87. COM_Screen_rite(&r);
  88. return r;
  89. }
  90. /*!
  91. * \brief bottom of screen
  92. *
  93. * Returns the coordinate of the bottom of the screen.
  94. *
  95. * \param void
  96. * \return int
  97. */
  98. int R_screen_bot(void)
  99. {
  100. int b;
  101. COM_Screen_bot(&b);
  102. return b;
  103. }
  104. /*!
  105. * \brief top of screen
  106. *
  107. * Returns the coordinate of the top of the screen.
  108. *
  109. * \param void
  110. * \return int
  111. */
  112. int R_screen_top(void)
  113. {
  114. int t;
  115. COM_Screen_top(&t);
  116. return t;
  117. }
  118. void R_get_num_colors(int *n)
  119. {
  120. COM_Number_of_colors(n);
  121. }
  122. /*!
  123. * \brief select standard color
  124. *
  125. * Selects the
  126. * standard <b>color</b> to be used in subsequent draw commands. The
  127. * <b>color</b> value is best retrieved using <i>D_translate_color.</i>
  128. * See Display_Graphics_Library.
  129. *
  130. * \param index
  131. * \return int
  132. */
  133. void R_standard_color(int index)
  134. {
  135. COM_Standard_color(index);
  136. }
  137. /*!
  138. * \brief select color
  139. *
  140. * When in
  141. * float mode (see <i>R_color_table_float</i>), this call selects the color
  142. * most closely matched to the <b>red, grn</b>, and <b>blue</b> intensities
  143. * requested. These values must be in the range of 0-255.
  144. *
  145. * \param red
  146. * \param grn
  147. * \param blue
  148. * \return int
  149. */
  150. void R_RGB_color(unsigned char red, unsigned char grn, unsigned char blu)
  151. {
  152. COM_Color_RGB(red, grn, blu);
  153. }
  154. /*!
  155. * \brief change the width of line
  156. *
  157. * Changes the <b>width</b> of line to be used in subsequent draw commands.
  158. *
  159. * \param width
  160. * \return int
  161. */
  162. void R_line_width(int width)
  163. {
  164. COM_Line_width(width);
  165. }
  166. /*!
  167. * \brief erase screen
  168. *
  169. * Erases the entire screen to black.
  170. *
  171. * \param void
  172. * \return int
  173. */
  174. void R_erase(void)
  175. {
  176. COM_Erase();
  177. }
  178. /*!
  179. * \brief move current location
  180. *
  181. * Move the current location to the absolute screen coordinate <b>x,y.</b>
  182. * Nothing is drawn on the screen.
  183. *
  184. * \param x
  185. * \param y
  186. * \return int
  187. */
  188. void R_move_abs(int x, int y)
  189. {
  190. COM_Move_abs(x, y);
  191. }
  192. /*!
  193. * \brief move current location
  194. *
  195. * Shift the current screen location by the values in <b>dx</b> and <b>dy</b>:
  196. \code
  197. Newx = Oldx + dx;
  198. Newy = Oldy + dy;
  199. \endcode
  200. * Nothing is drawn on the screen.
  201. *
  202. * \param x dx
  203. * \param y dy
  204. * \return int
  205. */
  206. void R_move_rel(int x, int y)
  207. {
  208. COM_Move_rel(x, y);
  209. }
  210. /*!
  211. * \brief draw line
  212. *
  213. * Draw a line using the current color, selected via <i>R_color</i>, from the
  214. * current location to the location specified by <b>x,y.</b> The current location
  215. * is updated to <b>x,y.</b>
  216. *
  217. * \param x
  218. * \param y
  219. * \return int
  220. */
  221. void R_cont_abs(int x, int y)
  222. {
  223. COM_Cont_abs(x, y);
  224. }
  225. /*!
  226. * \brief draw line
  227. *
  228. * Draw a line using the
  229. * current color, selected via <i>R_color</i>, from the current location to
  230. * the relative location specified by <b>x</b> and <b>y.</b> The current
  231. * location is updated:
  232. \code
  233. Newx = Oldx + x;
  234. Newy = Oldy + y;
  235. \endcode
  236. *
  237. * \param x
  238. * \param y
  239. * \return int
  240. */
  241. void R_cont_rel(int x, int y)
  242. {
  243. COM_Cont_rel(x, y);
  244. }
  245. /*!
  246. * \brief draw a series of dots
  247. *
  248. * Pixels at the <b>num</b> absolute positions in the <b>x</b> and
  249. * <b>y</b> arrays are turned to the current color. The current location is
  250. * left updated to the position of the last dot.
  251. *
  252. * \param xarray x
  253. * \param yarray y
  254. * \param number
  255. * \return int
  256. */
  257. void R_polydots_abs(const int *xarray, const int *yarray, int number)
  258. {
  259. COM_Polydots_abs(xarray, yarray, number);
  260. }
  261. /*!
  262. * \brief draw a series of dots
  263. *
  264. * Pixels at the <b>number</b> relative positions in the <b>x</b> and
  265. * <b>y</b> arrays are turned to the current color. The first position is
  266. * relative to the starting current location; the succeeding positions are then
  267. * relative to the previous position. The current location is updated to the
  268. * position of the last dot.
  269. *
  270. * \param xarray x
  271. * \param yarray y
  272. * \param number
  273. * \return int
  274. */
  275. void R_polydots_rel(const int *xarray, const int *yarray, int number)
  276. {
  277. COM_Polydots_rel(xarray, yarray, number);
  278. }
  279. /*!
  280. * \brief draw an open polygon
  281. *
  282. * The <b>number</b> absolute positions in the <b>x</b> and <b>y</b>
  283. * arrays are used to generate a multisegment line (often curved). This line is
  284. * drawn with the current color. The current location is left updated to the
  285. * position of the last point.
  286. * <b>Note.</b> It is not assumed that the line is closed, i.e., no line is
  287. * drawn from the last point to the first point.
  288. *
  289. * \param xarray x
  290. * \param yarray y
  291. * \param number
  292. * \return int
  293. */
  294. void R_polyline_abs(const int *xarray, const int *yarray, int number)
  295. {
  296. COM_Polyline_abs(xarray, yarray, number);
  297. }
  298. /*!
  299. * \brief draw an open polygon
  300. *
  301. * The <b>number</b> relative positions in the <b>x</b> and <b>y</b>
  302. * arrays are used to generate a multisegment line (often curved). The first
  303. * position is relative to the starting current location; the succeeding
  304. * positions are then relative to the previous position. The current location is
  305. * updated to the position of the last point. This line is drawn with the current
  306. * color.
  307. * <b>Note.</b> No line is drawn between the last point and the first point.
  308. *
  309. * \param xarray x
  310. * \param yarray y
  311. * \param number
  312. * \return int
  313. */
  314. void R_polyline_rel(const int *xarray, const int *yarray, int number)
  315. {
  316. COM_Polyline_rel(xarray, yarray, number);
  317. }
  318. /*!
  319. * \brief draw a closed polygon
  320. *
  321. * The <b>number</b> absolute positions in the <b>x</b> and <b>y</b> arrays
  322. * outline a closed polygon which is filled with the current color. The current
  323. * location is undefined afterwards.
  324. *
  325. * \param xarray x
  326. * \param yarray y
  327. * \param number
  328. * \return int
  329. */
  330. void R_polygon_abs(const int *xarray, const int *yarray, int number)
  331. {
  332. COM_Polygon_abs(xarray, yarray, number);
  333. }
  334. /*!
  335. * \brief draw a closed polygon
  336. *
  337. * The <b>number</b> relative positions in the <b>x</b> and <b>y</b>
  338. * arrays outline a closed polygon which is filled with the current color. The
  339. * first position is relative to the starting current location; the succeeding
  340. * positions are then relative to the previous position. The current location is
  341. * undefined afterwards.
  342. *
  343. * \param xarray x
  344. * \param yarray y
  345. * \param number
  346. * \return int
  347. */
  348. void R_polygon_rel(const int *xarray, const int *yarray, int number)
  349. {
  350. COM_Polygon_rel(xarray, yarray, number);
  351. }
  352. /*!
  353. * \brief fill a box
  354. *
  355. * A box is drawn in the current color using the coordinates <b>x1,y1</b> and
  356. * <b>x2,y2</b> as opposite corners of the box. The current location is undefined
  357. * afterwards
  358. *
  359. * \param x1
  360. * \param y1
  361. * \param x2
  362. * \param y2
  363. * \return int
  364. */
  365. void R_box_abs(int x1, int y1, int x2, int y2)
  366. {
  367. COM_Box_abs(x1, y1, x2, y2);
  368. }
  369. /*!
  370. * \brief fill a box
  371. *
  372. * A box is drawn in the current color using the current location as one corner
  373. * and the current location plus <b>x</b> and <b>y</b> as the opposite corner
  374. * of the box. The current location is undefined afterwards.
  375. *
  376. * \param x
  377. * \param y
  378. * \return int
  379. */
  380. void R_box_rel(int x, int y)
  381. {
  382. COM_Box_rel(x, y);
  383. }
  384. /*!
  385. * \brief set text size
  386. *
  387. * Sets text pixel width and height to <b>width</b> and <b>height.</b>
  388. *
  389. * \param width
  390. * \param height
  391. * \return int
  392. */
  393. void R_text_size(int width, int height)
  394. {
  395. COM_Text_size(width, height);
  396. }
  397. void R_text_rotation(float rotation)
  398. {
  399. COM_Text_rotation(rotation);
  400. }
  401. /*!
  402. * \brief set text clipping frame
  403. *
  404. * Subsequent calls to <i>R_text</i> will have text strings
  405. * clipped to the screen frame defined by <b>top, bottom, left, right.</b>
  406. *
  407. * \param t top
  408. * \param b bottom
  409. * \param l left
  410. * \param r right
  411. * \return int
  412. */
  413. void R_set_window(int t, int b, int l, int r)
  414. {
  415. COM_Set_window(t, b, l, r);
  416. }
  417. /*!
  418. * \brief write text
  419. *
  420. * Writes <b>text</b> in the current color and font, at the current text
  421. * width and height, starting at the current screen location.
  422. *
  423. * \param sometext
  424. * \return int
  425. */
  426. void R_text(const char *text)
  427. {
  428. COM_Text(text);
  429. }
  430. /*!
  431. * \brief get text extents
  432. *
  433. * The extent of the area enclosing the <b>text</b>
  434. * is returned in the integer pointers <b>top, bottom, left</b>, and
  435. * <b>right.</b> No text is actually drawn. This is useful for capturing the
  436. * text extent so that the text location can be prepared with proper background
  437. * or border.
  438. *
  439. * \param sometext
  440. * \param t top
  441. * \param b bottom
  442. * \param l left
  443. * \param r right
  444. * \return int
  445. */
  446. void R_get_text_box(const char *text, int *t, int *b, int *l, int *r)
  447. {
  448. COM_Get_text_box(text, t, b, l, r);
  449. }
  450. /*!
  451. * \brief choose font
  452. *
  453. * Set current font to <b>font name</b>.
  454. *
  455. * \param name
  456. * \return int
  457. */
  458. void R_font(const char *name)
  459. {
  460. COM_Font_get(name);
  461. }
  462. void R_charset(const char *name)
  463. {
  464. COM_Font_init_charset(name);
  465. }
  466. void R_font_list(char ***list, int *count)
  467. {
  468. COM_Font_list(list, count);
  469. }
  470. void R_font_info(char ***list, int *count)
  471. {
  472. COM_Font_info(list, count);
  473. }
  474. void R_begin_scaled_raster(int mask, int src[2][2], int dst[2][2])
  475. {
  476. COM_begin_scaled_raster(mask, src, dst);
  477. }
  478. int R_scaled_raster(int n, int row,
  479. const unsigned char *red, const unsigned char *grn,
  480. const unsigned char *blu, const unsigned char *nul)
  481. {
  482. return COM_scaled_raster(n, row, red, grn, blu, nul);
  483. }
  484. void R_end_scaled_raster(void)
  485. {
  486. COM_end_scaled_raster();
  487. }
  488. void R_bitmap(int ncols, int nrows, int threshold, const unsigned char *buf)
  489. {
  490. COM_Bitmap(ncols, nrows, threshold, buf);
  491. }