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