2 #ifdef HAVE_DIX_CONFIG_H
3 #include <dix-config.h>
10 #include "pixmapstr.h"
11 #include "scrnintstr.h"
19 afbPutImage(pDraw
, pGC
, depth
, x
, y
, width
, height
, leftPad
, format
, pImage
)
22 int depth
, x
, y
, width
, height
;
29 if ((width
== 0) || (height
== 0))
32 if (format
!= ZPixmap
|| depth
== 1 || pDraw
->depth
== 1) {
33 pPixmap
= GetScratchPixmapHeader(pDraw
->pScreen
, width
+leftPad
, height
,
35 BitmapBytePad(width
+leftPad
),
41 if (format
== XYBitmap
)
42 (void)(*pGC
->ops
->CopyPlane
)((DrawablePtr
)pPixmap
, pDraw
, pGC
, leftPad
,
43 0, width
, height
, x
, y
, 1);
45 (void)(*pGC
->ops
->CopyArea
)((DrawablePtr
)pPixmap
, pDraw
, pGC
, leftPad
,
46 0, width
, height
, x
, y
);
50 FreeScratchPixmapHeader(pPixmap
);
52 /* Chunky to planar conversion required */
55 ScreenPtr pScreen
= pDraw
->pScreen
;
59 register int dstshift
;
60 register int shift_step
;
61 register PixelType dst
;
62 register PixelType srcbits
;
63 register PixelType
*pdst
;
64 register PixelType
*psrc
;
74 /* Create a tmp pixmap */
75 pPixmap
= (pScreen
->CreatePixmap
)(pScreen
, width
, height
, depth
);
79 afbGetPixelWidthSizeDepthAndPointer((DrawablePtr
)pPixmap
, widthDst
,
80 sizeDst
, depthDst
, pdstBase
);
82 widthSrc
= PixmapWidthInPadUnits(width
, depth
);
83 /* XXX: if depth == 8, use fast chunky to planar assembly function.*/
92 for (d
= 0; d
< depth
; d
++, pdstBase
+= sizeDst
) { /* @@@ NEXT PLANE @@@ */
93 start_bit
= start_srcshift
+ d
;
94 psrc
= (PixelType
*)pImage
;
104 for (b
= start_bit
; b
>= 0; b
-= shift_step
) {
105 dst
|= ((srcbits
>> b
) & 1) << dstshift
;
106 if (--dstshift
< 0) {
113 if (dstshift
!= PPW
- 1)
116 } /* for (d = ...) */
118 pGC
->fExpose
= FALSE
;
119 (void)(*pGC
->ops
->CopyArea
)((DrawablePtr
)pPixmap
, pDraw
, pGC
, leftPad
, 0,
120 width
, height
, x
, y
);
122 (*pScreen
->DestroyPixmap
)(pPixmap
);
127 afbGetImage(pDrawable
, sx
, sy
, width
, height
, format
, planemask
, pdstLine
)
128 DrawablePtr pDrawable
;
129 int sx
, sy
, width
, height
;
131 unsigned long planemask
;
140 if ((width
== 0) || (height
== 0))
143 pScreen
= pDrawable
->pScreen
;
147 if (format
== XYPixmap
|| pDrawable
->depth
== 1) {
148 pPixmap
= GetScratchPixmapHeader(pScreen
, width
, height
, 1, 1,
149 BitmapBytePad(width
), (pointer
)pdstLine
);
159 REGION_INIT(pScreen
, &rgnDst
, &box
, 1);
161 pPixmap
->drawable
.depth
= 1;
162 pPixmap
->drawable
.bitsPerPixel
= 1;
163 /* dix layer only ever calls GetImage with 1 bit set in planemask
164 * when format is XYPixmap.
166 afbDoBitblt(pDrawable
, (DrawablePtr
)pPixmap
, GXcopy
, &rgnDst
, &ptSrc
,
169 FreeScratchPixmapHeader(pPixmap
);
170 REGION_UNINIT(pScreen
, &rgnDst
);
172 /* Planar to chunky conversion required */
176 PixelType startmask
, endmask
;
182 register PixelType
*psrc
;
183 register PixelType
*pdst
;
184 register PixelType dst
;
185 register PixelType srcbits
;
188 register int dstshift
;
189 register int shift_step
;
190 register int start_endbit
;
192 register int end_endbit
= 0;
193 register int start_dstshift
;
198 widthDst
= PixmapWidthInPadUnits(width
, pDrawable
->depth
);
199 sizeDst
= widthDst
* height
;
201 /* Clear the dest image */
202 bzero(pdstLine
, sizeDst
<< 2);
204 afbGetPixelWidthSizeDepthAndPointer(pDrawable
, widthSrc
, sizeSrc
,
207 psrcBits
= afbScanline(psrcBits
, sx
, sy
, widthSrc
);
209 start_startbit
= PPW
- 1 - (sx
& PIM
);
210 if ((sx
& PIM
) + width
< PPW
) {
211 maskpartialbits(sx
, width
, startmask
);
214 start_endbit
= PPW
- ((sx
+ width
) & PIM
);
216 maskbits(sx
, width
, startmask
, endmask
, nlmiddle
);
218 end_endbit
= PPW
- ((sx
+ width
) & PIM
);
220 /* ZPixmap images have either 4 or 8 bits per pixel dependent on
230 #define SHIFT_BITS(start_bit,end_bit) \
231 for (b = (start_bit); b >= (end_bit); b--) { \
232 dst |= ((srcbits >> b) & 1) << dstshift; \
233 if ((dstshift -= shift_step) < 0) { \
234 dstshift = start_dstshift + d; \
240 for (d = 0; d < depthSrc; d++, psrcBits += sizeSrc) { /* @@@ NEXT PLANE @@@ */
242 pdst
= (PixelType
*)pdstLine
;
247 psrcLine
+= widthSrc
;
249 dstshift
= start_dstshift
+ d
;
252 srcbits
= *psrc
++ & startmask
;
253 SHIFT_BITS(start_startbit
, start_endbit
);
259 SHIFT_BITS(PPW
- 1, 0);
262 srcbits
= *psrc
& endmask
;
263 SHIFT_BITS(PPW
- 1, end_endbit
);
266 if (dstshift
!= start_dstshift
+ d
)
269 } /* for (d = ...) */