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