mipushpxl.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. /***********************************************************
  2. Copyright 1987, 1998 The Open Group
  3. Permission to use, copy, modify, distribute, and sell this software and its
  4. documentation for any purpose is hereby granted without fee, provided that
  5. the above copyright notice appear in all copies and that both that
  6. copyright notice and this permission notice appear in supporting
  7. documentation.
  8. The above copyright notice and this permission notice shall be included in
  9. all copies or substantial portions of the Software.
  10. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  11. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  12. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  13. OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  14. AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  15. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  16. Except as contained in this notice, the name of The Open Group shall not be
  17. used in advertising or otherwise to promote the sale, use or other dealings
  18. in this Software without prior written authorization from The Open Group.
  19. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
  20. All Rights Reserved
  21. Permission to use, copy, modify, and distribute this software and its
  22. documentation for any purpose and without fee is hereby granted,
  23. provided that the above copyright notice appear in all copies and that
  24. both that copyright notice and this permission notice appear in
  25. supporting documentation, and that the name of Digital not be
  26. used in advertising or publicity pertaining to distribution of the
  27. software without specific, written prior permission.
  28. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  29. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  30. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  31. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  32. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  33. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  34. SOFTWARE.
  35. ******************************************************************/
  36. #ifdef HAVE_DIX_CONFIG_H
  37. #include <dix-config.h>
  38. #endif
  39. #include <X11/X.h>
  40. #include "gcstruct.h"
  41. #include "scrnintstr.h"
  42. #include "pixmapstr.h"
  43. #include "regionstr.h"
  44. #include "mi.h"
  45. #include "servermd.h"
  46. #define NPT 128
  47. /* These were stolen from mfb. They don't really belong here. */
  48. #define LONG2CHARSSAMEORDER(x) ((MiBits)(x))
  49. #define LONG2CHARSDIFFORDER( x ) ( ( ( ( x ) & (MiBits)0x000000FF ) << 0x18 ) \
  50. | ( ( ( x ) & (MiBits)0x0000FF00 ) << 0x08 ) \
  51. | ( ( ( x ) & (MiBits)0x00FF0000 ) >> 0x08 ) \
  52. | ( ( ( x ) & (MiBits)0xFF000000 ) >> 0x18 ) )
  53. #define PGSZB 4
  54. #define PPW (PGSZB<<3) /* assuming 8 bits per byte */
  55. #define PGSZ PPW
  56. #define PLST (PPW-1)
  57. #define PIM PLST
  58. #define PWSH 5
  59. /* miPushPixels -- squeegees the fill style of pGC through pBitMap
  60. * into pDrawable. pBitMap is a stencil (dx by dy of it is used, it may
  61. * be bigger) which is placed on the drawable at xOrg, yOrg. Where a 1 bit
  62. * is set in the bitmap, the fill style is put onto the drawable using
  63. * the GC's logical function. The drawable is not changed where the bitmap
  64. * has a zero bit or outside the area covered by the stencil.
  65. WARNING:
  66. this code works if the 1-bit deep pixmap format returned by GetSpans
  67. is the same as the format defined by the mfb code (i.e. 32-bit padding
  68. per scanline, scanline unit = 32 bits; later, this might mean
  69. bitsizeof(int) padding and sacnline unit == bitsizeof(int).)
  70. */
  71. /*
  72. * in order to have both (MSB_FIRST and LSB_FIRST) versions of this
  73. * in the server, we need to rename one of them
  74. */
  75. _X_EXPORT void
  76. miPushPixels(pGC, pBitMap, pDrawable, dx, dy, xOrg, yOrg)
  77. GCPtr pGC;
  78. PixmapPtr pBitMap;
  79. DrawablePtr pDrawable;
  80. int dx, dy, xOrg, yOrg;
  81. {
  82. int h, dxDivPPW, ibEnd;
  83. MiBits *pwLineStart;
  84. MiBits *pw, *pwEnd;
  85. MiBits msk;
  86. int ib, w;
  87. int ipt; /* index into above arrays */
  88. Bool fInBox;
  89. DDXPointRec pt[NPT], ptThisLine;
  90. int width[NPT];
  91. #if 1
  92. MiBits startmask;
  93. if (screenInfo.bitmapBitOrder == IMAGE_BYTE_ORDER)
  94. if (screenInfo.bitmapBitOrder == LSBFirst)
  95. startmask = (MiBits)(-1) ^
  96. LONG2CHARSSAMEORDER((MiBits)(-1) << 1);
  97. else
  98. startmask = (MiBits)(-1) ^
  99. LONG2CHARSSAMEORDER((MiBits)(-1) >> 1);
  100. else
  101. if (screenInfo.bitmapBitOrder == LSBFirst)
  102. startmask = (MiBits)(-1) ^
  103. LONG2CHARSDIFFORDER((MiBits)(-1) << 1);
  104. else
  105. startmask = (MiBits)(-1) ^
  106. LONG2CHARSDIFFORDER((MiBits)(-1) >> 1);
  107. #endif
  108. pwLineStart = (MiBits *)malloc(BitmapBytePad(dx));
  109. if (!pwLineStart)
  110. return;
  111. ipt = 0;
  112. dxDivPPW = dx/PPW;
  113. for(h = 0, ptThisLine.x = 0, ptThisLine.y = 0;
  114. h < dy;
  115. h++, ptThisLine.y++)
  116. {
  117. (*pBitMap->drawable.pScreen->GetSpans)((DrawablePtr)pBitMap, dx,
  118. &ptThisLine, &dx, 1, (char *)pwLineStart);
  119. pw = pwLineStart;
  120. /* Process all words which are fully in the pixmap */
  121. fInBox = FALSE;
  122. pwEnd = pwLineStart + dxDivPPW;
  123. while(pw < pwEnd)
  124. {
  125. w = *pw;
  126. #if 1
  127. msk = startmask;
  128. #else
  129. msk = (MiBits)(-1) ^ SCRRIGHT((MiBits)(-1), 1);
  130. #endif
  131. for(ib = 0; ib < PPW; ib++)
  132. {
  133. if(w & msk)
  134. {
  135. if(!fInBox)
  136. {
  137. pt[ipt].x = ((pw - pwLineStart) << PWSH) + ib + xOrg;
  138. pt[ipt].y = h + yOrg;
  139. /* start new box */
  140. fInBox = TRUE;
  141. }
  142. }
  143. else
  144. {
  145. if(fInBox)
  146. {
  147. width[ipt] = ((pw - pwLineStart) << PWSH) +
  148. ib + xOrg - pt[ipt].x;
  149. if (++ipt >= NPT)
  150. {
  151. (*pGC->ops->FillSpans)(pDrawable, pGC,
  152. NPT, pt, width, TRUE);
  153. ipt = 0;
  154. }
  155. /* end box */
  156. fInBox = FALSE;
  157. }
  158. }
  159. #if 1
  160. /* This is not quite right, but it'll do for now */
  161. if (screenInfo.bitmapBitOrder == IMAGE_BYTE_ORDER)
  162. if (screenInfo.bitmapBitOrder == LSBFirst)
  163. msk = LONG2CHARSSAMEORDER(LONG2CHARSSAMEORDER(msk) << 1);
  164. else
  165. msk = LONG2CHARSSAMEORDER(LONG2CHARSSAMEORDER(msk) >> 1);
  166. else
  167. if (screenInfo.bitmapBitOrder == LSBFirst)
  168. msk = LONG2CHARSDIFFORDER(LONG2CHARSDIFFORDER(msk) << 1);
  169. else
  170. msk = LONG2CHARSDIFFORDER(LONG2CHARSDIFFORDER(msk) >> 1);
  171. #else
  172. msk = SCRRIGHT(msk, 1);
  173. #endif
  174. }
  175. pw++;
  176. }
  177. ibEnd = dx & PIM;
  178. if(ibEnd)
  179. {
  180. /* Process final partial word on line */
  181. w = *pw;
  182. #if 1
  183. msk = startmask;
  184. #else
  185. msk = (MiBits)(-1) ^ SCRRIGHT((MiBits)(-1), 1);
  186. #endif
  187. for(ib = 0; ib < ibEnd; ib++)
  188. {
  189. if(w & msk)
  190. {
  191. if(!fInBox)
  192. {
  193. /* start new box */
  194. pt[ipt].x = ((pw - pwLineStart) << PWSH) + ib + xOrg;
  195. pt[ipt].y = h + yOrg;
  196. fInBox = TRUE;
  197. }
  198. }
  199. else
  200. {
  201. if(fInBox)
  202. {
  203. /* end box */
  204. width[ipt] = ((pw - pwLineStart) << PWSH) +
  205. ib + xOrg - pt[ipt].x;
  206. if (++ipt >= NPT)
  207. {
  208. (*pGC->ops->FillSpans)(pDrawable,
  209. pGC, NPT, pt, width, TRUE);
  210. ipt = 0;
  211. }
  212. fInBox = FALSE;
  213. }
  214. }
  215. #if 1
  216. /* This is not quite right, but it'll do for now */
  217. if (screenInfo.bitmapBitOrder == IMAGE_BYTE_ORDER)
  218. if (screenInfo.bitmapBitOrder == LSBFirst)
  219. msk = LONG2CHARSSAMEORDER(LONG2CHARSSAMEORDER(msk) << 1);
  220. else
  221. msk = LONG2CHARSSAMEORDER(LONG2CHARSSAMEORDER(msk) >> 1);
  222. else
  223. if (screenInfo.bitmapBitOrder == LSBFirst)
  224. msk = LONG2CHARSDIFFORDER(LONG2CHARSDIFFORDER(msk) << 1);
  225. else
  226. msk = LONG2CHARSDIFFORDER(LONG2CHARSDIFFORDER(msk) >> 1);
  227. #else
  228. msk = SCRRIGHT(msk, 1);
  229. #endif
  230. }
  231. }
  232. /* If scanline ended with last bit set, end the box */
  233. if(fInBox)
  234. {
  235. width[ipt] = dx + xOrg - pt[ipt].x;
  236. if (++ipt >= NPT)
  237. {
  238. (*pGC->ops->FillSpans)(pDrawable, pGC, NPT, pt, width, TRUE);
  239. ipt = 0;
  240. }
  241. }
  242. }
  243. free(pwLineStart);
  244. /* Flush any remaining spans */
  245. if (ipt)
  246. {
  247. (*pGC->ops->FillSpans)(pDrawable, pGC, ipt, pt, width, TRUE);
  248. }
  249. }