reverse some debug that slipped through
[mesa.git] / src / mesa / drivers / x11 / xm_span.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 5.1
4 *
5 * Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24 /* $XFree86: xc/extras/Mesa/src/X/xm_span.c,v 1.3 2002/02/27 21:07:54 tsi Exp $ */
25
26 #include "glxheader.h"
27 #include "colormac.h"
28 #include "context.h"
29 #include "depth.h"
30 #include "drawpix.h"
31 #include "extensions.h"
32 #include "macros.h"
33 #include "imports.h"
34 #include "mtypes.h"
35 #include "state.h"
36 #include "xmesaP.h"
37
38 #include "swrast/swrast.h"
39
40
41 /*
42 * The following functions are used to trap XGetImage() calls which
43 * generate BadMatch errors if the drawable isn't mapped.
44 */
45
46 #ifndef XFree86Server
47 static int caught_xgetimage_error = 0;
48 static int (*old_xerror_handler)( XMesaDisplay *dpy, XErrorEvent *ev );
49 static unsigned long xgetimage_serial;
50
51 /*
52 * This is the error handler which will be called if XGetImage fails.
53 */
54 static int xgetimage_error_handler( XMesaDisplay *dpy, XErrorEvent *ev )
55 {
56 if (ev->serial==xgetimage_serial && ev->error_code==BadMatch) {
57 /* caught the expected error */
58 caught_xgetimage_error = 0;
59 }
60 else {
61 /* call the original X error handler, if any. otherwise ignore */
62 if (old_xerror_handler) {
63 (*old_xerror_handler)( dpy, ev );
64 }
65 }
66 return 0;
67 }
68
69
70 /*
71 * Call this right before XGetImage to setup error trap.
72 */
73 static void catch_xgetimage_errors( XMesaDisplay *dpy )
74 {
75 xgetimage_serial = NextRequest( dpy );
76 old_xerror_handler = XSetErrorHandler( xgetimage_error_handler );
77 caught_xgetimage_error = 0;
78 }
79
80
81 /*
82 * Call this right after XGetImage to check if an error occured.
83 */
84 static int check_xgetimage_errors( void )
85 {
86 /* restore old handler */
87 (void) XSetErrorHandler( old_xerror_handler );
88 /* return 0=no error, 1=error caught */
89 return caught_xgetimage_error;
90 }
91 #endif
92
93
94 /*
95 * Read a pixel from an X drawable.
96 */
97 static unsigned long read_pixel( XMesaDisplay *dpy,
98 XMesaDrawable d, int x, int y )
99 {
100 unsigned long p;
101 #ifndef XFree86Server
102 XMesaImage *pixel = NULL;
103 int error;
104
105 catch_xgetimage_errors( dpy );
106 pixel = XGetImage( dpy, d, x, y, 1, 1, AllPlanes, ZPixmap );
107 error = check_xgetimage_errors();
108 if (pixel && !error) {
109 p = XMesaGetPixel( pixel, 0, 0 );
110 }
111 else {
112 p = 0;
113 }
114 if (pixel) {
115 XMesaDestroyImage( pixel );
116 }
117 #else
118 (*dpy->GetImage)(d, x, y, 1, 1, ZPixmap, ~0L, (pointer)&p);
119 #endif
120 return p;
121 }
122
123
124
125 /*
126 * The Mesa library needs to be able to draw pixels in a number of ways:
127 * 1. RGB vs Color Index
128 * 2. as horizontal spans (polygons, images) vs random locations (points,
129 * lines)
130 * 3. different color per-pixel or same color for all pixels
131 *
132 * Furthermore, the X driver needs to support rendering to 3 possible
133 * "buffers", usually one, but sometimes two at a time:
134 * 1. The front buffer as an X window
135 * 2. The back buffer as a Pixmap
136 * 3. The back buffer as an XImage
137 *
138 * Finally, if the back buffer is an XImage, we can avoid using XPutPixel and
139 * optimize common cases such as 24-bit and 8-bit modes.
140 *
141 * By multiplication, there's at least 48 possible combinations of the above.
142 *
143 * Below are implementations of the most commonly used combinations. They are
144 * accessed through function pointers which get initialized here and are used
145 * directly from the Mesa library. The 8 function pointers directly correspond
146 * to the first 3 cases listed above.
147 *
148 *
149 * The function naming convention is:
150 *
151 * write_[span|pixels]_[mono]_[format]_[pixmap|ximage]
152 *
153 * New functions optimized for specific cases can be added without too much
154 * trouble. An example might be the 24-bit TrueColor mode 8A8R8G8B which is
155 * found on IBM RS/6000 X servers.
156 */
157
158
159
160
161 /**********************************************************************/
162 /*** Write COLOR SPAN functions ***/
163 /**********************************************************************/
164
165
166 #define RGBA_SPAN_ARGS const GLcontext *ctx, \
167 GLuint n, GLint x, GLint y, \
168 CONST GLubyte rgba[][4], const GLubyte mask[]
169
170 #define RGB_SPAN_ARGS const GLcontext *ctx, \
171 GLuint n, GLint x, GLint y, \
172 CONST GLubyte rgb[][3], const GLubyte mask[]
173
174
175 /* NOTE: if mask==NULL, draw all pixels */
176
177
178 /*
179 * Write a span of PF_TRUECOLOR pixels to a pixmap.
180 */
181 static void write_span_TRUECOLOR_pixmap( RGBA_SPAN_ARGS )
182 {
183 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
184 XMesaDisplay *dpy = xmesa->xm_visual->display;
185 XMesaDrawable buffer = xmesa->xm_buffer->buffer;
186 XMesaGC gc = xmesa->xm_buffer->gc;
187 register GLuint i;
188
189 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 = XMESA_CONTEXT(ctx);
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 = XMESA_CONTEXT(ctx);
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 = XMESA_CONTEXT(ctx);
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 = XMESA_CONTEXT(ctx);
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 = XMESA_CONTEXT(ctx);
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 = XMESA_CONTEXT(ctx);
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 = XMESA_CONTEXT(ctx);
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 = XMESA_CONTEXT(ctx);
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 = XMESA_CONTEXT(ctx);
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 = XMESA_CONTEXT(ctx);
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 = XMESA_CONTEXT(ctx);
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 = XMESA_CONTEXT(ctx);
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 = XMESA_CONTEXT(ctx);
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 = XMESA_CONTEXT(ctx);
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 = XMESA_CONTEXT(ctx);
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 = XMESA_CONTEXT(ctx);
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 = XMESA_CONTEXT(ctx);
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 = XMESA_CONTEXT(ctx);
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 = XMESA_CONTEXT(ctx);
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 = XMESA_CONTEXT(ctx);
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 = XMESA_CONTEXT(ctx);
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 = XMESA_CONTEXT(ctx);
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 = XMESA_CONTEXT(ctx);
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 = XMESA_CONTEXT(ctx);
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 = XMESA_CONTEXT(ctx);
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 = XMESA_CONTEXT(ctx);
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 = XMESA_CONTEXT(ctx);
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 = XMESA_CONTEXT(ctx);
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 = XMESA_CONTEXT(ctx);
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 = XMESA_CONTEXT(ctx);
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 = XMESA_CONTEXT(ctx);
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 = XMESA_CONTEXT(ctx);
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 = XMESA_CONTEXT(ctx);
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 = XMESA_CONTEXT(ctx);
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 = XMESA_CONTEXT(ctx);
1508 register GLuint i;
1509 register GLushort *ptr = PIXELADDR2( xmesa->xm_buffer, x, y );
1510 const GLint y2 = FLIP(xmesa->xm_buffer, y);
1511 if (mask) {
1512 for (i=0;i<n;i++,x++) {
1513 if (mask[i]) {
1514 PACK_TRUEDITHER( ptr[i], x, y2, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
1515 }
1516 }
1517 }
1518 else {
1519 /* draw all pixels */
1520 #if defined(__i386__) /* word stores don't have to be on 4-byte boundaries */
1521 GLuint *ptr32 = (GLuint *) ptr;
1522 GLuint extraPixel = (n & 1);
1523 n -= extraPixel;
1524 for (i = 0; i < n; i += 2, x += 2) {
1525 GLuint p0, p1;
1526 PACK_TRUEDITHER( p0, x, y2, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
1527 PACK_TRUEDITHER( p1, x+1, y2, rgba[i+1][RCOMP], rgba[i+1][GCOMP], rgba[i+1][BCOMP] );
1528 *ptr32++ = (p1 << 16) | p0;
1529 }
1530 if (extraPixel) {
1531 PACK_TRUEDITHER( ptr[n], x+n, y2, rgba[n][RCOMP], rgba[n][GCOMP], rgba[n][BCOMP]);
1532 }
1533 #else
1534 for (i = 0; i < n; i++, x++) {
1535 PACK_TRUEDITHER( ptr[i], x, y2, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
1536 }
1537 #endif
1538 }
1539 }
1540
1541
1542 /*
1543 * Write a span of PF_5R6G5B-format pixels to an ximage (no alpha).
1544 */
1545 static void write_span_rgb_5R6G5B_ximage( RGB_SPAN_ARGS )
1546 {
1547 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
1548 register GLuint i;
1549 register GLushort *ptr = PIXELADDR2( xmesa->xm_buffer, x, y );
1550 if (mask) {
1551 for (i=0;i<n;i++) {
1552 if (mask[i]) {
1553 ptr[i] = PACK_5R6G5B( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
1554 }
1555 }
1556 }
1557 else {
1558 /* draw all pixels */
1559 #if defined(__i386__) /* word stores don't have to be on 4-byte boundaries */
1560 GLuint *ptr32 = (GLuint *) ptr;
1561 GLuint extraPixel = (n & 1);
1562 n -= extraPixel;
1563 for (i = 0; i < n; i += 2) {
1564 GLuint p0, p1;
1565 p0 = PACK_5R6G5B(rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]);
1566 p1 = PACK_5R6G5B(rgb[i+1][RCOMP], rgb[i+1][GCOMP], rgb[i+1][BCOMP]);
1567 *ptr32++ = (p1 << 16) | p0;
1568 }
1569 if (extraPixel) {
1570 ptr[n] = PACK_5R6G5B(rgb[n][RCOMP], rgb[n][GCOMP], rgb[n][BCOMP]);
1571 }
1572 #else
1573 for (i=0;i<n;i++) {
1574 ptr[i] = PACK_5R6G5B( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
1575 }
1576 #endif
1577 }
1578 }
1579
1580
1581 /*
1582 * Write a span of PF_DITHER_5R6G5B-format pixels to an ximage (no alpha).
1583 */
1584 static void write_span_rgb_DITHER_5R6G5B_ximage( RGB_SPAN_ARGS )
1585 {
1586 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
1587 register GLuint i;
1588 register GLushort *ptr = PIXELADDR2( xmesa->xm_buffer, x, y );
1589 if (mask) {
1590 for (i=0;i<n;i++,x++) {
1591 if (mask[i]) {
1592 PACK_TRUEDITHER( ptr[i], x, y, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
1593 }
1594 }
1595 }
1596 else {
1597 /* draw all pixels */
1598 #if defined(__i386__) /* word stores don't have to be on 4-byte boundaries */
1599 GLuint *ptr32 = (GLuint *) ptr;
1600 GLuint extraPixel = (n & 1);
1601 n -= extraPixel;
1602 for (i = 0; i < n; i += 2, x += 2) {
1603 GLuint p0, p1;
1604 PACK_TRUEDITHER( p0, x, y, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
1605 PACK_TRUEDITHER( p1, x+1, y, rgb[i+1][RCOMP], rgb[i+1][GCOMP], rgb[i+1][BCOMP] );
1606 *ptr32++ = (p1 << 16) | p0;
1607 }
1608 if (extraPixel) {
1609 PACK_TRUEDITHER( ptr[n], x+n, y, rgb[n][RCOMP], rgb[n][GCOMP], rgb[n][BCOMP]);
1610 }
1611 #else
1612 for (i=0;i<n;i++,x++) {
1613 PACK_TRUEDITHER( ptr[i], x, y, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
1614 }
1615 #endif
1616 }
1617 }
1618
1619
1620 /*
1621 * Write a span of PF_DITHER pixels to an XImage.
1622 */
1623 static void write_span_DITHER_ximage( RGBA_SPAN_ARGS )
1624 {
1625 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
1626 XMesaImage *img = xmesa->xm_buffer->backimage;
1627 register GLuint i;
1628 int yy = FLIP(xmesa->xm_buffer, y);
1629 XDITHER_SETUP(yy);
1630 if (mask) {
1631 for (i=0;i<n;i++,x++) {
1632 if (mask[i]) {
1633 XMesaPutPixel( img, x, yy, XDITHER( x, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
1634 }
1635 }
1636 }
1637 else {
1638 /* draw all pixels */
1639 for (i=0;i<n;i++,x++) {
1640 XMesaPutPixel( img, x, yy, XDITHER( x, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
1641 }
1642 }
1643 }
1644
1645
1646 /*
1647 * Write a span of PF_DITHER pixels to an XImage (no alpha).
1648 */
1649 static void write_span_rgb_DITHER_ximage( RGB_SPAN_ARGS )
1650 {
1651 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
1652 XMesaImage *img = xmesa->xm_buffer->backimage;
1653 register GLuint i;
1654 int yy = FLIP(xmesa->xm_buffer, y);
1655 XDITHER_SETUP(yy);
1656 if (mask) {
1657 for (i=0;i<n;i++,x++) {
1658 if (mask[i]) {
1659 XMesaPutPixel( img, x, yy, XDITHER( x, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] ) );
1660 }
1661 }
1662 }
1663 else {
1664 /* draw all pixels */
1665 for (i=0;i<n;i++,x++) {
1666 XMesaPutPixel( img, x, yy, XDITHER( x, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] ) );
1667 }
1668 }
1669 }
1670
1671
1672
1673 /*
1674 * Write a span of 8-bit PF_DITHER pixels to an XImage.
1675 */
1676 static void write_span_DITHER8_ximage( RGBA_SPAN_ARGS )
1677 {
1678 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
1679 register GLuint i;
1680 register GLubyte *ptr = PIXELADDR1( xmesa->xm_buffer, x, y );
1681 XDITHER_SETUP(y);
1682 if (mask) {
1683 for (i=0;i<n;i++,x++) {
1684 if (mask[i]) {
1685 ptr[i] = (GLubyte) XDITHER( x, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
1686 }
1687 }
1688 }
1689 else {
1690 for (i=0;i<n;i++,x++) {
1691 ptr[i] = (GLubyte) XDITHER( x, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
1692 }
1693 }
1694 }
1695
1696
1697 static void write_span_rgb_DITHER8_ximage( RGB_SPAN_ARGS )
1698 {
1699 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
1700 register GLuint i;
1701 register GLubyte *ptr = PIXELADDR1( xmesa->xm_buffer, x, y );
1702 XDITHER_SETUP(y);
1703 if (mask) {
1704 for (i=0;i<n;i++,x++) {
1705 if (mask[i]) {
1706 ptr[i] = (GLubyte) XDITHER( x, rgb[i][0], rgb[i][1], rgb[i][2] );
1707 }
1708 }
1709 }
1710 else {
1711 const GLubyte *data = (GLubyte *) rgb;
1712 for (i=0;i<n;i++,x++) {
1713 /*ptr[i] = XDITHER( x, rgb[i][0], rgb[i][1], rgb[i][2] );*/
1714 ptr[i] = (GLubyte) XDITHER( x, data[i+i+i], data[i+i+i+1], data[i+i+i+2] );
1715 }
1716 }
1717 }
1718
1719
1720
1721 /*
1722 * Write a span of PF_1BIT pixels to an XImage.
1723 */
1724 static void write_span_1BIT_ximage( RGBA_SPAN_ARGS )
1725 {
1726 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
1727 XMesaImage *img = xmesa->xm_buffer->backimage;
1728 register GLuint i;
1729 SETUP_1BIT;
1730 y = FLIP(xmesa->xm_buffer, y);
1731 if (mask) {
1732 for (i=0;i<n;i++,x++) {
1733 if (mask[i]) {
1734 XMesaPutPixel(img, x, y, DITHER_1BIT(x, y, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]));
1735 }
1736 }
1737 }
1738 else {
1739 for (i=0;i<n;i++,x++) {
1740 XMesaPutPixel( img, x, y, DITHER_1BIT(x, y, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]) );
1741 }
1742 }
1743 }
1744
1745
1746 /*
1747 * Write a span of PF_1BIT pixels to an XImage (no alpha).
1748 */
1749 static void write_span_rgb_1BIT_ximage( RGB_SPAN_ARGS )
1750 {
1751 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
1752 XMesaImage *img = xmesa->xm_buffer->backimage;
1753 register GLuint i;
1754 SETUP_1BIT;
1755 y = FLIP(xmesa->xm_buffer, y);
1756 if (mask) {
1757 for (i=0;i<n;i++,x++) {
1758 if (mask[i]) {
1759 XMesaPutPixel(img, x, y, DITHER_1BIT(x, y, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]));
1760 }
1761 }
1762 }
1763 else {
1764 for (i=0;i<n;i++,x++) {
1765 XMesaPutPixel( img, x, y, DITHER_1BIT(x, y, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]) );
1766 }
1767 }
1768 }
1769
1770
1771 /*
1772 * Write a span of PF_HPCR pixels to an XImage.
1773 */
1774 static void write_span_HPCR_ximage( RGBA_SPAN_ARGS )
1775 {
1776 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
1777 register GLuint i;
1778 register GLubyte *ptr = PIXELADDR1( xmesa->xm_buffer, x, y );
1779 if (mask) {
1780 for (i=0;i<n;i++,x++) {
1781 if (mask[i]) {
1782 ptr[i] = DITHER_HPCR( x, y, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
1783 }
1784 }
1785 }
1786 else {
1787 /* draw all pixels */
1788 for (i=0;i<n;i++,x++) {
1789 ptr[i] = DITHER_HPCR( x, y, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
1790 }
1791 }
1792 }
1793
1794
1795 /*
1796 * Write a span of PF_HPCR pixels to an XImage (no alpha).
1797 */
1798 static void write_span_rgb_HPCR_ximage( RGB_SPAN_ARGS )
1799 {
1800 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
1801 register GLuint i;
1802 register GLubyte *ptr = PIXELADDR1( xmesa->xm_buffer, x, y );
1803 if (mask) {
1804 for (i=0;i<n;i++,x++) {
1805 if (mask[i]) {
1806 ptr[i] = DITHER_HPCR( x, y, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
1807 }
1808 }
1809 }
1810 else {
1811 /* draw all pixels */
1812 for (i=0;i<n;i++,x++) {
1813 ptr[i] = DITHER_HPCR( x, y, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
1814 }
1815 }
1816 }
1817
1818
1819 /*
1820 * Write a span of PF_LOOKUP pixels to an XImage.
1821 */
1822 static void write_span_LOOKUP_ximage( RGBA_SPAN_ARGS )
1823 {
1824 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
1825 XMesaImage *img = xmesa->xm_buffer->backimage;
1826 register GLuint i;
1827 LOOKUP_SETUP;
1828 y = FLIP(xmesa->xm_buffer, y);
1829 if (mask) {
1830 for (i=0;i<n;i++,x++) {
1831 if (mask[i]) {
1832 XMesaPutPixel( img, x, y, LOOKUP( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
1833 }
1834 }
1835 }
1836 else {
1837 /* draw all pixels */
1838 for (i=0;i<n;i++,x++) {
1839 XMesaPutPixel( img, x, y, LOOKUP( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
1840 }
1841 }
1842 }
1843
1844
1845 /*
1846 * Write a span of PF_LOOKUP pixels to an XImage (no alpha).
1847 */
1848 static void write_span_rgb_LOOKUP_ximage( RGB_SPAN_ARGS )
1849 {
1850 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
1851 XMesaImage *img = xmesa->xm_buffer->backimage;
1852 register GLuint i;
1853 LOOKUP_SETUP;
1854 y = FLIP(xmesa->xm_buffer, y);
1855 if (mask) {
1856 for (i=0;i<n;i++,x++) {
1857 if (mask[i]) {
1858 XMesaPutPixel( img, x, y, LOOKUP( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] ) );
1859 }
1860 }
1861 }
1862 else {
1863 /* draw all pixels */
1864 for (i=0;i<n;i++,x++) {
1865 XMesaPutPixel( img, x, y, LOOKUP( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] ) );
1866 }
1867 }
1868 }
1869
1870
1871 /*
1872 * Write a span of 8-bit PF_LOOKUP pixels to an XImage.
1873 */
1874 static void write_span_LOOKUP8_ximage( RGBA_SPAN_ARGS )
1875 {
1876 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
1877 register GLuint i;
1878 register GLubyte *ptr = PIXELADDR1( xmesa->xm_buffer, x, y );
1879 LOOKUP_SETUP;
1880 if (mask) {
1881 for (i=0;i<n;i++,x++) {
1882 if (mask[i]) {
1883 ptr[i] = (GLubyte) LOOKUP( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
1884 }
1885 }
1886 }
1887 else {
1888 /* draw all pixels */
1889 for (i=0;i<n;i++,x++) {
1890 ptr[i] = (GLubyte) LOOKUP( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
1891 }
1892 }
1893 }
1894
1895
1896 static void write_rgb_LOOKUP8_ximage( const GLcontext *ctx,
1897 GLuint n, GLint x, GLint y,
1898 CONST GLubyte rgb[][3],
1899 const GLubyte mask[] )
1900 {
1901 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
1902 register GLuint i;
1903 register GLubyte *ptr = PIXELADDR1( xmesa->xm_buffer, x, y );
1904 LOOKUP_SETUP;
1905 if (mask) {
1906 for (i=0;i<n;i++,x++) {
1907 if (mask[i]) {
1908 ptr[i] = (GLubyte) LOOKUP( rgb[i][0], rgb[i][1], rgb[i][2] );
1909 }
1910 }
1911 }
1912 else {
1913 /* draw all pixels */
1914 const GLubyte *data = (GLubyte *) rgb;
1915 for (i=0;i<n;i++,x++) {
1916 /*ptr[i] = LOOKUP( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );*/
1917 ptr[i] = (GLubyte) LOOKUP( data[i+i+i], data[i+i+i+1], data[i+i+i+2] );
1918 }
1919 }
1920 }
1921
1922
1923 /*
1924 * Write a span of PF_GRAYSCALE pixels to an XImage.
1925 */
1926 static void write_span_GRAYSCALE_ximage( RGBA_SPAN_ARGS )
1927 {
1928 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
1929 XMesaImage *img = xmesa->xm_buffer->backimage;
1930 register GLuint i;
1931 y = FLIP(xmesa->xm_buffer, y);
1932 if (mask) {
1933 for (i=0;i<n;i++,x++) {
1934 if (mask[i]) {
1935 XMesaPutPixel( img, x, y, GRAY_RGB( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
1936 }
1937 }
1938 }
1939 else {
1940 /* draw all pixels */
1941 for (i=0;i<n;i++,x++) {
1942 XMesaPutPixel( img, x, y, GRAY_RGB( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
1943 }
1944 }
1945 }
1946
1947
1948 /*
1949 * Write a span of PF_GRAYSCALE pixels to an XImage (no alpha).
1950 */
1951 static void write_span_rgb_GRAYSCALE_ximage( RGB_SPAN_ARGS )
1952 {
1953 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
1954 XMesaImage *img = xmesa->xm_buffer->backimage;
1955 register GLuint i;
1956 y = FLIP(xmesa->xm_buffer, y);
1957 if (mask) {
1958 for (i=0;i<n;i++,x++) {
1959 if (mask[i]) {
1960 XMesaPutPixel( img, x, y, GRAY_RGB( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] ) );
1961 }
1962 }
1963 }
1964 else {
1965 /* draw all pixels */
1966 for (i=0;i<n;i++,x++) {
1967 XMesaPutPixel( img, x, y, GRAY_RGB( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] ) );
1968 }
1969 }
1970 }
1971
1972
1973 /*
1974 * Write a span of 8-bit PF_GRAYSCALE pixels to an XImage.
1975 */
1976 static void write_span_GRAYSCALE8_ximage( RGBA_SPAN_ARGS )
1977 {
1978 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
1979 register GLuint i;
1980 register GLubyte *ptr = PIXELADDR1( xmesa->xm_buffer, x, y );
1981 if (mask) {
1982 for (i=0;i<n;i++) {
1983 if (mask[i]) {
1984 ptr[i] = (GLubyte) GRAY_RGB( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
1985 }
1986 }
1987 }
1988 else {
1989 /* draw all pixels */
1990 for (i=0;i<n;i++) {
1991 ptr[i] = (GLubyte) GRAY_RGB( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
1992 }
1993 }
1994 }
1995
1996
1997 /*
1998 * Write a span of 8-bit PF_GRAYSCALE pixels to an XImage (no alpha).
1999 */
2000 static void write_span_rgb_GRAYSCALE8_ximage( RGB_SPAN_ARGS )
2001 {
2002 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2003 register GLuint i;
2004 register GLubyte *ptr = PIXELADDR1( xmesa->xm_buffer, x, y );
2005 if (mask) {
2006 for (i=0;i<n;i++) {
2007 if (mask[i]) {
2008 ptr[i] = (GLubyte) GRAY_RGB( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
2009 }
2010 }
2011 }
2012 else {
2013 /* draw all pixels */
2014 for (i=0;i<n;i++) {
2015 ptr[i] = (GLubyte) GRAY_RGB( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
2016 }
2017 }
2018 }
2019
2020
2021
2022
2023 /**********************************************************************/
2024 /*** Write COLOR PIXEL functions ***/
2025 /**********************************************************************/
2026
2027
2028 #define RGBA_PIXEL_ARGS const GLcontext *ctx, \
2029 GLuint n, const GLint x[], const GLint y[], \
2030 CONST GLubyte rgba[][4], const GLubyte mask[]
2031
2032
2033 /*
2034 * Write an array of PF_TRUECOLOR pixels to a pixmap.
2035 */
2036 static void write_pixels_TRUECOLOR_pixmap( RGBA_PIXEL_ARGS )
2037 {
2038 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2039 XMesaDisplay *dpy = xmesa->xm_visual->display;
2040 XMesaDrawable buffer = xmesa->xm_buffer->buffer;
2041 XMesaGC gc = xmesa->xm_buffer->gc;
2042 register GLuint i;
2043 for (i=0;i<n;i++) {
2044 if (mask[i]) {
2045 unsigned long p;
2046 PACK_TRUECOLOR( p, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
2047 XMesaSetForeground( dpy, gc, p );
2048 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) FLIP(xmesa->xm_buffer, y[i]) );
2049 }
2050 }
2051 }
2052
2053
2054 /*
2055 * Write an array of PF_TRUEDITHER pixels to a pixmap.
2056 */
2057 static void write_pixels_TRUEDITHER_pixmap( RGBA_PIXEL_ARGS )
2058 {
2059 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2060 XMesaDisplay *dpy = xmesa->xm_visual->display;
2061 XMesaDrawable buffer = xmesa->xm_buffer->buffer;
2062 XMesaGC gc = xmesa->xm_buffer->gc;
2063 register GLuint i;
2064 for (i=0;i<n;i++) {
2065 if (mask[i]) {
2066 unsigned long p;
2067 PACK_TRUEDITHER(p, x[i], y[i], rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
2068 XMesaSetForeground( dpy, gc, p );
2069 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) FLIP(xmesa->xm_buffer, y[i]) );
2070 }
2071 }
2072 }
2073
2074
2075 /*
2076 * Write an array of PF_8A8B8G8R pixels to a pixmap.
2077 */
2078 static void write_pixels_8A8B8G8R_pixmap( RGBA_PIXEL_ARGS )
2079 {
2080 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2081 XMesaDisplay *dpy = xmesa->xm_visual->display;
2082 XMesaDrawable buffer = xmesa->xm_buffer->buffer;
2083 XMesaGC gc = xmesa->xm_buffer->gc;
2084 register GLuint i;
2085 for (i=0;i<n;i++) {
2086 if (mask[i]) {
2087 XMesaSetForeground( dpy, gc,
2088 PACK_8A8B8G8R( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP], rgba[i][ACOMP] ));
2089 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) FLIP(xmesa->xm_buffer, y[i]) );
2090 }
2091 }
2092 }
2093
2094
2095 /*
2096 * Write an array of PF_8R8G8B pixels to a pixmap.
2097 */
2098 static void write_pixels_8R8G8B_pixmap( RGBA_PIXEL_ARGS )
2099 {
2100 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2101 XMesaDisplay *dpy = xmesa->xm_visual->display;
2102 XMesaDrawable buffer = xmesa->xm_buffer->buffer;
2103 XMesaGC gc = xmesa->xm_buffer->gc;
2104 register GLuint i;
2105 for (i=0;i<n;i++) {
2106 if (mask[i]) {
2107 XMesaSetForeground( dpy, gc, PACK_8R8G8B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
2108 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) FLIP(xmesa->xm_buffer, y[i]) );
2109 }
2110 }
2111 }
2112
2113
2114 /*
2115 * Write an array of PF_8R8G8B24 pixels to a pixmap.
2116 */
2117 static void write_pixels_8R8G8B24_pixmap( RGBA_PIXEL_ARGS )
2118 {
2119 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2120 XMesaDisplay *dpy = xmesa->xm_visual->display;
2121 XMesaDrawable buffer = xmesa->xm_buffer->buffer;
2122 XMesaGC gc = xmesa->xm_buffer->gc;
2123 register GLuint i;
2124 for (i=0;i<n;i++) {
2125 if (mask[i]) {
2126 XMesaSetForeground( dpy, gc, PACK_8R8G8B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
2127 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) FLIP(xmesa->xm_buffer, y[i]) );
2128 }
2129 }
2130 }
2131
2132
2133 /*
2134 * Write an array of PF_5R6G5B pixels to a pixmap.
2135 */
2136 static void write_pixels_5R6G5B_pixmap( RGBA_PIXEL_ARGS )
2137 {
2138 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2139 XMesaDisplay *dpy = xmesa->xm_visual->display;
2140 XMesaDrawable buffer = xmesa->xm_buffer->buffer;
2141 XMesaGC gc = xmesa->xm_buffer->gc;
2142 register GLuint i;
2143 for (i=0;i<n;i++) {
2144 if (mask[i]) {
2145 XMesaSetForeground( dpy, gc, PACK_5R6G5B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
2146 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) FLIP(xmesa->xm_buffer, y[i]) );
2147 }
2148 }
2149 }
2150
2151
2152 /*
2153 * Write an array of PF_DITHER_5R6G5B pixels to a pixmap.
2154 */
2155 static void write_pixels_DITHER_5R6G5B_pixmap( RGBA_PIXEL_ARGS )
2156 {
2157 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2158 XMesaDisplay *dpy = xmesa->xm_visual->display;
2159 XMesaDrawable buffer = xmesa->xm_buffer->buffer;
2160 XMesaGC gc = xmesa->xm_buffer->gc;
2161 register GLuint i;
2162 for (i=0;i<n;i++) {
2163 if (mask[i]) {
2164 unsigned long p;
2165 PACK_TRUEDITHER(p, x[i], y[i], rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
2166 XMesaSetForeground( dpy, gc, p );
2167 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) FLIP(xmesa->xm_buffer, y[i]) );
2168 }
2169 }
2170 }
2171
2172
2173 /*
2174 * Write an array of PF_DITHER pixels to a pixmap.
2175 */
2176 static void write_pixels_DITHER_pixmap( RGBA_PIXEL_ARGS )
2177 {
2178 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2179 XMesaDisplay *dpy = xmesa->xm_visual->display;
2180 XMesaDrawable buffer = xmesa->xm_buffer->buffer;
2181 XMesaGC gc = xmesa->xm_buffer->gc;
2182 register GLuint i;
2183 DITHER_SETUP;
2184 for (i=0;i<n;i++) {
2185 if (mask[i]) {
2186 XMesaSetForeground( dpy, gc,
2187 DITHER(x[i], y[i], rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]) );
2188 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) FLIP(xmesa->xm_buffer, y[i]) );
2189 }
2190 }
2191 }
2192
2193
2194 /*
2195 * Write an array of PF_1BIT pixels to a pixmap.
2196 */
2197 static void write_pixels_1BIT_pixmap( RGBA_PIXEL_ARGS )
2198 {
2199 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2200 XMesaDisplay *dpy = xmesa->xm_visual->display;
2201 XMesaDrawable buffer = xmesa->xm_buffer->buffer;
2202 XMesaGC gc = xmesa->xm_buffer->gc;
2203 register GLuint i;
2204 SETUP_1BIT;
2205 for (i=0;i<n;i++) {
2206 if (mask[i]) {
2207 XMesaSetForeground( dpy, gc,
2208 DITHER_1BIT( x[i], y[i], rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ));
2209 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) FLIP(xmesa->xm_buffer, y[i]) );
2210 }
2211 }
2212 }
2213
2214
2215 /*
2216 * Write an array of PF_HPCR pixels to a pixmap.
2217 */
2218 static void write_pixels_HPCR_pixmap( RGBA_PIXEL_ARGS )
2219 {
2220 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2221 XMesaDisplay *dpy = xmesa->xm_visual->display;
2222 XMesaDrawable buffer = xmesa->xm_buffer->buffer;
2223 XMesaGC gc = xmesa->xm_buffer->gc;
2224 register GLuint i;
2225 for (i=0;i<n;i++) {
2226 if (mask[i]) {
2227 XMesaSetForeground( dpy, gc,
2228 DITHER_HPCR( x[i], y[i], rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ));
2229 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) FLIP(xmesa->xm_buffer, y[i]) );
2230 }
2231 }
2232 }
2233
2234
2235 /*
2236 * Write an array of PF_LOOKUP pixels to a pixmap.
2237 */
2238 static void write_pixels_LOOKUP_pixmap( RGBA_PIXEL_ARGS )
2239 {
2240 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2241 XMesaDisplay *dpy = xmesa->xm_visual->display;
2242 XMesaDrawable buffer = xmesa->xm_buffer->buffer;
2243 XMesaGC gc = xmesa->xm_buffer->gc;
2244 register GLuint i;
2245 LOOKUP_SETUP;
2246 for (i=0;i<n;i++) {
2247 if (mask[i]) {
2248 XMesaSetForeground( dpy, gc, LOOKUP( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
2249 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) FLIP(xmesa->xm_buffer, y[i]) );
2250 }
2251 }
2252 }
2253
2254
2255 /*
2256 * Write an array of PF_GRAYSCALE pixels to a pixmap.
2257 */
2258 static void write_pixels_GRAYSCALE_pixmap( RGBA_PIXEL_ARGS )
2259 {
2260 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2261 XMesaDisplay *dpy = xmesa->xm_visual->display;
2262 XMesaDrawable buffer = xmesa->xm_buffer->buffer;
2263 XMesaGC gc = xmesa->xm_buffer->gc;
2264 register GLuint i;
2265 for (i=0;i<n;i++) {
2266 if (mask[i]) {
2267 XMesaSetForeground( dpy, gc, GRAY_RGB( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
2268 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) FLIP(xmesa->xm_buffer, y[i]) );
2269 }
2270 }
2271 }
2272
2273
2274 /*
2275 * Write an array of PF_TRUECOLOR pixels to an ximage.
2276 */
2277 static void write_pixels_TRUECOLOR_ximage( RGBA_PIXEL_ARGS )
2278 {
2279 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2280 XMesaImage *img = xmesa->xm_buffer->backimage;
2281 register GLuint i;
2282 for (i=0;i<n;i++) {
2283 if (mask[i]) {
2284 unsigned long p;
2285 PACK_TRUECOLOR( p, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
2286 XMesaPutPixel( img, x[i], FLIP(xmesa->xm_buffer, y[i]), p );
2287 }
2288 }
2289 }
2290
2291
2292 /*
2293 * Write an array of PF_TRUEDITHER pixels to an XImage.
2294 */
2295 static void write_pixels_TRUEDITHER_ximage( RGBA_PIXEL_ARGS )
2296 {
2297 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2298 XMesaImage *img = xmesa->xm_buffer->backimage;
2299 register GLuint i;
2300 for (i=0;i<n;i++) {
2301 if (mask[i]) {
2302 unsigned long p;
2303 PACK_TRUEDITHER(p, x[i], y[i], rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
2304 XMesaPutPixel( img, x[i], FLIP(xmesa->xm_buffer, y[i]), p );
2305 }
2306 }
2307 }
2308
2309
2310 /*
2311 * Write an array of PF_8A8B8G8R pixels to an ximage.
2312 */
2313 static void write_pixels_8A8B8G8R_ximage( RGBA_PIXEL_ARGS )
2314 {
2315 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2316 register GLuint i;
2317 for (i=0;i<n;i++) {
2318 if (mask[i]) {
2319 GLuint *ptr = PIXELADDR4( xmesa->xm_buffer, x[i], y[i] );
2320 *ptr = PACK_8A8B8G8R( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP], rgba[i][ACOMP] );
2321 }
2322 }
2323 }
2324
2325
2326 /*
2327 * Write an array of PF_8R8G8B pixels to an ximage.
2328 */
2329 static void write_pixels_8R8G8B_ximage( RGBA_PIXEL_ARGS )
2330 {
2331 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2332 register GLuint i;
2333 for (i=0;i<n;i++) {
2334 if (mask[i]) {
2335 GLuint *ptr = PIXELADDR4( xmesa->xm_buffer, x[i], y[i] );
2336 *ptr = PACK_8R8G8B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
2337 }
2338 }
2339 }
2340
2341
2342 /*
2343 * Write an array of PF_8R8G8B24 pixels to an ximage.
2344 */
2345 static void write_pixels_8R8G8B24_ximage( RGBA_PIXEL_ARGS )
2346 {
2347 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2348 register GLuint i;
2349 for (i=0;i<n;i++) {
2350 if (mask[i]) {
2351 bgr_t *ptr = PIXELADDR3( xmesa->xm_buffer, x[i], y[i] );
2352 ptr->r = rgba[i][RCOMP];
2353 ptr->g = rgba[i][GCOMP];
2354 ptr->b = rgba[i][BCOMP];
2355 }
2356 }
2357 }
2358
2359
2360 /*
2361 * Write an array of PF_5R6G5B pixels to an ximage.
2362 */
2363 static void write_pixels_5R6G5B_ximage( RGBA_PIXEL_ARGS )
2364 {
2365 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2366 register GLuint i;
2367 for (i=0;i<n;i++) {
2368 if (mask[i]) {
2369 GLushort *ptr = PIXELADDR2( xmesa->xm_buffer, x[i], y[i] );
2370 *ptr = PACK_5R6G5B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
2371 }
2372 }
2373 }
2374
2375
2376 /*
2377 * Write an array of PF_DITHER_5R6G5B pixels to an ximage.
2378 */
2379 static void write_pixels_DITHER_5R6G5B_ximage( RGBA_PIXEL_ARGS )
2380 {
2381 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2382 register GLuint i;
2383 for (i=0;i<n;i++) {
2384 if (mask[i]) {
2385 GLushort *ptr = PIXELADDR2( xmesa->xm_buffer, x[i], y[i] );
2386 PACK_TRUEDITHER( *ptr, x[i], y[i], rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
2387 }
2388 }
2389 }
2390
2391
2392 /*
2393 * Write an array of PF_DITHER pixels to an XImage.
2394 */
2395 static void write_pixels_DITHER_ximage( RGBA_PIXEL_ARGS )
2396 {
2397 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2398 XMesaImage *img = xmesa->xm_buffer->backimage;
2399 register GLuint i;
2400 DITHER_SETUP;
2401 for (i=0;i<n;i++) {
2402 if (mask[i]) {
2403 XMesaPutPixel( img, x[i], FLIP(xmesa->xm_buffer, y[i]),
2404 DITHER( x[i], y[i], rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
2405 }
2406 }
2407 }
2408
2409
2410 /*
2411 * Write an array of 8-bit PF_DITHER pixels to an XImage.
2412 */
2413 static void write_pixels_DITHER8_ximage( RGBA_PIXEL_ARGS )
2414 {
2415 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2416 register GLuint i;
2417 DITHER_SETUP;
2418 for (i=0;i<n;i++) {
2419 if (mask[i]) {
2420 GLubyte *ptr = PIXELADDR1( xmesa->xm_buffer,x[i],y[i]);
2421 *ptr = (GLubyte) DITHER( x[i], y[i], rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
2422 }
2423 }
2424 }
2425
2426
2427 /*
2428 * Write an array of PF_1BIT pixels to an XImage.
2429 */
2430 static void write_pixels_1BIT_ximage( RGBA_PIXEL_ARGS )
2431 {
2432 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2433 XMesaImage *img = xmesa->xm_buffer->backimage;
2434 register GLuint i;
2435 SETUP_1BIT;
2436 for (i=0;i<n;i++) {
2437 if (mask[i]) {
2438 XMesaPutPixel( img, x[i], FLIP(xmesa->xm_buffer, y[i]),
2439 DITHER_1BIT( x[i], y[i], rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ));
2440 }
2441 }
2442 }
2443
2444
2445 /*
2446 * Write an array of PF_HPCR pixels to an XImage.
2447 */
2448 static void write_pixels_HPCR_ximage( RGBA_PIXEL_ARGS )
2449 {
2450 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2451 register GLuint i;
2452 for (i=0;i<n;i++) {
2453 if (mask[i]) {
2454 GLubyte *ptr = PIXELADDR1( xmesa->xm_buffer,x[i],y[i]);
2455 *ptr = (GLubyte) DITHER_HPCR( x[i], y[i], rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
2456 }
2457 }
2458 }
2459
2460
2461 /*
2462 * Write an array of PF_LOOKUP pixels to an XImage.
2463 */
2464 static void write_pixels_LOOKUP_ximage( RGBA_PIXEL_ARGS )
2465 {
2466 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2467 XMesaImage *img = xmesa->xm_buffer->backimage;
2468 register GLuint i;
2469 LOOKUP_SETUP;
2470 for (i=0;i<n;i++) {
2471 if (mask[i]) {
2472 XMesaPutPixel( img, x[i], FLIP(xmesa->xm_buffer, y[i]), LOOKUP(rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]) );
2473 }
2474 }
2475 }
2476
2477
2478 /*
2479 * Write an array of 8-bit PF_LOOKUP pixels to an XImage.
2480 */
2481 static void write_pixels_LOOKUP8_ximage( RGBA_PIXEL_ARGS )
2482 {
2483 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2484 register GLuint i;
2485 LOOKUP_SETUP;
2486 for (i=0;i<n;i++) {
2487 if (mask[i]) {
2488 GLubyte *ptr = PIXELADDR1( xmesa->xm_buffer,x[i],y[i]);
2489 *ptr = (GLubyte) LOOKUP( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
2490 }
2491 }
2492 }
2493
2494
2495 /*
2496 * Write an array of PF_GRAYSCALE pixels to an XImage.
2497 */
2498 static void write_pixels_GRAYSCALE_ximage( RGBA_PIXEL_ARGS )
2499 {
2500 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2501 XMesaImage *img = xmesa->xm_buffer->backimage;
2502 register GLuint i;
2503 for (i=0;i<n;i++) {
2504 if (mask[i]) {
2505 XMesaPutPixel( img, x[i], FLIP(xmesa->xm_buffer, y[i]),
2506 GRAY_RGB( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
2507 }
2508 }
2509 }
2510
2511
2512 /*
2513 * Write an array of 8-bit PF_GRAYSCALE pixels to an XImage.
2514 */
2515 static void write_pixels_GRAYSCALE8_ximage( RGBA_PIXEL_ARGS )
2516 {
2517 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2518 register GLuint i;
2519 for (i=0;i<n;i++) {
2520 if (mask[i]) {
2521 GLubyte *ptr = PIXELADDR1( xmesa->xm_buffer, x[i], y[i] );
2522 *ptr = (GLubyte) GRAY_RGB( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
2523 }
2524 }
2525 }
2526
2527
2528
2529
2530 /**********************************************************************/
2531 /*** Write MONO COLOR SPAN functions ***/
2532 /**********************************************************************/
2533
2534 #define MONO_SPAN_ARGS const GLcontext *ctx, \
2535 GLuint n, GLint x, GLint y, const GLchan color[4], \
2536 const GLubyte mask[]
2537
2538
2539 /*
2540 * Write a span of identical pixels to a pixmap.
2541 */
2542 static void write_span_mono_pixmap( MONO_SPAN_ARGS )
2543 {
2544 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2545 XMesaDisplay *dpy = xmesa->xm_visual->display;
2546 XMesaDrawable buffer = xmesa->xm_buffer->buffer;
2547 XMesaGC gc = xmesa->xm_buffer->gc;
2548 const unsigned long pixel = xmesa_color_to_pixel(xmesa, color[RCOMP],
2549 color[GCOMP], color[BCOMP], color[ACOMP], xmesa->pixelformat);
2550 register GLuint i;
2551 XMesaSetForeground( xmesa->display, gc, pixel );
2552 y = FLIP(xmesa->xm_buffer, y);
2553
2554 /* New code contributed by Jeff Epler and cleaned up by Keith
2555 * Whitwell.
2556 */
2557 for (i = 0; i < n; ) {
2558 GLuint start = i;
2559
2560 /* Identify and emit contiguous rendered pixels
2561 */
2562 while (i < n && (!mask || mask[i]))
2563 i++;
2564
2565 if (start < i)
2566 XMesaFillRectangle( dpy, buffer, gc,
2567 (int)(x+start), (int) y,
2568 (int)(i-start), 1);
2569
2570 /* Eat up non-rendered pixels
2571 */
2572 while (i < n && !mask[i])
2573 i++;
2574 }
2575 }
2576
2577
2578
2579 static void write_span_mono_index_pixmap( const GLcontext *ctx, GLuint n,
2580 GLint x, GLint y, GLuint colorIndex,
2581 const GLubyte mask[] )
2582 {
2583 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2584 XMesaDisplay *dpy = xmesa->xm_visual->display;
2585 XMesaDrawable buffer = xmesa->xm_buffer->buffer;
2586 XMesaGC gc = xmesa->xm_buffer->gc;
2587 register GLuint i;
2588 XMesaSetForeground( xmesa->display, gc, colorIndex );
2589 y = FLIP(xmesa->xm_buffer, y);
2590
2591 for (i = 0 ; i < n ;) {
2592 GLuint start = i;
2593
2594 /* Identify and emit contiguous rendered pixels
2595 */
2596 while (i < n && mask[i])
2597 i++;
2598
2599 if (start < i)
2600 XMesaFillRectangle( dpy, buffer, gc,
2601 (int)(x+start), (int) y,
2602 (int)(i-start), 1);
2603
2604 /* Eat up non-rendered pixels
2605 */
2606 while (i < n && !mask[i])
2607 i++;
2608 }
2609 }
2610
2611
2612
2613 /*
2614 * Write a span of PF_TRUEDITHER pixels to a pixmap.
2615 */
2616 static void write_span_mono_TRUEDITHER_pixmap( MONO_SPAN_ARGS )
2617 {
2618 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2619 XMesaDisplay *dpy = xmesa->xm_visual->display;
2620 XMesaDrawable buffer = xmesa->xm_buffer->buffer;
2621 XMesaGC gc = xmesa->xm_buffer->gc;
2622 const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
2623 register GLuint i;
2624 int yy = FLIP(xmesa->xm_buffer, y);
2625 for (i=0;i<n;i++,x++) {
2626 if (mask[i]) {
2627 unsigned long p;
2628 PACK_TRUEDITHER(p, x, yy, r, g, b);
2629 XMesaSetForeground( dpy, gc, p );
2630 XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) yy );
2631 }
2632 }
2633 }
2634
2635
2636 /*
2637 * Write a span of PF_DITHER pixels to a pixmap.
2638 */
2639 static void write_span_mono_DITHER_pixmap( MONO_SPAN_ARGS )
2640 {
2641 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2642 XMesaDisplay *dpy = xmesa->xm_visual->display;
2643 XMesaDrawable buffer = xmesa->xm_buffer->buffer;
2644 XMesaGC gc = xmesa->xm_buffer->gc;
2645 const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
2646 register GLuint i;
2647 int yy = FLIP(xmesa->xm_buffer, y);
2648 XDITHER_SETUP(yy);
2649 for (i=0;i<n;i++,x++) {
2650 if (mask[i]) {
2651 XMesaSetForeground( dpy, gc, XDITHER( x, r, g, b ) );
2652 XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) yy );
2653 }
2654 }
2655 }
2656
2657
2658 /*
2659 * Write a span of PF_1BIT pixels to a pixmap.
2660 */
2661 static void write_span_mono_1BIT_pixmap( MONO_SPAN_ARGS )
2662 {
2663 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2664 XMesaDisplay *dpy = xmesa->xm_visual->display;
2665 XMesaDrawable buffer = xmesa->xm_buffer->buffer;
2666 XMesaGC gc = xmesa->xm_buffer->gc;
2667 const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
2668 register GLuint i;
2669 SETUP_1BIT;
2670 y = FLIP(xmesa->xm_buffer, y);
2671 for (i=0;i<n;i++,x++) {
2672 if (mask[i]) {
2673 XMesaSetForeground( dpy, gc, DITHER_1BIT( x, y, r, g, b ) );
2674 XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
2675 }
2676 }
2677 }
2678
2679
2680 /*
2681 * Write a span of identical pixels to an XImage.
2682 */
2683 static void write_span_mono_ximage( MONO_SPAN_ARGS )
2684 {
2685 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2686 XMesaImage *img = xmesa->xm_buffer->backimage;
2687 register GLuint i;
2688 const unsigned long pixel = xmesa_color_to_pixel(xmesa, color[RCOMP],
2689 color[GCOMP], color[BCOMP], color[ACOMP], xmesa->pixelformat);
2690 y = FLIP(xmesa->xm_buffer, y);
2691 for (i=0;i<n;i++,x++) {
2692 if (mask[i]) {
2693 XMesaPutPixel( img, x, y, pixel );
2694 }
2695 }
2696 }
2697
2698
2699 static void write_span_mono_index_ximage( const GLcontext *ctx, GLuint n,
2700 GLint x, GLint y,
2701 GLuint colorIndex,
2702 const GLubyte mask[] )
2703 {
2704 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2705 XMesaImage *img = xmesa->xm_buffer->backimage;
2706 register GLuint i;
2707 y = FLIP(xmesa->xm_buffer, y);
2708 for (i=0;i<n;i++,x++) {
2709 if (mask[i]) {
2710 XMesaPutPixel( img, x, y, colorIndex );
2711 }
2712 }
2713 }
2714
2715
2716 /*
2717 * Write a span of identical PF_TRUEDITHER pixels to an XImage.
2718 */
2719 static void write_span_mono_TRUEDITHER_ximage( MONO_SPAN_ARGS )
2720 {
2721 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2722 XMesaImage *img = xmesa->xm_buffer->backimage;
2723 const GLint r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
2724 GLuint i;
2725 y = FLIP(xmesa->xm_buffer, y);
2726 for (i=0;i<n;i++) {
2727 if (mask[i]) {
2728 unsigned long p;
2729 PACK_TRUEDITHER( p, x+i, y, r, g, b);
2730 XMesaPutPixel( img, x+i, y, p );
2731 }
2732 }
2733 }
2734
2735
2736 /*
2737 * Write a span of identical 8A8B8G8R pixels to an XImage.
2738 */
2739 static void write_span_mono_8A8B8G8R_ximage( MONO_SPAN_ARGS )
2740 {
2741 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2742 GLuint i, *ptr;
2743 const unsigned long pixel = xmesa_color_to_pixel(xmesa, color[RCOMP],
2744 color[GCOMP], color[BCOMP], color[ACOMP], xmesa->pixelformat);
2745 ptr = PIXELADDR4( xmesa->xm_buffer, x, y );
2746 for (i=0;i<n;i++) {
2747 if (mask[i]) {
2748 ptr[i] = pixel;
2749 }
2750 }
2751 }
2752
2753
2754 /*
2755 * Write a span of identical 8R8G8B pixels to an XImage.
2756 */
2757 static void write_span_mono_8R8G8B_ximage( MONO_SPAN_ARGS )
2758 {
2759 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2760 const GLuint pixel = PACK_8R8G8B(color[RCOMP], color[GCOMP], color[BCOMP]);
2761 GLuint *ptr = PIXELADDR4( xmesa->xm_buffer, x, y );
2762 GLuint i;
2763 for (i=0;i<n;i++) {
2764 if (!mask || mask[i]) {
2765 ptr[i] = pixel;
2766 }
2767 }
2768 }
2769
2770
2771 /*
2772 * Write a span of identical 8R8G8B pixels to an XImage.
2773 */
2774 static void write_span_mono_8R8G8B24_ximage( MONO_SPAN_ARGS )
2775 {
2776 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2777 const GLubyte r = color[RCOMP];
2778 const GLubyte g = color[GCOMP];
2779 const GLubyte b = color[BCOMP];
2780 GLuint i;
2781 bgr_t *ptr = PIXELADDR3( xmesa->xm_buffer, x, y );
2782 for (i=0;i<n;i++) {
2783 if (mask[i]) {
2784 ptr[i].r = r;
2785 ptr[i].g = g;
2786 ptr[i].b = b;
2787 }
2788 }
2789 }
2790
2791
2792 /*
2793 * Write a span of identical DITHER pixels to an XImage.
2794 */
2795 static void write_span_mono_DITHER_ximage( MONO_SPAN_ARGS )
2796 {
2797 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2798 const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
2799 XMesaImage *img = xmesa->xm_buffer->backimage;
2800 int yy = FLIP(xmesa->xm_buffer, y);
2801 register GLuint i;
2802 XDITHER_SETUP(yy);
2803 for (i=0;i<n;i++,x++) {
2804 if (mask[i]) {
2805 XMesaPutPixel( img, x, yy, XDITHER( x, r, g, b ) );
2806 }
2807 }
2808 }
2809
2810
2811 /*
2812 * Write a span of identical 8-bit DITHER pixels to an XImage.
2813 */
2814 static void write_span_mono_DITHER8_ximage( MONO_SPAN_ARGS )
2815 {
2816 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2817 const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
2818 register GLubyte *ptr = PIXELADDR1( xmesa->xm_buffer,x,y);
2819 register GLuint i;
2820 XDITHER_SETUP(y);
2821 for (i=0;i<n;i++,x++) {
2822 if (mask[i]) {
2823 ptr[i] = (GLubyte) XDITHER( x, r, g, b );
2824 }
2825 }
2826 }
2827
2828
2829 /*
2830 * Write a span of identical 8-bit LOOKUP pixels to an XImage.
2831 */
2832 static void write_span_mono_LOOKUP8_ximage( MONO_SPAN_ARGS )
2833 {
2834 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2835 register GLuint i;
2836 register GLubyte *ptr = PIXELADDR1( xmesa->xm_buffer,x,y);
2837 GLubyte pixel;
2838 LOOKUP_SETUP;
2839 pixel = LOOKUP(color[RCOMP], color[GCOMP], color[BCOMP]);
2840 for (i=0;i<n;i++) {
2841 if (mask[i]) {
2842 ptr[i] = pixel;
2843 }
2844 }
2845 }
2846
2847
2848 /*
2849 * Write a span of identical PF_1BIT pixels to an XImage.
2850 */
2851 static void write_span_mono_1BIT_ximage( MONO_SPAN_ARGS )
2852 {
2853 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2854 const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
2855 XMesaImage *img = xmesa->xm_buffer->backimage;
2856 register GLuint i;
2857 SETUP_1BIT;
2858 y = FLIP(xmesa->xm_buffer, y);
2859 for (i=0;i<n;i++,x++) {
2860 if (mask[i]) {
2861 XMesaPutPixel( img, x, y, DITHER_1BIT( x, y, r, g, b ) );
2862 }
2863 }
2864 }
2865
2866
2867 /*
2868 * Write a span of identical HPCR pixels to an XImage.
2869 */
2870 static void write_span_mono_HPCR_ximage( MONO_SPAN_ARGS )
2871 {
2872 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2873 const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
2874 register GLubyte *ptr = PIXELADDR1( xmesa->xm_buffer,x,y);
2875 register GLuint i;
2876 for (i=0;i<n;i++,x++) {
2877 if (mask[i]) {
2878 ptr[i] = DITHER_HPCR( x, y, r, g, b );
2879 }
2880 }
2881 }
2882
2883
2884 /*
2885 * Write a span of identical 8-bit GRAYSCALE pixels to an XImage.
2886 */
2887 static void write_span_mono_GRAYSCALE8_ximage( MONO_SPAN_ARGS )
2888 {
2889 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2890 const GLubyte p = GRAY_RGB(color[RCOMP], color[GCOMP], color[BCOMP]);
2891 GLubyte *ptr = (GLubyte *) PIXELADDR1( xmesa->xm_buffer,x,y);
2892 GLuint i;
2893 for (i=0;i<n;i++) {
2894 if (mask[i]) {
2895 ptr[i] = p;
2896 }
2897 }
2898 }
2899
2900
2901
2902 /*
2903 * Write a span of identical PF_DITHER_5R6G5B pixels to an XImage.
2904 */
2905 static void write_span_mono_DITHER_5R6G5B_ximage( MONO_SPAN_ARGS )
2906 {
2907 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2908 register GLushort *ptr = PIXELADDR2( xmesa->xm_buffer, x, y );
2909 const GLint r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
2910 GLuint i;
2911 y = FLIP(xmesa->xm_buffer, y);
2912 for (i=0;i<n;i++) {
2913 if (mask[i]) {
2914 PACK_TRUEDITHER(ptr[i], x+i, y, r, g, b);
2915 }
2916 }
2917 }
2918
2919
2920
2921 /**********************************************************************/
2922 /*** Write MONO COLOR PIXELS functions ***/
2923 /**********************************************************************/
2924
2925 #define MONO_PIXEL_ARGS const GLcontext *ctx, \
2926 GLuint n, const GLint x[], const GLint y[], \
2927 const GLchan color[4], const GLubyte mask[]
2928
2929 /*
2930 * Write an array of identical pixels to a pixmap.
2931 */
2932 static void write_pixels_mono_pixmap( MONO_PIXEL_ARGS )
2933 {
2934 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2935 XMesaDisplay *dpy = xmesa->xm_visual->display;
2936 XMesaDrawable buffer = xmesa->xm_buffer->buffer;
2937 XMesaGC gc = xmesa->xm_buffer->gc;
2938 register GLuint i;
2939 const unsigned long pixel = xmesa_color_to_pixel(xmesa, color[RCOMP],
2940 color[GCOMP], color[BCOMP], color[ACOMP], xmesa->pixelformat);
2941 XMesaSetForeground( xmesa->display, gc, pixel );
2942 for (i=0;i<n;i++) {
2943 if (mask[i]) {
2944 XMesaDrawPoint( dpy, buffer, gc,
2945 (int) x[i], (int) FLIP(xmesa->xm_buffer, y[i]) );
2946 }
2947 }
2948 }
2949
2950
2951 static void write_pixels_mono_index_pixmap(const GLcontext *ctx,
2952 GLuint n,
2953 const GLint x[], const GLint y[],
2954 GLuint colorIndex,
2955 const GLubyte mask[] )
2956 {
2957 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2958 XMesaDisplay *dpy = xmesa->xm_visual->display;
2959 XMesaDrawable buffer = xmesa->xm_buffer->buffer;
2960 XMesaGC gc = xmesa->xm_buffer->gc;
2961 register GLuint i;
2962 XMesaSetForeground( xmesa->display, gc, colorIndex );
2963 for (i=0;i<n;i++) {
2964 if (mask[i]) {
2965 XMesaDrawPoint( dpy, buffer, gc,
2966 (int) x[i], (int) FLIP(xmesa->xm_buffer, y[i]) );
2967 }
2968 }
2969 }
2970
2971
2972 /*
2973 * Write an array of PF_TRUEDITHER pixels to a pixmap.
2974 */
2975 static void write_pixels_mono_TRUEDITHER_pixmap( MONO_PIXEL_ARGS )
2976 {
2977 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2978 XMesaDisplay *dpy = xmesa->xm_visual->display;
2979 XMesaDrawable buffer = xmesa->xm_buffer->buffer;
2980 XMesaGC gc = xmesa->xm_buffer->gc;
2981 register GLuint i;
2982 const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
2983 for (i=0;i<n;i++) {
2984 if (mask[i]) {
2985 unsigned long p;
2986 PACK_TRUEDITHER(p, x[i], y[i], r, g, b);
2987 XMesaSetForeground( dpy, gc, p );
2988 XMesaDrawPoint( dpy, buffer, gc,
2989 (int) x[i], (int) FLIP(xmesa->xm_buffer, y[i]) );
2990 }
2991 }
2992 }
2993
2994
2995 /*
2996 * Write an array of PF_DITHER pixels to a pixmap.
2997 */
2998 static void write_pixels_mono_DITHER_pixmap( MONO_PIXEL_ARGS )
2999 {
3000 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
3001 XMesaDisplay *dpy = xmesa->xm_visual->display;
3002 XMesaDrawable buffer = xmesa->xm_buffer->buffer;
3003 XMesaGC gc = xmesa->xm_buffer->gc;
3004 register GLuint i;
3005 const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
3006 DITHER_SETUP;
3007 for (i=0;i<n;i++) {
3008 if (mask[i]) {
3009 XMesaSetForeground( dpy, gc, DITHER( x[i], y[i], r, g, b ) );
3010 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) FLIP(xmesa->xm_buffer, y[i]) );
3011 }
3012 }
3013 }
3014
3015
3016 /*
3017 * Write an array of PF_1BIT pixels to a pixmap.
3018 */
3019 static void write_pixels_mono_1BIT_pixmap( MONO_PIXEL_ARGS )
3020 {
3021 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
3022 XMesaDisplay *dpy = xmesa->xm_visual->display;
3023 XMesaDrawable buffer = xmesa->xm_buffer->buffer;
3024 XMesaGC gc = xmesa->xm_buffer->gc;
3025 register GLuint i;
3026 const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
3027 SETUP_1BIT;
3028 for (i=0;i<n;i++) {
3029 if (mask[i]) {
3030 XMesaSetForeground( dpy, gc, DITHER_1BIT( x[i], y[i], r, g, b ) );
3031 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) FLIP(xmesa->xm_buffer, y[i]) );
3032 }
3033 }
3034 }
3035
3036
3037 /*
3038 * Write an array of identical pixels to an XImage.
3039 */
3040 static void write_pixels_mono_ximage( MONO_PIXEL_ARGS )
3041 {
3042 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
3043 XMesaImage *img = xmesa->xm_buffer->backimage;
3044 register GLuint i;
3045 const unsigned long pixel = xmesa_color_to_pixel(xmesa, color[RCOMP],
3046 color[GCOMP], color[BCOMP], color[ACOMP], xmesa->pixelformat);
3047 for (i=0;i<n;i++) {
3048 if (mask[i]) {
3049 XMesaPutPixel( img, x[i], FLIP(xmesa->xm_buffer, y[i]), pixel );
3050 }
3051 }
3052 }
3053
3054
3055 static void write_pixels_mono_index_ximage( const GLcontext *ctx, GLuint n,
3056 const GLint x[], const GLint y[],
3057 GLuint colorIndex,
3058 const GLubyte mask[] )
3059 {
3060 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
3061 XMesaImage *img = xmesa->xm_buffer->backimage;
3062 register GLuint i;
3063 for (i=0;i<n;i++) {
3064 if (mask[i]) {
3065 XMesaPutPixel( img, x[i], FLIP(xmesa->xm_buffer, y[i]), colorIndex );
3066 }
3067 }
3068 }
3069
3070
3071 /*
3072 * Write an array of identical TRUEDITHER pixels to an XImage.
3073 */
3074 static void write_pixels_mono_TRUEDITHER_ximage( MONO_PIXEL_ARGS )
3075 {
3076 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
3077 XMesaImage *img = xmesa->xm_buffer->backimage;
3078 register GLuint i;
3079 const int r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
3080 for (i=0;i<n;i++) {
3081 if (mask[i]) {
3082 unsigned long p;
3083 PACK_TRUEDITHER(p, x[i], FLIP(xmesa->xm_buffer, y[i]), r, g, b);
3084 XMesaPutPixel( img, x[i], FLIP(xmesa->xm_buffer, y[i]), p );
3085 }
3086 }
3087 }
3088
3089
3090
3091 /*
3092 * Write an array of identical 8A8B8G8R pixels to an XImage
3093 */
3094 static void write_pixels_mono_8A8B8G8R_ximage( MONO_PIXEL_ARGS )
3095 {
3096 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
3097 const GLuint p = PACK_8A8B8G8R(color[RCOMP], color[GCOMP],
3098 color[BCOMP], color[ACOMP]);
3099 register GLuint i;
3100 for (i=0;i<n;i++) {
3101 if (mask[i]) {
3102 GLuint *ptr = PIXELADDR4( xmesa->xm_buffer, x[i], y[i] );
3103 *ptr = p;
3104 }
3105 }
3106 }
3107
3108
3109 /*
3110 * Write an array of identical 8R8G8B pixels to an XImage.
3111 */
3112 static void write_pixels_mono_8R8G8B_ximage( MONO_PIXEL_ARGS )
3113 {
3114 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
3115 register GLuint i;
3116 const GLuint p = PACK_8R8G8B(color[RCOMP], color[GCOMP], color[BCOMP]);
3117 for (i=0;i<n;i++) {
3118 if (mask[i]) {
3119 GLuint *ptr = PIXELADDR4( xmesa->xm_buffer, x[i], y[i] );
3120 *ptr = p;
3121 }
3122 }
3123 }
3124
3125
3126 /*
3127 * Write an array of identical 8R8G8B pixels to an XImage.
3128 */
3129 static void write_pixels_mono_8R8G8B24_ximage( MONO_PIXEL_ARGS )
3130 {
3131 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
3132 const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
3133 register GLuint i;
3134 for (i=0;i<n;i++) {
3135 if (mask[i]) {
3136 bgr_t *ptr = PIXELADDR3( xmesa->xm_buffer, x[i], y[i] );
3137 ptr->r = r;
3138 ptr->g = g;
3139 ptr->b = b;
3140 }
3141 }
3142 }
3143
3144
3145 /*
3146 * Write an array of identical PF_DITHER pixels to an XImage.
3147 */
3148 static void write_pixels_mono_DITHER_ximage( MONO_PIXEL_ARGS )
3149 {
3150 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
3151 const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
3152 XMesaImage *img = xmesa->xm_buffer->backimage;
3153 register GLuint i;
3154 DITHER_SETUP;
3155 for (i=0;i<n;i++) {
3156 if (mask[i]) {
3157 XMesaPutPixel( img, x[i], FLIP(xmesa->xm_buffer, y[i]), DITHER( x[i], y[i], r, g, b ) );
3158 }
3159 }
3160 }
3161
3162
3163 /*
3164 * Write an array of identical 8-bit PF_DITHER pixels to an XImage.
3165 */
3166 static void write_pixels_mono_DITHER8_ximage( MONO_PIXEL_ARGS )
3167 {
3168 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
3169 const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
3170 register GLuint i;
3171 DITHER_SETUP;
3172 for (i=0;i<n;i++) {
3173 if (mask[i]) {
3174 GLubyte *ptr = PIXELADDR1( xmesa->xm_buffer,x[i],y[i]);
3175 *ptr = (GLubyte) DITHER( x[i], y[i], r, g, b );
3176 }
3177 }
3178 }
3179
3180
3181 /*
3182 * Write an array of identical 8-bit PF_LOOKUP pixels to an XImage.
3183 */
3184 static void write_pixels_mono_LOOKUP8_ximage( MONO_PIXEL_ARGS )
3185 {
3186 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
3187 register GLuint i;
3188 GLubyte pixel;
3189 LOOKUP_SETUP;
3190 pixel = LOOKUP(color[RCOMP], color[GCOMP], color[BCOMP]);
3191 for (i=0;i<n;i++) {
3192 if (mask[i]) {
3193 GLubyte *ptr = PIXELADDR1( xmesa->xm_buffer,x[i],y[i]);
3194 *ptr = pixel;
3195 }
3196 }
3197 }
3198
3199
3200
3201 /*
3202 * Write an array of identical PF_1BIT pixels to an XImage.
3203 */
3204 static void write_pixels_mono_1BIT_ximage( MONO_PIXEL_ARGS )
3205 {
3206 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
3207 const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
3208 XMesaImage *img = xmesa->xm_buffer->backimage;
3209 register GLuint i;
3210 SETUP_1BIT;
3211 for (i=0;i<n;i++) {
3212 if (mask[i]) {
3213 XMesaPutPixel( img, x[i], FLIP(xmesa->xm_buffer, y[i]),
3214 DITHER_1BIT( x[i], y[i], r, g, b ));
3215 }
3216 }
3217 }
3218
3219
3220 /*
3221 * Write an array of identical PF_HPCR pixels to an XImage.
3222 */
3223 static void write_pixels_mono_HPCR_ximage( MONO_PIXEL_ARGS )
3224 {
3225 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
3226 const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
3227 register GLuint i;
3228 for (i=0;i<n;i++) {
3229 if (mask[i]) {
3230 GLubyte *ptr = PIXELADDR1( xmesa->xm_buffer,x[i],y[i]);
3231 *ptr = DITHER_HPCR( x[i], y[i], r, g, b );
3232 }
3233 }
3234 }
3235
3236
3237 /*
3238 * Write an array of identical 8-bit PF_GRAYSCALE pixels to an XImage.
3239 */
3240 static void write_pixels_mono_GRAYSCALE8_ximage( MONO_PIXEL_ARGS )
3241 {
3242 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
3243 register GLuint i;
3244 register GLubyte p = GRAY_RGB(color[RCOMP], color[GCOMP], color[BCOMP]);
3245 for (i=0;i<n;i++) {
3246 if (mask[i]) {
3247 GLubyte *ptr = PIXELADDR1( xmesa->xm_buffer,x[i],y[i]);
3248 *ptr = p;
3249 }
3250 }
3251 }
3252
3253
3254 /*
3255 * Write an array of identical PF_DITHER_5R6G5B pixels to an XImage.
3256 */
3257 static void write_pixels_mono_DITHER_5R6G5B_ximage( MONO_PIXEL_ARGS )
3258 {
3259 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
3260 const int r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
3261 register GLuint i;
3262 for (i=0;i<n;i++) {
3263 if (mask[i]) {
3264 GLushort *ptr = PIXELADDR2( xmesa->xm_buffer, x[i], y[i] );
3265 PACK_TRUEDITHER(*ptr, x[i], y[i], r, g, b);
3266 }
3267 }
3268 }
3269
3270
3271
3272 /**********************************************************************/
3273 /*** Write INDEX SPAN functions ***/
3274 /**********************************************************************/
3275
3276 #define INDEX_SPAN_ARGS const GLcontext *ctx, \
3277 GLuint n, GLint x, GLint y, const GLuint index[], \
3278 const GLubyte mask[]
3279
3280 #define INDEX8_SPAN_ARGS const GLcontext *ctx, \
3281 GLuint n, GLint x, GLint y, const GLubyte index[], \
3282 const GLubyte mask[]
3283
3284
3285 /*
3286 * Write a span of CI pixels to a Pixmap.
3287 */
3288 static void write_span_index_pixmap( INDEX_SPAN_ARGS )
3289 {
3290 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
3291 XMesaDisplay *dpy = xmesa->xm_visual->display;
3292 XMesaDrawable buffer = xmesa->xm_buffer->buffer;
3293 XMesaGC gc = xmesa->xm_buffer->gc;
3294 register GLuint i;
3295 y = FLIP(xmesa->xm_buffer, y);
3296 if (mask) {
3297 for (i=0;i<n;i++,x++) {
3298 if (mask[i]) {
3299 XMesaSetForeground( dpy, gc, (unsigned long) index[i] );
3300 XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
3301 }
3302 }
3303 }
3304 else {
3305 for (i=0;i<n;i++,x++) {
3306 XMesaSetForeground( dpy, gc, (unsigned long) index[i] );
3307 XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
3308 }
3309 }
3310 }
3311
3312
3313 /*
3314 * Write a span of 8-bit CI pixels to a Pixmap.
3315 */
3316 static void write_span_index8_pixmap( INDEX8_SPAN_ARGS )
3317 {
3318 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
3319 XMesaDisplay *dpy = xmesa->xm_visual->display;
3320 XMesaDrawable buffer = xmesa->xm_buffer->buffer;
3321 XMesaGC gc = xmesa->xm_buffer->gc;
3322 register GLuint i;
3323 y = FLIP(xmesa->xm_buffer, y);
3324 if (mask) {
3325 for (i=0;i<n;i++,x++) {
3326 if (mask[i]) {
3327 XMesaSetForeground( dpy, gc, (unsigned long) index[i] );
3328 XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
3329 }
3330 }
3331 }
3332 else {
3333 for (i=0;i<n;i++,x++) {
3334 XMesaSetForeground( dpy, gc, (unsigned long) index[i] );
3335 XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
3336 }
3337 }
3338 }
3339
3340
3341 /*
3342 * Write a span of CI pixels to an XImage.
3343 */
3344 static void write_span_index_ximage( INDEX_SPAN_ARGS )
3345 {
3346 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
3347 XMesaImage *img = xmesa->xm_buffer->backimage;
3348 register GLuint i;
3349 y = FLIP(xmesa->xm_buffer, y);
3350 if (mask) {
3351 for (i=0;i<n;i++,x++) {
3352 if (mask[i]) {
3353 XMesaPutPixel( img, x, y, (unsigned long) index[i] );
3354 }
3355 }
3356 }
3357 else {
3358 for (i=0;i<n;i++,x++) {
3359 XMesaPutPixel( img, x, y, (unsigned long) index[i] );
3360 }
3361 }
3362 }
3363
3364
3365 /*
3366 * Write a span of 8-bit CI pixels to a non 8-bit XImage.
3367 */
3368 static void write_span_index8_ximage( INDEX8_SPAN_ARGS )
3369 {
3370 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
3371 if (mask) {
3372 GLuint i;
3373 for (i=0;i<n;i++) {
3374 if (mask[i]) {
3375 XMesaPutPixel(xmesa->xm_buffer->backimage, x+i, y, index[i]);
3376 }
3377 }
3378 }
3379 else {
3380 GLuint i;
3381 for (i=0;i<n;i++) {
3382 XMesaPutPixel(xmesa->xm_buffer->backimage, x+i, y, index[i]);
3383 }
3384 }
3385 }
3386
3387 /*
3388 * Write a span of 8-bit CI pixels to an 8-bit XImage.
3389 */
3390 static void write_span_index8_ximage8( INDEX8_SPAN_ARGS )
3391 {
3392 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
3393 GLubyte *dst = PIXELADDR1( xmesa->xm_buffer,x,y);
3394 if (mask) {
3395 GLuint i;
3396 for (i=0;i<n;i++) {
3397 if (mask[i]) {
3398 dst[i] = index[i];
3399 }
3400 }
3401 }
3402 else {
3403 MEMCPY( dst, index, n );
3404 }
3405 }
3406
3407
3408
3409 /**********************************************************************/
3410 /*** Write INDEX PIXELS functions ***/
3411 /**********************************************************************/
3412
3413 #define INDEX_PIXELS_ARGS const GLcontext *ctx, \
3414 GLuint n, const GLint x[], const GLint y[], \
3415 const GLuint index[], const GLubyte mask[]
3416
3417
3418 /*
3419 * Write an array of CI pixels to a Pixmap.
3420 */
3421 static void write_pixels_index_pixmap( INDEX_PIXELS_ARGS )
3422 {
3423 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
3424 XMesaDisplay *dpy = xmesa->xm_visual->display;
3425 XMesaDrawable buffer = xmesa->xm_buffer->buffer;
3426 XMesaGC gc = xmesa->xm_buffer->gc;
3427 register GLuint i;
3428 for (i=0;i<n;i++) {
3429 if (mask[i]) {
3430 XMesaSetForeground( dpy, gc, (unsigned long) index[i] );
3431 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) FLIP(xmesa->xm_buffer, y[i]) );
3432 }
3433 }
3434 }
3435
3436
3437 /*
3438 * Write an array of CI pixels to an XImage.
3439 */
3440 static void write_pixels_index_ximage( INDEX_PIXELS_ARGS )
3441 {
3442 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
3443 XMesaImage *img = xmesa->xm_buffer->backimage;
3444 register GLuint i;
3445 for (i=0;i<n;i++) {
3446 if (mask[i]) {
3447 XMesaPutPixel( img, x[i], FLIP(xmesa->xm_buffer, y[i]), (unsigned long) index[i] );
3448 }
3449 }
3450 }
3451
3452
3453
3454
3455 /**********************************************************************/
3456 /***** Pixel reading *****/
3457 /**********************************************************************/
3458
3459 #ifndef XFree86Server
3460 /**
3461 * Do clip testing prior to calling XGetImage. If any of the region lies
3462 * outside the screen's bounds, XGetImage will return NULL.
3463 * We use XTranslateCoordinates() to check if that's the case and
3464 * adjust the x, y and length parameters accordingly.
3465 * \return -1 if span is totally clipped away,
3466 * else return number of pixels to skip in the destination array.
3467 */
3468 static int
3469 clip_for_xgetimage(XMesaContext xmesa, GLuint *n, GLint *x, GLint *y)
3470 {
3471 XMesaBuffer source = xmesa->xm_buffer;
3472 Window rootWin = RootWindow(xmesa->display, 0);
3473 Window child;
3474 int screenWidth = WidthOfScreen(DefaultScreenOfDisplay(xmesa->display));
3475 int dx, dy;
3476 XTranslateCoordinates(xmesa->display, source->buffer, rootWin,
3477 *x, *y, &dx, &dy, &child);
3478 if (dx >= screenWidth) {
3479 /* totally clipped on right */
3480 return -1;
3481 }
3482 if (dx < 0) {
3483 /* clipped on left */
3484 int clip = -dx;
3485 if (clip >= *n)
3486 return -1; /* totally clipped on left */
3487 *x += clip;
3488 *n -= clip;
3489 dx = 0;
3490 return clip;
3491 }
3492 if (dx + *n > screenWidth) {
3493 /* clipped on right */
3494 int clip = dx + *n - screenWidth;
3495 *n -= clip;
3496 }
3497 return 0;
3498 }
3499 #endif
3500
3501
3502 /*
3503 * Read a horizontal span of color-index pixels.
3504 */
3505 static void read_index_span( const GLcontext *ctx,
3506 GLuint n, GLint x, GLint y, GLuint index[] )
3507 {
3508 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
3509 XMesaBuffer source = xmesa->xm_buffer;
3510 GLuint i;
3511
3512 y = FLIP(source, y);
3513
3514 if (source->buffer) {
3515 #ifndef XFree86Server
3516 XMesaImage *span = NULL;
3517 int error;
3518 int k = clip_for_xgetimage(xmesa, &n, &x, &y);
3519 if (k < 0)
3520 return;
3521 index += k;
3522
3523 catch_xgetimage_errors( xmesa->display );
3524 span = XGetImage( xmesa->display, source->buffer,
3525 x, y, n, 1, AllPlanes, ZPixmap );
3526 error = check_xgetimage_errors();
3527 if (span && !error) {
3528 for (i=0;i<n;i++) {
3529 index[i] = (GLuint) XMesaGetPixel( span, i, 0 );
3530 }
3531 }
3532 else {
3533 /* return 0 pixels */
3534 for (i=0;i<n;i++) {
3535 index[i] = 0;
3536 }
3537 }
3538 if (span) {
3539 XMesaDestroyImage( span );
3540 }
3541 #else
3542 (*xmesa->display->GetImage)(source->buffer,
3543 x, y, n, 1, ZPixmap,
3544 ~0L, (pointer)index);
3545 #endif
3546 }
3547 else if (source->backimage) {
3548 XMesaImage *img = source->backimage;
3549 for (i=0;i<n;i++,x++) {
3550 index[i] = (GLuint) XMesaGetPixel( img, x, y );
3551 }
3552 }
3553 }
3554
3555
3556
3557 /*
3558 * Read a horizontal span of color pixels.
3559 */
3560 static void read_color_span( const GLcontext *ctx,
3561 GLuint n, GLint x, GLint y,
3562 GLubyte rgba[][4] )
3563 {
3564 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
3565 XMesaBuffer source = xmesa->xm_buffer;
3566
3567 if (source->buffer) {
3568 /* Read from Pixmap or Window */
3569 XMesaImage *span = NULL;
3570 int error;
3571 #ifdef XFree86Server
3572 span = XMesaCreateImage(xmesa->xm_visual->BitsPerPixel, n, 1, NULL);
3573 span->data = (char *)MALLOC(span->height * span->bytes_per_line);
3574 error = (!span->data);
3575 (*xmesa->display->GetImage)(source->buffer,
3576 x, FLIP(source, y), n, 1, ZPixmap,
3577 ~0L, (pointer)span->data);
3578 #else
3579 int k;
3580 y = FLIP(source, y);
3581 k = clip_for_xgetimage(xmesa, &n, &x, &y);
3582 if (k < 0)
3583 return;
3584 rgba += k;
3585 catch_xgetimage_errors( xmesa->display );
3586 span = XGetImage( xmesa->display, source->buffer,
3587 x, y, n, 1, AllPlanes, ZPixmap );
3588 error = check_xgetimage_errors();
3589 #endif
3590 if (span && !error) {
3591 switch (xmesa->pixelformat) {
3592 case PF_Truecolor:
3593 case PF_Dither_True:
3594 {
3595 const GLubyte *pixelToR = xmesa->xm_visual->PixelToR;
3596 const GLubyte *pixelToG = xmesa->xm_visual->PixelToG;
3597 const GLubyte *pixelToB = xmesa->xm_visual->PixelToB;
3598 unsigned long rMask = GET_REDMASK(xmesa->xm_visual);
3599 unsigned long gMask = GET_GREENMASK(xmesa->xm_visual);
3600 unsigned long bMask = GET_BLUEMASK(xmesa->xm_visual);
3601 GLint rShift = xmesa->xm_visual->rshift;
3602 GLint gShift = xmesa->xm_visual->gshift;
3603 GLint bShift = xmesa->xm_visual->bshift;
3604 GLuint i;
3605 for (i=0;i<n;i++) {
3606 unsigned long p;
3607 p = XMesaGetPixel( span, i, 0 );
3608 rgba[i][RCOMP] = pixelToR[(p & rMask) >> rShift];
3609 rgba[i][GCOMP] = pixelToG[(p & gMask) >> gShift];
3610 rgba[i][BCOMP] = pixelToB[(p & bMask) >> bShift];
3611 rgba[i][ACOMP] = 255;
3612 }
3613 }
3614 break;
3615 case PF_5R6G5B:
3616 case PF_Dither_5R6G5B:
3617 {
3618 const GLubyte *pixelToR = xmesa->xm_visual->PixelToR;
3619 const GLubyte *pixelToG = xmesa->xm_visual->PixelToG;
3620 const GLubyte *pixelToB = xmesa->xm_visual->PixelToB;
3621 GLuint i;
3622 for (i=0;i<n;i++) {
3623 unsigned long p = XMesaGetPixel( span, i, 0 );
3624 /* fast, but not quite accurate
3625 rgba[i][RCOMP] = ((p >> 8) & 0xf8);
3626 rgba[i][GCOMP] = ((p >> 3) & 0xfc);
3627 rgba[i][BCOMP] = ((p << 3) & 0xff);
3628 */
3629 rgba[i][RCOMP] = pixelToR[p >> 11];
3630 rgba[i][GCOMP] = pixelToG[(p >> 5) & 0x3f];
3631 rgba[i][BCOMP] = pixelToB[p & 0x1f];
3632 rgba[i][ACOMP] = 255;
3633 }
3634 }
3635 break;
3636 case PF_8A8B8G8R:
3637 {
3638 const GLuint *ptr4 = (GLuint *) span->data;
3639 GLuint i;
3640 for (i=0;i<n;i++) {
3641 GLuint p4 = *ptr4++;
3642 rgba[i][RCOMP] = (GLubyte) ( p4 & 0xff);
3643 rgba[i][GCOMP] = (GLubyte) ((p4 >> 8) & 0xff);
3644 rgba[i][BCOMP] = (GLubyte) ((p4 >> 16) & 0xff);
3645 rgba[i][ACOMP] = (GLubyte) ((p4 >> 24) & 0xff);
3646 }
3647 }
3648 break;
3649 case PF_8R8G8B:
3650 {
3651 const GLuint *ptr4 = (GLuint *) span->data;
3652 GLuint i;
3653 for (i=0;i<n;i++) {
3654 GLuint p4 = *ptr4++;
3655 rgba[i][RCOMP] = (GLubyte) ((p4 >> 16) & 0xff);
3656 rgba[i][GCOMP] = (GLubyte) ((p4 >> 8) & 0xff);
3657 rgba[i][BCOMP] = (GLubyte) ( p4 & 0xff);
3658 rgba[i][ACOMP] = 255;
3659 }
3660 }
3661 break;
3662 case PF_8R8G8B24:
3663 {
3664 const bgr_t *ptr3 = (bgr_t *) span->data;
3665 GLuint i;
3666 for (i=0;i<n;i++) {
3667 rgba[i][RCOMP] = ptr3[i].r;
3668 rgba[i][GCOMP] = ptr3[i].g;
3669 rgba[i][BCOMP] = ptr3[i].b;
3670 rgba[i][ACOMP] = 255;
3671 }
3672 }
3673 break;
3674 case PF_HPCR:
3675 {
3676 GLubyte *ptr1 = (GLubyte *) span->data;
3677 GLuint i;
3678 for (i=0;i<n;i++) {
3679 GLubyte p = *ptr1++;
3680 rgba[i][RCOMP] = p & 0xE0;
3681 rgba[i][GCOMP] = (p & 0x1C) << 3;
3682 rgba[i][BCOMP] = (p & 0x03) << 6;
3683 rgba[i][ACOMP] = 255;
3684 }
3685 }
3686 break;
3687 case PF_Dither:
3688 case PF_Lookup:
3689 case PF_Grayscale:
3690 {
3691 GLubyte *rTable = source->pixel_to_r;
3692 GLubyte *gTable = source->pixel_to_g;
3693 GLubyte *bTable = source->pixel_to_b;
3694 if (GET_VISUAL_DEPTH(xmesa->xm_visual)==8) {
3695 const GLubyte *ptr1 = (GLubyte *) span->data;
3696 GLuint i;
3697 for (i=0;i<n;i++) {
3698 unsigned long p = *ptr1++;
3699 rgba[i][RCOMP] = rTable[p];
3700 rgba[i][GCOMP] = gTable[p];
3701 rgba[i][BCOMP] = bTable[p];
3702 rgba[i][ACOMP] = 255;
3703 }
3704 }
3705 else {
3706 GLuint i;
3707 for (i=0;i<n;i++) {
3708 unsigned long p = XMesaGetPixel( span, i, 0 );
3709 rgba[i][RCOMP] = rTable[p];
3710 rgba[i][GCOMP] = gTable[p];
3711 rgba[i][BCOMP] = bTable[p];
3712 rgba[i][ACOMP] = 255;
3713 }
3714 }
3715 }
3716 break;
3717 case PF_1Bit:
3718 {
3719 int bitFlip = xmesa->xm_visual->bitFlip;
3720 GLuint i;
3721 for (i=0;i<n;i++) {
3722 unsigned long p;
3723 p = XMesaGetPixel( span, i, 0 ) ^ bitFlip;
3724 rgba[i][RCOMP] = (GLubyte) (p * 255);
3725 rgba[i][GCOMP] = (GLubyte) (p * 255);
3726 rgba[i][BCOMP] = (GLubyte) (p * 255);
3727 rgba[i][ACOMP] = 255;
3728 }
3729 }
3730 break;
3731 default:
3732 _mesa_problem(NULL,"Problem in DD.read_color_span (1)");
3733 return;
3734 }
3735 }
3736 else {
3737 /* return black pixels */
3738 GLuint i;
3739 for (i=0;i<n;i++) {
3740 rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = rgba[i][ACOMP] = 0;
3741 }
3742 }
3743 if (span) {
3744 XMesaDestroyImage( span );
3745 }
3746 }
3747 else if (source->backimage) {
3748 /* Read from XImage back buffer */
3749 switch (xmesa->pixelformat) {
3750 case PF_Truecolor:
3751 case PF_Dither_True:
3752 {
3753 const GLubyte *pixelToR = xmesa->xm_visual->PixelToR;
3754 const GLubyte *pixelToG = xmesa->xm_visual->PixelToG;
3755 const GLubyte *pixelToB = xmesa->xm_visual->PixelToB;
3756 unsigned long rMask = GET_REDMASK(xmesa->xm_visual);
3757 unsigned long gMask = GET_GREENMASK(xmesa->xm_visual);
3758 unsigned long bMask = GET_BLUEMASK(xmesa->xm_visual);
3759 GLint rShift = xmesa->xm_visual->rshift;
3760 GLint gShift = xmesa->xm_visual->gshift;
3761 GLint bShift = xmesa->xm_visual->bshift;
3762 XMesaImage *img = source->backimage;
3763 GLuint i;
3764 y = FLIP(source, y);
3765 for (i=0;i<n;i++) {
3766 unsigned long p;
3767 p = XMesaGetPixel( img, x+i, y );
3768 rgba[i][RCOMP] = pixelToR[(p & rMask) >> rShift];
3769 rgba[i][GCOMP] = pixelToG[(p & gMask) >> gShift];
3770 rgba[i][BCOMP] = pixelToB[(p & bMask) >> bShift];
3771 rgba[i][ACOMP] = 255;
3772 }
3773 }
3774 break;
3775 case PF_5R6G5B:
3776 case PF_Dither_5R6G5B:
3777 {
3778 const GLubyte *pixelToR = xmesa->xm_visual->PixelToR;
3779 const GLubyte *pixelToG = xmesa->xm_visual->PixelToG;
3780 const GLubyte *pixelToB = xmesa->xm_visual->PixelToB;
3781 const GLushort *ptr2 = PIXELADDR2( source, x, y );
3782 GLuint i;
3783 #if defined(__i386__) /* word stores don't have to be on 4-byte boundaries */
3784 const GLuint *ptr4 = (const GLuint *) ptr2;
3785 GLuint extraPixel = (n & 1);
3786 n -= extraPixel;
3787 for (i = 0; i < n; i += 2) {
3788 const GLuint p = *ptr4++;
3789 const GLuint p0 = p & 0xffff;
3790 const GLuint p1 = p >> 16;
3791 /* fast, but not quite accurate
3792 rgba[i][RCOMP] = ((p >> 8) & 0xf8);
3793 rgba[i][GCOMP] = ((p >> 3) & 0xfc);
3794 rgba[i][BCOMP] = ((p << 3) & 0xff);
3795 */
3796 rgba[i][RCOMP] = pixelToR[p0 >> 11];
3797 rgba[i][GCOMP] = pixelToG[(p0 >> 5) & 0x3f];
3798 rgba[i][BCOMP] = pixelToB[p0 & 0x1f];
3799 rgba[i][ACOMP] = 255;
3800 rgba[i+1][RCOMP] = pixelToR[p1 >> 11];
3801 rgba[i+1][GCOMP] = pixelToG[(p1 >> 5) & 0x3f];
3802 rgba[i+1][BCOMP] = pixelToB[p1 & 0x1f];
3803 rgba[i+1][ACOMP] = 255;
3804 }
3805 if (extraPixel) {
3806 GLushort p = ptr2[n];
3807 rgba[n][RCOMP] = pixelToR[p >> 11];
3808 rgba[n][GCOMP] = pixelToG[(p >> 5) & 0x3f];
3809 rgba[n][BCOMP] = pixelToB[p & 0x1f];
3810 rgba[n][ACOMP] = 255;
3811 }
3812 #else
3813 for (i = 0; i < n; i++) {
3814 const GLushort p = ptr2[i];
3815 rgba[i][RCOMP] = pixelToR[p >> 11];
3816 rgba[i][GCOMP] = pixelToG[(p >> 5) & 0x3f];
3817 rgba[i][BCOMP] = pixelToB[p & 0x1f];
3818 rgba[i][ACOMP] = 255;
3819 }
3820 #endif
3821 }
3822 break;
3823 case PF_8A8B8G8R:
3824 {
3825 const GLuint *ptr4 = PIXELADDR4( source, x, y );
3826 GLuint i;
3827 for (i=0;i<n;i++) {
3828 GLuint p4 = *ptr4++;
3829 rgba[i][RCOMP] = (GLubyte) ( p4 & 0xff);
3830 rgba[i][GCOMP] = (GLubyte) ((p4 >> 8) & 0xff);
3831 rgba[i][BCOMP] = (GLubyte) ((p4 >> 16) & 0xff);
3832 rgba[i][ACOMP] = (GLint) ((p4 >> 24) & 0xff);
3833 }
3834 }
3835 break;
3836 case PF_8R8G8B:
3837 {
3838 const GLuint *ptr4 = PIXELADDR4( source, x, y );
3839 GLuint i;
3840 for (i=0;i<n;i++) {
3841 GLuint p4 = *ptr4++;
3842 rgba[i][RCOMP] = (GLubyte) ((p4 >> 16) & 0xff);
3843 rgba[i][GCOMP] = (GLubyte) ((p4 >> 8) & 0xff);
3844 rgba[i][BCOMP] = (GLubyte) ( p4 & 0xff);
3845 rgba[i][ACOMP] = 255;
3846 }
3847 }
3848 break;
3849 case PF_8R8G8B24:
3850 {
3851 const bgr_t *ptr3 = PIXELADDR3( source, x, y );
3852 GLuint i;
3853 for (i=0;i<n;i++) {
3854 rgba[i][RCOMP] = ptr3[i].r;
3855 rgba[i][GCOMP] = ptr3[i].g;
3856 rgba[i][BCOMP] = ptr3[i].b;
3857 rgba[i][ACOMP] = 255;
3858 }
3859 }
3860 break;
3861 case PF_HPCR:
3862 {
3863 const GLubyte *ptr1 = PIXELADDR1( source, x, y );
3864 GLuint i;
3865 for (i=0;i<n;i++) {
3866 GLubyte p = *ptr1++;
3867 rgba[i][RCOMP] = p & 0xE0;
3868 rgba[i][GCOMP] = (p & 0x1C) << 3;
3869 rgba[i][BCOMP] = (p & 0x03) << 6;
3870 rgba[i][ACOMP] = 255;
3871 }
3872 }
3873 break;
3874 case PF_Dither:
3875 case PF_Lookup:
3876 case PF_Grayscale:
3877 {
3878 const GLubyte *rTable = source->pixel_to_r;
3879 const GLubyte *gTable = source->pixel_to_g;
3880 const GLubyte *bTable = source->pixel_to_b;
3881 if (GET_VISUAL_DEPTH(xmesa->xm_visual)==8) {
3882 GLubyte *ptr1 = PIXELADDR1( source, x, y );
3883 GLuint i;
3884 for (i=0;i<n;i++) {
3885 unsigned long p = *ptr1++;
3886 rgba[i][RCOMP] = rTable[p];
3887 rgba[i][GCOMP] = gTable[p];
3888 rgba[i][BCOMP] = bTable[p];
3889 rgba[i][ACOMP] = 255;
3890 }
3891 }
3892 else {
3893 XMesaImage *img = source->backimage;
3894 GLuint i;
3895 y = FLIP(source, y);
3896 for (i=0;i<n;i++,x++) {
3897 unsigned long p = XMesaGetPixel( img, x, y );
3898 rgba[i][RCOMP] = rTable[p];
3899 rgba[i][GCOMP] = gTable[p];
3900 rgba[i][BCOMP] = bTable[p];
3901 rgba[i][ACOMP] = 255;
3902 }
3903 }
3904 }
3905 break;
3906 case PF_1Bit:
3907 {
3908 XMesaImage *img = source->backimage;
3909 int bitFlip = xmesa->xm_visual->bitFlip;
3910 GLuint i;
3911 y = FLIP(source, y);
3912 for (i=0;i<n;i++,x++) {
3913 unsigned long p;
3914 p = XMesaGetPixel( img, x, y ) ^ bitFlip;
3915 rgba[i][RCOMP] = (GLubyte) (p * 255);
3916 rgba[i][GCOMP] = (GLubyte) (p * 255);
3917 rgba[i][BCOMP] = (GLubyte) (p * 255);
3918 rgba[i][ACOMP] = 255;
3919 }
3920 }
3921 break;
3922 default:
3923 _mesa_problem(NULL,"Problem in DD.read_color_span (2)");
3924 return;
3925 }
3926 }
3927 }
3928
3929
3930
3931 /*
3932 * Read an array of color index pixels.
3933 */
3934 static void read_index_pixels( const GLcontext *ctx,
3935 GLuint n, const GLint x[], const GLint y[],
3936 GLuint indx[], const GLubyte mask[] )
3937 {
3938 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
3939 register GLuint i;
3940 XMesaBuffer source = xmesa->xm_buffer;
3941
3942 if (source->buffer) {
3943 for (i=0;i<n;i++) {
3944 if (mask[i]) {
3945 indx[i] = (GLuint) read_pixel( xmesa->display,
3946 source->buffer,
3947 x[i], FLIP(source, y[i]) );
3948 }
3949 }
3950 }
3951 else if (source->backimage) {
3952 XMesaImage *img = source->backimage;
3953 for (i=0;i<n;i++) {
3954 if (mask[i]) {
3955 indx[i] = (GLuint) XMesaGetPixel( img, x[i], FLIP(source, y[i]) );
3956 }
3957 }
3958 }
3959 }
3960
3961
3962
3963 static void read_color_pixels( const GLcontext *ctx,
3964 GLuint n, const GLint x[], const GLint y[],
3965 GLubyte rgba[][4], const GLubyte mask[] )
3966 {
3967 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
3968 XMesaDisplay *dpy = xmesa->xm_visual->display;
3969 register GLuint i;
3970 XMesaBuffer source = xmesa->xm_buffer;
3971 XMesaDrawable buffer = source->buffer; /* the X drawable */
3972
3973 if (source->buffer) {
3974 switch (xmesa->pixelformat) {
3975 case PF_Truecolor:
3976 case PF_Dither_True:
3977 case PF_5R6G5B:
3978 case PF_Dither_5R6G5B:
3979 {
3980 unsigned long rMask = GET_REDMASK(xmesa->xm_visual);
3981 unsigned long gMask = GET_GREENMASK(xmesa->xm_visual);
3982 unsigned long bMask = GET_BLUEMASK(xmesa->xm_visual);
3983 GLubyte *pixelToR = xmesa->xm_visual->PixelToR;
3984 GLubyte *pixelToG = xmesa->xm_visual->PixelToG;
3985 GLubyte *pixelToB = xmesa->xm_visual->PixelToB;
3986 GLint rShift = xmesa->xm_visual->rshift;
3987 GLint gShift = xmesa->xm_visual->gshift;
3988 GLint bShift = xmesa->xm_visual->bshift;
3989 for (i=0;i<n;i++) {
3990 if (mask[i]) {
3991 unsigned long p = read_pixel( dpy, buffer,
3992 x[i], FLIP(source, y[i]) );
3993 rgba[i][RCOMP] = pixelToR[(p & rMask) >> rShift];
3994 rgba[i][GCOMP] = pixelToG[(p & gMask) >> gShift];
3995 rgba[i][BCOMP] = pixelToB[(p & bMask) >> bShift];
3996 rgba[i][ACOMP] = 255;
3997 }
3998 }
3999 }
4000 break;
4001 case PF_8A8B8G8R:
4002 for (i=0;i<n;i++) {
4003 if (mask[i]) {
4004 unsigned long p = read_pixel( dpy, buffer,
4005 x[i], FLIP(source, y[i]) );
4006 rgba[i][RCOMP] = (GLubyte) ( p & 0xff);
4007 rgba[i][GCOMP] = (GLubyte) ((p >> 8) & 0xff);
4008 rgba[i][BCOMP] = (GLubyte) ((p >> 16) & 0xff);
4009 rgba[i][ACOMP] = (GLubyte) ((p >> 24) & 0xff);
4010 }
4011 }
4012 break;
4013 case PF_8R8G8B:
4014 for (i=0;i<n;i++) {
4015 if (mask[i]) {
4016 unsigned long p = read_pixel( dpy, buffer,
4017 x[i], FLIP(source, y[i]) );
4018 rgba[i][RCOMP] = (GLubyte) ((p >> 16) & 0xff);
4019 rgba[i][GCOMP] = (GLubyte) ((p >> 8) & 0xff);
4020 rgba[i][BCOMP] = (GLubyte) ( p & 0xff);
4021 rgba[i][ACOMP] = 255;
4022 }
4023 }
4024 break;
4025 case PF_8R8G8B24:
4026 for (i=0;i<n;i++) {
4027 if (mask[i]) {
4028 unsigned long p = read_pixel( dpy, buffer,
4029 x[i], FLIP(source, y[i]) );
4030 rgba[i][RCOMP] = (GLubyte) ((p >> 16) & 0xff);
4031 rgba[i][GCOMP] = (GLubyte) ((p >> 8) & 0xff);
4032 rgba[i][BCOMP] = (GLubyte) ( p & 0xff);
4033 rgba[i][ACOMP] = 255;
4034 }
4035 }
4036 break;
4037 case PF_HPCR:
4038 {
4039 for (i=0;i<n;i++) {
4040 if (mask[i]) {
4041 unsigned long p = read_pixel( dpy, buffer,
4042 x[i], FLIP(source, y[i]) );
4043 rgba[i][RCOMP] = (GLubyte) ( p & 0xE0 );
4044 rgba[i][GCOMP] = (GLubyte) ((p & 0x1C) << 3);
4045 rgba[i][BCOMP] = (GLubyte) ((p & 0x03) << 6);
4046 rgba[i][ACOMP] = (GLubyte) 255;
4047 }
4048 }
4049 }
4050 break;
4051 case PF_Dither:
4052 case PF_Lookup:
4053 case PF_Grayscale:
4054 {
4055 GLubyte *rTable = source->pixel_to_r;
4056 GLubyte *gTable = source->pixel_to_g;
4057 GLubyte *bTable = source->pixel_to_b;
4058 for (i=0;i<n;i++) {
4059 if (mask[i]) {
4060 unsigned long p = read_pixel( dpy, buffer,
4061 x[i], FLIP(source, y[i]) );
4062 rgba[i][RCOMP] = rTable[p];
4063 rgba[i][GCOMP] = gTable[p];
4064 rgba[i][BCOMP] = bTable[p];
4065 rgba[i][ACOMP] = 255;
4066 }
4067 }
4068 }
4069 break;
4070 case PF_1Bit:
4071 {
4072 int bitFlip = xmesa->xm_visual->bitFlip;
4073 for (i=0;i<n;i++) {
4074 if (mask[i]) {
4075 unsigned long p = read_pixel( dpy, buffer,
4076 x[i], FLIP(source, y[i])) ^ bitFlip;
4077 rgba[i][RCOMP] = (GLubyte) (p * 255);
4078 rgba[i][GCOMP] = (GLubyte) (p * 255);
4079 rgba[i][BCOMP] = (GLubyte) (p * 255);
4080 rgba[i][ACOMP] = 255;
4081 }
4082 }
4083 }
4084 break;
4085 default:
4086 _mesa_problem(NULL,"Problem in DD.read_color_pixels (1)");
4087 return;
4088 }
4089 }
4090 else if (source->backimage) {
4091 switch (xmesa->pixelformat) {
4092 case PF_Truecolor:
4093 case PF_Dither_True:
4094 case PF_5R6G5B:
4095 case PF_Dither_5R6G5B:
4096 {
4097 unsigned long rMask = GET_REDMASK(xmesa->xm_visual);
4098 unsigned long gMask = GET_GREENMASK(xmesa->xm_visual);
4099 unsigned long bMask = GET_BLUEMASK(xmesa->xm_visual);
4100 GLubyte *pixelToR = xmesa->xm_visual->PixelToR;
4101 GLubyte *pixelToG = xmesa->xm_visual->PixelToG;
4102 GLubyte *pixelToB = xmesa->xm_visual->PixelToB;
4103 GLint rShift = xmesa->xm_visual->rshift;
4104 GLint gShift = xmesa->xm_visual->gshift;
4105 GLint bShift = xmesa->xm_visual->bshift;
4106 XMesaImage *img = source->backimage;
4107 for (i=0;i<n;i++) {
4108 if (mask[i]) {
4109 unsigned long p;
4110 p = XMesaGetPixel( img, x[i], FLIP(source, y[i]) );
4111 rgba[i][RCOMP] = pixelToR[(p & rMask) >> rShift];
4112 rgba[i][GCOMP] = pixelToG[(p & gMask) >> gShift];
4113 rgba[i][BCOMP] = pixelToB[(p & bMask) >> bShift];
4114 rgba[i][ACOMP] = 255;
4115 }
4116 }
4117 }
4118 break;
4119 case PF_8A8B8G8R:
4120 for (i=0;i<n;i++) {
4121 if (mask[i]) {
4122 GLuint *ptr4 = PIXELADDR4( source, x[i], y[i] );
4123 GLuint p4 = *ptr4;
4124 rgba[i][RCOMP] = (GLubyte) ( p4 & 0xff);
4125 rgba[i][GCOMP] = (GLubyte) ((p4 >> 8) & 0xff);
4126 rgba[i][BCOMP] = (GLubyte) ((p4 >> 16) & 0xff);
4127 rgba[i][ACOMP] = (GLubyte) ((p4 >> 24) & 0xff);
4128 }
4129 }
4130 break;
4131 case PF_8R8G8B:
4132 for (i=0;i<n;i++) {
4133 if (mask[i]) {
4134 GLuint *ptr4 = PIXELADDR4( source, x[i], y[i] );
4135 GLuint p4 = *ptr4;
4136 rgba[i][RCOMP] = (GLubyte) ((p4 >> 16) & 0xff);
4137 rgba[i][GCOMP] = (GLubyte) ((p4 >> 8) & 0xff);
4138 rgba[i][BCOMP] = (GLubyte) ( p4 & 0xff);
4139 rgba[i][ACOMP] = 255;
4140 }
4141 }
4142 break;
4143 case PF_8R8G8B24:
4144 for (i=0;i<n;i++) {
4145 if (mask[i]) {
4146 bgr_t *ptr3 = PIXELADDR3( source, x[i], y[i] );
4147 rgba[i][RCOMP] = ptr3->r;
4148 rgba[i][GCOMP] = ptr3->g;
4149 rgba[i][BCOMP] = ptr3->b;
4150 rgba[i][ACOMP] = 255;
4151 }
4152 }
4153 break;
4154 case PF_HPCR:
4155 for (i=0;i<n;i++) {
4156 if (mask[i]) {
4157 GLubyte *ptr1 = PIXELADDR1( source, x[i], y[i] );
4158 GLubyte p = *ptr1;
4159 rgba[i][RCOMP] = p & 0xE0;
4160 rgba[i][GCOMP] = (p & 0x1C) << 3;
4161 rgba[i][BCOMP] = (p & 0x03) << 6;
4162 rgba[i][ACOMP] = 255;
4163 }
4164 }
4165 break;
4166 case PF_Dither:
4167 case PF_Lookup:
4168 case PF_Grayscale:
4169 {
4170 GLubyte *rTable = source->pixel_to_r;
4171 GLubyte *gTable = source->pixel_to_g;
4172 GLubyte *bTable = source->pixel_to_b;
4173 XMesaImage *img = source->backimage;
4174 for (i=0;i<n;i++) {
4175 if (mask[i]) {
4176 unsigned long p;
4177 p = XMesaGetPixel( img, x[i], FLIP(source, y[i]) );
4178 rgba[i][RCOMP] = rTable[p];
4179 rgba[i][GCOMP] = gTable[p];
4180 rgba[i][BCOMP] = bTable[p];
4181 rgba[i][ACOMP] = 255;
4182 }
4183 }
4184 }
4185 break;
4186 case PF_1Bit:
4187 {
4188 XMesaImage *img = source->backimage;
4189 int bitFlip = xmesa->xm_visual->bitFlip;
4190 for (i=0;i<n;i++) {
4191 if (mask[i]) {
4192 unsigned long p;
4193 p = XMesaGetPixel( img, x[i], FLIP(source, y[i]) ) ^ bitFlip;
4194 rgba[i][RCOMP] = (GLubyte) (p * 255);
4195 rgba[i][GCOMP] = (GLubyte) (p * 255);
4196 rgba[i][BCOMP] = (GLubyte) (p * 255);
4197 rgba[i][ACOMP] = 255;
4198 }
4199 }
4200 }
4201 break;
4202 default:
4203 _mesa_problem(NULL,"Problem in DD.read_color_pixels (1)");
4204 return;
4205 }
4206 }
4207 }
4208
4209
4210 static void
4211 clear_color_HPCR_ximage( GLcontext *ctx, const GLfloat color[4] )
4212 {
4213 int i;
4214 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
4215
4216 CLAMPED_FLOAT_TO_UBYTE(xmesa->clearcolor[0], color[0]);
4217 CLAMPED_FLOAT_TO_UBYTE(xmesa->clearcolor[1], color[1]);
4218 CLAMPED_FLOAT_TO_UBYTE(xmesa->clearcolor[2], color[2]);
4219 CLAMPED_FLOAT_TO_UBYTE(xmesa->clearcolor[3], color[3]);
4220
4221 if (color[0] == 0.0 && color[1] == 0.0 && color[2] == 0.0) {
4222 /* black is black */
4223 MEMSET( xmesa->xm_visual->hpcr_clear_ximage_pattern, 0x0 ,
4224 sizeof(xmesa->xm_visual->hpcr_clear_ximage_pattern));
4225 }
4226 else {
4227 /* build clear pattern */
4228 for (i=0; i<16; i++) {
4229 xmesa->xm_visual->hpcr_clear_ximage_pattern[0][i] =
4230 DITHER_HPCR(i, 0,
4231 xmesa->clearcolor[0],
4232 xmesa->clearcolor[1],
4233 xmesa->clearcolor[2]);
4234 xmesa->xm_visual->hpcr_clear_ximage_pattern[1][i] =
4235 DITHER_HPCR(i, 1,
4236 xmesa->clearcolor[0],
4237 xmesa->clearcolor[1],
4238 xmesa->clearcolor[2]);
4239 }
4240 }
4241 }
4242
4243
4244 static void
4245 clear_color_HPCR_pixmap( GLcontext *ctx, const GLfloat color[4] )
4246 {
4247 int i;
4248 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
4249
4250 CLAMPED_FLOAT_TO_UBYTE(xmesa->clearcolor[0], color[0]);
4251 CLAMPED_FLOAT_TO_UBYTE(xmesa->clearcolor[1], color[1]);
4252 CLAMPED_FLOAT_TO_UBYTE(xmesa->clearcolor[2], color[2]);
4253 CLAMPED_FLOAT_TO_UBYTE(xmesa->clearcolor[3], color[3]);
4254
4255 if (color[0] == 0.0 && color[1] == 0.0 && color[2] == 0.0) {
4256 /* black is black */
4257 for (i=0; i<16; i++) {
4258 XMesaPutPixel(xmesa->xm_visual->hpcr_clear_ximage, i, 0, 0);
4259 XMesaPutPixel(xmesa->xm_visual->hpcr_clear_ximage, i, 1, 0);
4260 }
4261 }
4262 else {
4263 for (i=0; i<16; i++) {
4264 XMesaPutPixel(xmesa->xm_visual->hpcr_clear_ximage, i, 0,
4265 DITHER_HPCR(i, 0,
4266 xmesa->clearcolor[0],
4267 xmesa->clearcolor[1],
4268 xmesa->clearcolor[2]));
4269 XMesaPutPixel(xmesa->xm_visual->hpcr_clear_ximage, i, 1,
4270 DITHER_HPCR(i, 1,
4271 xmesa->clearcolor[0],
4272 xmesa->clearcolor[1],
4273 xmesa->clearcolor[2]));
4274 }
4275 }
4276 /* change tile pixmap content */
4277 XMesaPutImage(xmesa->display,
4278 (XMesaDrawable)xmesa->xm_visual->hpcr_clear_pixmap,
4279 xmesa->xm_buffer->cleargc,
4280 xmesa->xm_visual->hpcr_clear_ximage, 0, 0, 0, 0, 16, 2);
4281 }
4282
4283
4284
4285 void xmesa_update_span_funcs( GLcontext *ctx )
4286 {
4287 XMesaContext xmesa = XMESA_CONTEXT(ctx);
4288 int depth=GET_VISUAL_DEPTH(xmesa->xm_visual);
4289 struct swrast_device_driver *dd = _swrast_GetDeviceDriverReference( ctx );
4290
4291 /*
4292 * These drawing functions depend on color buffer config:
4293 */
4294 if (xmesa->xm_buffer->buffer!=XIMAGE) {
4295 /* Writing to window or back pixmap */
4296 switch (xmesa->pixelformat) {
4297 case PF_Index:
4298 dd->WriteCI32Span = write_span_index_pixmap;
4299 dd->WriteCI8Span = write_span_index8_pixmap;
4300 dd->WriteMonoCISpan = write_span_mono_index_pixmap;
4301 dd->WriteCI32Pixels = write_pixels_index_pixmap;
4302 dd->WriteMonoCIPixels = write_pixels_mono_index_pixmap;
4303 break;
4304 case PF_Truecolor:
4305 dd->WriteRGBASpan = write_span_TRUECOLOR_pixmap;
4306 dd->WriteRGBSpan = write_span_rgb_TRUECOLOR_pixmap;
4307 dd->WriteMonoRGBASpan = write_span_mono_pixmap;
4308 dd->WriteRGBAPixels = write_pixels_TRUECOLOR_pixmap;
4309 dd->WriteMonoRGBAPixels = write_pixels_mono_pixmap;
4310 break;
4311 case PF_Dither_True:
4312 dd->WriteRGBASpan = write_span_TRUEDITHER_pixmap;
4313 dd->WriteRGBSpan = write_span_rgb_TRUEDITHER_pixmap;
4314 dd->WriteMonoRGBASpan = write_span_mono_TRUEDITHER_pixmap;
4315 dd->WriteRGBAPixels = write_pixels_TRUEDITHER_pixmap;
4316 dd->WriteMonoRGBAPixels = write_pixels_mono_TRUEDITHER_pixmap;
4317 break;
4318 case PF_8A8B8G8R:
4319 dd->WriteRGBASpan = write_span_8A8B8G8R_pixmap;
4320 dd->WriteRGBSpan = write_span_rgb_8A8B8G8R_pixmap;
4321 dd->WriteMonoRGBASpan = write_span_mono_pixmap;
4322 dd->WriteRGBAPixels = write_pixels_8A8B8G8R_pixmap;
4323 dd->WriteMonoRGBAPixels = write_pixels_mono_pixmap;
4324 break;
4325 case PF_8R8G8B:
4326 dd->WriteRGBASpan = write_span_8R8G8B_pixmap;
4327 dd->WriteRGBSpan = write_span_rgb_8R8G8B_pixmap;
4328 dd->WriteMonoRGBASpan = write_span_mono_pixmap;
4329 dd->WriteRGBAPixels = write_pixels_8R8G8B_pixmap;
4330 dd->WriteMonoRGBAPixels = write_pixels_mono_pixmap;
4331 break;
4332 case PF_8R8G8B24:
4333 dd->WriteRGBASpan = write_span_8R8G8B24_pixmap;
4334 dd->WriteRGBSpan = write_span_rgb_8R8G8B24_pixmap;
4335 dd->WriteMonoRGBASpan = write_span_mono_pixmap;
4336 dd->WriteRGBAPixels = write_pixels_8R8G8B24_pixmap;
4337 dd->WriteMonoRGBAPixels = write_pixels_mono_pixmap;
4338 break;
4339 case PF_5R6G5B:
4340 dd->WriteRGBASpan = write_span_5R6G5B_pixmap;
4341 dd->WriteRGBSpan = write_span_rgb_5R6G5B_pixmap;
4342 dd->WriteMonoRGBASpan = write_span_mono_pixmap;
4343 dd->WriteRGBAPixels = write_pixels_5R6G5B_pixmap;
4344 dd->WriteMonoRGBAPixels = write_pixels_mono_pixmap;
4345 break;
4346 case PF_Dither_5R6G5B:
4347 dd->WriteRGBASpan = write_span_DITHER_5R6G5B_pixmap;
4348 dd->WriteRGBSpan = write_span_rgb_DITHER_5R6G5B_pixmap;
4349 dd->WriteMonoRGBASpan = write_span_mono_TRUEDITHER_pixmap;
4350 dd->WriteRGBAPixels = write_pixels_DITHER_5R6G5B_pixmap;
4351 dd->WriteMonoRGBAPixels = write_pixels_mono_TRUEDITHER_pixmap;
4352 break;
4353 case PF_Dither:
4354 dd->WriteRGBASpan = write_span_DITHER_pixmap;
4355 dd->WriteRGBSpan = write_span_rgb_DITHER_pixmap;
4356 dd->WriteMonoRGBASpan = write_span_mono_DITHER_pixmap;
4357 dd->WriteRGBAPixels = write_pixels_DITHER_pixmap;
4358 dd->WriteMonoRGBAPixels = write_pixels_mono_DITHER_pixmap;
4359 break;
4360 case PF_1Bit:
4361 dd->WriteRGBASpan = write_span_1BIT_pixmap;
4362 dd->WriteRGBSpan = write_span_rgb_1BIT_pixmap;
4363 dd->WriteMonoRGBASpan = write_span_mono_1BIT_pixmap;
4364 dd->WriteRGBAPixels = write_pixels_1BIT_pixmap;
4365 dd->WriteMonoRGBAPixels = write_pixels_mono_1BIT_pixmap;
4366 break;
4367 case PF_HPCR:
4368 dd->WriteRGBASpan = write_span_HPCR_pixmap;
4369 dd->WriteRGBSpan = write_span_rgb_HPCR_pixmap;
4370 dd->WriteMonoRGBASpan = write_span_mono_pixmap;
4371 dd->WriteRGBAPixels = write_pixels_HPCR_pixmap;
4372 dd->WriteMonoRGBAPixels = write_pixels_mono_pixmap;
4373 if (xmesa->xm_visual->hpcr_clear_flag) {
4374 ctx->Driver.ClearColor = clear_color_HPCR_pixmap;
4375 }
4376 break;
4377 case PF_Lookup:
4378 dd->WriteRGBASpan = write_span_LOOKUP_pixmap;
4379 dd->WriteRGBSpan = write_span_rgb_LOOKUP_pixmap;
4380 dd->WriteMonoRGBASpan = write_span_mono_pixmap;
4381 dd->WriteRGBAPixels = write_pixels_LOOKUP_pixmap;
4382 dd->WriteMonoRGBAPixels = write_pixels_mono_pixmap;
4383 break;
4384 case PF_Grayscale:
4385 dd->WriteRGBASpan = write_span_GRAYSCALE_pixmap;
4386 dd->WriteRGBSpan = write_span_rgb_GRAYSCALE_pixmap;
4387 dd->WriteMonoRGBASpan = write_span_mono_pixmap;
4388 dd->WriteRGBAPixels = write_pixels_GRAYSCALE_pixmap;
4389 dd->WriteMonoRGBAPixels = write_pixels_mono_pixmap;
4390 break;
4391 default:
4392 _mesa_problem(NULL,"Bad pixel format in xmesa_update_state (1)");
4393 return;
4394 }
4395 }
4396 else if (xmesa->xm_buffer->buffer==XIMAGE) {
4397 /* Writing to back XImage */
4398 switch (xmesa->pixelformat) {
4399 case PF_Index:
4400 dd->WriteCI32Span = write_span_index_ximage;
4401 if (depth==8)
4402 dd->WriteCI8Span = write_span_index8_ximage8;
4403 else
4404 dd->WriteCI8Span = write_span_index8_ximage;
4405 dd->WriteMonoCISpan = write_span_mono_index_ximage;
4406 dd->WriteCI32Pixels = write_pixels_index_ximage;
4407 dd->WriteMonoCIPixels = write_pixels_mono_index_ximage;
4408 break;
4409 case PF_Truecolor:
4410 /* Generic RGB */
4411 dd->WriteRGBASpan = write_span_TRUECOLOR_ximage;
4412 dd->WriteRGBSpan = write_span_rgb_TRUECOLOR_ximage;
4413 dd->WriteMonoRGBASpan = write_span_mono_ximage;
4414 dd->WriteRGBAPixels = write_pixels_TRUECOLOR_ximage;
4415 dd->WriteMonoRGBAPixels = write_pixels_mono_ximage;
4416 break;
4417 case PF_Dither_True:
4418 dd->WriteRGBASpan = write_span_TRUEDITHER_ximage;
4419 dd->WriteRGBSpan = write_span_rgb_TRUEDITHER_ximage;
4420 dd->WriteMonoRGBASpan = write_span_mono_TRUEDITHER_ximage;
4421 dd->WriteRGBAPixels = write_pixels_TRUEDITHER_ximage;
4422 dd->WriteMonoRGBAPixels = write_pixels_mono_TRUEDITHER_ximage;
4423 break;
4424 case PF_8A8B8G8R:
4425 dd->WriteRGBASpan = write_span_8A8B8G8R_ximage;
4426 dd->WriteRGBSpan = write_span_rgb_8A8B8G8R_ximage;
4427 dd->WriteMonoRGBASpan = write_span_mono_8A8B8G8R_ximage;
4428 dd->WriteRGBAPixels = write_pixels_8A8B8G8R_ximage;
4429 dd->WriteMonoRGBAPixels = write_pixels_mono_8A8B8G8R_ximage;
4430 break;
4431 case PF_8R8G8B:
4432 dd->WriteRGBASpan = write_span_8R8G8B_ximage;
4433 dd->WriteRGBSpan = write_span_rgb_8R8G8B_ximage;
4434 dd->WriteMonoRGBASpan = write_span_mono_8R8G8B_ximage;
4435 dd->WriteRGBAPixels = write_pixels_8R8G8B_ximage;
4436 dd->WriteMonoRGBAPixels = write_pixels_mono_8R8G8B_ximage;
4437 break;
4438 case PF_8R8G8B24:
4439 dd->WriteRGBASpan = write_span_8R8G8B24_ximage;
4440 dd->WriteRGBSpan = write_span_rgb_8R8G8B24_ximage;
4441 dd->WriteMonoRGBASpan = write_span_mono_8R8G8B24_ximage;
4442 dd->WriteRGBAPixels = write_pixels_8R8G8B24_ximage;
4443 dd->WriteMonoRGBAPixels = write_pixels_mono_8R8G8B24_ximage;
4444 break;
4445 case PF_5R6G5B:
4446 dd->WriteRGBASpan = write_span_5R6G5B_ximage;
4447 dd->WriteRGBSpan = write_span_rgb_5R6G5B_ximage;
4448 dd->WriteMonoRGBASpan = write_span_mono_ximage;
4449 dd->WriteRGBAPixels = write_pixels_5R6G5B_ximage;
4450 dd->WriteMonoRGBAPixels = write_pixels_mono_ximage;
4451 break;
4452 case PF_Dither_5R6G5B:
4453 dd->WriteRGBASpan = write_span_DITHER_5R6G5B_ximage;
4454 dd->WriteRGBSpan = write_span_rgb_DITHER_5R6G5B_ximage;
4455 dd->WriteMonoRGBASpan = write_span_mono_DITHER_5R6G5B_ximage;
4456 dd->WriteRGBAPixels = write_pixels_DITHER_5R6G5B_ximage;
4457 dd->WriteMonoRGBAPixels = write_pixels_mono_DITHER_5R6G5B_ximage;
4458 break;
4459 case PF_Dither:
4460 if (depth==8) {
4461 dd->WriteRGBASpan = write_span_DITHER8_ximage;
4462 dd->WriteRGBSpan = write_span_rgb_DITHER8_ximage;
4463 dd->WriteMonoRGBASpan = write_span_mono_DITHER8_ximage;
4464 dd->WriteRGBAPixels = write_pixels_DITHER8_ximage;
4465 dd->WriteMonoRGBAPixels = write_pixels_mono_DITHER8_ximage;
4466 }
4467 else {
4468 dd->WriteRGBASpan = write_span_DITHER_ximage;
4469 dd->WriteRGBSpan = write_span_rgb_DITHER_ximage;
4470 dd->WriteMonoRGBASpan = write_span_mono_DITHER_ximage;
4471 dd->WriteRGBAPixels = write_pixels_DITHER_ximage;
4472 dd->WriteMonoRGBAPixels = write_pixels_mono_DITHER_ximage;
4473 }
4474 break;
4475 case PF_1Bit:
4476 dd->WriteRGBASpan = write_span_1BIT_ximage;
4477 dd->WriteRGBSpan = write_span_rgb_1BIT_ximage;
4478 dd->WriteMonoRGBASpan = write_span_mono_1BIT_ximage;
4479 dd->WriteRGBAPixels = write_pixels_1BIT_ximage;
4480 dd->WriteMonoRGBAPixels = write_pixels_mono_1BIT_ximage;
4481 break;
4482 case PF_HPCR:
4483 dd->WriteRGBASpan = write_span_HPCR_ximage;
4484 dd->WriteRGBSpan = write_span_rgb_HPCR_ximage;
4485 dd->WriteMonoRGBASpan = write_span_mono_HPCR_ximage;
4486 dd->WriteRGBAPixels = write_pixels_HPCR_ximage;
4487 dd->WriteMonoRGBAPixels = write_pixels_mono_HPCR_ximage;
4488 if (xmesa->xm_visual->hpcr_clear_flag) {
4489 ctx->Driver.ClearColor = clear_color_HPCR_ximage;
4490 }
4491 break;
4492 case PF_Lookup:
4493 if (depth==8) {
4494 dd->WriteRGBASpan = write_span_LOOKUP8_ximage;
4495 dd->WriteRGBSpan = write_rgb_LOOKUP8_ximage;
4496 dd->WriteMonoRGBASpan = write_span_mono_LOOKUP8_ximage;
4497 dd->WriteRGBAPixels = write_pixels_LOOKUP8_ximage;
4498 dd->WriteMonoRGBAPixels = write_pixels_mono_LOOKUP8_ximage;
4499 }
4500 else {
4501 dd->WriteRGBASpan = write_span_LOOKUP_ximage;
4502 dd->WriteRGBSpan = write_span_rgb_LOOKUP_ximage;
4503 dd->WriteMonoRGBASpan = write_span_mono_ximage;
4504 dd->WriteRGBAPixels = write_pixels_LOOKUP_ximage;
4505 dd->WriteMonoRGBAPixels = write_pixels_mono_ximage;
4506 }
4507 break;
4508 case PF_Grayscale:
4509 if (depth==8) {
4510 dd->WriteRGBASpan = write_span_GRAYSCALE8_ximage;
4511 dd->WriteRGBSpan = write_span_rgb_GRAYSCALE8_ximage;
4512 dd->WriteMonoRGBASpan = write_span_mono_GRAYSCALE8_ximage;
4513 dd->WriteRGBAPixels = write_pixels_GRAYSCALE8_ximage;
4514 dd->WriteMonoRGBAPixels = write_pixels_mono_GRAYSCALE8_ximage;
4515 }
4516 else {
4517 dd->WriteRGBASpan = write_span_GRAYSCALE_ximage;
4518 dd->WriteRGBSpan = write_span_rgb_GRAYSCALE_ximage;
4519 dd->WriteMonoRGBASpan = write_span_mono_ximage;
4520 dd->WriteRGBAPixels = write_pixels_GRAYSCALE_ximage;
4521 dd->WriteMonoRGBAPixels = write_pixels_mono_ximage;
4522 }
4523 break;
4524 default:
4525 _mesa_problem(NULL,"Bad pixel format in xmesa_update_state (2)");
4526 return;
4527 }
4528 }
4529
4530 /* Pixel/span reading functions: */
4531 dd->ReadCI32Span = read_index_span;
4532 dd->ReadRGBASpan = read_color_span;
4533 dd->ReadCI32Pixels = read_index_pixels;
4534 dd->ReadRGBAPixels = read_color_pixels;
4535 }