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