1 /***********************************************************
3 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:
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 Except as contained in this notice, the name of the X Consortium shall not be
23 used in advertising or otherwise to promote the sale, use or other dealings
24 in this Software without prior written authorization from the X Consortium.
27 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
31 Permission to use, copy, modify, and distribute this software and its
32 documentation for any purpose and without fee is hereby granted,
33 provided that the above copyright notice appear in all copies and that
34 both that copyright notice and this permission notice appear in
35 supporting documentation, and that the name of Digital not be
36 used in advertising or publicity pertaining to distribution of the
37 software without specific, written prior permission.
39 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
40 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
41 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
42 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
43 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
44 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
47 ******************************************************************/
50 written by drewry, september 1986
52 on a monchrome device, a pixmap is a bitmap.
55 #ifdef HAVE_DIX_CONFIG_H
56 #include <dix-config.h>
62 #include "scrnintstr.h"
63 #include "pixmapstr.h"
73 afbCreatePixmap(pScreen
, width
, height
, depth
)
83 paddedWidth
= BitmapBytePad(width
);
85 if (paddedWidth
> 32767 || height
> 32767 || depth
> 4)
88 datasize
= height
* paddedWidth
* depth
;
89 pPixmap
= AllocatePixmap(pScreen
, datasize
);
92 pPixmap
->drawable
.type
= DRAWABLE_PIXMAP
;
93 pPixmap
->drawable
.class = 0;
94 pPixmap
->drawable
.pScreen
= pScreen
;
95 pPixmap
->drawable
.depth
= depth
;
96 pPixmap
->drawable
.bitsPerPixel
= depth
;
97 pPixmap
->drawable
.id
= 0;
98 pPixmap
->drawable
.serialNumber
= NEXT_SERIAL_NUMBER
;
99 pPixmap
->drawable
.x
= 0;
100 pPixmap
->drawable
.y
= 0;
101 pPixmap
->drawable
.width
= width
;
102 pPixmap
->drawable
.height
= height
;
103 pPixmap
->devKind
= paddedWidth
;
105 pPixmap
->devPrivate
.ptr
= datasize
?
106 (pointer
)((char *)pPixmap
+ pScreen
->totalPixmapSize
) : NULL
;
111 afbDestroyPixmap(pPixmap
)
114 if(--pPixmap
->refcnt
)
122 afbCopyPixmap(PixmapPtr pSrc
)
124 register PixmapPtr pDst
;
128 size
= pSrc
->drawable
.height
* pSrc
->devKind
* pSrc
->drawable
.depth
;
129 pScreen
= pSrc
->drawable
.pScreen
;
130 pDst
= (*pScreen
->CreatePixmap
)(pScreen
, pSrc
->drawable
.width
,
131 pSrc
->drawable
.height
, pSrc
->drawable
.depth
);
134 memmove((char *)pDst
->devPrivate
.ptr
, (char *)pSrc
->devPrivate
.ptr
, size
);
139 /* replicates a pattern to be a full 32 bits wide.
140 relies on the fact that each scnaline is longword padded.
141 doesn't do anything if pixmap is not a factor of 32 wide.
142 changes width field of pixmap if successful, so that the fast
143 XRotatePixmap code gets used if we rotate the pixmap later.
145 calculate number of times to repeat
146 for each scanline of pattern
147 zero out area to be filled with replicate
148 left shift and or in original as many times as needed
151 afbPadPixmap(PixmapPtr pPixmap
)
153 register int width
= pPixmap
->drawable
.width
;
155 register PixelType mask
;
156 register PixelType
*p
;
157 register PixelType bits
; /* real pattern bits */
160 int rep
; /* repeat count for pattern */
166 if (rep
*width
!= PPW
)
169 mask
= mfbGetendtab(width
);
171 p
= (PixelType
*)(pPixmap
->devPrivate
.ptr
);
173 for (d
= 0; d
< pPixmap
->drawable
.depth
; d
++) {
174 for (h
= 0; h
< pPixmap
->drawable
.height
; h
++) {
177 for(i
= 1; i
< rep
; i
++) {
178 bits
= SCRRIGHT(bits
, width
);
181 p
++; /* @@@ NEXT PLANE @@@ */
184 pPixmap
->drawable
.width
= PPW
;
187 /* Rotates pixmap pPix by w pixels to the right on the screen. Assumes that
188 * words are PPW bits wide, and that the least significant bit appears on the
192 afbXRotatePixmap(pPix
, rw
)
196 register PixelType
*pw
, *pwFinal
;
197 register PixelType t
;
199 if (pPix
== NullPixmap
)
202 pw
= (PixelType
*)pPix
->devPrivate
.ptr
;
203 rw
%= (int)pPix
->drawable
.width
;
205 rw
+= (int)pPix
->drawable
.width
;
206 if(pPix
->drawable
.width
== PPW
) {
207 pwFinal
= pw
+ pPix
->drawable
.height
* pPix
->drawable
.depth
;
208 while(pw
< pwFinal
) {
210 *pw
++ = SCRRIGHT(t
, rw
) |
211 (SCRLEFT(t
, (PPW
-rw
)) & mfbGetendtab(rw
));
214 /* We no longer do this. Validate doesn't try to rotate odd-size
215 * tiles or stipples. afbUnnatural<tile/stipple>FS works directly off
216 * the unrotate tile/stipple in the GC
218 ErrorF("X internal error: trying to rotate odd-sized pixmap.\n");
223 /* Rotates pixmap pPix by h lines. Assumes that h is always less than
228 afbYRotatePixmap(pPix
, rh
)
229 register PixmapPtr pPix
;
232 int nbyDown
; /* bytes to move down to row 0; also offset of
234 int nbyUp
; /* bytes to move up to line rh; also
235 offset of first line moved down to 0 */
241 if (pPix
== NullPixmap
)
243 height
= (int) pPix
->drawable
.height
;
248 nbyDown
= rh
* pPix
->devKind
;
249 nbyUp
= (pPix
->devKind
* height
) - nbyDown
;
251 if(!(ptmp
= (char *)ALLOCATE_LOCAL(nbyUp
)))
254 for (d
= 0; d
< pPix
->drawable
.depth
; d
++) {
255 pbase
= (char *)pPix
->devPrivate
.ptr
+ pPix
->devKind
* height
* d
; /* @@@ NEXT PLANE @@@ */
257 memmove(ptmp
, pbase
, nbyUp
); /* save the low rows */
258 memmove(pbase
, pbase
+nbyUp
, nbyDown
); /* slide the top rows down */
259 memmove(pbase
+nbyDown
, ptmp
, nbyUp
); /* move lower rows up to row rh */
261 DEALLOCATE_LOCAL(ptmp
);
265 afbCopyRotatePixmap(psrcPix
, ppdstPix
, xrot
, yrot
)
266 register PixmapPtr psrcPix
, *ppdstPix
;
269 register PixmapPtr pdstPix
;
271 if ((pdstPix
= *ppdstPix
) &&
272 (pdstPix
->devKind
== psrcPix
->devKind
) &&
273 (pdstPix
->drawable
.height
== psrcPix
->drawable
.height
) &&
274 (pdstPix
->drawable
.depth
== psrcPix
->drawable
.depth
)) {
275 memmove((char *)pdstPix
->devPrivate
.ptr
,
276 (char *)psrcPix
->devPrivate
.ptr
,
277 psrcPix
->drawable
.height
* psrcPix
->devKind
*
278 psrcPix
->drawable
.depth
);
279 pdstPix
->drawable
.width
= psrcPix
->drawable
.width
;
280 pdstPix
->drawable
.serialNumber
= NEXT_SERIAL_NUMBER
;
284 (*pdstPix
->drawable
.pScreen
->DestroyPixmap
)(pdstPix
);
285 *ppdstPix
= pdstPix
= afbCopyPixmap(psrcPix
);
289 afbPadPixmap(pdstPix
);
291 afbXRotatePixmap(pdstPix
, xrot
);
293 afbYRotatePixmap(pdstPix
, yrot
);