PageRenderTime 39ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/nx-3.5.0/nx-X11/programs/Xserver/afb/afbbres.c

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