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