fbbltone.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841
  1. /*
  2. *
  3. * Copyright © 1998 Keith Packard
  4. *
  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, and that the name of Keith Packard not be used in
  10. * advertising or publicity pertaining to distribution of the software without
  11. * specific, written prior permission. Keith Packard makes no
  12. * representations about the suitability of this software for any purpose. It
  13. * is provided "as is" without express or implied warranty.
  14. *
  15. * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  16. * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  17. * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  18. * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  19. * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  20. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  21. * PERFORMANCE OF THIS SOFTWARE.
  22. */
  23. #ifdef HAVE_DIX_CONFIG_H
  24. #include <dix-config.h>
  25. #endif
  26. #include "fb.h"
  27. /*
  28. * Example: srcX = 13 dstX = 8 (FB unit 32 dstBpp 8)
  29. *
  30. * **** **** **** **** **** **** **** ****
  31. * ^
  32. * ******** ******** ******** ********
  33. * ^
  34. * leftShift = 12
  35. * rightShift = 20
  36. *
  37. * Example: srcX = 0 dstX = 8 (FB unit 32 dstBpp 8)
  38. *
  39. * **** **** **** **** **** **** **** ****
  40. * ^
  41. * ******** ******** ******** ********
  42. * ^
  43. *
  44. * leftShift = 24
  45. * rightShift = 8
  46. */
  47. #define LoadBits {\
  48. if (leftShift) { \
  49. bitsRight = (src < srcEnd ? *src++ : 0); \
  50. bits = (FbStipLeft (bitsLeft, leftShift) | \
  51. FbStipRight(bitsRight, rightShift)); \
  52. bitsLeft = bitsRight; \
  53. } else \
  54. bits = (src < srcEnd ? *src++ : 0); \
  55. }
  56. #define LaneCases1(n,a) case n: (void)FbLaneCase(n,a); break
  57. #define LaneCases2(n,a) LaneCases1(n,a); LaneCases1(n+1,a)
  58. #define LaneCases4(n,a) LaneCases2(n,a); LaneCases2(n+2,a)
  59. #define LaneCases8(n,a) LaneCases4(n,a); LaneCases4(n+4,a)
  60. #define LaneCases16(n,a) LaneCases8(n,a); LaneCases8(n+8,a)
  61. #define LaneCases32(n,a) LaneCases16(n,a); LaneCases16(n+16,a)
  62. #define LaneCases64(n,a) LaneCases32(n,a); LaneCases32(n+32,a)
  63. #define LaneCases128(n,a) LaneCases64(n,a); LaneCases64(n+64,a)
  64. #define LaneCases256(n,a) LaneCases128(n,a); LaneCases128(n+128,a)
  65. #if FB_SHIFT == 6
  66. #define LaneCases(a) LaneCases256(0,a)
  67. #endif
  68. #if FB_SHIFT == 5
  69. #define LaneCases(a) LaneCases16(0,a)
  70. #endif
  71. #if FB_SHIFT == 6
  72. static const CARD8 fb8Lane[256] = {
  73. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
  74. 21,
  75. 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
  76. 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
  77. 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78,
  78. 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97,
  79. 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112,
  80. 113, 114, 115,
  81. 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130,
  82. 131, 132, 133,
  83. 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148,
  84. 149, 150, 151,
  85. 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166,
  86. 167, 168, 169,
  87. 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184,
  88. 185, 186, 187,
  89. 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202,
  90. 203, 204, 205,
  91. 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220,
  92. 221, 222, 223,
  93. 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238,
  94. 239, 240, 241,
  95. 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255,
  96. };
  97. static const CARD8 fb16Lane[256] = {
  98. 0x00, 0x03, 0x0c, 0x0f,
  99. 0x30, 0x33, 0x3c, 0x3f,
  100. 0xc0, 0xc3, 0xcc, 0xcf,
  101. 0xf0, 0xf3, 0xfc, 0xff,
  102. };
  103. static const CARD8 fb32Lane[16] = {
  104. 0x00, 0x0f, 0xf0, 0xff,
  105. };
  106. #endif
  107. #if FB_SHIFT == 5
  108. static const CARD8 fb8Lane[16] = {
  109. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
  110. };
  111. static const CARD8 fb16Lane[16] = {
  112. 0, 3, 12, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113. };
  114. static const CARD8 fb32Lane[16] = {
  115. 0, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116. };
  117. #endif
  118. static const CARD8 * const fbLaneTable[33] = {
  119. 0, 0, 0, 0, 0, 0, 0, 0,
  120. fb8Lane, 0, 0, 0, 0, 0, 0, 0,
  121. fb16Lane, 0, 0, 0, 0, 0, 0, 0,
  122. 0, 0, 0, 0, 0, 0, 0, 0,
  123. fb32Lane
  124. };
  125. void
  126. fbBltOne(FbStip * src, FbStride srcStride, /* FbStip units per scanline */
  127. int srcX, /* bit position of source */
  128. FbBits * dst, FbStride dstStride, /* FbBits units per scanline */
  129. int dstX, /* bit position of dest */
  130. int dstBpp, /* bits per destination unit */
  131. int width, /* width in bits of destination */
  132. int height, /* height in scanlines */
  133. FbBits fgand, /* rrop values */
  134. FbBits fgxor, FbBits bgand, FbBits bgxor)
  135. {
  136. const FbBits *fbBits;
  137. FbBits *srcEnd;
  138. int pixelsPerDst; /* dst pixels per FbBits */
  139. int unitsPerSrc; /* src patterns per FbStip */
  140. int leftShift, rightShift; /* align source with dest */
  141. FbBits startmask, endmask; /* dest scanline masks */
  142. FbStip bits = 0, bitsLeft, bitsRight; /* source bits */
  143. FbStip left;
  144. FbBits mask;
  145. int nDst; /* dest longwords (w.o. end) */
  146. int w;
  147. int n, nmiddle;
  148. int dstS; /* stipple-relative dst X coordinate */
  149. Bool copy; /* accelerate dest-invariant */
  150. Bool transparent; /* accelerate 0 nop */
  151. int srcinc; /* source units consumed */
  152. Bool endNeedsLoad = FALSE; /* need load for endmask */
  153. const CARD8 *fbLane;
  154. int startbyte, endbyte;
  155. if (dstBpp == 24) {
  156. fbBltOne24(src, srcStride, srcX,
  157. dst, dstStride, dstX, dstBpp,
  158. width, height, fgand, fgxor, bgand, bgxor);
  159. return;
  160. }
  161. /*
  162. * Do not read past the end of the buffer!
  163. */
  164. srcEnd = src + height * srcStride;
  165. /*
  166. * Number of destination units in FbBits == number of stipple pixels
  167. * used each time
  168. */
  169. pixelsPerDst = FB_UNIT / dstBpp;
  170. /*
  171. * Number of source stipple patterns in FbStip
  172. */
  173. unitsPerSrc = FB_STIP_UNIT / pixelsPerDst;
  174. copy = FALSE;
  175. transparent = FALSE;
  176. if (bgand == 0 && fgand == 0)
  177. copy = TRUE;
  178. else if (bgand == FB_ALLONES && bgxor == 0)
  179. transparent = TRUE;
  180. /*
  181. * Adjust source and dest to nearest FbBits boundary
  182. */
  183. src += srcX >> FB_STIP_SHIFT;
  184. dst += dstX >> FB_SHIFT;
  185. srcX &= FB_STIP_MASK;
  186. dstX &= FB_MASK;
  187. FbMaskBitsBytes(dstX, width, copy,
  188. startmask, startbyte, nmiddle, endmask, endbyte);
  189. /*
  190. * Compute effective dest alignment requirement for
  191. * source -- must align source to dest unit boundary
  192. */
  193. dstS = dstX / dstBpp;
  194. /*
  195. * Compute shift constants for effective alignement
  196. */
  197. if (srcX >= dstS) {
  198. leftShift = srcX - dstS;
  199. rightShift = FB_STIP_UNIT - leftShift;
  200. }
  201. else {
  202. rightShift = dstS - srcX;
  203. leftShift = FB_STIP_UNIT - rightShift;
  204. }
  205. /*
  206. * Get pointer to stipple mask array for this depth
  207. */
  208. fbBits = 0; /* unused */
  209. if (pixelsPerDst <= 8)
  210. fbBits = fbStippleTable[pixelsPerDst];
  211. fbLane = 0;
  212. if (transparent && fgand == 0 && dstBpp >= 8)
  213. fbLane = fbLaneTable[dstBpp];
  214. /*
  215. * Compute total number of destination words written, but
  216. * don't count endmask
  217. */
  218. nDst = nmiddle;
  219. if (startmask)
  220. nDst++;
  221. dstStride -= nDst;
  222. /*
  223. * Compute total number of source words consumed
  224. */
  225. srcinc = (nDst + unitsPerSrc - 1) / unitsPerSrc;
  226. if (srcX > dstS)
  227. srcinc++;
  228. if (endmask) {
  229. endNeedsLoad = nDst % unitsPerSrc == 0;
  230. if (endNeedsLoad)
  231. srcinc++;
  232. }
  233. srcStride -= srcinc;
  234. /*
  235. * Copy rectangle
  236. */
  237. while (height--) {
  238. w = nDst; /* total units across scanline */
  239. n = unitsPerSrc; /* units avail in single stipple */
  240. if (n > w)
  241. n = w;
  242. bitsLeft = 0;
  243. if (srcX > dstS)
  244. bitsLeft = *src++;
  245. if (n) {
  246. /*
  247. * Load first set of stipple bits
  248. */
  249. LoadBits;
  250. /*
  251. * Consume stipple bits for startmask
  252. */
  253. if (startmask) {
  254. #if FB_UNIT > 32
  255. if (pixelsPerDst == 16)
  256. mask = FbStipple16Bits(FbLeftStipBits(bits, 16));
  257. else
  258. #endif
  259. mask = fbBits[FbLeftStipBits(bits, pixelsPerDst)];
  260. if (fbLane) {
  261. fbTransparentSpan(dst, mask & startmask, fgxor, 1);
  262. }
  263. else
  264. {
  265. if (mask || !transparent)
  266. FbDoLeftMaskByteStippleRRop(dst, mask,
  267. fgand, fgxor, bgand, bgxor,
  268. startbyte, startmask);
  269. }
  270. bits = FbStipLeft(bits, pixelsPerDst);
  271. dst++;
  272. n--;
  273. w--;
  274. }
  275. /*
  276. * Consume stipple bits across scanline
  277. */
  278. for (;;) {
  279. w -= n;
  280. if (copy) {
  281. while (n--) {
  282. #if FB_UNIT > 32
  283. if (pixelsPerDst == 16)
  284. mask = FbStipple16Bits(FbLeftStipBits(bits, 16));
  285. else
  286. #endif
  287. mask = fbBits[FbLeftStipBits(bits, pixelsPerDst)];
  288. *dst = FbOpaqueStipple(mask, fgxor, bgxor);
  289. dst++;
  290. bits = FbStipLeft(bits, pixelsPerDst);
  291. }
  292. }
  293. else {
  294. if (fbLane) {
  295. while (bits && n) {
  296. switch (fbLane[FbLeftStipBits(bits, pixelsPerDst)]) {
  297. LaneCases((CARD8 *) dst);
  298. }
  299. bits = FbStipLeft(bits, pixelsPerDst);
  300. dst++;
  301. n--;
  302. }
  303. dst += n;
  304. }
  305. else
  306. {
  307. while (n--) {
  308. left = FbLeftStipBits(bits, pixelsPerDst);
  309. if (left || !transparent) {
  310. mask = fbBits[left];
  311. *dst = FbStippleRRop(*dst, mask,
  312. fgand, fgxor, bgand,
  313. bgxor);
  314. }
  315. dst++;
  316. bits = FbStipLeft(bits, pixelsPerDst);
  317. }
  318. }
  319. }
  320. if (!w)
  321. break;
  322. /*
  323. * Load another set and reset number of available units
  324. */
  325. LoadBits;
  326. n = unitsPerSrc;
  327. if (n > w)
  328. n = w;
  329. }
  330. }
  331. /*
  332. * Consume stipple bits for endmask
  333. */
  334. if (endmask) {
  335. if (endNeedsLoad) {
  336. LoadBits;
  337. }
  338. #if FB_UNIT > 32
  339. if (pixelsPerDst == 16)
  340. mask = FbStipple16Bits(FbLeftStipBits(bits, 16));
  341. else
  342. #endif
  343. mask = fbBits[FbLeftStipBits(bits, pixelsPerDst)];
  344. if (fbLane) {
  345. fbTransparentSpan(dst, mask & endmask, fgxor, 1);
  346. }
  347. else
  348. {
  349. if (mask || !transparent)
  350. FbDoRightMaskByteStippleRRop(dst, mask,
  351. fgand, fgxor, bgand, bgxor,
  352. endbyte, endmask);
  353. }
  354. }
  355. dst += dstStride;
  356. src += srcStride;
  357. }
  358. }
  359. /*
  360. * Crufty macros to initialize the mask array, most of this
  361. * is to avoid compile-time warnings about shift overflow
  362. */
  363. #if BITMAP_BIT_ORDER == MSBFirst
  364. #define Mask24Pos(x,r) ((x)*24-(r))
  365. #else
  366. #define Mask24Pos(x,r) ((x)*24-((r) ? 24 - (r) : 0))
  367. #endif
  368. #define Mask24Neg(x,r) (Mask24Pos(x,r) < 0 ? -Mask24Pos(x,r) : 0)
  369. #define Mask24Check(x,r) (Mask24Pos(x,r) < 0 ? 0 : \
  370. Mask24Pos(x,r) >= FB_UNIT ? 0 : Mask24Pos(x,r))
  371. #define Mask24(x,r) (Mask24Pos(x,r) < FB_UNIT ? \
  372. (Mask24Pos(x,r) < 0 ? \
  373. 0xffffff >> Mask24Neg (x,r) : \
  374. 0xffffff << Mask24Check(x,r)) : 0)
  375. #define SelMask24(b,n,r) ((((b) >> n) & 1) * Mask24(n,r))
  376. /*
  377. * Untested for MSBFirst or FB_UNIT == 32
  378. */
  379. #if FB_UNIT == 64
  380. #define C4_24(b,r) \
  381. (SelMask24(b,0,r) | \
  382. SelMask24(b,1,r) | \
  383. SelMask24(b,2,r) | \
  384. SelMask24(b,3,r))
  385. #define FbStip24New(rot) (2 + (rot != 0))
  386. #define FbStip24Len 4
  387. const FbBits fbStipple24Bits[3][1 << FbStip24Len] = {
  388. /* rotate 0 */
  389. {
  390. C4_24(0, 0), C4_24(1, 0), C4_24(2, 0), C4_24(3, 0),
  391. C4_24(4, 0), C4_24(5, 0), C4_24(6, 0), C4_24(7, 0),
  392. C4_24(8, 0), C4_24(9, 0), C4_24(10, 0), C4_24(11, 0),
  393. C4_24(12, 0), C4_24(13, 0), C4_24(14, 0), C4_24(15, 0),
  394. },
  395. /* rotate 8 */
  396. {
  397. C4_24(0, 8), C4_24(1, 8), C4_24(2, 8), C4_24(3, 8),
  398. C4_24(4, 8), C4_24(5, 8), C4_24(6, 8), C4_24(7, 8),
  399. C4_24(8, 8), C4_24(9, 8), C4_24(10, 8), C4_24(11, 8),
  400. C4_24(12, 8), C4_24(13, 8), C4_24(14, 8), C4_24(15, 8),
  401. },
  402. /* rotate 16 */
  403. {
  404. C4_24(0, 16), C4_24(1, 16), C4_24(2, 16), C4_24(3, 16),
  405. C4_24(4, 16), C4_24(5, 16), C4_24(6, 16), C4_24(7, 16),
  406. C4_24(8, 16), C4_24(9, 16), C4_24(10, 16), C4_24(11, 16),
  407. C4_24(12, 16), C4_24(13, 16), C4_24(14, 16), C4_24(15, 16),
  408. }
  409. };
  410. #endif
  411. #if FB_UNIT == 32
  412. #define C2_24(b,r) \
  413. (SelMask24(b,0,r) | \
  414. SelMask24(b,1,r))
  415. #define FbStip24Len 2
  416. #if BITMAP_BIT_ORDER == MSBFirst
  417. #define FbStip24New(rot) (1 + (rot == 0))
  418. #else
  419. #define FbStip24New(rot) (1 + (rot == 8))
  420. #endif
  421. const FbBits fbStipple24Bits[3][1 << FbStip24Len] = {
  422. /* rotate 0 */
  423. {
  424. C2_24(0, 0), C2_24(1, 0), C2_24(2, 0), C2_24(3, 0),
  425. },
  426. /* rotate 8 */
  427. {
  428. C2_24(0, 8), C2_24(1, 8), C2_24(2, 8), C2_24(3, 8),
  429. },
  430. /* rotate 16 */
  431. {
  432. C2_24(0, 16), C2_24(1, 16), C2_24(2, 16), C2_24(3, 16),
  433. }
  434. };
  435. #endif
  436. #if BITMAP_BIT_ORDER == LSBFirst
  437. #define FbMergeStip24Bits(left, right, new) \
  438. (FbStipLeft (left, new) | FbStipRight ((right), (FbStip24Len - (new))))
  439. #define FbMergePartStip24Bits(left, right, llen, rlen) \
  440. (left | FbStipRight(right, llen))
  441. #else
  442. #define FbMergeStip24Bits(left, right, new) \
  443. ((FbStipLeft (left, new) & ((1 << FbStip24Len) - 1)) | right)
  444. #define FbMergePartStip24Bits(left, right, llen, rlen) \
  445. (FbStipLeft(left, rlen) | right)
  446. #endif
  447. #define fbFirstStipBits(len,stip) {\
  448. int __len = (len); \
  449. if (len <= remain) { \
  450. stip = FbLeftStipBits(bits, len); \
  451. } else { \
  452. stip = FbLeftStipBits(bits, remain); \
  453. bits = (src < srcEnd ? *src++ : 0); \
  454. __len = (len) - remain; \
  455. stip = FbMergePartStip24Bits(stip, FbLeftStipBits(bits, __len), \
  456. remain, __len); \
  457. remain = FB_STIP_UNIT; \
  458. } \
  459. bits = FbStipLeft (bits, __len); \
  460. remain -= __len; \
  461. }
  462. #define fbInitStipBits(offset,len,stip) {\
  463. bits = FbStipLeft (*src++,offset); \
  464. remain = FB_STIP_UNIT - offset; \
  465. fbFirstStipBits(len,stip); \
  466. stip = FbMergeStip24Bits (0, stip, len); \
  467. }
  468. #define fbNextStipBits(rot,stip) {\
  469. int __new = FbStip24New(rot); \
  470. FbStip __right; \
  471. fbFirstStipBits(__new, __right); \
  472. stip = FbMergeStip24Bits (stip, __right, __new); \
  473. rot = FbNext24Rot (rot); \
  474. }
  475. /*
  476. * Use deep mask tables that incorporate rotation, pull
  477. * a variable number of bits out of the stipple and
  478. * reuse the right bits as needed for the next write
  479. *
  480. * Yes, this is probably too much code, but most 24-bpp screens
  481. * have no acceleration so this code is used for stipples, copyplane
  482. * and text
  483. */
  484. void
  485. fbBltOne24(FbStip * srcLine, FbStride srcStride, /* FbStip units per scanline */
  486. int srcX, /* bit position of source */
  487. FbBits * dst, FbStride dstStride, /* FbBits units per scanline */
  488. int dstX, /* bit position of dest */
  489. int dstBpp, /* bits per destination unit */
  490. int width, /* width in bits of destination */
  491. int height, /* height in scanlines */
  492. FbBits fgand, /* rrop values */
  493. FbBits fgxor, FbBits bgand, FbBits bgxor)
  494. {
  495. FbStip *src, *srcEnd;
  496. FbBits leftMask, rightMask, mask;
  497. int nlMiddle, nl;
  498. FbStip stip, bits;
  499. int remain;
  500. int dstS;
  501. int firstlen;
  502. int rot0, rot;
  503. int nDst;
  504. /*
  505. * Do not read past the end of the buffer!
  506. */
  507. srcEnd = srcLine + height * srcStride;
  508. srcLine += srcX >> FB_STIP_SHIFT;
  509. dst += dstX >> FB_SHIFT;
  510. srcX &= FB_STIP_MASK;
  511. dstX &= FB_MASK;
  512. rot0 = FbFirst24Rot(dstX);
  513. FbMaskBits(dstX, width, leftMask, nlMiddle, rightMask);
  514. dstS = (dstX + 23) / 24;
  515. firstlen = FbStip24Len - dstS;
  516. nDst = nlMiddle;
  517. if (leftMask)
  518. nDst++;
  519. dstStride -= nDst;
  520. /* opaque copy */
  521. if (bgand == 0 && fgand == 0) {
  522. while (height--) {
  523. rot = rot0;
  524. src = srcLine;
  525. srcLine += srcStride;
  526. fbInitStipBits(srcX, firstlen, stip);
  527. if (leftMask) {
  528. mask = fbStipple24Bits[rot >> 3][stip];
  529. *dst = (*dst & ~leftMask) | (FbOpaqueStipple(mask,
  530. FbRot24(fgxor,
  531. rot),
  532. FbRot24(bgxor,
  533. rot))
  534. & leftMask);
  535. dst++;
  536. fbNextStipBits(rot, stip);
  537. }
  538. nl = nlMiddle;
  539. while (nl--) {
  540. mask = fbStipple24Bits[rot >> 3][stip];
  541. *dst = FbOpaqueStipple(mask,
  542. FbRot24(fgxor, rot),
  543. FbRot24(bgxor, rot));
  544. dst++;
  545. fbNextStipBits(rot, stip);
  546. }
  547. if (rightMask) {
  548. mask = fbStipple24Bits[rot >> 3][stip];
  549. *dst = (*dst & ~rightMask) | (FbOpaqueStipple(mask,
  550. FbRot24(fgxor,
  551. rot),
  552. FbRot24(bgxor,
  553. rot))
  554. & rightMask);
  555. }
  556. dst += dstStride;
  557. src += srcStride;
  558. }
  559. }
  560. /* transparent copy */
  561. else if (bgand == FB_ALLONES && bgxor == 0 && fgand == 0) {
  562. while (height--) {
  563. rot = rot0;
  564. src = srcLine;
  565. srcLine += srcStride;
  566. fbInitStipBits(srcX, firstlen, stip);
  567. if (leftMask) {
  568. if (stip) {
  569. mask = fbStipple24Bits[rot >> 3][stip] & leftMask;
  570. *dst = (*dst & ~mask) | (FbRot24(fgxor, rot) & mask);
  571. }
  572. dst++;
  573. fbNextStipBits(rot, stip);
  574. }
  575. nl = nlMiddle;
  576. while (nl--) {
  577. if (stip) {
  578. mask = fbStipple24Bits[rot >> 3][stip];
  579. *dst = (*dst & ~mask) | (FbRot24(fgxor, rot) & mask);
  580. }
  581. dst++;
  582. fbNextStipBits(rot, stip);
  583. }
  584. if (rightMask) {
  585. if (stip) {
  586. mask = fbStipple24Bits[rot >> 3][stip] & rightMask;
  587. *dst = (*dst & ~mask) | (FbRot24(fgxor, rot) & mask);
  588. }
  589. }
  590. dst += dstStride;
  591. }
  592. }
  593. else {
  594. while (height--) {
  595. rot = rot0;
  596. src = srcLine;
  597. srcLine += srcStride;
  598. fbInitStipBits(srcX, firstlen, stip);
  599. if (leftMask) {
  600. mask = fbStipple24Bits[rot >> 3][stip];
  601. *dst = FbStippleRRopMask(*dst, mask,
  602. FbRot24(fgand, rot),
  603. FbRot24(fgxor, rot),
  604. FbRot24(bgand, rot),
  605. FbRot24(bgxor, rot), leftMask);
  606. dst++;
  607. fbNextStipBits(rot, stip);
  608. }
  609. nl = nlMiddle;
  610. while (nl--) {
  611. mask = fbStipple24Bits[rot >> 3][stip];
  612. *dst = FbStippleRRop(*dst, mask,
  613. FbRot24(fgand, rot),
  614. FbRot24(fgxor, rot),
  615. FbRot24(bgand, rot), FbRot24(bgxor, rot));
  616. dst++;
  617. fbNextStipBits(rot, stip);
  618. }
  619. if (rightMask) {
  620. mask = fbStipple24Bits[rot >> 3][stip];
  621. *dst = FbStippleRRopMask(*dst, mask,
  622. FbRot24(fgand, rot),
  623. FbRot24(fgxor, rot),
  624. FbRot24(bgand, rot),
  625. FbRot24(bgxor, rot), rightMask);
  626. }
  627. dst += dstStride;
  628. }
  629. }
  630. }
  631. /*
  632. * Not very efficient, but simple -- copy a single plane
  633. * from an N bit image to a 1 bit image
  634. */
  635. void
  636. fbBltPlane(FbBits * src,
  637. FbStride srcStride,
  638. int srcX,
  639. int srcBpp,
  640. FbStip * dst,
  641. FbStride dstStride,
  642. int dstX,
  643. int width,
  644. int height,
  645. FbStip fgand,
  646. FbStip fgxor, FbStip bgand, FbStip bgxor, Pixel planeMask)
  647. {
  648. FbBits *s;
  649. FbBits pm;
  650. FbBits srcMask;
  651. FbBits srcMaskFirst;
  652. FbBits srcMask0 = 0;
  653. FbBits srcBits;
  654. FbStip dstBits;
  655. FbStip *d;
  656. FbStip dstMask;
  657. FbStip dstMaskFirst;
  658. FbStip dstUnion;
  659. int w;
  660. int wt;
  661. int rot0;
  662. if (!width)
  663. return;
  664. src += srcX >> FB_SHIFT;
  665. srcX &= FB_MASK;
  666. dst += dstX >> FB_STIP_SHIFT;
  667. dstX &= FB_STIP_MASK;
  668. w = width / srcBpp;
  669. pm = fbReplicatePixel(planeMask, srcBpp);
  670. if (srcBpp == 24) {
  671. int tmpw = 24;
  672. rot0 = FbFirst24Rot(srcX);
  673. if (srcX + tmpw > FB_UNIT)
  674. tmpw = FB_UNIT - srcX;
  675. srcMaskFirst = FbRot24(pm, rot0) & FbBitsMask(srcX, tmpw);
  676. }
  677. else
  678. {
  679. rot0 = 0;
  680. srcMaskFirst = pm & FbBitsMask(srcX, srcBpp);
  681. srcMask0 = pm & FbBitsMask(0, srcBpp);
  682. }
  683. dstMaskFirst = FbStipMask(dstX, 1);
  684. while (height--) {
  685. d = dst;
  686. dst += dstStride;
  687. s = src;
  688. src += srcStride;
  689. srcMask = srcMaskFirst;
  690. if (srcBpp == 24)
  691. srcMask0 = FbRot24(pm, rot0) & FbBitsMask(0, srcBpp);
  692. srcBits = *s++;
  693. dstMask = dstMaskFirst;
  694. dstUnion = 0;
  695. dstBits = 0;
  696. wt = w;
  697. while (wt--) {
  698. if (!srcMask) {
  699. srcBits = *s++;
  700. if (srcBpp == 24)
  701. srcMask0 = FbNext24Pix(srcMask0) & FbBitsMask(0, 24);
  702. srcMask = srcMask0;
  703. }
  704. if (!dstMask) {
  705. *d = FbStippleRRopMask(*d, dstBits,
  706. fgand, fgxor, bgand, bgxor, dstUnion);
  707. d++;
  708. dstMask = FbStipMask(0, 1);
  709. dstUnion = 0;
  710. dstBits = 0;
  711. }
  712. if (srcBits & srcMask)
  713. dstBits |= dstMask;
  714. dstUnion |= dstMask;
  715. if (srcBpp == FB_UNIT)
  716. srcMask = 0;
  717. else
  718. srcMask = FbScrRight(srcMask, srcBpp);
  719. dstMask = FbStipRight(dstMask, 1);
  720. }
  721. if (dstUnion)
  722. *d = FbStippleRRopMask(*d, dstBits,
  723. fgand, fgxor, bgand, bgxor, dstUnion);
  724. }
  725. }