PageRenderTime 66ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/nx-3.5.0/nx-X11/programs/Xserver/mfb/mfbbres.c

#
C | 370 lines | 310 code | 6 blank | 54 comment | 61 complexity | 2d7436b23367815d5f7a677ae2e7102e MD5 | raw file
Possible License(s): BSD-3-Clause, GPL-2.0, LGPL-2.0
  1. /* Combined Purdue/PurduePlus patches, level 2.0, 1/17/89 */
  2. /* $XFree86: xc/programs/Xserver/mfb/mfbbres.c,v 1.4 2001/01/17 22:37:02 dawes Exp $ */
  3. /***********************************************************
  4. Copyright 1987, 1998 The Open Group
  5. Permission to use, copy, modify, distribute, and sell this software and its
  6. documentation for any purpose is hereby granted without fee, provided that
  7. the above copyright notice appear in all copies and that both that
  8. copyright notice and this permission notice appear in supporting
  9. documentation.
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  16. AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  17. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  18. Except as contained in this notice, the name of The Open Group shall not be
  19. used in advertising or otherwise to promote the sale, use or other dealings
  20. in this Software without prior written authorization from The Open Group.
  21. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
  22. All Rights Reserved
  23. Permission to use, copy, modify, and distribute this software and its
  24. documentation for any purpose and without fee is hereby granted,
  25. provided that the above copyright notice appear in all copies and that
  26. both that copyright notice and this permission notice appear in
  27. supporting documentation, and that the name of Digital not be
  28. used in advertising or publicity pertaining to distribution of the
  29. software without specific, written prior permission.
  30. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  31. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  32. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  33. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  34. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  35. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  36. SOFTWARE.
  37. ******************************************************************/
  38. /* $Xorg: mfbbres.c,v 1.4 2001/02/09 02:05:18 xorgcvs Exp $ */
  39. #ifdef HAVE_DIX_CONFIG_H
  40. #include <dix-config.h>
  41. #endif
  42. #include <X11/X.h>
  43. #include "misc.h"
  44. #include "mfb.h"
  45. #include "maskbits.h"
  46. #include "miline.h"
  47. /* Solid bresenham line */
  48. /* NOTES
  49. e2 is used less often than e1, so it's not in a register
  50. */
  51. void
  52. mfbBresS(rop, addrlbase, nlwidth, signdx, signdy, axis, x1, y1, e, e1, e2, len)
  53. int rop; /* a reduced rasterop */
  54. PixelType *addrlbase; /* pointer to base of bitmap */
  55. int nlwidth; /* width in longwords of bitmap */
  56. int signdx, signdy; /* signs of directions */
  57. int axis; /* major axis (Y_AXIS or X_AXIS) */
  58. int x1, y1; /* initial point */
  59. register int e; /* error accumulator */
  60. register int e1; /* bresenham increments */
  61. int e2;
  62. int len; /* length of line */
  63. {
  64. register int yinc; /* increment to next scanline, in bytes */
  65. register PixelType *addrl; /* bitmask 32-bit pointer */
  66. register PixelType bit; /* current bit being set/cleared/etc. */
  67. PixelType leftbit = mask[0]; /* leftmost bit to process in new word */
  68. PixelType rightbit = mask[PPW-1]; /* rightmost bit to process in new word */
  69. register int e3 = e2-e1;
  70. PixelType tmp;
  71. /* point to longword containing first point */
  72. addrl = mfbScanline(addrlbase, x1, y1, nlwidth);
  73. yinc = signdy * nlwidth;
  74. e = e-e1; /* to make looping easier */
  75. bit = mask[x1 & PIM];
  76. if (!len)
  77. return;
  78. if (rop == RROP_BLACK)
  79. {
  80. if (axis == X_AXIS)
  81. {
  82. if (signdx > 0)
  83. {
  84. tmp = *addrl;
  85. for (;;)
  86. {
  87. tmp &= ~bit;
  88. if (!--len)
  89. break;
  90. bit = SCRRIGHT(bit,1);
  91. e += e1;
  92. if (e >= 0)
  93. {
  94. *addrl = tmp;
  95. mfbScanlineInc(addrl, yinc);
  96. e += e3;
  97. if (!bit)
  98. {
  99. bit = leftbit;
  100. addrl ++;
  101. }
  102. tmp = *addrl;
  103. }
  104. else if (!bit)
  105. {
  106. *addrl = tmp;
  107. bit = leftbit;
  108. addrl ++;
  109. tmp = *addrl;
  110. }
  111. }
  112. *addrl = tmp;
  113. }
  114. else
  115. {
  116. tmp = *addrl;
  117. for (;;)
  118. {
  119. tmp &= ~bit;
  120. if (!--len)
  121. break;
  122. e += e1;
  123. bit = SCRLEFT(bit,1);
  124. if (e >= 0)
  125. {
  126. *addrl = tmp;
  127. mfbScanlineInc(addrl, yinc);
  128. e += e3;
  129. if (!bit)
  130. {
  131. bit = rightbit;
  132. addrl --;
  133. }
  134. tmp = *addrl;
  135. }
  136. else if (!bit)
  137. {
  138. *addrl = tmp;
  139. bit = rightbit;
  140. addrl --;
  141. tmp = *addrl;
  142. }
  143. }
  144. *addrl = tmp;
  145. }
  146. } /* if X_AXIS */
  147. else
  148. {
  149. if (signdx > 0)
  150. {
  151. while(len--)
  152. {
  153. *addrl &= ~bit;
  154. e += e1;
  155. if (e >= 0)
  156. {
  157. bit = SCRRIGHT(bit,1);
  158. if (!bit) { bit = leftbit;addrl ++; }
  159. e += e3;
  160. }
  161. mfbScanlineInc(addrl, yinc);
  162. }
  163. }
  164. else
  165. {
  166. while(len--)
  167. {
  168. *addrl &= ~bit;
  169. e += e1;
  170. if (e >= 0)
  171. {
  172. bit = SCRLEFT(bit,1);
  173. if (!bit) { bit = rightbit;addrl --; }
  174. e += e3;
  175. }
  176. mfbScanlineInc(addrl, yinc);
  177. }
  178. }
  179. } /* else Y_AXIS */
  180. }
  181. else if (rop == RROP_WHITE)
  182. {
  183. if (axis == X_AXIS)
  184. {
  185. if (signdx > 0)
  186. {
  187. tmp = *addrl;
  188. for (;;)
  189. {
  190. tmp |= bit;
  191. if (!--len)
  192. break;
  193. e += e1;
  194. bit = SCRRIGHT(bit,1);
  195. if (e >= 0)
  196. {
  197. *addrl = tmp;
  198. mfbScanlineInc(addrl, yinc);
  199. e += e3;
  200. if (!bit)
  201. {
  202. bit = leftbit;
  203. addrl ++;
  204. }
  205. tmp = *addrl;
  206. }
  207. else if (!bit)
  208. {
  209. *addrl = tmp;
  210. bit = leftbit;
  211. addrl ++;
  212. tmp = *addrl;
  213. }
  214. }
  215. *addrl = tmp;
  216. }
  217. else
  218. {
  219. tmp = *addrl;
  220. for (;;)
  221. {
  222. tmp |= bit;
  223. if (!--len)
  224. break;
  225. e += e1;
  226. bit = SCRLEFT(bit,1);
  227. if (e >= 0)
  228. {
  229. *addrl = tmp;
  230. mfbScanlineInc(addrl, yinc);
  231. e += e3;
  232. if (!bit)
  233. {
  234. bit = rightbit;
  235. addrl --;
  236. }
  237. tmp = *addrl;
  238. }
  239. else if (!bit)
  240. {
  241. *addrl = tmp;
  242. bit = rightbit;
  243. addrl --;
  244. tmp = *addrl;
  245. }
  246. }
  247. *addrl = tmp;
  248. }
  249. } /* if X_AXIS */
  250. else
  251. {
  252. if (signdx > 0)
  253. {
  254. while(len--)
  255. {
  256. *addrl |= bit;
  257. e += e1;
  258. if (e >= 0)
  259. {
  260. bit = SCRRIGHT(bit,1);
  261. if (!bit) { bit = leftbit;addrl ++; }
  262. e += e3;
  263. }
  264. mfbScanlineInc(addrl, yinc);
  265. }
  266. }
  267. else
  268. {
  269. while(len--)
  270. {
  271. *addrl |= bit;
  272. e += e1;
  273. if (e >= 0)
  274. {
  275. bit = SCRLEFT(bit,1);
  276. if (!bit) { bit = rightbit;addrl --; }
  277. e += e3;
  278. }
  279. mfbScanlineInc(addrl, yinc);
  280. }
  281. }
  282. } /* else Y_AXIS */
  283. }
  284. else if (rop == RROP_INVERT)
  285. {
  286. if (axis == X_AXIS)
  287. {
  288. if (signdx > 0)
  289. {
  290. while(len--)
  291. {
  292. *addrl ^= bit;
  293. e += e1;
  294. if (e >= 0)
  295. {
  296. mfbScanlineInc(addrl, yinc);
  297. e += e3;
  298. }
  299. bit = SCRRIGHT(bit,1);
  300. if (!bit) { bit = leftbit;addrl ++; }
  301. }
  302. }
  303. else
  304. {
  305. while(len--)
  306. {
  307. *addrl ^= bit;
  308. e += e1;
  309. if (e >= 0)
  310. {
  311. mfbScanlineInc(addrl, yinc);
  312. e += e3;
  313. }
  314. bit = SCRLEFT(bit,1);
  315. if (!bit) { bit = rightbit;addrl --; }
  316. }
  317. }
  318. } /* if X_AXIS */
  319. else
  320. {
  321. if (signdx > 0)
  322. {
  323. while(len--)
  324. {
  325. *addrl ^= bit;
  326. e += e1;
  327. if (e >= 0)
  328. {
  329. bit = SCRRIGHT(bit,1);
  330. if (!bit) { bit = leftbit;addrl ++; }
  331. e += e3;
  332. }
  333. mfbScanlineInc(addrl, yinc);
  334. }
  335. }
  336. else
  337. {
  338. while(len--)
  339. {
  340. *addrl ^= bit;
  341. e += e1;
  342. if (e >= 0)
  343. {
  344. bit = SCRLEFT(bit,1);
  345. if (!bit) { bit = rightbit; addrl --; }
  346. e += e3;
  347. }
  348. mfbScanlineInc(addrl, yinc);
  349. }
  350. }
  351. } /* else Y_AXIS */
  352. }
  353. }