2
/***********************************************************
4
Copyright (c) 1987 X Consortium
6
Permission is hereby granted, free of charge, to any person obtaining a copy
7
of this software and associated documentation files (the "Software"), to deal
8
in the Software without restriction, including without limitation the rights
9
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
copies of the Software, and to permit persons to whom the Software is
11
furnished to do so, subject to the following conditions:
13
The above copyright notice and this permission notice shall be included in
14
all copies or substantial portions of the Software.
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
Except as contained in this notice, the name of the X Consortium shall not be
24
used in advertising or otherwise to promote the sale, use or other dealings
25
in this Software without prior written authorization from the X Consortium.
28
Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
32
Permission to use, copy, modify, and distribute this software and its
33
documentation for any purpose and without fee is hereby granted,
34
provided that the above copyright notice appear in all copies and that
35
both that copyright notice and this permission notice appear in
36
supporting documentation, and that the name of Digital not be
37
used in advertising or publicity pertaining to distribution of the
38
software without specific, written prior permission.
40
DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
41
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
42
DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
43
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
44
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
45
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
48
******************************************************************/
49
/* $XConsortium: ilbmpixmap.c,v 5.13 94/04/17 20:28:28 dpw Exp $ */
52
written by drewry, september 1986
54
on a monchrome device, a pixmap is a bitmap.
57
/* Modified jun 95 by Geert Uytterhoeven (Geert.Uytterhoeven@cs.kuleuven.ac.be)
58
to use interleaved bitplanes instead of normal bitplanes */
60
#ifdef HAVE_DIX_CONFIG_H
61
#include <dix-config.h>
65
#include "scrnintstr.h"
66
#include "pixmapstr.h"
75
ilbmCreatePixmap(pScreen, width, height, depth)
85
paddedWidth = BitmapBytePad(width);
86
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;
106
pPixmap->devPrivate.ptr = datasize ?
107
(pointer)((char *)pPixmap + pScreen->totalPixmapSize) : NULL;
109
pPixmap->devPrivate.ptr = (pointer)(pPixmap + 1);
115
ilbmDestroyPixmap(pPixmap)
118
if (--pPixmap->refcnt)
127
register PixmapPtr pSrc;
129
register PixmapPtr pDst;
133
size = pSrc->drawable.height * pSrc->devKind * pSrc->drawable.depth;
134
pScreen = pSrc->drawable.pScreen;
135
pDst = (*pScreen->CreatePixmap)(pScreen, pSrc->drawable.width,
136
pSrc->drawable.height, pSrc->drawable.depth);
139
memmove((char *)pDst->devPrivate.ptr, (char *)pSrc->devPrivate.ptr, size);
144
/* replicates a pattern to be a full 32 bits wide.
145
relies on the fact that each scnaline is longword padded.
146
doesn't do anything if pixmap is not a factor of 32 wide.
147
changes width field of pixmap if successful, so that the fast
148
XRotatePixmap code gets used if we rotate the pixmap later.
150
calculate number of times to repeat
151
for each scanline of pattern
152
zero out area to be filled with replicate
153
left shift and or in original as many times as needed
156
ilbmPadPixmap(pPixmap)
159
register int width = pPixmap->drawable.width;
161
register PixelType mask;
162
register PixelType *p;
163
register PixelType bits; /* real pattern bits */
166
int rep; /* repeat count for pattern */
172
if (rep*width != PPW)
175
mask = endtab[width];
177
p = (PixelType *)(pPixmap->devPrivate.ptr);
179
for (d = 0; d < pPixmap->drawable.depth; d++) {
180
for (h = 0; h < pPixmap->drawable.height; h++) {
183
for (i = 1; i < rep; i++) {
184
bits = SCRRIGHT(bits, width);
190
pPixmap->drawable.width = PPW;
193
/* Rotates pixmap pPix by w pixels to the right on the screen. Assumes that
194
* words are PPW bits wide, and that the least significant bit appears on the
198
ilbmXRotatePixmap(pPix, rw)
202
register PixelType *pw, *pwFinal;
203
register PixelType t;
205
if (pPix == NullPixmap)
208
pw = (PixelType *)pPix->devPrivate.ptr;
209
rw %= (int)pPix->drawable.width;
211
rw += (int)pPix->drawable.width;
212
if (pPix->drawable.width == PPW) {
213
pwFinal = pw + pPix->drawable.height * pPix->drawable.depth;
214
while (pw < pwFinal) {
216
*pw++ = SCRRIGHT(t, rw) | (SCRLEFT(t, (PPW-rw)) & endtab[rw]);
219
/* We no longer do this. Validate doesn't try to rotate odd-size
220
* tiles or stipples. ilbmUnnatural<tile/stipple>FS works directly off
221
* the unrotate tile/stipple in the GC
223
ErrorF("X internal error: trying to rotate odd-sized pixmap.\n");
228
/* Rotates pixmap pPix by h lines. Assumes that h is always less than
233
ilbmYRotatePixmap(pPix, rh)
234
register PixmapPtr pPix;
237
int nbyDown; /* bytes to move down to row 0; also offset of
239
int nbyUp; /* bytes to move up to line rh; also
240
offset of first line moved down to 0 */
246
if (pPix == NullPixmap)
248
height = (int) pPix->drawable.height;
253
aux = pPix->devKind*pPix->drawable.depth;
255
nbyUp = height*aux-nbyDown;
257
if (!(ptmp = (char *)ALLOCATE_LOCAL(nbyUp)))
260
pbase = (char *)pPix->devPrivate.ptr;
261
memmove(ptmp, pbase, nbyUp); /* save the low rows */
262
memmove(pbase, pbase+nbyUp, nbyDown); /* slide the top rows down */
263
memmove(pbase+nbyDown, ptmp, nbyUp); /* move lower rows up to row rh */
264
DEALLOCATE_LOCAL(ptmp);
268
ilbmCopyRotatePixmap(psrcPix, ppdstPix, xrot, yrot)
269
register PixmapPtr psrcPix, *ppdstPix;
272
register PixmapPtr pdstPix;
274
if ((pdstPix = *ppdstPix) && (pdstPix->devKind == psrcPix->devKind) &&
275
(pdstPix->drawable.height == psrcPix->drawable.height) &&
276
(pdstPix->drawable.depth == psrcPix->drawable.depth)) {
277
memmove((char *)pdstPix->devPrivate.ptr, (char *)psrcPix->devPrivate.ptr,
278
psrcPix->drawable.height * psrcPix->devKind *
279
psrcPix->drawable.depth);
280
pdstPix->drawable.width = psrcPix->drawable.width;
281
pdstPix->drawable.serialNumber = NEXT_SERIAL_NUMBER;
285
(*pdstPix->drawable.pScreen->DestroyPixmap)(pdstPix);
286
*ppdstPix = pdstPix = ilbmCopyPixmap(psrcPix);
290
ilbmPadPixmap(pdstPix);
292
ilbmXRotatePixmap(pdstPix, xrot);
294
ilbmYRotatePixmap(pdstPix, yrot);