b_path.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. /* This file is part of the GNU plotutils package. Copyright (C) 1995,
  2. 1996, 1997, 1998, 1999, 2000, 2005, 2008, Free Software Foundation, Inc.
  3. The GNU plotutils package is free software. You may redistribute it
  4. and/or modify it under the terms of the GNU General Public License as
  5. published by the Free Software foundation; either version 2, or (at your
  6. option) any later version.
  7. The GNU plotutils package is distributed in the hope that it will be
  8. useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. General Public License for more details.
  11. You should have received a copy of the GNU General Public License along
  12. with the GNU plotutils package; see the file COPYING. If not, write to
  13. the Free Software Foundation, Inc., 51 Franklin St., Fifth Floor,
  14. Boston, MA 02110-1301, USA. */
  15. /* This file contains the internal paint_path() method, which the public
  16. method endpath() is a wrapper around. */
  17. /* This version is for Bitmap Plotters. By construction, for Bitmap
  18. Plotters our path buffer always contains either a segment list, or an
  19. ellipse object. If it's a segment list, it contains either (1) a
  20. sequence of line segments, or (2) a single circular or elliptic arc
  21. segment. Those are all sorts of path that libxmi can handle. (For an
  22. ellipse or circular/elliptic arc segment to have been added to the path
  23. buffer, the map from user to device coordinates must preserve axes.) */
  24. #include "sys-defines.h"
  25. #include "extern.h"
  26. #include "xmi.h" /* use libxmi scan conversion module */
  27. #define DIST(p1, p2) sqrt( ((p1).x - (p2).x) * ((p1).x - (p2).x) \
  28. + ((p1).y - (p2).y) * ((p1).y - (p2).y))
  29. void
  30. _pl_b_paint_path (S___(Plotter *_plotter))
  31. {
  32. if (_plotter->drawstate->pen_type == 0
  33. && _plotter->drawstate->fill_type == 0)
  34. /* nothing to draw */
  35. return;
  36. switch ((int)_plotter->drawstate->path->type)
  37. {
  38. case (int)PATH_SEGMENT_LIST:
  39. {
  40. int i, polyline_len;
  41. bool identical_user_coordinates = true;
  42. double xu_last, yu_last;
  43. miGC *pGC;
  44. miPoint *miPoints, offset;
  45. miPixel fgPixel, bgPixel;
  46. miPixel pixels[2];
  47. unsigned char red, green, blue;
  48. plPoint p0, p1, pc;
  49. /* sanity checks */
  50. if (_plotter->drawstate->path->num_segments == 0)/* nothing to do */
  51. break;
  52. if (_plotter->drawstate->path->num_segments == 1)/* shouldn't happen */
  53. break;
  54. if (_plotter->drawstate->path->num_segments == 2
  55. && _plotter->drawstate->path->segments[1].type == S_ARC)
  56. /* segment buffer contains a single circular arc, not a polyline */
  57. {
  58. p0 = _plotter->drawstate->path->segments[0].p;
  59. p1 = _plotter->drawstate->path->segments[1].p;
  60. pc = _plotter->drawstate->path->segments[1].pc;
  61. /* use libxmi rendering */
  62. _pl_b_draw_elliptic_arc (R___(_plotter) p0, p1, pc);
  63. break;
  64. }
  65. if (_plotter->drawstate->path->num_segments == 2
  66. && _plotter->drawstate->path->segments[1].type == S_ELLARC)
  67. /* segment buffer contains a single elliptic arc, not a polyline */
  68. {
  69. p0 = _plotter->drawstate->path->segments[0].p;
  70. p1 = _plotter->drawstate->path->segments[1].p;
  71. pc = _plotter->drawstate->path->segments[1].pc;
  72. /* use libxmi rendering */
  73. _pl_b_draw_elliptic_arc_2 (R___(_plotter) p0, p1, pc);
  74. break;
  75. }
  76. /* neither of above applied, so segment buffer contains a polyline,
  77. not an arc */
  78. /* construct point array for libxmi module; convert vertices to
  79. device coordinates, removing runs */
  80. miPoints = (miPoint *)_pl_xmalloc (_plotter->drawstate->path->num_segments * sizeof(miPoint));
  81. polyline_len = 0;
  82. xu_last = 0.0;
  83. yu_last = 0.0;
  84. identical_user_coordinates = true;
  85. for (i = 0; i < _plotter->drawstate->path->num_segments; i++)
  86. {
  87. double xu, yu;
  88. int device_x, device_y;
  89. xu = _plotter->drawstate->path->segments[i].p.x;
  90. yu = _plotter->drawstate->path->segments[i].p.y;
  91. if (i > 0 && (xu != xu_last || yu != yu_last))
  92. /* in user space, not all points are the same */
  93. identical_user_coordinates = false;
  94. device_x = IROUND(XD(xu, yu));
  95. device_y = IROUND(YD(xu, yu));
  96. if ((polyline_len == 0)
  97. || (device_x != miPoints[polyline_len-1].x)
  98. || (device_y != miPoints[polyline_len-1].y))
  99. /* add point, in integer device coordinates, to the array */
  100. {
  101. miPoints[polyline_len].x = device_x;
  102. miPoints[polyline_len].y = device_y;
  103. polyline_len++;
  104. }
  105. xu_last = xu;
  106. yu_last = yu;
  107. }
  108. /* determine background pixel color */
  109. bgPixel.type = MI_PIXEL_RGB_TYPE;
  110. bgPixel.u.rgb[0] = _plotter->drawstate->bgcolor.red & 0xff;
  111. bgPixel.u.rgb[1] = _plotter->drawstate->bgcolor.green & 0xff;
  112. bgPixel.u.rgb[2] = _plotter->drawstate->bgcolor.blue & 0xff;
  113. pixels[0] = bgPixel;
  114. pixels[1] = bgPixel;
  115. /* construct an miGC (graphics context for the libxmi module); copy
  116. attributes from the Plotter's GC to it */
  117. pGC = miNewGC (2, pixels);
  118. _set_common_mi_attributes (_plotter->drawstate, (void *)pGC);
  119. if (_plotter->drawstate->fill_type)
  120. /* not transparent, will fill */
  121. {
  122. /* flattened drawing primitives, i.e., box/circle/ellipse,
  123. are always convex */
  124. miPolygonShape polygon_shape
  125. = (_plotter->drawstate->path->primitive ? MI_SHAPE_CONVEX : MI_SHAPE_GENERAL);
  126. /* set fg color in GC to a 24-bit version of our fill color */
  127. red = ((unsigned int)(_plotter->drawstate->fillcolor.red) >> 8) & 0xff;
  128. green = ((unsigned int)(_plotter->drawstate->fillcolor.green) >> 8) & 0xff;
  129. blue = ((unsigned int)(_plotter->drawstate->fillcolor.blue) >> 8) & 0xff;
  130. fgPixel.type = MI_PIXEL_RGB_TYPE;
  131. fgPixel.u.rgb[0] = red;
  132. fgPixel.u.rgb[1] = green;
  133. fgPixel.u.rgb[2] = blue;
  134. pixels[0] = bgPixel;
  135. pixels[1] = fgPixel;
  136. miSetGCPixels (pGC, 2, pixels);
  137. /* do the filling */
  138. if (_plotter->drawstate->path->num_segments > 1
  139. && polyline_len == 1)
  140. /* special case: all user-space points in polyline were
  141. mapped to a single integer pixel, so just paint it */
  142. miDrawPoints ((miPaintedSet *)_plotter->b_painted_set, pGC,
  143. MI_COORD_MODE_ORIGIN, 1, miPoints);
  144. else
  145. /* normal case */
  146. miFillPolygon ((miPaintedSet *)_plotter->b_painted_set, pGC,
  147. polygon_shape,
  148. MI_COORD_MODE_ORIGIN, polyline_len, miPoints);
  149. }
  150. if (_plotter->drawstate->pen_type)
  151. /* pen is present, so edge the polyline */
  152. {
  153. /* set pen color in GC to a 24-bit version of our pen color
  154. (and set bg color too) */
  155. red = ((unsigned int)(_plotter->drawstate->fgcolor.red) >> 8) & 0xff;
  156. green = ((unsigned int)(_plotter->drawstate->fgcolor.green) >> 8) & 0xff;
  157. blue = ((unsigned int)(_plotter->drawstate->fgcolor.blue) >> 8) & 0xff;
  158. fgPixel.type = MI_PIXEL_RGB_TYPE;
  159. fgPixel.u.rgb[0] = red;
  160. fgPixel.u.rgb[1] = green;
  161. fgPixel.u.rgb[2] = blue;
  162. pixels[0] = bgPixel;
  163. pixels[1] = fgPixel;
  164. miSetGCPixels (pGC, 2, pixels);
  165. if (polyline_len == 1)
  166. /* Special case: all user-space points in the polyline were
  167. mapped to a single pixel. If (1) they weren't all the
  168. same to begin with, or (2) they were all the same to begin
  169. with and the cap mode is "round", then draw as a filled
  170. circle of diameter equal to the line width; otherwise draw
  171. nothing. */
  172. {
  173. if (identical_user_coordinates == false
  174. || _plotter->drawstate->cap_type == PL_CAP_ROUND)
  175. {
  176. unsigned int sp_size
  177. = (unsigned int)_plotter->drawstate->quantized_device_line_width;
  178. if (sp_size == 0)
  179. sp_size = 1;
  180. if (sp_size == 1)
  181. /* subcase: just draw a point */
  182. miDrawPoints ((miPaintedSet *)_plotter->b_painted_set, pGC,
  183. MI_COORD_MODE_ORIGIN, 1, miPoints);
  184. else
  185. /* draw a filled circle */
  186. {
  187. int sp_offset;
  188. miArc arc;
  189. sp_offset =
  190. (_plotter->drawstate->quantized_device_line_width + 1) / 2;
  191. arc.x = miPoints[0].x - sp_offset;
  192. arc.y = miPoints[0].y - sp_offset;
  193. arc.width = sp_size;
  194. arc.height = sp_size;
  195. arc.angle1 = 0;
  196. arc.angle2 = 64 * 360;
  197. miFillArcs ((miPaintedSet *)_plotter->b_painted_set,
  198. pGC, 1, &arc);
  199. }
  200. }
  201. }
  202. else
  203. /* normal case: draw a nondegenerate polyline in integer
  204. device space */
  205. miDrawLines ((miPaintedSet *)_plotter->b_painted_set, pGC,
  206. MI_COORD_MODE_ORIGIN, polyline_len, miPoints);
  207. }
  208. /* deallocate miGC and free temporary points array */
  209. miDeleteGC (pGC);
  210. free (miPoints);
  211. /* copy from painted set to canvas, and clear */
  212. offset.x = 0;
  213. offset.y = 0;
  214. miCopyPaintedSetToCanvas ((miPaintedSet *)_plotter->b_painted_set,
  215. (miCanvas *)_plotter->b_canvas,
  216. offset);
  217. miClearPaintedSet ((miPaintedSet *)_plotter->b_painted_set);
  218. }
  219. break;
  220. case (int)PATH_ELLIPSE:
  221. {
  222. int ninetymult;
  223. int x_orientation, y_orientation;
  224. int xorigin, yorigin;
  225. unsigned int squaresize_x, squaresize_y;
  226. plPoint pc;
  227. double rx, ry, angle;
  228. pc = _plotter->drawstate->path->pc;
  229. rx = _plotter->drawstate->path->rx;
  230. ry = _plotter->drawstate->path->ry;
  231. angle = _plotter->drawstate->path->angle;
  232. /* if angle is multiple of 90 degrees, modify to permit use of
  233. libxmi's arc rendering */
  234. ninetymult = IROUND(angle / 90.0);
  235. if (angle == (double) (90 * ninetymult))
  236. {
  237. angle = 0.0;
  238. if (ninetymult % 2)
  239. {
  240. double temp;
  241. temp = rx;
  242. rx = ry;
  243. ry = temp;
  244. }
  245. }
  246. rx = (rx < 0.0 ? -rx : rx); /* avoid obscure libxmi problems */
  247. ry = (ry < 0.0 ? -ry : ry);
  248. /* axes flipped? (by default y-axis is, due to libxmi's flipped-y
  249. convention) */
  250. x_orientation = (_plotter->drawstate->transform.m[0] >= 0 ? 1 : -1);
  251. y_orientation = (_plotter->drawstate->transform.m[3] >= 0 ? 1 : -1);
  252. /* location of `origin' (upper left corner of bounding rect. for
  253. ellipse) and width and height; libxmi's flipped-y convention
  254. affects these values */
  255. xorigin = IROUND(XD(pc.x - x_orientation * rx,
  256. pc.y - y_orientation * ry));
  257. yorigin = IROUND(YD(pc.x - x_orientation * rx,
  258. pc.y - y_orientation * ry));
  259. squaresize_x = (unsigned int)IROUND(XDV(2 * x_orientation * rx, 0.0));
  260. squaresize_y = (unsigned int)IROUND(YDV(0.0, 2 * y_orientation * ry));
  261. /* Because this ellipse object was added to the path buffer, we
  262. already know that (1) the user->device frame map preserves
  263. coordinate axes, (2) effectively, angle == 0. These are
  264. necessary for the libxmi scan-conversion module to do the
  265. drawing. */
  266. /* draw ellipse (elliptic arc aligned with the coordinate axes, arc
  267. range = 64*360 64'ths of a degree) */
  268. _pl_b_draw_elliptic_arc_internal (R___(_plotter)
  269. xorigin, yorigin,
  270. squaresize_x, squaresize_y,
  271. 0, 64 * 360);
  272. }
  273. break;
  274. default: /* shouldn't happen */
  275. break;
  276. }
  277. }
  278. /* Use libxmi rendering to draw what would be a circular arc in the user
  279. frame. If this is called, the map from user to device coordinates is
  280. assumed to preserve coordinate axes (it may be anisotropic [x and y
  281. directions scaled differently], and it may include a reflection through
  282. either or both axes). So it will be a circular or elliptic arc in the
  283. device frame, of the sort that libxmi supports. */
  284. void
  285. _pl_b_draw_elliptic_arc (R___(Plotter *_plotter) plPoint p0, plPoint p1, plPoint pc)
  286. {
  287. double radius;
  288. double theta0, theta1;
  289. int startangle, anglerange;
  290. int x_orientation, y_orientation;
  291. int xorigin, yorigin;
  292. unsigned int squaresize_x, squaresize_y;
  293. /* axes flipped? (by default y-axis is, due to xmi's flipped-y convention) */
  294. x_orientation = (_plotter->drawstate->transform.m[0] >= 0 ? 1 : -1);
  295. y_orientation = (_plotter->drawstate->transform.m[3] >= 0 ? 1 : -1);
  296. /* radius of circular arc in user frame is distance to p0, and also to p1 */
  297. radius = DIST(pc, p0);
  298. /* location of `origin' (upper left corner of bounding rect. on display)
  299. and width and height; X's flipped-y convention affects these values */
  300. xorigin = IROUND(XD(pc.x - x_orientation * radius,
  301. pc.y - y_orientation * radius));
  302. yorigin = IROUND(YD(pc.x - x_orientation * radius,
  303. pc.y - y_orientation * radius));
  304. squaresize_x = (unsigned int)IROUND(XDV(2 * x_orientation * radius, 0.0));
  305. squaresize_y = (unsigned int)IROUND(YDV(0.0, 2 * y_orientation * radius));
  306. theta0 = _xatan2 (-y_orientation * (p0.y - pc.y),
  307. x_orientation * (p0.x - pc.x)) / M_PI;
  308. theta1 = _xatan2 (-y_orientation * (p1.y - pc.y),
  309. x_orientation * (p1.x - pc.x)) / M_PI;
  310. if (theta1 < theta0)
  311. theta1 += 2.0; /* adjust so that difference > 0 */
  312. if (theta0 < 0.0)
  313. {
  314. theta0 += 2.0; /* adjust so that startangle > 0 */
  315. theta1 += 2.0;
  316. }
  317. if (theta1 - theta0 > 1.0) /* swap if angle appear to be > 180 degrees */
  318. {
  319. double tmp;
  320. tmp = theta0;
  321. theta0 = theta1;
  322. theta1 = tmp;
  323. theta1 += 2.0; /* adjust so that difference > 0 */
  324. }
  325. if (theta0 >= 2.0 && theta1 >= 2.0)
  326. /* avoid obscure X bug */
  327. {
  328. theta0 -= 2.0;
  329. theta1 -= 2.0;
  330. }
  331. startangle = IROUND(64 * theta0 * 180.0); /* in 64'ths of a degree */
  332. anglerange = IROUND(64 * (theta1 - theta0) * 180.0); /* likewise */
  333. _pl_b_draw_elliptic_arc_internal (R___(_plotter)
  334. xorigin, yorigin,
  335. squaresize_x, squaresize_y,
  336. startangle, anglerange);
  337. }
  338. /* Use libxmi rendering to draw what would be a quarter-ellipse in the user
  339. frame. If this is called, the map from user to device coordinates is
  340. assumed to preserve coordinate axes (it may be anisotropic [x and y
  341. directions scaled differently], and it may include a reflection through
  342. either or both axes). So it will be a quarter-ellipse in the device
  343. frame, of the sort that libxmi supports. */
  344. void
  345. _pl_b_draw_elliptic_arc_2 (R___(Plotter *_plotter) plPoint p0, plPoint p1, plPoint pc)
  346. {
  347. double rx, ry;
  348. double x0, y0, x1, y1, xc, yc;
  349. int startangle, endangle, anglerange;
  350. int x_orientation, y_orientation;
  351. int xorigin, yorigin;
  352. unsigned int squaresize_x, squaresize_y;
  353. /* axes flipped? (by default y-axis is, due to xmi's flipped-y convention) */
  354. x_orientation = (_plotter->drawstate->transform.m[0] >= 0 ? 1 : -1);
  355. y_orientation = (_plotter->drawstate->transform.m[3] >= 0 ? 1 : -1);
  356. xc = pc.x, yc = pc.y;
  357. x0 = p0.x, y0 = p0.y;
  358. x1 = p1.x, y1 = p1.y;
  359. if (y0 == yc && x1 == xc)
  360. /* initial pt. on x-axis, final pt. on y-axis */
  361. {
  362. /* semi-axes in user frame */
  363. rx = (x0 > xc) ? x0 - xc : xc - x0;
  364. ry = (y1 > yc) ? y1 - yc : yc - y1;
  365. /* starting and ending angles; note flipped-y convention */
  366. startangle = ((x0 > xc ? 1 : -1) * x_orientation == 1) ? 0 : 180;
  367. endangle = ((y1 > yc ? 1 : -1) * y_orientation == -1) ? 90 : 270;
  368. }
  369. else
  370. /* initial pt. on y-axis, final pt. on x-axis */
  371. {
  372. /* semi-axes in user frame */
  373. rx = (x1 > xc) ? x1 - xc : xc - x1;
  374. ry = (y0 > yc) ? y0 - yc : yc - y0;
  375. /* starting and ending angles; note flipped-y convention */
  376. startangle = ((y0 > yc ? 1 : -1) * y_orientation == -1) ? 90 : 270;
  377. endangle = ((x1 > xc ? 1 : -1) * x_orientation == 1) ? 0 : 180;
  378. }
  379. if (endangle < startangle)
  380. endangle += 360;
  381. anglerange = endangle - startangle; /* always 90 or 270 */
  382. /* our convention: a quarter-ellipse can only be 90 degrees
  383. of a libxmi ellipse, not 270 degrees, so interchange points */
  384. if (anglerange == 270)
  385. {
  386. int tmp;
  387. tmp = startangle;
  388. startangle = endangle;
  389. endangle = tmp;
  390. anglerange = 90;
  391. }
  392. if (startangle >= 360)
  393. /* avoid obscure libxmi bug */
  394. startangle -= 360; /* endangle no longer relevant */
  395. /* location of `origin' (upper left corner of bounding rect. on display)
  396. and width and height; xmi's flipped-y convention affects these values */
  397. xorigin = IROUND(XD(xc - x_orientation * rx,
  398. yc - y_orientation * ry));
  399. yorigin = IROUND(YD(xc - x_orientation * rx,
  400. yc - y_orientation * ry));
  401. squaresize_x = (unsigned int)IROUND(XDV(2 * x_orientation * rx, 0.0));
  402. squaresize_y = (unsigned int)IROUND(YDV(0.0, 2 * y_orientation * ry));
  403. /* reexpress in 64'ths of a degree (libxmi convention) */
  404. startangle *= 64;
  405. anglerange *= 64;
  406. _pl_b_draw_elliptic_arc_internal (R___(_plotter)
  407. xorigin, yorigin,
  408. squaresize_x, squaresize_y,
  409. startangle, anglerange);
  410. }
  411. /* Draw an elliptic arc aligned with the coordinate axes, by invoking
  412. functions in the libxmi API. Takes account of the possible need for
  413. filling.
  414. The cases squaresize_x = 0 and squaresize_y = 0 are handled specially,
  415. since miFillArcs() and miDrawArcs() do not support them. */
  416. void
  417. _pl_b_draw_elliptic_arc_internal (R___(Plotter *_plotter) int xorigin, int yorigin, unsigned int squaresize_x, unsigned int squaresize_y, int startangle, int anglerange)
  418. {
  419. miGC *pGC;
  420. miArc arc;
  421. miPixel fgPixel, bgPixel;
  422. miPixel pixels[2];
  423. miPoint offset;
  424. unsigned char red, green, blue;
  425. /* determine background pixel color */
  426. bgPixel.type = MI_PIXEL_RGB_TYPE;
  427. bgPixel.u.rgb[0] = _plotter->drawstate->bgcolor.red & 0xff;
  428. bgPixel.u.rgb[1] = _plotter->drawstate->bgcolor.green & 0xff;
  429. bgPixel.u.rgb[2] = _plotter->drawstate->bgcolor.blue & 0xff;
  430. pixels[0] = bgPixel;
  431. pixels[1] = bgPixel;
  432. /* construct an miGC (graphics context for the libxmi module); copy
  433. attributes from the Plotter's GC to it */
  434. pGC = miNewGC (2, pixels);
  435. _set_common_mi_attributes (_plotter->drawstate, (void *)pGC);
  436. /* libxmi's definition of an elliptic arc aligned with the axes */
  437. arc.x = xorigin;
  438. arc.y = yorigin;
  439. arc.width = squaresize_x;
  440. arc.height = squaresize_y;
  441. arc.angle1 = startangle;
  442. arc.angle2 = anglerange;
  443. if (_plotter->drawstate->fill_type)
  444. /* not transparent, so fill the arc */
  445. {
  446. double red_d, green_d, blue_d;
  447. double desaturate;
  448. /* scale fillcolor RGB values from 16-bits to range [0.0,1.0] */
  449. red_d = ((double)((_plotter->drawstate->fillcolor).red))/0xFFFF;
  450. green_d = ((double)((_plotter->drawstate->fillcolor).green))/0xFFFF;
  451. blue_d = ((double)((_plotter->drawstate->fillcolor).blue))/0xFFFF;
  452. /* fill_type, if nonzero, specifies the extent to which the
  453. nominal fill color should be desaturated. 1 means no
  454. desaturation, 0xffff means complete desaturation (white). */
  455. desaturate = ((double)_plotter->drawstate->fill_type - 1.)/0xFFFE;
  456. red_d = red_d + desaturate * (1.0 - red_d);
  457. green_d = green_d + desaturate * (1.0 - green_d);
  458. blue_d = blue_d + desaturate * (1.0 - blue_d);
  459. /* convert desaturated RGB values to 8 bits each (24 bits in all) */
  460. red = IROUND(0xff * red_d);
  461. green = IROUND(0xff * green_d);
  462. blue = IROUND(0xff * blue_d);
  463. /* set fg color in GC to the 24-bit desaturated RGB (and set bg color
  464. too) */
  465. fgPixel.type = MI_PIXEL_RGB_TYPE;
  466. fgPixel.u.rgb[0] = red;
  467. fgPixel.u.rgb[1] = green;
  468. fgPixel.u.rgb[2] = blue;
  469. pixels[0] = bgPixel;
  470. pixels[1] = fgPixel;
  471. miSetGCPixels (pGC, 2, pixels);
  472. /* fill the arc */
  473. if (squaresize_x <= 1 || squaresize_y <= 1)
  474. /* a special case, which miFillArcs() doesn't handle in the way we'd
  475. like; just paint a single pixel, irrespective of angle range */
  476. {
  477. miPoint point;
  478. point.x = xorigin;
  479. point.y = yorigin;
  480. miDrawPoints ((miPaintedSet *)_plotter->b_painted_set,
  481. pGC, MI_COORD_MODE_ORIGIN, 1, &point);
  482. }
  483. else
  484. /* default case */
  485. miFillArcs ((miPaintedSet *)_plotter->b_painted_set, pGC, 1, &arc);
  486. }
  487. if (_plotter->drawstate->pen_type)
  488. /* pen is present, so edge the arc */
  489. {
  490. unsigned int sp_size = 0; /* keep compiler happy */
  491. /* set fg color in GC to a 24-bit version of our pen color (and set
  492. bg color too) */
  493. red = ((unsigned int)(_plotter->drawstate->fgcolor.red) >> 8) & 0xff;
  494. green = ((unsigned int)(_plotter->drawstate->fgcolor.green) >> 8) & 0xff;
  495. blue = ((unsigned int)(_plotter->drawstate->fgcolor.blue) >> 8) & 0xff;
  496. fgPixel.type = MI_PIXEL_RGB_TYPE;
  497. fgPixel.u.rgb[0] = red;
  498. fgPixel.u.rgb[1] = green;
  499. fgPixel.u.rgb[2] = blue;
  500. pixels[0] = bgPixel;
  501. pixels[1] = fgPixel;
  502. miSetGCPixels (pGC, 2, pixels);
  503. if (squaresize_x <= 1 || squaresize_y <= 1)
  504. /* Won't call miDrawArcs in the usual way, because it performs
  505. poorly when one of these two is zero, at least. Irrespective of
  506. angle range, will fill a disk of diameter equal to line width */
  507. {
  508. int sp_offset;
  509. sp_size
  510. = (unsigned int)_plotter->drawstate->quantized_device_line_width;
  511. sp_offset
  512. = (int)(_plotter->drawstate->quantized_device_line_width + 1) / 2;
  513. if (sp_size == 0)
  514. sp_size = 1;
  515. arc.x -= sp_offset;
  516. arc.y -= sp_offset;
  517. arc.width = sp_size;
  518. arc.height = sp_size;
  519. arc.angle1 = 0;
  520. arc.angle2 = 64 * 360;
  521. }
  522. /* edge the arc by invoking libxmi's reentrant arc-drawing function,
  523. passing it as final argument a pointer to persistent storage
  524. maintained by the Plotter */
  525. if (squaresize_x <= 1 || squaresize_y <= 1)
  526. /* miDrawArcs doesn't handle this case as we'd wish, will
  527. treat specially */
  528. {
  529. if (sp_size == 1)
  530. /* special subcase: line width is small too, so just paint a
  531. single pixel rather than filling abovementioned disk */
  532. {
  533. miPoint point;
  534. point.x = xorigin;
  535. point.y = yorigin;
  536. miDrawPoints ((miPaintedSet *)_plotter->b_painted_set,
  537. pGC, MI_COORD_MODE_ORIGIN, 1, &point);
  538. }
  539. else
  540. /* normal version of special case: draw filled disk of diameter
  541. equal to the line width, irrespective of the angle range */
  542. miFillArcs((miPaintedSet *)_plotter->b_painted_set, pGC, 1, &arc);
  543. }
  544. else
  545. /* default case, which is what is almost always used */
  546. miDrawArcs_r ((miPaintedSet *)_plotter->b_painted_set, pGC, 1, &arc,
  547. (miEllipseCache *)(_plotter->b_arc_cache_data));
  548. }
  549. /* deallocate miGC */
  550. miDeleteGC (pGC);
  551. /* copy from painted set to canvas, and clear */
  552. offset.x = 0;
  553. offset.y = 0;
  554. miCopyPaintedSetToCanvas ((miPaintedSet *)_plotter->b_painted_set,
  555. (miCanvas *)_plotter->b_canvas,
  556. offset);
  557. miClearPaintedSet ((miPaintedSet *)_plotter->b_painted_set);
  558. }
  559. bool
  560. _pl_b_paint_paths (S___(Plotter *_plotter))
  561. {
  562. return false;
  563. }