1 /***********************************************************
3 Copyright 1987, 1998 The Open Group
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
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 Except as contained in this notice, the name of The Open Group shall not be
22 used in advertising or otherwise to promote the sale, use or other dealings
23 in this Software without prior written authorization from The Open Group.
26 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
30 Permission to use, copy, modify, and distribute this software and its
31 documentation for any purpose and without fee is hereby granted,
32 provided that the above copyright notice appear in all copies and that
33 both that copyright notice and this permission notice appear in
34 supporting documentation, and that the name of Digital not be
35 used in advertising or publicity pertaining to distribution of the
36 software without specific, written prior permission.
38 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
39 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
40 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
41 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
42 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
43 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
46 ******************************************************************/
49 written by drewry, september 1986
51 on a monchrome device, a pixmap is a bitmap.
54 #ifdef HAVE_DIX_CONFIG_H
55 #include <dix-config.h>
61 #include "scrnintstr.h"
62 #include "pixmapstr.h"
72 mfbCreatePixmap (pScreen
, width
, height
, depth
)
84 paddedWidth
= BitmapBytePad(width
);
85 if (paddedWidth
/ 4 > 32767 || height
> 32767)
87 datasize
= height
* paddedWidth
;
88 pPixmap
= AllocatePixmap(pScreen
, datasize
);
91 pPixmap
->drawable
.type
= DRAWABLE_PIXMAP
;
92 pPixmap
->drawable
.class = 0;
93 pPixmap
->drawable
.pScreen
= pScreen
;
94 pPixmap
->drawable
.depth
= depth
;
95 pPixmap
->drawable
.bitsPerPixel
= depth
;
96 pPixmap
->drawable
.id
= 0;
97 pPixmap
->drawable
.serialNumber
= NEXT_SERIAL_NUMBER
;
98 pPixmap
->drawable
.x
= 0;
99 pPixmap
->drawable
.y
= 0;
100 pPixmap
->drawable
.width
= width
;
101 pPixmap
->drawable
.height
= height
;
102 pPixmap
->devKind
= paddedWidth
;
104 pPixmap
->devPrivate
.ptr
= datasize
?
105 (pointer
)((char *)pPixmap
+ pScreen
->totalPixmapSize
) : NULL
;
111 mfbDestroyPixmap(pPixmap
)
114 if(--pPixmap
->refcnt
)
123 register PixmapPtr pSrc
;
125 register PixmapPtr pDst
;
129 size
= pSrc
->drawable
.height
* pSrc
->devKind
;
130 pScreen
= pSrc
->drawable
.pScreen
;
131 pDst
= (*pScreen
->CreatePixmap
) (pScreen
, pSrc
->drawable
.width
,
132 pSrc
->drawable
.height
, pSrc
->drawable
.depth
);
135 memmove((char *)pDst
->devPrivate
.ptr
, (char *)pSrc
->devPrivate
.ptr
, size
);
140 /* replicates a pattern to be a full 32 bits wide.
141 relies on the fact that each scnaline is longword padded.
142 doesn't do anything if pixmap is not a factor of 32 wide.
143 changes width field of pixmap if successful, so that the fast
144 XRotatePixmap code gets used if we rotate the pixmap later.
146 calculate number of times to repeat
147 for each scanline of pattern
148 zero out area to be filled with replicate
149 left shift and or in original as many times as needed
152 mfbPadPixmap(pPixmap
)
155 register int width
= pPixmap
->drawable
.width
;
157 register PixelType mask
;
158 register PixelType
*p
;
159 register PixelType bits
; /* real pattern bits */
161 int rep
; /* repeat count for pattern */
167 if (rep
*width
!= PPW
)
170 mask
= endtab
[width
];
172 p
= (PixelType
*)(pPixmap
->devPrivate
.ptr
);
173 for (h
=0; h
< pPixmap
->drawable
.height
; h
++)
179 bits
= SCRRIGHT(bits
, width
);
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 mfbXRotatePixmap(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
)
208 pwFinal
= pw
+ pPix
->drawable
.height
;
212 *pw
++ = SCRRIGHT(t
, rw
) |
213 (SCRLEFT(t
, (PPW
-rw
)) & endtab
[rw
]);
218 /* We no longer do this. Validate doesn't try to rotate odd-size
219 * tiles or stipples. mfbUnnatural<tile/stipple>FS works directly off
220 * the unrotate tile/stipple in the GC
222 ErrorF("X internal error: trying to rotate odd-sized pixmap.\n");
227 /* Rotates pixmap pPix by h lines. Assumes that h is always less than
232 mfbYRotatePixmap(pPix
, rh
)
233 register PixmapPtr pPix
;
236 int nbyDown
; /* bytes to move down to row 0; also offset of
238 int nbyUp
; /* bytes to move up to line rh; also
239 offset of first line moved down to 0 */
244 if (pPix
== NullPixmap
)
246 height
= (int) pPix
->drawable
.height
;
251 pbase
= (char *)pPix
->devPrivate
.ptr
;
253 nbyDown
= rh
* pPix
->devKind
;
254 nbyUp
= (pPix
->devKind
* height
) - nbyDown
;
255 if(!(ptmp
= (char *)ALLOCATE_LOCAL(nbyUp
)))
258 memmove(ptmp
, pbase
, nbyUp
); /* save the low rows */
259 memmove(pbase
, pbase
+nbyUp
, nbyDown
); /* slide the top rows down */
260 memmove(pbase
+nbyDown
, ptmp
, nbyUp
); /* move lower rows up to row rh */
261 DEALLOCATE_LOCAL(ptmp
);
265 mfbCopyRotatePixmap(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
))
275 memmove((char *)pdstPix
->devPrivate
.ptr
,
276 (char *)psrcPix
->devPrivate
.ptr
,
277 psrcPix
->drawable
.height
* psrcPix
->devKind
);
278 pdstPix
->drawable
.width
= psrcPix
->drawable
.width
;
279 pdstPix
->drawable
.serialNumber
= NEXT_SERIAL_NUMBER
;
285 (*pdstPix
->drawable
.pScreen
->DestroyPixmap
)(pdstPix
);
286 *ppdstPix
= pdstPix
= mfbCopyPixmap(psrcPix
);
290 mfbPadPixmap(pdstPix
);
292 mfbXRotatePixmap(pdstPix
, xrot
);
294 mfbYRotatePixmap(pdstPix
, yrot
);