2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 #include "glxheader.h"
26 #include "main/colormac.h"
27 #include "main/context.h"
28 #include "main/depth.h"
29 #include "main/drawpix.h"
30 #include "main/extensions.h"
31 #include "main/macros.h"
32 #include "main/imports.h"
33 #include "main/mtypes.h"
34 #include "main/state.h"
37 #include "swrast/swrast.h"
41 * The following functions are used to trap XGetImage() calls which
42 * generate BadMatch errors if the drawable isn't mapped.
45 static int caught_xgetimage_error = 0;
46 static int (*old_xerror_handler)( XMesaDisplay *dpy, XErrorEvent *ev );
47 static unsigned long xgetimage_serial;
50 * This is the error handler which will be called if XGetImage fails.
52 static int xgetimage_error_handler( XMesaDisplay *dpy, XErrorEvent *ev )
54 if (ev->serial==xgetimage_serial && ev->error_code==BadMatch) {
55 /* caught the expected error */
56 caught_xgetimage_error = 0;
59 /* call the original X error handler, if any. otherwise ignore */
60 if (old_xerror_handler) {
61 (*old_xerror_handler)( dpy, ev );
69 * Call this right before XGetImage to setup error trap.
71 static void catch_xgetimage_errors( XMesaDisplay *dpy )
73 xgetimage_serial = NextRequest( dpy );
74 old_xerror_handler = XSetErrorHandler( xgetimage_error_handler );
75 caught_xgetimage_error = 0;
80 * Call this right after XGetImage to check if an error occured.
82 static int check_xgetimage_errors( void )
84 /* restore old handler */
85 (void) XSetErrorHandler( old_xerror_handler );
86 /* return 0=no error, 1=error caught */
87 return caught_xgetimage_error;
92 * Read a pixel from an X drawable.
94 static unsigned long read_pixel( XMesaDisplay *dpy,
95 XMesaDrawable d, int x, int y )
98 XMesaImage *pixel = NULL;
101 catch_xgetimage_errors( dpy );
102 pixel = XGetImage( dpy, d, x, y, 1, 1, AllPlanes, ZPixmap );
103 error = check_xgetimage_errors();
104 if (pixel && !error) {
105 p = XMesaGetPixel( pixel, 0, 0 );
111 XMesaDestroyImage( pixel );
119 * The Mesa library needs to be able to draw pixels in a number of ways:
120 * 1. RGB vs Color Index
121 * 2. as horizontal spans (polygons, images) vs random locations (points,
123 * 3. different color per-pixel or same color for all pixels
125 * Furthermore, the X driver needs to support rendering to 3 possible
126 * "buffers", usually one, but sometimes two at a time:
127 * 1. The front buffer as an X window
128 * 2. The back buffer as a Pixmap
129 * 3. The back buffer as an XImage
131 * Finally, if the back buffer is an XImage, we can avoid using XPutPixel and
132 * optimize common cases such as 24-bit and 8-bit modes.
134 * By multiplication, there's at least 48 possible combinations of the above.
136 * Below are implementations of the most commonly used combinations. They are
137 * accessed through function pointers which get initialized here and are used
138 * directly from the Mesa library. The 8 function pointers directly correspond
139 * to the first 3 cases listed above.
142 * The function naming convention is:
144 * [put|get]_[mono]_[row|values]_[format]_[pixmap|ximage]
146 * New functions optimized for specific cases can be added without too much
147 * trouble. An example might be the 24-bit TrueColor mode 8A8R8G8B which is
148 * found on IBM RS/6000 X servers.
154 /**********************************************************************/
155 /*** Write COLOR SPAN functions ***/
156 /**********************************************************************/
159 #define PUT_ROW_ARGS \
160 struct gl_context *ctx, \
161 struct gl_renderbuffer *rb, \
162 GLuint n, GLint x, GLint y, \
163 const void *values, const GLubyte mask[]
165 #define RGB_SPAN_ARGS \
166 struct gl_context *ctx, \
167 struct gl_renderbuffer *rb, \
168 GLuint n, GLint x, GLint y, \
169 const void *values, const GLubyte mask[]
172 #define GET_XRB(XRB) \
173 struct xmesa_renderbuffer *XRB = xmesa_renderbuffer(rb)
177 * Write a span of PF_TRUECOLOR pixels to a pixmap.
179 static void put_row_TRUECOLOR_pixmap( PUT_ROW_ARGS )
181 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
182 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
184 XMesaDisplay *dpy = XMESA_BUFFER(ctx->DrawBuffer)->display;
185 XMesaDrawable buffer = xrb->drawable;
186 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
191 for (i=0;i<n;i++,x++) {
194 PACK_TRUECOLOR( p, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
195 XMesaSetForeground( dpy, gc, p );
196 XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
201 /* draw all pixels */
202 XMesaImage *rowimg = XMESA_BUFFER(ctx->DrawBuffer)->rowimage;
205 PACK_TRUECOLOR( p, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
206 XMesaPutPixel( rowimg, i, 0, p );
208 XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
214 * Write a span of PF_TRUECOLOR pixels to a pixmap.
216 static void put_row_rgb_TRUECOLOR_pixmap( RGB_SPAN_ARGS )
218 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
219 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
221 XMesaDisplay *dpy = xmesa->xm_visual->display;
222 XMesaDrawable buffer = xrb->drawable;
223 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
227 for (i=0;i<n;i++,x++) {
230 PACK_TRUECOLOR( p, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
231 XMesaSetForeground( dpy, gc, p );
232 XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
237 /* draw all pixels */
238 XMesaImage *rowimg = XMESA_BUFFER(ctx->DrawBuffer)->rowimage;
241 PACK_TRUECOLOR( p, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
242 XMesaPutPixel( rowimg, i, 0, p );
244 XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
249 * Write a span of PF_TRUEDITHER pixels to a pixmap.
251 static void put_row_TRUEDITHER_pixmap( PUT_ROW_ARGS )
253 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
254 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
256 XMesaDisplay *dpy = xmesa->xm_visual->display;
257 XMesaDrawable buffer = xrb->drawable;
258 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
262 for (i=0;i<n;i++,x++) {
265 PACK_TRUEDITHER(p, x, y, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
266 XMesaSetForeground( dpy, gc, p );
267 XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
272 XMesaImage *rowimg = XMESA_BUFFER(ctx->DrawBuffer)->rowimage;
275 PACK_TRUEDITHER(p, x+i, y, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
276 XMesaPutPixel( rowimg, i, 0, p );
278 XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
284 * Write a span of PF_TRUEDITHER pixels to a pixmap (no alpha).
286 static void put_row_rgb_TRUEDITHER_pixmap( RGB_SPAN_ARGS )
288 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
289 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
291 XMesaDisplay *dpy = xmesa->xm_visual->display;
292 XMesaDrawable buffer = xrb->drawable;
293 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
297 for (i=0;i<n;i++,x++) {
300 PACK_TRUEDITHER(p, x, y, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]);
301 XMesaSetForeground( dpy, gc, p );
302 XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
307 XMesaImage *rowimg = XMESA_BUFFER(ctx->DrawBuffer)->rowimage;
310 PACK_TRUEDITHER(p, x+i, y, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]);
311 XMesaPutPixel( rowimg, i, 0, p );
313 XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
319 * Write a span of PF_8A8B8G8R pixels to a pixmap.
321 static void put_row_8A8B8G8R_pixmap( PUT_ROW_ARGS )
323 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
324 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
326 XMesaDisplay *dpy = xmesa->xm_visual->display;
327 XMesaDrawable buffer = xrb->drawable;
328 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
332 for (i=0;i<n;i++,x++) {
334 XMesaSetForeground( dpy, gc,
335 PACK_8A8B8G8R(rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP], rgba[i][ACOMP]) );
336 XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
341 /* draw all pixels */
342 XMesaImage *rowimg = XMESA_BUFFER(ctx->DrawBuffer)->rowimage;
343 register GLuint *ptr4 = (GLuint *) rowimg->data;
345 *ptr4++ = PACK_8A8B8G8R( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP], rgba[i][ACOMP] );
347 XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
353 * Write a span of PF_8A8B8G8R pixels to a pixmap (no alpha).
355 static void put_row_rgb_8A8B8G8R_pixmap( RGB_SPAN_ARGS )
357 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
358 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
360 XMesaDisplay *dpy = xmesa->xm_visual->display;
361 XMesaDrawable buffer = xrb->drawable;
362 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
366 for (i=0;i<n;i++,x++) {
368 XMesaSetForeground( dpy, gc,
369 PACK_8B8G8R(rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]) );
370 XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
375 /* draw all pixels */
376 XMesaImage *rowimg = XMESA_BUFFER(ctx->DrawBuffer)->rowimage;
377 register GLuint *ptr4 = (GLuint *) rowimg->data;
379 *ptr4++ = PACK_8B8G8R(rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]);
381 XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
386 * Write a span of PF_8A8R8G8B pixels to a pixmap.
388 static void put_row_8A8R8G8B_pixmap( PUT_ROW_ARGS )
390 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
391 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
393 XMesaDisplay *dpy = xmesa->xm_visual->display;
394 XMesaDrawable buffer = xrb->drawable;
395 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
399 for (i=0;i<n;i++,x++) {
401 XMesaSetForeground( dpy, gc,
402 PACK_8A8R8G8B(rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP], rgba[i][ACOMP]) );
403 XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
408 /* draw all pixels */
409 XMesaImage *rowimg = XMESA_BUFFER(ctx->DrawBuffer)->rowimage;
410 register GLuint *ptr4 = (GLuint *) rowimg->data;
412 *ptr4++ = PACK_8A8R8G8B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP], rgba[i][ACOMP] );
414 XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
420 * Write a span of PF_8A8R8G8B pixels to a pixmap (no alpha).
422 static void put_row_rgb_8A8R8G8B_pixmap( RGB_SPAN_ARGS )
424 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
425 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
427 XMesaDisplay *dpy = xmesa->xm_visual->display;
428 XMesaDrawable buffer = xrb->drawable;
429 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
433 for (i=0;i<n;i++,x++) {
435 XMesaSetForeground( dpy, gc,
436 PACK_8R8G8B(rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]) );
437 XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
442 /* draw all pixels */
443 XMesaImage *rowimg = XMESA_BUFFER(ctx->DrawBuffer)->rowimage;
444 register GLuint *ptr4 = (GLuint *) rowimg->data;
446 *ptr4++ = PACK_8R8G8B(rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]);
448 XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
453 * Write a span of PF_8R8G8B pixels to a pixmap.
455 static void put_row_8R8G8B_pixmap( PUT_ROW_ARGS )
457 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
458 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
460 XMesaDisplay *dpy = xmesa->xm_visual->display;
461 XMesaDrawable buffer = xrb->drawable;
462 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
466 for (i=0;i<n;i++,x++) {
470 * XXX Something funny is going on here.
471 * If we're drawing into a window that uses a depth 32 TrueColor
472 * visual, we see the right pixels on screen, but when we read
473 * them back with XGetImage() we get random colors.
474 * The alternative code below which uses XPutImage() instead
475 * seems to mostly fix the problem, but not always.
476 * We don't normally create windows with this visual, but glean
477 * does and we're seeing some failures there.
479 XMesaSetForeground( dpy, gc, PACK_8R8G8B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ));
480 XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
482 /* This code works more often, but not always */
483 XMesaImage *rowimg = XMESA_BUFFER(ctx->DrawBuffer)->rowimage;
484 GLuint *ptr4 = (GLuint *) rowimg->data;
485 *ptr4 = PACK_8R8G8B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
486 XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, 1, 1 );
492 /* draw all pixels */
493 XMesaImage *rowimg = XMESA_BUFFER(ctx->DrawBuffer)->rowimage;
494 register GLuint *ptr4 = (GLuint *) rowimg->data;
496 *ptr4++ = PACK_8R8G8B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
498 XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
504 * Write a span of PF_8R8G8B24 pixels to a pixmap.
506 static void put_row_8R8G8B24_pixmap( PUT_ROW_ARGS )
508 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
509 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
511 XMesaDisplay *dpy = xmesa->xm_visual->display;
512 XMesaDrawable buffer = xrb->drawable;
513 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
517 for (i=0;i<n;i++,x++) {
519 XMesaSetForeground( dpy, gc,
520 PACK_8R8G8B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ));
521 XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
526 /* draw all pixels */
527 XMesaImage *rowimg = XMESA_BUFFER(ctx->DrawBuffer)->rowimage;
528 register GLuint *ptr4 = (GLuint *) rowimg->data;
529 register GLuint pixel;
530 static const GLuint shift[4] = {0, 8, 16, 24};
531 register GLuint i = 0;
534 pixel = rgba[i][BCOMP] /* << shift[0]*/;
535 pixel |= rgba[i][GCOMP] << shift[1];
536 pixel |= rgba[i++][RCOMP] << shift[2];
537 pixel |= rgba[i][BCOMP] << shift[3];
540 pixel = rgba[i][GCOMP] /* << shift[0]*/;
541 pixel |= rgba[i++][RCOMP] << shift[1];
542 pixel |= rgba[i][BCOMP] << shift[2];
543 pixel |= rgba[i][GCOMP] << shift[3];
546 pixel = rgba[i++][RCOMP]/* << shift[0]*/;
547 pixel |= rgba[i][BCOMP] << shift[1];
548 pixel |= rgba[i][GCOMP] << shift[2];
549 pixel |= rgba[i++][RCOMP] << shift[3];
557 pixel |= rgba[i][BCOMP] /*<< shift[0]*/;
558 pixel |= rgba[i][GCOMP] << shift[1];
559 pixel |= rgba[i++][RCOMP] << shift[2];
560 pixel |= rgba[i][BCOMP] << shift[3];
563 pixel |= rgba[i][GCOMP] /*<< shift[0]*/;
564 pixel |= rgba[i++][RCOMP] << shift[1];
565 pixel |= rgba[i][BCOMP] << shift[2];
566 pixel |= rgba[i][GCOMP] << shift[3];
568 pixel = 0xffffff00 & *ptr4;
569 pixel |= rgba[i][RCOMP] /*<< shift[0]*/;
574 pixel |= rgba[i][BCOMP] /*<< shift[0]*/;
575 pixel |= rgba[i][GCOMP] << shift[1];
576 pixel |= rgba[i++][RCOMP] << shift[2];
577 pixel |= rgba[i][BCOMP] << shift[3];
579 pixel = 0xffff0000 & *ptr4;
580 pixel |= rgba[i][GCOMP] /*<< shift[0]*/;
581 pixel |= rgba[i][RCOMP] << shift[1];
585 pixel = 0xff000000 & *ptr4;
586 pixel |= rgba[i][BCOMP] /*<< shift[0]*/;
587 pixel |= rgba[i][GCOMP] << shift[1];
588 pixel |= rgba[i][RCOMP] << shift[2];
594 XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
600 * Write a span of PF_8R8G8B pixels to a pixmap (no alpha).
602 static void put_row_rgb_8R8G8B_pixmap( RGB_SPAN_ARGS )
604 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
605 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
607 XMesaDisplay *dpy = xmesa->xm_visual->display;
608 XMesaDrawable buffer = xrb->drawable;
609 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
613 for (i=0;i<n;i++,x++) {
615 XMesaSetForeground( dpy, gc, PACK_8R8G8B( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] ));
616 XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
621 /* draw all pixels */
622 XMesaImage *rowimg = XMESA_BUFFER(ctx->DrawBuffer)->rowimage;
623 register GLuint *ptr4 = (GLuint *) rowimg->data;
625 *ptr4++ = PACK_8R8G8B( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
627 XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
632 * Write a span of PF_8R8G8B24 pixels to a pixmap (no alpha).
634 static void put_row_rgb_8R8G8B24_pixmap( RGB_SPAN_ARGS )
636 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
637 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
639 XMesaDisplay *dpy = xmesa->xm_visual->display;
640 XMesaDrawable buffer = xrb->drawable;
641 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
645 for (i=0;i<n;i++,x++) {
647 XMesaSetForeground( dpy, gc,
648 PACK_8R8G8B( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] ));
649 XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
654 /* draw all pixels */
655 XMesaImage *rowimg = XMESA_BUFFER(ctx->DrawBuffer)->rowimage;
656 register GLuint *ptr4 = (GLuint *) rowimg->data;
657 register GLuint pixel;
658 static const GLuint shift[4] = {0, 8, 16, 24};
660 register GLuint i = 0;
663 pixel |= rgb[i][BCOMP]/* << shift[0]*/;
664 pixel |= rgb[i][GCOMP] << shift[1];
665 pixel |= rgb[i++][RCOMP] << shift[2];
666 pixel |= rgb[i][BCOMP] <<shift[3];
670 pixel |= rgb[i][GCOMP]/* << shift[0]*/;
671 pixel |= rgb[i++][RCOMP] << shift[1];
672 pixel |= rgb[i][BCOMP] << shift[2];
673 pixel |= rgb[i][GCOMP] << shift[3];
677 pixel |= rgb[i++][RCOMP]/* << shift[0]*/;
678 pixel |= rgb[i][BCOMP] << shift[1];
679 pixel |= rgb[i][GCOMP] << shift[2];
680 pixel |= rgb[i++][RCOMP] << shift[3];
687 pixel |= rgb[i][BCOMP]/* << shift[0]*/;
688 pixel |= rgb[i][GCOMP] << shift[1];
689 pixel |= rgb[i++][RCOMP] << shift[2];
690 pixel |= rgb[i][BCOMP] << shift[3];
693 pixel |= rgb[i][GCOMP]/* << shift[0]*/;
694 pixel |= rgb[i++][RCOMP] << shift[1];
695 pixel |= rgb[i][BCOMP] << shift[2];
696 pixel |= rgb[i][GCOMP] << shift[3];
700 pixel |= rgb[i++][RCOMP]/* << shift[0]*/;
705 pixel |= rgb[i][BCOMP]/* << shift[0]*/;
706 pixel |= rgb[i][GCOMP] << shift[1];
707 pixel |= rgb[i++][RCOMP] << shift[2];
708 pixel |= rgb[i][BCOMP] << shift[3];
712 pixel |= rgb[i][GCOMP]/* << shift[0]*/;
713 pixel |= rgb[i++][RCOMP] << shift[1];
719 pixel |= rgb[i][BCOMP]/* << shift[0]*/;
720 pixel |= rgb[i][GCOMP] << shift[1];
721 pixel |= rgb[i++][RCOMP] << shift[2];
727 XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
733 * Write a span of PF_5R6G5B pixels to a pixmap.
735 static void put_row_5R6G5B_pixmap( PUT_ROW_ARGS )
737 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
738 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
740 XMesaDisplay *dpy = xmesa->xm_visual->display;
741 XMesaDrawable buffer = xrb->drawable;
742 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
746 for (i=0;i<n;i++,x++) {
748 XMesaSetForeground( dpy, gc, PACK_5R6G5B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ));
749 XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
754 /* draw all pixels */
755 XMesaImage *rowimg = XMESA_BUFFER(ctx->DrawBuffer)->rowimage;
756 register GLushort *ptr2 = (GLushort *) rowimg->data;
758 ptr2[i] = PACK_5R6G5B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
760 XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
766 * Write a span of PF_DITHER_5R6G5B pixels to a pixmap.
768 static void put_row_DITHER_5R6G5B_pixmap( PUT_ROW_ARGS )
770 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
771 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
773 XMesaDisplay *dpy = xmesa->xm_visual->display;
774 XMesaDrawable buffer = xrb->drawable;
775 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
779 for (i=0;i<n;i++,x++) {
782 PACK_TRUEDITHER(p, x, y, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
783 XMesaSetForeground( dpy, gc, p );
784 XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
789 /* draw all pixels */
790 XMesaImage *rowimg = XMESA_BUFFER(ctx->DrawBuffer)->rowimage;
791 register GLushort *ptr2 = (GLushort *) rowimg->data;
793 PACK_TRUEDITHER( ptr2[i], x+i, y, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
795 XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
801 * Write a span of PF_5R6G5B pixels to a pixmap (no alpha).
803 static void put_row_rgb_5R6G5B_pixmap( RGB_SPAN_ARGS )
805 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
806 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
808 XMesaDisplay *dpy = xmesa->xm_visual->display;
809 XMesaDrawable buffer = xrb->drawable;
810 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
814 for (i=0;i<n;i++,x++) {
816 XMesaSetForeground( dpy, gc, PACK_5R6G5B( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] ));
817 XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
822 /* draw all pixels */
823 XMesaImage *rowimg = XMESA_BUFFER(ctx->DrawBuffer)->rowimage;
824 register GLushort *ptr2 = (GLushort *) rowimg->data;
826 ptr2[i] = PACK_5R6G5B( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
828 XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
834 * Write a span of PF_DITHER_5R6G5B pixels to a pixmap (no alpha).
836 static void put_row_rgb_DITHER_5R6G5B_pixmap( RGB_SPAN_ARGS )
838 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
839 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
841 XMesaDisplay *dpy = xmesa->xm_visual->display;
842 XMesaDrawable buffer = xrb->drawable;
843 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
847 for (i=0;i<n;i++,x++) {
850 PACK_TRUEDITHER(p, x, y, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]);
851 XMesaSetForeground( dpy, gc, p );
852 XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
857 /* draw all pixels */
858 XMesaImage *rowimg = XMESA_BUFFER(ctx->DrawBuffer)->rowimage;
859 register GLushort *ptr2 = (GLushort *) rowimg->data;
861 PACK_TRUEDITHER( ptr2[i], x+i, y, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
863 XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
869 * Write a span of PF_DITHER pixels to a pixmap.
871 static void put_row_DITHER_pixmap( PUT_ROW_ARGS )
873 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
874 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
876 XMesaDisplay *dpy = xmesa->xm_visual->display;
877 XMesaDrawable buffer = xrb->drawable;
878 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
883 for (i=0;i<n;i++,x++) {
885 XMesaSetForeground( dpy, gc, XDITHER(x, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]) );
886 XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
891 /* draw all pixels */
892 XMesaImage *rowimg = XMESA_BUFFER(ctx->DrawBuffer)->rowimage;
894 XMesaPutPixel( rowimg, i, 0, XDITHER(x+i, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]) );
896 XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
902 * Write a span of PF_DITHER pixels to a pixmap (no alpha).
904 static void put_row_rgb_DITHER_pixmap( RGB_SPAN_ARGS )
906 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
907 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
909 XMesaDisplay *dpy = xmesa->xm_visual->display;
910 XMesaDrawable buffer = xrb->drawable;
911 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
916 for (i=0;i<n;i++,x++) {
918 XMesaSetForeground( dpy, gc, XDITHER(x, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]) );
919 XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
924 /* draw all pixels */
925 XMesaImage *rowimg = XMESA_BUFFER(ctx->DrawBuffer)->rowimage;
927 XMesaPutPixel( rowimg, i, 0, XDITHER(x+i, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]) );
929 XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
935 * Write a span of PF_1BIT pixels to a pixmap.
937 static void put_row_1BIT_pixmap( PUT_ROW_ARGS )
939 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
940 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
942 XMesaDisplay *dpy = xmesa->xm_visual->display;
943 XMesaDrawable buffer = xrb->drawable;
944 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
949 for (i=0;i<n;i++,x++) {
951 XMesaSetForeground( dpy, gc,
952 DITHER_1BIT( x, y, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
953 XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
958 /* draw all pixels */
959 XMesaImage *rowimg = XMESA_BUFFER(ctx->DrawBuffer)->rowimage;
961 XMesaPutPixel( rowimg, i, 0,
962 DITHER_1BIT( x+i, y, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
964 XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
970 * Write a span of PF_1BIT pixels to a pixmap (no alpha).
972 static void put_row_rgb_1BIT_pixmap( RGB_SPAN_ARGS )
974 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
975 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
977 XMesaDisplay *dpy = xmesa->xm_visual->display;
978 XMesaDrawable buffer = xrb->drawable;
979 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
984 for (i=0;i<n;i++,x++) {
986 XMesaSetForeground( dpy, gc,
987 DITHER_1BIT(x, y, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]) );
988 XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
993 /* draw all pixels */
994 XMesaImage *rowimg = XMESA_BUFFER(ctx->DrawBuffer)->rowimage;
996 XMesaPutPixel( rowimg, i, 0,
997 DITHER_1BIT(x+i, y, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]) );
999 XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
1005 * Write a span of PF_HPCR pixels to a pixmap.
1007 static void put_row_HPCR_pixmap( PUT_ROW_ARGS )
1009 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
1010 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
1012 XMesaDisplay *dpy = xmesa->xm_visual->display;
1013 XMesaDrawable buffer = xrb->drawable;
1014 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
1018 for (i=0;i<n;i++,x++) {
1020 XMesaSetForeground( dpy, gc,
1021 DITHER_HPCR( x, y, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
1022 XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
1027 XMesaImage *rowimg = XMESA_BUFFER(ctx->DrawBuffer)->rowimage;
1028 register GLubyte *ptr = (GLubyte *) XMESA_BUFFER(ctx->DrawBuffer)->rowimage->data;
1030 ptr[i] = DITHER_HPCR( (x+i), y, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
1032 XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
1038 * Write a span of PF_HPCR pixels to a pixmap (no alpha).
1040 static void put_row_rgb_HPCR_pixmap( RGB_SPAN_ARGS )
1042 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
1043 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
1045 XMesaDisplay *dpy = xmesa->xm_visual->display;
1046 XMesaDrawable buffer = xrb->drawable;
1047 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
1051 for (i=0;i<n;i++,x++) {
1053 XMesaSetForeground( dpy, gc,
1054 DITHER_HPCR(x, y, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]) );
1055 XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
1060 XMesaImage *rowimg = XMESA_BUFFER(ctx->DrawBuffer)->rowimage;
1061 register GLubyte *ptr = (GLubyte *) XMESA_BUFFER(ctx->DrawBuffer)->rowimage->data;
1063 ptr[i] = DITHER_HPCR( (x+i), y, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
1065 XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
1070 * Write a span of PF_LOOKUP pixels to a pixmap.
1072 static void put_row_LOOKUP_pixmap( PUT_ROW_ARGS )
1074 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
1075 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
1077 XMesaDisplay *dpy = xmesa->xm_visual->display;
1078 XMesaDrawable buffer = xrb->drawable;
1079 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
1084 for (i=0;i<n;i++,x++) {
1086 XMesaSetForeground( dpy, gc, LOOKUP( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
1087 XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
1092 XMesaImage *rowimg = XMESA_BUFFER(ctx->DrawBuffer)->rowimage;
1094 XMesaPutPixel( rowimg, i, 0, LOOKUP(rgba[i][RCOMP],rgba[i][GCOMP],rgba[i][BCOMP]) );
1096 XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
1102 * Write a span of PF_LOOKUP pixels to a pixmap (no alpha).
1104 static void put_row_rgb_LOOKUP_pixmap( RGB_SPAN_ARGS )
1106 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
1107 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
1109 XMesaDisplay *dpy = xmesa->xm_visual->display;
1110 XMesaDrawable buffer = xrb->drawable;
1111 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
1116 for (i=0;i<n;i++,x++) {
1118 XMesaSetForeground( dpy, gc, LOOKUP( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] ) );
1119 XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
1124 XMesaImage *rowimg = XMESA_BUFFER(ctx->DrawBuffer)->rowimage;
1126 XMesaPutPixel( rowimg, i, 0, LOOKUP(rgb[i][RCOMP],rgb[i][GCOMP],rgb[i][BCOMP]) );
1128 XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
1134 * Write a span of PF_GRAYSCALE pixels to a pixmap.
1136 static void put_row_GRAYSCALE_pixmap( PUT_ROW_ARGS )
1138 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
1139 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
1141 XMesaDisplay *dpy = xmesa->xm_visual->display;
1142 XMesaDrawable buffer = xrb->drawable;
1143 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
1147 for (i=0;i<n;i++,x++) {
1149 XMesaSetForeground( dpy, gc, GRAY_RGB( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
1150 XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
1155 XMesaImage *rowimg = XMESA_BUFFER(ctx->DrawBuffer)->rowimage;
1157 XMesaPutPixel( rowimg, i, 0, GRAY_RGB(rgba[i][RCOMP],rgba[i][GCOMP],rgba[i][BCOMP]) );
1159 XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
1165 * Write a span of PF_GRAYSCALE pixels to a pixmap (no alpha).
1167 static void put_row_rgb_GRAYSCALE_pixmap( RGB_SPAN_ARGS )
1169 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
1170 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
1172 XMesaDisplay *dpy = xmesa->xm_visual->display;
1173 XMesaDrawable buffer = xrb->drawable;
1174 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
1178 for (i=0;i<n;i++,x++) {
1180 XMesaSetForeground( dpy, gc, GRAY_RGB( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] ) );
1181 XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
1186 XMesaImage *rowimg = XMESA_BUFFER(ctx->DrawBuffer)->rowimage;
1188 XMesaPutPixel( rowimg, i, 0, GRAY_RGB(rgb[i][RCOMP],rgb[i][GCOMP],rgb[i][BCOMP]) );
1190 XMesaPutImage( dpy, buffer, gc, rowimg, 0, 0, x, y, n, 1 );
1195 * Write a span of PF_TRUECOLOR pixels to an XImage.
1197 static void put_row_TRUECOLOR_ximage( PUT_ROW_ARGS )
1199 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
1200 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
1202 XMesaImage *img = xrb->ximage;
1206 for (i=0;i<n;i++,x++) {
1209 PACK_TRUECOLOR( p, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
1210 XMesaPutPixel( img, x, y, p );
1215 /* draw all pixels */
1216 for (i=0;i<n;i++,x++) {
1218 PACK_TRUECOLOR( p, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
1219 XMesaPutPixel( img, x, y, p );
1226 * Write a span of PF_TRUECOLOR pixels to an XImage (no alpha).
1228 static void put_row_rgb_TRUECOLOR_ximage( RGB_SPAN_ARGS )
1230 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
1231 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
1233 XMesaImage *img = xrb->ximage;
1237 for (i=0;i<n;i++,x++) {
1240 PACK_TRUECOLOR( p, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
1241 XMesaPutPixel( img, x, y, p );
1246 /* draw all pixels */
1247 for (i=0;i<n;i++,x++) {
1249 PACK_TRUECOLOR( p, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
1250 XMesaPutPixel( img, x, y, p );
1257 * Write a span of PF_TRUEDITHER pixels to an XImage.
1259 static void put_row_TRUEDITHER_ximage( PUT_ROW_ARGS )
1261 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
1262 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
1264 XMesaImage *img = xrb->ximage;
1268 for (i=0;i<n;i++,x++) {
1271 PACK_TRUEDITHER(p, x, y, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
1272 XMesaPutPixel( img, x, y, p );
1277 /* draw all pixels */
1278 for (i=0;i<n;i++,x++) {
1280 PACK_TRUEDITHER(p, x, y, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
1281 XMesaPutPixel( img, x, y, p );
1288 * Write a span of PF_TRUEDITHER pixels to an XImage (no alpha).
1290 static void put_row_rgb_TRUEDITHER_ximage( RGB_SPAN_ARGS )
1292 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
1293 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
1295 XMesaImage *img = xrb->ximage;
1299 for (i=0;i<n;i++,x++) {
1302 PACK_TRUEDITHER(p, x, y, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]);
1303 XMesaPutPixel( img, x, y, p );
1308 /* draw all pixels */
1309 for (i=0;i<n;i++,x++) {
1311 PACK_TRUEDITHER(p, x, y, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]);
1312 XMesaPutPixel( img, x, y, p );
1319 * Write a span of PF_8A8B8G8R-format pixels to an ximage.
1321 static void put_row_8A8B8G8R_ximage( PUT_ROW_ARGS )
1323 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
1326 register GLuint *ptr = PIXEL_ADDR4(xrb, x, y);
1331 ptr[i] = PACK_8A8B8G8R( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP], rgba[i][ACOMP] );
1336 /* draw all pixels */
1338 ptr[i] = PACK_8A8B8G8R( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP], rgba[i][ACOMP] );
1345 * Write a span of PF_8A8B8G8R-format pixels to an ximage (no alpha).
1347 static void put_row_rgb_8A8B8G8R_ximage( RGB_SPAN_ARGS )
1349 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
1352 register GLuint *ptr = PIXEL_ADDR4(xrb, x, y);
1356 ptr[i] = PACK_8A8B8G8R( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP], 255 );
1361 /* draw all pixels */
1363 ptr[i] = PACK_8A8B8G8R( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP], 255 );
1369 * Write a span of PF_8A8R8G8B-format pixels to an ximage.
1371 static void put_row_8A8R8G8B_ximage( PUT_ROW_ARGS )
1373 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
1376 register GLuint *ptr = PIXEL_ADDR4(xrb, x, y);
1380 ptr[i] = PACK_8A8R8G8B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP], rgba[i][ACOMP] );
1385 /* draw all pixels */
1387 ptr[i] = PACK_8A8R8G8B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP], rgba[i][ACOMP] );
1394 * Write a span of PF_8A8R8G8B-format pixels to an ximage (no alpha).
1396 static void put_row_rgb_8A8R8G8B_ximage( RGB_SPAN_ARGS )
1398 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
1401 register GLuint *ptr = PIXEL_ADDR4(xrb, x, y);
1405 ptr[i] = PACK_8A8R8G8B( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP], 255 );
1410 /* draw all pixels */
1412 ptr[i] = PACK_8A8R8G8B( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP], 255 );
1419 * Write a span of PF_8R8G8B-format pixels to an ximage.
1421 static void put_row_8R8G8B_ximage( PUT_ROW_ARGS )
1423 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
1426 register GLuint *ptr = PIXEL_ADDR4(xrb, x, y);
1430 ptr[i] = PACK_8R8G8B(rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
1436 ptr[i] = PACK_8R8G8B(rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
1443 * Write a span of PF_8R8G8B24-format pixels to an ximage.
1445 static void put_row_8R8G8B24_ximage( PUT_ROW_ARGS )
1447 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
1450 register GLubyte *ptr = (GLubyte *) PIXEL_ADDR3(xrb, x, y );
1454 GLuint *ptr4 = (GLuint *) ptr;
1455 register GLuint pixel = *ptr4;
1456 switch (3 & (int)(ptr - (GLubyte*)ptr4)) {
1458 pixel &= 0xff000000;
1459 pixel |= rgba[i][BCOMP];
1460 pixel |= rgba[i][GCOMP] << 8;
1461 pixel |= rgba[i][RCOMP] << 16;
1465 pixel &= 0x00ffffff;
1466 pixel |= rgba[i][BCOMP] << 24;
1468 pixel = *ptr4 & 0xffff0000;
1469 pixel |= rgba[i][GCOMP];
1470 pixel |= rgba[i][RCOMP] << 8;
1474 pixel &= 0x0000ffff;
1475 pixel |= rgba[i][BCOMP] << 16;
1476 pixel |= rgba[i][GCOMP] << 24;
1478 pixel = *ptr4 & 0xffffff00;
1479 pixel |= rgba[i][RCOMP];
1483 pixel &= 0x000000ff;
1484 pixel |= rgba[i][BCOMP] << 8;
1485 pixel |= rgba[i][GCOMP] << 16;
1486 pixel |= rgba[i][RCOMP] << 24;
1495 /* write all pixels */
1497 GLuint *ptr4 = (GLuint *) ptr;
1498 register GLuint pixel = *ptr4;
1499 int index = (int)(ptr - (GLubyte *)ptr4);
1500 register GLuint i = 0;
1505 pixel &= 0x00ffffff;
1506 pixel |= rgba[i][BCOMP] << 24;
1508 pixel = *ptr4 & 0xffff0000;
1509 pixel |= rgba[i][GCOMP];
1510 pixel |= rgba[i++][RCOMP] << 8;
1515 pixel &= 0x0000ffff;
1516 pixel |= rgba[i][BCOMP] << 16;
1517 pixel |= rgba[i][GCOMP] << 24;
1519 pixel = *ptr4 & 0xffffff00;
1520 pixel |= rgba[i++][RCOMP];
1525 pixel &= 0x000000ff;
1526 pixel |= rgba[i][BCOMP] << 8;
1527 pixel |= rgba[i][GCOMP] << 16;
1528 pixel |= rgba[i++][RCOMP] << 24;
1535 pixel = rgba[i][BCOMP];
1536 pixel |= rgba[i][GCOMP] << 8;
1537 pixel |= rgba[i++][RCOMP] << 16;
1538 pixel |= rgba[i][BCOMP] << 24;
1540 pixel = rgba[i][GCOMP];
1541 pixel |= rgba[i++][RCOMP] << 8;
1542 pixel |= rgba[i][BCOMP] << 16;
1543 pixel |= rgba[i][GCOMP] << 24;
1545 pixel = rgba[i++][RCOMP];
1546 pixel |= rgba[i][BCOMP] << 8;
1547 pixel |= rgba[i][GCOMP] << 16;
1548 pixel |= rgba[i++][RCOMP] << 24;
1556 pixel = *ptr4 & 0xff000000;
1557 pixel |= rgba[i][BCOMP];
1558 pixel |= rgba[i][GCOMP] << 8;
1559 pixel |= rgba[i][RCOMP] << 16;
1563 pixel = rgba[i][BCOMP];
1564 pixel |= rgba[i][GCOMP] << 8;
1565 pixel |= rgba[i++][RCOMP] << 16;
1566 pixel |= rgba[i][BCOMP] << 24;
1568 pixel = *ptr4 & 0xffff0000;
1569 pixel |= rgba[i][GCOMP];
1570 pixel |= rgba[i][RCOMP] << 8;
1574 pixel = rgba[i][BCOMP];
1575 pixel |= rgba[i][GCOMP] << 8;
1576 pixel |= rgba[i++][RCOMP] << 16;
1577 pixel |= rgba[i][BCOMP] << 24;
1579 pixel = rgba[i][GCOMP];
1580 pixel |= rgba[i++][RCOMP] << 8;
1581 pixel |= rgba[i][BCOMP] << 16;
1582 pixel |= rgba[i][GCOMP] << 24;
1584 pixel = *ptr4 & 0xffffff00;
1585 pixel |= rgba[i][RCOMP];
1594 * Write a span of PF_8R8G8B-format pixels to an ximage (no alpha).
1596 static void put_row_rgb_8R8G8B_ximage( RGB_SPAN_ARGS )
1598 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
1601 register GLuint *ptr = PIXEL_ADDR4(xrb, x, y);
1605 ptr[i] = PACK_8R8G8B(rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]);
1610 /* draw all pixels */
1612 ptr[i] = PACK_8R8G8B(rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]);
1619 * Write a span of PF_8R8G8B24-format pixels to an ximage (no alpha).
1621 static void put_row_rgb_8R8G8B24_ximage( RGB_SPAN_ARGS )
1623 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
1626 register GLubyte *ptr = (GLubyte *) PIXEL_ADDR3(xrb, x, y);
1630 *ptr++ = rgb[i][BCOMP];
1631 *ptr++ = rgb[i][GCOMP];
1632 *ptr++ = rgb[i][RCOMP];
1640 /* draw all pixels */
1642 *ptr++ = rgb[i][BCOMP];
1643 *ptr++ = rgb[i][GCOMP];
1644 *ptr++ = rgb[i][RCOMP];
1651 * Write a span of PF_5R6G5B-format pixels to an ximage.
1653 static void put_row_5R6G5B_ximage( PUT_ROW_ARGS )
1655 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
1658 register GLushort *ptr = PIXEL_ADDR2(xrb, x, y);
1662 ptr[i] = PACK_5R6G5B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
1667 /* draw all pixels */
1668 #if defined(__i386__) /* word stores don't have to be on 4-byte boundaries */
1669 GLuint *ptr32 = (GLuint *) ptr;
1670 GLuint extraPixel = (n & 1);
1672 for (i = 0; i < n; i += 2) {
1674 p0 = PACK_5R6G5B(rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
1675 p1 = PACK_5R6G5B(rgba[i+1][RCOMP], rgba[i+1][GCOMP], rgba[i+1][BCOMP]);
1676 *ptr32++ = (p1 << 16) | p0;
1679 ptr[n] = PACK_5R6G5B(rgba[n][RCOMP], rgba[n][GCOMP], rgba[n][BCOMP]);
1682 for (i = 0; i < n; i++) {
1683 ptr[i] = PACK_5R6G5B(rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
1691 * Write a span of PF_DITHER_5R6G5B-format pixels to an ximage.
1693 static void put_row_DITHER_5R6G5B_ximage( PUT_ROW_ARGS )
1695 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
1697 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
1699 register GLushort *ptr = PIXEL_ADDR2(xrb, x, y);
1700 const GLint y2 = YFLIP(xrb, y);
1702 for (i=0;i<n;i++,x++) {
1704 PACK_TRUEDITHER( ptr[i], x, y2, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
1709 /* draw all pixels */
1710 #if defined(__i386__) /* word stores don't have to be on 4-byte boundaries */
1711 GLuint *ptr32 = (GLuint *) ptr;
1712 GLuint extraPixel = (n & 1);
1714 for (i = 0; i < n; i += 2, x += 2) {
1716 PACK_TRUEDITHER( p0, x, y2, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
1717 PACK_TRUEDITHER( p1, x+1, y2, rgba[i+1][RCOMP], rgba[i+1][GCOMP], rgba[i+1][BCOMP] );
1718 *ptr32++ = (p1 << 16) | p0;
1721 PACK_TRUEDITHER( ptr[n], x+n, y2, rgba[n][RCOMP], rgba[n][GCOMP], rgba[n][BCOMP]);
1724 for (i = 0; i < n; i++, x++) {
1725 PACK_TRUEDITHER( ptr[i], x, y2, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
1733 * Write a span of PF_5R6G5B-format pixels to an ximage (no alpha).
1735 static void put_row_rgb_5R6G5B_ximage( RGB_SPAN_ARGS )
1737 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
1740 register GLushort *ptr = PIXEL_ADDR2(xrb, x, y);
1744 ptr[i] = PACK_5R6G5B( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
1749 /* draw all pixels */
1750 #if defined(__i386__) /* word stores don't have to be on 4-byte boundaries */
1751 GLuint *ptr32 = (GLuint *) ptr;
1752 GLuint extraPixel = (n & 1);
1754 for (i = 0; i < n; i += 2) {
1756 p0 = PACK_5R6G5B(rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]);
1757 p1 = PACK_5R6G5B(rgb[i+1][RCOMP], rgb[i+1][GCOMP], rgb[i+1][BCOMP]);
1758 *ptr32++ = (p1 << 16) | p0;
1761 ptr[n] = PACK_5R6G5B(rgb[n][RCOMP], rgb[n][GCOMP], rgb[n][BCOMP]);
1765 ptr[i] = PACK_5R6G5B( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
1773 * Write a span of PF_DITHER_5R6G5B-format pixels to an ximage (no alpha).
1775 static void put_row_rgb_DITHER_5R6G5B_ximage( RGB_SPAN_ARGS )
1777 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
1779 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
1781 register GLushort *ptr = PIXEL_ADDR2(xrb, x, y );
1783 for (i=0;i<n;i++,x++) {
1785 PACK_TRUEDITHER( ptr[i], x, y, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
1790 /* draw all pixels */
1791 #if defined(__i386__) /* word stores don't have to be on 4-byte boundaries */
1792 GLuint *ptr32 = (GLuint *) ptr;
1793 GLuint extraPixel = (n & 1);
1795 for (i = 0; i < n; i += 2, x += 2) {
1797 PACK_TRUEDITHER( p0, x, y, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
1798 PACK_TRUEDITHER( p1, x+1, y, rgb[i+1][RCOMP], rgb[i+1][GCOMP], rgb[i+1][BCOMP] );
1799 *ptr32++ = (p1 << 16) | p0;
1802 PACK_TRUEDITHER( ptr[n], x+n, y, rgb[n][RCOMP], rgb[n][GCOMP], rgb[n][BCOMP]);
1805 for (i=0;i<n;i++,x++) {
1806 PACK_TRUEDITHER( ptr[i], x, y, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
1814 * Write a span of PF_DITHER pixels to an XImage.
1816 static void put_row_DITHER_ximage( PUT_ROW_ARGS )
1818 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
1820 XMesaImage *img = xrb->ximage;
1822 int yy = YFLIP(xrb, y);
1825 for (i=0;i<n;i++,x++) {
1827 XMesaPutPixel( img, x, yy, XDITHER( x, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
1832 /* draw all pixels */
1833 for (i=0;i<n;i++,x++) {
1834 XMesaPutPixel( img, x, yy, XDITHER( x, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
1841 * Write a span of PF_DITHER pixels to an XImage (no alpha).
1843 static void put_row_rgb_DITHER_ximage( RGB_SPAN_ARGS )
1845 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
1847 XMesaImage *img = xrb->ximage;
1849 int yy = YFLIP(xrb, y);
1852 for (i=0;i<n;i++,x++) {
1854 XMesaPutPixel( img, x, yy, XDITHER( x, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] ) );
1859 /* draw all pixels */
1860 for (i=0;i<n;i++,x++) {
1861 XMesaPutPixel( img, x, yy, XDITHER( x, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] ) );
1869 * Write a span of 8-bit PF_DITHER pixels to an XImage.
1871 static void put_row_DITHER8_ximage( PUT_ROW_ARGS )
1873 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
1876 register GLubyte *ptr = PIXEL_ADDR1(xrb, x, y);
1879 for (i=0;i<n;i++,x++) {
1881 ptr[i] = (GLubyte) XDITHER( x, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
1886 for (i=0;i<n;i++,x++) {
1887 ptr[i] = (GLubyte) XDITHER( x, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
1893 static void put_row_rgb_DITHER8_ximage( RGB_SPAN_ARGS )
1895 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
1898 register GLubyte *ptr = PIXEL_ADDR1(xrb, x, y);
1901 for (i=0;i<n;i++,x++) {
1903 ptr[i] = (GLubyte) XDITHER( x, rgb[i][0], rgb[i][1], rgb[i][2] );
1908 const GLubyte *data = (GLubyte *) rgb;
1909 for (i=0;i<n;i++,x++) {
1910 /*ptr[i] = XDITHER( x, rgb[i][0], rgb[i][1], rgb[i][2] );*/
1911 ptr[i] = (GLubyte) XDITHER( x, data[i+i+i], data[i+i+i+1], data[i+i+i+2] );
1919 * Write a span of PF_1BIT pixels to an XImage.
1921 static void put_row_1BIT_ximage( PUT_ROW_ARGS )
1923 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
1924 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
1926 XMesaImage *img = xrb->ximage;
1931 for (i=0;i<n;i++,x++) {
1933 XMesaPutPixel(img, x, y, DITHER_1BIT(x, y, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]));
1938 for (i=0;i<n;i++,x++) {
1939 XMesaPutPixel( img, x, y, DITHER_1BIT(x, y, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]) );
1946 * Write a span of PF_1BIT pixels to an XImage (no alpha).
1948 static void put_row_rgb_1BIT_ximage( RGB_SPAN_ARGS )
1950 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
1951 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
1953 XMesaImage *img = xrb->ximage;
1958 for (i=0;i<n;i++,x++) {
1960 XMesaPutPixel(img, x, y, DITHER_1BIT(x, y, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]));
1965 for (i=0;i<n;i++,x++) {
1966 XMesaPutPixel( img, x, y, DITHER_1BIT(x, y, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]) );
1973 * Write a span of PF_HPCR pixels to an XImage.
1975 static void put_row_HPCR_ximage( PUT_ROW_ARGS )
1977 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
1979 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
1981 register GLubyte *ptr = PIXEL_ADDR1(xrb, x, y);
1983 for (i=0;i<n;i++,x++) {
1985 ptr[i] = DITHER_HPCR( x, y, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
1990 /* draw all pixels */
1991 for (i=0;i<n;i++,x++) {
1992 ptr[i] = DITHER_HPCR( x, y, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
1999 * Write a span of PF_HPCR pixels to an XImage (no alpha).
2001 static void put_row_rgb_HPCR_ximage( RGB_SPAN_ARGS )
2003 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
2005 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2007 register GLubyte *ptr = PIXEL_ADDR1(xrb, x, y);
2009 for (i=0;i<n;i++,x++) {
2011 ptr[i] = DITHER_HPCR( x, y, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
2016 /* draw all pixels */
2017 for (i=0;i<n;i++,x++) {
2018 ptr[i] = DITHER_HPCR( x, y, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
2025 * Write a span of PF_LOOKUP pixels to an XImage.
2027 static void put_row_LOOKUP_ximage( PUT_ROW_ARGS )
2029 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2031 XMesaImage *img = xrb->ximage;
2036 for (i=0;i<n;i++,x++) {
2038 XMesaPutPixel( img, x, y, LOOKUP( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
2043 /* draw all pixels */
2044 for (i=0;i<n;i++,x++) {
2045 XMesaPutPixel( img, x, y, LOOKUP( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
2052 * Write a span of PF_LOOKUP pixels to an XImage (no alpha).
2054 static void put_row_rgb_LOOKUP_ximage( RGB_SPAN_ARGS )
2056 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
2058 XMesaImage *img = xrb->ximage;
2063 for (i=0;i<n;i++,x++) {
2065 XMesaPutPixel( img, x, y, LOOKUP( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] ) );
2070 /* draw all pixels */
2071 for (i=0;i<n;i++,x++) {
2072 XMesaPutPixel( img, x, y, LOOKUP( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] ) );
2079 * Write a span of 8-bit PF_LOOKUP pixels to an XImage.
2081 static void put_row_LOOKUP8_ximage( PUT_ROW_ARGS )
2083 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2086 register GLubyte *ptr = PIXEL_ADDR1(xrb, x, y);
2089 for (i=0;i<n;i++,x++) {
2091 ptr[i] = (GLubyte) LOOKUP( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
2096 /* draw all pixels */
2097 for (i=0;i<n;i++,x++) {
2098 ptr[i] = (GLubyte) LOOKUP( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
2104 static void put_row_rgb_LOOKUP8_ximage( RGB_SPAN_ARGS )
2106 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
2109 register GLubyte *ptr = PIXEL_ADDR1(xrb, x, y);
2112 for (i=0;i<n;i++,x++) {
2114 ptr[i] = (GLubyte) LOOKUP( rgb[i][0], rgb[i][1], rgb[i][2] );
2119 /* draw all pixels */
2120 const GLubyte *data = (GLubyte *) rgb;
2121 for (i=0;i<n;i++,x++) {
2122 /*ptr[i] = LOOKUP( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );*/
2123 ptr[i] = (GLubyte) LOOKUP( data[i+i+i], data[i+i+i+1], data[i+i+i+2] );
2130 * Write a span of PF_GRAYSCALE pixels to an XImage.
2132 static void put_row_GRAYSCALE_ximage( PUT_ROW_ARGS )
2134 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2136 XMesaImage *img = xrb->ximage;
2140 for (i=0;i<n;i++,x++) {
2142 XMesaPutPixel( img, x, y, GRAY_RGB( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
2147 /* draw all pixels */
2148 for (i=0;i<n;i++,x++) {
2149 XMesaPutPixel( img, x, y, GRAY_RGB( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
2156 * Write a span of PF_GRAYSCALE pixels to an XImage (no alpha).
2158 static void put_row_rgb_GRAYSCALE_ximage( RGB_SPAN_ARGS )
2160 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
2162 XMesaImage *img = xrb->ximage;
2166 for (i=0;i<n;i++,x++) {
2168 XMesaPutPixel( img, x, y, GRAY_RGB( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] ) );
2173 /* draw all pixels */
2174 for (i=0;i<n;i++,x++) {
2175 XMesaPutPixel( img, x, y, GRAY_RGB( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] ) );
2182 * Write a span of 8-bit PF_GRAYSCALE pixels to an XImage.
2184 static void put_row_GRAYSCALE8_ximage( PUT_ROW_ARGS )
2186 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2189 register GLubyte *ptr = PIXEL_ADDR1(xrb, x, y);
2193 ptr[i] = (GLubyte) GRAY_RGB( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
2198 /* draw all pixels */
2200 ptr[i] = (GLubyte) GRAY_RGB( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
2207 * Write a span of 8-bit PF_GRAYSCALE pixels to an XImage (no alpha).
2209 static void put_row_rgb_GRAYSCALE8_ximage( RGB_SPAN_ARGS )
2211 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
2214 register GLubyte *ptr = PIXEL_ADDR1(xrb, x, y);
2218 ptr[i] = (GLubyte) GRAY_RGB( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
2223 /* draw all pixels */
2225 ptr[i] = (GLubyte) GRAY_RGB( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
2233 /**********************************************************************/
2234 /*** Write COLOR PIXEL functions ***/
2235 /**********************************************************************/
2238 #define PUT_VALUES_ARGS \
2239 struct gl_context *ctx, struct gl_renderbuffer *rb, \
2240 GLuint n, const GLint x[], const GLint y[], \
2241 const void *values, const GLubyte mask[]
2245 * Write an array of PF_TRUECOLOR pixels to a pixmap.
2247 static void put_values_TRUECOLOR_pixmap( PUT_VALUES_ARGS )
2249 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2250 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2252 XMesaDisplay *dpy = xmesa->xm_visual->display;
2253 XMesaDrawable buffer = xrb->drawable;
2254 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
2259 PACK_TRUECOLOR( p, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
2260 XMesaSetForeground( dpy, gc, p );
2261 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) YFLIP(xrb, y[i]) );
2268 * Write an array of PF_TRUEDITHER pixels to a pixmap.
2270 static void put_values_TRUEDITHER_pixmap( PUT_VALUES_ARGS )
2272 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2273 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2275 XMesaDisplay *dpy = xmesa->xm_visual->display;
2276 XMesaDrawable buffer = xrb->drawable;
2277 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
2282 PACK_TRUEDITHER(p, x[i], y[i], rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
2283 XMesaSetForeground( dpy, gc, p );
2284 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) YFLIP(xrb, y[i]) );
2291 * Write an array of PF_8A8B8G8R pixels to a pixmap.
2293 static void put_values_8A8B8G8R_pixmap( PUT_VALUES_ARGS )
2295 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2296 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2298 XMesaDisplay *dpy = xmesa->xm_visual->display;
2299 XMesaDrawable buffer = xrb->drawable;
2300 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
2304 XMesaSetForeground( dpy, gc,
2305 PACK_8A8B8G8R( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP], rgba[i][ACOMP] ));
2306 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) YFLIP(xrb, y[i]) );
2312 * Write an array of PF_8A8R8G8B pixels to a pixmap.
2314 static void put_values_8A8R8G8B_pixmap( PUT_VALUES_ARGS )
2316 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2317 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2319 XMesaDisplay *dpy = xmesa->xm_visual->display;
2320 XMesaDrawable buffer = xrb->drawable;
2321 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
2325 XMesaSetForeground( dpy, gc,
2326 PACK_8A8R8G8B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP], rgba[i][ACOMP] ));
2327 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) YFLIP(xrb, y[i]) );
2333 * Write an array of PF_8R8G8B pixels to a pixmap.
2335 static void put_values_8R8G8B_pixmap( PUT_VALUES_ARGS )
2337 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2338 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2340 XMesaDisplay *dpy = xmesa->xm_visual->display;
2341 XMesaDrawable buffer = xrb->drawable;
2342 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
2346 XMesaSetForeground( dpy, gc, PACK_8R8G8B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
2347 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) YFLIP(xrb, y[i]) );
2354 * Write an array of PF_8R8G8B24 pixels to a pixmap.
2356 static void put_values_8R8G8B24_pixmap( PUT_VALUES_ARGS )
2358 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2359 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2361 XMesaDisplay *dpy = xmesa->xm_visual->display;
2362 XMesaDrawable buffer = xrb->drawable;
2363 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
2367 XMesaSetForeground( dpy, gc, PACK_8R8G8B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
2368 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) YFLIP(xrb, y[i]) );
2375 * Write an array of PF_5R6G5B pixels to a pixmap.
2377 static void put_values_5R6G5B_pixmap( PUT_VALUES_ARGS )
2379 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2380 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2382 XMesaDisplay *dpy = xmesa->xm_visual->display;
2383 XMesaDrawable buffer = xrb->drawable;
2384 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
2388 XMesaSetForeground( dpy, gc, PACK_5R6G5B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
2389 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) YFLIP(xrb, y[i]) );
2396 * Write an array of PF_DITHER_5R6G5B pixels to a pixmap.
2398 static void put_values_DITHER_5R6G5B_pixmap( PUT_VALUES_ARGS )
2400 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2401 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2403 XMesaDisplay *dpy = xmesa->xm_visual->display;
2404 XMesaDrawable buffer = xrb->drawable;
2405 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
2410 PACK_TRUEDITHER(p, x[i], y[i], rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
2411 XMesaSetForeground( dpy, gc, p );
2412 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) YFLIP(xrb, y[i]) );
2419 * Write an array of PF_DITHER pixels to a pixmap.
2421 static void put_values_DITHER_pixmap( PUT_VALUES_ARGS )
2423 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2424 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2426 XMesaDisplay *dpy = xmesa->xm_visual->display;
2427 XMesaDrawable buffer = xrb->drawable;
2428 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
2433 XMesaSetForeground( dpy, gc,
2434 DITHER(x[i], y[i], rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]) );
2435 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) YFLIP(xrb, y[i]) );
2442 * Write an array of PF_1BIT pixels to a pixmap.
2444 static void put_values_1BIT_pixmap( PUT_VALUES_ARGS )
2446 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2447 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2449 XMesaDisplay *dpy = xmesa->xm_visual->display;
2450 XMesaDrawable buffer = xrb->drawable;
2451 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
2456 XMesaSetForeground( dpy, gc,
2457 DITHER_1BIT( x[i], y[i], rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ));
2458 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) YFLIP(xrb, y[i]) );
2465 * Write an array of PF_HPCR pixels to a pixmap.
2467 static void put_values_HPCR_pixmap( PUT_VALUES_ARGS )
2469 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2470 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2472 XMesaDisplay *dpy = xmesa->xm_visual->display;
2473 XMesaDrawable buffer = xrb->drawable;
2474 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
2478 XMesaSetForeground( dpy, gc,
2479 DITHER_HPCR( x[i], y[i], rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ));
2480 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) YFLIP(xrb, y[i]) );
2487 * Write an array of PF_LOOKUP pixels to a pixmap.
2489 static void put_values_LOOKUP_pixmap( PUT_VALUES_ARGS )
2491 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2492 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2494 XMesaDisplay *dpy = xmesa->xm_visual->display;
2495 XMesaDrawable buffer = xrb->drawable;
2496 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
2501 XMesaSetForeground( dpy, gc, LOOKUP( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
2502 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) YFLIP(xrb, y[i]) );
2509 * Write an array of PF_GRAYSCALE pixels to a pixmap.
2511 static void put_values_GRAYSCALE_pixmap( PUT_VALUES_ARGS )
2513 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2514 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2516 XMesaDisplay *dpy = xmesa->xm_visual->display;
2517 XMesaDrawable buffer = xrb->drawable;
2518 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
2522 XMesaSetForeground( dpy, gc, GRAY_RGB( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
2523 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) YFLIP(xrb, y[i]) );
2530 * Write an array of PF_TRUECOLOR pixels to an ximage.
2532 static void put_values_TRUECOLOR_ximage( PUT_VALUES_ARGS )
2534 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2535 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2537 XMesaImage *img = xrb->ximage;
2542 PACK_TRUECOLOR( p, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
2543 XMesaPutPixel( img, x[i], YFLIP(xrb, y[i]), p );
2550 * Write an array of PF_TRUEDITHER pixels to an XImage.
2552 static void put_values_TRUEDITHER_ximage( PUT_VALUES_ARGS )
2554 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2555 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2557 XMesaImage *img = xrb->ximage;
2562 PACK_TRUEDITHER(p, x[i], y[i], rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
2563 XMesaPutPixel( img, x[i], YFLIP(xrb, y[i]), p );
2570 * Write an array of PF_8A8B8G8R pixels to an ximage.
2572 static void put_values_8A8B8G8R_ximage( PUT_VALUES_ARGS )
2574 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2579 GLuint *ptr = PIXEL_ADDR4(xrb, x[i], y[i] );
2580 *ptr = PACK_8A8B8G8R( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP], rgba[i][ACOMP] );
2586 * Write an array of PF_8A8R8G8B pixels to an ximage.
2588 static void put_values_8A8R8G8B_ximage( PUT_VALUES_ARGS )
2590 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2595 GLuint *ptr = PIXEL_ADDR4(xrb, x[i], y[i]);
2596 *ptr = PACK_8A8R8G8B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP], rgba[i][ACOMP] );
2603 * Write an array of PF_8R8G8B pixels to an ximage.
2605 static void put_values_8R8G8B_ximage( PUT_VALUES_ARGS )
2607 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2612 GLuint *ptr = PIXEL_ADDR4(xrb, x[i], y[i]);
2613 *ptr = PACK_8R8G8B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
2620 * Write an array of PF_8R8G8B24 pixels to an ximage.
2622 static void put_values_8R8G8B24_ximage( PUT_VALUES_ARGS )
2624 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2629 bgr_t *ptr = PIXEL_ADDR3(xrb, x[i], y[i] );
2630 ptr->r = rgba[i][RCOMP];
2631 ptr->g = rgba[i][GCOMP];
2632 ptr->b = rgba[i][BCOMP];
2639 * Write an array of PF_5R6G5B pixels to an ximage.
2641 static void put_values_5R6G5B_ximage( PUT_VALUES_ARGS )
2643 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2648 GLushort *ptr = PIXEL_ADDR2(xrb, x[i], y[i] );
2649 *ptr = PACK_5R6G5B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
2656 * Write an array of PF_DITHER_5R6G5B pixels to an ximage.
2658 static void put_values_DITHER_5R6G5B_ximage( PUT_VALUES_ARGS )
2660 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2662 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2666 GLushort *ptr = PIXEL_ADDR2(xrb, x[i], y[i] );
2667 PACK_TRUEDITHER( *ptr, x[i], y[i], rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
2674 * Write an array of PF_DITHER pixels to an XImage.
2676 static void put_values_DITHER_ximage( PUT_VALUES_ARGS )
2678 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2680 XMesaImage *img = xrb->ximage;
2685 XMesaPutPixel( img, x[i], YFLIP(xrb, y[i]),
2686 DITHER( x[i], y[i], rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
2693 * Write an array of 8-bit PF_DITHER pixels to an XImage.
2695 static void put_values_DITHER8_ximage( PUT_VALUES_ARGS )
2697 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2703 GLubyte *ptr = PIXEL_ADDR1(xrb, x[i], y[i]);
2704 *ptr = (GLubyte) DITHER( x[i], y[i], rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
2711 * Write an array of PF_1BIT pixels to an XImage.
2713 static void put_values_1BIT_ximage( PUT_VALUES_ARGS )
2715 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2716 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2718 XMesaImage *img = xrb->ximage;
2723 XMesaPutPixel( img, x[i], YFLIP(xrb, y[i]),
2724 DITHER_1BIT( x[i], y[i], rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ));
2731 * Write an array of PF_HPCR pixels to an XImage.
2733 static void put_values_HPCR_ximage( PUT_VALUES_ARGS )
2735 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2737 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2741 GLubyte *ptr = PIXEL_ADDR1(xrb, x[i], y[i]);
2742 *ptr = (GLubyte) DITHER_HPCR( x[i], y[i], rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
2749 * Write an array of PF_LOOKUP pixels to an XImage.
2751 static void put_values_LOOKUP_ximage( PUT_VALUES_ARGS )
2753 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2755 XMesaImage *img = xrb->ximage;
2760 XMesaPutPixel( img, x[i], YFLIP(xrb, y[i]), LOOKUP(rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]) );
2767 * Write an array of 8-bit PF_LOOKUP pixels to an XImage.
2769 static void put_values_LOOKUP8_ximage( PUT_VALUES_ARGS )
2771 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2777 GLubyte *ptr = PIXEL_ADDR1(xrb, x[i], y[i]);
2778 *ptr = (GLubyte) LOOKUP( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
2785 * Write an array of PF_GRAYSCALE pixels to an XImage.
2787 static void put_values_GRAYSCALE_ximage( PUT_VALUES_ARGS )
2789 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2791 XMesaImage *img = xrb->ximage;
2795 XMesaPutPixel( img, x[i], YFLIP(xrb, y[i]),
2796 GRAY_RGB( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
2803 * Write an array of 8-bit PF_GRAYSCALE pixels to an XImage.
2805 static void put_values_GRAYSCALE8_ximage( PUT_VALUES_ARGS )
2807 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2812 GLubyte *ptr = PIXEL_ADDR1(xrb, x[i], y[i] );
2813 *ptr = (GLubyte) GRAY_RGB( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
2821 /**********************************************************************/
2822 /*** Write MONO COLOR SPAN functions ***/
2823 /**********************************************************************/
2825 #define PUT_MONO_ROW_ARGS \
2826 struct gl_context *ctx, struct gl_renderbuffer *rb, \
2827 GLuint n, GLint x, GLint y, const void *value, \
2828 const GLubyte mask[]
2833 * Write a span of identical pixels to a pixmap.
2835 static void put_mono_row_pixmap( PUT_MONO_ROW_ARGS )
2837 const GLubyte *color = (const GLubyte *) value;
2839 XMesaContext xmesa = XMESA_CONTEXT(ctx);
2840 XMesaDisplay *dpy = xmesa->xm_visual->display;
2841 XMesaDrawable buffer = xrb->drawable;
2842 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
2843 const unsigned long pixel = xmesa_color_to_pixel(ctx, color[RCOMP],
2844 color[GCOMP], color[BCOMP], color[ACOMP], xmesa->pixelformat);
2846 XMesaSetForeground( xmesa->display, gc, pixel );
2849 /* New code contributed by Jeff Epler and cleaned up by Keith
2852 for (i = 0; i < n; ) {
2855 /* Identify and emit contiguous rendered pixels
2857 while (i < n && (!mask || mask[i]))
2861 XMesaFillRectangle( dpy, buffer, gc,
2862 (int)(x+start), (int) y,
2865 /* Eat up non-rendered pixels
2867 while (i < n && !mask[i])
2875 put_mono_row_ci_pixmap( PUT_MONO_ROW_ARGS )
2877 GLuint colorIndex = *((GLuint *) value);
2878 XMesaContext xmesa = XMESA_CONTEXT(ctx);
2880 XMesaDisplay *dpy = xmesa->xm_visual->display;
2881 XMesaDrawable buffer = xrb->drawable;
2882 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
2884 XMesaSetForeground( xmesa->display, gc, colorIndex );
2887 for (i = 0 ; i < n ;) {
2890 /* Identify and emit contiguous rendered pixels
2892 while (i < n && (!mask || mask[i]))
2896 XMesaFillRectangle( dpy, buffer, gc,
2897 (int)(x+start), (int) y,
2900 /* Eat up non-rendered pixels
2902 while (i < n && !mask[i])
2910 * Write a span of PF_TRUEDITHER pixels to a pixmap.
2912 static void put_mono_row_TRUEDITHER_pixmap( PUT_MONO_ROW_ARGS )
2914 const GLubyte *color = (const GLubyte *) value;
2916 XMesaContext xmesa = XMESA_CONTEXT(ctx);
2917 XMesaDisplay *dpy = xmesa->xm_visual->display;
2918 XMesaDrawable buffer = xrb->drawable;
2919 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
2920 const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
2922 int yy = YFLIP(xrb, y);
2923 for (i=0;i<n;i++,x++) {
2924 if (!mask || mask[i]) {
2926 PACK_TRUEDITHER(p, x, yy, r, g, b);
2927 XMesaSetForeground( dpy, gc, p );
2928 XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) yy );
2935 * Write a span of PF_DITHER pixels to a pixmap.
2937 static void put_mono_row_DITHER_pixmap( PUT_MONO_ROW_ARGS )
2939 const GLubyte *color = (const GLubyte *) value;
2941 XMesaContext xmesa = XMESA_CONTEXT(ctx);
2942 XMesaDisplay *dpy = xmesa->xm_visual->display;
2943 XMesaDrawable buffer = xrb->drawable;
2944 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
2945 const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
2947 int yy = YFLIP(xrb, y);
2949 for (i=0;i<n;i++,x++) {
2950 if (!mask || mask[i]) {
2951 XMesaSetForeground( dpy, gc, XDITHER( x, r, g, b ) );
2952 XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) yy );
2959 * Write a span of PF_1BIT pixels to a pixmap.
2961 static void put_mono_row_1BIT_pixmap( PUT_MONO_ROW_ARGS )
2963 const GLubyte *color = (const GLubyte *) value;
2965 XMesaContext xmesa = XMESA_CONTEXT(ctx);
2966 XMesaDisplay *dpy = xmesa->xm_visual->display;
2967 XMesaDrawable buffer = xrb->drawable;
2968 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
2969 const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
2973 for (i=0;i<n;i++,x++) {
2974 if (!mask || mask[i]) {
2975 XMesaSetForeground( dpy, gc, DITHER_1BIT( x, y, r, g, b ) );
2976 XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
2983 * Write a span of identical pixels to an XImage.
2985 static void put_mono_row_ximage( PUT_MONO_ROW_ARGS )
2987 const GLubyte *color = (const GLubyte *) value;
2989 XMesaContext xmesa = XMESA_CONTEXT(ctx);
2990 XMesaImage *img = xrb->ximage;
2992 const unsigned long pixel = xmesa_color_to_pixel(ctx, color[RCOMP],
2993 color[GCOMP], color[BCOMP], color[ACOMP], xmesa->pixelformat);
2995 for (i=0;i<n;i++,x++) {
2996 if (!mask || mask[i]) {
2997 XMesaPutPixel( img, x, y, pixel );
3004 put_mono_row_ci_ximage( PUT_MONO_ROW_ARGS )
3006 const GLuint colorIndex = *((GLuint *) value);
3008 XMesaImage *img = xrb->ximage;
3011 for (i=0;i<n;i++,x++) {
3012 if (!mask || mask[i]) {
3013 XMesaPutPixel( img, x, y, colorIndex );
3020 * Write a span of identical PF_TRUEDITHER pixels to an XImage.
3022 static void put_mono_row_TRUEDITHER_ximage( PUT_MONO_ROW_ARGS )
3024 const GLubyte *color = (const GLubyte *) value;
3026 XMesaContext xmesa = XMESA_CONTEXT(ctx);
3027 XMesaImage *img = xrb->ximage;
3028 const GLint r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
3032 if (!mask || mask[i]) {
3034 PACK_TRUEDITHER( p, x+i, y, r, g, b);
3035 XMesaPutPixel( img, x+i, y, p );
3042 * Write a span of identical 8A8B8G8R pixels to an XImage.
3044 static void put_mono_row_8A8B8G8R_ximage( PUT_MONO_ROW_ARGS )
3046 const GLubyte *color = (const GLubyte *) value;
3048 XMesaContext xmesa = XMESA_CONTEXT(ctx);
3050 const unsigned long pixel = xmesa_color_to_pixel(ctx, color[RCOMP],
3051 color[GCOMP], color[BCOMP], color[ACOMP], xmesa->pixelformat);
3052 ptr = PIXEL_ADDR4(xrb, x, y );
3054 if (!mask || mask[i]) {
3061 * Write a span of identical 8A8R8G8B pixels to an XImage.
3063 static void put_mono_row_8A8R8G8B_ximage( PUT_MONO_ROW_ARGS )
3065 const GLubyte *color = (const GLubyte *) value;
3068 XMesaContext xmesa = XMESA_CONTEXT(ctx);
3069 const unsigned long pixel = xmesa_color_to_pixel(ctx, color[RCOMP],
3070 color[GCOMP], color[BCOMP], color[ACOMP], xmesa->pixelformat);
3071 ptr = PIXEL_ADDR4(xrb, x, y );
3073 if (!mask || mask[i]) {
3081 * Write a span of identical 8R8G8B pixels to an XImage.
3083 static void put_mono_row_8R8G8B_ximage( PUT_MONO_ROW_ARGS )
3085 const GLubyte *color = (const GLubyte *) value;
3087 const GLuint pixel = PACK_8R8G8B(color[RCOMP], color[GCOMP], color[BCOMP]);
3088 GLuint *ptr = PIXEL_ADDR4(xrb, x, y );
3091 if (!mask || mask[i]) {
3099 * Write a span of identical 8R8G8B pixels to an XImage.
3101 static void put_mono_row_8R8G8B24_ximage( PUT_MONO_ROW_ARGS )
3103 const GLubyte *color = (const GLubyte *) value;
3105 const GLubyte r = color[RCOMP];
3106 const GLubyte g = color[GCOMP];
3107 const GLubyte b = color[BCOMP];
3109 bgr_t *ptr = PIXEL_ADDR3(xrb, x, y );
3111 if (!mask || mask[i]) {
3121 * Write a span of identical DITHER pixels to an XImage.
3123 static void put_mono_row_DITHER_ximage( PUT_MONO_ROW_ARGS )
3125 const GLubyte *color = (const GLubyte *) value;
3127 const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
3128 XMesaImage *img = xrb->ximage;
3129 int yy = YFLIP(xrb, y);
3132 for (i=0;i<n;i++,x++) {
3133 if (!mask || mask[i]) {
3134 XMesaPutPixel( img, x, yy, XDITHER( x, r, g, b ) );
3141 * Write a span of identical 8-bit DITHER pixels to an XImage.
3143 static void put_mono_row_DITHER8_ximage( PUT_MONO_ROW_ARGS )
3145 const GLubyte *color = (const GLubyte *) value;
3147 const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
3148 register GLubyte *ptr = PIXEL_ADDR1(xrb, x, y);
3151 for (i=0;i<n;i++,x++) {
3152 if (!mask || mask[i]) {
3153 ptr[i] = (GLubyte) XDITHER( x, r, g, b );
3160 * Write a span of identical 8-bit LOOKUP pixels to an XImage.
3162 static void put_mono_row_LOOKUP8_ximage( PUT_MONO_ROW_ARGS )
3164 const GLubyte *color = (const GLubyte *) value;
3167 register GLubyte *ptr = PIXEL_ADDR1(xrb, x, y);
3170 pixel = LOOKUP(color[RCOMP], color[GCOMP], color[BCOMP]);
3172 if (!mask || mask[i]) {
3180 * Write a span of identical PF_1BIT pixels to an XImage.
3182 static void put_mono_row_1BIT_ximage( PUT_MONO_ROW_ARGS )
3184 const GLubyte *color = (const GLubyte *) value;
3185 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
3187 const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
3188 XMesaImage *img = xrb->ximage;
3192 for (i=0;i<n;i++,x++) {
3193 if (!mask || mask[i]) {
3194 XMesaPutPixel( img, x, y, DITHER_1BIT( x, y, r, g, b ) );
3201 * Write a span of identical HPCR pixels to an XImage.
3203 static void put_mono_row_HPCR_ximage( PUT_MONO_ROW_ARGS )
3205 const GLubyte *color = (const GLubyte *) value;
3207 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
3208 const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
3209 register GLubyte *ptr = PIXEL_ADDR1(xrb, x, y);
3211 for (i=0;i<n;i++,x++) {
3212 if (!mask || mask[i]) {
3213 ptr[i] = DITHER_HPCR( x, y, r, g, b );
3220 * Write a span of identical 8-bit GRAYSCALE pixels to an XImage.
3222 static void put_mono_row_GRAYSCALE8_ximage( PUT_MONO_ROW_ARGS )
3224 const GLubyte *color = (const GLubyte *) value;
3226 const GLubyte p = GRAY_RGB(color[RCOMP], color[GCOMP], color[BCOMP]);
3227 GLubyte *ptr = (GLubyte *) PIXEL_ADDR1(xrb, x, y);
3230 if (!mask || mask[i]) {
3239 * Write a span of identical PF_DITHER_5R6G5B pixels to an XImage.
3241 static void put_mono_row_DITHER_5R6G5B_ximage( PUT_MONO_ROW_ARGS )
3243 const GLubyte *color = (const GLubyte *) value;
3245 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
3246 register GLushort *ptr = PIXEL_ADDR2(xrb, x, y );
3247 const GLint r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
3251 if (!mask || mask[i]) {
3252 PACK_TRUEDITHER(ptr[i], x+i, y, r, g, b);
3259 /**********************************************************************/
3260 /*** Write MONO COLOR PIXELS functions ***/
3261 /**********************************************************************/
3263 #define PUT_MONO_VALUES_ARGS \
3264 struct gl_context *ctx, struct gl_renderbuffer *rb, \
3265 GLuint n, const GLint x[], const GLint y[], \
3266 const void *value, const GLubyte mask[]
3271 * Write an array of identical pixels to a pixmap.
3273 static void put_mono_values_pixmap( PUT_MONO_VALUES_ARGS )
3275 const GLubyte *color = (const GLubyte *) value;
3276 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
3278 XMesaDisplay *dpy = xmesa->xm_visual->display;
3279 XMesaDrawable buffer = xrb->drawable;
3280 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
3282 const unsigned long pixel = xmesa_color_to_pixel(ctx, color[RCOMP],
3283 color[GCOMP], color[BCOMP], color[ACOMP], xmesa->pixelformat);
3284 XMesaSetForeground( xmesa->display, gc, pixel );
3287 XMesaDrawPoint( dpy, buffer, gc,
3288 (int) x[i], (int) YFLIP(xrb, y[i]) );
3295 put_mono_values_ci_pixmap( PUT_MONO_VALUES_ARGS )
3297 const GLuint colorIndex = *((GLuint *) value);
3298 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
3300 XMesaDisplay *dpy = xmesa->xm_visual->display;
3301 XMesaDrawable buffer = xrb->drawable;
3302 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
3304 XMesaSetForeground( xmesa->display, gc, colorIndex );
3307 XMesaDrawPoint( dpy, buffer, gc,
3308 (int) x[i], (int) YFLIP(xrb, y[i]) );
3315 * Write an array of PF_TRUEDITHER pixels to a pixmap.
3317 static void put_mono_values_TRUEDITHER_pixmap( PUT_MONO_VALUES_ARGS )
3319 const GLubyte *color = (const GLubyte *) value;
3320 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
3322 XMesaDisplay *dpy = xmesa->xm_visual->display;
3323 XMesaDrawable buffer = xrb->drawable;
3324 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
3326 const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
3330 PACK_TRUEDITHER(p, x[i], y[i], r, g, b);
3331 XMesaSetForeground( dpy, gc, p );
3332 XMesaDrawPoint( dpy, buffer, gc,
3333 (int) x[i], (int) YFLIP(xrb, y[i]) );
3340 * Write an array of PF_DITHER pixels to a pixmap.
3342 static void put_mono_values_DITHER_pixmap( PUT_MONO_VALUES_ARGS )
3344 const GLubyte *color = (const GLubyte *) value;
3345 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
3347 XMesaDisplay *dpy = xmesa->xm_visual->display;
3348 XMesaDrawable buffer = xrb->drawable;
3349 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
3351 const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
3355 XMesaSetForeground( dpy, gc, DITHER( x[i], y[i], r, g, b ) );
3356 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) YFLIP(xrb, y[i]) );
3363 * Write an array of PF_1BIT pixels to a pixmap.
3365 static void put_mono_values_1BIT_pixmap( PUT_MONO_VALUES_ARGS )
3367 const GLubyte *color = (const GLubyte *) value;
3368 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
3370 XMesaDisplay *dpy = xmesa->xm_visual->display;
3371 XMesaDrawable buffer = xrb->drawable;
3372 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
3374 const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
3378 XMesaSetForeground( dpy, gc, DITHER_1BIT( x[i], y[i], r, g, b ) );
3379 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) YFLIP(xrb, y[i]) );
3386 * Write an array of identical pixels to an XImage.
3388 static void put_mono_values_ximage( PUT_MONO_VALUES_ARGS )
3390 const GLubyte *color = (const GLubyte *) value;
3391 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
3393 XMesaImage *img = xrb->ximage;
3395 const unsigned long pixel = xmesa_color_to_pixel(ctx, color[RCOMP],
3396 color[GCOMP], color[BCOMP], color[ACOMP], xmesa->pixelformat);
3399 XMesaPutPixel( img, x[i], YFLIP(xrb, y[i]), pixel );
3406 put_mono_values_ci_ximage( PUT_MONO_VALUES_ARGS )
3408 const GLuint colorIndex = *((GLuint *) value);
3410 XMesaImage *img = xrb->ximage;
3414 XMesaPutPixel( img, x[i], YFLIP(xrb, y[i]), colorIndex );
3421 * Write an array of identical TRUEDITHER pixels to an XImage.
3423 static void put_mono_values_TRUEDITHER_ximage( PUT_MONO_VALUES_ARGS )
3425 const GLubyte *color = (const GLubyte *) value;
3426 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
3428 XMesaImage *img = xrb->ximage;
3430 const int r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
3434 PACK_TRUEDITHER(p, x[i], YFLIP(xrb, y[i]), r, g, b);
3435 XMesaPutPixel( img, x[i], YFLIP(xrb, y[i]), p );
3443 * Write an array of identical 8A8B8G8R pixels to an XImage
3445 static void put_mono_values_8A8B8G8R_ximage( PUT_MONO_VALUES_ARGS )
3447 const GLubyte *color = (const GLubyte *) value;
3449 const GLuint p = PACK_8A8B8G8R(color[RCOMP], color[GCOMP],
3450 color[BCOMP], color[ACOMP]);
3454 GLuint *ptr = PIXEL_ADDR4(xrb, x[i], y[i] );
3461 * Write an array of identical 8A8R8G8B pixels to an XImage
3463 static void put_mono_values_8A8R8G8B_ximage( PUT_MONO_VALUES_ARGS )
3465 const GLubyte *color = (const GLubyte *) value;
3467 const GLuint p = PACK_8A8R8G8B(color[RCOMP], color[GCOMP],
3468 color[BCOMP], color[ACOMP]);
3472 GLuint *ptr = PIXEL_ADDR4(xrb, x[i], y[i] );
3479 * Write an array of identical 8R8G8B pixels to an XImage.
3481 static void put_mono_values_8R8G8B_ximage( PUT_MONO_VALUES_ARGS )
3483 const GLubyte *color = (const GLubyte *) value;
3486 const GLuint p = PACK_8R8G8B(color[RCOMP], color[GCOMP], color[BCOMP]);
3489 GLuint *ptr = PIXEL_ADDR4(xrb, x[i], y[i] );
3497 * Write an array of identical 8R8G8B pixels to an XImage.
3499 static void put_mono_values_8R8G8B24_ximage( PUT_MONO_VALUES_ARGS )
3501 const GLubyte *color = (const GLubyte *) value;
3503 const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
3507 bgr_t *ptr = PIXEL_ADDR3(xrb, x[i], y[i] );
3517 * Write an array of identical PF_DITHER pixels to an XImage.
3519 static void put_mono_values_DITHER_ximage( PUT_MONO_VALUES_ARGS )
3521 const GLubyte *color = (const GLubyte *) value;
3523 const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
3524 XMesaImage *img = xrb->ximage;
3529 XMesaPutPixel( img, x[i], YFLIP(xrb, y[i]), DITHER( x[i], y[i], r, g, b ) );
3536 * Write an array of identical 8-bit PF_DITHER pixels to an XImage.
3538 static void put_mono_values_DITHER8_ximage( PUT_MONO_VALUES_ARGS )
3540 const GLubyte *color = (const GLubyte *) value;
3542 const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
3547 GLubyte *ptr = PIXEL_ADDR1(xrb, x[i], y[i]);
3548 *ptr = (GLubyte) DITHER( x[i], y[i], r, g, b );
3555 * Write an array of identical 8-bit PF_LOOKUP pixels to an XImage.
3557 static void put_mono_values_LOOKUP8_ximage( PUT_MONO_VALUES_ARGS )
3559 const GLubyte *color = (const GLubyte *) value;
3564 pixel = LOOKUP(color[RCOMP], color[GCOMP], color[BCOMP]);
3567 GLubyte *ptr = PIXEL_ADDR1(xrb, x[i], y[i]);
3576 * Write an array of identical PF_1BIT pixels to an XImage.
3578 static void put_mono_values_1BIT_ximage( PUT_MONO_VALUES_ARGS )
3580 const GLubyte *color = (const GLubyte *) value;
3581 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
3583 const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
3584 XMesaImage *img = xrb->ximage;
3589 XMesaPutPixel( img, x[i], YFLIP(xrb, y[i]),
3590 DITHER_1BIT( x[i], y[i], r, g, b ));
3597 * Write an array of identical PF_HPCR pixels to an XImage.
3599 static void put_mono_values_HPCR_ximage( PUT_MONO_VALUES_ARGS )
3601 const GLubyte *color = (const GLubyte *) value;
3603 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
3604 const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
3608 GLubyte *ptr = PIXEL_ADDR1(xrb, x[i], y[i]);
3609 *ptr = DITHER_HPCR( x[i], y[i], r, g, b );
3616 * Write an array of identical 8-bit PF_GRAYSCALE pixels to an XImage.
3618 static void put_mono_values_GRAYSCALE8_ximage( PUT_MONO_VALUES_ARGS )
3620 const GLubyte *color = (const GLubyte *) value;
3623 register GLubyte p = GRAY_RGB(color[RCOMP], color[GCOMP], color[BCOMP]);
3626 GLubyte *ptr = PIXEL_ADDR1(xrb, x[i], y[i]);
3634 * Write an array of identical PF_DITHER_5R6G5B pixels to an XImage.
3636 static void put_mono_values_DITHER_5R6G5B_ximage( PUT_MONO_VALUES_ARGS )
3638 const GLubyte *color = (const GLubyte *) value;
3640 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
3641 const int r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
3645 GLushort *ptr = PIXEL_ADDR2(xrb, x[i], y[i] );
3646 PACK_TRUEDITHER(*ptr, x[i], y[i], r, g, b);
3653 /**********************************************************************/
3654 /*** Write INDEX SPAN functions ***/
3655 /**********************************************************************/
3658 * Write a span of CI pixels to a Pixmap.
3660 static void put_row_ci_pixmap( PUT_ROW_ARGS )
3662 const GLuint *index = (GLuint *) values;
3663 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
3665 XMesaDisplay *dpy = xmesa->xm_visual->display;
3666 XMesaDrawable buffer = xrb->drawable;
3667 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
3671 for (i=0;i<n;i++,x++) {
3673 XMesaSetForeground( dpy, gc, (unsigned long) index[i] );
3674 XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
3679 for (i=0;i<n;i++,x++) {
3680 XMesaSetForeground( dpy, gc, (unsigned long) index[i] );
3681 XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
3688 * Write a span of CI pixels to an XImage.
3690 static void put_row_ci_ximage( PUT_ROW_ARGS )
3692 const GLuint *index = (const GLuint *) values;
3694 XMesaImage *img = xrb->ximage;
3698 for (i=0;i<n;i++,x++) {
3700 XMesaPutPixel( img, x, y, (unsigned long) index[i] );
3705 for (i=0;i<n;i++,x++) {
3706 XMesaPutPixel( img, x, y, (unsigned long) index[i] );
3712 /**********************************************************************/
3713 /*** Write INDEX PIXELS functions ***/
3714 /**********************************************************************/
3717 * Write an array of CI pixels to a Pixmap.
3719 static void put_values_ci_pixmap( PUT_VALUES_ARGS )
3721 const GLuint *index = (const GLuint *) values;
3722 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
3724 XMesaDisplay *dpy = xmesa->xm_visual->display;
3725 XMesaDrawable buffer = xrb->drawable;
3726 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
3730 XMesaSetForeground( dpy, gc, (unsigned long) index[i] );
3731 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) YFLIP(xrb, y[i]) );
3738 * Write an array of CI pixels to an XImage.
3740 static void put_values_ci_ximage( PUT_VALUES_ARGS )
3742 const GLuint *index = (const GLuint *) values;
3744 XMesaImage *img = xrb->ximage;
3748 XMesaPutPixel(img, x[i], YFLIP(xrb, y[i]), (unsigned long) index[i]);
3756 /**********************************************************************/
3757 /***** Pixel reading *****/
3758 /**********************************************************************/
3761 * Do clip testing prior to calling XGetImage. If any of the region lies
3762 * outside the screen's bounds, XGetImage will return NULL.
3763 * We use XTranslateCoordinates() to check if that's the case and
3764 * adjust the x, y and length parameters accordingly.
3765 * \return -1 if span is totally clipped away,
3766 * else return number of pixels to skip in the destination array.
3769 clip_for_xgetimage(struct gl_context *ctx, XMesaPixmap pixmap, GLuint *n, GLint *x, GLint *y)
3771 XMesaContext xmesa = XMESA_CONTEXT(ctx);
3772 XMesaBuffer source = XMESA_BUFFER(ctx->DrawBuffer);
3773 Window rootWin = RootWindow(xmesa->display, 0);
3775 GLint screenWidth = WidthOfScreen(DefaultScreenOfDisplay(xmesa->display));
3777 if (source->type == PBUFFER || source->type == PIXMAP)
3779 XTranslateCoordinates(xmesa->display, pixmap, rootWin,
3780 *x, *y, &dx, &dy, &child);
3781 if (dx >= screenWidth) {
3782 /* totally clipped on right */
3786 /* clipped on left */
3788 if (clip >= (GLint) *n)
3789 return -1; /* totally clipped on left */
3795 if ((GLint) (dx + *n) > screenWidth) {
3796 /* clipped on right */
3797 GLint clip = dx + *n - screenWidth;
3805 * Read a horizontal span of color-index pixels.
3808 get_row_ci(struct gl_context *ctx, struct gl_renderbuffer *rb,
3809 GLuint n, GLint x, GLint y, void *values)
3811 GLuint *index = (GLuint *) values;
3812 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
3819 XMesaImage *span = NULL;
3821 int k = clip_for_xgetimage(ctx, xrb->pixmap, &n, &x, &y);
3826 catch_xgetimage_errors( xmesa->display );
3827 span = XGetImage( xmesa->display, xrb->pixmap,
3828 x, y, n, 1, AllPlanes, ZPixmap );
3829 error = check_xgetimage_errors();
3830 if (span && !error) {
3832 index[i] = (GLuint) XMesaGetPixel( span, i, 0 );
3836 /* return 0 pixels */
3842 XMesaDestroyImage( span );
3845 else if (xrb->ximage) {
3846 XMesaImage *img = xrb->ximage;
3847 for (i=0;i<n;i++,x++) {
3848 index[i] = (GLuint) XMesaGetPixel( img, x, y );
3856 * Read a horizontal span of color pixels.
3859 get_row_rgba(struct gl_context *ctx, struct gl_renderbuffer *rb,
3860 GLuint n, GLint x, GLint y, void *values)
3862 GLubyte (*rgba)[4] = (GLubyte (*)[4]) values;
3863 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
3865 XMesaBuffer source = XMESA_BUFFER(ctx->DrawBuffer);
3868 /* Read from Pixmap or Window */
3869 XMesaImage *span = NULL;
3873 k = clip_for_xgetimage(ctx, xrb->pixmap, &n, &x, &y);
3877 catch_xgetimage_errors( xmesa->display );
3878 span = XGetImage( xmesa->display, xrb->pixmap,
3879 x, y, n, 1, AllPlanes, ZPixmap );
3880 error = check_xgetimage_errors();
3881 if (span && !error) {
3882 switch (xmesa->pixelformat) {
3884 case PF_Dither_True:
3886 const GLubyte *pixelToR = xmesa->xm_visual->PixelToR;
3887 const GLubyte *pixelToG = xmesa->xm_visual->PixelToG;
3888 const GLubyte *pixelToB = xmesa->xm_visual->PixelToB;
3889 unsigned long rMask = GET_REDMASK(xmesa->xm_visual);
3890 unsigned long gMask = GET_GREENMASK(xmesa->xm_visual);
3891 unsigned long bMask = GET_BLUEMASK(xmesa->xm_visual);
3892 GLint rShift = xmesa->xm_visual->rshift;
3893 GLint gShift = xmesa->xm_visual->gshift;
3894 GLint bShift = xmesa->xm_visual->bshift;
3898 p = XMesaGetPixel( span, i, 0 );
3899 rgba[i][RCOMP] = pixelToR[(p & rMask) >> rShift];
3900 rgba[i][GCOMP] = pixelToG[(p & gMask) >> gShift];
3901 rgba[i][BCOMP] = pixelToB[(p & bMask) >> bShift];
3902 rgba[i][ACOMP] = 255;
3907 case PF_Dither_5R6G5B:
3909 const GLubyte *pixelToR = xmesa->xm_visual->PixelToR;
3910 const GLubyte *pixelToG = xmesa->xm_visual->PixelToG;
3911 const GLubyte *pixelToB = xmesa->xm_visual->PixelToB;
3914 unsigned long p = XMesaGetPixel( span, i, 0 );
3915 /* fast, but not quite accurate
3916 rgba[i][RCOMP] = ((p >> 8) & 0xf8);
3917 rgba[i][GCOMP] = ((p >> 3) & 0xfc);
3918 rgba[i][BCOMP] = ((p << 3) & 0xff);
3920 rgba[i][RCOMP] = pixelToR[p >> 11];
3921 rgba[i][GCOMP] = pixelToG[(p >> 5) & 0x3f];
3922 rgba[i][BCOMP] = pixelToB[p & 0x1f];
3923 rgba[i][ACOMP] = 255;
3929 const GLuint *ptr4 = (GLuint *) span->data;
3932 GLuint p4 = *ptr4++;
3933 rgba[i][RCOMP] = (GLubyte) ( p4 & 0xff);
3934 rgba[i][GCOMP] = (GLubyte) ((p4 >> 8) & 0xff);
3935 rgba[i][BCOMP] = (GLubyte) ((p4 >> 16) & 0xff);
3936 rgba[i][ACOMP] = (GLubyte) ((p4 >> 24) & 0xff);
3942 const GLuint *ptr4 = (GLuint *) span->data;
3945 GLuint p4 = *ptr4++;
3946 rgba[i][RCOMP] = (GLubyte) ((p4 >> 16) & 0xff);
3947 rgba[i][GCOMP] = (GLubyte) ((p4 >> 8) & 0xff);
3948 rgba[i][BCOMP] = (GLubyte) ( p4 & 0xff);
3949 rgba[i][ACOMP] = (GLubyte) ((p4 >> 24) & 0xff);
3955 const GLuint *ptr4 = (GLuint *) span->data;
3958 GLuint p4 = *ptr4++;
3959 rgba[i][RCOMP] = (GLubyte) ((p4 >> 16) & 0xff);
3960 rgba[i][GCOMP] = (GLubyte) ((p4 >> 8) & 0xff);
3961 rgba[i][BCOMP] = (GLubyte) ( p4 & 0xff);
3962 rgba[i][ACOMP] = 255;
3968 const bgr_t *ptr3 = (bgr_t *) span->data;
3971 rgba[i][RCOMP] = ptr3[i].r;
3972 rgba[i][GCOMP] = ptr3[i].g;
3973 rgba[i][BCOMP] = ptr3[i].b;
3974 rgba[i][ACOMP] = 255;
3980 GLubyte *ptr1 = (GLubyte *) span->data;
3983 GLubyte p = *ptr1++;
3984 rgba[i][RCOMP] = p & 0xE0;
3985 rgba[i][GCOMP] = (p & 0x1C) << 3;
3986 rgba[i][BCOMP] = (p & 0x03) << 6;
3987 rgba[i][ACOMP] = 255;
3995 GLubyte *rTable = source->pixel_to_r;
3996 GLubyte *gTable = source->pixel_to_g;
3997 GLubyte *bTable = source->pixel_to_b;
3998 if (GET_VISUAL_DEPTH(xmesa->xm_visual)==8) {
3999 const GLubyte *ptr1 = (GLubyte *) span->data;
4002 unsigned long p = *ptr1++;
4003 rgba[i][RCOMP] = rTable[p];
4004 rgba[i][GCOMP] = gTable[p];
4005 rgba[i][BCOMP] = bTable[p];
4006 rgba[i][ACOMP] = 255;
4012 unsigned long p = XMesaGetPixel( span, i, 0 );
4013 rgba[i][RCOMP] = rTable[p];
4014 rgba[i][GCOMP] = gTable[p];
4015 rgba[i][BCOMP] = bTable[p];
4016 rgba[i][ACOMP] = 255;
4023 int bitFlip = xmesa->xm_visual->bitFlip;
4027 p = XMesaGetPixel( span, i, 0 ) ^ bitFlip;
4028 rgba[i][RCOMP] = (GLubyte) (p * 255);
4029 rgba[i][GCOMP] = (GLubyte) (p * 255);
4030 rgba[i][BCOMP] = (GLubyte) (p * 255);
4031 rgba[i][ACOMP] = 255;
4036 _mesa_problem(NULL,"Problem in DD.read_color_span (1)");
4041 /* return black pixels */
4044 rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = rgba[i][ACOMP] = 0;
4048 XMesaDestroyImage( span );
4051 else if (xrb->ximage) {
4052 /* Read from XImage back buffer */
4053 switch (xmesa->pixelformat) {
4055 case PF_Dither_True:
4057 const GLubyte *pixelToR = xmesa->xm_visual->PixelToR;
4058 const GLubyte *pixelToG = xmesa->xm_visual->PixelToG;
4059 const GLubyte *pixelToB = xmesa->xm_visual->PixelToB;
4060 unsigned long rMask = GET_REDMASK(xmesa->xm_visual);
4061 unsigned long gMask = GET_GREENMASK(xmesa->xm_visual);
4062 unsigned long bMask = GET_BLUEMASK(xmesa->xm_visual);
4063 GLint rShift = xmesa->xm_visual->rshift;
4064 GLint gShift = xmesa->xm_visual->gshift;
4065 GLint bShift = xmesa->xm_visual->bshift;
4066 XMesaImage *img = xrb->ximage;
4071 p = XMesaGetPixel( img, x+i, y );
4072 rgba[i][RCOMP] = pixelToR[(p & rMask) >> rShift];
4073 rgba[i][GCOMP] = pixelToG[(p & gMask) >> gShift];
4074 rgba[i][BCOMP] = pixelToB[(p & bMask) >> bShift];
4075 rgba[i][ACOMP] = 255;
4080 case PF_Dither_5R6G5B:
4082 const GLubyte *pixelToR = xmesa->xm_visual->PixelToR;
4083 const GLubyte *pixelToG = xmesa->xm_visual->PixelToG;
4084 const GLubyte *pixelToB = xmesa->xm_visual->PixelToB;
4085 const GLushort *ptr2 = PIXEL_ADDR2(xrb, x, y);
4087 #if defined(__i386__) /* word stores don't have to be on 4-byte boundaries */
4088 const GLuint *ptr4 = (const GLuint *) ptr2;
4089 GLuint extraPixel = (n & 1);
4091 for (i = 0; i < n; i += 2) {
4092 const GLuint p = *ptr4++;
4093 const GLuint p0 = p & 0xffff;
4094 const GLuint p1 = p >> 16;
4095 /* fast, but not quite accurate
4096 rgba[i][RCOMP] = ((p >> 8) & 0xf8);
4097 rgba[i][GCOMP] = ((p >> 3) & 0xfc);
4098 rgba[i][BCOMP] = ((p << 3) & 0xff);
4100 rgba[i][RCOMP] = pixelToR[p0 >> 11];
4101 rgba[i][GCOMP] = pixelToG[(p0 >> 5) & 0x3f];
4102 rgba[i][BCOMP] = pixelToB[p0 & 0x1f];
4103 rgba[i][ACOMP] = 255;
4104 rgba[i+1][RCOMP] = pixelToR[p1 >> 11];
4105 rgba[i+1][GCOMP] = pixelToG[(p1 >> 5) & 0x3f];
4106 rgba[i+1][BCOMP] = pixelToB[p1 & 0x1f];
4107 rgba[i+1][ACOMP] = 255;
4110 GLushort p = ptr2[n];
4111 rgba[n][RCOMP] = pixelToR[p >> 11];
4112 rgba[n][GCOMP] = pixelToG[(p >> 5) & 0x3f];
4113 rgba[n][BCOMP] = pixelToB[p & 0x1f];
4114 rgba[n][ACOMP] = 255;
4117 for (i = 0; i < n; i++) {
4118 const GLushort p = ptr2[i];
4119 rgba[i][RCOMP] = pixelToR[p >> 11];
4120 rgba[i][GCOMP] = pixelToG[(p >> 5) & 0x3f];
4121 rgba[i][BCOMP] = pixelToB[p & 0x1f];
4122 rgba[i][ACOMP] = 255;
4129 const GLuint *ptr4 = PIXEL_ADDR4(xrb, x, y);
4132 GLuint p4 = *ptr4++;
4133 rgba[i][RCOMP] = (GLubyte) ( p4 & 0xff);
4134 rgba[i][GCOMP] = (GLubyte) ((p4 >> 8) & 0xff);
4135 rgba[i][BCOMP] = (GLubyte) ((p4 >> 16) & 0xff);
4136 rgba[i][ACOMP] = (GLint) ((p4 >> 24) & 0xff);
4142 const GLuint *ptr4 = PIXEL_ADDR4(xrb, x, y);
4145 GLuint p4 = *ptr4++;
4146 rgba[i][RCOMP] = (GLubyte) ((p4 >> 16) & 0xff);
4147 rgba[i][GCOMP] = (GLubyte) ((p4 >> 8) & 0xff);
4148 rgba[i][BCOMP] = (GLubyte) ( p4 & 0xff);
4149 rgba[i][ACOMP] = (GLint) ((p4 >> 24) & 0xff);
4155 const GLuint *ptr4 = PIXEL_ADDR4(xrb, x, y);
4158 GLuint p4 = *ptr4++;
4159 rgba[i][RCOMP] = (GLubyte) ((p4 >> 16) & 0xff);
4160 rgba[i][GCOMP] = (GLubyte) ((p4 >> 8) & 0xff);
4161 rgba[i][BCOMP] = (GLubyte) ( p4 & 0xff);
4162 rgba[i][ACOMP] = 255;
4168 const bgr_t *ptr3 = PIXEL_ADDR3(xrb, x, y);
4171 rgba[i][RCOMP] = ptr3[i].r;
4172 rgba[i][GCOMP] = ptr3[i].g;
4173 rgba[i][BCOMP] = ptr3[i].b;
4174 rgba[i][ACOMP] = 255;
4180 const GLubyte *ptr1 = PIXEL_ADDR1(xrb, x, y);
4183 GLubyte p = *ptr1++;
4184 rgba[i][RCOMP] = p & 0xE0;
4185 rgba[i][GCOMP] = (p & 0x1C) << 3;
4186 rgba[i][BCOMP] = (p & 0x03) << 6;
4187 rgba[i][ACOMP] = 255;
4195 const GLubyte *rTable = source->pixel_to_r;
4196 const GLubyte *gTable = source->pixel_to_g;
4197 const GLubyte *bTable = source->pixel_to_b;
4198 if (GET_VISUAL_DEPTH(xmesa->xm_visual)==8) {
4199 GLubyte *ptr1 = PIXEL_ADDR1(xrb, x, y);
4202 unsigned long p = *ptr1++;
4203 rgba[i][RCOMP] = rTable[p];
4204 rgba[i][GCOMP] = gTable[p];
4205 rgba[i][BCOMP] = bTable[p];
4206 rgba[i][ACOMP] = 255;
4210 XMesaImage *img = xrb->ximage;
4213 for (i=0;i<n;i++,x++) {
4214 unsigned long p = XMesaGetPixel( img, x, y );
4215 rgba[i][RCOMP] = rTable[p];
4216 rgba[i][GCOMP] = gTable[p];
4217 rgba[i][BCOMP] = bTable[p];
4218 rgba[i][ACOMP] = 255;
4225 XMesaImage *img = xrb->ximage;
4226 int bitFlip = xmesa->xm_visual->bitFlip;
4229 for (i=0;i<n;i++,x++) {
4231 p = XMesaGetPixel( img, x, y ) ^ bitFlip;
4232 rgba[i][RCOMP] = (GLubyte) (p * 255);
4233 rgba[i][GCOMP] = (GLubyte) (p * 255);
4234 rgba[i][BCOMP] = (GLubyte) (p * 255);
4235 rgba[i][ACOMP] = 255;
4240 _mesa_problem(NULL,"Problem in DD.read_color_span (2)");
4249 * Read an array of color index pixels.
4252 get_values_ci(struct gl_context *ctx, struct gl_renderbuffer *rb,
4253 GLuint n, const GLint x[], const GLint y[], void *values)
4255 GLuint *indx = (GLuint *) values;
4256 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
4261 indx[i] = (GLuint) read_pixel( xmesa->display, xrb->drawable,
4262 x[i], YFLIP(xrb, y[i]) );
4265 else if (xrb->ximage) {
4266 XMesaImage *img = xrb->ximage;
4268 indx[i] = (GLuint) XMesaGetPixel( img, x[i], YFLIP(xrb, y[i]) );
4276 get_values_rgba(struct gl_context *ctx, struct gl_renderbuffer *rb,
4277 GLuint n, const GLint x[], const GLint y[], void *values)
4279 GLubyte (*rgba)[4] = (GLubyte (*)[4]) values;
4281 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
4282 XMesaDisplay *dpy = xmesa->xm_visual->display;
4283 XMesaBuffer source = XMESA_BUFFER(ctx->DrawBuffer);
4287 XMesaDrawable buffer = xrb->drawable;
4288 switch (xmesa->pixelformat) {
4290 case PF_Dither_True:
4292 case PF_Dither_5R6G5B:
4294 unsigned long rMask = GET_REDMASK(xmesa->xm_visual);
4295 unsigned long gMask = GET_GREENMASK(xmesa->xm_visual);
4296 unsigned long bMask = GET_BLUEMASK(xmesa->xm_visual);
4297 GLubyte *pixelToR = xmesa->xm_visual->PixelToR;
4298 GLubyte *pixelToG = xmesa->xm_visual->PixelToG;
4299 GLubyte *pixelToB = xmesa->xm_visual->PixelToB;
4300 GLint rShift = xmesa->xm_visual->rshift;
4301 GLint gShift = xmesa->xm_visual->gshift;
4302 GLint bShift = xmesa->xm_visual->bshift;
4304 unsigned long p = read_pixel( dpy, buffer,
4305 x[i], YFLIP(xrb, y[i]) );
4306 rgba[i][RCOMP] = pixelToR[(p & rMask) >> rShift];
4307 rgba[i][GCOMP] = pixelToG[(p & gMask) >> gShift];
4308 rgba[i][BCOMP] = pixelToB[(p & bMask) >> bShift];
4309 rgba[i][ACOMP] = 255;
4315 unsigned long p = read_pixel( dpy, buffer,
4316 x[i], YFLIP(xrb, y[i]) );
4317 rgba[i][RCOMP] = (GLubyte) ( p & 0xff);
4318 rgba[i][GCOMP] = (GLubyte) ((p >> 8) & 0xff);
4319 rgba[i][BCOMP] = (GLubyte) ((p >> 16) & 0xff);
4320 rgba[i][ACOMP] = (GLubyte) ((p >> 24) & 0xff);
4325 unsigned long p = read_pixel( dpy, buffer,
4326 x[i], YFLIP(xrb, y[i]) );
4327 rgba[i][RCOMP] = (GLubyte) ((p >> 16) & 0xff);
4328 rgba[i][GCOMP] = (GLubyte) ((p >> 8) & 0xff);
4329 rgba[i][BCOMP] = (GLubyte) ( p & 0xff);
4330 rgba[i][ACOMP] = (GLubyte) ((p >> 24) & 0xff);
4335 unsigned long p = read_pixel( dpy, buffer,
4336 x[i], YFLIP(xrb, y[i]) );
4337 rgba[i][RCOMP] = (GLubyte) ((p >> 16) & 0xff);
4338 rgba[i][GCOMP] = (GLubyte) ((p >> 8) & 0xff);
4339 rgba[i][BCOMP] = (GLubyte) ( p & 0xff);
4340 rgba[i][ACOMP] = 255;
4345 unsigned long p = read_pixel( dpy, buffer,
4346 x[i], YFLIP(xrb, y[i]) );
4347 rgba[i][RCOMP] = (GLubyte) ((p >> 16) & 0xff);
4348 rgba[i][GCOMP] = (GLubyte) ((p >> 8) & 0xff);
4349 rgba[i][BCOMP] = (GLubyte) ( p & 0xff);
4350 rgba[i][ACOMP] = 255;
4355 unsigned long p = read_pixel( dpy, buffer,
4356 x[i], YFLIP(xrb, y[i]) );
4357 rgba[i][RCOMP] = (GLubyte) ( p & 0xE0 );
4358 rgba[i][GCOMP] = (GLubyte) ((p & 0x1C) << 3);
4359 rgba[i][BCOMP] = (GLubyte) ((p & 0x03) << 6);
4360 rgba[i][ACOMP] = (GLubyte) 255;
4367 GLubyte *rTable = source->pixel_to_r;
4368 GLubyte *gTable = source->pixel_to_g;
4369 GLubyte *bTable = source->pixel_to_b;
4371 unsigned long p = read_pixel( dpy, buffer,
4372 x[i], YFLIP(xrb, y[i]) );
4373 rgba[i][RCOMP] = rTable[p];
4374 rgba[i][GCOMP] = gTable[p];
4375 rgba[i][BCOMP] = bTable[p];
4376 rgba[i][ACOMP] = 255;
4382 int bitFlip = xmesa->xm_visual->bitFlip;
4384 unsigned long p = read_pixel( dpy, buffer,
4385 x[i], YFLIP(xrb, y[i])) ^ bitFlip;
4386 rgba[i][RCOMP] = (GLubyte) (p * 255);
4387 rgba[i][GCOMP] = (GLubyte) (p * 255);
4388 rgba[i][BCOMP] = (GLubyte) (p * 255);
4389 rgba[i][ACOMP] = 255;
4394 _mesa_problem(NULL,"Problem in DD.read_color_pixels (1)");
4398 else if (xrb->ximage) {
4399 /* Read from XImage back buffer */
4400 switch (xmesa->pixelformat) {
4402 case PF_Dither_True:
4404 case PF_Dither_5R6G5B:
4406 unsigned long rMask = GET_REDMASK(xmesa->xm_visual);
4407 unsigned long gMask = GET_GREENMASK(xmesa->xm_visual);
4408 unsigned long bMask = GET_BLUEMASK(xmesa->xm_visual);
4409 GLubyte *pixelToR = xmesa->xm_visual->PixelToR;
4410 GLubyte *pixelToG = xmesa->xm_visual->PixelToG;
4411 GLubyte *pixelToB = xmesa->xm_visual->PixelToB;
4412 GLint rShift = xmesa->xm_visual->rshift;
4413 GLint gShift = xmesa->xm_visual->gshift;
4414 GLint bShift = xmesa->xm_visual->bshift;
4415 XMesaImage *img = xrb->ximage;
4418 p = XMesaGetPixel( img, x[i], YFLIP(xrb, y[i]) );
4419 rgba[i][RCOMP] = pixelToR[(p & rMask) >> rShift];
4420 rgba[i][GCOMP] = pixelToG[(p & gMask) >> gShift];
4421 rgba[i][BCOMP] = pixelToB[(p & bMask) >> bShift];
4422 rgba[i][ACOMP] = 255;
4428 GLuint *ptr4 = PIXEL_ADDR4(xrb, x[i], y[i]);
4430 rgba[i][RCOMP] = (GLubyte) ( p4 & 0xff);
4431 rgba[i][GCOMP] = (GLubyte) ((p4 >> 8) & 0xff);
4432 rgba[i][BCOMP] = (GLubyte) ((p4 >> 16) & 0xff);
4433 rgba[i][ACOMP] = (GLubyte) ((p4 >> 24) & 0xff);
4438 GLuint *ptr4 = PIXEL_ADDR4(xrb, x[i], y[i]);
4440 rgba[i][RCOMP] = (GLubyte) ((p4 >> 16) & 0xff);
4441 rgba[i][GCOMP] = (GLubyte) ((p4 >> 8) & 0xff);
4442 rgba[i][BCOMP] = (GLubyte) ( p4 & 0xff);
4443 rgba[i][ACOMP] = (GLubyte) ((p4 >> 24) & 0xff);
4448 GLuint *ptr4 = PIXEL_ADDR4(xrb, x[i], y[i]);
4450 rgba[i][RCOMP] = (GLubyte) ((p4 >> 16) & 0xff);
4451 rgba[i][GCOMP] = (GLubyte) ((p4 >> 8) & 0xff);
4452 rgba[i][BCOMP] = (GLubyte) ( p4 & 0xff);
4453 rgba[i][ACOMP] = 255;
4458 bgr_t *ptr3 = PIXEL_ADDR3(xrb, x[i], y[i]);
4459 rgba[i][RCOMP] = ptr3->r;
4460 rgba[i][GCOMP] = ptr3->g;
4461 rgba[i][BCOMP] = ptr3->b;
4462 rgba[i][ACOMP] = 255;
4467 GLubyte *ptr1 = PIXEL_ADDR1(xrb, x[i], y[i]);
4469 rgba[i][RCOMP] = p & 0xE0;
4470 rgba[i][GCOMP] = (p & 0x1C) << 3;
4471 rgba[i][BCOMP] = (p & 0x03) << 6;
4472 rgba[i][ACOMP] = 255;
4479 GLubyte *rTable = source->pixel_to_r;
4480 GLubyte *gTable = source->pixel_to_g;
4481 GLubyte *bTable = source->pixel_to_b;
4482 XMesaImage *img = xrb->ximage;
4485 p = XMesaGetPixel( img, x[i], YFLIP(xrb, y[i]) );
4486 rgba[i][RCOMP] = rTable[p];
4487 rgba[i][GCOMP] = gTable[p];
4488 rgba[i][BCOMP] = bTable[p];
4489 rgba[i][ACOMP] = 255;
4495 XMesaImage *img = xrb->ximage;
4496 int bitFlip = xmesa->xm_visual->bitFlip;
4499 p = XMesaGetPixel( img, x[i], YFLIP(xrb, y[i]) ) ^ bitFlip;
4500 rgba[i][RCOMP] = (GLubyte) (p * 255);
4501 rgba[i][GCOMP] = (GLubyte) (p * 255);
4502 rgba[i][BCOMP] = (GLubyte) (p * 255);
4503 rgba[i][ACOMP] = 255;
4508 _mesa_problem(NULL,"Problem in DD.read_color_pixels (1)");
4516 * Initialize the renderbuffer's PutRow, GetRow, etc. functions.
4517 * This would generally only need to be called once when the renderbuffer
4518 * is created. However, we can change pixel formats on the fly if dithering
4519 * is enabled/disabled. Therefore, we may call this more often than that.
4522 xmesa_set_renderbuffer_funcs(struct xmesa_renderbuffer *xrb,
4523 enum pixel_format pixelformat, GLint depth)
4525 const GLboolean pixmap = xrb->pixmap ? GL_TRUE : GL_FALSE;
4527 switch (pixelformat) {
4529 ASSERT(xrb->Base.DataType == GL_UNSIGNED_INT);
4531 xrb->Base.PutRow = put_row_ci_pixmap;
4532 xrb->Base.PutRowRGB = NULL;
4533 xrb->Base.PutMonoRow = put_mono_row_ci_pixmap;
4534 xrb->Base.PutValues = put_values_ci_pixmap;
4535 xrb->Base.PutMonoValues = put_mono_values_ci_pixmap;
4538 xrb->Base.PutRow = put_row_ci_ximage;
4539 xrb->Base.PutRowRGB = NULL;
4540 xrb->Base.PutMonoRow = put_mono_row_ci_ximage;
4541 xrb->Base.PutValues = put_values_ci_ximage;
4542 xrb->Base.PutMonoValues = put_mono_values_ci_ximage;
4547 xrb->Base.PutRow = put_row_TRUECOLOR_pixmap;
4548 xrb->Base.PutRowRGB = put_row_rgb_TRUECOLOR_pixmap;
4549 xrb->Base.PutMonoRow = put_mono_row_pixmap;
4550 xrb->Base.PutValues = put_values_TRUECOLOR_pixmap;
4551 xrb->Base.PutMonoValues = put_mono_values_pixmap;
4554 xrb->Base.PutRow = put_row_TRUECOLOR_ximage;
4555 xrb->Base.PutRowRGB = put_row_rgb_TRUECOLOR_ximage;
4556 xrb->Base.PutMonoRow = put_mono_row_ximage;
4557 xrb->Base.PutValues = put_values_TRUECOLOR_ximage;
4558 xrb->Base.PutMonoValues = put_mono_values_ximage;
4561 case PF_Dither_True:
4563 xrb->Base.PutRow = put_row_TRUEDITHER_pixmap;
4564 xrb->Base.PutRowRGB = put_row_rgb_TRUEDITHER_pixmap;
4565 xrb->Base.PutMonoRow = put_mono_row_TRUEDITHER_pixmap;
4566 xrb->Base.PutValues = put_values_TRUEDITHER_pixmap;
4567 xrb->Base.PutMonoValues = put_mono_values_TRUEDITHER_pixmap;
4570 xrb->Base.PutRow = put_row_TRUEDITHER_ximage;
4571 xrb->Base.PutRowRGB = put_row_rgb_TRUEDITHER_ximage;
4572 xrb->Base.PutMonoRow = put_mono_row_TRUEDITHER_ximage;
4573 xrb->Base.PutValues = put_values_TRUEDITHER_ximage;
4574 xrb->Base.PutMonoValues = put_mono_values_TRUEDITHER_ximage;
4579 xrb->Base.PutRow = put_row_8A8B8G8R_pixmap;
4580 xrb->Base.PutRowRGB = put_row_rgb_8A8B8G8R_pixmap;
4581 xrb->Base.PutMonoRow = put_mono_row_pixmap;
4582 xrb->Base.PutValues = put_values_8A8B8G8R_pixmap;
4583 xrb->Base.PutMonoValues = put_mono_values_pixmap;
4586 xrb->Base.PutRow = put_row_8A8B8G8R_ximage;
4587 xrb->Base.PutRowRGB = put_row_rgb_8A8B8G8R_ximage;
4588 xrb->Base.PutMonoRow = put_mono_row_8A8B8G8R_ximage;
4589 xrb->Base.PutValues = put_values_8A8B8G8R_ximage;
4590 xrb->Base.PutMonoValues = put_mono_values_8A8B8G8R_ximage;
4595 xrb->Base.PutRow = put_row_8A8R8G8B_pixmap;
4596 xrb->Base.PutRowRGB = put_row_rgb_8A8R8G8B_pixmap;
4597 xrb->Base.PutMonoRow = put_mono_row_pixmap;
4598 xrb->Base.PutValues = put_values_8A8R8G8B_pixmap;
4599 xrb->Base.PutMonoValues = put_mono_values_pixmap;
4602 xrb->Base.PutRow = put_row_8A8R8G8B_ximage;
4603 xrb->Base.PutRowRGB = put_row_rgb_8A8R8G8B_ximage;
4604 xrb->Base.PutMonoRow = put_mono_row_8A8R8G8B_ximage;
4605 xrb->Base.PutValues = put_values_8A8R8G8B_ximage;
4606 xrb->Base.PutMonoValues = put_mono_values_8A8R8G8B_ximage;
4611 xrb->Base.PutRow = put_row_8R8G8B_pixmap;
4612 xrb->Base.PutRowRGB = put_row_rgb_8R8G8B_pixmap;
4613 xrb->Base.PutMonoRow = put_mono_row_pixmap;
4614 xrb->Base.PutValues = put_values_8R8G8B_pixmap;
4615 xrb->Base.PutMonoValues = put_mono_values_pixmap;
4618 xrb->Base.PutRow = put_row_8R8G8B_ximage;
4619 xrb->Base.PutRowRGB = put_row_rgb_8R8G8B_ximage;
4620 xrb->Base.PutMonoRow = put_mono_row_8R8G8B_ximage;
4621 xrb->Base.PutValues = put_values_8R8G8B_ximage;
4622 xrb->Base.PutMonoValues = put_mono_values_8R8G8B_ximage;
4627 xrb->Base.PutRow = put_row_8R8G8B24_pixmap;
4628 xrb->Base.PutRowRGB = put_row_rgb_8R8G8B24_pixmap;
4629 xrb->Base.PutMonoRow = put_mono_row_pixmap;
4630 xrb->Base.PutValues = put_values_8R8G8B24_pixmap;
4631 xrb->Base.PutMonoValues = put_mono_values_pixmap;
4634 xrb->Base.PutRow = put_row_8R8G8B24_ximage;
4635 xrb->Base.PutRowRGB = put_row_rgb_8R8G8B24_ximage;
4636 xrb->Base.PutMonoRow = put_mono_row_8R8G8B24_ximage;
4637 xrb->Base.PutValues = put_values_8R8G8B24_ximage;
4638 xrb->Base.PutMonoValues = put_mono_values_8R8G8B24_ximage;
4643 xrb->Base.PutRow = put_row_5R6G5B_pixmap;
4644 xrb->Base.PutRowRGB = put_row_rgb_5R6G5B_pixmap;
4645 xrb->Base.PutMonoRow = put_mono_row_pixmap;
4646 xrb->Base.PutValues = put_values_5R6G5B_pixmap;
4647 xrb->Base.PutMonoValues = put_mono_values_pixmap;
4650 xrb->Base.PutRow = put_row_5R6G5B_ximage;
4651 xrb->Base.PutRowRGB = put_row_rgb_5R6G5B_ximage;
4652 xrb->Base.PutMonoRow = put_mono_row_ximage;
4653 xrb->Base.PutValues = put_values_5R6G5B_ximage;
4654 xrb->Base.PutMonoValues = put_mono_values_ximage;
4657 case PF_Dither_5R6G5B:
4659 xrb->Base.PutRow = put_row_DITHER_5R6G5B_pixmap;
4660 xrb->Base.PutRowRGB = put_row_rgb_DITHER_5R6G5B_pixmap;
4661 xrb->Base.PutMonoRow = put_mono_row_TRUEDITHER_pixmap;
4662 xrb->Base.PutValues = put_values_DITHER_5R6G5B_pixmap;
4663 xrb->Base.PutMonoValues = put_mono_values_TRUEDITHER_pixmap;
4666 xrb->Base.PutRow = put_row_DITHER_5R6G5B_ximage;
4667 xrb->Base.PutRowRGB = put_row_rgb_DITHER_5R6G5B_ximage;
4668 xrb->Base.PutMonoRow = put_mono_row_DITHER_5R6G5B_ximage;
4669 xrb->Base.PutValues = put_values_DITHER_5R6G5B_ximage;
4670 xrb->Base.PutMonoValues = put_mono_values_DITHER_5R6G5B_ximage;
4675 xrb->Base.PutRow = put_row_DITHER_pixmap;
4676 xrb->Base.PutRowRGB = put_row_rgb_DITHER_pixmap;
4677 xrb->Base.PutMonoRow = put_mono_row_DITHER_pixmap;
4678 xrb->Base.PutValues = put_values_DITHER_pixmap;
4679 xrb->Base.PutMonoValues = put_mono_values_DITHER_pixmap;
4683 xrb->Base.PutRow = put_row_DITHER8_ximage;
4684 xrb->Base.PutRowRGB = put_row_rgb_DITHER8_ximage;
4685 xrb->Base.PutMonoRow = put_mono_row_DITHER8_ximage;
4686 xrb->Base.PutValues = put_values_DITHER8_ximage;
4687 xrb->Base.PutMonoValues = put_mono_values_DITHER8_ximage;
4690 xrb->Base.PutRow = put_row_DITHER_ximage;
4691 xrb->Base.PutRowRGB = put_row_rgb_DITHER_ximage;
4692 xrb->Base.PutMonoRow = put_mono_row_DITHER_ximage;
4693 xrb->Base.PutValues = put_values_DITHER_ximage;
4694 xrb->Base.PutMonoValues = put_mono_values_DITHER_ximage;
4700 xrb->Base.PutRow = put_row_1BIT_pixmap;
4701 xrb->Base.PutRowRGB = put_row_rgb_1BIT_pixmap;
4702 xrb->Base.PutMonoRow = put_mono_row_1BIT_pixmap;
4703 xrb->Base.PutValues = put_values_1BIT_pixmap;
4704 xrb->Base.PutMonoValues = put_mono_values_1BIT_pixmap;
4707 xrb->Base.PutRow = put_row_1BIT_ximage;
4708 xrb->Base.PutRowRGB = put_row_rgb_1BIT_ximage;
4709 xrb->Base.PutMonoRow = put_mono_row_1BIT_ximage;
4710 xrb->Base.PutValues = put_values_1BIT_ximage;
4711 xrb->Base.PutMonoValues = put_mono_values_1BIT_ximage;
4716 xrb->Base.PutRow = put_row_HPCR_pixmap;
4717 xrb->Base.PutRowRGB = put_row_rgb_HPCR_pixmap;
4718 xrb->Base.PutMonoRow = put_mono_row_pixmap;
4719 xrb->Base.PutValues = put_values_HPCR_pixmap;
4720 xrb->Base.PutMonoValues = put_mono_values_pixmap;
4723 xrb->Base.PutRow = put_row_HPCR_ximage;
4724 xrb->Base.PutRowRGB = put_row_rgb_HPCR_ximage;
4725 xrb->Base.PutMonoRow = put_mono_row_HPCR_ximage;
4726 xrb->Base.PutValues = put_values_HPCR_ximage;
4727 xrb->Base.PutMonoValues = put_mono_values_HPCR_ximage;
4732 xrb->Base.PutRow = put_row_LOOKUP_pixmap;
4733 xrb->Base.PutRowRGB = put_row_rgb_LOOKUP_pixmap;
4734 xrb->Base.PutMonoRow = put_mono_row_pixmap;
4735 xrb->Base.PutValues = put_values_LOOKUP_pixmap;
4736 xrb->Base.PutMonoValues = put_mono_values_pixmap;
4740 xrb->Base.PutRow = put_row_LOOKUP8_ximage;
4741 xrb->Base.PutRowRGB = put_row_rgb_LOOKUP8_ximage;
4742 xrb->Base.PutMonoRow = put_mono_row_LOOKUP8_ximage;
4743 xrb->Base.PutValues = put_values_LOOKUP8_ximage;
4744 xrb->Base.PutMonoValues = put_mono_values_LOOKUP8_ximage;
4747 xrb->Base.PutRow = put_row_LOOKUP_ximage;
4748 xrb->Base.PutRowRGB = put_row_rgb_LOOKUP_ximage;
4749 xrb->Base.PutMonoRow = put_mono_row_ximage;
4750 xrb->Base.PutValues = put_values_LOOKUP_ximage;
4751 xrb->Base.PutMonoValues = put_mono_values_ximage;
4757 xrb->Base.PutRow = put_row_GRAYSCALE_pixmap;
4758 xrb->Base.PutRowRGB = put_row_rgb_GRAYSCALE_pixmap;
4759 xrb->Base.PutMonoRow = put_mono_row_pixmap;
4760 xrb->Base.PutValues = put_values_GRAYSCALE_pixmap;
4761 xrb->Base.PutMonoValues = put_mono_values_pixmap;
4765 xrb->Base.PutRow = put_row_GRAYSCALE8_ximage;
4766 xrb->Base.PutRowRGB = put_row_rgb_GRAYSCALE8_ximage;
4767 xrb->Base.PutMonoRow = put_mono_row_GRAYSCALE8_ximage;
4768 xrb->Base.PutValues = put_values_GRAYSCALE8_ximage;
4769 xrb->Base.PutMonoValues = put_mono_values_GRAYSCALE8_ximage;
4772 xrb->Base.PutRow = put_row_GRAYSCALE_ximage;
4773 xrb->Base.PutRowRGB = put_row_rgb_GRAYSCALE_ximage;
4774 xrb->Base.PutMonoRow = put_mono_row_ximage;
4775 xrb->Base.PutValues = put_values_GRAYSCALE_ximage;
4776 xrb->Base.PutMonoValues = put_mono_values_ximage;
4781 _mesa_problem(NULL, "Bad pixel format in xmesa_update_state (1)");
4787 if (pixelformat == PF_Index) {
4788 xrb->Base.GetRow = get_row_ci;
4789 xrb->Base.GetValues = get_values_ci;
4792 xrb->Base.GetRow = get_row_rgba;
4793 xrb->Base.GetValues = get_values_rgba;