~ubuntu-branches/ubuntu/edgy/xorg-server/edgy-updates

« back to all changes in this revision

Viewing changes to ilbm/ilbmimage.c

  • Committer: Bazaar Package Importer
  • Author(s): Rodrigo Parra Novo
  • Date: 2006-07-25 20:06:28 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20060725200628-gjmmd9gxfxdc4ejs
Tags: 1:1.1.1-0ubuntu1
* New Upstream version
* Changed Build-Depends from mesa-swrast-source to mesa-swx11-source,
  following Debian package nomenclature
* Re-did 12_security_policy_in_etc.diff for 1.1.1
* Dropped 15_security_allocate_local.diff (applied upstream)
* Dropped 16_SECURITY_setuid.diff (applied upstream)
* Dropped 000_ubuntu_fix_read_kernel_mapping.patch (applied upstream)
* Dropped 002_ubuntu_fix_for_certain_intel_chipsets.patch (applied upstream)
* Updated versioned Build-Depends on mesa-swx11-source to version
  6.5.0.cvs.20060725-0ubuntu1
* Added arrayobj.c, arrayobj.h, bitset.h & rbadaptors.h to
  GL/symlink-mesa.sh (linked from mesa-swx11-source)
* Added arrayobj.c to default build target on GL/mesa/main

Show diffs side-by-side

added added

removed removed

Lines of Context:
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>
4
 
#endif
5
 
 
6
 
#include <stdio.h>
7
 
 
8
 
/* Modified jun 95 by Geert Uytterhoeven (Geert.Uytterhoeven@cs.kuleuven.ac.be)
9
 
   to use interleaved bitplanes instead of normal bitplanes */
10
 
 
11
 
#include <X11/X.h>
12
 
#include "windowstr.h"
13
 
#include "pixmapstr.h"
14
 
#include "scrnintstr.h"
15
 
#include "gcstruct.h"
16
 
#include "ilbm.h"
17
 
#include "maskbits.h"
18
 
#include "servermd.h"
19
 
 
20
 
void
21
 
ilbmPutImage(pDraw, pGC, depth, x, y, width, height, leftPad, format, pImage)
22
 
        DrawablePtr pDraw;
23
 
        GCPtr pGC;
24
 
        int depth, x, y, width, height;
25
 
        int leftPad;
26
 
        int format;
27
 
        char *pImage;
28
 
{
29
 
        PixmapPtr pPixmap;
30
 
 
31
 
#if 1
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);
35
 
        switch (format) {
36
 
                case XYBitmap:
37
 
                        fprintf(stderr, "\tformat = XYBitmap\n");
38
 
                        break;
39
 
                case XYPixmap:
40
 
                        fprintf(stderr, "\tformat = XYPixmap\n");
41
 
                        break;
42
 
                case ZPixmap:
43
 
                        fprintf(stderr, "\tformat = ZPixmap\n");
44
 
                        break;
45
 
                default:
46
 
                        fprintf(stderr, "\tformat = %d\n");
47
 
                        break;
48
 
        }
49
 
#endif
50
 
 
51
 
        if ((width == 0) || (height == 0))
52
 
                return;
53
 
 
54
 
        if (format != ZPixmap || depth == 1 || pDraw->depth == 1) {
55
 
                if (format == XYBitmap) {
56
 
                        char *ptmp;
57
 
                        int realwidth;
58
 
                        int size;
59
 
                        int aux;
60
 
                        int d, yy, xx;
61
 
                        char *ss, *dd;
62
 
 
63
 
                        realwidth = BitmapBytePad(width+leftPad);
64
 
                        aux = depth*realwidth;
65
 
                        size = height*aux;
66
 
 
67
 
#if 1
68
 
                        fprintf(stderr, "\trealwidth = %d, aux = %d, size = %d\n", realwidth,
69
 
                                          aux, size);
70
 
#endif
71
 
 
72
 
                        if (!(ptmp = (char *)ALLOCATE_LOCAL(size)))
73
 
                                return;
74
 
 
75
 
                        /*
76
 
                         *              Convert from bitplanes to interleaved bitplanes
77
 
                         */
78
 
 
79
 
                        ss = (char *)pImage;
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++)
84
 
#if 1
85
 
                                        {
86
 
                                                fprintf(stderr, "*(%d) = *(%d)\n", (&dd[xx])-ptmp,
87
 
                                                                  ss-(char *)pImage);
88
 
#endif
89
 
                                                dd[xx] = *(ss++);
90
 
#if 1
91
 
                                        }
92
 
#endif
93
 
                                        dd += aux;
94
 
                                }
95
 
                        }
96
 
 
97
 
                        pPixmap = GetScratchPixmapHeader(pDraw->pScreen, width+leftPad, height,
98
 
                                                                                                                depth, depth,
99
 
                                                                                                                BitmapBytePad(width+leftPad),
100
 
                                                                                                                (pointer)ptmp);
101
 
                        if (!pPixmap) {
102
 
                                DEALLOCATE_LOCAL(ptmp);
103
 
                                return;
104
 
                        }
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);
109
 
                } else {
110
 
#if 0
111
 
                        /* XXX: bit plane order wronge ! */
112
 
                        pPixmap->drawable.depth = 1;
113
 
                        pPixmap->drawable.bitsPerPixel = 1;
114
 
 
115
 
                        switch (pGC->alu) {
116
 
                                case GXcopy:
117
 
                                        doBitBlt = ilbmDoBitbltCopy;
118
 
                                        break;
119
 
                                case GXxor:
120
 
                                        doBitBlt = ilbmDoBitbltXor;
121
 
                                        break;
122
 
                                case GXcopyInverted:
123
 
                                        doBitBlt = ilbmDoBitbltCopyInverted;
124
 
                                        break;
125
 
                                case GXor:
126
 
                                        doBitBlt = ilbmDoBitbltOr;
127
 
                                        break;
128
 
                                default:
129
 
                                        doBitBlt = ilbmDoBitbltGeneral;
130
 
                                        break;
131
 
                        }
132
 
 
133
 
                        for (plane = (1L << (pPixmap->drawable.depth - 1)); plane;
134
 
                                  plane >>= 1) {
135
 
                                (void)ilbmBitBlt((DrawablePtr)pPixmap, pDraw, pGC, leftPad, 0,
136
 
                                                                          width, height, x, y, doBitBlt, plane);
137
 
                                /* pDraw->devKind += sizeDst; */
138
 
                        }
139
 
#else
140
 
                        char *ptmp;
141
 
                        int realwidth;
142
 
                        int size;
143
 
                        int aux;
144
 
                        int d, yy, xx;
145
 
                        char *ss, *dd;
146
 
 
147
 
                        realwidth = BitmapBytePad(width+leftPad);
148
 
                        aux = depth*realwidth;
149
 
                        size = height*aux;
150
 
 
151
 
#if 1
152
 
                        fprintf(stderr, "\trealwidth = %d, aux = %d, size = %d\n", realwidth,
153
 
                                          aux, size);
154
 
#endif
155
 
 
156
 
                        if (!(ptmp = (char *)ALLOCATE_LOCAL(size)))
157
 
                                return;
158
 
 
159
 
                        /*
160
 
                         *              Convert from bitplanes to interleaved bitplanes
161
 
                         */
162
 
 
163
 
                        ss = (char *)pImage;
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++)
168
 
#if 1
169
 
                                        {
170
 
                                                fprintf(stderr, "*(%d) = *(%d)\n", (&dd[xx])-ptmp,
171
 
                                                                  ss-(char *)pImage);
172
 
#endif
173
 
                                                dd[xx] = *(ss++);
174
 
#if 1
175
 
                                        }
176
 
#endif
177
 
                                        dd += aux;
178
 
                                }
179
 
                        }
180
 
 
181
 
                        pPixmap = GetScratchPixmapHeader(pDraw->pScreen, width+leftPad, height,
182
 
                                                                                                                depth, depth,
183
 
                                                                                                                BitmapBytePad(width+leftPad),
184
 
                                                                                                                (pointer)ptmp);
185
 
                        if (!pPixmap) {
186
 
                                DEALLOCATE_LOCAL(ptmp);
187
 
                                return;
188
 
                        }
189
 
 
190
 
                        pGC->fExpose = FALSE;
191
 
                        (void)(*pGC->ops->CopyArea)((DrawablePtr)pPixmap, pDraw, pGC, leftPad,
192
 
                                                                                                 0, width, height, x, y);
193
 
                        DEALLOCATE_LOCAL(ptmp);
194
 
#endif
195
 
                }
196
 
 
197
 
                pGC->fExpose = TRUE;
198
 
                FreeScratchPixmapHeader(pPixmap);
199
 
        } else {
200
 
                /* Chunky to planar conversion required */
201
 
 
202
 
                PixmapPtr pPixmap;
203
 
                ScreenPtr pScreen = pDraw->pScreen;
204
 
                int widthSrc;
205
 
                int start_srcshift;
206
 
                register int b;
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;
213
 
                int start_bit;
214
 
                register int nl;
215
 
                register int h;
216
 
                register int d;
217
 
                int auxDst;
218
 
                PixelType *pdstBase;
219
 
                int widthDst;
220
 
                int depthDst;
221
 
 
222
 
                /* Create a tmp pixmap */
223
 
                pPixmap = (pScreen->CreatePixmap)(pScreen, width, height, depth);
224
 
                if (!pPixmap)
225
 
                        return;
226
 
 
227
 
                ilbmGetPixelWidthAuxDepthAndPointer((DrawablePtr)pPixmap, widthDst,
228
 
                                                                                                                auxDst, depthDst, pdstBase);
229
 
 
230
 
                widthSrc = PixmapWidthInPadUnits(width, depth);
231
 
                /* XXX: if depth == 8, use fast chunky to planar assembly function.*/
232
 
                if (depth > 4) {
233
 
                        start_srcshift = 24;
234
 
                        shift_step = 8;
235
 
                } else {
236
 
                        start_srcshift = 28;
237
 
                        shift_step = 4;
238
 
                }
239
 
 
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;
244
 
                        h = height;
245
 
 
246
 
                        while (h--) {
247
 
                                pdst = pdstLine;
248
 
                                pdstLine += auxDst;
249
 
                                dstshift = PPW - 1;
250
 
                                dst = 0;
251
 
                                nl = widthSrc;
252
 
                                while (nl--) {
253
 
                                        srcbits = *psrc++;
254
 
                                        for (b = start_bit; b >= 0; b -= shift_step) {
255
 
                                                dst |= ((srcbits >> b) & 1) << dstshift;
256
 
                                                if (--dstshift < 0) {
257
 
                                                        dstshift = PPW - 1;
258
 
                                                        *pdst++ = dst;
259
 
                                                        dst = 0;
260
 
                                                }
261
 
                                        }
262
 
                                }
263
 
                                if (dstshift != PPW - 1)
264
 
                                        *pdst++ = dst;
265
 
                        }
266
 
                } /* for (d = ...) */
267
 
 
268
 
                pGC->fExpose = FALSE;
269
 
                (void)(*pGC->ops->CopyArea)((DrawablePtr)pPixmap, pDraw, pGC, leftPad, 0,
270
 
                                                                                         width, height, x, y);
271
 
                pGC->fExpose = TRUE;
272
 
                (*pScreen->DestroyPixmap)(pPixmap);
273
 
        }
274
 
}
275
 
 
276
 
void
277
 
ilbmGetImage(pDrawable, sx, sy, width, height, format, planemask, pdstLine)
278
 
        DrawablePtr pDrawable;
279
 
        int sx, sy, width, height;
280
 
        unsigned int format;
281
 
        unsigned long planemask;
282
 
        char *pdstLine;
283
 
{
284
 
        BoxRec box;
285
 
        DDXPointRec ptSrc;
286
 
        RegionRec rgnDst;
287
 
        ScreenPtr pScreen;
288
 
        PixmapPtr pPixmap;
289
 
 
290
 
#if 1
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);
294
 
        switch (format) {
295
 
                case XYBitmap:
296
 
                        fprintf(stderr, "\tformat = XYBitmap\n");
297
 
                        break;
298
 
                case XYPixmap:
299
 
                        fprintf(stderr, "\tformat = XYPixmap\n");
300
 
                        break;
301
 
                case ZPixmap:
302
 
                        fprintf(stderr, "\tformat = ZPixmap\n");
303
 
                        break;
304
 
                default:
305
 
                        fprintf(stderr, "\tformat = %d\n");
306
 
                        break;
307
 
        }
308
 
#endif
309
 
 
310
 
        if ((width == 0) || (height == 0))
311
 
                return;
312
 
 
313
 
        pScreen = pDrawable->pScreen;
314
 
        sx += pDrawable->x;
315
 
        sy += pDrawable->y;
316
 
 
317
 
        if (format == XYPixmap || pDrawable->depth == 1) {
318
 
                pPixmap = GetScratchPixmapHeader(pScreen, width, height, 1, 1,
319
 
                                                                                                        BitmapBytePad(width), (pointer)pdstLine);
320
 
                if (!pPixmap)
321
 
                        return;
322
 
 
323
 
                ptSrc.x = sx;
324
 
                ptSrc.y = sy;
325
 
                box.x1 = 0;
326
 
                box.y1 = 0;
327
 
                box.x2 = width;
328
 
                box.y2 = height;
329
 
                REGION_INIT(pScreen, &rgnDst, &box, 1);
330
 
 
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.
335
 
                 */
336
 
                ilbmDoBitblt(pDrawable, (DrawablePtr)pPixmap, GXcopy, &rgnDst, &ptSrc,
337
 
                                                 planemask);
338
 
 
339
 
                FreeScratchPixmapHeader(pPixmap);
340
 
                REGION_UNINIT(pScreen, &rgnDst);
341
 
        } else {
342
 
                /* Planar to chunky conversion required */
343
 
 
344
 
                PixelType *psrcBits;
345
 
                PixelType *psrcLine;
346
 
                PixelType startmask, endmask;
347
 
                int depthSrc;
348
 
                int widthSrc;
349
 
                int auxSrc;
350
 
                int sizeDst;
351
 
                int widthDst;
352
 
                register PixelType *psrc;
353
 
                register PixelType *pdst;
354
 
                register PixelType dst;
355
 
                register PixelType srcbits;
356
 
                register int d;
357
 
                register int b;
358
 
                register int dstshift;
359
 
                register int shift_step;
360
 
                register int start_endbit;
361
 
                int start_startbit;
362
 
                register int end_endbit;
363
 
                register int start_dstshift;
364
 
                register int nl;
365
 
                register int h;
366
 
                int nlmiddle;
367
 
 
368
 
                widthDst = PixmapWidthInPadUnits(width, pDrawable->depth);
369
 
                sizeDst = widthDst * height;
370
 
 
371
 
                /* Clear the dest image */
372
 
                bzero(pdstLine, sizeDst << 2);
373
 
 
374
 
                ilbmGetPixelWidthAuxDepthAndPointer(pDrawable, widthSrc, auxSrc,
375
 
                                                                                                                depthSrc, psrcBits);
376
 
 
377
 
                psrcBits = ilbmScanline(psrcBits, sx, sy, auxSrc);
378
 
 
379
 
                start_startbit = PPW - 1 - (sx & PIM);
380
 
                if ((sx & PIM) + width < PPW) {
381
 
                        maskpartialbits(sx, width, startmask);
382
 
                        nlmiddle = 0;
383
 
                        endmask = 0;
384
 
                        start_endbit = PPW - ((sx + width) & PIM);
385
 
                } else {
386
 
                        maskbits(sx, width, startmask, endmask, nlmiddle);
387
 
                        start_endbit = 0;
388
 
                        end_endbit = PPW - ((sx + width) & PIM);
389
 
                }
390
 
                /* ZPixmap images have either 4 or 8 bits per pixel dependent on
391
 
                 * depth.
392
 
                 */
393
 
                if (depthSrc > 4) {
394
 
                        start_dstshift = 24;
395
 
                        shift_step = 8;
396
 
                } else {
397
 
                        start_dstshift = 28;
398
 
                        shift_step = 4;
399
 
                }
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; \
405
 
                *pdst++ = dst; \
406
 
                dst = *pdst; \
407
 
        } \
408
 
} \
409
 
 
410
 
                for (d = 0; d < depthSrc; d++, psrcBits += widthSrc) {  /* @@@ NEXT PLANE @@@ */
411
 
                        psrcLine = psrcBits;
412
 
                        pdst = (PixelType *)pdstLine;
413
 
                        h = height;
414
 
 
415
 
                        while (h--) {
416
 
                                psrc = psrcLine;
417
 
                                psrcLine += auxSrc;
418
 
                                dst = *pdst;
419
 
                                dstshift = start_dstshift + d;
420
 
 
421
 
                                if (startmask) {
422
 
                                        srcbits = *psrc++ & startmask;
423
 
                                        SHIFT_BITS(start_startbit, start_endbit);
424
 
                                }
425
 
 
426
 
                                nl = nlmiddle;
427
 
                                while (nl--) {
428
 
                                        srcbits = *psrc++;
429
 
                                        SHIFT_BITS(PPW - 1, 0);
430
 
                                }
431
 
                                if (endmask) {
432
 
                                        srcbits = *psrc & endmask;
433
 
                                        SHIFT_BITS(PPW - 1, end_endbit);
434
 
                                }
435
 
 
436
 
                                if (dstshift != start_dstshift + d)
437
 
                                        *pdst++ = dst;
438
 
                        } /* while (h--) */
439
 
                } /* for (d = ...) */
440
 
        }
441
 
}