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