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