~ubuntu-branches/ubuntu/gutsy/vnc4/gutsy

« back to all changes in this revision

Viewing changes to unix/xc/extras/Mesa/src/X/xm_span.c

  • Committer: Bazaar Package Importer
  • Author(s): Ola Lundqvist
  • Date: 2006-05-15 20:35:17 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060515203517-l4lre1ku942mn26k
Tags: 4.1.1+X4.3.0-10
* Correction of critical security issue. Thanks to Martin Kogler
  <e9925248@student.tuwien.ac.at> that informed me about the issue,
  and provided the patch.
  This flaw was originally found by Steve Wiseman of intelliadmin.com.
* Applied patch from Javier Kohen <jkohen@users.sourceforge.net> that
  inform the user that only 8 first characters of the password will
  actually be used when typing more than 8 characters, closes:
  #355619.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/*
 
3
 * Mesa 3-D graphics library
 
4
 * Version:  3.5
 
5
 *
 
6
 * Copyright (C) 1999-2001  Brian Paul   All Rights Reserved.
 
7
 *
 
8
 * Permission is hereby granted, free of charge, to any person obtaining a
 
9
 * copy of this software and associated documentation files (the "Software"),
 
10
 * to deal in the Software without restriction, including without limitation
 
11
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 
12
 * and/or sell copies of the Software, and to permit persons to whom the
 
13
 * Software is furnished to do so, subject to the following conditions:
 
14
 *
 
15
 * The above copyright notice and this permission notice shall be included
 
16
 * in all copies or substantial portions of the Software.
 
17
 *
 
18
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 
19
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
20
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 
21
 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
 
22
 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 
23
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
24
 */
 
25
/* $XFree86: xc/extras/Mesa/src/X/xm_span.c,v 1.5 2002/12/16 16:18:31 dawes Exp $ */
 
26
 
 
27
#include "glxheader.h"
 
28
#include "context.h"
 
29
#include "drawpix.h"
 
30
#include "mem.h"
 
31
#include "state.h"
 
32
#include "depth.h"
 
33
#include "macros.h"
 
34
#include "mtypes.h"
 
35
#include "xmesaP.h"
 
36
#include "extensions.h"
 
37
 
 
38
#include "swrast/swrast.h"
 
39
 
 
40
 
 
41
/*
 
42
 * The following functions are used to trap XGetImage() calls which
 
43
 * generate BadMatch errors if the drawable isn't mapped.
 
44
 */
 
45
 
 
46
#ifndef XFree86Server
 
47
static int caught_xgetimage_error = 0;
 
48
static int (*old_xerror_handler)( XMesaDisplay *dpy, XErrorEvent *ev );
 
49
static unsigned long xgetimage_serial;
 
50
 
 
51
/*
 
52
 * This is the error handler which will be called if XGetImage fails.
 
53
 */
 
54
static int xgetimage_error_handler( XMesaDisplay *dpy, XErrorEvent *ev )
 
55
{
 
56
   if (ev->serial==xgetimage_serial && ev->error_code==BadMatch) {
 
57
      /* caught the expected error */
 
58
      caught_xgetimage_error = 0;
 
59
   }
 
60
   else {
 
61
      /* call the original X error handler, if any.  otherwise ignore */
 
62
      if (old_xerror_handler) {
 
63
         (*old_xerror_handler)( dpy, ev );
 
64
      }
 
65
   }
 
66
   return 0;
 
67
}
 
68
 
 
69
 
 
70
/*
 
71
 * Call this right before XGetImage to setup error trap.
 
72
 */
 
73
static void catch_xgetimage_errors( XMesaDisplay *dpy )
 
74
{
 
75
   xgetimage_serial = NextRequest( dpy );
 
76
   old_xerror_handler = XSetErrorHandler( xgetimage_error_handler );
 
77
   caught_xgetimage_error = 0;
 
78
}
 
79
 
 
80
 
 
81
/*
 
82
 * Call this right after XGetImage to check if an error occured.
 
83
 */
 
84
static int check_xgetimage_errors( void )
 
85
{
 
86
   /* restore old handler */
 
87
   (void) XSetErrorHandler( old_xerror_handler );
 
88
   /* return 0=no error, 1=error caught */
 
89
   return caught_xgetimage_error;
 
90
}
 
91
#endif
 
92
 
 
93
 
 
94
/*
 
95
 * Read a pixel from an X drawable.
 
96
 */
 
97
static unsigned long read_pixel( XMesaDisplay *dpy,
 
98
                                 XMesaDrawable d, int x, int y )
 
99
{
 
100
   unsigned long p;
 
101
#ifndef XFree86Server
 
102
   XMesaImage *pixel = NULL;
 
103
   int error;
 
104
 
 
105
   catch_xgetimage_errors( dpy );
 
106
   pixel = XGetImage( dpy, d, x, y, 1, 1, AllPlanes, ZPixmap );
 
107
   error = check_xgetimage_errors();
 
108
   if (pixel && !error) {
 
109
      p = XMesaGetPixel( pixel, 0, 0 );
 
110
   }
 
111
   else {
 
112
      p = 0;
 
113
   }
 
114
   if (pixel) {
 
115
      XMesaDestroyImage( pixel );
 
116
   }
 
117
#else
 
118
   (*dpy->GetImage)(d, x, y, 1, 1, ZPixmap, ~0L, (pointer)&p);
 
119
#endif
 
120
   return p;
 
121
}
 
122
 
 
123
 
 
124
 
 
125
/*
 
126
 * The Mesa library needs to be able to draw pixels in a number of ways:
 
127
 *   1. RGB vs Color Index
 
128
 *   2. as horizontal spans (polygons, images) vs random locations (points,
 
129
 *      lines)
 
130
 *   3. different color per-pixel or same color for all pixels
 
131
 *
 
132
 * Furthermore, the X driver needs to support rendering to 3 possible
 
133
 * "buffers", usually one, but sometimes two at a time:
 
134
 *   1. The front buffer as an X window
 
135
 *   2. The back buffer as a Pixmap
 
136
 *   3. The back buffer as an XImage
 
137
 *
 
138
 * Finally, if the back buffer is an XImage, we can avoid using XPutPixel and
 
139
 * optimize common cases such as 24-bit and 8-bit modes.
 
140
 *
 
141
 * By multiplication, there's at least 48 possible combinations of the above.
 
142
 *
 
143
 * Below are implementations of the most commonly used combinations.  They are
 
144
 * accessed through function pointers which get initialized here and are used
 
145
 * directly from the Mesa library.  The 8 function pointers directly correspond
 
146
 * to the first 3 cases listed above.
 
147
 *
 
148
 *
 
149
 * The function naming convention is:
 
150
 *
 
151
 *   write_[span|pixels]_[mono]_[format]_[pixmap|ximage]
 
152
 *
 
153
 * New functions optimized for specific cases can be added without too much
 
154
 * trouble.  An example might be the 24-bit TrueColor mode 8A8R8G8B which is
 
155
 * found on IBM RS/6000 X servers.
 
156
 */
 
157
 
 
158
 
 
159
 
 
160
 
 
161
/**********************************************************************/
 
162
/*** Write COLOR SPAN functions                                     ***/
 
163
/**********************************************************************/
 
164
 
 
165
 
 
166
#define RGBA_SPAN_ARGS  const GLcontext *ctx,                           \
 
167
                        GLuint n, GLint x, GLint y,                     \
 
168
                        CONST GLubyte rgba[][4], const GLubyte mask[]
 
169
 
 
170
#define RGB_SPAN_ARGS   const GLcontext *ctx,                           \
 
171
                        GLuint n, GLint x, GLint y,                     \
 
172
                        CONST GLubyte rgb[][3], const GLubyte mask[]
 
173
 
 
174
 
 
175
/* NOTE: if mask==NULL, draw all pixels */
 
176
 
 
177
 
 
178
/*
 
179
 * Write a span of PF_TRUECOLOR pixels to a pixmap.
 
180
 */
 
181
static void write_span_TRUECOLOR_pixmap( RGBA_SPAN_ARGS )
 
182
{
 
183
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
184
   XMesaDisplay *dpy = xmesa->xm_visual->display;
 
185
   XMesaDrawable buffer = xmesa->xm_buffer->buffer;
 
186
   XMesaGC gc = xmesa->xm_buffer->gc;
 
187
   register GLuint i;
 
188
 
 
189
   (void)DitherValues;          /* Muffle compiler */
 
190
 
 
191
   y = FLIP(xmesa->xm_buffer, y);
 
192
   if (mask) {
 
193
      for (i=0;i<n;i++,x++) {
 
194
         if (mask[i]) {
 
195
            unsigned long p;
 
196
            PACK_TRUECOLOR( p, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
 
197
            XMesaSetForeground( dpy, gc, p );
 
198
            XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
 
199
         }
 
200
      }
 
201
   }
 
202
   else {
 
203
      /* draw all pixels */
 
204
      XMesaImage *rowimg = xmesa->xm_buffer->rowimage;
 
205
      for (i=0;i<n;i++) {
 
206
         unsigned long p;
 
207
         PACK_TRUECOLOR( p, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
 
208
         XMesaPutPixel( rowimg, i, 0, p );
 
209
      }
 
210
      XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
 
211
   }
 
212
}
 
213
 
 
214
 
 
215
/*
 
216
 * Write a span of PF_TRUECOLOR pixels to a pixmap.
 
217
 */
 
218
static void write_span_rgb_TRUECOLOR_pixmap( RGB_SPAN_ARGS )
 
219
{
 
220
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
221
   XMesaDisplay *dpy = xmesa->xm_visual->display;
 
222
   XMesaDrawable buffer = xmesa->xm_buffer->buffer;
 
223
   XMesaGC gc = xmesa->xm_buffer->gc;
 
224
   register GLuint i;
 
225
   y = FLIP(xmesa->xm_buffer, y);
 
226
   if (mask) {
 
227
      for (i=0;i<n;i++,x++) {
 
228
         if (mask[i]) {
 
229
            unsigned long p;
 
230
            PACK_TRUECOLOR( p, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
 
231
            XMesaSetForeground( dpy, gc, p );
 
232
            XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
 
233
         }
 
234
      }
 
235
   }
 
236
   else {
 
237
      /* draw all pixels */
 
238
      XMesaImage *rowimg = xmesa->xm_buffer->rowimage;
 
239
      for (i=0;i<n;i++) {
 
240
         unsigned long p;
 
241
         PACK_TRUECOLOR( p, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
 
242
         XMesaPutPixel( rowimg, i, 0, p );
 
243
      }
 
244
      XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
 
245
   }
 
246
}
 
247
 
 
248
 
 
249
/*
 
250
 * Write a span of PF_TRUEDITHER pixels to a pixmap.
 
251
 */
 
252
static void write_span_TRUEDITHER_pixmap( RGBA_SPAN_ARGS )
 
253
{
 
254
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
255
   XMesaDisplay *dpy = xmesa->xm_visual->display;
 
256
   XMesaDrawable buffer = xmesa->xm_buffer->buffer;
 
257
   XMesaGC gc = xmesa->xm_buffer->gc;
 
258
   register GLuint i;
 
259
   y = FLIP(xmesa->xm_buffer, y);
 
260
   if (mask) {
 
261
      for (i=0;i<n;i++,x++) {
 
262
         if (mask[i]) {
 
263
            unsigned long p;
 
264
            PACK_TRUEDITHER(p, x, y, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
 
265
            XMesaSetForeground( dpy, gc, p );
 
266
            XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
 
267
         }
 
268
      }
 
269
   }
 
270
   else {
 
271
      XMesaImage *rowimg = xmesa->xm_buffer->rowimage;
 
272
      for (i=0;i<n;i++) {
 
273
         unsigned long p;
 
274
         PACK_TRUEDITHER(p, x+i, y, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
 
275
         XMesaPutPixel( rowimg, i, 0, p );
 
276
      }
 
277
      XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
 
278
   }
 
279
}
 
280
 
 
281
 
 
282
/*
 
283
 * Write a span of PF_TRUEDITHER pixels to a pixmap (no alpha).
 
284
 */
 
285
static void write_span_rgb_TRUEDITHER_pixmap( RGB_SPAN_ARGS )
 
286
{
 
287
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
288
   XMesaDisplay *dpy = xmesa->xm_visual->display;
 
289
   XMesaDrawable buffer = xmesa->xm_buffer->buffer;
 
290
   XMesaGC gc = xmesa->xm_buffer->gc;
 
291
   register GLuint i;
 
292
   y = FLIP(xmesa->xm_buffer, y);
 
293
   if (mask) {
 
294
      for (i=0;i<n;i++,x++) {
 
295
         if (mask[i]) {
 
296
            unsigned long p;
 
297
            PACK_TRUEDITHER(p, x, y, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]);
 
298
            XMesaSetForeground( dpy, gc, p );
 
299
            XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
 
300
         }
 
301
      }
 
302
   }
 
303
   else {
 
304
      XMesaImage *rowimg = xmesa->xm_buffer->rowimage;
 
305
      for (i=0;i<n;i++) {
 
306
         unsigned long p;
 
307
         PACK_TRUEDITHER(p, x+i, y, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]);
 
308
         XMesaPutPixel( rowimg, i, 0, p );
 
309
      }
 
310
      XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
 
311
   }
 
312
}
 
313
 
 
314
 
 
315
 
 
316
/*
 
317
 * Write a span of PF_8A8B8G8R pixels to a pixmap.
 
318
 */
 
319
static void write_span_8A8B8G8R_pixmap( RGBA_SPAN_ARGS )
 
320
{
 
321
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
322
   XMesaDisplay *dpy = xmesa->xm_visual->display;
 
323
   XMesaDrawable buffer = xmesa->xm_buffer->buffer;
 
324
   XMesaGC gc = xmesa->xm_buffer->gc;
 
325
   register GLuint i;
 
326
   y = FLIP(xmesa->xm_buffer, y);
 
327
   if (mask) {
 
328
      for (i=0;i<n;i++,x++) {
 
329
         if (mask[i]) {
 
330
            XMesaSetForeground( dpy, gc,
 
331
                         PACK_8A8B8G8R(rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP], rgba[i][ACOMP]) );
 
332
            XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
 
333
         }
 
334
      }
 
335
   }
 
336
   else {
 
337
      /* draw all pixels */
 
338
      XMesaImage *rowimg = xmesa->xm_buffer->rowimage;
 
339
      register GLuint *ptr4 = (GLuint *) rowimg->data;
 
340
      for (i=0;i<n;i++) {
 
341
         *ptr4++ = PACK_8A8B8G8R( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP], rgba[i][ACOMP] );
 
342
      }
 
343
      XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
 
344
   }
 
345
}
 
346
 
 
347
 
 
348
/*
 
349
 * Write a span of PF_8A8B8G8R pixels to a pixmap (no alpha).
 
350
 */
 
351
static void write_span_rgb_8A8B8G8R_pixmap( RGB_SPAN_ARGS )
 
352
{
 
353
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
354
   XMesaDisplay *dpy = xmesa->xm_visual->display;
 
355
   XMesaDrawable buffer = xmesa->xm_buffer->buffer;
 
356
   XMesaGC gc = xmesa->xm_buffer->gc;
 
357
   register GLuint i;
 
358
   y = FLIP(xmesa->xm_buffer, y);
 
359
   if (mask) {
 
360
      for (i=0;i<n;i++,x++) {
 
361
         if (mask[i]) {
 
362
            XMesaSetForeground( dpy, gc,
 
363
                   PACK_8B8G8R(rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]) );
 
364
            XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
 
365
         }
 
366
      }
 
367
   }
 
368
   else {
 
369
      /* draw all pixels */
 
370
      XMesaImage *rowimg = xmesa->xm_buffer->rowimage;
 
371
      register GLuint *ptr4 = (GLuint *) rowimg->data;
 
372
      for (i=0;i<n;i++) {
 
373
         *ptr4++ = PACK_8B8G8R(rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]);
 
374
      }
 
375
      XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
 
376
   }
 
377
}
 
378
 
 
379
 
 
380
/*
 
381
 * Write a span of PF_8R8G8B pixels to a pixmap.
 
382
 */
 
383
static void write_span_8R8G8B_pixmap( RGBA_SPAN_ARGS )
 
384
{
 
385
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
386
   XMesaDisplay *dpy = xmesa->xm_visual->display;
 
387
   XMesaDrawable buffer = xmesa->xm_buffer->buffer;
 
388
   XMesaGC gc = xmesa->xm_buffer->gc;
 
389
   register GLuint i;
 
390
   y = FLIP(xmesa->xm_buffer, y);
 
391
   if (mask) {
 
392
      for (i=0;i<n;i++,x++) {
 
393
         if (mask[i]) {
 
394
            XMesaSetForeground( dpy, gc, PACK_8R8G8B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ));
 
395
            XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
 
396
         }
 
397
      }
 
398
   }
 
399
   else {
 
400
      /* draw all pixels */
 
401
      XMesaImage *rowimg = xmesa->xm_buffer->rowimage;
 
402
      register GLuint *ptr4 = (GLuint *) rowimg->data;
 
403
      for (i=0;i<n;i++) {
 
404
         *ptr4++ = PACK_8R8G8B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
 
405
      }
 
406
      XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
 
407
   }
 
408
}
 
409
 
 
410
 
 
411
/*
 
412
 * Write a span of PF_8R8G8B24 pixels to a pixmap.
 
413
 */
 
414
static void write_span_8R8G8B24_pixmap( RGBA_SPAN_ARGS )
 
415
{
 
416
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
417
   XMesaDisplay *dpy = xmesa->xm_visual->display;
 
418
   XMesaDrawable buffer = xmesa->xm_buffer->buffer;
 
419
   XMesaGC gc = xmesa->xm_buffer->gc;
 
420
   y = FLIP(xmesa->xm_buffer, y);
 
421
   if (mask) {
 
422
      register GLuint i;
 
423
      for (i=0;i<n;i++,x++) {
 
424
         if (mask[i]) {
 
425
            XMesaSetForeground( dpy, gc,
 
426
               PACK_8R8G8B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ));
 
427
            XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
 
428
         }
 
429
      }
 
430
   }
 
431
   else {
 
432
      /* draw all pixels */
 
433
      XMesaImage *rowimg = xmesa->xm_buffer->rowimage;
 
434
      register GLuint *ptr4 = (GLuint *) rowimg->data;
 
435
      register GLuint pixel;
 
436
      static const GLuint shift[4] = {0, 8, 16, 24};
 
437
      register GLuint i = 0;
 
438
      int w = n;
 
439
      while (w > 3) {
 
440
         pixel  = rgba[i][BCOMP] /* << shift[0]*/;
 
441
         pixel |= rgba[i][GCOMP]    << shift[1];
 
442
         pixel |= rgba[i++][RCOMP]  << shift[2];
 
443
         pixel |= rgba[i][BCOMP]    << shift[3];
 
444
         *ptr4++ = pixel;
 
445
 
 
446
         pixel  = rgba[i][GCOMP] /* << shift[0]*/;
 
447
         pixel |= rgba[i++][RCOMP]  << shift[1];
 
448
         pixel |= rgba[i][BCOMP]    << shift[2];
 
449
         pixel |= rgba[i][GCOMP]    << shift[3];
 
450
         *ptr4++ = pixel;
 
451
 
 
452
         pixel  = rgba[i++][RCOMP]/* << shift[0]*/;
 
453
         pixel |= rgba[i][BCOMP]     << shift[1];
 
454
         pixel |= rgba[i][GCOMP]     << shift[2];
 
455
         pixel |= rgba[i++][RCOMP]   << shift[3];
 
456
         *ptr4++ = pixel;
 
457
 
 
458
         w -= 4;
 
459
      }
 
460
      switch (w) {
 
461
         case 3:
 
462
            pixel = 0;
 
463
            pixel |= rgba[i][BCOMP] /*<< shift[0]*/;
 
464
            pixel |= rgba[i][GCOMP]   << shift[1];
 
465
            pixel |= rgba[i++][RCOMP] << shift[2];
 
466
            pixel |= rgba[i][BCOMP]   << shift[3];
 
467
            *ptr4++ = pixel;
 
468
            pixel = 0;
 
469
            pixel |= rgba[i][GCOMP] /*<< shift[0]*/;
 
470
            pixel |= rgba[i++][RCOMP] << shift[1];
 
471
            pixel |= rgba[i][BCOMP]   << shift[2];
 
472
            pixel |= rgba[i][GCOMP]   << shift[3];
 
473
            *ptr4++ = pixel;
 
474
            pixel = 0xffffff00 & *ptr4;
 
475
            pixel |= rgba[i][RCOMP] /*<< shift[0]*/;
 
476
            *ptr4 = pixel;
 
477
            break;
 
478
         case 2:
 
479
            pixel = 0;
 
480
            pixel |= rgba[i][BCOMP] /*<< shift[0]*/;
 
481
            pixel |= rgba[i][GCOMP]   << shift[1];
 
482
            pixel |= rgba[i++][RCOMP] << shift[2];
 
483
            pixel |= rgba[i][BCOMP]   << shift[3];
 
484
            *ptr4++ = pixel;
 
485
            pixel = 0xffff0000 & *ptr4;
 
486
            pixel |= rgba[i][GCOMP] /*<< shift[0]*/;
 
487
            pixel |= rgba[i][RCOMP]   << shift[1];
 
488
            *ptr4 = pixel;
 
489
            break;
 
490
         case 1:
 
491
            pixel = 0xff000000 & *ptr4;
 
492
            pixel |= rgba[i][BCOMP] /*<< shift[0]*/;
 
493
            pixel |= rgba[i][GCOMP] << shift[1];
 
494
            pixel |= rgba[i][RCOMP] << shift[2];
 
495
            *ptr4 = pixel;
 
496
            break;
 
497
         case 0:
 
498
            break;
 
499
      }
 
500
      XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
 
501
   }
 
502
}
 
503
 
 
504
 
 
505
/*
 
506
 * Write a span of PF_8R8G8B pixels to a pixmap (no alpha).
 
507
 */
 
508
static void write_span_rgb_8R8G8B_pixmap( RGB_SPAN_ARGS )
 
509
{
 
510
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
511
   XMesaDisplay *dpy = xmesa->xm_visual->display;
 
512
   XMesaDrawable buffer = xmesa->xm_buffer->buffer;
 
513
   XMesaGC gc = xmesa->xm_buffer->gc;
 
514
   register GLuint i;
 
515
   y = FLIP(xmesa->xm_buffer, y);
 
516
   if (mask) {
 
517
      for (i=0;i<n;i++,x++) {
 
518
         if (mask[i]) {
 
519
            XMesaSetForeground( dpy, gc, PACK_8R8G8B( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] ));
 
520
            XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
 
521
         }
 
522
      }
 
523
   }
 
524
   else {
 
525
      /* draw all pixels */
 
526
      XMesaImage *rowimg = xmesa->xm_buffer->rowimage;
 
527
      register GLuint *ptr4 = (GLuint *) rowimg->data;
 
528
      for (i=0;i<n;i++) {
 
529
         *ptr4++ = PACK_8R8G8B( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
 
530
      }
 
531
      XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
 
532
   }
 
533
}
 
534
 
 
535
 
 
536
/*
 
537
 * Write a span of PF_8R8G8B24 pixels to a pixmap (no alpha).
 
538
 */
 
539
static void write_span_rgb_8R8G8B24_pixmap( RGB_SPAN_ARGS )
 
540
{
 
541
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
542
   XMesaDisplay *dpy = xmesa->xm_visual->display;
 
543
   XMesaDrawable buffer = xmesa->xm_buffer->buffer;
 
544
   XMesaGC gc = xmesa->xm_buffer->gc;
 
545
   y = FLIP(xmesa->xm_buffer, y);
 
546
   if (mask) {
 
547
      register GLuint i;
 
548
      for (i=0;i<n;i++,x++) {
 
549
         if (mask[i]) {
 
550
            XMesaSetForeground( dpy, gc,
 
551
                  PACK_8R8G8B( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] ));
 
552
            XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
 
553
         }
 
554
      }
 
555
   }
 
556
   else {
 
557
      /* draw all pixels */
 
558
      XMesaImage *rowimg = xmesa->xm_buffer->rowimage;
 
559
      register GLuint *ptr4 = (GLuint *) rowimg->data;
 
560
      register GLuint pixel;
 
561
      static const GLuint shift[4] = {0, 8, 16, 24};
 
562
      unsigned w = n;
 
563
      register GLuint i = 0;
 
564
      while (w > 3) {
 
565
         pixel = 0;
 
566
         pixel |= rgb[i][BCOMP]/* << shift[0]*/;
 
567
         pixel |= rgb[i][GCOMP] << shift[1];
 
568
         pixel |= rgb[i++][RCOMP] << shift[2];
 
569
         pixel |= rgb[i][BCOMP] <<shift[3];
 
570
         *ptr4++ = pixel;
 
571
 
 
572
         pixel = 0;
 
573
         pixel |= rgb[i][GCOMP]/* << shift[0]*/;
 
574
         pixel |= rgb[i++][RCOMP] << shift[1];
 
575
         pixel |= rgb[i][BCOMP] << shift[2];
 
576
         pixel |= rgb[i][GCOMP] << shift[3];
 
577
         *ptr4++ = pixel;
 
578
 
 
579
         pixel = 0;
 
580
         pixel |= rgb[i++][RCOMP]/* << shift[0]*/;
 
581
         pixel |= rgb[i][BCOMP] << shift[1];
 
582
         pixel |= rgb[i][GCOMP] << shift[2];
 
583
         pixel |= rgb[i++][RCOMP] << shift[3];
 
584
         *ptr4++ = pixel;
 
585
         w -= 4;
 
586
      }
 
587
      switch (w) {
 
588
         case 3:
 
589
            pixel = 0;
 
590
            pixel |= rgb[i][BCOMP]/* << shift[0]*/;
 
591
            pixel |= rgb[i][GCOMP] << shift[1];
 
592
            pixel |= rgb[i++][RCOMP] << shift[2];
 
593
            pixel |= rgb[i][BCOMP] << shift[3];
 
594
            *ptr4++ = pixel;
 
595
            pixel = 0;
 
596
            pixel |= rgb[i][GCOMP]/* << shift[0]*/;
 
597
            pixel |= rgb[i++][RCOMP] << shift[1];
 
598
            pixel |= rgb[i][BCOMP] << shift[2];
 
599
            pixel |= rgb[i][GCOMP] << shift[3];
 
600
            *ptr4++ = pixel;
 
601
            pixel = *ptr4;
 
602
            pixel &= 0xffffff00;
 
603
            pixel |= rgb[i++][RCOMP]/* << shift[0]*/;
 
604
            *ptr4++ = pixel;
 
605
            break;
 
606
         case 2:
 
607
            pixel = 0;
 
608
            pixel |= rgb[i][BCOMP]/* << shift[0]*/;
 
609
            pixel |= rgb[i][GCOMP] << shift[1];
 
610
            pixel |= rgb[i++][RCOMP] << shift[2];
 
611
            pixel |= rgb[i][BCOMP]  << shift[3];
 
612
            *ptr4++ = pixel;
 
613
            pixel = *ptr4;
 
614
            pixel &= 0xffff0000;
 
615
            pixel |= rgb[i][GCOMP]/* << shift[0]*/;
 
616
            pixel |= rgb[i++][RCOMP] << shift[1];
 
617
            *ptr4++ = pixel;
 
618
            break;
 
619
         case 1:
 
620
            pixel = *ptr4;
 
621
            pixel &= 0xff000000;
 
622
            pixel |= rgb[i][BCOMP]/* << shift[0]*/;
 
623
            pixel |= rgb[i][GCOMP] << shift[1];
 
624
            pixel |= rgb[i++][RCOMP] << shift[2];
 
625
            *ptr4++ = pixel;
 
626
            break;
 
627
         case 0:
 
628
            break;
 
629
      }
 
630
      XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
 
631
   }
 
632
}
 
633
 
 
634
 
 
635
/*
 
636
 * Write a span of PF_5R6G5B pixels to a pixmap.
 
637
 */
 
638
static void write_span_5R6G5B_pixmap( RGBA_SPAN_ARGS )
 
639
{
 
640
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
641
   XMesaDisplay *dpy = xmesa->xm_visual->display;
 
642
   XMesaDrawable buffer = xmesa->xm_buffer->buffer;
 
643
   XMesaGC gc = xmesa->xm_buffer->gc;
 
644
   register GLuint i;
 
645
   y = FLIP(xmesa->xm_buffer, y);
 
646
   if (mask) {
 
647
      for (i=0;i<n;i++,x++) {
 
648
         if (mask[i]) {
 
649
            XMesaSetForeground( dpy, gc, PACK_5R6G5B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ));
 
650
            XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
 
651
         }
 
652
      }
 
653
   }
 
654
   else {
 
655
      /* draw all pixels */
 
656
      XMesaImage *rowimg = xmesa->xm_buffer->rowimage;
 
657
      register GLushort *ptr2 = (GLushort *) rowimg->data;
 
658
      for (i=0;i<n;i++) {
 
659
         ptr2[i] = PACK_5R6G5B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
 
660
      }
 
661
      XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
 
662
   }
 
663
}
 
664
 
 
665
 
 
666
/*
 
667
 * Write a span of PF_DITHER_5R6G5B pixels to a pixmap.
 
668
 */
 
669
static void write_span_DITHER_5R6G5B_pixmap( RGBA_SPAN_ARGS )
 
670
{
 
671
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
672
   XMesaDisplay *dpy = xmesa->xm_visual->display;
 
673
   XMesaDrawable buffer = xmesa->xm_buffer->buffer;
 
674
   XMesaGC gc = xmesa->xm_buffer->gc;
 
675
   register GLuint i;
 
676
   y = FLIP(xmesa->xm_buffer, y);
 
677
   if (mask) {
 
678
      for (i=0;i<n;i++,x++) {
 
679
         if (mask[i]) {
 
680
            unsigned long p;
 
681
            PACK_TRUEDITHER(p, x, y, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
 
682
            XMesaSetForeground( dpy, gc, p );
 
683
            XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
 
684
         }
 
685
      }
 
686
   }
 
687
   else {
 
688
      /* draw all pixels */
 
689
      XMesaImage *rowimg = xmesa->xm_buffer->rowimage;
 
690
      register GLushort *ptr2 = (GLushort *) rowimg->data;
 
691
      for (i=0;i<n;i++) {
 
692
         PACK_TRUEDITHER( ptr2[i], x+i, y, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
 
693
      }
 
694
      XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
 
695
   }
 
696
}
 
697
 
 
698
 
 
699
/*
 
700
 * Write a span of PF_5R6G5B pixels to a pixmap (no alpha).
 
701
 */
 
702
static void write_span_rgb_5R6G5B_pixmap( RGB_SPAN_ARGS )
 
703
{
 
704
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
705
   XMesaDisplay *dpy = xmesa->xm_visual->display;
 
706
   XMesaDrawable buffer = xmesa->xm_buffer->buffer;
 
707
   XMesaGC gc = xmesa->xm_buffer->gc;
 
708
   register GLuint i;
 
709
   y = FLIP(xmesa->xm_buffer, y);
 
710
   if (mask) {
 
711
      for (i=0;i<n;i++,x++) {
 
712
         if (mask[i]) {
 
713
            XMesaSetForeground( dpy, gc, PACK_5R6G5B( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] ));
 
714
            XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
 
715
         }
 
716
      }
 
717
   }
 
718
   else {
 
719
      /* draw all pixels */
 
720
      XMesaImage *rowimg = xmesa->xm_buffer->rowimage;
 
721
      register GLushort *ptr2 = (GLushort *) rowimg->data;
 
722
      for (i=0;i<n;i++) {
 
723
         ptr2[i] = PACK_5R6G5B( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
 
724
      }
 
725
      XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
 
726
   }
 
727
}
 
728
 
 
729
 
 
730
/*
 
731
 * Write a span of PF_DITHER_5R6G5B pixels to a pixmap (no alpha).
 
732
 */
 
733
static void write_span_rgb_DITHER_5R6G5B_pixmap( RGB_SPAN_ARGS )
 
734
{
 
735
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
736
   XMesaDisplay *dpy = xmesa->xm_visual->display;
 
737
   XMesaDrawable buffer = xmesa->xm_buffer->buffer;
 
738
   XMesaGC gc = xmesa->xm_buffer->gc;
 
739
   register GLuint i;
 
740
   y = FLIP(xmesa->xm_buffer, y);
 
741
   if (mask) {
 
742
      for (i=0;i<n;i++,x++) {
 
743
         if (mask[i]) {
 
744
            unsigned long p;
 
745
            PACK_TRUEDITHER(p, x, y, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]);
 
746
            XMesaSetForeground( dpy, gc, p );
 
747
            XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
 
748
         }
 
749
      }
 
750
   }
 
751
   else {
 
752
      /* draw all pixels */
 
753
      XMesaImage *rowimg = xmesa->xm_buffer->rowimage;
 
754
      register GLushort *ptr2 = (GLushort *) rowimg->data;
 
755
      for (i=0;i<n;i++) {
 
756
         PACK_TRUEDITHER( ptr2[i], x+i, y, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
 
757
      }
 
758
      XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
 
759
   }
 
760
}
 
761
 
 
762
 
 
763
 
 
764
/*
 
765
 * Write a span of PF_DITHER pixels to a pixmap.
 
766
 */
 
767
static void write_span_DITHER_pixmap( RGBA_SPAN_ARGS )
 
768
{
 
769
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
770
   XMesaDisplay *dpy = xmesa->xm_visual->display;
 
771
   XMesaDrawable buffer = xmesa->xm_buffer->buffer;
 
772
   XMesaGC gc = xmesa->xm_buffer->gc;
 
773
   register GLuint i;
 
774
   XDITHER_SETUP(y);
 
775
   y = FLIP(xmesa->xm_buffer, y);
 
776
   if (mask) {
 
777
      for (i=0;i<n;i++,x++) {
 
778
         if (mask[i]) {
 
779
            XMesaSetForeground( dpy, gc, XDITHER(x, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]) );
 
780
            XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
 
781
         }
 
782
      }
 
783
   }
 
784
   else {
 
785
      /* draw all pixels */
 
786
      XMesaImage *rowimg = xmesa->xm_buffer->rowimage;
 
787
      for (i=0;i<n;i++) {
 
788
         XMesaPutPixel( rowimg, i, 0, XDITHER(x+i, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]) );
 
789
      }
 
790
      XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
 
791
   }
 
792
}
 
793
 
 
794
 
 
795
/*
 
796
 * Write a span of PF_DITHER pixels to a pixmap (no alpha).
 
797
 */
 
798
static void write_span_rgb_DITHER_pixmap( RGB_SPAN_ARGS )
 
799
{
 
800
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
801
   XMesaDisplay *dpy = xmesa->xm_visual->display;
 
802
   XMesaDrawable buffer = xmesa->xm_buffer->buffer;
 
803
   XMesaGC gc = xmesa->xm_buffer->gc;
 
804
   register GLuint i;
 
805
   XDITHER_SETUP(y);
 
806
   y = FLIP(xmesa->xm_buffer, y);
 
807
   if (mask) {
 
808
      for (i=0;i<n;i++,x++) {
 
809
         if (mask[i]) {
 
810
            XMesaSetForeground( dpy, gc, XDITHER(x, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]) );
 
811
            XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
 
812
         }
 
813
      }
 
814
   }
 
815
   else {
 
816
      /* draw all pixels */
 
817
      XMesaImage *rowimg = xmesa->xm_buffer->rowimage;
 
818
      for (i=0;i<n;i++) {
 
819
         XMesaPutPixel( rowimg, i, 0, XDITHER(x+i, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]) );
 
820
      }
 
821
      XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
 
822
   }
 
823
}
 
824
 
 
825
 
 
826
/*
 
827
 * Write a span of PF_1BIT pixels to a pixmap.
 
828
 */
 
829
static void write_span_1BIT_pixmap( RGBA_SPAN_ARGS )
 
830
{
 
831
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
832
   XMesaDisplay *dpy = xmesa->xm_visual->display;
 
833
   XMesaDrawable buffer = xmesa->xm_buffer->buffer;
 
834
   XMesaGC gc = xmesa->xm_buffer->gc;
 
835
   register GLuint i;
 
836
   SETUP_1BIT;
 
837
   y = FLIP(xmesa->xm_buffer, y);
 
838
   if (mask) {
 
839
      for (i=0;i<n;i++,x++) {
 
840
         if (mask[i]) {
 
841
            XMesaSetForeground( dpy, gc,
 
842
                            DITHER_1BIT( x, y, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
 
843
            XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
 
844
         }
 
845
      }
 
846
   }
 
847
   else {
 
848
      /* draw all pixels */
 
849
      XMesaImage *rowimg = xmesa->xm_buffer->rowimage;
 
850
      for (i=0;i<n;i++) {
 
851
         XMesaPutPixel( rowimg, i, 0,
 
852
                    DITHER_1BIT( x+i, y, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
 
853
      }
 
854
      XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
 
855
   }
 
856
}
 
857
 
 
858
 
 
859
/*
 
860
 * Write a span of PF_1BIT pixels to a pixmap (no alpha).
 
861
 */
 
862
static void write_span_rgb_1BIT_pixmap( RGB_SPAN_ARGS )
 
863
{
 
864
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
865
   XMesaDisplay *dpy = xmesa->xm_visual->display;
 
866
   XMesaDrawable buffer = xmesa->xm_buffer->buffer;
 
867
   XMesaGC gc = xmesa->xm_buffer->gc;
 
868
   register GLuint i;
 
869
   SETUP_1BIT;
 
870
   y = FLIP(xmesa->xm_buffer, y);
 
871
   if (mask) {
 
872
      for (i=0;i<n;i++,x++) {
 
873
         if (mask[i]) {
 
874
            XMesaSetForeground( dpy, gc,
 
875
              DITHER_1BIT(x, y, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]) );
 
876
            XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
 
877
         }
 
878
      }
 
879
   }
 
880
   else {
 
881
      /* draw all pixels */
 
882
      XMesaImage *rowimg = xmesa->xm_buffer->rowimage;
 
883
      for (i=0;i<n;i++) {
 
884
         XMesaPutPixel( rowimg, i, 0,
 
885
          DITHER_1BIT(x+i, y, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]) );
 
886
      }
 
887
      XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
 
888
   }
 
889
}
 
890
 
 
891
 
 
892
/*
 
893
 * Write a span of PF_HPCR pixels to a pixmap.
 
894
 */
 
895
static void write_span_HPCR_pixmap( RGBA_SPAN_ARGS )
 
896
{
 
897
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
898
   XMesaDisplay *dpy = xmesa->xm_visual->display;
 
899
   XMesaDrawable buffer = xmesa->xm_buffer->buffer;
 
900
   XMesaGC gc = xmesa->xm_buffer->gc;
 
901
   register GLuint i;
 
902
   y = FLIP(xmesa->xm_buffer, y);
 
903
   if (mask) {
 
904
      for (i=0;i<n;i++,x++) {
 
905
         if (mask[i]) {
 
906
            XMesaSetForeground( dpy, gc,
 
907
                            DITHER_HPCR( x, y, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
 
908
            XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
 
909
         }
 
910
      }
 
911
   }
 
912
   else {
 
913
      XMesaImage *rowimg = xmesa->xm_buffer->rowimage;
 
914
      register GLubyte *ptr = (GLubyte *) xmesa->xm_buffer->rowimage->data;
 
915
      for (i=0;i<n;i++) {
 
916
         ptr[i] = DITHER_HPCR( (x+i), y, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
 
917
      }
 
918
      XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
 
919
   }
 
920
}
 
921
 
 
922
 
 
923
/*
 
924
 * Write a span of PF_HPCR pixels to a pixmap (no alpha).
 
925
 */
 
926
static void write_span_rgb_HPCR_pixmap( RGB_SPAN_ARGS )
 
927
{
 
928
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
929
   XMesaDisplay *dpy = xmesa->xm_visual->display;
 
930
   XMesaDrawable buffer = xmesa->xm_buffer->buffer;
 
931
   XMesaGC gc = xmesa->xm_buffer->gc;
 
932
   register GLuint i;
 
933
   y = FLIP(xmesa->xm_buffer, y);
 
934
   if (mask) {
 
935
      for (i=0;i<n;i++,x++) {
 
936
         if (mask[i]) {
 
937
            XMesaSetForeground( dpy, gc,
 
938
              DITHER_HPCR(x, y, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]) );
 
939
            XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
 
940
         }
 
941
      }
 
942
   }
 
943
   else {
 
944
      XMesaImage *rowimg = xmesa->xm_buffer->rowimage;
 
945
      register GLubyte *ptr = (GLubyte *) xmesa->xm_buffer->rowimage->data;
 
946
      for (i=0;i<n;i++) {
 
947
         ptr[i] = DITHER_HPCR( (x+i), y, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
 
948
      }
 
949
      XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
 
950
   }
 
951
}
 
952
 
 
953
 
 
954
/*
 
955
 * Write a span of PF_LOOKUP pixels to a pixmap.
 
956
 */
 
957
static void write_span_LOOKUP_pixmap( RGBA_SPAN_ARGS )
 
958
{
 
959
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
960
   XMesaDisplay *dpy = xmesa->xm_visual->display;
 
961
   XMesaDrawable buffer = xmesa->xm_buffer->buffer;
 
962
   XMesaGC gc = xmesa->xm_buffer->gc;
 
963
   register GLuint i;
 
964
   LOOKUP_SETUP;
 
965
   y = FLIP(xmesa->xm_buffer, y);
 
966
   if (mask) {
 
967
      for (i=0;i<n;i++,x++) {
 
968
         if (mask[i]) {
 
969
            XMesaSetForeground( dpy, gc, LOOKUP( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
 
970
            XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
 
971
         }
 
972
      }
 
973
   }
 
974
   else {
 
975
      XMesaImage *rowimg = xmesa->xm_buffer->rowimage;
 
976
      for (i=0;i<n;i++) {
 
977
         XMesaPutPixel( rowimg, i, 0, LOOKUP(rgba[i][RCOMP],rgba[i][GCOMP],rgba[i][BCOMP]) );
 
978
      }
 
979
      XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
 
980
   }
 
981
}
 
982
 
 
983
 
 
984
/*
 
985
 * Write a span of PF_LOOKUP pixels to a pixmap (no alpha).
 
986
 */
 
987
static void write_span_rgb_LOOKUP_pixmap( RGB_SPAN_ARGS )
 
988
{
 
989
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
990
   XMesaDisplay *dpy = xmesa->xm_visual->display;
 
991
   XMesaDrawable buffer = xmesa->xm_buffer->buffer;
 
992
   XMesaGC gc = xmesa->xm_buffer->gc;
 
993
   register GLuint i;
 
994
   LOOKUP_SETUP;
 
995
   y = FLIP(xmesa->xm_buffer, y);
 
996
   if (mask) {
 
997
      for (i=0;i<n;i++,x++) {
 
998
         if (mask[i]) {
 
999
            XMesaSetForeground( dpy, gc, LOOKUP( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] ) );
 
1000
            XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
 
1001
         }
 
1002
      }
 
1003
   }
 
1004
   else {
 
1005
      XMesaImage *rowimg = xmesa->xm_buffer->rowimage;
 
1006
      for (i=0;i<n;i++) {
 
1007
         XMesaPutPixel( rowimg, i, 0, LOOKUP(rgb[i][RCOMP],rgb[i][GCOMP],rgb[i][BCOMP]) );
 
1008
      }
 
1009
      XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
 
1010
   }
 
1011
}
 
1012
 
 
1013
 
 
1014
 
 
1015
/*
 
1016
 * Write a span of PF_GRAYSCALE pixels to a pixmap.
 
1017
 */
 
1018
static void write_span_GRAYSCALE_pixmap( RGBA_SPAN_ARGS )
 
1019
{
 
1020
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
1021
   XMesaDisplay *dpy = xmesa->xm_visual->display;
 
1022
   XMesaDrawable buffer = xmesa->xm_buffer->buffer;
 
1023
   XMesaGC gc = xmesa->xm_buffer->gc;
 
1024
   register GLuint i;
 
1025
   y = FLIP(xmesa->xm_buffer, y);
 
1026
   if (mask) {
 
1027
      for (i=0;i<n;i++,x++) {
 
1028
         if (mask[i]) {
 
1029
            XMesaSetForeground( dpy, gc, GRAY_RGB( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
 
1030
            XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
 
1031
         }
 
1032
      }
 
1033
   }
 
1034
   else {
 
1035
      XMesaImage *rowimg = xmesa->xm_buffer->rowimage;
 
1036
      for (i=0;i<n;i++) {
 
1037
         XMesaPutPixel( rowimg, i, 0, GRAY_RGB(rgba[i][RCOMP],rgba[i][GCOMP],rgba[i][BCOMP]) );
 
1038
      }
 
1039
      XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
 
1040
   }
 
1041
}
 
1042
 
 
1043
 
 
1044
/*
 
1045
 * Write a span of PF_GRAYSCALE pixels to a pixmap (no alpha).
 
1046
 */
 
1047
static void write_span_rgb_GRAYSCALE_pixmap( RGB_SPAN_ARGS )
 
1048
{
 
1049
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
1050
   XMesaDisplay *dpy = xmesa->xm_visual->display;
 
1051
   XMesaDrawable buffer = xmesa->xm_buffer->buffer;
 
1052
   XMesaGC gc = xmesa->xm_buffer->gc;
 
1053
   register GLuint i;
 
1054
   y = FLIP(xmesa->xm_buffer, y);
 
1055
   if (mask) {
 
1056
      for (i=0;i<n;i++,x++) {
 
1057
         if (mask[i]) {
 
1058
            XMesaSetForeground( dpy, gc, GRAY_RGB( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] ) );
 
1059
            XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
 
1060
         }
 
1061
      }
 
1062
   }
 
1063
   else {
 
1064
      XMesaImage *rowimg = xmesa->xm_buffer->rowimage;
 
1065
      for (i=0;i<n;i++) {
 
1066
         XMesaPutPixel( rowimg, i, 0, GRAY_RGB(rgb[i][RCOMP],rgb[i][GCOMP],rgb[i][BCOMP]) );
 
1067
      }
 
1068
      XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
 
1069
   }
 
1070
}
 
1071
 
 
1072
 
 
1073
/*
 
1074
 * Write a span of PF_TRUECOLOR pixels to an XImage.
 
1075
 */
 
1076
static void write_span_TRUECOLOR_ximage( RGBA_SPAN_ARGS )
 
1077
{
 
1078
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
1079
   XMesaImage *img = xmesa->xm_buffer->backimage;
 
1080
   register GLuint i;
 
1081
   y = FLIP(xmesa->xm_buffer, y);
 
1082
   if (mask) {
 
1083
      for (i=0;i<n;i++,x++) {
 
1084
         if (mask[i]) {
 
1085
            unsigned long p;
 
1086
            PACK_TRUECOLOR( p, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
 
1087
            XMesaPutPixel( img, x, y, p );
 
1088
         }
 
1089
      }
 
1090
   }
 
1091
   else {
 
1092
      /* draw all pixels */
 
1093
      for (i=0;i<n;i++,x++) {
 
1094
         unsigned long p;
 
1095
         PACK_TRUECOLOR( p, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
 
1096
         XMesaPutPixel( img, x, y, p );
 
1097
      }
 
1098
   }
 
1099
}
 
1100
 
 
1101
 
 
1102
/*
 
1103
 * Write a span of PF_TRUECOLOR pixels to an XImage (no alpha).
 
1104
 */
 
1105
static void write_span_rgb_TRUECOLOR_ximage( RGB_SPAN_ARGS )
 
1106
{
 
1107
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
1108
   XMesaImage *img = xmesa->xm_buffer->backimage;
 
1109
   register GLuint i;
 
1110
   y = FLIP(xmesa->xm_buffer, y);
 
1111
   if (mask) {
 
1112
      for (i=0;i<n;i++,x++) {
 
1113
         if (mask[i]) {
 
1114
            unsigned long p;
 
1115
            PACK_TRUECOLOR( p, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
 
1116
            XMesaPutPixel( img, x, y, p );
 
1117
         }
 
1118
      }
 
1119
   }
 
1120
   else {
 
1121
      /* draw all pixels */
 
1122
      for (i=0;i<n;i++,x++) {
 
1123
         unsigned long p;
 
1124
         PACK_TRUECOLOR( p, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
 
1125
         XMesaPutPixel( img, x, y, p );
 
1126
      }
 
1127
   }
 
1128
}
 
1129
 
 
1130
 
 
1131
/*
 
1132
 * Write a span of PF_TRUEDITHER pixels to an XImage.
 
1133
 */
 
1134
static void write_span_TRUEDITHER_ximage( RGBA_SPAN_ARGS )
 
1135
{
 
1136
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
1137
   XMesaImage *img = xmesa->xm_buffer->backimage;
 
1138
   register GLuint i;
 
1139
   y = FLIP(xmesa->xm_buffer, y);
 
1140
   if (mask) {
 
1141
      for (i=0;i<n;i++,x++) {
 
1142
         if (mask[i]) {
 
1143
            unsigned long p;
 
1144
            PACK_TRUEDITHER(p, x, y, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
 
1145
            XMesaPutPixel( img, x, y, p );
 
1146
         }
 
1147
      }
 
1148
   }
 
1149
   else {
 
1150
      /* draw all pixels */
 
1151
      for (i=0;i<n;i++,x++) {
 
1152
         unsigned long p;
 
1153
         PACK_TRUEDITHER(p, x, y, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
 
1154
         XMesaPutPixel( img, x, y, p );
 
1155
      }
 
1156
   }
 
1157
}
 
1158
 
 
1159
 
 
1160
/*
 
1161
 * Write a span of PF_TRUEDITHER pixels to an XImage (no alpha).
 
1162
 */
 
1163
static void write_span_rgb_TRUEDITHER_ximage( RGB_SPAN_ARGS )
 
1164
{
 
1165
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
1166
   XMesaImage *img = xmesa->xm_buffer->backimage;
 
1167
   register GLuint i;
 
1168
   y = FLIP(xmesa->xm_buffer, y);
 
1169
   if (mask) {
 
1170
      for (i=0;i<n;i++,x++) {
 
1171
         if (mask[i]) {
 
1172
            unsigned long p;
 
1173
            PACK_TRUEDITHER(p, x, y, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]);
 
1174
            XMesaPutPixel( img, x, y, p );
 
1175
         }
 
1176
      }
 
1177
   }
 
1178
   else {
 
1179
      /* draw all pixels */
 
1180
      for (i=0;i<n;i++,x++) {
 
1181
         unsigned long p;
 
1182
         PACK_TRUEDITHER(p, x, y, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]);
 
1183
         XMesaPutPixel( img, x, y, p );
 
1184
      }
 
1185
   }
 
1186
}
 
1187
 
 
1188
 
 
1189
/*
 
1190
 * Write a span of PF_8A8B8G8R-format pixels to an ximage.
 
1191
 */
 
1192
static void write_span_8A8B8G8R_ximage( RGBA_SPAN_ARGS )
 
1193
{
 
1194
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
1195
   register GLuint i;
 
1196
   register GLuint *ptr = PIXELADDR4( xmesa->xm_buffer, x, y );
 
1197
   if (mask) {
 
1198
      for (i=0;i<n;i++) {
 
1199
         if (mask[i]) {
 
1200
            ptr[i] = PACK_8A8B8G8R( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP], rgba[i][ACOMP] );
 
1201
         }
 
1202
      }
 
1203
   }
 
1204
   else {
 
1205
      /* draw all pixels */
 
1206
      for (i=0;i<n;i++) {
 
1207
         ptr[i] = PACK_8A8B8G8R( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP], rgba[i][ACOMP] );
 
1208
      }
 
1209
   }
 
1210
}
 
1211
 
 
1212
 
 
1213
/*
 
1214
 * Write a span of PF_8A8B8G8R-format pixels to an ximage (no alpha).
 
1215
 */
 
1216
static void write_span_rgb_8A8B8G8R_ximage( RGB_SPAN_ARGS )
 
1217
{
 
1218
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
1219
   register GLuint i;
 
1220
   register GLuint *ptr = PIXELADDR4( xmesa->xm_buffer, x, y );
 
1221
   if (mask) {
 
1222
      for (i=0;i<n;i++) {
 
1223
         if (mask[i]) {
 
1224
            ptr[i] = PACK_8A8B8G8R( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP], 255 );
 
1225
         }
 
1226
      }
 
1227
   }
 
1228
   else {
 
1229
      /* draw all pixels */
 
1230
      for (i=0;i<n;i++) {
 
1231
         ptr[i] = PACK_8A8B8G8R( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP], 255 );
 
1232
      }
 
1233
   }
 
1234
}
 
1235
 
 
1236
 
 
1237
/*
 
1238
 * Write a span of PF_8R8G8B-format pixels to an ximage.
 
1239
 */
 
1240
static void write_span_8R8G8B_ximage( RGBA_SPAN_ARGS )
 
1241
{
 
1242
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
1243
   register GLuint i;
 
1244
   register GLuint *ptr = PIXELADDR4( xmesa->xm_buffer, x, y );
 
1245
   if (mask) {
 
1246
      for (i=0;i<n;i++) {
 
1247
         if (mask[i]) {
 
1248
            ptr[i] = PACK_8R8G8B(rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
 
1249
         }
 
1250
      }
 
1251
   }
 
1252
   else {
 
1253
      for (i=0;i<n;i++) {
 
1254
         ptr[i] = PACK_8R8G8B(rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
 
1255
      }
 
1256
   }
 
1257
}
 
1258
 
 
1259
 
 
1260
/*
 
1261
 * Write a span of PF_8R8G8B24-format pixels to an ximage.
 
1262
 */
 
1263
static void write_span_8R8G8B24_ximage( RGBA_SPAN_ARGS )
 
1264
{
 
1265
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
1266
   register GLuint i;
 
1267
   register GLubyte *ptr = (GLubyte *) PIXELADDR3( xmesa->xm_buffer, x, y );
 
1268
   if (mask) {
 
1269
      for (i=0;i<n;i++) {
 
1270
         if (mask[i]) {
 
1271
            GLuint *ptr4 = (GLuint *) ptr;
 
1272
            register GLuint pixel = *ptr4;
 
1273
            switch (3 & (int)(ptr - (GLubyte*)ptr4)) {
 
1274
               case 0:
 
1275
                  pixel &= 0xff000000;
 
1276
                  pixel |= rgba[i][BCOMP];
 
1277
                  pixel |= rgba[i][GCOMP] << 8;
 
1278
                  pixel |= rgba[i][RCOMP] << 16;
 
1279
                  *ptr4 = pixel;
 
1280
                  break;
 
1281
               case 3:
 
1282
                  pixel &= 0x00ffffff;
 
1283
                  pixel |= rgba[i][BCOMP] << 24;
 
1284
                  *ptr4++ = pixel;
 
1285
                  pixel = *ptr4 && 0xffff0000;
 
1286
                  pixel |= rgba[i][GCOMP];
 
1287
                  pixel |= rgba[i][RCOMP] << 8;
 
1288
                  *ptr4 = pixel;
 
1289
                  break;
 
1290
               case 2:
 
1291
                  pixel &= 0x0000ffff;
 
1292
                  pixel |= rgba[i][BCOMP] << 16;
 
1293
                  pixel |= rgba[i][GCOMP] << 24;
 
1294
                  *ptr4++ = pixel;
 
1295
                  pixel = *ptr4 && 0xffffff00;
 
1296
                  pixel |= rgba[i][RCOMP];
 
1297
                  *ptr4 = pixel;
 
1298
                  break;
 
1299
               case 1:
 
1300
                  pixel &= 0x000000ff;
 
1301
                  pixel |= rgba[i][BCOMP] << 8;
 
1302
                  pixel |= rgba[i][GCOMP] << 16;
 
1303
                  pixel |= rgba[i][RCOMP] << 24;
 
1304
                  *ptr4 = pixel;
 
1305
                  break;
 
1306
            }
 
1307
         }
 
1308
         ptr += 3;
 
1309
      }
 
1310
   }
 
1311
   else {
 
1312
      /* write all pixels */
 
1313
      int w = n;
 
1314
      GLuint *ptr4 = (GLuint *) ptr;
 
1315
      register GLuint pixel = *ptr4;
 
1316
      int index = (int)(ptr - (GLubyte *)ptr4);
 
1317
      register GLuint i = 0;
 
1318
      switch (index) {
 
1319
         case 0:
 
1320
            break;
 
1321
         case 1:
 
1322
            pixel &= 0x00ffffff;
 
1323
            pixel |= rgba[i][BCOMP] << 24;
 
1324
            *ptr4++ = pixel;
 
1325
            pixel = *ptr4 && 0xffff0000;
 
1326
            pixel |= rgba[i][GCOMP];
 
1327
            pixel |= rgba[i++][RCOMP] << 8;
 
1328
            *ptr4 = pixel;
 
1329
            if (0 == --w)
 
1330
               break;
 
1331
         case 2:
 
1332
            pixel &= 0x0000ffff;
 
1333
            pixel |= rgba[i][BCOMP] << 16;
 
1334
            pixel |= rgba[i][GCOMP] << 24;
 
1335
            *ptr4++ = pixel;
 
1336
            pixel = *ptr4 && 0xffffff00;
 
1337
            pixel |= rgba[i++][RCOMP];
 
1338
            *ptr4 = pixel;
 
1339
            if (0 == --w)
 
1340
               break;
 
1341
         case 3:
 
1342
            pixel &= 0x000000ff;
 
1343
            pixel |= rgba[i][BCOMP] << 8;
 
1344
            pixel |= rgba[i][GCOMP] << 16;
 
1345
            pixel |= rgba[i++][RCOMP] << 24;
 
1346
            *ptr4++ = pixel;
 
1347
            if (0 == --w)
 
1348
               break;
 
1349
            break;
 
1350
      }
 
1351
      while (w > 3) {
 
1352
         pixel = rgba[i][BCOMP];
 
1353
         pixel |= rgba[i][GCOMP] << 8;
 
1354
         pixel |= rgba[i++][RCOMP] << 16;
 
1355
         pixel |= rgba[i][BCOMP] << 24;
 
1356
         *ptr4++ = pixel;
 
1357
         pixel = rgba[i][GCOMP];
 
1358
         pixel |= rgba[i++][RCOMP] << 8;
 
1359
         pixel |= rgba[i][BCOMP] << 16;
 
1360
         pixel |= rgba[i][GCOMP] << 24;
 
1361
         *ptr4++ = pixel;
 
1362
         pixel = rgba[i++][RCOMP];
 
1363
         pixel |= rgba[i][BCOMP] << 8;
 
1364
         pixel |= rgba[i][GCOMP] << 16;
 
1365
         pixel |= rgba[i++][RCOMP] << 24;
 
1366
         *ptr4++ = pixel;
 
1367
         w -= 4;
 
1368
      }
 
1369
      switch (w) {
 
1370
         case 0:
 
1371
            break;
 
1372
         case 1:
 
1373
            pixel = *ptr4 & 0xff000000;
 
1374
            pixel |= rgba[i][BCOMP];
 
1375
            pixel |= rgba[i][GCOMP] << 8;
 
1376
            pixel |= rgba[i][RCOMP] << 16;
 
1377
            *ptr4 = pixel;
 
1378
            break;
 
1379
         case 2:
 
1380
            pixel = rgba[i][BCOMP];
 
1381
            pixel |= rgba[i][GCOMP] << 8;
 
1382
            pixel |= rgba[i++][RCOMP] << 16;
 
1383
            pixel |= rgba[i][BCOMP] << 24;
 
1384
            *ptr4++ = pixel;
 
1385
            pixel = *ptr4 & 0xffff0000;
 
1386
            pixel |= rgba[i][GCOMP];
 
1387
            pixel |= rgba[i][RCOMP] << 8;
 
1388
            *ptr4 = pixel;
 
1389
            break;
 
1390
         case 3:
 
1391
            pixel = rgba[i][BCOMP];
 
1392
            pixel |= rgba[i][GCOMP] << 8;
 
1393
            pixel |= rgba[i++][RCOMP] << 16;
 
1394
            pixel |= rgba[i][BCOMP] << 24;
 
1395
            *ptr4++ = pixel;
 
1396
            pixel = rgba[i][GCOMP];
 
1397
            pixel |= rgba[i++][RCOMP] << 8;
 
1398
            pixel |= rgba[i][BCOMP] << 16;
 
1399
            pixel |= rgba[i][GCOMP] << 24;
 
1400
            *ptr4++ = pixel;
 
1401
            pixel = *ptr4 & 0xffffff00;
 
1402
            pixel |= rgba[i][RCOMP];
 
1403
            *ptr4 = pixel;
 
1404
            break;
 
1405
      }
 
1406
   }
 
1407
}
 
1408
 
 
1409
 
 
1410
/*
 
1411
 * Write a span of PF_8R8G8B-format pixels to an ximage (no alpha).
 
1412
 */
 
1413
static void write_span_rgb_8R8G8B_ximage( RGB_SPAN_ARGS )
 
1414
{
 
1415
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
1416
   register GLuint i;
 
1417
   register GLuint *ptr = PIXELADDR4( xmesa->xm_buffer, x, y );
 
1418
   if (mask) {
 
1419
      for (i=0;i<n;i++) {
 
1420
         if (mask[i]) {
 
1421
            ptr[i] = PACK_8R8G8B(rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]);
 
1422
         }
 
1423
      }
 
1424
   }
 
1425
   else {
 
1426
      /* draw all pixels */
 
1427
      for (i=0;i<n;i++) {
 
1428
         ptr[i] = PACK_8R8G8B(rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]);
 
1429
      }
 
1430
   }
 
1431
}
 
1432
 
 
1433
 
 
1434
/*
 
1435
 * Write a span of PF_8R8G8B24-format pixels to an ximage (no alpha).
 
1436
 */
 
1437
static void write_span_rgb_8R8G8B24_ximage( RGB_SPAN_ARGS )
 
1438
{
 
1439
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
1440
   register GLuint i;
 
1441
   register GLubyte *ptr = (GLubyte *) PIXELADDR3( xmesa->xm_buffer, x, y );
 
1442
   if (mask) {
 
1443
      for (i=0;i<n;i++) {
 
1444
         if (mask[i]) {
 
1445
            *ptr++ = rgb[i][BCOMP];
 
1446
            *ptr++ = rgb[i][GCOMP];
 
1447
            *ptr++ = rgb[i][RCOMP];
 
1448
         }
 
1449
         else {
 
1450
            ptr += 3;
 
1451
         }
 
1452
      }
 
1453
   }
 
1454
   else {
 
1455
      /* draw all pixels */
 
1456
      for (i=0;i<n;i++) {
 
1457
         *ptr++ = rgb[i][BCOMP];
 
1458
         *ptr++ = rgb[i][GCOMP];
 
1459
         *ptr++ = rgb[i][RCOMP];
 
1460
      }
 
1461
   }
 
1462
}
 
1463
 
 
1464
 
 
1465
/*
 
1466
 * Write a span of PF_5R6G5B-format pixels to an ximage.
 
1467
 */
 
1468
static void write_span_5R6G5B_ximage( RGBA_SPAN_ARGS )
 
1469
{
 
1470
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
1471
   register GLuint i;
 
1472
   register GLushort *ptr = PIXELADDR2( xmesa->xm_buffer, x, y );
 
1473
   if (mask) {
 
1474
      for (i=0;i<n;i++) {
 
1475
         if (mask[i]) {
 
1476
            ptr[i] = PACK_5R6G5B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
 
1477
         }
 
1478
      }
 
1479
   }
 
1480
   else {
 
1481
      /* draw all pixels */
 
1482
#if defined(__i386__) /* word stores don't have to be on 4-byte boundaries */
 
1483
      GLuint *ptr32 = (GLuint *) ptr;
 
1484
      GLuint extraPixel = (n & 1);
 
1485
      n -= extraPixel;
 
1486
      for (i = 0; i < n; i += 2) {
 
1487
         GLuint p0, p1;
 
1488
         p0 = PACK_5R6G5B(rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
 
1489
         p1 = PACK_5R6G5B(rgba[i+1][RCOMP], rgba[i+1][GCOMP], rgba[i+1][BCOMP]);
 
1490
         *ptr32++ = (p1 << 16) | p0;
 
1491
      }
 
1492
      if (extraPixel) {
 
1493
         ptr[n] = PACK_5R6G5B(rgba[n][RCOMP], rgba[n][GCOMP], rgba[n][BCOMP]);
 
1494
      }
 
1495
#else
 
1496
      for (i = 0; i < n; i++) {
 
1497
         ptr[i] = PACK_5R6G5B(rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
 
1498
      }
 
1499
#endif
 
1500
   }
 
1501
}
 
1502
 
 
1503
 
 
1504
/*
 
1505
 * Write a span of PF_DITHER_5R6G5B-format pixels to an ximage.
 
1506
 */
 
1507
static void write_span_DITHER_5R6G5B_ximage( RGBA_SPAN_ARGS )
 
1508
{
 
1509
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
1510
   register GLuint i;
 
1511
   register GLushort *ptr = PIXELADDR2( xmesa->xm_buffer, x, y );
 
1512
   const GLint y2 = FLIP(xmesa->xm_buffer, y);
 
1513
   if (mask) {
 
1514
      for (i=0;i<n;i++,x++) {
 
1515
         if (mask[i]) {
 
1516
            PACK_TRUEDITHER( ptr[i], x, y2, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
 
1517
         }
 
1518
      }
 
1519
   }
 
1520
   else {
 
1521
      /* draw all pixels */
 
1522
#if defined(__i386__) /* word stores don't have to be on 4-byte boundaries */
 
1523
      GLuint *ptr32 = (GLuint *) ptr;
 
1524
      GLuint extraPixel = (n & 1);
 
1525
      n -= extraPixel;
 
1526
      for (i = 0; i < n; i += 2, x += 2) {
 
1527
         GLuint p0, p1;
 
1528
         PACK_TRUEDITHER( p0, x, y2, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
 
1529
         PACK_TRUEDITHER( p1, x+1, y2, rgba[i+1][RCOMP], rgba[i+1][GCOMP], rgba[i+1][BCOMP] );
 
1530
         *ptr32++ = (p1 << 16) | p0;
 
1531
      }
 
1532
      if (extraPixel) {
 
1533
         PACK_TRUEDITHER( ptr[n], x+n, y2, rgba[n][RCOMP], rgba[n][GCOMP], rgba[n][BCOMP]);
 
1534
      }
 
1535
#else
 
1536
      for (i = 0; i < n; i++, x++) {
 
1537
         PACK_TRUEDITHER( ptr[i], x, y2, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
 
1538
      }
 
1539
#endif
 
1540
   }
 
1541
}
 
1542
 
 
1543
 
 
1544
/*
 
1545
 * Write a span of PF_5R6G5B-format pixels to an ximage (no alpha).
 
1546
 */
 
1547
static void write_span_rgb_5R6G5B_ximage( RGB_SPAN_ARGS )
 
1548
{
 
1549
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
1550
   register GLuint i;
 
1551
   register GLushort *ptr = PIXELADDR2( xmesa->xm_buffer, x, y );
 
1552
   if (mask) {
 
1553
      for (i=0;i<n;i++) {
 
1554
         if (mask[i]) {
 
1555
            ptr[i] = PACK_5R6G5B( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
 
1556
         }
 
1557
      }
 
1558
   }
 
1559
   else {
 
1560
      /* draw all pixels */
 
1561
#if defined(__i386__) /* word stores don't have to be on 4-byte boundaries */
 
1562
      GLuint *ptr32 = (GLuint *) ptr;
 
1563
      GLuint extraPixel = (n & 1);
 
1564
      n -= extraPixel;
 
1565
      for (i = 0; i < n; i += 2) {
 
1566
         GLuint p0, p1;
 
1567
         p0 = PACK_5R6G5B(rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]);
 
1568
         p1 = PACK_5R6G5B(rgb[i+1][RCOMP], rgb[i+1][GCOMP], rgb[i+1][BCOMP]);
 
1569
         *ptr32++ = (p1 << 16) | p0;
 
1570
      }
 
1571
      if (extraPixel) {
 
1572
         ptr[n] = PACK_5R6G5B(rgb[n][RCOMP], rgb[n][GCOMP], rgb[n][BCOMP]);
 
1573
      }
 
1574
#else
 
1575
      for (i=0;i<n;i++) {
 
1576
         ptr[i] = PACK_5R6G5B( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
 
1577
      }
 
1578
#endif
 
1579
   }
 
1580
}
 
1581
 
 
1582
 
 
1583
/*
 
1584
 * Write a span of PF_DITHER_5R6G5B-format pixels to an ximage (no alpha).
 
1585
 */
 
1586
static void write_span_rgb_DITHER_5R6G5B_ximage( RGB_SPAN_ARGS )
 
1587
{
 
1588
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
1589
   register GLuint i;
 
1590
   register GLushort *ptr = PIXELADDR2( xmesa->xm_buffer, x, y );
 
1591
   if (mask) {
 
1592
      for (i=0;i<n;i++,x++) {
 
1593
         if (mask[i]) {
 
1594
            PACK_TRUEDITHER( ptr[i], x, y, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
 
1595
         }
 
1596
      }
 
1597
   }
 
1598
   else {
 
1599
      /* draw all pixels */
 
1600
#if defined(__i386__) /* word stores don't have to be on 4-byte boundaries */
 
1601
      GLuint *ptr32 = (GLuint *) ptr;
 
1602
      GLuint extraPixel = (n & 1);
 
1603
      n -= extraPixel;
 
1604
      for (i = 0; i < n; i += 2, x += 2) {
 
1605
         GLuint p0, p1;
 
1606
         PACK_TRUEDITHER( p0, x, y, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
 
1607
         PACK_TRUEDITHER( p1, x+1, y, rgb[i+1][RCOMP], rgb[i+1][GCOMP], rgb[i+1][BCOMP] );
 
1608
         *ptr32++ = (p1 << 16) | p0;
 
1609
      }
 
1610
      if (extraPixel) {
 
1611
         PACK_TRUEDITHER( ptr[n], x+n, y, rgb[n][RCOMP], rgb[n][GCOMP], rgb[n][BCOMP]);
 
1612
      }
 
1613
#else
 
1614
      for (i=0;i<n;i++,x++) {
 
1615
         PACK_TRUEDITHER( ptr[i], x, y, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
 
1616
      }
 
1617
#endif
 
1618
   }
 
1619
}
 
1620
 
 
1621
 
 
1622
/*
 
1623
 * Write a span of PF_DITHER pixels to an XImage.
 
1624
 */
 
1625
static void write_span_DITHER_ximage( RGBA_SPAN_ARGS )
 
1626
{
 
1627
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
1628
   XMesaImage *img = xmesa->xm_buffer->backimage;
 
1629
   register GLuint i;
 
1630
   int yy = FLIP(xmesa->xm_buffer, y);
 
1631
   XDITHER_SETUP(yy);
 
1632
   if (mask) {
 
1633
      for (i=0;i<n;i++,x++) {
 
1634
         if (mask[i]) {
 
1635
            XMesaPutPixel( img, x, yy, XDITHER( x, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
 
1636
         }
 
1637
      }
 
1638
   }
 
1639
   else {
 
1640
      /* draw all pixels */
 
1641
      for (i=0;i<n;i++,x++) {
 
1642
         XMesaPutPixel( img, x, yy, XDITHER( x, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
 
1643
      }
 
1644
   }
 
1645
}
 
1646
 
 
1647
 
 
1648
/*
 
1649
 * Write a span of PF_DITHER pixels to an XImage (no alpha).
 
1650
 */
 
1651
static void write_span_rgb_DITHER_ximage( RGB_SPAN_ARGS )
 
1652
{
 
1653
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
1654
   XMesaImage *img = xmesa->xm_buffer->backimage;
 
1655
   register GLuint i;
 
1656
   int yy = FLIP(xmesa->xm_buffer, y);
 
1657
   XDITHER_SETUP(yy);
 
1658
   if (mask) {
 
1659
      for (i=0;i<n;i++,x++) {
 
1660
         if (mask[i]) {
 
1661
            XMesaPutPixel( img, x, yy, XDITHER( x, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] ) );
 
1662
         }
 
1663
      }
 
1664
   }
 
1665
   else {
 
1666
      /* draw all pixels */
 
1667
      for (i=0;i<n;i++,x++) {
 
1668
         XMesaPutPixel( img, x, yy, XDITHER( x, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] ) );
 
1669
      }
 
1670
   }
 
1671
}
 
1672
 
 
1673
 
 
1674
 
 
1675
/*
 
1676
 * Write a span of 8-bit PF_DITHER pixels to an XImage.
 
1677
 */
 
1678
static void write_span_DITHER8_ximage( RGBA_SPAN_ARGS )
 
1679
{
 
1680
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
1681
   register GLuint i;
 
1682
   register GLubyte *ptr = PIXELADDR1( xmesa->xm_buffer, x, y );
 
1683
   XDITHER_SETUP(y);
 
1684
   if (mask) {
 
1685
      for (i=0;i<n;i++,x++) {
 
1686
         if (mask[i]) {
 
1687
            ptr[i] = (GLubyte) XDITHER( x, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
 
1688
         }
 
1689
      }
 
1690
   }
 
1691
   else {
 
1692
      for (i=0;i<n;i++,x++) {
 
1693
         ptr[i] = (GLubyte) XDITHER( x, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
 
1694
      }
 
1695
   }
 
1696
}
 
1697
 
 
1698
 
 
1699
static void write_span_rgb_DITHER8_ximage( RGB_SPAN_ARGS )
 
1700
{
 
1701
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
1702
   register GLuint i;
 
1703
   register GLubyte *ptr = PIXELADDR1( xmesa->xm_buffer, x, y );
 
1704
   XDITHER_SETUP(y);
 
1705
   if (mask) {
 
1706
      for (i=0;i<n;i++,x++) {
 
1707
         if (mask[i]) {
 
1708
            ptr[i] = (GLubyte) XDITHER( x, rgb[i][0], rgb[i][1], rgb[i][2] );
 
1709
         }
 
1710
      }
 
1711
   }
 
1712
   else {
 
1713
      const GLubyte *data = (GLubyte *) rgb;
 
1714
      for (i=0;i<n;i++,x++) {
 
1715
         /*ptr[i] = XDITHER( x, rgb[i][0], rgb[i][1], rgb[i][2] );*/
 
1716
         ptr[i] = (GLubyte) XDITHER( x, data[i+i+i], data[i+i+i+1], data[i+i+i+2] );
 
1717
      }
 
1718
   }
 
1719
}
 
1720
 
 
1721
 
 
1722
 
 
1723
/*
 
1724
 * Write a span of PF_1BIT pixels to an XImage.
 
1725
 */
 
1726
static void write_span_1BIT_ximage( RGBA_SPAN_ARGS )
 
1727
{
 
1728
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
1729
   XMesaImage *img = xmesa->xm_buffer->backimage;
 
1730
   register GLuint i;
 
1731
   SETUP_1BIT;
 
1732
   y = FLIP(xmesa->xm_buffer, y);
 
1733
   if (mask) {
 
1734
      for (i=0;i<n;i++,x++) {
 
1735
         if (mask[i]) {
 
1736
            XMesaPutPixel(img, x, y, DITHER_1BIT(x, y, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]));
 
1737
         }
 
1738
      }
 
1739
   }
 
1740
   else {
 
1741
      for (i=0;i<n;i++,x++) {
 
1742
         XMesaPutPixel( img, x, y, DITHER_1BIT(x, y, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]) );
 
1743
      }
 
1744
   }
 
1745
}
 
1746
 
 
1747
 
 
1748
/*
 
1749
 * Write a span of PF_1BIT pixels to an XImage (no alpha).
 
1750
 */
 
1751
static void write_span_rgb_1BIT_ximage( RGB_SPAN_ARGS )
 
1752
{
 
1753
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
1754
   XMesaImage *img = xmesa->xm_buffer->backimage;
 
1755
   register GLuint i;
 
1756
   SETUP_1BIT;
 
1757
   y = FLIP(xmesa->xm_buffer, y);
 
1758
   if (mask) {
 
1759
      for (i=0;i<n;i++,x++) {
 
1760
         if (mask[i]) {
 
1761
            XMesaPutPixel(img, x, y, DITHER_1BIT(x, y, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]));
 
1762
         }
 
1763
      }
 
1764
   }
 
1765
   else {
 
1766
      for (i=0;i<n;i++,x++) {
 
1767
         XMesaPutPixel( img, x, y, DITHER_1BIT(x, y, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]) );
 
1768
      }
 
1769
   }
 
1770
}
 
1771
 
 
1772
 
 
1773
/*
 
1774
 * Write a span of PF_HPCR pixels to an XImage.
 
1775
 */
 
1776
static void write_span_HPCR_ximage( RGBA_SPAN_ARGS )
 
1777
{
 
1778
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
1779
   register GLuint i;
 
1780
   register GLubyte *ptr = PIXELADDR1( xmesa->xm_buffer, x, y );
 
1781
   if (mask) {
 
1782
      for (i=0;i<n;i++,x++) {
 
1783
         if (mask[i]) {
 
1784
            ptr[i] = DITHER_HPCR( x, y, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
 
1785
         }
 
1786
      }
 
1787
   }
 
1788
   else {
 
1789
      /* draw all pixels */
 
1790
      for (i=0;i<n;i++,x++) {
 
1791
         ptr[i] = DITHER_HPCR( x, y, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
 
1792
      }
 
1793
   }
 
1794
}
 
1795
 
 
1796
 
 
1797
/*
 
1798
 * Write a span of PF_HPCR pixels to an XImage (no alpha).
 
1799
 */
 
1800
static void write_span_rgb_HPCR_ximage( RGB_SPAN_ARGS )
 
1801
{
 
1802
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
1803
   register GLuint i;
 
1804
   register GLubyte *ptr = PIXELADDR1( xmesa->xm_buffer, x, y );
 
1805
   if (mask) {
 
1806
      for (i=0;i<n;i++,x++) {
 
1807
         if (mask[i]) {
 
1808
            ptr[i] = DITHER_HPCR( x, y, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
 
1809
         }
 
1810
      }
 
1811
   }
 
1812
   else {
 
1813
      /* draw all pixels */
 
1814
      for (i=0;i<n;i++,x++) {
 
1815
         ptr[i] = DITHER_HPCR( x, y, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
 
1816
      }
 
1817
   }
 
1818
}
 
1819
 
 
1820
 
 
1821
/*
 
1822
 * Write a span of PF_LOOKUP pixels to an XImage.
 
1823
 */
 
1824
static void write_span_LOOKUP_ximage( RGBA_SPAN_ARGS )
 
1825
{
 
1826
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
1827
   XMesaImage *img = xmesa->xm_buffer->backimage;
 
1828
   register GLuint i;
 
1829
   LOOKUP_SETUP;
 
1830
   y = FLIP(xmesa->xm_buffer, y);
 
1831
   if (mask) {
 
1832
      for (i=0;i<n;i++,x++) {
 
1833
         if (mask[i]) {
 
1834
            XMesaPutPixel( img, x, y, LOOKUP( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
 
1835
         }
 
1836
      }
 
1837
   }
 
1838
   else {
 
1839
      /* draw all pixels */
 
1840
      for (i=0;i<n;i++,x++) {
 
1841
         XMesaPutPixel( img, x, y, LOOKUP( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
 
1842
      }
 
1843
   }
 
1844
}
 
1845
 
 
1846
 
 
1847
/*
 
1848
 * Write a span of PF_LOOKUP pixels to an XImage (no alpha).
 
1849
 */
 
1850
static void write_span_rgb_LOOKUP_ximage( RGB_SPAN_ARGS )
 
1851
{
 
1852
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
1853
   XMesaImage *img = xmesa->xm_buffer->backimage;
 
1854
   register GLuint i;
 
1855
   LOOKUP_SETUP;
 
1856
   y = FLIP(xmesa->xm_buffer, y);
 
1857
   if (mask) {
 
1858
      for (i=0;i<n;i++,x++) {
 
1859
         if (mask[i]) {
 
1860
            XMesaPutPixel( img, x, y, LOOKUP( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] ) );
 
1861
         }
 
1862
      }
 
1863
   }
 
1864
   else {
 
1865
      /* draw all pixels */
 
1866
      for (i=0;i<n;i++,x++) {
 
1867
         XMesaPutPixel( img, x, y, LOOKUP( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] ) );
 
1868
      }
 
1869
   }
 
1870
}
 
1871
 
 
1872
 
 
1873
/*
 
1874
 * Write a span of 8-bit PF_LOOKUP pixels to an XImage.
 
1875
 */
 
1876
static void write_span_LOOKUP8_ximage( RGBA_SPAN_ARGS )
 
1877
{
 
1878
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
1879
   register GLuint i;
 
1880
   register GLubyte *ptr = PIXELADDR1( xmesa->xm_buffer, x, y );
 
1881
   LOOKUP_SETUP;
 
1882
   if (mask) {
 
1883
      for (i=0;i<n;i++,x++) {
 
1884
         if (mask[i]) {
 
1885
            ptr[i] = (GLubyte) LOOKUP( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
 
1886
         }
 
1887
      }
 
1888
   }
 
1889
   else {
 
1890
      /* draw all pixels */
 
1891
      for (i=0;i<n;i++,x++) {
 
1892
         ptr[i] = (GLubyte) LOOKUP( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
 
1893
      }
 
1894
   }
 
1895
}
 
1896
 
 
1897
 
 
1898
static void write_rgb_LOOKUP8_ximage( const GLcontext *ctx,
 
1899
                                      GLuint n, GLint x, GLint y,
 
1900
                                      CONST GLubyte rgb[][3],
 
1901
                                      const GLubyte mask[] )
 
1902
{
 
1903
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
1904
   register GLuint i;
 
1905
   register GLubyte *ptr = PIXELADDR1( xmesa->xm_buffer, x, y );
 
1906
   LOOKUP_SETUP;
 
1907
   if (mask) {
 
1908
      for (i=0;i<n;i++,x++) {
 
1909
         if (mask[i]) {
 
1910
            ptr[i] = (GLubyte) LOOKUP( rgb[i][0], rgb[i][1], rgb[i][2] );
 
1911
         }
 
1912
      }
 
1913
   }
 
1914
   else {
 
1915
      /* draw all pixels */
 
1916
      const GLubyte *data = (GLubyte *) rgb;
 
1917
      for (i=0;i<n;i++,x++) {
 
1918
         /*ptr[i] = LOOKUP( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );*/
 
1919
         ptr[i] = (GLubyte) LOOKUP( data[i+i+i], data[i+i+i+1], data[i+i+i+2] );
 
1920
      }
 
1921
   }
 
1922
}
 
1923
 
 
1924
 
 
1925
/*
 
1926
 * Write a span of PF_GRAYSCALE pixels to an XImage.
 
1927
 */
 
1928
static void write_span_GRAYSCALE_ximage( RGBA_SPAN_ARGS )
 
1929
{
 
1930
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
1931
   XMesaImage *img = xmesa->xm_buffer->backimage;
 
1932
   register GLuint i;
 
1933
   y = FLIP(xmesa->xm_buffer, y);
 
1934
   if (mask) {
 
1935
      for (i=0;i<n;i++,x++) {
 
1936
         if (mask[i]) {
 
1937
            XMesaPutPixel( img, x, y, GRAY_RGB( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
 
1938
         }
 
1939
      }
 
1940
   }
 
1941
   else {
 
1942
      /* draw all pixels */
 
1943
      for (i=0;i<n;i++,x++) {
 
1944
         XMesaPutPixel( img, x, y, GRAY_RGB( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
 
1945
      }
 
1946
   }
 
1947
}
 
1948
 
 
1949
 
 
1950
/*
 
1951
 * Write a span of PF_GRAYSCALE pixels to an XImage (no alpha).
 
1952
 */
 
1953
static void write_span_rgb_GRAYSCALE_ximage( RGB_SPAN_ARGS )
 
1954
{
 
1955
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
1956
   XMesaImage *img = xmesa->xm_buffer->backimage;
 
1957
   register GLuint i;
 
1958
   y = FLIP(xmesa->xm_buffer, y);
 
1959
   if (mask) {
 
1960
      for (i=0;i<n;i++,x++) {
 
1961
         if (mask[i]) {
 
1962
            XMesaPutPixel( img, x, y, GRAY_RGB( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] ) );
 
1963
         }
 
1964
      }
 
1965
   }
 
1966
   else {
 
1967
      /* draw all pixels */
 
1968
      for (i=0;i<n;i++,x++) {
 
1969
         XMesaPutPixel( img, x, y, GRAY_RGB( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] ) );
 
1970
      }
 
1971
   }
 
1972
}
 
1973
 
 
1974
 
 
1975
/*
 
1976
 * Write a span of 8-bit PF_GRAYSCALE pixels to an XImage.
 
1977
 */
 
1978
static void write_span_GRAYSCALE8_ximage( RGBA_SPAN_ARGS )
 
1979
{
 
1980
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
1981
   register GLuint i;
 
1982
   register GLubyte *ptr = PIXELADDR1( xmesa->xm_buffer, x, y );
 
1983
   if (mask) {
 
1984
      for (i=0;i<n;i++) {
 
1985
         if (mask[i]) {
 
1986
            ptr[i] = (GLubyte) GRAY_RGB( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
 
1987
         }
 
1988
      }
 
1989
   }
 
1990
   else {
 
1991
      /* draw all pixels */
 
1992
      for (i=0;i<n;i++) {
 
1993
         ptr[i] = (GLubyte) GRAY_RGB( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
 
1994
      }
 
1995
   }
 
1996
}
 
1997
 
 
1998
 
 
1999
/*
 
2000
 * Write a span of 8-bit PF_GRAYSCALE pixels to an XImage (no alpha).
 
2001
 */
 
2002
static void write_span_rgb_GRAYSCALE8_ximage( RGB_SPAN_ARGS )
 
2003
{
 
2004
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
2005
   register GLuint i;
 
2006
   register GLubyte *ptr = PIXELADDR1( xmesa->xm_buffer, x, y );
 
2007
   if (mask) {
 
2008
      for (i=0;i<n;i++) {
 
2009
         if (mask[i]) {
 
2010
            ptr[i] = (GLubyte) GRAY_RGB( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
 
2011
         }
 
2012
      }
 
2013
   }
 
2014
   else {
 
2015
      /* draw all pixels */
 
2016
      for (i=0;i<n;i++) {
 
2017
         ptr[i] = (GLubyte) GRAY_RGB( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
 
2018
      }
 
2019
   }
 
2020
}
 
2021
 
 
2022
 
 
2023
 
 
2024
 
 
2025
/**********************************************************************/
 
2026
/*** Write COLOR PIXEL functions                                    ***/
 
2027
/**********************************************************************/
 
2028
 
 
2029
 
 
2030
#define RGBA_PIXEL_ARGS   const GLcontext *ctx,                         \
 
2031
                          GLuint n, const GLint x[], const GLint y[],   \
 
2032
                          CONST GLubyte rgba[][4], const GLubyte mask[]
 
2033
 
 
2034
 
 
2035
/*
 
2036
 * Write an array of PF_TRUECOLOR pixels to a pixmap.
 
2037
 */
 
2038
static void write_pixels_TRUECOLOR_pixmap( RGBA_PIXEL_ARGS )
 
2039
{
 
2040
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
2041
   XMesaDisplay *dpy = xmesa->xm_visual->display;
 
2042
   XMesaDrawable buffer = xmesa->xm_buffer->buffer;
 
2043
   XMesaGC gc = xmesa->xm_buffer->gc;
 
2044
   register GLuint i;
 
2045
   for (i=0;i<n;i++) {
 
2046
      if (mask[i]) {
 
2047
         unsigned long p;
 
2048
         PACK_TRUECOLOR( p, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
 
2049
         XMesaSetForeground( dpy, gc, p );
 
2050
         XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) FLIP(xmesa->xm_buffer, y[i]) );
 
2051
      }
 
2052
   }
 
2053
}
 
2054
 
 
2055
 
 
2056
/*
 
2057
 * Write an array of PF_TRUEDITHER pixels to a pixmap.
 
2058
 */
 
2059
static void write_pixels_TRUEDITHER_pixmap( RGBA_PIXEL_ARGS )
 
2060
{
 
2061
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
2062
   XMesaDisplay *dpy = xmesa->xm_visual->display;
 
2063
   XMesaDrawable buffer = xmesa->xm_buffer->buffer;
 
2064
   XMesaGC gc = xmesa->xm_buffer->gc;
 
2065
   register GLuint i;
 
2066
   for (i=0;i<n;i++) {
 
2067
      if (mask[i]) {
 
2068
         unsigned long p;
 
2069
         PACK_TRUEDITHER(p, x[i], y[i], rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
 
2070
         XMesaSetForeground( dpy, gc, p );
 
2071
         XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) FLIP(xmesa->xm_buffer, y[i]) );
 
2072
      }
 
2073
   }
 
2074
}
 
2075
 
 
2076
 
 
2077
/*
 
2078
 * Write an array of PF_8A8B8G8R pixels to a pixmap.
 
2079
 */
 
2080
static void write_pixels_8A8B8G8R_pixmap( RGBA_PIXEL_ARGS )
 
2081
{
 
2082
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
2083
   XMesaDisplay *dpy = xmesa->xm_visual->display;
 
2084
   XMesaDrawable buffer = xmesa->xm_buffer->buffer;
 
2085
   XMesaGC gc = xmesa->xm_buffer->gc;
 
2086
   register GLuint i;
 
2087
   for (i=0;i<n;i++) {
 
2088
      if (mask[i]) {
 
2089
         XMesaSetForeground( dpy, gc,
 
2090
                         PACK_8A8B8G8R( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP], rgba[i][ACOMP] ));
 
2091
         XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) FLIP(xmesa->xm_buffer, y[i]) );
 
2092
      }
 
2093
   }
 
2094
}
 
2095
 
 
2096
 
 
2097
/*
 
2098
 * Write an array of PF_8R8G8B pixels to a pixmap.
 
2099
 */
 
2100
static void write_pixels_8R8G8B_pixmap( RGBA_PIXEL_ARGS )
 
2101
{
 
2102
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
2103
   XMesaDisplay *dpy = xmesa->xm_visual->display;
 
2104
   XMesaDrawable buffer = xmesa->xm_buffer->buffer;
 
2105
   XMesaGC gc = xmesa->xm_buffer->gc;
 
2106
   register GLuint i;
 
2107
   for (i=0;i<n;i++) {
 
2108
      if (mask[i]) {
 
2109
         XMesaSetForeground( dpy, gc, PACK_8R8G8B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
 
2110
         XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) FLIP(xmesa->xm_buffer, y[i]) );
 
2111
      }
 
2112
   }
 
2113
}
 
2114
 
 
2115
 
 
2116
/*
 
2117
 * Write an array of PF_8R8G8B24 pixels to a pixmap.
 
2118
 */
 
2119
static void write_pixels_8R8G8B24_pixmap( RGBA_PIXEL_ARGS )
 
2120
{
 
2121
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
2122
   XMesaDisplay *dpy = xmesa->xm_visual->display;
 
2123
   XMesaDrawable buffer = xmesa->xm_buffer->buffer;
 
2124
   XMesaGC gc = xmesa->xm_buffer->gc;
 
2125
   register GLuint i;
 
2126
   for (i=0;i<n;i++) {
 
2127
      if (mask[i]) {
 
2128
         XMesaSetForeground( dpy, gc, PACK_8R8G8B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
 
2129
         XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) FLIP(xmesa->xm_buffer, y[i]) );
 
2130
      }
 
2131
   }
 
2132
}
 
2133
 
 
2134
 
 
2135
/*
 
2136
 * Write an array of PF_5R6G5B pixels to a pixmap.
 
2137
 */
 
2138
static void write_pixels_5R6G5B_pixmap( RGBA_PIXEL_ARGS )
 
2139
{
 
2140
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
2141
   XMesaDisplay *dpy = xmesa->xm_visual->display;
 
2142
   XMesaDrawable buffer = xmesa->xm_buffer->buffer;
 
2143
   XMesaGC gc = xmesa->xm_buffer->gc;
 
2144
   register GLuint i;
 
2145
   for (i=0;i<n;i++) {
 
2146
      if (mask[i]) {
 
2147
         XMesaSetForeground( dpy, gc, PACK_5R6G5B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
 
2148
         XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) FLIP(xmesa->xm_buffer, y[i]) );
 
2149
      }
 
2150
   }
 
2151
}
 
2152
 
 
2153
 
 
2154
/*
 
2155
 * Write an array of PF_DITHER_5R6G5B pixels to a pixmap.
 
2156
 */
 
2157
static void write_pixels_DITHER_5R6G5B_pixmap( RGBA_PIXEL_ARGS )
 
2158
{
 
2159
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
2160
   XMesaDisplay *dpy = xmesa->xm_visual->display;
 
2161
   XMesaDrawable buffer = xmesa->xm_buffer->buffer;
 
2162
   XMesaGC gc = xmesa->xm_buffer->gc;
 
2163
   register GLuint i;
 
2164
   for (i=0;i<n;i++) {
 
2165
      if (mask[i]) {
 
2166
         unsigned long p;
 
2167
         PACK_TRUEDITHER(p, x[i], y[i], rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
 
2168
         XMesaSetForeground( dpy, gc, p );
 
2169
         XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) FLIP(xmesa->xm_buffer, y[i]) );
 
2170
      }
 
2171
   }
 
2172
}
 
2173
 
 
2174
 
 
2175
/*
 
2176
 * Write an array of PF_DITHER pixels to a pixmap.
 
2177
 */
 
2178
static void write_pixels_DITHER_pixmap( RGBA_PIXEL_ARGS )
 
2179
{
 
2180
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
2181
   XMesaDisplay *dpy = xmesa->xm_visual->display;
 
2182
   XMesaDrawable buffer = xmesa->xm_buffer->buffer;
 
2183
   XMesaGC gc = xmesa->xm_buffer->gc;
 
2184
   register GLuint i;
 
2185
   DITHER_SETUP;
 
2186
   for (i=0;i<n;i++) {
 
2187
      if (mask[i]) {
 
2188
         XMesaSetForeground( dpy, gc,
 
2189
                         DITHER(x[i], y[i], rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]) );
 
2190
         XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) FLIP(xmesa->xm_buffer, y[i]) );
 
2191
      }
 
2192
   }
 
2193
}
 
2194
 
 
2195
 
 
2196
/*
 
2197
 * Write an array of PF_1BIT pixels to a pixmap.
 
2198
 */
 
2199
static void write_pixels_1BIT_pixmap( RGBA_PIXEL_ARGS )
 
2200
{
 
2201
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
2202
   XMesaDisplay *dpy = xmesa->xm_visual->display;
 
2203
   XMesaDrawable buffer = xmesa->xm_buffer->buffer;
 
2204
   XMesaGC gc = xmesa->xm_buffer->gc;
 
2205
   register GLuint i;
 
2206
   SETUP_1BIT;
 
2207
   for (i=0;i<n;i++) {
 
2208
      if (mask[i]) {
 
2209
         XMesaSetForeground( dpy, gc,
 
2210
                         DITHER_1BIT( x[i], y[i], rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ));
 
2211
         XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) FLIP(xmesa->xm_buffer, y[i]) );
 
2212
      }
 
2213
   }
 
2214
}
 
2215
 
 
2216
 
 
2217
/*
 
2218
 * Write an array of PF_HPCR pixels to a pixmap.
 
2219
 */
 
2220
static void write_pixels_HPCR_pixmap( RGBA_PIXEL_ARGS )
 
2221
{
 
2222
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
2223
   XMesaDisplay *dpy = xmesa->xm_visual->display;
 
2224
   XMesaDrawable buffer = xmesa->xm_buffer->buffer;
 
2225
   XMesaGC gc = xmesa->xm_buffer->gc;
 
2226
   register GLuint i;
 
2227
   for (i=0;i<n;i++) {
 
2228
      if (mask[i]) {
 
2229
         XMesaSetForeground( dpy, gc,
 
2230
                         DITHER_HPCR( x[i], y[i], rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ));
 
2231
         XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) FLIP(xmesa->xm_buffer, y[i]) );
 
2232
      }
 
2233
   }
 
2234
}
 
2235
 
 
2236
 
 
2237
/*
 
2238
 * Write an array of PF_LOOKUP pixels to a pixmap.
 
2239
 */
 
2240
static void write_pixels_LOOKUP_pixmap( RGBA_PIXEL_ARGS )
 
2241
{
 
2242
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
2243
   XMesaDisplay *dpy = xmesa->xm_visual->display;
 
2244
   XMesaDrawable buffer = xmesa->xm_buffer->buffer;
 
2245
   XMesaGC gc = xmesa->xm_buffer->gc;
 
2246
   register GLuint i;
 
2247
   LOOKUP_SETUP;
 
2248
   for (i=0;i<n;i++) {
 
2249
      if (mask[i]) {
 
2250
         XMesaSetForeground( dpy, gc, LOOKUP( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
 
2251
         XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) FLIP(xmesa->xm_buffer, y[i]) );
 
2252
      }
 
2253
   }
 
2254
}
 
2255
 
 
2256
 
 
2257
/*
 
2258
 * Write an array of PF_GRAYSCALE pixels to a pixmap.
 
2259
 */
 
2260
static void write_pixels_GRAYSCALE_pixmap( RGBA_PIXEL_ARGS )
 
2261
{
 
2262
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
2263
   XMesaDisplay *dpy = xmesa->xm_visual->display;
 
2264
   XMesaDrawable buffer = xmesa->xm_buffer->buffer;
 
2265
   XMesaGC gc = xmesa->xm_buffer->gc;
 
2266
   register GLuint i;
 
2267
   for (i=0;i<n;i++) {
 
2268
      if (mask[i]) {
 
2269
         XMesaSetForeground( dpy, gc, GRAY_RGB( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
 
2270
         XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) FLIP(xmesa->xm_buffer, y[i]) );
 
2271
      }
 
2272
   }
 
2273
}
 
2274
 
 
2275
 
 
2276
/*
 
2277
 * Write an array of PF_TRUECOLOR pixels to an ximage.
 
2278
 */
 
2279
static void write_pixels_TRUECOLOR_ximage( RGBA_PIXEL_ARGS )
 
2280
{
 
2281
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
2282
   XMesaImage *img = xmesa->xm_buffer->backimage;
 
2283
   register GLuint i;
 
2284
   for (i=0;i<n;i++) {
 
2285
      if (mask[i]) {
 
2286
         unsigned long p;
 
2287
         PACK_TRUECOLOR( p, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
 
2288
         XMesaPutPixel( img, x[i], FLIP(xmesa->xm_buffer, y[i]), p );
 
2289
      }
 
2290
   }
 
2291
}
 
2292
 
 
2293
 
 
2294
/*
 
2295
 * Write an array of PF_TRUEDITHER pixels to an XImage.
 
2296
 */
 
2297
static void write_pixels_TRUEDITHER_ximage( RGBA_PIXEL_ARGS )
 
2298
{
 
2299
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
2300
   XMesaImage *img = xmesa->xm_buffer->backimage;
 
2301
   register GLuint i;
 
2302
   for (i=0;i<n;i++) {
 
2303
      if (mask[i]) {
 
2304
         unsigned long p;
 
2305
         PACK_TRUEDITHER(p, x[i], y[i], rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
 
2306
         XMesaPutPixel( img, x[i], FLIP(xmesa->xm_buffer, y[i]), p );
 
2307
      }
 
2308
   }
 
2309
}
 
2310
 
 
2311
 
 
2312
/*
 
2313
 * Write an array of PF_8A8B8G8R pixels to an ximage.
 
2314
 */
 
2315
static void write_pixels_8A8B8G8R_ximage( RGBA_PIXEL_ARGS )
 
2316
{
 
2317
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
2318
   register GLuint i;
 
2319
   for (i=0;i<n;i++) {
 
2320
      if (mask[i]) {
 
2321
         GLuint *ptr = PIXELADDR4( xmesa->xm_buffer, x[i], y[i] );
 
2322
         *ptr = PACK_8A8B8G8R( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP], rgba[i][ACOMP] );
 
2323
      }
 
2324
   }
 
2325
}
 
2326
 
 
2327
 
 
2328
/*
 
2329
 * Write an array of PF_8R8G8B pixels to an ximage.
 
2330
 */
 
2331
static void write_pixels_8R8G8B_ximage( RGBA_PIXEL_ARGS )
 
2332
{
 
2333
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
2334
   register GLuint i;
 
2335
   for (i=0;i<n;i++) {
 
2336
      if (mask[i]) {
 
2337
         GLuint *ptr = PIXELADDR4( xmesa->xm_buffer, x[i], y[i] );
 
2338
         *ptr = PACK_8R8G8B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
 
2339
      }
 
2340
   }
 
2341
}
 
2342
 
 
2343
 
 
2344
/*
 
2345
 * Write an array of PF_8R8G8B24 pixels to an ximage.
 
2346
 */
 
2347
static void write_pixels_8R8G8B24_ximage( RGBA_PIXEL_ARGS )
 
2348
{
 
2349
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
2350
   register GLuint i;
 
2351
   for (i=0;i<n;i++) {
 
2352
      if (mask[i]) {
 
2353
         bgr_t *ptr = PIXELADDR3( xmesa->xm_buffer, x[i], y[i] );
 
2354
         ptr->r = rgba[i][RCOMP];
 
2355
         ptr->g = rgba[i][GCOMP];
 
2356
         ptr->b = rgba[i][BCOMP];
 
2357
      }
 
2358
   }
 
2359
}
 
2360
 
 
2361
 
 
2362
/*
 
2363
 * Write an array of PF_5R6G5B pixels to an ximage.
 
2364
 */
 
2365
static void write_pixels_5R6G5B_ximage( RGBA_PIXEL_ARGS )
 
2366
{
 
2367
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
2368
   register GLuint i;
 
2369
   for (i=0;i<n;i++) {
 
2370
      if (mask[i]) {
 
2371
         GLushort *ptr = PIXELADDR2( xmesa->xm_buffer, x[i], y[i] );
 
2372
         *ptr = PACK_5R6G5B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
 
2373
      }
 
2374
   }
 
2375
}
 
2376
 
 
2377
 
 
2378
/*
 
2379
 * Write an array of PF_DITHER_5R6G5B pixels to an ximage.
 
2380
 */
 
2381
static void write_pixels_DITHER_5R6G5B_ximage( RGBA_PIXEL_ARGS )
 
2382
{
 
2383
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
2384
   register GLuint i;
 
2385
   for (i=0;i<n;i++) {
 
2386
      if (mask[i]) {
 
2387
         GLushort *ptr = PIXELADDR2( xmesa->xm_buffer, x[i], y[i] );
 
2388
         PACK_TRUEDITHER( *ptr, x[i], y[i], rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
 
2389
      }
 
2390
   }
 
2391
}
 
2392
 
 
2393
 
 
2394
/*
 
2395
 * Write an array of PF_DITHER pixels to an XImage.
 
2396
 */
 
2397
static void write_pixels_DITHER_ximage( RGBA_PIXEL_ARGS )
 
2398
{
 
2399
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
2400
   XMesaImage *img = xmesa->xm_buffer->backimage;
 
2401
   register GLuint i;
 
2402
   DITHER_SETUP;
 
2403
   for (i=0;i<n;i++) {
 
2404
      if (mask[i]) {
 
2405
         XMesaPutPixel( img, x[i], FLIP(xmesa->xm_buffer, y[i]),
 
2406
                    DITHER( x[i], y[i], rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
 
2407
      }
 
2408
   }
 
2409
}
 
2410
 
 
2411
 
 
2412
/*
 
2413
 * Write an array of 8-bit PF_DITHER pixels to an XImage.
 
2414
 */
 
2415
static void write_pixels_DITHER8_ximage( RGBA_PIXEL_ARGS )
 
2416
{
 
2417
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
2418
   register GLuint i;
 
2419
   DITHER_SETUP;
 
2420
   for (i=0;i<n;i++) {
 
2421
      if (mask[i]) {
 
2422
         GLubyte *ptr = PIXELADDR1( xmesa->xm_buffer,x[i],y[i]);
 
2423
         *ptr = (GLubyte) DITHER( x[i], y[i], rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
 
2424
      }
 
2425
   }
 
2426
}
 
2427
 
 
2428
 
 
2429
/*
 
2430
 * Write an array of PF_1BIT pixels to an XImage.
 
2431
 */
 
2432
static void write_pixels_1BIT_ximage( RGBA_PIXEL_ARGS )
 
2433
{
 
2434
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
2435
   XMesaImage *img = xmesa->xm_buffer->backimage;
 
2436
   register GLuint i;
 
2437
   SETUP_1BIT;
 
2438
   for (i=0;i<n;i++) {
 
2439
      if (mask[i]) {
 
2440
         XMesaPutPixel( img, x[i], FLIP(xmesa->xm_buffer, y[i]),
 
2441
                    DITHER_1BIT( x[i], y[i], rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ));
 
2442
      }
 
2443
   }
 
2444
}
 
2445
 
 
2446
 
 
2447
/*
 
2448
 * Write an array of PF_HPCR pixels to an XImage.
 
2449
 */
 
2450
static void write_pixels_HPCR_ximage( RGBA_PIXEL_ARGS )
 
2451
{
 
2452
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
2453
   register GLuint i;
 
2454
   for (i=0;i<n;i++) {
 
2455
      if (mask[i]) {
 
2456
         GLubyte *ptr = PIXELADDR1( xmesa->xm_buffer,x[i],y[i]);
 
2457
         *ptr = (GLubyte) DITHER_HPCR( x[i], y[i], rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
 
2458
      }
 
2459
   }
 
2460
}
 
2461
 
 
2462
 
 
2463
/*
 
2464
 * Write an array of PF_LOOKUP pixels to an XImage.
 
2465
 */
 
2466
static void write_pixels_LOOKUP_ximage( RGBA_PIXEL_ARGS )
 
2467
{
 
2468
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
2469
   XMesaImage *img = xmesa->xm_buffer->backimage;
 
2470
   register GLuint i;
 
2471
   LOOKUP_SETUP;
 
2472
   for (i=0;i<n;i++) {
 
2473
      if (mask[i]) {
 
2474
         XMesaPutPixel( img, x[i], FLIP(xmesa->xm_buffer, y[i]), LOOKUP(rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]) );
 
2475
      }
 
2476
   }
 
2477
}
 
2478
 
 
2479
 
 
2480
/*
 
2481
 * Write an array of 8-bit PF_LOOKUP pixels to an XImage.
 
2482
 */
 
2483
static void write_pixels_LOOKUP8_ximage( RGBA_PIXEL_ARGS )
 
2484
{
 
2485
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
2486
   register GLuint i;
 
2487
   LOOKUP_SETUP;
 
2488
   for (i=0;i<n;i++) {
 
2489
      if (mask[i]) {
 
2490
         GLubyte *ptr = PIXELADDR1( xmesa->xm_buffer,x[i],y[i]);
 
2491
         *ptr = (GLubyte) LOOKUP( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
 
2492
      }
 
2493
   }
 
2494
}
 
2495
 
 
2496
 
 
2497
/*
 
2498
 * Write an array of PF_GRAYSCALE pixels to an XImage.
 
2499
 */
 
2500
static void write_pixels_GRAYSCALE_ximage( RGBA_PIXEL_ARGS )
 
2501
{
 
2502
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
2503
   XMesaImage *img = xmesa->xm_buffer->backimage;
 
2504
   register GLuint i;
 
2505
   for (i=0;i<n;i++) {
 
2506
      if (mask[i]) {
 
2507
         XMesaPutPixel( img, x[i], FLIP(xmesa->xm_buffer, y[i]),
 
2508
                    GRAY_RGB( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
 
2509
      }
 
2510
   }
 
2511
}
 
2512
 
 
2513
 
 
2514
/*
 
2515
 * Write an array of 8-bit PF_GRAYSCALE pixels to an XImage.
 
2516
 */
 
2517
static void write_pixels_GRAYSCALE8_ximage( RGBA_PIXEL_ARGS )
 
2518
{
 
2519
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
2520
   register GLuint i;
 
2521
   for (i=0;i<n;i++) {
 
2522
      if (mask[i]) {
 
2523
         GLubyte *ptr = PIXELADDR1( xmesa->xm_buffer, x[i], y[i] );
 
2524
         *ptr = (GLubyte) GRAY_RGB( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
 
2525
      }
 
2526
   }
 
2527
}
 
2528
 
 
2529
 
 
2530
 
 
2531
 
 
2532
/**********************************************************************/
 
2533
/*** Write MONO COLOR SPAN functions                                ***/
 
2534
/**********************************************************************/
 
2535
 
 
2536
#define MONO_SPAN_ARGS  const GLcontext *ctx,   \
 
2537
                        GLuint n, GLint x, GLint y, const GLchan color[4], \
 
2538
                        const GLubyte mask[]
 
2539
 
 
2540
 
 
2541
/*
 
2542
 * Write a span of identical pixels to a pixmap.
 
2543
 */
 
2544
static void write_span_mono_pixmap( MONO_SPAN_ARGS )
 
2545
{
 
2546
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
2547
   XMesaDisplay *dpy = xmesa->xm_visual->display;
 
2548
   XMesaDrawable buffer = xmesa->xm_buffer->buffer;
 
2549
   XMesaGC gc = xmesa->xm_buffer->gc;
 
2550
   const unsigned long pixel = xmesa_color_to_pixel(xmesa, color[RCOMP],
 
2551
               color[GCOMP], color[BCOMP], color[ACOMP], xmesa->pixelformat);
 
2552
   register GLuint i;
 
2553
   XMesaSetForeground( xmesa->display, gc, pixel );
 
2554
   y = FLIP(xmesa->xm_buffer, y);
 
2555
 
 
2556
   /* New code contributed by Jeff Epler and cleaned up by Keith
 
2557
    * Whitwell.  
 
2558
    */
 
2559
   for (i = 0; i < n; ) {
 
2560
      GLuint start = i;
 
2561
 
 
2562
      /* Identify and emit contiguous rendered pixels
 
2563
       */
 
2564
      while (i < n && mask[i])
 
2565
         i++;
 
2566
 
 
2567
      if (start < i) 
 
2568
         XMesaFillRectangle( dpy, buffer, gc,
 
2569
                             (int)(x+start), (int) y,
 
2570
                             (int)(i-start), 1);
 
2571
 
 
2572
      /* Eat up non-rendered pixels
 
2573
       */
 
2574
      while (i < n && !mask[i])
 
2575
         i++;
 
2576
   }
 
2577
}
 
2578
 
 
2579
 
 
2580
 
 
2581
static void write_span_mono_index_pixmap( const GLcontext *ctx, GLuint n,
 
2582
                                          GLint x, GLint y, GLuint colorIndex,
 
2583
                                          const GLubyte mask[] )
 
2584
{
 
2585
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
2586
   XMesaDisplay *dpy = xmesa->xm_visual->display;
 
2587
   XMesaDrawable buffer = xmesa->xm_buffer->buffer;
 
2588
   XMesaGC gc = xmesa->xm_buffer->gc;
 
2589
   register GLuint i;
 
2590
   XMesaSetForeground( xmesa->display, gc, colorIndex );
 
2591
   y = FLIP(xmesa->xm_buffer, y);
 
2592
 
 
2593
   for (i = 0 ; i < n ;) {
 
2594
      GLuint start = i;
 
2595
      
 
2596
      /* Identify and emit contiguous rendered pixels 
 
2597
       */
 
2598
      while (i < n && mask[i])
 
2599
         i++;
 
2600
 
 
2601
      if (start < i) 
 
2602
         XMesaFillRectangle( dpy, buffer, gc, 
 
2603
                             (int)(x+start), (int) y, 
 
2604
                             (int)(i-start), 1);
 
2605
 
 
2606
      /* Eat up non-rendered pixels
 
2607
       */
 
2608
      while (i < n && !mask[i])
 
2609
         i++;
 
2610
   }
 
2611
}
 
2612
 
 
2613
 
 
2614
 
 
2615
/*
 
2616
 * Write a span of PF_TRUEDITHER pixels to a pixmap.
 
2617
 */
 
2618
static void write_span_mono_TRUEDITHER_pixmap( MONO_SPAN_ARGS )
 
2619
{
 
2620
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
2621
   XMesaDisplay *dpy = xmesa->xm_visual->display;
 
2622
   XMesaDrawable buffer = xmesa->xm_buffer->buffer;
 
2623
   XMesaGC gc = xmesa->xm_buffer->gc;
 
2624
   const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
 
2625
   register GLuint i;
 
2626
   int yy = FLIP(xmesa->xm_buffer, y);
 
2627
   for (i=0;i<n;i++,x++) {
 
2628
      if (mask[i]) {
 
2629
         unsigned long p;
 
2630
         PACK_TRUEDITHER(p, x, yy, r, g, b);
 
2631
         XMesaSetForeground( dpy, gc, p );
 
2632
         XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) yy );
 
2633
      }
 
2634
   }
 
2635
}
 
2636
 
 
2637
 
 
2638
/*
 
2639
 * Write a span of PF_DITHER pixels to a pixmap.
 
2640
 */
 
2641
static void write_span_mono_DITHER_pixmap( MONO_SPAN_ARGS )
 
2642
{
 
2643
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
2644
   XMesaDisplay *dpy = xmesa->xm_visual->display;
 
2645
   XMesaDrawable buffer = xmesa->xm_buffer->buffer;
 
2646
   XMesaGC gc = xmesa->xm_buffer->gc;
 
2647
   const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
 
2648
   register GLuint i;
 
2649
   int yy = FLIP(xmesa->xm_buffer, y);
 
2650
   XDITHER_SETUP(yy);
 
2651
   for (i=0;i<n;i++,x++) {
 
2652
      if (mask[i]) {
 
2653
         XMesaSetForeground( dpy, gc, XDITHER( x, r, g, b ) );
 
2654
         XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) yy );
 
2655
      }
 
2656
   }
 
2657
}
 
2658
 
 
2659
 
 
2660
/*
 
2661
 * Write a span of PF_1BIT pixels to a pixmap.
 
2662
 */
 
2663
static void write_span_mono_1BIT_pixmap( MONO_SPAN_ARGS )
 
2664
{
 
2665
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
2666
   XMesaDisplay *dpy = xmesa->xm_visual->display;
 
2667
   XMesaDrawable buffer = xmesa->xm_buffer->buffer;
 
2668
   XMesaGC gc = xmesa->xm_buffer->gc;
 
2669
   const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
 
2670
   register GLuint i;
 
2671
   SETUP_1BIT;
 
2672
   y = FLIP(xmesa->xm_buffer, y);
 
2673
   for (i=0;i<n;i++,x++) {
 
2674
      if (mask[i]) {
 
2675
         XMesaSetForeground( dpy, gc, DITHER_1BIT( x, y, r, g, b ) );
 
2676
         XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
 
2677
      }
 
2678
   }
 
2679
}
 
2680
 
 
2681
 
 
2682
/*
 
2683
 * Write a span of identical pixels to an XImage.
 
2684
 */
 
2685
static void write_span_mono_ximage( MONO_SPAN_ARGS )
 
2686
{
 
2687
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
2688
   XMesaImage *img = xmesa->xm_buffer->backimage;
 
2689
   register GLuint i;
 
2690
   const unsigned long pixel = xmesa_color_to_pixel(xmesa, color[RCOMP],
 
2691
               color[GCOMP], color[BCOMP], color[ACOMP], xmesa->pixelformat);
 
2692
   y = FLIP(xmesa->xm_buffer, y);
 
2693
   for (i=0;i<n;i++,x++) {
 
2694
      if (mask[i]) {
 
2695
         XMesaPutPixel( img, x, y, pixel );
 
2696
      }
 
2697
   }
 
2698
}
 
2699
 
 
2700
 
 
2701
static void write_span_mono_index_ximage( const GLcontext *ctx, GLuint n,
 
2702
                                          GLint x, GLint y,
 
2703
                                          GLuint colorIndex,
 
2704
                                          const GLubyte mask[] )
 
2705
{
 
2706
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
2707
   XMesaImage *img = xmesa->xm_buffer->backimage;
 
2708
   register GLuint i;
 
2709
   y = FLIP(xmesa->xm_buffer, y);
 
2710
   for (i=0;i<n;i++,x++) {
 
2711
      if (mask[i]) {
 
2712
         XMesaPutPixel( img, x, y, colorIndex );
 
2713
      }
 
2714
   }
 
2715
}
 
2716
 
 
2717
 
 
2718
/*
 
2719
 * Write a span of identical PF_TRUEDITHER pixels to an XImage.
 
2720
 */
 
2721
static void write_span_mono_TRUEDITHER_ximage( MONO_SPAN_ARGS )
 
2722
{
 
2723
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
2724
   XMesaImage *img = xmesa->xm_buffer->backimage;
 
2725
   const GLint r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
 
2726
   GLuint i;
 
2727
   y = FLIP(xmesa->xm_buffer, y);
 
2728
   for (i=0;i<n;i++) {
 
2729
      if (mask[i]) {
 
2730
         unsigned long p;
 
2731
         PACK_TRUEDITHER( p, x+i, y, r, g, b);
 
2732
         XMesaPutPixel( img, x+i, y, p );
 
2733
      }
 
2734
   }
 
2735
}
 
2736
 
 
2737
 
 
2738
/*
 
2739
 * Write a span of identical 8A8B8G8R pixels to an XImage.
 
2740
 */
 
2741
static void write_span_mono_8A8B8G8R_ximage( MONO_SPAN_ARGS )
 
2742
{
 
2743
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
2744
   GLuint i, *ptr;
 
2745
   const unsigned long pixel = xmesa_color_to_pixel(xmesa, color[RCOMP],
 
2746
               color[GCOMP], color[BCOMP], color[ACOMP], xmesa->pixelformat);
 
2747
   ptr = PIXELADDR4( xmesa->xm_buffer, x, y );
 
2748
   for (i=0;i<n;i++) {
 
2749
      if (mask[i]) {
 
2750
         ptr[i] = pixel;
 
2751
      }
 
2752
   }
 
2753
}
 
2754
 
 
2755
 
 
2756
/*
 
2757
 * Write a span of identical 8R8G8B pixels to an XImage.
 
2758
 */
 
2759
static void write_span_mono_8R8G8B_ximage( MONO_SPAN_ARGS )
 
2760
{
 
2761
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
2762
   const GLuint pixel = PACK_8R8G8B(color[RCOMP], color[GCOMP], color[BCOMP]);
 
2763
   GLuint *ptr = PIXELADDR4( xmesa->xm_buffer, x, y );
 
2764
   GLuint i;
 
2765
   for (i=0;i<n;i++) {
 
2766
      if (mask[i]) {
 
2767
         ptr[i] = pixel;
 
2768
      }
 
2769
   }
 
2770
}
 
2771
 
 
2772
 
 
2773
/*
 
2774
 * Write a span of identical 8R8G8B pixels to an XImage.
 
2775
 */
 
2776
static void write_span_mono_8R8G8B24_ximage( MONO_SPAN_ARGS )
 
2777
{
 
2778
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
2779
   const GLubyte r = color[RCOMP];
 
2780
   const GLubyte g = color[GCOMP];
 
2781
   const GLubyte b = color[BCOMP];
 
2782
   GLuint i;
 
2783
   bgr_t *ptr = PIXELADDR3( xmesa->xm_buffer, x, y );
 
2784
   for (i=0;i<n;i++) {
 
2785
      if (mask[i]) {
 
2786
         ptr[i].r = r;
 
2787
         ptr[i].g = g;
 
2788
         ptr[i].b = b;
 
2789
      }
 
2790
   }
 
2791
}
 
2792
 
 
2793
 
 
2794
/*
 
2795
 * Write a span of identical DITHER pixels to an XImage.
 
2796
 */
 
2797
static void write_span_mono_DITHER_ximage( MONO_SPAN_ARGS )
 
2798
{
 
2799
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
2800
   const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
 
2801
   XMesaImage *img = xmesa->xm_buffer->backimage;
 
2802
   int yy = FLIP(xmesa->xm_buffer, y);
 
2803
   register GLuint i;
 
2804
   XDITHER_SETUP(yy);
 
2805
   for (i=0;i<n;i++,x++) {
 
2806
      if (mask[i]) {
 
2807
         XMesaPutPixel( img, x, yy, XDITHER( x, r, g, b ) );
 
2808
      }
 
2809
   }
 
2810
}
 
2811
 
 
2812
 
 
2813
/*
 
2814
 * Write a span of identical 8-bit DITHER pixels to an XImage.
 
2815
 */
 
2816
static void write_span_mono_DITHER8_ximage( MONO_SPAN_ARGS )
 
2817
{
 
2818
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
2819
   const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
 
2820
   register GLubyte *ptr = PIXELADDR1( xmesa->xm_buffer,x,y);
 
2821
   register GLuint i;
 
2822
   XDITHER_SETUP(y);
 
2823
   for (i=0;i<n;i++,x++) {
 
2824
      if (mask[i]) {
 
2825
         ptr[i] = (GLubyte) XDITHER( x, r, g, b );
 
2826
      }
 
2827
   }
 
2828
}
 
2829
 
 
2830
 
 
2831
/*
 
2832
 * Write a span of identical 8-bit LOOKUP pixels to an XImage.
 
2833
 */
 
2834
static void write_span_mono_LOOKUP8_ximage( MONO_SPAN_ARGS )
 
2835
{
 
2836
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
2837
   register GLuint i;
 
2838
   register GLubyte *ptr = PIXELADDR1( xmesa->xm_buffer,x,y);
 
2839
   GLubyte pixel;
 
2840
   LOOKUP_SETUP;
 
2841
   pixel = LOOKUP(color[RCOMP], color[GCOMP], color[BCOMP]);
 
2842
   for (i=0;i<n;i++) {
 
2843
      if (mask[i]) {
 
2844
         ptr[i] = pixel;
 
2845
      }
 
2846
   }
 
2847
}
 
2848
 
 
2849
 
 
2850
/*
 
2851
 * Write a span of identical PF_1BIT pixels to an XImage.
 
2852
 */
 
2853
static void write_span_mono_1BIT_ximage( MONO_SPAN_ARGS )
 
2854
{
 
2855
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
2856
   const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
 
2857
   XMesaImage *img = xmesa->xm_buffer->backimage;
 
2858
   register GLuint i;
 
2859
   SETUP_1BIT;
 
2860
   y = FLIP(xmesa->xm_buffer, y);
 
2861
   for (i=0;i<n;i++,x++) {
 
2862
      if (mask[i]) {
 
2863
         XMesaPutPixel( img, x, y, DITHER_1BIT( x, y, r, g, b ) );
 
2864
      }
 
2865
   }
 
2866
}
 
2867
 
 
2868
 
 
2869
/*
 
2870
 * Write a span of identical HPCR pixels to an XImage.
 
2871
 */
 
2872
static void write_span_mono_HPCR_ximage( MONO_SPAN_ARGS )
 
2873
{
 
2874
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
2875
   const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
 
2876
   register GLubyte *ptr = PIXELADDR1( xmesa->xm_buffer,x,y);
 
2877
   register GLuint i;
 
2878
   for (i=0;i<n;i++,x++) {
 
2879
      if (mask[i]) {
 
2880
         ptr[i] = DITHER_HPCR( x, y, r, g, b );
 
2881
      }
 
2882
   }
 
2883
}
 
2884
 
 
2885
 
 
2886
/*
 
2887
 * Write a span of identical 8-bit GRAYSCALE pixels to an XImage.
 
2888
 */
 
2889
static void write_span_mono_GRAYSCALE8_ximage( MONO_SPAN_ARGS )
 
2890
{
 
2891
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
2892
   const GLubyte p = GRAY_RGB(color[RCOMP], color[GCOMP], color[BCOMP]);
 
2893
   GLubyte *ptr = (GLubyte *) PIXELADDR1( xmesa->xm_buffer,x,y);
 
2894
   GLuint i;
 
2895
   for (i=0;i<n;i++) {
 
2896
      if (mask[i]) {
 
2897
         ptr[i] = p;
 
2898
      }
 
2899
   }
 
2900
}
 
2901
 
 
2902
 
 
2903
 
 
2904
/*
 
2905
 * Write a span of identical PF_DITHER_5R6G5B pixels to an XImage.
 
2906
 */
 
2907
static void write_span_mono_DITHER_5R6G5B_ximage( MONO_SPAN_ARGS )
 
2908
{
 
2909
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
2910
   register GLushort *ptr = PIXELADDR2( xmesa->xm_buffer, x, y );
 
2911
   const GLint r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
 
2912
   GLuint i;
 
2913
   y = FLIP(xmesa->xm_buffer, y);
 
2914
   for (i=0;i<n;i++) {
 
2915
      if (mask[i]) {
 
2916
         PACK_TRUEDITHER(ptr[i], x+i, y, r, g, b);
 
2917
      }
 
2918
   }
 
2919
}
 
2920
 
 
2921
 
 
2922
 
 
2923
/**********************************************************************/
 
2924
/*** Write MONO COLOR PIXELS functions                              ***/
 
2925
/**********************************************************************/
 
2926
 
 
2927
#define MONO_PIXEL_ARGS const GLcontext *ctx,                           \
 
2928
                        GLuint n, const GLint x[], const GLint y[],     \
 
2929
                        const GLchan color[4], const GLubyte mask[]
 
2930
 
 
2931
/*
 
2932
 * Write an array of identical pixels to a pixmap.
 
2933
 */
 
2934
static void write_pixels_mono_pixmap( MONO_PIXEL_ARGS )
 
2935
{
 
2936
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
2937
   XMesaDisplay *dpy = xmesa->xm_visual->display;
 
2938
   XMesaDrawable buffer = xmesa->xm_buffer->buffer;
 
2939
   XMesaGC gc = xmesa->xm_buffer->gc;
 
2940
   register GLuint i;
 
2941
   const unsigned long pixel = xmesa_color_to_pixel(xmesa, color[RCOMP],
 
2942
               color[GCOMP], color[BCOMP], color[ACOMP], xmesa->pixelformat);
 
2943
   XMesaSetForeground( xmesa->display, gc, pixel );
 
2944
   for (i=0;i<n;i++) {
 
2945
      if (mask[i]) {
 
2946
         XMesaDrawPoint( dpy, buffer, gc,
 
2947
                         (int) x[i], (int) FLIP(xmesa->xm_buffer, y[i]) );
 
2948
      }
 
2949
   }
 
2950
}
 
2951
 
 
2952
 
 
2953
static void write_pixels_mono_index_pixmap(const GLcontext *ctx,
 
2954
                                           GLuint n,
 
2955
                                           const GLint x[], const GLint y[],
 
2956
                                           GLuint colorIndex,
 
2957
                                           const GLubyte mask[] )
 
2958
{
 
2959
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
2960
   XMesaDisplay *dpy = xmesa->xm_visual->display;
 
2961
   XMesaDrawable buffer = xmesa->xm_buffer->buffer;
 
2962
   XMesaGC gc = xmesa->xm_buffer->gc;
 
2963
   register GLuint i;
 
2964
   XMesaSetForeground( xmesa->display, gc, colorIndex );
 
2965
   for (i=0;i<n;i++) {
 
2966
      if (mask[i]) {
 
2967
         XMesaDrawPoint( dpy, buffer, gc,
 
2968
                         (int) x[i], (int) FLIP(xmesa->xm_buffer, y[i]) );
 
2969
      }
 
2970
   }
 
2971
}
 
2972
 
 
2973
 
 
2974
/*
 
2975
 * Write an array of PF_TRUEDITHER pixels to a pixmap.
 
2976
 */
 
2977
static void write_pixels_mono_TRUEDITHER_pixmap( MONO_PIXEL_ARGS )
 
2978
{
 
2979
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
2980
   XMesaDisplay *dpy = xmesa->xm_visual->display;
 
2981
   XMesaDrawable buffer = xmesa->xm_buffer->buffer;
 
2982
   XMesaGC gc = xmesa->xm_buffer->gc;
 
2983
   register GLuint i;
 
2984
   const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
 
2985
   for (i=0;i<n;i++) {
 
2986
      if (mask[i]) {
 
2987
         unsigned long p;
 
2988
         PACK_TRUEDITHER(p, x[i], y[i], r, g, b);
 
2989
         XMesaSetForeground( dpy, gc, p );
 
2990
         XMesaDrawPoint( dpy, buffer, gc,
 
2991
                         (int) x[i], (int) FLIP(xmesa->xm_buffer, y[i]) );
 
2992
      }
 
2993
   }
 
2994
}
 
2995
 
 
2996
 
 
2997
/*
 
2998
 * Write an array of PF_DITHER pixels to a pixmap.
 
2999
 */
 
3000
static void write_pixels_mono_DITHER_pixmap( MONO_PIXEL_ARGS )
 
3001
{
 
3002
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
3003
   XMesaDisplay *dpy = xmesa->xm_visual->display;
 
3004
   XMesaDrawable buffer = xmesa->xm_buffer->buffer;
 
3005
   XMesaGC gc = xmesa->xm_buffer->gc;
 
3006
   register GLuint i;
 
3007
   const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
 
3008
   DITHER_SETUP;
 
3009
   for (i=0;i<n;i++) {
 
3010
      if (mask[i]) {
 
3011
         XMesaSetForeground( dpy, gc, DITHER( x[i], y[i], r, g, b ) );
 
3012
         XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) FLIP(xmesa->xm_buffer, y[i]) );
 
3013
      }
 
3014
   }
 
3015
}
 
3016
 
 
3017
 
 
3018
/*
 
3019
 * Write an array of PF_1BIT pixels to a pixmap.
 
3020
 */
 
3021
static void write_pixels_mono_1BIT_pixmap( MONO_PIXEL_ARGS )
 
3022
{
 
3023
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
3024
   XMesaDisplay *dpy = xmesa->xm_visual->display;
 
3025
   XMesaDrawable buffer = xmesa->xm_buffer->buffer;
 
3026
   XMesaGC gc = xmesa->xm_buffer->gc;
 
3027
   register GLuint i;
 
3028
   const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
 
3029
   SETUP_1BIT;
 
3030
   for (i=0;i<n;i++) {
 
3031
      if (mask[i]) {
 
3032
         XMesaSetForeground( dpy, gc, DITHER_1BIT( x[i], y[i], r, g, b ) );
 
3033
         XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) FLIP(xmesa->xm_buffer, y[i]) );
 
3034
      }
 
3035
   }
 
3036
}
 
3037
 
 
3038
 
 
3039
/*
 
3040
 * Write an array of identical pixels to an XImage.
 
3041
 */
 
3042
static void write_pixels_mono_ximage( MONO_PIXEL_ARGS )
 
3043
{
 
3044
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
3045
   XMesaImage *img = xmesa->xm_buffer->backimage;
 
3046
   register GLuint i;
 
3047
   const unsigned long pixel = xmesa_color_to_pixel(xmesa, color[RCOMP],
 
3048
               color[GCOMP], color[BCOMP], color[ACOMP], xmesa->pixelformat);
 
3049
   for (i=0;i<n;i++) {
 
3050
      if (mask[i]) {
 
3051
         XMesaPutPixel( img, x[i], FLIP(xmesa->xm_buffer, y[i]), pixel );
 
3052
      }
 
3053
   }
 
3054
}
 
3055
 
 
3056
 
 
3057
static void write_pixels_mono_index_ximage( const GLcontext *ctx, GLuint n,
 
3058
                                            const GLint x[], const GLint y[],
 
3059
                                            GLuint colorIndex,
 
3060
                                            const GLubyte mask[] )
 
3061
{
 
3062
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
3063
   XMesaImage *img = xmesa->xm_buffer->backimage;
 
3064
   register GLuint i;
 
3065
   for (i=0;i<n;i++) {
 
3066
      if (mask[i]) {
 
3067
         XMesaPutPixel( img, x[i], FLIP(xmesa->xm_buffer, y[i]), colorIndex );
 
3068
      }
 
3069
   }
 
3070
}
 
3071
 
 
3072
 
 
3073
/*
 
3074
 * Write an array of identical TRUEDITHER pixels to an XImage.
 
3075
 */
 
3076
static void write_pixels_mono_TRUEDITHER_ximage( MONO_PIXEL_ARGS )
 
3077
{
 
3078
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
3079
   XMesaImage *img = xmesa->xm_buffer->backimage;
 
3080
   register GLuint i;
 
3081
   const int r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
 
3082
   for (i=0;i<n;i++) {
 
3083
      if (mask[i]) {
 
3084
         unsigned long p;
 
3085
         PACK_TRUEDITHER(p, x[i], FLIP(xmesa->xm_buffer, y[i]), r, g, b);
 
3086
         XMesaPutPixel( img, x[i], FLIP(xmesa->xm_buffer, y[i]), p );
 
3087
      }
 
3088
   }
 
3089
}
 
3090
 
 
3091
 
 
3092
 
 
3093
/*
 
3094
 * Write an array of identical 8A8B8G8R pixels to an XImage
 
3095
 */
 
3096
static void write_pixels_mono_8A8B8G8R_ximage( MONO_PIXEL_ARGS )
 
3097
{
 
3098
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
3099
   const GLuint p = PACK_8A8B8G8R(color[RCOMP], color[GCOMP],
 
3100
                                  color[BCOMP], color[ACOMP]);
 
3101
   register GLuint i;
 
3102
   for (i=0;i<n;i++) {
 
3103
      if (mask[i]) {
 
3104
         GLuint *ptr = PIXELADDR4( xmesa->xm_buffer, x[i], y[i] );
 
3105
         *ptr = p;
 
3106
      }
 
3107
   }
 
3108
}
 
3109
 
 
3110
 
 
3111
/*
 
3112
 * Write an array of identical 8R8G8B pixels to an XImage.
 
3113
 */
 
3114
static void write_pixels_mono_8R8G8B_ximage( MONO_PIXEL_ARGS )
 
3115
{
 
3116
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
3117
   register GLuint i;
 
3118
   const GLuint p = PACK_8R8G8B(color[RCOMP], color[GCOMP], color[BCOMP]);
 
3119
   for (i=0;i<n;i++) {
 
3120
      if (mask[i]) {
 
3121
         GLuint *ptr = PIXELADDR4( xmesa->xm_buffer, x[i], y[i] );
 
3122
         *ptr = p;
 
3123
      }
 
3124
   }
 
3125
}
 
3126
 
 
3127
 
 
3128
/*
 
3129
 * Write an array of identical 8R8G8B pixels to an XImage.
 
3130
 */
 
3131
static void write_pixels_mono_8R8G8B24_ximage( MONO_PIXEL_ARGS )
 
3132
{
 
3133
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
3134
   const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
 
3135
   register GLuint i;
 
3136
   for (i=0;i<n;i++) {
 
3137
      if (mask[i]) {
 
3138
         bgr_t *ptr = PIXELADDR3( xmesa->xm_buffer, x[i], y[i] );
 
3139
         ptr->r = r;
 
3140
         ptr->g = g;
 
3141
         ptr->b = b;
 
3142
      }
 
3143
   }
 
3144
}
 
3145
 
 
3146
 
 
3147
/*
 
3148
 * Write an array of identical PF_DITHER pixels to an XImage.
 
3149
 */
 
3150
static void write_pixels_mono_DITHER_ximage( MONO_PIXEL_ARGS )
 
3151
{
 
3152
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
3153
   const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
 
3154
   XMesaImage *img = xmesa->xm_buffer->backimage;
 
3155
   register GLuint i;
 
3156
   DITHER_SETUP;
 
3157
   for (i=0;i<n;i++) {
 
3158
      if (mask[i]) {
 
3159
         XMesaPutPixel( img, x[i], FLIP(xmesa->xm_buffer, y[i]), DITHER( x[i], y[i], r, g, b ) );
 
3160
      }
 
3161
   }
 
3162
}
 
3163
 
 
3164
 
 
3165
/*
 
3166
 * Write an array of identical 8-bit PF_DITHER pixels to an XImage.
 
3167
 */
 
3168
static void write_pixels_mono_DITHER8_ximage( MONO_PIXEL_ARGS )
 
3169
{
 
3170
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
3171
   const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
 
3172
   register GLuint i;
 
3173
   DITHER_SETUP;
 
3174
   for (i=0;i<n;i++) {
 
3175
      if (mask[i]) {
 
3176
         GLubyte *ptr = PIXELADDR1( xmesa->xm_buffer,x[i],y[i]);
 
3177
         *ptr = (GLubyte) DITHER( x[i], y[i], r, g, b );
 
3178
      }
 
3179
   }
 
3180
}
 
3181
 
 
3182
 
 
3183
/*
 
3184
 * Write an array of identical 8-bit PF_LOOKUP pixels to an XImage.
 
3185
 */
 
3186
static void write_pixels_mono_LOOKUP8_ximage( MONO_PIXEL_ARGS )
 
3187
{
 
3188
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
3189
   register GLuint i;
 
3190
   GLubyte pixel;
 
3191
   LOOKUP_SETUP;
 
3192
   pixel = LOOKUP(color[RCOMP], color[GCOMP], color[BCOMP]);
 
3193
   for (i=0;i<n;i++) {
 
3194
      if (mask[i]) {
 
3195
         GLubyte *ptr = PIXELADDR1( xmesa->xm_buffer,x[i],y[i]);
 
3196
         *ptr = pixel;
 
3197
      }
 
3198
   }
 
3199
}
 
3200
 
 
3201
 
 
3202
 
 
3203
/*
 
3204
 * Write an array of identical PF_1BIT pixels to an XImage.
 
3205
 */
 
3206
static void write_pixels_mono_1BIT_ximage( MONO_PIXEL_ARGS )
 
3207
{
 
3208
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
3209
   const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
 
3210
   XMesaImage *img = xmesa->xm_buffer->backimage;
 
3211
   register GLuint i;
 
3212
   SETUP_1BIT;
 
3213
   for (i=0;i<n;i++) {
 
3214
      if (mask[i]) {
 
3215
         XMesaPutPixel( img, x[i], FLIP(xmesa->xm_buffer, y[i]),
 
3216
                        DITHER_1BIT( x[i], y[i], r, g, b ));
 
3217
      }
 
3218
   }
 
3219
}
 
3220
 
 
3221
 
 
3222
/*
 
3223
 * Write an array of identical PF_HPCR pixels to an XImage.
 
3224
 */
 
3225
static void write_pixels_mono_HPCR_ximage( MONO_PIXEL_ARGS )
 
3226
{
 
3227
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
3228
   const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
 
3229
   register GLuint i;
 
3230
   for (i=0;i<n;i++) {
 
3231
      if (mask[i]) {
 
3232
         GLubyte *ptr = PIXELADDR1( xmesa->xm_buffer,x[i],y[i]);
 
3233
         *ptr = DITHER_HPCR( x[i], y[i], r, g, b );
 
3234
      }
 
3235
   }
 
3236
}
 
3237
 
 
3238
 
 
3239
/*
 
3240
 * Write an array of identical 8-bit PF_GRAYSCALE pixels to an XImage.
 
3241
 */
 
3242
static void write_pixels_mono_GRAYSCALE8_ximage( MONO_PIXEL_ARGS )
 
3243
{
 
3244
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
3245
   register GLuint i;
 
3246
   register GLubyte p = GRAY_RGB(color[RCOMP], color[GCOMP], color[BCOMP]);
 
3247
   for (i=0;i<n;i++) {
 
3248
      if (mask[i]) {
 
3249
         GLubyte *ptr = PIXELADDR1( xmesa->xm_buffer,x[i],y[i]);
 
3250
         *ptr = p;
 
3251
      }
 
3252
   }
 
3253
}
 
3254
 
 
3255
 
 
3256
/*
 
3257
 * Write an array of identical PF_DITHER_5R6G5B pixels to an XImage.
 
3258
 */
 
3259
static void write_pixels_mono_DITHER_5R6G5B_ximage( MONO_PIXEL_ARGS )
 
3260
{
 
3261
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
3262
   const int r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
 
3263
   register GLuint i;
 
3264
   for (i=0;i<n;i++) {
 
3265
      if (mask[i]) {
 
3266
         GLushort *ptr = PIXELADDR2( xmesa->xm_buffer, x[i], y[i] );
 
3267
         PACK_TRUEDITHER(*ptr, x[i], y[i], r, g, b);
 
3268
      }
 
3269
   }
 
3270
}
 
3271
 
 
3272
 
 
3273
 
 
3274
/**********************************************************************/
 
3275
/*** Write INDEX SPAN functions                                     ***/
 
3276
/**********************************************************************/
 
3277
 
 
3278
#define INDEX_SPAN_ARGS const GLcontext *ctx,                           \
 
3279
                        GLuint n, GLint x, GLint y, const GLuint index[], \
 
3280
                        const GLubyte mask[]
 
3281
 
 
3282
#define INDEX8_SPAN_ARGS const GLcontext *ctx,                          \
 
3283
                         GLuint n, GLint x, GLint y, const GLubyte index[], \
 
3284
                         const GLubyte mask[]
 
3285
 
 
3286
 
 
3287
/*
 
3288
 * Write a span of CI pixels to a Pixmap.
 
3289
 */
 
3290
static void write_span_index_pixmap( INDEX_SPAN_ARGS )
 
3291
{
 
3292
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
3293
   XMesaDisplay *dpy = xmesa->xm_visual->display;
 
3294
   XMesaDrawable buffer = xmesa->xm_buffer->buffer;
 
3295
   XMesaGC gc = xmesa->xm_buffer->gc;
 
3296
   register GLuint i;
 
3297
   y = FLIP(xmesa->xm_buffer, y);
 
3298
   if (mask) {
 
3299
      for (i=0;i<n;i++,x++) {
 
3300
         if (mask[i]) {
 
3301
            XMesaSetForeground( dpy, gc, (unsigned long) index[i] );
 
3302
            XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
 
3303
         }
 
3304
      }
 
3305
   }
 
3306
   else {
 
3307
      for (i=0;i<n;i++,x++) {
 
3308
         XMesaSetForeground( dpy, gc, (unsigned long) index[i] );
 
3309
         XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
 
3310
      }
 
3311
   }
 
3312
}
 
3313
 
 
3314
 
 
3315
/*
 
3316
 * Write a span of 8-bit CI pixels to a Pixmap.
 
3317
 */
 
3318
static void write_span_index8_pixmap( INDEX8_SPAN_ARGS )
 
3319
{
 
3320
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
3321
   XMesaDisplay *dpy = xmesa->xm_visual->display;
 
3322
   XMesaDrawable buffer = xmesa->xm_buffer->buffer;
 
3323
   XMesaGC gc = xmesa->xm_buffer->gc;
 
3324
   register GLuint i;
 
3325
   y = FLIP(xmesa->xm_buffer, y);
 
3326
   if (mask) {
 
3327
      for (i=0;i<n;i++,x++) {
 
3328
         if (mask[i]) {
 
3329
            XMesaSetForeground( dpy, gc, (unsigned long) index[i] );
 
3330
            XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
 
3331
         }
 
3332
      }
 
3333
   }
 
3334
   else {
 
3335
      for (i=0;i<n;i++,x++) {
 
3336
         XMesaSetForeground( dpy, gc, (unsigned long) index[i] );
 
3337
         XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
 
3338
      }
 
3339
   }
 
3340
}
 
3341
 
 
3342
 
 
3343
/*
 
3344
 * Write a span of CI pixels to an XImage.
 
3345
 */
 
3346
static void write_span_index_ximage( INDEX_SPAN_ARGS )
 
3347
{
 
3348
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
3349
   XMesaImage *img = xmesa->xm_buffer->backimage;
 
3350
   register GLuint i;
 
3351
   y = FLIP(xmesa->xm_buffer, y);
 
3352
   if (mask) {
 
3353
      for (i=0;i<n;i++,x++) {
 
3354
         if (mask[i]) {
 
3355
            XMesaPutPixel( img, x, y, (unsigned long) index[i] );
 
3356
         }
 
3357
      }
 
3358
   }
 
3359
   else {
 
3360
      for (i=0;i<n;i++,x++) {
 
3361
         XMesaPutPixel( img, x, y, (unsigned long) index[i] );
 
3362
      }
 
3363
   }
 
3364
}
 
3365
 
 
3366
 
 
3367
/*
 
3368
 * Write a span of 8-bit CI pixels to a non 8-bit XImage.
 
3369
 */
 
3370
static void write_span_index8_ximage( const GLcontext *ctx, GLuint n,
 
3371
                                      GLint x, GLint y, const GLubyte index[],
 
3372
                                      const GLubyte mask[] )
 
3373
{
 
3374
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
3375
   if (mask) {
 
3376
      GLuint i;
 
3377
      for (i=0;i<n;i++) {
 
3378
         if (mask[i]) {
 
3379
            XMesaPutPixel(xmesa->xm_buffer->backimage, x+i, y, index[i]);
 
3380
         }
 
3381
      }
 
3382
   }
 
3383
   else {
 
3384
      GLuint i;
 
3385
      for (i=0;i<n;i++) {
 
3386
         XMesaPutPixel(xmesa->xm_buffer->backimage, x+i, y, index[i]);
 
3387
      }
 
3388
   }
 
3389
}
 
3390
 
 
3391
/*
 
3392
 * Write a span of 8-bit CI pixels to an 8-bit XImage.
 
3393
 */
 
3394
static void write_span_index8_ximage8( const GLcontext *ctx, GLuint n,
 
3395
                                      GLint x, GLint y, const GLubyte index[],
 
3396
                                      const GLubyte mask[] )
 
3397
{
 
3398
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
3399
   GLubyte *dst = PIXELADDR1( xmesa->xm_buffer,x,y);
 
3400
   if (mask) {
 
3401
      GLuint i;
 
3402
      for (i=0;i<n;i++) {
 
3403
         if (mask[i]) {
 
3404
            dst[i] = index[i];
 
3405
         }
 
3406
      }
 
3407
   }
 
3408
   else {
 
3409
      MEMCPY( dst, index, n );
 
3410
   }
 
3411
}
 
3412
 
 
3413
 
 
3414
 
 
3415
/**********************************************************************/
 
3416
/*** Write INDEX PIXELS functions                                   ***/
 
3417
/**********************************************************************/
 
3418
 
 
3419
#define INDEX_PIXELS_ARGS       const GLcontext *ctx,                   \
 
3420
                                GLuint n, const GLint x[], const GLint y[], \
 
3421
                                const GLuint index[], const GLubyte mask[]
 
3422
 
 
3423
 
 
3424
/*
 
3425
 * Write an array of CI pixels to a Pixmap.
 
3426
 */
 
3427
static void write_pixels_index_pixmap( INDEX_PIXELS_ARGS )
 
3428
{
 
3429
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
3430
   XMesaDisplay *dpy = xmesa->xm_visual->display;
 
3431
   XMesaDrawable buffer = xmesa->xm_buffer->buffer;
 
3432
   XMesaGC gc = xmesa->xm_buffer->gc;
 
3433
   register GLuint i;
 
3434
   for (i=0;i<n;i++) {
 
3435
      if (mask[i]) {
 
3436
         XMesaSetForeground( dpy, gc, (unsigned long) index[i] );
 
3437
         XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) FLIP(xmesa->xm_buffer, y[i]) );
 
3438
      }
 
3439
   }
 
3440
}
 
3441
 
 
3442
 
 
3443
/*
 
3444
 * Write an array of CI pixels to an XImage.
 
3445
 */
 
3446
static void write_pixels_index_ximage( INDEX_PIXELS_ARGS )
 
3447
{
 
3448
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
3449
   XMesaImage *img = xmesa->xm_buffer->backimage;
 
3450
   register GLuint i;
 
3451
   for (i=0;i<n;i++) {
 
3452
      if (mask[i]) {
 
3453
         XMesaPutPixel( img, x[i], FLIP(xmesa->xm_buffer, y[i]), (unsigned long) index[i] );
 
3454
      }
 
3455
   }
 
3456
}
 
3457
 
 
3458
 
 
3459
 
 
3460
 
 
3461
/**********************************************************************/
 
3462
/*****                      Pixel reading                         *****/
 
3463
/**********************************************************************/
 
3464
 
 
3465
 
 
3466
 
 
3467
/*
 
3468
 * Read a horizontal span of color-index pixels.
 
3469
 */
 
3470
static void read_index_span( const GLcontext *ctx,
 
3471
                             GLuint n, GLint x, GLint y, GLuint index[] )
 
3472
{
 
3473
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
3474
   XMesaBuffer source;
 
3475
   GLuint i;
 
3476
 
 
3477
   if (xmesa->use_read_buffer)
 
3478
      source = xmesa->xm_read_buffer;
 
3479
   else
 
3480
      source = xmesa->xm_buffer;
 
3481
 
 
3482
   y = FLIP(source, y);
 
3483
 
 
3484
   if (source->buffer) {
 
3485
#ifndef XFree86Server
 
3486
      XMesaImage *span = NULL;
 
3487
      int error;
 
3488
      catch_xgetimage_errors( xmesa->display );
 
3489
      span = XGetImage( xmesa->display, source->buffer,
 
3490
                        x, y, n, 1, AllPlanes, ZPixmap );
 
3491
      error = check_xgetimage_errors();
 
3492
      if (span && !error) {
 
3493
         for (i=0;i<n;i++) {
 
3494
            index[i] = (GLuint) XMesaGetPixel( span, i, 0 );
 
3495
         }
 
3496
      }
 
3497
      else {
 
3498
         /* return 0 pixels */
 
3499
         for (i=0;i<n;i++) {
 
3500
            index[i] = 0;
 
3501
         }
 
3502
      }
 
3503
      if (span) {
 
3504
         XMesaDestroyImage( span );
 
3505
      }
 
3506
#else
 
3507
      (*xmesa->display->GetImage)(source->buffer,
 
3508
                                  x, y, n, 1, ZPixmap,
 
3509
                                  ~0L, (pointer)index);
 
3510
#endif
 
3511
   }
 
3512
   else if (source->backimage) {
 
3513
      XMesaImage *img = source->backimage;
 
3514
      for (i=0;i<n;i++,x++) {
 
3515
         index[i] = (GLuint) XMesaGetPixel( img, x, y );
 
3516
      }
 
3517
   }
 
3518
}
 
3519
 
 
3520
 
 
3521
 
 
3522
/*
 
3523
 * Read a horizontal span of color pixels.
 
3524
 */
 
3525
static void read_color_span( const GLcontext *ctx,
 
3526
                             GLuint n, GLint x, GLint y,
 
3527
                             GLubyte rgba[][4] )
 
3528
{
 
3529
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
3530
   XMesaBuffer source;
 
3531
 
 
3532
   if (xmesa->use_read_buffer)
 
3533
      source = xmesa->xm_read_buffer;
 
3534
   else
 
3535
      source = xmesa->xm_buffer;
 
3536
 
 
3537
   if (source->buffer) {
 
3538
      /* Read from Pixmap or Window */
 
3539
      XMesaImage *span = NULL;
 
3540
      int error;
 
3541
#ifdef XFree86Server
 
3542
      span = XMesaCreateImage(xmesa->xm_visual->BitsPerPixel, n, 1, NULL);
 
3543
      span->data = (char *)MALLOC(span->height * span->bytes_per_line);
 
3544
      error = (!span->data);
 
3545
      (*xmesa->display->GetImage)(source->buffer,
 
3546
                                  x, FLIP(source, y), n, 1, ZPixmap,
 
3547
                                  ~0L, (pointer)span->data);
 
3548
#else
 
3549
      catch_xgetimage_errors( xmesa->display );
 
3550
      span = XGetImage( xmesa->display, source->buffer,
 
3551
                        x, FLIP(source, y), n, 1, AllPlanes, ZPixmap );
 
3552
      error = check_xgetimage_errors();
 
3553
#endif
 
3554
      if (span && !error) {
 
3555
         switch (xmesa->pixelformat) {
 
3556
            case PF_TRUECOLOR:
 
3557
            case PF_TRUEDITHER:
 
3558
               {
 
3559
                  const GLubyte *pixelToR = xmesa->xm_visual->PixelToR;
 
3560
                  const GLubyte *pixelToG = xmesa->xm_visual->PixelToG;
 
3561
                  const GLubyte *pixelToB = xmesa->xm_visual->PixelToB;
 
3562
                  unsigned long rMask = GET_REDMASK(xmesa->xm_visual);
 
3563
                  unsigned long gMask = GET_GREENMASK(xmesa->xm_visual);
 
3564
                  unsigned long bMask = GET_BLUEMASK(xmesa->xm_visual);
 
3565
                  GLint rShift = xmesa->xm_visual->rshift;
 
3566
                  GLint gShift = xmesa->xm_visual->gshift;
 
3567
                  GLint bShift = xmesa->xm_visual->bshift;
 
3568
                  GLuint i;
 
3569
                  for (i=0;i<n;i++) {
 
3570
                     unsigned long p;
 
3571
                     p = XMesaGetPixel( span, i, 0 );
 
3572
                     rgba[i][RCOMP] = pixelToR[(p & rMask) >> rShift];
 
3573
                     rgba[i][GCOMP] = pixelToG[(p & gMask) >> gShift];
 
3574
                     rgba[i][BCOMP] = pixelToB[(p & bMask) >> bShift];
 
3575
                     rgba[i][ACOMP] = 255;
 
3576
                  }
 
3577
               }
 
3578
               break;
 
3579
            case PF_5R6G5B:
 
3580
            case PF_DITHER_5R6G5B:
 
3581
               {
 
3582
                  const GLubyte *pixelToR = xmesa->xm_visual->PixelToR;
 
3583
                  const GLubyte *pixelToG = xmesa->xm_visual->PixelToG;
 
3584
                  const GLubyte *pixelToB = xmesa->xm_visual->PixelToB;
 
3585
                  GLuint i;
 
3586
                  for (i=0;i<n;i++) {
 
3587
                     unsigned long p = XMesaGetPixel( span, i, 0 );
 
3588
                     /* fast, but not quite accurate
 
3589
                     rgba[i][RCOMP] = ((p >> 8) & 0xf8);
 
3590
                     rgba[i][GCOMP] = ((p >> 3) & 0xfc);
 
3591
                     rgba[i][BCOMP] = ((p << 3) & 0xff);
 
3592
                     */
 
3593
                     rgba[i][RCOMP] = pixelToR[p >> 11];
 
3594
                     rgba[i][GCOMP] = pixelToG[(p >> 5) & 0x3f];
 
3595
                     rgba[i][BCOMP] = pixelToB[p & 0x1f];
 
3596
                     rgba[i][ACOMP] = 255;
 
3597
                  }
 
3598
               }
 
3599
               break;
 
3600
            case PF_8A8B8G8R:
 
3601
               {
 
3602
                  const GLuint *ptr4 = (GLuint *) span->data;
 
3603
                  GLuint i;
 
3604
                  for (i=0;i<n;i++) {
 
3605
                     GLuint p4 = *ptr4++;
 
3606
                     rgba[i][RCOMP] = (GLubyte) ( p4        & 0xff);
 
3607
                     rgba[i][GCOMP] = (GLubyte) ((p4 >> 8)  & 0xff);
 
3608
                     rgba[i][BCOMP] = (GLubyte) ((p4 >> 16) & 0xff);
 
3609
                     rgba[i][ACOMP] = (GLubyte) ((p4 >> 24) & 0xff);
 
3610
                  }
 
3611
               }
 
3612
               break;
 
3613
            case PF_8R8G8B:
 
3614
               {
 
3615
                  const GLuint *ptr4 = (GLuint *) span->data;
 
3616
                  GLuint i;
 
3617
                  for (i=0;i<n;i++) {
 
3618
                     GLuint p4 = *ptr4++;
 
3619
                     rgba[i][RCOMP] = (GLubyte) ((p4 >> 16) & 0xff);
 
3620
                     rgba[i][GCOMP] = (GLubyte) ((p4 >> 8)  & 0xff);
 
3621
                     rgba[i][BCOMP] = (GLubyte) ( p4        & 0xff);
 
3622
                     rgba[i][ACOMP] = 255;
 
3623
                  }
 
3624
               }
 
3625
               break;
 
3626
            case PF_8R8G8B24:
 
3627
               {
 
3628
                  const bgr_t *ptr3 = (bgr_t *) span->data;
 
3629
                  GLuint i;
 
3630
                  for (i=0;i<n;i++) {
 
3631
                     rgba[i][RCOMP] = ptr3[i].r;
 
3632
                     rgba[i][GCOMP] = ptr3[i].g;
 
3633
                     rgba[i][BCOMP] = ptr3[i].b;
 
3634
                     rgba[i][ACOMP] = 255;
 
3635
                  }
 
3636
               }
 
3637
               break;
 
3638
            case PF_HPCR:
 
3639
               {
 
3640
                  GLubyte *ptr1 = (GLubyte *) span->data;
 
3641
                  GLuint i;
 
3642
                  for (i=0;i<n;i++) {
 
3643
                     GLubyte p = *ptr1++;
 
3644
                     rgba[i][RCOMP] =  p & 0xE0;
 
3645
                     rgba[i][GCOMP] = (p & 0x1C) << 3;
 
3646
                     rgba[i][BCOMP] = (p & 0x03) << 6;
 
3647
                     rgba[i][ACOMP] = 255;
 
3648
                  }
 
3649
               }
 
3650
               break;
 
3651
            case PF_DITHER:
 
3652
            case PF_LOOKUP:
 
3653
            case PF_GRAYSCALE:
 
3654
               {
 
3655
                  GLubyte *rTable = source->pixel_to_r;
 
3656
                  GLubyte *gTable = source->pixel_to_g;
 
3657
                  GLubyte *bTable = source->pixel_to_b;
 
3658
                  if (GET_VISUAL_DEPTH(xmesa->xm_visual)==8) {
 
3659
                     const GLubyte *ptr1 = (GLubyte *) span->data;
 
3660
                     GLuint i;
 
3661
                     for (i=0;i<n;i++) {
 
3662
                        unsigned long p = *ptr1++;
 
3663
                        rgba[i][RCOMP] = rTable[p];
 
3664
                        rgba[i][GCOMP] = gTable[p];
 
3665
                        rgba[i][BCOMP] = bTable[p];
 
3666
                        rgba[i][ACOMP] = 255;
 
3667
                     }
 
3668
                  }
 
3669
                  else {
 
3670
                     GLuint i;
 
3671
                     for (i=0;i<n;i++) {
 
3672
                        unsigned long p = XMesaGetPixel( span, i, 0 );
 
3673
                        rgba[i][RCOMP] = rTable[p];
 
3674
                        rgba[i][GCOMP] = gTable[p];
 
3675
                        rgba[i][BCOMP] = bTable[p];
 
3676
                        rgba[i][ACOMP] = 255;
 
3677
                     }
 
3678
                  }
 
3679
               }
 
3680
               break;
 
3681
            case PF_1BIT:
 
3682
               {
 
3683
                  int bitFlip = xmesa->xm_visual->bitFlip;
 
3684
                  GLuint i;
 
3685
                  for (i=0;i<n;i++) {
 
3686
                     unsigned long p;
 
3687
                     p = XMesaGetPixel( span, i, 0 ) ^ bitFlip;
 
3688
                     rgba[i][RCOMP] = (GLubyte) (p * 255);
 
3689
                     rgba[i][GCOMP] = (GLubyte) (p * 255);
 
3690
                     rgba[i][BCOMP] = (GLubyte) (p * 255);
 
3691
                     rgba[i][ACOMP] = 255;
 
3692
                  }
 
3693
               }
 
3694
               break;
 
3695
            default:
 
3696
               _mesa_problem(NULL,"Problem in DD.read_color_span (1)");
 
3697
               return;
 
3698
         }
 
3699
      }
 
3700
      else {
 
3701
         /* return black pixels */
 
3702
         GLuint i;
 
3703
         for (i=0;i<n;i++) {
 
3704
            rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = rgba[i][ACOMP] = 0;
 
3705
         }
 
3706
      }
 
3707
      if (span) {
 
3708
         XMesaDestroyImage( span );
 
3709
      }
 
3710
   }
 
3711
   else if (source->backimage) {
 
3712
      /* Read from XImage back buffer */
 
3713
      switch (xmesa->pixelformat) {
 
3714
         case PF_TRUECOLOR:
 
3715
         case PF_TRUEDITHER:
 
3716
            {
 
3717
               const GLubyte *pixelToR = xmesa->xm_visual->PixelToR;
 
3718
               const GLubyte *pixelToG = xmesa->xm_visual->PixelToG;
 
3719
               const GLubyte *pixelToB = xmesa->xm_visual->PixelToB;
 
3720
               unsigned long rMask = GET_REDMASK(xmesa->xm_visual);
 
3721
               unsigned long gMask = GET_GREENMASK(xmesa->xm_visual);
 
3722
               unsigned long bMask = GET_BLUEMASK(xmesa->xm_visual);
 
3723
               GLint rShift = xmesa->xm_visual->rshift;
 
3724
               GLint gShift = xmesa->xm_visual->gshift;
 
3725
               GLint bShift = xmesa->xm_visual->bshift;
 
3726
               XMesaImage *img = source->backimage;
 
3727
               GLuint i;
 
3728
               y = FLIP(source, y);
 
3729
               for (i=0;i<n;i++) {
 
3730
                  unsigned long p;
 
3731
                  p = XMesaGetPixel( img, x+i, y );
 
3732
                  rgba[i][RCOMP] = pixelToR[(p & rMask) >> rShift];
 
3733
                  rgba[i][GCOMP] = pixelToG[(p & gMask) >> gShift];
 
3734
                  rgba[i][BCOMP] = pixelToB[(p & bMask) >> bShift];
 
3735
                  rgba[i][ACOMP] = 255;
 
3736
               }
 
3737
            }
 
3738
            break;
 
3739
         case PF_5R6G5B:
 
3740
         case PF_DITHER_5R6G5B:
 
3741
            {
 
3742
               const GLubyte *pixelToR = xmesa->xm_visual->PixelToR;
 
3743
               const GLubyte *pixelToG = xmesa->xm_visual->PixelToG;
 
3744
               const GLubyte *pixelToB = xmesa->xm_visual->PixelToB;
 
3745
               const GLushort *ptr2 = PIXELADDR2( source, x, y );
 
3746
               GLuint i;
 
3747
#if defined(__i386__) /* word stores don't have to be on 4-byte boundaries */
 
3748
               const GLuint *ptr4 = (const GLuint *) ptr2;
 
3749
               GLuint extraPixel = (n & 1);
 
3750
               n -= extraPixel;
 
3751
               for (i = 0; i < n; i += 2) {
 
3752
                  const GLuint p = *ptr4++;
 
3753
                  const GLuint p0 = p & 0xffff;
 
3754
                  const GLuint p1 = p >> 16;
 
3755
                  /* fast, but not quite accurate
 
3756
                  rgba[i][RCOMP] = ((p >> 8) & 0xf8);
 
3757
                  rgba[i][GCOMP] = ((p >> 3) & 0xfc);
 
3758
                  rgba[i][BCOMP] = ((p << 3) & 0xff);
 
3759
                  */
 
3760
                  rgba[i][RCOMP] = pixelToR[p0 >> 11];
 
3761
                  rgba[i][GCOMP] = pixelToG[(p0 >> 5) & 0x3f];
 
3762
                  rgba[i][BCOMP] = pixelToB[p0 & 0x1f];
 
3763
                  rgba[i][ACOMP] = 255;
 
3764
                  rgba[i+1][RCOMP] = pixelToR[p1 >> 11];
 
3765
                  rgba[i+1][GCOMP] = pixelToG[(p1 >> 5) & 0x3f];
 
3766
                  rgba[i+1][BCOMP] = pixelToB[p1 & 0x1f];
 
3767
                  rgba[i+1][ACOMP] = 255;
 
3768
               }
 
3769
               if (extraPixel) {
 
3770
                  GLushort p = ptr2[n];
 
3771
                  rgba[n][RCOMP] = pixelToR[p >> 11];
 
3772
                  rgba[n][GCOMP] = pixelToG[(p >> 5) & 0x3f];
 
3773
                  rgba[n][BCOMP] = pixelToB[p & 0x1f];
 
3774
                  rgba[n][ACOMP] = 255;
 
3775
               }
 
3776
#else
 
3777
               for (i = 0; i < n; i++) {
 
3778
                  const GLushort p = ptr2[i];
 
3779
                  rgba[i][RCOMP] = pixelToR[p >> 11];
 
3780
                  rgba[i][GCOMP] = pixelToG[(p >> 5) & 0x3f];
 
3781
                  rgba[i][BCOMP] = pixelToB[p & 0x1f];
 
3782
                  rgba[i][ACOMP] = 255;
 
3783
               }
 
3784
#endif
 
3785
            }
 
3786
            break;
 
3787
         case PF_8A8B8G8R:
 
3788
            {
 
3789
               const GLuint *ptr4 = PIXELADDR4( source, x, y );
 
3790
               GLuint i;
 
3791
               for (i=0;i<n;i++) {
 
3792
                  GLuint p4 = *ptr4++;
 
3793
                  rgba[i][RCOMP] = (GLubyte) ( p4        & 0xff);
 
3794
                  rgba[i][GCOMP] = (GLubyte) ((p4 >> 8)  & 0xff);
 
3795
                  rgba[i][BCOMP] = (GLubyte) ((p4 >> 16) & 0xff);
 
3796
                  rgba[i][ACOMP] = (GLint)   ((p4 >> 24) & 0xff);
 
3797
               }
 
3798
            }
 
3799
            break;
 
3800
         case PF_8R8G8B:
 
3801
            {
 
3802
               const GLuint *ptr4 = PIXELADDR4( source, x, y );
 
3803
               GLuint i;
 
3804
               for (i=0;i<n;i++) {
 
3805
                  GLuint p4 = *ptr4++;
 
3806
                  rgba[i][RCOMP] = (GLubyte) ((p4 >> 16) & 0xff);
 
3807
                  rgba[i][GCOMP] = (GLubyte) ((p4 >> 8)  & 0xff);
 
3808
                  rgba[i][BCOMP] = (GLubyte) ( p4        & 0xff);
 
3809
                  rgba[i][ACOMP] = 255;
 
3810
               }
 
3811
            }
 
3812
            break;
 
3813
         case PF_8R8G8B24:
 
3814
            {
 
3815
               const bgr_t *ptr3 = PIXELADDR3( source, x, y );
 
3816
               GLuint i;
 
3817
               for (i=0;i<n;i++) {
 
3818
                  rgba[i][RCOMP] = ptr3[i].r;
 
3819
                  rgba[i][GCOMP] = ptr3[i].g;
 
3820
                  rgba[i][BCOMP] = ptr3[i].b;
 
3821
                  rgba[i][ACOMP] = 255;
 
3822
               }
 
3823
            }
 
3824
            break;
 
3825
         case PF_HPCR:
 
3826
            {
 
3827
               const GLubyte *ptr1 = PIXELADDR1( source, x, y );
 
3828
               GLuint i;
 
3829
               for (i=0;i<n;i++) {
 
3830
                  GLubyte p = *ptr1++;
 
3831
                  rgba[i][RCOMP] =  p & 0xE0;
 
3832
                  rgba[i][GCOMP] = (p & 0x1C) << 3;
 
3833
                  rgba[i][BCOMP] = (p & 0x03) << 6;
 
3834
                  rgba[i][ACOMP] = 255;
 
3835
               }
 
3836
            }
 
3837
            break;
 
3838
         case PF_DITHER:
 
3839
         case PF_LOOKUP:
 
3840
         case PF_GRAYSCALE:
 
3841
            {
 
3842
               const GLubyte *rTable = source->pixel_to_r;
 
3843
               const GLubyte *gTable = source->pixel_to_g;
 
3844
               const GLubyte *bTable = source->pixel_to_b;
 
3845
               if (GET_VISUAL_DEPTH(xmesa->xm_visual)==8) {
 
3846
                  GLubyte *ptr1 = PIXELADDR1( source, x, y );
 
3847
                  GLuint i;
 
3848
                  for (i=0;i<n;i++) {
 
3849
                     unsigned long p = *ptr1++;
 
3850
                     rgba[i][RCOMP] = rTable[p];
 
3851
                     rgba[i][GCOMP] = gTable[p];
 
3852
                     rgba[i][BCOMP] = bTable[p];
 
3853
                     rgba[i][ACOMP] = 255;
 
3854
                  }
 
3855
               }
 
3856
               else {
 
3857
                  XMesaImage *img = source->backimage;
 
3858
                  GLuint i;
 
3859
                  y = FLIP(source, y);
 
3860
                  for (i=0;i<n;i++,x++) {
 
3861
                     unsigned long p = XMesaGetPixel( img, x, y );
 
3862
                     rgba[i][RCOMP] = rTable[p];
 
3863
                     rgba[i][GCOMP] = gTable[p];
 
3864
                     rgba[i][BCOMP] = bTable[p];
 
3865
                     rgba[i][ACOMP] = 255;
 
3866
                  }
 
3867
               }
 
3868
            }
 
3869
            break;
 
3870
         case PF_1BIT:
 
3871
            {
 
3872
               XMesaImage *img = source->backimage;
 
3873
               int bitFlip = xmesa->xm_visual->bitFlip;
 
3874
               GLuint i;
 
3875
               y = FLIP(source, y);
 
3876
               for (i=0;i<n;i++,x++) {
 
3877
                  unsigned long p;
 
3878
                  p = XMesaGetPixel( img, x, y ) ^ bitFlip;
 
3879
                  rgba[i][RCOMP] = (GLubyte) (p * 255);
 
3880
                  rgba[i][GCOMP] = (GLubyte) (p * 255);
 
3881
                  rgba[i][BCOMP] = (GLubyte) (p * 255);
 
3882
                  rgba[i][ACOMP] = 255;
 
3883
               }
 
3884
            }
 
3885
            break;
 
3886
         default:
 
3887
            _mesa_problem(NULL,"Problem in DD.read_color_span (2)");
 
3888
            return;
 
3889
      }
 
3890
   }
 
3891
}
 
3892
 
 
3893
 
 
3894
 
 
3895
/*
 
3896
 * Read an array of color index pixels.
 
3897
 */
 
3898
static void read_index_pixels( const GLcontext *ctx,
 
3899
                               GLuint n, const GLint x[], const GLint y[],
 
3900
                               GLuint indx[], const GLubyte mask[] )
 
3901
{
 
3902
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
3903
   register GLuint i;
 
3904
   XMesaBuffer source;
 
3905
 
 
3906
   if (xmesa->use_read_buffer)
 
3907
      source = xmesa->xm_read_buffer;
 
3908
   else
 
3909
      source = xmesa->xm_buffer;
 
3910
 
 
3911
   if (source->buffer) {
 
3912
      for (i=0;i<n;i++) {
 
3913
         if (mask[i]) {
 
3914
            indx[i] = (GLuint) read_pixel( xmesa->display,
 
3915
                                           source->buffer,
 
3916
                                           x[i], FLIP(source, y[i]) );
 
3917
         }
 
3918
      }
 
3919
   }
 
3920
   else if (source->backimage) {
 
3921
      XMesaImage *img = source->backimage;
 
3922
      for (i=0;i<n;i++) {
 
3923
         if (mask[i]) {
 
3924
            indx[i] = (GLuint) XMesaGetPixel( img, x[i], FLIP(source, y[i]) );
 
3925
         }
 
3926
      }
 
3927
   }
 
3928
}
 
3929
 
 
3930
 
 
3931
 
 
3932
static void read_color_pixels( const GLcontext *ctx,
 
3933
                               GLuint n, const GLint x[], const GLint y[],
 
3934
                               GLubyte rgba[][4], const GLubyte mask[] )
 
3935
{
 
3936
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
3937
   XMesaDisplay *dpy = xmesa->xm_visual->display;
 
3938
   register GLuint i;
 
3939
   XMesaBuffer source;
 
3940
   XMesaDrawable buffer;
 
3941
 
 
3942
   if (xmesa->use_read_buffer)
 
3943
      source = xmesa->xm_read_buffer;
 
3944
   else
 
3945
      source = xmesa->xm_buffer;
 
3946
 
 
3947
   buffer = source->buffer;  /* the X drawable */
 
3948
 
 
3949
   if (source->buffer) {
 
3950
      switch (xmesa->pixelformat) {
 
3951
         case PF_TRUECOLOR:
 
3952
         case PF_TRUEDITHER:
 
3953
         case PF_5R6G5B:
 
3954
         case PF_DITHER_5R6G5B:
 
3955
            {
 
3956
               unsigned long rMask = GET_REDMASK(xmesa->xm_visual);
 
3957
               unsigned long gMask = GET_GREENMASK(xmesa->xm_visual);
 
3958
               unsigned long bMask = GET_BLUEMASK(xmesa->xm_visual);
 
3959
               GLubyte *pixelToR = xmesa->xm_visual->PixelToR;
 
3960
               GLubyte *pixelToG = xmesa->xm_visual->PixelToG;
 
3961
               GLubyte *pixelToB = xmesa->xm_visual->PixelToB;
 
3962
               GLint rShift = xmesa->xm_visual->rshift;
 
3963
               GLint gShift = xmesa->xm_visual->gshift;
 
3964
               GLint bShift = xmesa->xm_visual->bshift;
 
3965
               for (i=0;i<n;i++) {
 
3966
                  if (mask[i]) {
 
3967
                     unsigned long p = read_pixel( dpy, buffer,
 
3968
                                                   x[i], FLIP(source, y[i]) );
 
3969
                     rgba[i][RCOMP] = pixelToR[(p & rMask) >> rShift];
 
3970
                     rgba[i][GCOMP] = pixelToG[(p & gMask) >> gShift];
 
3971
                     rgba[i][BCOMP] = pixelToB[(p & bMask) >> bShift];
 
3972
                     rgba[i][ACOMP] = 255;
 
3973
                  }
 
3974
               }
 
3975
            }
 
3976
            break;
 
3977
         case PF_8A8B8G8R:
 
3978
            for (i=0;i<n;i++) {
 
3979
               if (mask[i]) {
 
3980
                  unsigned long p = read_pixel( dpy, buffer,
 
3981
                                                x[i], FLIP(source, y[i]) );
 
3982
                  rgba[i][RCOMP] = (GLubyte) ( p        & 0xff);
 
3983
                  rgba[i][GCOMP] = (GLubyte) ((p >> 8)  & 0xff);
 
3984
                  rgba[i][BCOMP] = (GLubyte) ((p >> 16) & 0xff);
 
3985
                  rgba[i][ACOMP] = (GLubyte) ((p >> 24) & 0xff);
 
3986
               }
 
3987
            }
 
3988
            break;
 
3989
         case PF_8R8G8B:
 
3990
            for (i=0;i<n;i++) {
 
3991
               if (mask[i]) {
 
3992
                  unsigned long p = read_pixel( dpy, buffer,
 
3993
                                                x[i], FLIP(source, y[i]) );
 
3994
                  rgba[i][RCOMP] = (GLubyte) ((p >> 16) & 0xff);
 
3995
                  rgba[i][GCOMP] = (GLubyte) ((p >> 8)  & 0xff);
 
3996
                  rgba[i][BCOMP] = (GLubyte) ( p        & 0xff);
 
3997
                  rgba[i][ACOMP] = 255;
 
3998
               }
 
3999
            }
 
4000
            break;
 
4001
         case PF_8R8G8B24:
 
4002
            for (i=0;i<n;i++) {
 
4003
               if (mask[i]) {
 
4004
                  unsigned long p = read_pixel( dpy, buffer,
 
4005
                                                x[i], FLIP(source, y[i]) );
 
4006
                  rgba[i][RCOMP] = (GLubyte) ((p >> 16) & 0xff);
 
4007
                  rgba[i][GCOMP] = (GLubyte) ((p >> 8)  & 0xff);
 
4008
                  rgba[i][BCOMP] = (GLubyte) ( p        & 0xff);
 
4009
                  rgba[i][ACOMP] = 255;
 
4010
               }
 
4011
            }
 
4012
            break;
 
4013
         case PF_HPCR:
 
4014
            {
 
4015
               for (i=0;i<n;i++) {
 
4016
                  if (mask[i]) {
 
4017
                     unsigned long p = read_pixel( dpy, buffer,
 
4018
                                                   x[i], FLIP(source, y[i]) );
 
4019
                     rgba[i][RCOMP] = (GLubyte) ( p & 0xE0      );
 
4020
                     rgba[i][GCOMP] = (GLubyte) ((p & 0x1C) << 3);
 
4021
                     rgba[i][BCOMP] = (GLubyte) ((p & 0x03) << 6);
 
4022
                     rgba[i][ACOMP] = (GLubyte) 255;
 
4023
                  }
 
4024
               }
 
4025
            }
 
4026
            break;
 
4027
         case PF_DITHER:
 
4028
         case PF_LOOKUP:
 
4029
         case PF_GRAYSCALE:
 
4030
            {
 
4031
               GLubyte *rTable = source->pixel_to_r;
 
4032
               GLubyte *gTable = source->pixel_to_g;
 
4033
               GLubyte *bTable = source->pixel_to_b;
 
4034
               for (i=0;i<n;i++) {
 
4035
                  if (mask[i]) {
 
4036
                     unsigned long p = read_pixel( dpy, buffer,
 
4037
                                                   x[i], FLIP(source, y[i]) );
 
4038
                     rgba[i][RCOMP] = rTable[p];
 
4039
                     rgba[i][GCOMP] = gTable[p];
 
4040
                     rgba[i][BCOMP] = bTable[p];
 
4041
                     rgba[i][ACOMP] = 255;
 
4042
                  }
 
4043
               }
 
4044
            }
 
4045
            break;
 
4046
         case PF_1BIT:
 
4047
            {
 
4048
               int bitFlip = xmesa->xm_visual->bitFlip;
 
4049
               for (i=0;i<n;i++) {
 
4050
                  if (mask[i]) {
 
4051
                     unsigned long p = read_pixel( dpy, buffer,
 
4052
                                     x[i], FLIP(source, y[i])) ^ bitFlip;
 
4053
                     rgba[i][RCOMP] = (GLubyte) (p * 255);
 
4054
                     rgba[i][GCOMP] = (GLubyte) (p * 255);
 
4055
                     rgba[i][BCOMP] = (GLubyte) (p * 255);
 
4056
                     rgba[i][ACOMP] = 255;
 
4057
                  }
 
4058
               }
 
4059
            }
 
4060
            break;
 
4061
         default:
 
4062
            _mesa_problem(NULL,"Problem in DD.read_color_pixels (1)");
 
4063
            return;
 
4064
      }
 
4065
   }
 
4066
   else if (source->backimage) {
 
4067
      switch (xmesa->pixelformat) {
 
4068
         case PF_TRUECOLOR:
 
4069
         case PF_TRUEDITHER:
 
4070
         case PF_5R6G5B:
 
4071
         case PF_DITHER_5R6G5B:
 
4072
            {
 
4073
               unsigned long rMask = GET_REDMASK(xmesa->xm_visual);
 
4074
               unsigned long gMask = GET_GREENMASK(xmesa->xm_visual);
 
4075
               unsigned long bMask = GET_BLUEMASK(xmesa->xm_visual);
 
4076
               GLubyte *pixelToR = xmesa->xm_visual->PixelToR;
 
4077
               GLubyte *pixelToG = xmesa->xm_visual->PixelToG;
 
4078
               GLubyte *pixelToB = xmesa->xm_visual->PixelToB;
 
4079
               GLint rShift = xmesa->xm_visual->rshift;
 
4080
               GLint gShift = xmesa->xm_visual->gshift;
 
4081
               GLint bShift = xmesa->xm_visual->bshift;
 
4082
               XMesaImage *img = source->backimage;
 
4083
               for (i=0;i<n;i++) {
 
4084
                  if (mask[i]) {
 
4085
                     unsigned long p;
 
4086
                     p = XMesaGetPixel( img, x[i], FLIP(source, y[i]) );
 
4087
                     rgba[i][RCOMP] = pixelToR[(p & rMask) >> rShift];
 
4088
                     rgba[i][GCOMP] = pixelToG[(p & gMask) >> gShift];
 
4089
                     rgba[i][BCOMP] = pixelToB[(p & bMask) >> bShift];
 
4090
                     rgba[i][ACOMP] = 255;
 
4091
                  }
 
4092
               }
 
4093
            }
 
4094
            break;
 
4095
         case PF_8A8B8G8R:
 
4096
            for (i=0;i<n;i++) {
 
4097
               if (mask[i]) {
 
4098
                  GLuint *ptr4 = PIXELADDR4( source, x[i], y[i] );
 
4099
                  GLuint p4 = *ptr4;
 
4100
                  rgba[i][RCOMP] = (GLubyte) ( p4        & 0xff);
 
4101
                  rgba[i][GCOMP] = (GLubyte) ((p4 >> 8)  & 0xff);
 
4102
                  rgba[i][BCOMP] = (GLubyte) ((p4 >> 16) & 0xff);
 
4103
                  rgba[i][ACOMP] = (GLubyte) ((p4 >> 24) & 0xff);
 
4104
               }
 
4105
            }
 
4106
            break;
 
4107
         case PF_8R8G8B:
 
4108
            for (i=0;i<n;i++) {
 
4109
               if (mask[i]) {
 
4110
                  GLuint *ptr4 = PIXELADDR4( source, x[i], y[i] );
 
4111
                  GLuint p4 = *ptr4;
 
4112
                  rgba[i][RCOMP] = (GLubyte) ((p4 >> 16) & 0xff);
 
4113
                  rgba[i][GCOMP] = (GLubyte) ((p4 >> 8)  & 0xff);
 
4114
                  rgba[i][BCOMP] = (GLubyte) ( p4        & 0xff);
 
4115
                  rgba[i][ACOMP] = 255;
 
4116
               }
 
4117
            }
 
4118
            break;
 
4119
         case PF_8R8G8B24:
 
4120
            for (i=0;i<n;i++) {
 
4121
               if (mask[i]) {
 
4122
                  bgr_t *ptr3 = PIXELADDR3( source, x[i], y[i] );
 
4123
                  rgba[i][RCOMP] = ptr3->r;
 
4124
                  rgba[i][GCOMP] = ptr3->g;
 
4125
                  rgba[i][BCOMP] = ptr3->b;
 
4126
                  rgba[i][ACOMP] = 255;
 
4127
               }
 
4128
            }
 
4129
            break;
 
4130
         case PF_HPCR:
 
4131
            for (i=0;i<n;i++) {
 
4132
               if (mask[i]) {
 
4133
                  GLubyte *ptr1 = PIXELADDR1( source, x[i], y[i] );
 
4134
                  GLubyte p = *ptr1;
 
4135
                  rgba[i][RCOMP] =  p & 0xE0;
 
4136
                  rgba[i][GCOMP] = (p & 0x1C) << 3;
 
4137
                  rgba[i][BCOMP] = (p & 0x03) << 6;
 
4138
                  rgba[i][ACOMP] = 255;
 
4139
               }
 
4140
            }
 
4141
            break;
 
4142
         case PF_DITHER:
 
4143
         case PF_LOOKUP:
 
4144
         case PF_GRAYSCALE:
 
4145
            {
 
4146
               GLubyte *rTable = source->pixel_to_r;
 
4147
               GLubyte *gTable = source->pixel_to_g;
 
4148
               GLubyte *bTable = source->pixel_to_b;
 
4149
               XMesaImage *img = source->backimage;
 
4150
               for (i=0;i<n;i++) {
 
4151
                  if (mask[i]) {
 
4152
                     unsigned long p;
 
4153
                     p = XMesaGetPixel( img, x[i], FLIP(source, y[i]) );
 
4154
                     rgba[i][RCOMP] = rTable[p];
 
4155
                     rgba[i][GCOMP] = gTable[p];
 
4156
                     rgba[i][BCOMP] = bTable[p];
 
4157
                     rgba[i][ACOMP] = 255;
 
4158
                  }
 
4159
               }
 
4160
            }
 
4161
            break;
 
4162
         case PF_1BIT:
 
4163
            {
 
4164
               XMesaImage *img = source->backimage;
 
4165
               int bitFlip = xmesa->xm_visual->bitFlip;
 
4166
               for (i=0;i<n;i++) {
 
4167
                  if (mask[i]) {
 
4168
                     unsigned long p;
 
4169
                     p = XMesaGetPixel( img, x[i], FLIP(source, y[i]) ) ^ bitFlip;
 
4170
                     rgba[i][RCOMP] = (GLubyte) (p * 255);
 
4171
                     rgba[i][GCOMP] = (GLubyte) (p * 255);
 
4172
                     rgba[i][BCOMP] = (GLubyte) (p * 255);
 
4173
                     rgba[i][ACOMP] = 255;
 
4174
                  }
 
4175
               }
 
4176
            }
 
4177
            break;
 
4178
         default:
 
4179
            _mesa_problem(NULL,"Problem in DD.read_color_pixels (1)");
 
4180
            return;
 
4181
      }
 
4182
   }
 
4183
}
 
4184
 
 
4185
 
 
4186
static void
 
4187
clear_color_HPCR_ximage( GLcontext *ctx, const GLchan color[4] )
 
4188
{
 
4189
   int i;
 
4190
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
4191
 
 
4192
   COPY_4V(xmesa->clearcolor, color);
 
4193
 
 
4194
   if (color[0] == 0 && color[1] == 0 && color[2] == 0) {
 
4195
      /* black is black */
 
4196
      MEMSET( xmesa->xm_visual->hpcr_clear_ximage_pattern, 0x0 ,
 
4197
              sizeof(xmesa->xm_visual->hpcr_clear_ximage_pattern));
 
4198
   }
 
4199
   else {
 
4200
      /* build clear pattern */
 
4201
      for (i=0; i<16; i++) {
 
4202
         xmesa->xm_visual->hpcr_clear_ximage_pattern[0][i]    =
 
4203
            DITHER_HPCR(i, 0, color[0], color[1], color[2]);
 
4204
         xmesa->xm_visual->hpcr_clear_ximage_pattern[1][i]    =
 
4205
            DITHER_HPCR(i, 1, color[0], color[1], color[2]);
 
4206
      }
 
4207
   }
 
4208
}
 
4209
 
 
4210
 
 
4211
static void
 
4212
clear_color_HPCR_pixmap( GLcontext *ctx, const GLchan color[4] )
 
4213
{
 
4214
   int i;
 
4215
   const XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
4216
 
 
4217
   COPY_4V(xmesa->clearcolor, color);
 
4218
 
 
4219
   if (color[0] == 0 && color[1] == 0 && color[2] == 0) {
 
4220
      /* black is black */
 
4221
      for (i=0; i<16; i++) {
 
4222
         XMesaPutPixel(xmesa->xm_visual->hpcr_clear_ximage, i, 0, 0);
 
4223
         XMesaPutPixel(xmesa->xm_visual->hpcr_clear_ximage, i, 1, 0);
 
4224
      }
 
4225
   }
 
4226
   else {
 
4227
      for (i=0; i<16; i++) {
 
4228
         XMesaPutPixel(xmesa->xm_visual->hpcr_clear_ximage, i, 0,
 
4229
                       DITHER_HPCR(i, 0, color[0], color[1], color[2]));
 
4230
         XMesaPutPixel(xmesa->xm_visual->hpcr_clear_ximage, i, 1,
 
4231
                       DITHER_HPCR(i, 1, color[0], color[1], color[2]));
 
4232
      }
 
4233
   }
 
4234
   /* change tile pixmap content */
 
4235
   XMesaPutImage(xmesa->display,
 
4236
                 (XMesaDrawable)xmesa->xm_visual->hpcr_clear_pixmap,
 
4237
                 xmesa->xm_buffer->cleargc,
 
4238
                 xmesa->xm_visual->hpcr_clear_ximage, 0, 0, 0, 0, 16, 2);
 
4239
}
 
4240
 
 
4241
 
 
4242
 
 
4243
void xmesa_update_span_funcs( GLcontext *ctx )
 
4244
{
 
4245
   XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
 
4246
   int depth=GET_VISUAL_DEPTH(xmesa->xm_visual);
 
4247
   struct swrast_device_driver *dd = _swrast_GetDeviceDriverReference( ctx );
 
4248
 
 
4249
   /*
 
4250
    * These drawing functions depend on color buffer config:
 
4251
    */
 
4252
   if (xmesa->xm_buffer->buffer!=XIMAGE) {
 
4253
      /* Writing to window or back pixmap */
 
4254
      switch (xmesa->pixelformat) {
 
4255
         case PF_INDEX:
 
4256
            dd->WriteCI32Span     = write_span_index_pixmap;
 
4257
            dd->WriteCI8Span      = write_span_index8_pixmap;
 
4258
            dd->WriteMonoCISpan   = write_span_mono_index_pixmap;
 
4259
            dd->WriteCI32Pixels   = write_pixels_index_pixmap;
 
4260
            dd->WriteMonoCIPixels = write_pixels_mono_index_pixmap;
 
4261
            break;
 
4262
         case PF_TRUECOLOR:
 
4263
            dd->WriteRGBASpan       = write_span_TRUECOLOR_pixmap;
 
4264
            dd->WriteRGBSpan        = write_span_rgb_TRUECOLOR_pixmap;
 
4265
            dd->WriteMonoRGBASpan   = write_span_mono_pixmap;
 
4266
            dd->WriteRGBAPixels     = write_pixels_TRUECOLOR_pixmap;
 
4267
            dd->WriteMonoRGBAPixels = write_pixels_mono_pixmap;
 
4268
            break;
 
4269
         case PF_TRUEDITHER:
 
4270
            dd->WriteRGBASpan       = write_span_TRUEDITHER_pixmap;
 
4271
            dd->WriteRGBSpan        = write_span_rgb_TRUEDITHER_pixmap;
 
4272
            dd->WriteMonoRGBASpan   = write_span_mono_TRUEDITHER_pixmap;
 
4273
            dd->WriteRGBAPixels     = write_pixels_TRUEDITHER_pixmap;
 
4274
            dd->WriteMonoRGBAPixels = write_pixels_mono_TRUEDITHER_pixmap;
 
4275
            break;
 
4276
         case PF_8A8B8G8R:
 
4277
            dd->WriteRGBASpan       = write_span_8A8B8G8R_pixmap;
 
4278
            dd->WriteRGBSpan        = write_span_rgb_8A8B8G8R_pixmap;
 
4279
            dd->WriteMonoRGBASpan   = write_span_mono_pixmap;
 
4280
            dd->WriteRGBAPixels     = write_pixels_8A8B8G8R_pixmap;
 
4281
            dd->WriteMonoRGBAPixels = write_pixels_mono_pixmap;
 
4282
            break;
 
4283
         case PF_8R8G8B:
 
4284
            dd->WriteRGBASpan       = write_span_8R8G8B_pixmap;
 
4285
            dd->WriteRGBSpan        = write_span_rgb_8R8G8B_pixmap;
 
4286
            dd->WriteMonoRGBASpan   = write_span_mono_pixmap;
 
4287
            dd->WriteRGBAPixels     = write_pixels_8R8G8B_pixmap;
 
4288
            dd->WriteMonoRGBAPixels = write_pixels_mono_pixmap;
 
4289
            break;
 
4290
         case PF_8R8G8B24:
 
4291
            dd->WriteRGBASpan       = write_span_8R8G8B24_pixmap;
 
4292
            dd->WriteRGBSpan        = write_span_rgb_8R8G8B24_pixmap;
 
4293
            dd->WriteMonoRGBASpan   = write_span_mono_pixmap;
 
4294
            dd->WriteRGBAPixels     = write_pixels_8R8G8B24_pixmap;
 
4295
            dd->WriteMonoRGBAPixels = write_pixels_mono_pixmap;
 
4296
            break;
 
4297
         case PF_5R6G5B:
 
4298
            dd->WriteRGBASpan       = write_span_5R6G5B_pixmap;
 
4299
            dd->WriteRGBSpan        = write_span_rgb_5R6G5B_pixmap;
 
4300
            dd->WriteMonoRGBASpan   = write_span_mono_pixmap;
 
4301
            dd->WriteRGBAPixels     = write_pixels_5R6G5B_pixmap;
 
4302
            dd->WriteMonoRGBAPixels = write_pixels_mono_pixmap;
 
4303
            break;
 
4304
         case PF_DITHER_5R6G5B:
 
4305
            dd->WriteRGBASpan       = write_span_DITHER_5R6G5B_pixmap;
 
4306
            dd->WriteRGBSpan        = write_span_rgb_DITHER_5R6G5B_pixmap;
 
4307
            dd->WriteMonoRGBASpan   = write_span_mono_TRUEDITHER_pixmap;
 
4308
            dd->WriteRGBAPixels     = write_pixels_DITHER_5R6G5B_pixmap;
 
4309
            dd->WriteMonoRGBAPixels = write_pixels_mono_TRUEDITHER_pixmap;
 
4310
            break;
 
4311
         case PF_DITHER:
 
4312
            dd->WriteRGBASpan       = write_span_DITHER_pixmap;
 
4313
            dd->WriteRGBSpan        = write_span_rgb_DITHER_pixmap;
 
4314
            dd->WriteMonoRGBASpan   = write_span_mono_DITHER_pixmap;
 
4315
            dd->WriteRGBAPixels     = write_pixels_DITHER_pixmap;
 
4316
            dd->WriteMonoRGBAPixels = write_pixels_mono_DITHER_pixmap;
 
4317
            break;
 
4318
         case PF_1BIT:
 
4319
            dd->WriteRGBASpan       = write_span_1BIT_pixmap;
 
4320
            dd->WriteRGBSpan        = write_span_rgb_1BIT_pixmap;
 
4321
            dd->WriteMonoRGBASpan   = write_span_mono_1BIT_pixmap;
 
4322
            dd->WriteRGBAPixels     = write_pixels_1BIT_pixmap;
 
4323
            dd->WriteMonoRGBAPixels = write_pixels_mono_1BIT_pixmap;
 
4324
            break;
 
4325
         case PF_HPCR:
 
4326
            dd->WriteRGBASpan       = write_span_HPCR_pixmap;
 
4327
            dd->WriteRGBSpan        = write_span_rgb_HPCR_pixmap;
 
4328
            dd->WriteMonoRGBASpan   = write_span_mono_pixmap;
 
4329
            dd->WriteRGBAPixels     = write_pixels_HPCR_pixmap;
 
4330
            dd->WriteMonoRGBAPixels = write_pixels_mono_pixmap;
 
4331
            if (xmesa->xm_visual->hpcr_clear_flag) {
 
4332
               ctx->Driver.ClearColor = clear_color_HPCR_pixmap;
 
4333
            }
 
4334
            break;
 
4335
         case PF_LOOKUP:
 
4336
            dd->WriteRGBASpan       = write_span_LOOKUP_pixmap;
 
4337
            dd->WriteRGBSpan        = write_span_rgb_LOOKUP_pixmap;
 
4338
            dd->WriteMonoRGBASpan   = write_span_mono_pixmap;
 
4339
            dd->WriteRGBAPixels     = write_pixels_LOOKUP_pixmap;
 
4340
            dd->WriteMonoRGBAPixels = write_pixels_mono_pixmap;
 
4341
            break;
 
4342
         case PF_GRAYSCALE:
 
4343
            dd->WriteRGBASpan       = write_span_GRAYSCALE_pixmap;
 
4344
            dd->WriteRGBSpan        = write_span_rgb_GRAYSCALE_pixmap;
 
4345
            dd->WriteMonoRGBASpan   = write_span_mono_pixmap;
 
4346
            dd->WriteRGBAPixels     = write_pixels_GRAYSCALE_pixmap;
 
4347
            dd->WriteMonoRGBAPixels = write_pixels_mono_pixmap;
 
4348
            break;
 
4349
         default:
 
4350
            _mesa_problem(NULL,"Bad pixel format in xmesa_update_state (1)");
 
4351
            return;
 
4352
      }
 
4353
   }
 
4354
   else if (xmesa->xm_buffer->buffer==XIMAGE) {
 
4355
      /* Writing to back XImage */
 
4356
      switch (xmesa->pixelformat) {
 
4357
         case PF_INDEX:
 
4358
            dd->WriteCI32Span     = write_span_index_ximage;
 
4359
            if (depth==8)
 
4360
               dd->WriteCI8Span   = write_span_index8_ximage8;
 
4361
            else
 
4362
               dd->WriteCI8Span   = write_span_index8_ximage;
 
4363
            dd->WriteMonoCISpan   = write_span_mono_index_ximage;
 
4364
            dd->WriteCI32Pixels   = write_pixels_index_ximage;
 
4365
            dd->WriteMonoCIPixels = write_pixels_mono_index_ximage;
 
4366
            break;
 
4367
         case PF_TRUECOLOR:
 
4368
            /* Generic RGB */
 
4369
            dd->WriteRGBASpan       = write_span_TRUECOLOR_ximage;
 
4370
            dd->WriteRGBSpan        = write_span_rgb_TRUECOLOR_ximage;
 
4371
            dd->WriteMonoRGBASpan   = write_span_mono_ximage;
 
4372
            dd->WriteRGBAPixels     = write_pixels_TRUECOLOR_ximage;
 
4373
            dd->WriteMonoRGBAPixels = write_pixels_mono_ximage;
 
4374
            break;
 
4375
         case PF_TRUEDITHER:
 
4376
            dd->WriteRGBASpan       = write_span_TRUEDITHER_ximage;
 
4377
            dd->WriteRGBSpan        = write_span_rgb_TRUEDITHER_ximage;
 
4378
            dd->WriteMonoRGBASpan   = write_span_mono_TRUEDITHER_ximage;
 
4379
            dd->WriteRGBAPixels     = write_pixels_TRUEDITHER_ximage;
 
4380
            dd->WriteMonoRGBAPixels = write_pixels_mono_TRUEDITHER_ximage;
 
4381
            break;
 
4382
         case PF_8A8B8G8R:
 
4383
            dd->WriteRGBASpan       = write_span_8A8B8G8R_ximage;
 
4384
            dd->WriteRGBSpan        = write_span_rgb_8A8B8G8R_ximage;
 
4385
            dd->WriteMonoRGBASpan   = write_span_mono_8A8B8G8R_ximage;
 
4386
            dd->WriteRGBAPixels     = write_pixels_8A8B8G8R_ximage;
 
4387
            dd->WriteMonoRGBAPixels = write_pixels_mono_8A8B8G8R_ximage;
 
4388
            break;
 
4389
         case PF_8R8G8B:
 
4390
            dd->WriteRGBASpan       = write_span_8R8G8B_ximage;
 
4391
            dd->WriteRGBSpan        = write_span_rgb_8R8G8B_ximage;
 
4392
            dd->WriteMonoRGBASpan   = write_span_mono_8R8G8B_ximage;
 
4393
            dd->WriteRGBAPixels     = write_pixels_8R8G8B_ximage;
 
4394
            dd->WriteMonoRGBAPixels = write_pixels_mono_8R8G8B_ximage;
 
4395
            break;
 
4396
         case PF_8R8G8B24:
 
4397
            dd->WriteRGBASpan       = write_span_8R8G8B24_ximage;
 
4398
            dd->WriteRGBSpan        = write_span_rgb_8R8G8B24_ximage;
 
4399
            dd->WriteMonoRGBASpan   = write_span_mono_8R8G8B24_ximage;
 
4400
            dd->WriteRGBAPixels     = write_pixels_8R8G8B24_ximage;
 
4401
            dd->WriteMonoRGBAPixels = write_pixels_mono_8R8G8B24_ximage;
 
4402
            break;
 
4403
         case PF_5R6G5B:
 
4404
            dd->WriteRGBASpan       = write_span_5R6G5B_ximage;
 
4405
            dd->WriteRGBSpan        = write_span_rgb_5R6G5B_ximage;
 
4406
            dd->WriteMonoRGBASpan   = write_span_mono_ximage;
 
4407
            dd->WriteRGBAPixels     = write_pixels_5R6G5B_ximage;
 
4408
            dd->WriteMonoRGBAPixels = write_pixels_mono_ximage;
 
4409
            break;
 
4410
         case PF_DITHER_5R6G5B:
 
4411
            dd->WriteRGBASpan       = write_span_DITHER_5R6G5B_ximage;
 
4412
            dd->WriteRGBSpan        = write_span_rgb_DITHER_5R6G5B_ximage;
 
4413
            dd->WriteMonoRGBASpan   = write_span_mono_DITHER_5R6G5B_ximage;
 
4414
            dd->WriteRGBAPixels     = write_pixels_DITHER_5R6G5B_ximage;
 
4415
            dd->WriteMonoRGBAPixels = write_pixels_mono_DITHER_5R6G5B_ximage;
 
4416
            break;
 
4417
         case PF_DITHER:
 
4418
            if (depth==8) {
 
4419
               dd->WriteRGBASpan      = write_span_DITHER8_ximage;
 
4420
               dd->WriteRGBSpan       = write_span_rgb_DITHER8_ximage;
 
4421
               dd->WriteMonoRGBASpan  = write_span_mono_DITHER8_ximage;
 
4422
               dd->WriteRGBAPixels    = write_pixels_DITHER8_ximage;
 
4423
               dd->WriteMonoRGBAPixels = write_pixels_mono_DITHER8_ximage;
 
4424
            }
 
4425
            else {
 
4426
               dd->WriteRGBASpan       = write_span_DITHER_ximage;
 
4427
               dd->WriteRGBSpan        = write_span_rgb_DITHER_ximage;
 
4428
               dd->WriteMonoRGBASpan   = write_span_mono_DITHER_ximage;
 
4429
               dd->WriteRGBAPixels     = write_pixels_DITHER_ximage;
 
4430
               dd->WriteMonoRGBAPixels = write_pixels_mono_DITHER_ximage;
 
4431
            }
 
4432
            break;
 
4433
         case PF_1BIT:
 
4434
            dd->WriteRGBASpan       = write_span_1BIT_ximage;
 
4435
            dd->WriteRGBSpan        = write_span_rgb_1BIT_ximage;
 
4436
            dd->WriteMonoRGBASpan   = write_span_mono_1BIT_ximage;
 
4437
            dd->WriteRGBAPixels     = write_pixels_1BIT_ximage;
 
4438
            dd->WriteMonoRGBAPixels = write_pixels_mono_1BIT_ximage;
 
4439
            break;
 
4440
         case PF_HPCR:
 
4441
            dd->WriteRGBASpan       = write_span_HPCR_ximage;
 
4442
            dd->WriteRGBSpan        = write_span_rgb_HPCR_ximage;
 
4443
            dd->WriteMonoRGBASpan   = write_span_mono_HPCR_ximage;
 
4444
            dd->WriteRGBAPixels     = write_pixels_HPCR_ximage;
 
4445
            dd->WriteMonoRGBAPixels = write_pixels_mono_HPCR_ximage;
 
4446
            if (xmesa->xm_visual->hpcr_clear_flag) {
 
4447
               ctx->Driver.ClearColor = clear_color_HPCR_ximage;
 
4448
            }
 
4449
            break;
 
4450
         case PF_LOOKUP:
 
4451
            if (depth==8) {
 
4452
               dd->WriteRGBASpan       = write_span_LOOKUP8_ximage;
 
4453
               dd->WriteRGBSpan        = write_rgb_LOOKUP8_ximage;
 
4454
               dd->WriteMonoRGBASpan   = write_span_mono_LOOKUP8_ximage;
 
4455
               dd->WriteRGBAPixels     = write_pixels_LOOKUP8_ximage;
 
4456
               dd->WriteMonoRGBAPixels = write_pixels_mono_LOOKUP8_ximage;
 
4457
            }
 
4458
            else {
 
4459
               dd->WriteRGBASpan       = write_span_LOOKUP_ximage;
 
4460
               dd->WriteRGBSpan        = write_span_rgb_LOOKUP_ximage;
 
4461
               dd->WriteMonoRGBASpan   = write_span_mono_ximage;
 
4462
               dd->WriteRGBAPixels     = write_pixels_LOOKUP_ximage;
 
4463
               dd->WriteMonoRGBAPixels = write_pixels_mono_ximage;
 
4464
            }
 
4465
            break;
 
4466
         case PF_GRAYSCALE:
 
4467
            if (depth==8) {
 
4468
               dd->WriteRGBASpan       = write_span_GRAYSCALE8_ximage;
 
4469
               dd->WriteRGBSpan        = write_span_rgb_GRAYSCALE8_ximage;
 
4470
               dd->WriteMonoRGBASpan   = write_span_mono_GRAYSCALE8_ximage;
 
4471
               dd->WriteRGBAPixels     = write_pixels_GRAYSCALE8_ximage;
 
4472
               dd->WriteMonoRGBAPixels = write_pixels_mono_GRAYSCALE8_ximage;
 
4473
            }
 
4474
            else {
 
4475
               dd->WriteRGBASpan       = write_span_GRAYSCALE_ximage;
 
4476
               dd->WriteRGBSpan        = write_span_rgb_GRAYSCALE_ximage;
 
4477
               dd->WriteMonoRGBASpan   = write_span_mono_ximage;
 
4478
               dd->WriteRGBAPixels     = write_pixels_GRAYSCALE_ximage;
 
4479
               dd->WriteMonoRGBAPixels = write_pixels_mono_ximage;
 
4480
            }
 
4481
            break;
 
4482
         default:
 
4483
            _mesa_problem(NULL,"Bad pixel format in xmesa_update_state (2)");
 
4484
            return;
 
4485
      }
 
4486
   }
 
4487
 
 
4488
   /* Pixel/span reading functions: */
 
4489
   dd->ReadCI32Span = read_index_span;
 
4490
   dd->ReadRGBASpan = read_color_span;
 
4491
   dd->ReadCI32Pixels = read_index_pixels;
 
4492
   dd->ReadRGBAPixels = read_color_pixels;
 
4493
 
 
4494
   dd->SetReadBuffer = xmesa_set_read_buffer;
 
4495
}