PageRenderTime 80ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/nx-3.5.0/nx-X11/programs/Xserver/cfb/cfbbres.c

#
C | 342 lines | 278 code | 10 blank | 54 comment | 38 complexity | 2a5adde25f7597c6147b5e6d73295dec MD5 | raw file
Possible License(s): BSD-3-Clause, GPL-2.0, LGPL-2.0
  1. /* $XFree86: xc/programs/Xserver/cfb/cfbbres.c,v 3.4 2001/01/17 22:36:34 dawes Exp $ */
  2. /***********************************************************
  3. Copyright 1987, 1998 The Open Group
  4. Permission to use, copy, modify, distribute, and sell this software and its
  5. documentation for any purpose is hereby granted without fee, provided that
  6. the above copyright notice appear in all copies and that both that
  7. copyright notice and this permission notice appear in supporting
  8. documentation.
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  15. AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  16. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  17. Except as contained in this notice, the name of The Open Group shall not be
  18. used in advertising or otherwise to promote the sale, use or other dealings
  19. in this Software without prior written authorization from The Open Group.
  20. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
  21. All Rights Reserved
  22. Permission to use, copy, modify, and distribute this software and its
  23. documentation for any purpose and without fee is hereby granted,
  24. provided that the above copyright notice appear in all copies and that
  25. both that copyright notice and this permission notice appear in
  26. supporting documentation, and that the name of Digital not be
  27. used in advertising or publicity pertaining to distribution of the
  28. software without specific, written prior permission.
  29. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  30. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  31. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  32. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  33. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  34. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  35. SOFTWARE.
  36. ******************************************************************/
  37. /* $Xorg: cfbbres.c,v 1.4 2001/02/09 02:04:37 xorgcvs Exp $ */
  38. #ifdef HAVE_DIX_CONFIG_H
  39. #include <dix-config.h>
  40. #endif
  41. #include <X11/X.h>
  42. #include "misc.h"
  43. #include "cfb.h"
  44. #include "cfbmskbits.h"
  45. #include "servermd.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. cfbBresS(rop, and, xor, addrl, nlwidth, signdx, signdy, axis, x1, y1, e, e1,
  53. e2, len)
  54. int rop;
  55. CfbBits and, xor;
  56. CfbBits *addrl; /* pointer to base of bitmap */
  57. int nlwidth; /* width in longwords of bitmap */
  58. register int signdx;
  59. int 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. {
  67. register int e3 = e2-e1;
  68. #if PSZ == 24
  69. CfbBits piQxelXor[3],piQxelAnd[3];
  70. char *addrb;
  71. int nlwidth3, signdx3;
  72. #endif
  73. #ifdef PIXEL_ADDR
  74. register PixelType *addrp; /* Pixel pointer */
  75. if (len == 0)
  76. return;
  77. /* point to first point */
  78. nlwidth <<= PWSH;
  79. #if PSZ == 24
  80. addrp = (PixelType *)(addrl) + (y1 * nlwidth);
  81. addrb = (char *)addrp + x1 * 3;
  82. piQxelXor[0] = (xor << 24) | xor;
  83. piQxelXor[1] = (xor << 16)| (xor >> 8);
  84. piQxelXor[2] = (xor << 8) | (xor >> 16);
  85. piQxelAnd[0] = (and << 24) | and;
  86. piQxelAnd[1] = (and << 16)| (and >> 8);
  87. piQxelAnd[2] = (and << 8) | (and >> 16);
  88. #else
  89. addrp = (PixelType *)(addrl) + (y1 * nlwidth) + x1;
  90. #endif
  91. if (signdy < 0)
  92. nlwidth = -nlwidth;
  93. e = e-e1; /* to make looping easier */
  94. #if PSZ == 24
  95. nlwidth3 = nlwidth * sizeof (CfbBits);
  96. signdx3 = signdx * 3;
  97. #endif
  98. if (axis == Y_AXIS)
  99. {
  100. int t;
  101. t = nlwidth;
  102. nlwidth = signdx;
  103. signdx = t;
  104. #if PSZ == 24
  105. t = nlwidth3;
  106. nlwidth3 = signdx3;
  107. signdx3 = t;
  108. #endif
  109. }
  110. if (rop == GXcopy)
  111. {
  112. --len;
  113. #if PSZ == 24
  114. #define body_copy \
  115. addrp = (PixelType *)((unsigned long)addrb & ~0x03); \
  116. switch((unsigned long)addrb & 3){ \
  117. case 0: \
  118. *addrp = ((*addrp)&0xFF000000)|(piQxelXor[0] & 0xFFFFFF); \
  119. break; \
  120. case 1: \
  121. *addrp = ((*addrp)&0xFF)|(piQxelXor[2] & 0xFFFFFF00); \
  122. break; \
  123. case 3: \
  124. *addrp = ((*addrp)&0xFFFFFF)|(piQxelXor[0] & 0xFF000000); \
  125. *(addrp+1) = ((*(addrp+1))&0xFFFF0000)|(piQxelXor[1] & 0xFFFF); \
  126. break; \
  127. case 2: \
  128. *addrp = ((*addrp)&0xFFFF)|(piQxelXor[1] & 0xFFFF0000); \
  129. *(addrp+1) = ((*(addrp+1))&0xFFFFFF00)|(piQxelXor[2] & 0xFF); \
  130. break; \
  131. }
  132. #define body {\
  133. body_copy \
  134. addrb += signdx3; \
  135. e += e1; \
  136. if (e >= 0) \
  137. { \
  138. addrb += nlwidth3; \
  139. e += e3; \
  140. } \
  141. }
  142. #else /* PSZ == 24 */
  143. #define body {\
  144. *addrp = xor; \
  145. addrp += signdx; \
  146. e += e1; \
  147. if (e >= 0) \
  148. { \
  149. addrp += nlwidth; \
  150. e += e3; \
  151. } \
  152. }
  153. #endif /* PSZ == 24 */
  154. while (len >= 4)
  155. {
  156. body body body body
  157. len -= 4;
  158. }
  159. switch (len)
  160. {
  161. case 3: body case 2: body case 1: body
  162. }
  163. #undef body
  164. #if PSZ == 24
  165. body_copy
  166. # undef body_copy
  167. #else
  168. *addrp = xor;
  169. #endif
  170. }
  171. else /* not GXcopy */
  172. {
  173. while(len--)
  174. {
  175. #if PSZ == 24
  176. addrp = (PixelType *)((unsigned long)addrb & ~0x03);
  177. switch((unsigned long)addrb & 3){
  178. case 0:
  179. *addrp = (*addrp & (piQxelAnd[0]|0xFF000000))
  180. ^ (piQxelXor[0] & 0xFFFFFF);
  181. break;
  182. case 1:
  183. *addrp = (*addrp & (piQxelAnd[2]|0xFF))
  184. ^ (piQxelXor[2] & 0xFFFFFF00);
  185. break;
  186. case 3:
  187. *addrp = (*addrp & (piQxelAnd[0]|0xFFFFFF))
  188. ^ (piQxelXor[0] & 0xFF000000);
  189. *(addrp+1) = (*(addrp+1) & (piQxelAnd[1]|0xFFFF0000))
  190. ^ (piQxelXor[1] & 0xFFFF);
  191. break;
  192. case 2:
  193. *addrp = (*addrp & (piQxelAnd[1]|0xFFFF))
  194. ^ (piQxelXor[1] & 0xFFFF0000);
  195. *(addrp+1) = (*(addrp+1) & (piQxelAnd[2]|0xFFFFFF00))
  196. ^ (piQxelXor[2] & 0xFF);
  197. break;
  198. }
  199. e += e1;
  200. if (e >= 0)
  201. {
  202. addrb += nlwidth3;
  203. e += e3;
  204. }
  205. addrb += signdx3;
  206. #else /* PSZ == 24 */
  207. *addrp = DoRRop (*addrp, and, xor);
  208. e += e1;
  209. if (e >= 0)
  210. {
  211. addrp += nlwidth;
  212. e += e3;
  213. }
  214. addrp += signdx;
  215. #endif /* PSZ == 24 */
  216. }
  217. }
  218. #else /* !PIXEL_ADDR */
  219. register CfbBits tmp, bit;
  220. CfbBits leftbit, rightbit;
  221. /* point to longword containing first point */
  222. #if PSZ == 24
  223. addrl = (addrl + (y1 * nlwidth) + ((x1 * 3) >>2);
  224. #else
  225. addrl = (addrl + (y1 * nlwidth) + (x1 >> PWSH));
  226. #endif
  227. if (signdy < 0)
  228. nlwidth = -nlwidth;
  229. e = e-e1; /* to make looping easier */
  230. leftbit = cfbmask[0];
  231. #if PSZ == 24
  232. rightbit = cfbmask[(PPW-1)<<1];
  233. bit = cfbmask[(x1 & 3)<<1];
  234. #else
  235. rightbit = cfbmask[PPW-1];
  236. bit = cfbmask[x1 & PIM];
  237. #endif
  238. if (axis == X_AXIS)
  239. {
  240. if (signdx > 0)
  241. {
  242. while (len--)
  243. {
  244. *addrl = DoMaskRRop (*addrl, and, xor, bit);
  245. bit = SCRRIGHT(bit,1);
  246. e += e1;
  247. if (e >= 0)
  248. {
  249. addrl += nlwidth;
  250. e += e3;
  251. }
  252. if (!bit)
  253. {
  254. bit = leftbit;
  255. addrl++;
  256. }
  257. }
  258. }
  259. else
  260. {
  261. while (len--)
  262. {
  263. *addrl = DoMaskRRop (*addrl, and, xor, bit);
  264. e += e1;
  265. bit = SCRLEFT(bit,1);
  266. if (e >= 0)
  267. {
  268. addrl += nlwidth;
  269. e += e3;
  270. }
  271. if (!bit)
  272. {
  273. bit = rightbit;
  274. addrl--;
  275. }
  276. }
  277. }
  278. } /* if X_AXIS */
  279. else
  280. {
  281. if (signdx > 0)
  282. {
  283. while(len--)
  284. {
  285. *addrl = DoMaskRRop (*addrl, and, xor, bit);
  286. e += e1;
  287. if (e >= 0)
  288. {
  289. bit = SCRRIGHT(bit,1);
  290. if (!bit)
  291. {
  292. bit = leftbit;
  293. addrl++;
  294. }
  295. e += e3;
  296. }
  297. addrl += nlwidth;
  298. }
  299. }
  300. else
  301. {
  302. while(len--)
  303. {
  304. *addrl = DoMaskRRop (*addrl, and, xor, bit);
  305. e += e1;
  306. if (e >= 0)
  307. {
  308. bit = SCRLEFT(bit,1);
  309. if (!bit)
  310. {
  311. bit = rightbit;
  312. addrl--;
  313. }
  314. e += e3;
  315. }
  316. addrl += nlwidth;
  317. }
  318. }
  319. } /* else Y_AXIS */
  320. #endif
  321. }