1
/* $XFree86: xc/programs/Xserver/ilbm/ilbmimage.c,v 3.0 1996/08/18 01:53:56 dawes Exp $ */
2
#ifdef HAVE_DIX_CONFIG_H
3
#include <dix-config.h>
8
/* Modified jun 95 by Geert Uytterhoeven (Geert.Uytterhoeven@cs.kuleuven.ac.be)
9
to use interleaved bitplanes instead of normal bitplanes */
12
#include "windowstr.h"
13
#include "pixmapstr.h"
14
#include "scrnintstr.h"
21
ilbmPutImage(pDraw, pGC, depth, x, y, width, height, leftPad, format, pImage)
24
int depth, x, y, width, height;
32
fprintf(stderr, "ilbmPutImage()\n");
33
fprintf(stderr, "\tdepth = %d, x = %d, y = %d, width = %d, height = %d, "
34
"leftPad = %d\n", depth, x, y, width, height, leftPad);
37
fprintf(stderr, "\tformat = XYBitmap\n");
40
fprintf(stderr, "\tformat = XYPixmap\n");
43
fprintf(stderr, "\tformat = ZPixmap\n");
46
fprintf(stderr, "\tformat = %d\n");
51
if ((width == 0) || (height == 0))
54
if (format != ZPixmap || depth == 1 || pDraw->depth == 1) {
55
if (format == XYBitmap) {
63
realwidth = BitmapBytePad(width+leftPad);
64
aux = depth*realwidth;
68
fprintf(stderr, "\trealwidth = %d, aux = %d, size = %d\n", realwidth,
72
if (!(ptmp = (char *)ALLOCATE_LOCAL(size)))
76
* Convert from bitplanes to interleaved bitplanes
80
for (d = 0; d < depth; d++) {
81
dd = ptmp+d*realwidth;
82
for (yy = 0; yy < height; yy++) {
83
for (xx = 0; xx < realwidth; xx++)
86
fprintf(stderr, "*(%d) = *(%d)\n", (&dd[xx])-ptmp,
97
pPixmap = GetScratchPixmapHeader(pDraw->pScreen, width+leftPad, height,
99
BitmapBytePad(width+leftPad),
102
DEALLOCATE_LOCAL(ptmp);
105
pGC->fExpose = FALSE;
106
(void)(*pGC->ops->CopyPlane)((DrawablePtr)pPixmap, pDraw, pGC, leftPad,
107
0, width, height, x, y, 1);
108
DEALLOCATE_LOCAL(ptmp);
111
/* XXX: bit plane order wronge ! */
112
pPixmap->drawable.depth = 1;
113
pPixmap->drawable.bitsPerPixel = 1;
117
doBitBlt = ilbmDoBitbltCopy;
120
doBitBlt = ilbmDoBitbltXor;
123
doBitBlt = ilbmDoBitbltCopyInverted;
126
doBitBlt = ilbmDoBitbltOr;
129
doBitBlt = ilbmDoBitbltGeneral;
133
for (plane = (1L << (pPixmap->drawable.depth - 1)); plane;
135
(void)ilbmBitBlt((DrawablePtr)pPixmap, pDraw, pGC, leftPad, 0,
136
width, height, x, y, doBitBlt, plane);
137
/* pDraw->devKind += sizeDst; */
147
realwidth = BitmapBytePad(width+leftPad);
148
aux = depth*realwidth;
152
fprintf(stderr, "\trealwidth = %d, aux = %d, size = %d\n", realwidth,
156
if (!(ptmp = (char *)ALLOCATE_LOCAL(size)))
160
* Convert from bitplanes to interleaved bitplanes
164
for (d = 0; d < depth; d++) {
165
dd = ptmp+d*realwidth;
166
for (yy = 0; yy < height; yy++) {
167
for (xx = 0; xx < realwidth; xx++)
170
fprintf(stderr, "*(%d) = *(%d)\n", (&dd[xx])-ptmp,
181
pPixmap = GetScratchPixmapHeader(pDraw->pScreen, width+leftPad, height,
183
BitmapBytePad(width+leftPad),
186
DEALLOCATE_LOCAL(ptmp);
190
pGC->fExpose = FALSE;
191
(void)(*pGC->ops->CopyArea)((DrawablePtr)pPixmap, pDraw, pGC, leftPad,
192
0, width, height, x, y);
193
DEALLOCATE_LOCAL(ptmp);
198
FreeScratchPixmapHeader(pPixmap);
200
/* Chunky to planar conversion required */
203
ScreenPtr pScreen = pDraw->pScreen;
207
register int dstshift;
208
register int shift_step;
209
register PixelType dst;
210
register PixelType srcbits;
211
register PixelType *pdst;
212
register PixelType *psrc;
222
/* Create a tmp pixmap */
223
pPixmap = (pScreen->CreatePixmap)(pScreen, width, height, depth);
227
ilbmGetPixelWidthAuxDepthAndPointer((DrawablePtr)pPixmap, widthDst,
228
auxDst, depthDst, pdstBase);
230
widthSrc = PixmapWidthInPadUnits(width, depth);
231
/* XXX: if depth == 8, use fast chunky to planar assembly function.*/
240
for (d = 0; d < depth; d++, pdstBase += widthDst) { /* @@@ NEXT PLANE @@@ */
241
register PixelType *pdstLine = pdstBase;
242
start_bit = start_srcshift + d;
243
psrc = (PixelType *)pImage;
254
for (b = start_bit; b >= 0; b -= shift_step) {
255
dst |= ((srcbits >> b) & 1) << dstshift;
256
if (--dstshift < 0) {
263
if (dstshift != PPW - 1)
266
} /* for (d = ...) */
268
pGC->fExpose = FALSE;
269
(void)(*pGC->ops->CopyArea)((DrawablePtr)pPixmap, pDraw, pGC, leftPad, 0,
270
width, height, x, y);
272
(*pScreen->DestroyPixmap)(pPixmap);
277
ilbmGetImage(pDrawable, sx, sy, width, height, format, planemask, pdstLine)
278
DrawablePtr pDrawable;
279
int sx, sy, width, height;
281
unsigned long planemask;
291
fprintf(stderr, "ilbmGetImage()\n");
292
fprintf(stderr, "\tsx = %d, sy = %d, width = %d, height = %d, "
293
"planemask = 0x%08x\n", sx, sy, width, height, planemask);
296
fprintf(stderr, "\tformat = XYBitmap\n");
299
fprintf(stderr, "\tformat = XYPixmap\n");
302
fprintf(stderr, "\tformat = ZPixmap\n");
305
fprintf(stderr, "\tformat = %d\n");
310
if ((width == 0) || (height == 0))
313
pScreen = pDrawable->pScreen;
317
if (format == XYPixmap || pDrawable->depth == 1) {
318
pPixmap = GetScratchPixmapHeader(pScreen, width, height, 1, 1,
319
BitmapBytePad(width), (pointer)pdstLine);
329
REGION_INIT(pScreen, &rgnDst, &box, 1);
331
pPixmap->drawable.depth = 1;
332
pPixmap->drawable.bitsPerPixel = 1;
333
/* dix layer only ever calls GetImage with 1 bit set in planemask
334
* when format is XYPixmap.
336
ilbmDoBitblt(pDrawable, (DrawablePtr)pPixmap, GXcopy, &rgnDst, &ptSrc,
339
FreeScratchPixmapHeader(pPixmap);
340
REGION_UNINIT(pScreen, &rgnDst);
342
/* Planar to chunky conversion required */
346
PixelType startmask, endmask;
352
register PixelType *psrc;
353
register PixelType *pdst;
354
register PixelType dst;
355
register PixelType srcbits;
358
register int dstshift;
359
register int shift_step;
360
register int start_endbit;
362
register int end_endbit;
363
register int start_dstshift;
368
widthDst = PixmapWidthInPadUnits(width, pDrawable->depth);
369
sizeDst = widthDst * height;
371
/* Clear the dest image */
372
bzero(pdstLine, sizeDst << 2);
374
ilbmGetPixelWidthAuxDepthAndPointer(pDrawable, widthSrc, auxSrc,
377
psrcBits = ilbmScanline(psrcBits, sx, sy, auxSrc);
379
start_startbit = PPW - 1 - (sx & PIM);
380
if ((sx & PIM) + width < PPW) {
381
maskpartialbits(sx, width, startmask);
384
start_endbit = PPW - ((sx + width) & PIM);
386
maskbits(sx, width, startmask, endmask, nlmiddle);
388
end_endbit = PPW - ((sx + width) & PIM);
390
/* ZPixmap images have either 4 or 8 bits per pixel dependent on
400
#define SHIFT_BITS(start_bit,end_bit) \
401
for (b = (start_bit); b >= (end_bit); b--) { \
402
dst |= ((srcbits >> b) & 1) << dstshift; \
403
if ((dstshift -= shift_step) < 0) { \
404
dstshift = start_dstshift + d; \
410
for (d = 0; d < depthSrc; d++, psrcBits += widthSrc) { /* @@@ NEXT PLANE @@@ */
412
pdst = (PixelType *)pdstLine;
419
dstshift = start_dstshift + d;
422
srcbits = *psrc++ & startmask;
423
SHIFT_BITS(start_startbit, start_endbit);
429
SHIFT_BITS(PPW - 1, 0);
432
srcbits = *psrc & endmask;
433
SHIFT_BITS(PPW - 1, end_endbit);
436
if (dstshift != start_dstshift + d)
439
} /* for (d = ...) */