bumped nouveau DRM interface version number
[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 * Write a span of PF_8A8B8G8R-format pixels to an ximage.
1308 */
1309 static void put_row_8A8B8G8R_ximage( PUT_ROW_ARGS )
1310 {
1311 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
1312 GET_XRB(xrb);
1313 register GLuint i;
1314 register GLuint *ptr = PIXEL_ADDR4(xrb, x, y);
1315 (void) ctx;
1316 if (mask) {
1317 for (i=0;i<n;i++) {
1318 if (mask[i]) {
1319 ptr[i] = PACK_8A8B8G8R( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP], rgba[i][ACOMP] );
1320 }
1321 }
1322 }
1323 else {
1324 /* draw all pixels */
1325 for (i=0;i<n;i++) {
1326 ptr[i] = PACK_8A8B8G8R( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP], rgba[i][ACOMP] );
1327 }
1328 }
1329 }
1330
1331
1332 /*
1333 * Write a span of PF_8A8B8G8R-format pixels to an ximage (no alpha).
1334 */
1335 static void put_row_rgb_8A8B8G8R_ximage( RGB_SPAN_ARGS )
1336 {
1337 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
1338 GET_XRB(xrb);
1339 register GLuint i;
1340 register GLuint *ptr = PIXEL_ADDR4(xrb, x, y);
1341 if (mask) {
1342 for (i=0;i<n;i++) {
1343 if (mask[i]) {
1344 ptr[i] = PACK_8A8B8G8R( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP], 255 );
1345 }
1346 }
1347 }
1348 else {
1349 /* draw all pixels */
1350 for (i=0;i<n;i++) {
1351 ptr[i] = PACK_8A8B8G8R( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP], 255 );
1352 }
1353 }
1354 }
1355
1356 /*
1357 * Write a span of PF_8A8R8G8B-format pixels to an ximage.
1358 */
1359 static void put_row_8A8R8G8B_ximage( PUT_ROW_ARGS )
1360 {
1361 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
1362 GET_XRB(xrb);
1363 register GLuint i;
1364 register GLuint *ptr = PIXEL_ADDR4(xrb, x, y);
1365 if (mask) {
1366 for (i=0;i<n;i++) {
1367 if (mask[i]) {
1368 ptr[i] = PACK_8A8R8G8B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP], rgba[i][ACOMP] );
1369 }
1370 }
1371 }
1372 else {
1373 /* draw all pixels */
1374 for (i=0;i<n;i++) {
1375 ptr[i] = PACK_8A8R8G8B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP], rgba[i][ACOMP] );
1376 }
1377 }
1378 }
1379
1380
1381 /*
1382 * Write a span of PF_8A8R8G8B-format pixels to an ximage (no alpha).
1383 */
1384 static void put_row_rgb_8A8R8G8B_ximage( RGB_SPAN_ARGS )
1385 {
1386 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
1387 GET_XRB(xrb);
1388 register GLuint i;
1389 register GLuint *ptr = PIXEL_ADDR4(xrb, x, y);
1390 if (mask) {
1391 for (i=0;i<n;i++) {
1392 if (mask[i]) {
1393 ptr[i] = PACK_8A8R8G8B( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP], 255 );
1394 }
1395 }
1396 }
1397 else {
1398 /* draw all pixels */
1399 for (i=0;i<n;i++) {
1400 ptr[i] = PACK_8A8R8G8B( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP], 255 );
1401 }
1402 }
1403 }
1404
1405
1406 /*
1407 * Write a span of PF_8R8G8B-format pixels to an ximage.
1408 */
1409 static void put_row_8R8G8B_ximage( PUT_ROW_ARGS )
1410 {
1411 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
1412 GET_XRB(xrb);
1413 register GLuint i;
1414 register GLuint *ptr = PIXEL_ADDR4(xrb, x, y);
1415 if (mask) {
1416 for (i=0;i<n;i++) {
1417 if (mask[i]) {
1418 ptr[i] = PACK_8R8G8B(rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
1419 }
1420 }
1421 }
1422 else {
1423 for (i=0;i<n;i++) {
1424 ptr[i] = PACK_8R8G8B(rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
1425 }
1426 }
1427 }
1428
1429
1430 /*
1431 * Write a span of PF_8R8G8B24-format pixels to an ximage.
1432 */
1433 static void put_row_8R8G8B24_ximage( PUT_ROW_ARGS )
1434 {
1435 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
1436 GET_XRB(xrb);
1437 register GLuint i;
1438 register GLubyte *ptr = (GLubyte *) PIXEL_ADDR3(xrb, x, y );
1439 if (mask) {
1440 for (i=0;i<n;i++) {
1441 if (mask[i]) {
1442 GLuint *ptr4 = (GLuint *) ptr;
1443 register GLuint pixel = *ptr4;
1444 switch (3 & (int)(ptr - (GLubyte*)ptr4)) {
1445 case 0:
1446 pixel &= 0xff000000;
1447 pixel |= rgba[i][BCOMP];
1448 pixel |= rgba[i][GCOMP] << 8;
1449 pixel |= rgba[i][RCOMP] << 16;
1450 *ptr4 = pixel;
1451 break;
1452 case 3:
1453 pixel &= 0x00ffffff;
1454 pixel |= rgba[i][BCOMP] << 24;
1455 *ptr4++ = pixel;
1456 pixel = *ptr4 & 0xffff0000;
1457 pixel |= rgba[i][GCOMP];
1458 pixel |= rgba[i][RCOMP] << 8;
1459 *ptr4 = pixel;
1460 break;
1461 case 2:
1462 pixel &= 0x0000ffff;
1463 pixel |= rgba[i][BCOMP] << 16;
1464 pixel |= rgba[i][GCOMP] << 24;
1465 *ptr4++ = pixel;
1466 pixel = *ptr4 & 0xffffff00;
1467 pixel |= rgba[i][RCOMP];
1468 *ptr4 = pixel;
1469 break;
1470 case 1:
1471 pixel &= 0x000000ff;
1472 pixel |= rgba[i][BCOMP] << 8;
1473 pixel |= rgba[i][GCOMP] << 16;
1474 pixel |= rgba[i][RCOMP] << 24;
1475 *ptr4 = pixel;
1476 break;
1477 }
1478 }
1479 ptr += 3;
1480 }
1481 }
1482 else {
1483 /* write all pixels */
1484 int w = n;
1485 GLuint *ptr4 = (GLuint *) ptr;
1486 register GLuint pixel = *ptr4;
1487 int index = (int)(ptr - (GLubyte *)ptr4);
1488 register GLuint i = 0;
1489 switch (index) {
1490 case 0:
1491 break;
1492 case 1:
1493 pixel &= 0x00ffffff;
1494 pixel |= rgba[i][BCOMP] << 24;
1495 *ptr4++ = pixel;
1496 pixel = *ptr4 & 0xffff0000;
1497 pixel |= rgba[i][GCOMP];
1498 pixel |= rgba[i++][RCOMP] << 8;
1499 *ptr4 = pixel;
1500 if (0 == --w)
1501 break;
1502 case 2:
1503 pixel &= 0x0000ffff;
1504 pixel |= rgba[i][BCOMP] << 16;
1505 pixel |= rgba[i][GCOMP] << 24;
1506 *ptr4++ = pixel;
1507 pixel = *ptr4 & 0xffffff00;
1508 pixel |= rgba[i++][RCOMP];
1509 *ptr4 = pixel;
1510 if (0 == --w)
1511 break;
1512 case 3:
1513 pixel &= 0x000000ff;
1514 pixel |= rgba[i][BCOMP] << 8;
1515 pixel |= rgba[i][GCOMP] << 16;
1516 pixel |= rgba[i++][RCOMP] << 24;
1517 *ptr4++ = pixel;
1518 if (0 == --w)
1519 break;
1520 break;
1521 }
1522 while (w > 3) {
1523 pixel = rgba[i][BCOMP];
1524 pixel |= rgba[i][GCOMP] << 8;
1525 pixel |= rgba[i++][RCOMP] << 16;
1526 pixel |= rgba[i][BCOMP] << 24;
1527 *ptr4++ = pixel;
1528 pixel = rgba[i][GCOMP];
1529 pixel |= rgba[i++][RCOMP] << 8;
1530 pixel |= rgba[i][BCOMP] << 16;
1531 pixel |= rgba[i][GCOMP] << 24;
1532 *ptr4++ = pixel;
1533 pixel = rgba[i++][RCOMP];
1534 pixel |= rgba[i][BCOMP] << 8;
1535 pixel |= rgba[i][GCOMP] << 16;
1536 pixel |= rgba[i++][RCOMP] << 24;
1537 *ptr4++ = pixel;
1538 w -= 4;
1539 }
1540 switch (w) {
1541 case 0:
1542 break;
1543 case 1:
1544 pixel = *ptr4 & 0xff000000;
1545 pixel |= rgba[i][BCOMP];
1546 pixel |= rgba[i][GCOMP] << 8;
1547 pixel |= rgba[i][RCOMP] << 16;
1548 *ptr4 = pixel;
1549 break;
1550 case 2:
1551 pixel = rgba[i][BCOMP];
1552 pixel |= rgba[i][GCOMP] << 8;
1553 pixel |= rgba[i++][RCOMP] << 16;
1554 pixel |= rgba[i][BCOMP] << 24;
1555 *ptr4++ = pixel;
1556 pixel = *ptr4 & 0xffff0000;
1557 pixel |= rgba[i][GCOMP];
1558 pixel |= rgba[i][RCOMP] << 8;
1559 *ptr4 = pixel;
1560 break;
1561 case 3:
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 = rgba[i][GCOMP];
1568 pixel |= rgba[i++][RCOMP] << 8;
1569 pixel |= rgba[i][BCOMP] << 16;
1570 pixel |= rgba[i][GCOMP] << 24;
1571 *ptr4++ = pixel;
1572 pixel = *ptr4 & 0xffffff00;
1573 pixel |= rgba[i][RCOMP];
1574 *ptr4 = pixel;
1575 break;
1576 }
1577 }
1578 }
1579
1580
1581 /*
1582 * Write a span of PF_8R8G8B-format pixels to an ximage (no alpha).
1583 */
1584 static void put_row_rgb_8R8G8B_ximage( RGB_SPAN_ARGS )
1585 {
1586 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
1587 GET_XRB(xrb);
1588 register GLuint i;
1589 register GLuint *ptr = PIXEL_ADDR4(xrb, x, y);
1590 if (mask) {
1591 for (i=0;i<n;i++) {
1592 if (mask[i]) {
1593 ptr[i] = PACK_8R8G8B(rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]);
1594 }
1595 }
1596 }
1597 else {
1598 /* draw all pixels */
1599 for (i=0;i<n;i++) {
1600 ptr[i] = PACK_8R8G8B(rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]);
1601 }
1602 }
1603 }
1604
1605
1606 /*
1607 * Write a span of PF_8R8G8B24-format pixels to an ximage (no alpha).
1608 */
1609 static void put_row_rgb_8R8G8B24_ximage( RGB_SPAN_ARGS )
1610 {
1611 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
1612 GET_XRB(xrb);
1613 register GLuint i;
1614 register GLubyte *ptr = (GLubyte *) PIXEL_ADDR3(xrb, x, y);
1615 if (mask) {
1616 for (i=0;i<n;i++) {
1617 if (mask[i]) {
1618 *ptr++ = rgb[i][BCOMP];
1619 *ptr++ = rgb[i][GCOMP];
1620 *ptr++ = rgb[i][RCOMP];
1621 }
1622 else {
1623 ptr += 3;
1624 }
1625 }
1626 }
1627 else {
1628 /* draw all pixels */
1629 for (i=0;i<n;i++) {
1630 *ptr++ = rgb[i][BCOMP];
1631 *ptr++ = rgb[i][GCOMP];
1632 *ptr++ = rgb[i][RCOMP];
1633 }
1634 }
1635 }
1636
1637
1638 /*
1639 * Write a span of PF_5R6G5B-format pixels to an ximage.
1640 */
1641 static void put_row_5R6G5B_ximage( PUT_ROW_ARGS )
1642 {
1643 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
1644 GET_XRB(xrb);
1645 register GLuint i;
1646 register GLushort *ptr = PIXEL_ADDR2(xrb, x, y);
1647 if (mask) {
1648 for (i=0;i<n;i++) {
1649 if (mask[i]) {
1650 ptr[i] = PACK_5R6G5B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
1651 }
1652 }
1653 }
1654 else {
1655 /* draw all pixels */
1656 #if defined(__i386__) /* word stores don't have to be on 4-byte boundaries */
1657 GLuint *ptr32 = (GLuint *) ptr;
1658 GLuint extraPixel = (n & 1);
1659 n -= extraPixel;
1660 for (i = 0; i < n; i += 2) {
1661 GLuint p0, p1;
1662 p0 = PACK_5R6G5B(rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
1663 p1 = PACK_5R6G5B(rgba[i+1][RCOMP], rgba[i+1][GCOMP], rgba[i+1][BCOMP]);
1664 *ptr32++ = (p1 << 16) | p0;
1665 }
1666 if (extraPixel) {
1667 ptr[n] = PACK_5R6G5B(rgba[n][RCOMP], rgba[n][GCOMP], rgba[n][BCOMP]);
1668 }
1669 #else
1670 for (i = 0; i < n; i++) {
1671 ptr[i] = PACK_5R6G5B(rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
1672 }
1673 #endif
1674 }
1675 }
1676
1677
1678 /*
1679 * Write a span of PF_DITHER_5R6G5B-format pixels to an ximage.
1680 */
1681 static void put_row_DITHER_5R6G5B_ximage( PUT_ROW_ARGS )
1682 {
1683 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
1684 GET_XRB(xrb);
1685 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
1686 register GLuint i;
1687 register GLushort *ptr = PIXEL_ADDR2(xrb, x, y);
1688 const GLint y2 = YFLIP(xrb, y);
1689 if (mask) {
1690 for (i=0;i<n;i++,x++) {
1691 if (mask[i]) {
1692 PACK_TRUEDITHER( ptr[i], x, y2, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
1693 }
1694 }
1695 }
1696 else {
1697 /* draw all pixels */
1698 #if defined(__i386__) /* word stores don't have to be on 4-byte boundaries */
1699 GLuint *ptr32 = (GLuint *) ptr;
1700 GLuint extraPixel = (n & 1);
1701 n -= extraPixel;
1702 for (i = 0; i < n; i += 2, x += 2) {
1703 GLuint p0, p1;
1704 PACK_TRUEDITHER( p0, x, y2, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
1705 PACK_TRUEDITHER( p1, x+1, y2, rgba[i+1][RCOMP], rgba[i+1][GCOMP], rgba[i+1][BCOMP] );
1706 *ptr32++ = (p1 << 16) | p0;
1707 }
1708 if (extraPixel) {
1709 PACK_TRUEDITHER( ptr[n], x+n, y2, rgba[n][RCOMP], rgba[n][GCOMP], rgba[n][BCOMP]);
1710 }
1711 #else
1712 for (i = 0; i < n; i++, x++) {
1713 PACK_TRUEDITHER( ptr[i], x, y2, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
1714 }
1715 #endif
1716 }
1717 }
1718
1719
1720 /*
1721 * Write a span of PF_5R6G5B-format pixels to an ximage (no alpha).
1722 */
1723 static void put_row_rgb_5R6G5B_ximage( RGB_SPAN_ARGS )
1724 {
1725 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
1726 GET_XRB(xrb);
1727 register GLuint i;
1728 register GLushort *ptr = PIXEL_ADDR2(xrb, x, y);
1729 if (mask) {
1730 for (i=0;i<n;i++) {
1731 if (mask[i]) {
1732 ptr[i] = PACK_5R6G5B( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
1733 }
1734 }
1735 }
1736 else {
1737 /* draw all pixels */
1738 #if defined(__i386__) /* word stores don't have to be on 4-byte boundaries */
1739 GLuint *ptr32 = (GLuint *) ptr;
1740 GLuint extraPixel = (n & 1);
1741 n -= extraPixel;
1742 for (i = 0; i < n; i += 2) {
1743 GLuint p0, p1;
1744 p0 = PACK_5R6G5B(rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]);
1745 p1 = PACK_5R6G5B(rgb[i+1][RCOMP], rgb[i+1][GCOMP], rgb[i+1][BCOMP]);
1746 *ptr32++ = (p1 << 16) | p0;
1747 }
1748 if (extraPixel) {
1749 ptr[n] = PACK_5R6G5B(rgb[n][RCOMP], rgb[n][GCOMP], rgb[n][BCOMP]);
1750 }
1751 #else
1752 for (i=0;i<n;i++) {
1753 ptr[i] = PACK_5R6G5B( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
1754 }
1755 #endif
1756 }
1757 }
1758
1759
1760 /*
1761 * Write a span of PF_DITHER_5R6G5B-format pixels to an ximage (no alpha).
1762 */
1763 static void put_row_rgb_DITHER_5R6G5B_ximage( RGB_SPAN_ARGS )
1764 {
1765 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
1766 GET_XRB(xrb);
1767 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
1768 register GLuint i;
1769 register GLushort *ptr = PIXEL_ADDR2(xrb, x, y );
1770 if (mask) {
1771 for (i=0;i<n;i++,x++) {
1772 if (mask[i]) {
1773 PACK_TRUEDITHER( ptr[i], x, y, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
1774 }
1775 }
1776 }
1777 else {
1778 /* draw all pixels */
1779 #if defined(__i386__) /* word stores don't have to be on 4-byte boundaries */
1780 GLuint *ptr32 = (GLuint *) ptr;
1781 GLuint extraPixel = (n & 1);
1782 n -= extraPixel;
1783 for (i = 0; i < n; i += 2, x += 2) {
1784 GLuint p0, p1;
1785 PACK_TRUEDITHER( p0, x, y, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
1786 PACK_TRUEDITHER( p1, x+1, y, rgb[i+1][RCOMP], rgb[i+1][GCOMP], rgb[i+1][BCOMP] );
1787 *ptr32++ = (p1 << 16) | p0;
1788 }
1789 if (extraPixel) {
1790 PACK_TRUEDITHER( ptr[n], x+n, y, rgb[n][RCOMP], rgb[n][GCOMP], rgb[n][BCOMP]);
1791 }
1792 #else
1793 for (i=0;i<n;i++,x++) {
1794 PACK_TRUEDITHER( ptr[i], x, y, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
1795 }
1796 #endif
1797 }
1798 }
1799
1800
1801 /*
1802 * Write a span of PF_DITHER pixels to an XImage.
1803 */
1804 static void put_row_DITHER_ximage( PUT_ROW_ARGS )
1805 {
1806 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
1807 GET_XRB(xrb);
1808 XMesaImage *img = xrb->ximage;
1809 register GLuint i;
1810 int yy = YFLIP(xrb, y);
1811 XDITHER_SETUP(yy);
1812 if (mask) {
1813 for (i=0;i<n;i++,x++) {
1814 if (mask[i]) {
1815 XMesaPutPixel( img, x, yy, XDITHER( x, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
1816 }
1817 }
1818 }
1819 else {
1820 /* draw all pixels */
1821 for (i=0;i<n;i++,x++) {
1822 XMesaPutPixel( img, x, yy, XDITHER( x, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
1823 }
1824 }
1825 }
1826
1827
1828 /*
1829 * Write a span of PF_DITHER pixels to an XImage (no alpha).
1830 */
1831 static void put_row_rgb_DITHER_ximage( RGB_SPAN_ARGS )
1832 {
1833 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
1834 GET_XRB(xrb);
1835 XMesaImage *img = xrb->ximage;
1836 register GLuint i;
1837 int yy = YFLIP(xrb, y);
1838 XDITHER_SETUP(yy);
1839 if (mask) {
1840 for (i=0;i<n;i++,x++) {
1841 if (mask[i]) {
1842 XMesaPutPixel( img, x, yy, XDITHER( x, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] ) );
1843 }
1844 }
1845 }
1846 else {
1847 /* draw all pixels */
1848 for (i=0;i<n;i++,x++) {
1849 XMesaPutPixel( img, x, yy, XDITHER( x, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] ) );
1850 }
1851 }
1852 }
1853
1854
1855
1856 /*
1857 * Write a span of 8-bit PF_DITHER pixels to an XImage.
1858 */
1859 static void put_row_DITHER8_ximage( PUT_ROW_ARGS )
1860 {
1861 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
1862 GET_XRB(xrb);
1863 register GLuint i;
1864 register GLubyte *ptr = PIXEL_ADDR1(xrb, x, y);
1865 XDITHER_SETUP(y);
1866 if (mask) {
1867 for (i=0;i<n;i++,x++) {
1868 if (mask[i]) {
1869 ptr[i] = (GLubyte) XDITHER( x, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
1870 }
1871 }
1872 }
1873 else {
1874 for (i=0;i<n;i++,x++) {
1875 ptr[i] = (GLubyte) XDITHER( x, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
1876 }
1877 }
1878 }
1879
1880
1881 static void put_row_rgb_DITHER8_ximage( RGB_SPAN_ARGS )
1882 {
1883 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
1884 GET_XRB(xrb);
1885 register GLuint i;
1886 register GLubyte *ptr = PIXEL_ADDR1(xrb, x, y);
1887 XDITHER_SETUP(y);
1888 if (mask) {
1889 for (i=0;i<n;i++,x++) {
1890 if (mask[i]) {
1891 ptr[i] = (GLubyte) XDITHER( x, rgb[i][0], rgb[i][1], rgb[i][2] );
1892 }
1893 }
1894 }
1895 else {
1896 const GLubyte *data = (GLubyte *) rgb;
1897 for (i=0;i<n;i++,x++) {
1898 /*ptr[i] = XDITHER( x, rgb[i][0], rgb[i][1], rgb[i][2] );*/
1899 ptr[i] = (GLubyte) XDITHER( x, data[i+i+i], data[i+i+i+1], data[i+i+i+2] );
1900 }
1901 }
1902 }
1903
1904
1905
1906 /*
1907 * Write a span of PF_1BIT pixels to an XImage.
1908 */
1909 static void put_row_1BIT_ximage( PUT_ROW_ARGS )
1910 {
1911 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
1912 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
1913 GET_XRB(xrb);
1914 XMesaImage *img = xrb->ximage;
1915 register GLuint i;
1916 SETUP_1BIT;
1917 y = YFLIP(xrb, y);
1918 if (mask) {
1919 for (i=0;i<n;i++,x++) {
1920 if (mask[i]) {
1921 XMesaPutPixel(img, x, y, DITHER_1BIT(x, y, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]));
1922 }
1923 }
1924 }
1925 else {
1926 for (i=0;i<n;i++,x++) {
1927 XMesaPutPixel( img, x, y, DITHER_1BIT(x, y, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]) );
1928 }
1929 }
1930 }
1931
1932
1933 /*
1934 * Write a span of PF_1BIT pixels to an XImage (no alpha).
1935 */
1936 static void put_row_rgb_1BIT_ximage( RGB_SPAN_ARGS )
1937 {
1938 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
1939 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
1940 GET_XRB(xrb);
1941 XMesaImage *img = xrb->ximage;
1942 register GLuint i;
1943 SETUP_1BIT;
1944 y = YFLIP(xrb, y);
1945 if (mask) {
1946 for (i=0;i<n;i++,x++) {
1947 if (mask[i]) {
1948 XMesaPutPixel(img, x, y, DITHER_1BIT(x, y, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]));
1949 }
1950 }
1951 }
1952 else {
1953 for (i=0;i<n;i++,x++) {
1954 XMesaPutPixel( img, x, y, DITHER_1BIT(x, y, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP]) );
1955 }
1956 }
1957 }
1958
1959
1960 /*
1961 * Write a span of PF_HPCR pixels to an XImage.
1962 */
1963 static void put_row_HPCR_ximage( PUT_ROW_ARGS )
1964 {
1965 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
1966 GET_XRB(xrb);
1967 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
1968 register GLuint i;
1969 register GLubyte *ptr = PIXEL_ADDR1(xrb, x, y);
1970 if (mask) {
1971 for (i=0;i<n;i++,x++) {
1972 if (mask[i]) {
1973 ptr[i] = DITHER_HPCR( x, y, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
1974 }
1975 }
1976 }
1977 else {
1978 /* draw all pixels */
1979 for (i=0;i<n;i++,x++) {
1980 ptr[i] = DITHER_HPCR( x, y, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
1981 }
1982 }
1983 }
1984
1985
1986 /*
1987 * Write a span of PF_HPCR pixels to an XImage (no alpha).
1988 */
1989 static void put_row_rgb_HPCR_ximage( RGB_SPAN_ARGS )
1990 {
1991 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
1992 GET_XRB(xrb);
1993 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
1994 register GLuint i;
1995 register GLubyte *ptr = PIXEL_ADDR1(xrb, x, y);
1996 if (mask) {
1997 for (i=0;i<n;i++,x++) {
1998 if (mask[i]) {
1999 ptr[i] = DITHER_HPCR( x, y, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
2000 }
2001 }
2002 }
2003 else {
2004 /* draw all pixels */
2005 for (i=0;i<n;i++,x++) {
2006 ptr[i] = DITHER_HPCR( x, y, rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
2007 }
2008 }
2009 }
2010
2011
2012 /*
2013 * Write a span of PF_LOOKUP pixels to an XImage.
2014 */
2015 static void put_row_LOOKUP_ximage( PUT_ROW_ARGS )
2016 {
2017 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2018 GET_XRB(xrb);
2019 XMesaImage *img = xrb->ximage;
2020 register GLuint i;
2021 LOOKUP_SETUP;
2022 y = YFLIP(xrb, y);
2023 if (mask) {
2024 for (i=0;i<n;i++,x++) {
2025 if (mask[i]) {
2026 XMesaPutPixel( img, x, y, LOOKUP( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
2027 }
2028 }
2029 }
2030 else {
2031 /* draw all pixels */
2032 for (i=0;i<n;i++,x++) {
2033 XMesaPutPixel( img, x, y, LOOKUP( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
2034 }
2035 }
2036 }
2037
2038
2039 /*
2040 * Write a span of PF_LOOKUP pixels to an XImage (no alpha).
2041 */
2042 static void put_row_rgb_LOOKUP_ximage( RGB_SPAN_ARGS )
2043 {
2044 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
2045 GET_XRB(xrb);
2046 XMesaImage *img = xrb->ximage;
2047 register GLuint i;
2048 LOOKUP_SETUP;
2049 y = YFLIP(xrb, y);
2050 if (mask) {
2051 for (i=0;i<n;i++,x++) {
2052 if (mask[i]) {
2053 XMesaPutPixel( img, x, y, LOOKUP( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] ) );
2054 }
2055 }
2056 }
2057 else {
2058 /* draw all pixels */
2059 for (i=0;i<n;i++,x++) {
2060 XMesaPutPixel( img, x, y, LOOKUP( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] ) );
2061 }
2062 }
2063 }
2064
2065
2066 /*
2067 * Write a span of 8-bit PF_LOOKUP pixels to an XImage.
2068 */
2069 static void put_row_LOOKUP8_ximage( PUT_ROW_ARGS )
2070 {
2071 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2072 GET_XRB(xrb);
2073 register GLuint i;
2074 register GLubyte *ptr = PIXEL_ADDR1(xrb, x, y);
2075 LOOKUP_SETUP;
2076 if (mask) {
2077 for (i=0;i<n;i++,x++) {
2078 if (mask[i]) {
2079 ptr[i] = (GLubyte) LOOKUP( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
2080 }
2081 }
2082 }
2083 else {
2084 /* draw all pixels */
2085 for (i=0;i<n;i++,x++) {
2086 ptr[i] = (GLubyte) LOOKUP( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
2087 }
2088 }
2089 }
2090
2091
2092 static void put_row_rgb_LOOKUP8_ximage( RGB_SPAN_ARGS )
2093 {
2094 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
2095 GET_XRB(xrb);
2096 register GLuint i;
2097 register GLubyte *ptr = PIXEL_ADDR1(xrb, x, y);
2098 LOOKUP_SETUP;
2099 if (mask) {
2100 for (i=0;i<n;i++,x++) {
2101 if (mask[i]) {
2102 ptr[i] = (GLubyte) LOOKUP( rgb[i][0], rgb[i][1], rgb[i][2] );
2103 }
2104 }
2105 }
2106 else {
2107 /* draw all pixels */
2108 const GLubyte *data = (GLubyte *) rgb;
2109 for (i=0;i<n;i++,x++) {
2110 /*ptr[i] = LOOKUP( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );*/
2111 ptr[i] = (GLubyte) LOOKUP( data[i+i+i], data[i+i+i+1], data[i+i+i+2] );
2112 }
2113 }
2114 }
2115
2116
2117 /*
2118 * Write a span of PF_GRAYSCALE pixels to an XImage.
2119 */
2120 static void put_row_GRAYSCALE_ximage( PUT_ROW_ARGS )
2121 {
2122 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2123 GET_XRB(xrb);
2124 XMesaImage *img = xrb->ximage;
2125 register GLuint i;
2126 y = YFLIP(xrb, y);
2127 if (mask) {
2128 for (i=0;i<n;i++,x++) {
2129 if (mask[i]) {
2130 XMesaPutPixel( img, x, y, GRAY_RGB( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
2131 }
2132 }
2133 }
2134 else {
2135 /* draw all pixels */
2136 for (i=0;i<n;i++,x++) {
2137 XMesaPutPixel( img, x, y, GRAY_RGB( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
2138 }
2139 }
2140 }
2141
2142
2143 /*
2144 * Write a span of PF_GRAYSCALE pixels to an XImage (no alpha).
2145 */
2146 static void put_row_rgb_GRAYSCALE_ximage( RGB_SPAN_ARGS )
2147 {
2148 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
2149 GET_XRB(xrb);
2150 XMesaImage *img = xrb->ximage;
2151 register GLuint i;
2152 y = YFLIP(xrb, y);
2153 if (mask) {
2154 for (i=0;i<n;i++,x++) {
2155 if (mask[i]) {
2156 XMesaPutPixel( img, x, y, GRAY_RGB( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] ) );
2157 }
2158 }
2159 }
2160 else {
2161 /* draw all pixels */
2162 for (i=0;i<n;i++,x++) {
2163 XMesaPutPixel( img, x, y, GRAY_RGB( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] ) );
2164 }
2165 }
2166 }
2167
2168
2169 /*
2170 * Write a span of 8-bit PF_GRAYSCALE pixels to an XImage.
2171 */
2172 static void put_row_GRAYSCALE8_ximage( PUT_ROW_ARGS )
2173 {
2174 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2175 GET_XRB(xrb);
2176 register GLuint i;
2177 register GLubyte *ptr = PIXEL_ADDR1(xrb, x, y);
2178 if (mask) {
2179 for (i=0;i<n;i++) {
2180 if (mask[i]) {
2181 ptr[i] = (GLubyte) GRAY_RGB( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
2182 }
2183 }
2184 }
2185 else {
2186 /* draw all pixels */
2187 for (i=0;i<n;i++) {
2188 ptr[i] = (GLubyte) GRAY_RGB( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
2189 }
2190 }
2191 }
2192
2193
2194 /*
2195 * Write a span of 8-bit PF_GRAYSCALE pixels to an XImage (no alpha).
2196 */
2197 static void put_row_rgb_GRAYSCALE8_ximage( RGB_SPAN_ARGS )
2198 {
2199 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
2200 GET_XRB(xrb);
2201 register GLuint i;
2202 register GLubyte *ptr = PIXEL_ADDR1(xrb, x, y);
2203 if (mask) {
2204 for (i=0;i<n;i++) {
2205 if (mask[i]) {
2206 ptr[i] = (GLubyte) GRAY_RGB( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
2207 }
2208 }
2209 }
2210 else {
2211 /* draw all pixels */
2212 for (i=0;i<n;i++) {
2213 ptr[i] = (GLubyte) GRAY_RGB( rgb[i][RCOMP], rgb[i][GCOMP], rgb[i][BCOMP] );
2214 }
2215 }
2216 }
2217
2218
2219
2220
2221 /**********************************************************************/
2222 /*** Write COLOR PIXEL functions ***/
2223 /**********************************************************************/
2224
2225
2226 #define PUT_VALUES_ARGS \
2227 GLcontext *ctx, struct gl_renderbuffer *rb, \
2228 GLuint n, const GLint x[], const GLint y[], \
2229 const void *values, const GLubyte mask[]
2230
2231
2232 /*
2233 * Write an array of PF_TRUECOLOR pixels to a pixmap.
2234 */
2235 static void put_values_TRUECOLOR_pixmap( PUT_VALUES_ARGS )
2236 {
2237 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2238 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2239 GET_XRB(xrb);
2240 XMesaDisplay *dpy = xmesa->xm_visual->display;
2241 XMesaDrawable buffer = xrb->drawable;
2242 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
2243 register GLuint i;
2244 for (i=0;i<n;i++) {
2245 if (mask[i]) {
2246 unsigned long p;
2247 PACK_TRUECOLOR( p, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
2248 XMesaSetForeground( dpy, gc, p );
2249 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) YFLIP(xrb, y[i]) );
2250 }
2251 }
2252 }
2253
2254
2255 /*
2256 * Write an array of PF_TRUEDITHER pixels to a pixmap.
2257 */
2258 static void put_values_TRUEDITHER_pixmap( PUT_VALUES_ARGS )
2259 {
2260 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2261 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2262 GET_XRB(xrb);
2263 XMesaDisplay *dpy = xmesa->xm_visual->display;
2264 XMesaDrawable buffer = xrb->drawable;
2265 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
2266 register GLuint i;
2267 for (i=0;i<n;i++) {
2268 if (mask[i]) {
2269 unsigned long p;
2270 PACK_TRUEDITHER(p, x[i], y[i], rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
2271 XMesaSetForeground( dpy, gc, p );
2272 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) YFLIP(xrb, y[i]) );
2273 }
2274 }
2275 }
2276
2277
2278 /*
2279 * Write an array of PF_8A8B8G8R pixels to a pixmap.
2280 */
2281 static void put_values_8A8B8G8R_pixmap( PUT_VALUES_ARGS )
2282 {
2283 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2284 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2285 GET_XRB(xrb);
2286 XMesaDisplay *dpy = xmesa->xm_visual->display;
2287 XMesaDrawable buffer = xrb->drawable;
2288 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
2289 register GLuint i;
2290 for (i=0;i<n;i++) {
2291 if (mask[i]) {
2292 XMesaSetForeground( dpy, gc,
2293 PACK_8A8B8G8R( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP], rgba[i][ACOMP] ));
2294 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) YFLIP(xrb, y[i]) );
2295 }
2296 }
2297 }
2298
2299 /*
2300 * Write an array of PF_8A8R8G8B pixels to a pixmap.
2301 */
2302 static void put_values_8A8R8G8B_pixmap( PUT_VALUES_ARGS )
2303 {
2304 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2305 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2306 GET_XRB(xrb);
2307 XMesaDisplay *dpy = xmesa->xm_visual->display;
2308 XMesaDrawable buffer = xrb->drawable;
2309 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
2310 register GLuint i;
2311 for (i=0;i<n;i++) {
2312 if (mask[i]) {
2313 XMesaSetForeground( dpy, gc,
2314 PACK_8A8R8G8B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP], rgba[i][ACOMP] ));
2315 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) YFLIP(xrb, y[i]) );
2316 }
2317 }
2318 }
2319
2320 /*
2321 * Write an array of PF_8R8G8B pixels to a pixmap.
2322 */
2323 static void put_values_8R8G8B_pixmap( PUT_VALUES_ARGS )
2324 {
2325 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2326 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2327 GET_XRB(xrb);
2328 XMesaDisplay *dpy = xmesa->xm_visual->display;
2329 XMesaDrawable buffer = xrb->drawable;
2330 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
2331 register GLuint i;
2332 for (i=0;i<n;i++) {
2333 if (mask[i]) {
2334 XMesaSetForeground( dpy, gc, PACK_8R8G8B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
2335 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) YFLIP(xrb, y[i]) );
2336 }
2337 }
2338 }
2339
2340
2341 /*
2342 * Write an array of PF_8R8G8B24 pixels to a pixmap.
2343 */
2344 static void put_values_8R8G8B24_pixmap( PUT_VALUES_ARGS )
2345 {
2346 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2347 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2348 GET_XRB(xrb);
2349 XMesaDisplay *dpy = xmesa->xm_visual->display;
2350 XMesaDrawable buffer = xrb->drawable;
2351 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
2352 register GLuint i;
2353 for (i=0;i<n;i++) {
2354 if (mask[i]) {
2355 XMesaSetForeground( dpy, gc, PACK_8R8G8B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
2356 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) YFLIP(xrb, y[i]) );
2357 }
2358 }
2359 }
2360
2361
2362 /*
2363 * Write an array of PF_5R6G5B pixels to a pixmap.
2364 */
2365 static void put_values_5R6G5B_pixmap( PUT_VALUES_ARGS )
2366 {
2367 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2368 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2369 GET_XRB(xrb);
2370 XMesaDisplay *dpy = xmesa->xm_visual->display;
2371 XMesaDrawable buffer = xrb->drawable;
2372 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
2373 register GLuint i;
2374 for (i=0;i<n;i++) {
2375 if (mask[i]) {
2376 XMesaSetForeground( dpy, gc, PACK_5R6G5B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
2377 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) YFLIP(xrb, y[i]) );
2378 }
2379 }
2380 }
2381
2382
2383 /*
2384 * Write an array of PF_DITHER_5R6G5B pixels to a pixmap.
2385 */
2386 static void put_values_DITHER_5R6G5B_pixmap( PUT_VALUES_ARGS )
2387 {
2388 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2389 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2390 GET_XRB(xrb);
2391 XMesaDisplay *dpy = xmesa->xm_visual->display;
2392 XMesaDrawable buffer = xrb->drawable;
2393 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
2394 register GLuint i;
2395 for (i=0;i<n;i++) {
2396 if (mask[i]) {
2397 unsigned long p;
2398 PACK_TRUEDITHER(p, x[i], y[i], rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
2399 XMesaSetForeground( dpy, gc, p );
2400 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) YFLIP(xrb, y[i]) );
2401 }
2402 }
2403 }
2404
2405
2406 /*
2407 * Write an array of PF_DITHER pixels to a pixmap.
2408 */
2409 static void put_values_DITHER_pixmap( PUT_VALUES_ARGS )
2410 {
2411 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2412 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2413 GET_XRB(xrb);
2414 XMesaDisplay *dpy = xmesa->xm_visual->display;
2415 XMesaDrawable buffer = xrb->drawable;
2416 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
2417 register GLuint i;
2418 DITHER_SETUP;
2419 for (i=0;i<n;i++) {
2420 if (mask[i]) {
2421 XMesaSetForeground( dpy, gc,
2422 DITHER(x[i], y[i], rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]) );
2423 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) YFLIP(xrb, y[i]) );
2424 }
2425 }
2426 }
2427
2428
2429 /*
2430 * Write an array of PF_1BIT pixels to a pixmap.
2431 */
2432 static void put_values_1BIT_pixmap( PUT_VALUES_ARGS )
2433 {
2434 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2435 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2436 GET_XRB(xrb);
2437 XMesaDisplay *dpy = xmesa->xm_visual->display;
2438 XMesaDrawable buffer = xrb->drawable;
2439 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
2440 register GLuint i;
2441 SETUP_1BIT;
2442 for (i=0;i<n;i++) {
2443 if (mask[i]) {
2444 XMesaSetForeground( dpy, gc,
2445 DITHER_1BIT( x[i], y[i], rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ));
2446 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) YFLIP(xrb, y[i]) );
2447 }
2448 }
2449 }
2450
2451
2452 /*
2453 * Write an array of PF_HPCR pixels to a pixmap.
2454 */
2455 static void put_values_HPCR_pixmap( PUT_VALUES_ARGS )
2456 {
2457 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2458 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2459 GET_XRB(xrb);
2460 XMesaDisplay *dpy = xmesa->xm_visual->display;
2461 XMesaDrawable buffer = xrb->drawable;
2462 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
2463 register GLuint i;
2464 for (i=0;i<n;i++) {
2465 if (mask[i]) {
2466 XMesaSetForeground( dpy, gc,
2467 DITHER_HPCR( x[i], y[i], rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ));
2468 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) YFLIP(xrb, y[i]) );
2469 }
2470 }
2471 }
2472
2473
2474 /*
2475 * Write an array of PF_LOOKUP pixels to a pixmap.
2476 */
2477 static void put_values_LOOKUP_pixmap( PUT_VALUES_ARGS )
2478 {
2479 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2480 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2481 GET_XRB(xrb);
2482 XMesaDisplay *dpy = xmesa->xm_visual->display;
2483 XMesaDrawable buffer = xrb->drawable;
2484 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
2485 register GLuint i;
2486 LOOKUP_SETUP;
2487 for (i=0;i<n;i++) {
2488 if (mask[i]) {
2489 XMesaSetForeground( dpy, gc, LOOKUP( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
2490 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) YFLIP(xrb, y[i]) );
2491 }
2492 }
2493 }
2494
2495
2496 /*
2497 * Write an array of PF_GRAYSCALE pixels to a pixmap.
2498 */
2499 static void put_values_GRAYSCALE_pixmap( PUT_VALUES_ARGS )
2500 {
2501 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2502 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2503 GET_XRB(xrb);
2504 XMesaDisplay *dpy = xmesa->xm_visual->display;
2505 XMesaDrawable buffer = xrb->drawable;
2506 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
2507 register GLuint i;
2508 for (i=0;i<n;i++) {
2509 if (mask[i]) {
2510 XMesaSetForeground( dpy, gc, GRAY_RGB( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
2511 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) YFLIP(xrb, y[i]) );
2512 }
2513 }
2514 }
2515
2516
2517 /*
2518 * Write an array of PF_TRUECOLOR pixels to an ximage.
2519 */
2520 static void put_values_TRUECOLOR_ximage( PUT_VALUES_ARGS )
2521 {
2522 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2523 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2524 GET_XRB(xrb);
2525 XMesaImage *img = xrb->ximage;
2526 register GLuint i;
2527 for (i=0;i<n;i++) {
2528 if (mask[i]) {
2529 unsigned long p;
2530 PACK_TRUECOLOR( p, rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
2531 XMesaPutPixel( img, x[i], YFLIP(xrb, y[i]), p );
2532 }
2533 }
2534 }
2535
2536
2537 /*
2538 * Write an array of PF_TRUEDITHER pixels to an XImage.
2539 */
2540 static void put_values_TRUEDITHER_ximage( PUT_VALUES_ARGS )
2541 {
2542 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2543 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2544 GET_XRB(xrb);
2545 XMesaImage *img = xrb->ximage;
2546 register GLuint i;
2547 for (i=0;i<n;i++) {
2548 if (mask[i]) {
2549 unsigned long p;
2550 PACK_TRUEDITHER(p, x[i], y[i], rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]);
2551 XMesaPutPixel( img, x[i], YFLIP(xrb, y[i]), p );
2552 }
2553 }
2554 }
2555
2556
2557 /*
2558 * Write an array of PF_8A8B8G8R pixels to an ximage.
2559 */
2560 static void put_values_8A8B8G8R_ximage( PUT_VALUES_ARGS )
2561 {
2562 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2563 GET_XRB(xrb);
2564 register GLuint i;
2565 for (i=0;i<n;i++) {
2566 if (mask[i]) {
2567 GLuint *ptr = PIXEL_ADDR4(xrb, x[i], y[i] );
2568 *ptr = PACK_8A8B8G8R( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP], rgba[i][ACOMP] );
2569 }
2570 }
2571 }
2572
2573 /*
2574 * Write an array of PF_8A8R8G8B pixels to an ximage.
2575 */
2576 static void put_values_8A8R8G8B_ximage( PUT_VALUES_ARGS )
2577 {
2578 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2579 GET_XRB(xrb);
2580 register GLuint i;
2581 for (i=0;i<n;i++) {
2582 if (mask[i]) {
2583 GLuint *ptr = PIXEL_ADDR4(xrb, x[i], y[i]);
2584 *ptr = PACK_8A8R8G8B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP], rgba[i][ACOMP] );
2585 }
2586 }
2587 }
2588
2589
2590 /*
2591 * Write an array of PF_8R8G8B pixels to an ximage.
2592 */
2593 static void put_values_8R8G8B_ximage( PUT_VALUES_ARGS )
2594 {
2595 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2596 GET_XRB(xrb);
2597 register GLuint i;
2598 for (i=0;i<n;i++) {
2599 if (mask[i]) {
2600 GLuint *ptr = PIXEL_ADDR4(xrb, x[i], y[i]);
2601 *ptr = PACK_8R8G8B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
2602 }
2603 }
2604 }
2605
2606
2607 /*
2608 * Write an array of PF_8R8G8B24 pixels to an ximage.
2609 */
2610 static void put_values_8R8G8B24_ximage( PUT_VALUES_ARGS )
2611 {
2612 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2613 GET_XRB(xrb);
2614 register GLuint i;
2615 for (i=0;i<n;i++) {
2616 if (mask[i]) {
2617 bgr_t *ptr = PIXEL_ADDR3(xrb, x[i], y[i] );
2618 ptr->r = rgba[i][RCOMP];
2619 ptr->g = rgba[i][GCOMP];
2620 ptr->b = rgba[i][BCOMP];
2621 }
2622 }
2623 }
2624
2625
2626 /*
2627 * Write an array of PF_5R6G5B pixels to an ximage.
2628 */
2629 static void put_values_5R6G5B_ximage( PUT_VALUES_ARGS )
2630 {
2631 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2632 GET_XRB(xrb);
2633 register GLuint i;
2634 for (i=0;i<n;i++) {
2635 if (mask[i]) {
2636 GLushort *ptr = PIXEL_ADDR2(xrb, x[i], y[i] );
2637 *ptr = PACK_5R6G5B( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
2638 }
2639 }
2640 }
2641
2642
2643 /*
2644 * Write an array of PF_DITHER_5R6G5B pixels to an ximage.
2645 */
2646 static void put_values_DITHER_5R6G5B_ximage( PUT_VALUES_ARGS )
2647 {
2648 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2649 GET_XRB(xrb);
2650 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2651 register GLuint i;
2652 for (i=0;i<n;i++) {
2653 if (mask[i]) {
2654 GLushort *ptr = PIXEL_ADDR2(xrb, x[i], y[i] );
2655 PACK_TRUEDITHER( *ptr, x[i], y[i], rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
2656 }
2657 }
2658 }
2659
2660
2661 /*
2662 * Write an array of PF_DITHER pixels to an XImage.
2663 */
2664 static void put_values_DITHER_ximage( PUT_VALUES_ARGS )
2665 {
2666 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2667 GET_XRB(xrb);
2668 XMesaImage *img = xrb->ximage;
2669 register GLuint i;
2670 DITHER_SETUP;
2671 for (i=0;i<n;i++) {
2672 if (mask[i]) {
2673 XMesaPutPixel( img, x[i], YFLIP(xrb, y[i]),
2674 DITHER( x[i], y[i], rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
2675 }
2676 }
2677 }
2678
2679
2680 /*
2681 * Write an array of 8-bit PF_DITHER pixels to an XImage.
2682 */
2683 static void put_values_DITHER8_ximage( PUT_VALUES_ARGS )
2684 {
2685 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2686 GET_XRB(xrb);
2687 register GLuint i;
2688 DITHER_SETUP;
2689 for (i=0;i<n;i++) {
2690 if (mask[i]) {
2691 GLubyte *ptr = PIXEL_ADDR1(xrb, x[i], y[i]);
2692 *ptr = (GLubyte) DITHER( x[i], y[i], rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
2693 }
2694 }
2695 }
2696
2697
2698 /*
2699 * Write an array of PF_1BIT pixels to an XImage.
2700 */
2701 static void put_values_1BIT_ximage( PUT_VALUES_ARGS )
2702 {
2703 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2704 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2705 GET_XRB(xrb);
2706 XMesaImage *img = xrb->ximage;
2707 register GLuint i;
2708 SETUP_1BIT;
2709 for (i=0;i<n;i++) {
2710 if (mask[i]) {
2711 XMesaPutPixel( img, x[i], YFLIP(xrb, y[i]),
2712 DITHER_1BIT( x[i], y[i], rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ));
2713 }
2714 }
2715 }
2716
2717
2718 /*
2719 * Write an array of PF_HPCR pixels to an XImage.
2720 */
2721 static void put_values_HPCR_ximage( PUT_VALUES_ARGS )
2722 {
2723 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2724 GET_XRB(xrb);
2725 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
2726 register GLuint i;
2727 for (i=0;i<n;i++) {
2728 if (mask[i]) {
2729 GLubyte *ptr = PIXEL_ADDR1(xrb, x[i], y[i]);
2730 *ptr = (GLubyte) DITHER_HPCR( x[i], y[i], rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
2731 }
2732 }
2733 }
2734
2735
2736 /*
2737 * Write an array of PF_LOOKUP pixels to an XImage.
2738 */
2739 static void put_values_LOOKUP_ximage( PUT_VALUES_ARGS )
2740 {
2741 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2742 GET_XRB(xrb);
2743 XMesaImage *img = xrb->ximage;
2744 register GLuint i;
2745 LOOKUP_SETUP;
2746 for (i=0;i<n;i++) {
2747 if (mask[i]) {
2748 XMesaPutPixel( img, x[i], YFLIP(xrb, y[i]), LOOKUP(rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP]) );
2749 }
2750 }
2751 }
2752
2753
2754 /*
2755 * Write an array of 8-bit PF_LOOKUP pixels to an XImage.
2756 */
2757 static void put_values_LOOKUP8_ximage( PUT_VALUES_ARGS )
2758 {
2759 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2760 GET_XRB(xrb);
2761 register GLuint i;
2762 LOOKUP_SETUP;
2763 for (i=0;i<n;i++) {
2764 if (mask[i]) {
2765 GLubyte *ptr = PIXEL_ADDR1(xrb, x[i], y[i]);
2766 *ptr = (GLubyte) LOOKUP( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
2767 }
2768 }
2769 }
2770
2771
2772 /*
2773 * Write an array of PF_GRAYSCALE pixels to an XImage.
2774 */
2775 static void put_values_GRAYSCALE_ximage( PUT_VALUES_ARGS )
2776 {
2777 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2778 GET_XRB(xrb);
2779 XMesaImage *img = xrb->ximage;
2780 register GLuint i;
2781 for (i=0;i<n;i++) {
2782 if (mask[i]) {
2783 XMesaPutPixel( img, x[i], YFLIP(xrb, y[i]),
2784 GRAY_RGB( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] ) );
2785 }
2786 }
2787 }
2788
2789
2790 /*
2791 * Write an array of 8-bit PF_GRAYSCALE pixels to an XImage.
2792 */
2793 static void put_values_GRAYSCALE8_ximage( PUT_VALUES_ARGS )
2794 {
2795 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
2796 GET_XRB(xrb);
2797 register GLuint i;
2798 for (i=0;i<n;i++) {
2799 if (mask[i]) {
2800 GLubyte *ptr = PIXEL_ADDR1(xrb, x[i], y[i] );
2801 *ptr = (GLubyte) GRAY_RGB( rgba[i][RCOMP], rgba[i][GCOMP], rgba[i][BCOMP] );
2802 }
2803 }
2804 }
2805
2806
2807
2808
2809 /**********************************************************************/
2810 /*** Write MONO COLOR SPAN functions ***/
2811 /**********************************************************************/
2812
2813 #define PUT_MONO_ROW_ARGS \
2814 GLcontext *ctx, struct gl_renderbuffer *rb, \
2815 GLuint n, GLint x, GLint y, const void *value, \
2816 const GLubyte mask[]
2817
2818
2819
2820 /*
2821 * Write a span of identical pixels to a pixmap.
2822 */
2823 static void put_mono_row_pixmap( PUT_MONO_ROW_ARGS )
2824 {
2825 const GLubyte *color = (const GLubyte *) value;
2826 GET_XRB(xrb);
2827 XMesaContext xmesa = XMESA_CONTEXT(ctx);
2828 XMesaDisplay *dpy = xmesa->xm_visual->display;
2829 XMesaDrawable buffer = xrb->drawable;
2830 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
2831 const unsigned long pixel = xmesa_color_to_pixel(ctx, color[RCOMP],
2832 color[GCOMP], color[BCOMP], color[ACOMP], xmesa->pixelformat);
2833 register GLuint i;
2834 XMesaSetForeground( xmesa->display, gc, pixel );
2835 y = YFLIP(xrb, y);
2836
2837 /* New code contributed by Jeff Epler and cleaned up by Keith
2838 * Whitwell.
2839 */
2840 for (i = 0; i < n; ) {
2841 GLuint start = i;
2842
2843 /* Identify and emit contiguous rendered pixels
2844 */
2845 while (i < n && (!mask || mask[i]))
2846 i++;
2847
2848 if (start < i)
2849 XMesaFillRectangle( dpy, buffer, gc,
2850 (int)(x+start), (int) y,
2851 (int)(i-start), 1);
2852
2853 /* Eat up non-rendered pixels
2854 */
2855 while (i < n && !mask[i])
2856 i++;
2857 }
2858 }
2859
2860
2861
2862 static void
2863 put_mono_row_ci_pixmap( PUT_MONO_ROW_ARGS )
2864 {
2865 GLuint colorIndex = *((GLuint *) value);
2866 XMesaContext xmesa = XMESA_CONTEXT(ctx);
2867 GET_XRB(xrb);
2868 XMesaDisplay *dpy = xmesa->xm_visual->display;
2869 XMesaDrawable buffer = xrb->drawable;
2870 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
2871 register GLuint i;
2872 XMesaSetForeground( xmesa->display, gc, colorIndex );
2873 y = YFLIP(xrb, y);
2874
2875 for (i = 0 ; i < n ;) {
2876 GLuint start = i;
2877
2878 /* Identify and emit contiguous rendered pixels
2879 */
2880 while (i < n && (!mask || mask[i]))
2881 i++;
2882
2883 if (start < i)
2884 XMesaFillRectangle( dpy, buffer, gc,
2885 (int)(x+start), (int) y,
2886 (int)(i-start), 1);
2887
2888 /* Eat up non-rendered pixels
2889 */
2890 while (i < n && !mask[i])
2891 i++;
2892 }
2893 }
2894
2895
2896
2897 /*
2898 * Write a span of PF_TRUEDITHER pixels to a pixmap.
2899 */
2900 static void put_mono_row_TRUEDITHER_pixmap( PUT_MONO_ROW_ARGS )
2901 {
2902 const GLubyte *color = (const GLubyte *) value;
2903 GET_XRB(xrb);
2904 XMesaContext xmesa = XMESA_CONTEXT(ctx);
2905 XMesaDisplay *dpy = xmesa->xm_visual->display;
2906 XMesaDrawable buffer = xrb->drawable;
2907 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
2908 const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
2909 register GLuint i;
2910 int yy = YFLIP(xrb, y);
2911 for (i=0;i<n;i++,x++) {
2912 if (!mask || mask[i]) {
2913 unsigned long p;
2914 PACK_TRUEDITHER(p, x, yy, r, g, b);
2915 XMesaSetForeground( dpy, gc, p );
2916 XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) yy );
2917 }
2918 }
2919 }
2920
2921
2922 /*
2923 * Write a span of PF_DITHER pixels to a pixmap.
2924 */
2925 static void put_mono_row_DITHER_pixmap( PUT_MONO_ROW_ARGS )
2926 {
2927 const GLubyte *color = (const GLubyte *) value;
2928 GET_XRB(xrb);
2929 XMesaContext xmesa = XMESA_CONTEXT(ctx);
2930 XMesaDisplay *dpy = xmesa->xm_visual->display;
2931 XMesaDrawable buffer = xrb->drawable;
2932 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
2933 const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
2934 register GLuint i;
2935 int yy = YFLIP(xrb, y);
2936 XDITHER_SETUP(yy);
2937 for (i=0;i<n;i++,x++) {
2938 if (!mask || mask[i]) {
2939 XMesaSetForeground( dpy, gc, XDITHER( x, r, g, b ) );
2940 XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) yy );
2941 }
2942 }
2943 }
2944
2945
2946 /*
2947 * Write a span of PF_1BIT pixels to a pixmap.
2948 */
2949 static void put_mono_row_1BIT_pixmap( PUT_MONO_ROW_ARGS )
2950 {
2951 const GLubyte *color = (const GLubyte *) value;
2952 GET_XRB(xrb);
2953 XMesaContext xmesa = XMESA_CONTEXT(ctx);
2954 XMesaDisplay *dpy = xmesa->xm_visual->display;
2955 XMesaDrawable buffer = xrb->drawable;
2956 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
2957 const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
2958 register GLuint i;
2959 SETUP_1BIT;
2960 y = YFLIP(xrb, y);
2961 for (i=0;i<n;i++,x++) {
2962 if (!mask || mask[i]) {
2963 XMesaSetForeground( dpy, gc, DITHER_1BIT( x, y, r, g, b ) );
2964 XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
2965 }
2966 }
2967 }
2968
2969
2970 /*
2971 * Write a span of identical pixels to an XImage.
2972 */
2973 static void put_mono_row_ximage( PUT_MONO_ROW_ARGS )
2974 {
2975 const GLubyte *color = (const GLubyte *) value;
2976 GET_XRB(xrb);
2977 XMesaContext xmesa = XMESA_CONTEXT(ctx);
2978 XMesaImage *img = xrb->ximage;
2979 register GLuint i;
2980 const unsigned long pixel = xmesa_color_to_pixel(ctx, color[RCOMP],
2981 color[GCOMP], color[BCOMP], color[ACOMP], xmesa->pixelformat);
2982 y = YFLIP(xrb, y);
2983 for (i=0;i<n;i++,x++) {
2984 if (!mask || mask[i]) {
2985 XMesaPutPixel( img, x, y, pixel );
2986 }
2987 }
2988 }
2989
2990
2991 static void
2992 put_mono_row_ci_ximage( PUT_MONO_ROW_ARGS )
2993 {
2994 const GLuint colorIndex = *((GLuint *) value);
2995 GET_XRB(xrb);
2996 XMesaImage *img = xrb->ximage;
2997 register GLuint i;
2998 y = YFLIP(xrb, y);
2999 for (i=0;i<n;i++,x++) {
3000 if (!mask || mask[i]) {
3001 XMesaPutPixel( img, x, y, colorIndex );
3002 }
3003 }
3004 }
3005
3006
3007 /*
3008 * Write a span of identical PF_TRUEDITHER pixels to an XImage.
3009 */
3010 static void put_mono_row_TRUEDITHER_ximage( PUT_MONO_ROW_ARGS )
3011 {
3012 const GLubyte *color = (const GLubyte *) value;
3013 GET_XRB(xrb);
3014 XMesaContext xmesa = XMESA_CONTEXT(ctx);
3015 XMesaImage *img = xrb->ximage;
3016 const GLint r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
3017 GLuint i;
3018 y = YFLIP(xrb, y);
3019 for (i=0;i<n;i++) {
3020 if (!mask || mask[i]) {
3021 unsigned long p;
3022 PACK_TRUEDITHER( p, x+i, y, r, g, b);
3023 XMesaPutPixel( img, x+i, y, p );
3024 }
3025 }
3026 }
3027
3028
3029 /*
3030 * Write a span of identical 8A8B8G8R pixels to an XImage.
3031 */
3032 static void put_mono_row_8A8B8G8R_ximage( PUT_MONO_ROW_ARGS )
3033 {
3034 const GLubyte *color = (const GLubyte *) value;
3035 GET_XRB(xrb);
3036 XMesaContext xmesa = XMESA_CONTEXT(ctx);
3037 GLuint i, *ptr;
3038 const unsigned long pixel = xmesa_color_to_pixel(ctx, color[RCOMP],
3039 color[GCOMP], color[BCOMP], color[ACOMP], xmesa->pixelformat);
3040 ptr = PIXEL_ADDR4(xrb, x, y );
3041 for (i=0;i<n;i++) {
3042 if (!mask || mask[i]) {
3043 ptr[i] = pixel;
3044 }
3045 }
3046 }
3047
3048 /*
3049 * Write a span of identical 8A8R8G8B pixels to an XImage.
3050 */
3051 static void put_mono_row_8A8R8G8B_ximage( PUT_MONO_ROW_ARGS )
3052 {
3053 const GLubyte *color = (const GLubyte *) value;
3054 GET_XRB(xrb);
3055 GLuint i, *ptr;
3056 XMesaContext xmesa = XMESA_CONTEXT(ctx);
3057 const unsigned long pixel = xmesa_color_to_pixel(ctx, color[RCOMP],
3058 color[GCOMP], color[BCOMP], color[ACOMP], xmesa->pixelformat);
3059 ptr = PIXEL_ADDR4(xrb, x, y );
3060 for (i=0;i<n;i++) {
3061 if (!mask || mask[i]) {
3062 ptr[i] = pixel;
3063 }
3064 }
3065 }
3066
3067
3068 /*
3069 * Write a span of identical 8R8G8B pixels to an XImage.
3070 */
3071 static void put_mono_row_8R8G8B_ximage( PUT_MONO_ROW_ARGS )
3072 {
3073 const GLubyte *color = (const GLubyte *) value;
3074 GET_XRB(xrb);
3075 const GLuint pixel = PACK_8R8G8B(color[RCOMP], color[GCOMP], color[BCOMP]);
3076 GLuint *ptr = PIXEL_ADDR4(xrb, x, y );
3077 GLuint i;
3078 for (i=0;i<n;i++) {
3079 if (!mask || mask[i]) {
3080 ptr[i] = pixel;
3081 }
3082 }
3083 }
3084
3085
3086 /*
3087 * Write a span of identical 8R8G8B pixels to an XImage.
3088 */
3089 static void put_mono_row_8R8G8B24_ximage( PUT_MONO_ROW_ARGS )
3090 {
3091 const GLubyte *color = (const GLubyte *) value;
3092 GET_XRB(xrb);
3093 const GLubyte r = color[RCOMP];
3094 const GLubyte g = color[GCOMP];
3095 const GLubyte b = color[BCOMP];
3096 GLuint i;
3097 bgr_t *ptr = PIXEL_ADDR3(xrb, x, y );
3098 for (i=0;i<n;i++) {
3099 if (!mask || mask[i]) {
3100 ptr[i].r = r;
3101 ptr[i].g = g;
3102 ptr[i].b = b;
3103 }
3104 }
3105 }
3106
3107
3108 /*
3109 * Write a span of identical DITHER pixels to an XImage.
3110 */
3111 static void put_mono_row_DITHER_ximage( PUT_MONO_ROW_ARGS )
3112 {
3113 const GLubyte *color = (const GLubyte *) value;
3114 GET_XRB(xrb);
3115 const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
3116 XMesaImage *img = xrb->ximage;
3117 int yy = YFLIP(xrb, y);
3118 register GLuint i;
3119 XDITHER_SETUP(yy);
3120 for (i=0;i<n;i++,x++) {
3121 if (!mask || mask[i]) {
3122 XMesaPutPixel( img, x, yy, XDITHER( x, r, g, b ) );
3123 }
3124 }
3125 }
3126
3127
3128 /*
3129 * Write a span of identical 8-bit DITHER pixels to an XImage.
3130 */
3131 static void put_mono_row_DITHER8_ximage( PUT_MONO_ROW_ARGS )
3132 {
3133 const GLubyte *color = (const GLubyte *) value;
3134 GET_XRB(xrb);
3135 const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
3136 register GLubyte *ptr = PIXEL_ADDR1(xrb, x, y);
3137 register GLuint i;
3138 XDITHER_SETUP(y);
3139 for (i=0;i<n;i++,x++) {
3140 if (!mask || mask[i]) {
3141 ptr[i] = (GLubyte) XDITHER( x, r, g, b );
3142 }
3143 }
3144 }
3145
3146
3147 /*
3148 * Write a span of identical 8-bit LOOKUP pixels to an XImage.
3149 */
3150 static void put_mono_row_LOOKUP8_ximage( PUT_MONO_ROW_ARGS )
3151 {
3152 const GLubyte *color = (const GLubyte *) value;
3153 GET_XRB(xrb);
3154 register GLuint i;
3155 register GLubyte *ptr = PIXEL_ADDR1(xrb, x, y);
3156 GLubyte pixel;
3157 LOOKUP_SETUP;
3158 pixel = LOOKUP(color[RCOMP], color[GCOMP], color[BCOMP]);
3159 for (i=0;i<n;i++) {
3160 if (!mask || mask[i]) {
3161 ptr[i] = pixel;
3162 }
3163 }
3164 }
3165
3166
3167 /*
3168 * Write a span of identical PF_1BIT pixels to an XImage.
3169 */
3170 static void put_mono_row_1BIT_ximage( PUT_MONO_ROW_ARGS )
3171 {
3172 const GLubyte *color = (const GLubyte *) value;
3173 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
3174 GET_XRB(xrb);
3175 const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
3176 XMesaImage *img = xrb->ximage;
3177 register GLuint i;
3178 SETUP_1BIT;
3179 y = YFLIP(xrb, y);
3180 for (i=0;i<n;i++,x++) {
3181 if (!mask || mask[i]) {
3182 XMesaPutPixel( img, x, y, DITHER_1BIT( x, y, r, g, b ) );
3183 }
3184 }
3185 }
3186
3187
3188 /*
3189 * Write a span of identical HPCR pixels to an XImage.
3190 */
3191 static void put_mono_row_HPCR_ximage( PUT_MONO_ROW_ARGS )
3192 {
3193 const GLubyte *color = (const GLubyte *) value;
3194 GET_XRB(xrb);
3195 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
3196 const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
3197 register GLubyte *ptr = PIXEL_ADDR1(xrb, x, y);
3198 register GLuint i;
3199 for (i=0;i<n;i++,x++) {
3200 if (!mask || mask[i]) {
3201 ptr[i] = DITHER_HPCR( x, y, r, g, b );
3202 }
3203 }
3204 }
3205
3206
3207 /*
3208 * Write a span of identical 8-bit GRAYSCALE pixels to an XImage.
3209 */
3210 static void put_mono_row_GRAYSCALE8_ximage( PUT_MONO_ROW_ARGS )
3211 {
3212 const GLubyte *color = (const GLubyte *) value;
3213 GET_XRB(xrb);
3214 const GLubyte p = GRAY_RGB(color[RCOMP], color[GCOMP], color[BCOMP]);
3215 GLubyte *ptr = (GLubyte *) PIXEL_ADDR1(xrb, x, y);
3216 GLuint i;
3217 for (i=0;i<n;i++) {
3218 if (!mask || mask[i]) {
3219 ptr[i] = p;
3220 }
3221 }
3222 }
3223
3224
3225
3226 /*
3227 * Write a span of identical PF_DITHER_5R6G5B pixels to an XImage.
3228 */
3229 static void put_mono_row_DITHER_5R6G5B_ximage( PUT_MONO_ROW_ARGS )
3230 {
3231 const GLubyte *color = (const GLubyte *) value;
3232 GET_XRB(xrb);
3233 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
3234 register GLushort *ptr = PIXEL_ADDR2(xrb, x, y );
3235 const GLint r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
3236 GLuint i;
3237 y = YFLIP(xrb, y);
3238 for (i=0;i<n;i++) {
3239 if (!mask || mask[i]) {
3240 PACK_TRUEDITHER(ptr[i], x+i, y, r, g, b);
3241 }
3242 }
3243 }
3244
3245
3246
3247 /**********************************************************************/
3248 /*** Write MONO COLOR PIXELS functions ***/
3249 /**********************************************************************/
3250
3251 #define PUT_MONO_VALUES_ARGS \
3252 GLcontext *ctx, struct gl_renderbuffer *rb, \
3253 GLuint n, const GLint x[], const GLint y[], \
3254 const void *value, const GLubyte mask[]
3255
3256
3257
3258 /*
3259 * Write an array of identical pixels to a pixmap.
3260 */
3261 static void put_mono_values_pixmap( PUT_MONO_VALUES_ARGS )
3262 {
3263 const GLubyte *color = (const GLubyte *) value;
3264 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
3265 GET_XRB(xrb);
3266 XMesaDisplay *dpy = xmesa->xm_visual->display;
3267 XMesaDrawable buffer = xrb->drawable;
3268 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
3269 register GLuint i;
3270 const unsigned long pixel = xmesa_color_to_pixel(ctx, color[RCOMP],
3271 color[GCOMP], color[BCOMP], color[ACOMP], xmesa->pixelformat);
3272 XMesaSetForeground( xmesa->display, gc, pixel );
3273 for (i=0;i<n;i++) {
3274 if (mask[i]) {
3275 XMesaDrawPoint( dpy, buffer, gc,
3276 (int) x[i], (int) YFLIP(xrb, y[i]) );
3277 }
3278 }
3279 }
3280
3281
3282 static void
3283 put_mono_values_ci_pixmap( PUT_MONO_VALUES_ARGS )
3284 {
3285 const GLuint colorIndex = *((GLuint *) value);
3286 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
3287 GET_XRB(xrb);
3288 XMesaDisplay *dpy = xmesa->xm_visual->display;
3289 XMesaDrawable buffer = xrb->drawable;
3290 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
3291 register GLuint i;
3292 XMesaSetForeground( xmesa->display, gc, colorIndex );
3293 for (i=0;i<n;i++) {
3294 if (mask[i]) {
3295 XMesaDrawPoint( dpy, buffer, gc,
3296 (int) x[i], (int) YFLIP(xrb, y[i]) );
3297 }
3298 }
3299 }
3300
3301
3302 /*
3303 * Write an array of PF_TRUEDITHER pixels to a pixmap.
3304 */
3305 static void put_mono_values_TRUEDITHER_pixmap( PUT_MONO_VALUES_ARGS )
3306 {
3307 const GLubyte *color = (const GLubyte *) value;
3308 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
3309 GET_XRB(xrb);
3310 XMesaDisplay *dpy = xmesa->xm_visual->display;
3311 XMesaDrawable buffer = xrb->drawable;
3312 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
3313 register GLuint i;
3314 const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
3315 for (i=0;i<n;i++) {
3316 if (mask[i]) {
3317 unsigned long p;
3318 PACK_TRUEDITHER(p, x[i], y[i], r, g, b);
3319 XMesaSetForeground( dpy, gc, p );
3320 XMesaDrawPoint( dpy, buffer, gc,
3321 (int) x[i], (int) YFLIP(xrb, y[i]) );
3322 }
3323 }
3324 }
3325
3326
3327 /*
3328 * Write an array of PF_DITHER pixels to a pixmap.
3329 */
3330 static void put_mono_values_DITHER_pixmap( PUT_MONO_VALUES_ARGS )
3331 {
3332 const GLubyte *color = (const GLubyte *) value;
3333 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
3334 GET_XRB(xrb);
3335 XMesaDisplay *dpy = xmesa->xm_visual->display;
3336 XMesaDrawable buffer = xrb->drawable;
3337 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
3338 register GLuint i;
3339 const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
3340 DITHER_SETUP;
3341 for (i=0;i<n;i++) {
3342 if (mask[i]) {
3343 XMesaSetForeground( dpy, gc, DITHER( x[i], y[i], r, g, b ) );
3344 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) YFLIP(xrb, y[i]) );
3345 }
3346 }
3347 }
3348
3349
3350 /*
3351 * Write an array of PF_1BIT pixels to a pixmap.
3352 */
3353 static void put_mono_values_1BIT_pixmap( PUT_MONO_VALUES_ARGS )
3354 {
3355 const GLubyte *color = (const GLubyte *) value;
3356 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
3357 GET_XRB(xrb);
3358 XMesaDisplay *dpy = xmesa->xm_visual->display;
3359 XMesaDrawable buffer = xrb->drawable;
3360 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
3361 register GLuint i;
3362 const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
3363 SETUP_1BIT;
3364 for (i=0;i<n;i++) {
3365 if (mask[i]) {
3366 XMesaSetForeground( dpy, gc, DITHER_1BIT( x[i], y[i], r, g, b ) );
3367 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) YFLIP(xrb, y[i]) );
3368 }
3369 }
3370 }
3371
3372
3373 /*
3374 * Write an array of identical pixels to an XImage.
3375 */
3376 static void put_mono_values_ximage( PUT_MONO_VALUES_ARGS )
3377 {
3378 const GLubyte *color = (const GLubyte *) value;
3379 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
3380 GET_XRB(xrb);
3381 XMesaImage *img = xrb->ximage;
3382 register GLuint i;
3383 const unsigned long pixel = xmesa_color_to_pixel(ctx, color[RCOMP],
3384 color[GCOMP], color[BCOMP], color[ACOMP], xmesa->pixelformat);
3385 for (i=0;i<n;i++) {
3386 if (mask[i]) {
3387 XMesaPutPixel( img, x[i], YFLIP(xrb, y[i]), pixel );
3388 }
3389 }
3390 }
3391
3392
3393 static void
3394 put_mono_values_ci_ximage( PUT_MONO_VALUES_ARGS )
3395 {
3396 const GLuint colorIndex = *((GLuint *) value);
3397 GET_XRB(xrb);
3398 XMesaImage *img = xrb->ximage;
3399 register GLuint i;
3400 for (i=0;i<n;i++) {
3401 if (mask[i]) {
3402 XMesaPutPixel( img, x[i], YFLIP(xrb, y[i]), colorIndex );
3403 }
3404 }
3405 }
3406
3407
3408 /*
3409 * Write an array of identical TRUEDITHER pixels to an XImage.
3410 */
3411 static void put_mono_values_TRUEDITHER_ximage( PUT_MONO_VALUES_ARGS )
3412 {
3413 const GLubyte *color = (const GLubyte *) value;
3414 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
3415 GET_XRB(xrb);
3416 XMesaImage *img = xrb->ximage;
3417 register GLuint i;
3418 const int r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
3419 for (i=0;i<n;i++) {
3420 if (mask[i]) {
3421 unsigned long p;
3422 PACK_TRUEDITHER(p, x[i], YFLIP(xrb, y[i]), r, g, b);
3423 XMesaPutPixel( img, x[i], YFLIP(xrb, y[i]), p );
3424 }
3425 }
3426 }
3427
3428
3429
3430 /*
3431 * Write an array of identical 8A8B8G8R pixels to an XImage
3432 */
3433 static void put_mono_values_8A8B8G8R_ximage( PUT_MONO_VALUES_ARGS )
3434 {
3435 const GLubyte *color = (const GLubyte *) value;
3436 GET_XRB(xrb);
3437 const GLuint p = PACK_8A8B8G8R(color[RCOMP], color[GCOMP],
3438 color[BCOMP], color[ACOMP]);
3439 register GLuint i;
3440 for (i=0;i<n;i++) {
3441 if (mask[i]) {
3442 GLuint *ptr = PIXEL_ADDR4(xrb, x[i], y[i] );
3443 *ptr = p;
3444 }
3445 }
3446 }
3447
3448 /*
3449 * Write an array of identical 8A8R8G8B pixels to an XImage
3450 */
3451 static void put_mono_values_8A8R8G8B_ximage( PUT_MONO_VALUES_ARGS )
3452 {
3453 const GLubyte *color = (const GLubyte *) value;
3454 GET_XRB(xrb);
3455 const GLuint p = PACK_8A8R8G8B(color[RCOMP], color[GCOMP],
3456 color[BCOMP], color[ACOMP]);
3457 register GLuint i;
3458 for (i=0;i<n;i++) {
3459 if (mask[i]) {
3460 GLuint *ptr = PIXEL_ADDR4(xrb, x[i], y[i] );
3461 *ptr = p;
3462 }
3463 }
3464 }
3465
3466 /*
3467 * Write an array of identical 8R8G8B pixels to an XImage.
3468 */
3469 static void put_mono_values_8R8G8B_ximage( PUT_MONO_VALUES_ARGS )
3470 {
3471 const GLubyte *color = (const GLubyte *) value;
3472 GET_XRB(xrb);
3473 register GLuint i;
3474 const GLuint p = PACK_8R8G8B(color[RCOMP], color[GCOMP], color[BCOMP]);
3475 for (i=0;i<n;i++) {
3476 if (mask[i]) {
3477 GLuint *ptr = PIXEL_ADDR4(xrb, x[i], y[i] );
3478 *ptr = p;
3479 }
3480 }
3481 }
3482
3483
3484 /*
3485 * Write an array of identical 8R8G8B pixels to an XImage.
3486 */
3487 static void put_mono_values_8R8G8B24_ximage( PUT_MONO_VALUES_ARGS )
3488 {
3489 const GLubyte *color = (const GLubyte *) value;
3490 GET_XRB(xrb);
3491 const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
3492 register GLuint i;
3493 for (i=0;i<n;i++) {
3494 if (mask[i]) {
3495 bgr_t *ptr = PIXEL_ADDR3(xrb, x[i], y[i] );
3496 ptr->r = r;
3497 ptr->g = g;
3498 ptr->b = b;
3499 }
3500 }
3501 }
3502
3503
3504 /*
3505 * Write an array of identical PF_DITHER pixels to an XImage.
3506 */
3507 static void put_mono_values_DITHER_ximage( PUT_MONO_VALUES_ARGS )
3508 {
3509 const GLubyte *color = (const GLubyte *) value;
3510 GET_XRB(xrb);
3511 const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
3512 XMesaImage *img = xrb->ximage;
3513 register GLuint i;
3514 DITHER_SETUP;
3515 for (i=0;i<n;i++) {
3516 if (mask[i]) {
3517 XMesaPutPixel( img, x[i], YFLIP(xrb, y[i]), DITHER( x[i], y[i], r, g, b ) );
3518 }
3519 }
3520 }
3521
3522
3523 /*
3524 * Write an array of identical 8-bit PF_DITHER pixels to an XImage.
3525 */
3526 static void put_mono_values_DITHER8_ximage( PUT_MONO_VALUES_ARGS )
3527 {
3528 const GLubyte *color = (const GLubyte *) value;
3529 GET_XRB(xrb);
3530 const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
3531 register GLuint i;
3532 DITHER_SETUP;
3533 for (i=0;i<n;i++) {
3534 if (mask[i]) {
3535 GLubyte *ptr = PIXEL_ADDR1(xrb, x[i], y[i]);
3536 *ptr = (GLubyte) DITHER( x[i], y[i], r, g, b );
3537 }
3538 }
3539 }
3540
3541
3542 /*
3543 * Write an array of identical 8-bit PF_LOOKUP pixels to an XImage.
3544 */
3545 static void put_mono_values_LOOKUP8_ximage( PUT_MONO_VALUES_ARGS )
3546 {
3547 const GLubyte *color = (const GLubyte *) value;
3548 GET_XRB(xrb);
3549 register GLuint i;
3550 GLubyte pixel;
3551 LOOKUP_SETUP;
3552 pixel = LOOKUP(color[RCOMP], color[GCOMP], color[BCOMP]);
3553 for (i=0;i<n;i++) {
3554 if (mask[i]) {
3555 GLubyte *ptr = PIXEL_ADDR1(xrb, x[i], y[i]);
3556 *ptr = pixel;
3557 }
3558 }
3559 }
3560
3561
3562
3563 /*
3564 * Write an array of identical PF_1BIT pixels to an XImage.
3565 */
3566 static void put_mono_values_1BIT_ximage( PUT_MONO_VALUES_ARGS )
3567 {
3568 const GLubyte *color = (const GLubyte *) value;
3569 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
3570 GET_XRB(xrb);
3571 const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
3572 XMesaImage *img = xrb->ximage;
3573 register GLuint i;
3574 SETUP_1BIT;
3575 for (i=0;i<n;i++) {
3576 if (mask[i]) {
3577 XMesaPutPixel( img, x[i], YFLIP(xrb, y[i]),
3578 DITHER_1BIT( x[i], y[i], r, g, b ));
3579 }
3580 }
3581 }
3582
3583
3584 /*
3585 * Write an array of identical PF_HPCR pixels to an XImage.
3586 */
3587 static void put_mono_values_HPCR_ximage( PUT_MONO_VALUES_ARGS )
3588 {
3589 const GLubyte *color = (const GLubyte *) value;
3590 GET_XRB(xrb);
3591 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
3592 const GLubyte r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
3593 register GLuint i;
3594 for (i=0;i<n;i++) {
3595 if (mask[i]) {
3596 GLubyte *ptr = PIXEL_ADDR1(xrb, x[i], y[i]);
3597 *ptr = DITHER_HPCR( x[i], y[i], r, g, b );
3598 }
3599 }
3600 }
3601
3602
3603 /*
3604 * Write an array of identical 8-bit PF_GRAYSCALE pixels to an XImage.
3605 */
3606 static void put_mono_values_GRAYSCALE8_ximage( PUT_MONO_VALUES_ARGS )
3607 {
3608 const GLubyte *color = (const GLubyte *) value;
3609 GET_XRB(xrb);
3610 register GLuint i;
3611 register GLubyte p = GRAY_RGB(color[RCOMP], color[GCOMP], color[BCOMP]);
3612 for (i=0;i<n;i++) {
3613 if (mask[i]) {
3614 GLubyte *ptr = PIXEL_ADDR1(xrb, x[i], y[i]);
3615 *ptr = p;
3616 }
3617 }
3618 }
3619
3620
3621 /*
3622 * Write an array of identical PF_DITHER_5R6G5B pixels to an XImage.
3623 */
3624 static void put_mono_values_DITHER_5R6G5B_ximage( PUT_MONO_VALUES_ARGS )
3625 {
3626 const GLubyte *color = (const GLubyte *) value;
3627 GET_XRB(xrb);
3628 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
3629 const int r = color[RCOMP], g = color[GCOMP], b = color[BCOMP];
3630 register GLuint i;
3631 for (i=0;i<n;i++) {
3632 if (mask[i]) {
3633 GLushort *ptr = PIXEL_ADDR2(xrb, x[i], y[i] );
3634 PACK_TRUEDITHER(*ptr, x[i], y[i], r, g, b);
3635 }
3636 }
3637 }
3638
3639
3640
3641 /**********************************************************************/
3642 /*** Write INDEX SPAN functions ***/
3643 /**********************************************************************/
3644
3645 /*
3646 * Write a span of CI pixels to a Pixmap.
3647 */
3648 static void put_row_ci_pixmap( PUT_ROW_ARGS )
3649 {
3650 const GLuint *index = (GLuint *) values;
3651 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
3652 GET_XRB(xrb);
3653 XMesaDisplay *dpy = xmesa->xm_visual->display;
3654 XMesaDrawable buffer = xrb->drawable;
3655 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
3656 register GLuint i;
3657 y = YFLIP(xrb, y);
3658 if (mask) {
3659 for (i=0;i<n;i++,x++) {
3660 if (mask[i]) {
3661 XMesaSetForeground( dpy, gc, (unsigned long) index[i] );
3662 XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
3663 }
3664 }
3665 }
3666 else {
3667 for (i=0;i<n;i++,x++) {
3668 XMesaSetForeground( dpy, gc, (unsigned long) index[i] );
3669 XMesaDrawPoint( dpy, buffer, gc, (int) x, (int) y );
3670 }
3671 }
3672 }
3673
3674
3675 /*
3676 * Write a span of CI pixels to an XImage.
3677 */
3678 static void put_row_ci_ximage( PUT_ROW_ARGS )
3679 {
3680 const GLuint *index = (const GLuint *) values;
3681 GET_XRB(xrb);
3682 XMesaImage *img = xrb->ximage;
3683 register GLuint i;
3684 y = YFLIP(xrb, y);
3685 if (mask) {
3686 for (i=0;i<n;i++,x++) {
3687 if (mask[i]) {
3688 XMesaPutPixel( img, x, y, (unsigned long) index[i] );
3689 }
3690 }
3691 }
3692 else {
3693 for (i=0;i<n;i++,x++) {
3694 XMesaPutPixel( img, x, y, (unsigned long) index[i] );
3695 }
3696 }
3697 }
3698
3699
3700 /**********************************************************************/
3701 /*** Write INDEX PIXELS functions ***/
3702 /**********************************************************************/
3703
3704 /*
3705 * Write an array of CI pixels to a Pixmap.
3706 */
3707 static void put_values_ci_pixmap( PUT_VALUES_ARGS )
3708 {
3709 const GLuint *index = (const GLuint *) values;
3710 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
3711 GET_XRB(xrb);
3712 XMesaDisplay *dpy = xmesa->xm_visual->display;
3713 XMesaDrawable buffer = xrb->drawable;
3714 XMesaGC gc = XMESA_BUFFER(ctx->DrawBuffer)->gc;
3715 register GLuint i;
3716 for (i=0;i<n;i++) {
3717 if (mask[i]) {
3718 XMesaSetForeground( dpy, gc, (unsigned long) index[i] );
3719 XMesaDrawPoint( dpy, buffer, gc, (int) x[i], (int) YFLIP(xrb, y[i]) );
3720 }
3721 }
3722 }
3723
3724
3725 /*
3726 * Write an array of CI pixels to an XImage.
3727 */
3728 static void put_values_ci_ximage( PUT_VALUES_ARGS )
3729 {
3730 const GLuint *index = (const GLuint *) values;
3731 GET_XRB(xrb);
3732 XMesaImage *img = xrb->ximage;
3733 register GLuint i;
3734 for (i=0;i<n;i++) {
3735 if (mask[i]) {
3736 XMesaPutPixel(img, x[i], YFLIP(xrb, y[i]), (unsigned long) index[i]);
3737 }
3738 }
3739 }
3740
3741
3742
3743
3744 /**********************************************************************/
3745 /***** Pixel reading *****/
3746 /**********************************************************************/
3747
3748 #ifndef XFree86Server
3749 /**
3750 * Do clip testing prior to calling XGetImage. If any of the region lies
3751 * outside the screen's bounds, XGetImage will return NULL.
3752 * We use XTranslateCoordinates() to check if that's the case and
3753 * adjust the x, y and length parameters accordingly.
3754 * \return -1 if span is totally clipped away,
3755 * else return number of pixels to skip in the destination array.
3756 */
3757 static int
3758 clip_for_xgetimage(GLcontext *ctx, GLuint *n, GLint *x, GLint *y)
3759 {
3760 XMesaContext xmesa = XMESA_CONTEXT(ctx);
3761 XMesaBuffer source = XMESA_BUFFER(ctx->DrawBuffer);
3762 Window rootWin = RootWindow(xmesa->display, 0);
3763 Window child;
3764 GLint screenWidth = WidthOfScreen(DefaultScreenOfDisplay(xmesa->display));
3765 GLint dx, dy;
3766 if (source->type == PBUFFER || source->type == PIXMAP)
3767 return 0;
3768 XTranslateCoordinates(xmesa->display, source->frontxrb->pixmap, rootWin,
3769 *x, *y, &dx, &dy, &child);
3770 if (dx >= screenWidth) {
3771 /* totally clipped on right */
3772 return -1;
3773 }
3774 if (dx < 0) {
3775 /* clipped on left */
3776 GLint clip = -dx;
3777 if (clip >= (GLint) *n)
3778 return -1; /* totally clipped on left */
3779 *x += clip;
3780 *n -= clip;
3781 dx = 0;
3782 return clip;
3783 }
3784 if ((GLint) (dx + *n) > screenWidth) {
3785 /* clipped on right */
3786 GLint clip = dx + *n - screenWidth;
3787 *n -= clip;
3788 }
3789 return 0;
3790 }
3791 #endif
3792
3793
3794 /*
3795 * Read a horizontal span of color-index pixels.
3796 */
3797 static void
3798 get_row_ci(GLcontext *ctx, struct gl_renderbuffer *rb,
3799 GLuint n, GLint x, GLint y, void *values)
3800 {
3801 GLuint *index = (GLuint *) values;
3802 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
3803 GET_XRB(xrb);
3804 GLuint i;
3805
3806 y = YFLIP(xrb, y);
3807
3808 if (xrb->pixmap) {
3809 #ifndef XFree86Server
3810 XMesaImage *span = NULL;
3811 int error;
3812 int k = clip_for_xgetimage(ctx, &n, &x, &y);
3813 if (k < 0)
3814 return;
3815 index += k;
3816
3817 catch_xgetimage_errors( xmesa->display );
3818 span = XGetImage( xmesa->display, xrb->pixmap,
3819 x, y, n, 1, AllPlanes, ZPixmap );
3820 error = check_xgetimage_errors();
3821 if (span && !error) {
3822 for (i=0;i<n;i++) {
3823 index[i] = (GLuint) XMesaGetPixel( span, i, 0 );
3824 }
3825 }
3826 else {
3827 /* return 0 pixels */
3828 for (i=0;i<n;i++) {
3829 index[i] = 0;
3830 }
3831 }
3832 if (span) {
3833 XMesaDestroyImage( span );
3834 }
3835 #else
3836 (*xmesa->display->GetImage)(xrb->drawable,
3837 x, y, n, 1, ZPixmap,
3838 ~0L, (pointer)index);
3839 #endif
3840 }
3841 else if (xrb->ximage) {
3842 XMesaImage *img = xrb->ximage;
3843 for (i=0;i<n;i++,x++) {
3844 index[i] = (GLuint) XMesaGetPixel( img, x, y );
3845 }
3846 }
3847 }
3848
3849
3850
3851 /*
3852 * Read a horizontal span of color pixels.
3853 */
3854 static void
3855 get_row_rgba(GLcontext *ctx, struct gl_renderbuffer *rb,
3856 GLuint n, GLint x, GLint y, void *values)
3857 {
3858 GLubyte (*rgba)[4] = (GLubyte (*)[4]) values;
3859 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
3860 GET_XRB(xrb);
3861 XMesaBuffer source = XMESA_BUFFER(ctx->DrawBuffer);
3862
3863 if (xrb->pixmap) {
3864 /* Read from Pixmap or Window */
3865 XMesaImage *span = NULL;
3866 int error;
3867 #ifdef XFree86Server
3868 span = XMesaCreateImage(xmesa->xm_visual->BitsPerPixel, n, 1, NULL);
3869 span->data = (char *)MALLOC(span->height * span->bytes_per_line);
3870 error = (!span->data);
3871 (*xmesa->display->GetImage)(xrb->drawable,
3872 x, YFLIP(xrb, y), n, 1, ZPixmap,
3873 ~0L, (pointer)span->data);
3874 #else
3875 int k;
3876 y = YFLIP(xrb, y);
3877 k = clip_for_xgetimage(ctx, &n, &x, &y);
3878 if (k < 0)
3879 return;
3880 rgba += k;
3881 catch_xgetimage_errors( xmesa->display );
3882 span = XGetImage( xmesa->display, xrb->pixmap,
3883 x, y, n, 1, AllPlanes, ZPixmap );
3884 error = check_xgetimage_errors();
3885 #endif
3886 if (span && !error) {
3887 switch (xmesa->pixelformat) {
3888 case PF_Truecolor:
3889 case PF_Dither_True:
3890 {
3891 const GLubyte *pixelToR = xmesa->xm_visual->PixelToR;
3892 const GLubyte *pixelToG = xmesa->xm_visual->PixelToG;
3893 const GLubyte *pixelToB = xmesa->xm_visual->PixelToB;
3894 unsigned long rMask = GET_REDMASK(xmesa->xm_visual);
3895 unsigned long gMask = GET_GREENMASK(xmesa->xm_visual);
3896 unsigned long bMask = GET_BLUEMASK(xmesa->xm_visual);
3897 GLint rShift = xmesa->xm_visual->rshift;
3898 GLint gShift = xmesa->xm_visual->gshift;
3899 GLint bShift = xmesa->xm_visual->bshift;
3900 GLuint i;
3901 for (i=0;i<n;i++) {
3902 unsigned long p;
3903 p = XMesaGetPixel( span, i, 0 );
3904 rgba[i][RCOMP] = pixelToR[(p & rMask) >> rShift];
3905 rgba[i][GCOMP] = pixelToG[(p & gMask) >> gShift];
3906 rgba[i][BCOMP] = pixelToB[(p & bMask) >> bShift];
3907 rgba[i][ACOMP] = 255;
3908 }
3909 }
3910 break;
3911 case PF_5R6G5B:
3912 case PF_Dither_5R6G5B:
3913 {
3914 const GLubyte *pixelToR = xmesa->xm_visual->PixelToR;
3915 const GLubyte *pixelToG = xmesa->xm_visual->PixelToG;
3916 const GLubyte *pixelToB = xmesa->xm_visual->PixelToB;
3917 GLuint i;
3918 for (i=0;i<n;i++) {
3919 unsigned long p = XMesaGetPixel( span, i, 0 );
3920 /* fast, but not quite accurate
3921 rgba[i][RCOMP] = ((p >> 8) & 0xf8);
3922 rgba[i][GCOMP] = ((p >> 3) & 0xfc);
3923 rgba[i][BCOMP] = ((p << 3) & 0xff);
3924 */
3925 rgba[i][RCOMP] = pixelToR[p >> 11];
3926 rgba[i][GCOMP] = pixelToG[(p >> 5) & 0x3f];
3927 rgba[i][BCOMP] = pixelToB[p & 0x1f];
3928 rgba[i][ACOMP] = 255;
3929 }
3930 }
3931 break;
3932 case PF_8A8B8G8R:
3933 {
3934 const GLuint *ptr4 = (GLuint *) span->data;
3935 GLuint i;
3936 for (i=0;i<n;i++) {
3937 GLuint p4 = *ptr4++;
3938 rgba[i][RCOMP] = (GLubyte) ( p4 & 0xff);
3939 rgba[i][GCOMP] = (GLubyte) ((p4 >> 8) & 0xff);
3940 rgba[i][BCOMP] = (GLubyte) ((p4 >> 16) & 0xff);
3941 rgba[i][ACOMP] = (GLubyte) ((p4 >> 24) & 0xff);
3942 }
3943 }
3944 break;
3945 case PF_8A8R8G8B:
3946 {
3947 const GLuint *ptr4 = (GLuint *) span->data;
3948 GLuint i;
3949 for (i=0;i<n;i++) {
3950 GLuint p4 = *ptr4++;
3951 rgba[i][RCOMP] = (GLubyte) ((p4 >> 16) & 0xff);
3952 rgba[i][GCOMP] = (GLubyte) ((p4 >> 8) & 0xff);
3953 rgba[i][BCOMP] = (GLubyte) ( p4 & 0xff);
3954 rgba[i][ACOMP] = (GLubyte) ((p4 >> 24) & 0xff);
3955 }
3956 }
3957 break;
3958 case PF_8R8G8B:
3959 {
3960 const GLuint *ptr4 = (GLuint *) span->data;
3961 GLuint i;
3962 for (i=0;i<n;i++) {
3963 GLuint p4 = *ptr4++;
3964 rgba[i][RCOMP] = (GLubyte) ((p4 >> 16) & 0xff);
3965 rgba[i][GCOMP] = (GLubyte) ((p4 >> 8) & 0xff);
3966 rgba[i][BCOMP] = (GLubyte) ( p4 & 0xff);
3967 rgba[i][ACOMP] = 255;
3968 }
3969 }
3970 break;
3971 case PF_8R8G8B24:
3972 {
3973 const bgr_t *ptr3 = (bgr_t *) span->data;
3974 GLuint i;
3975 for (i=0;i<n;i++) {
3976 rgba[i][RCOMP] = ptr3[i].r;
3977 rgba[i][GCOMP] = ptr3[i].g;
3978 rgba[i][BCOMP] = ptr3[i].b;
3979 rgba[i][ACOMP] = 255;
3980 }
3981 }
3982 break;
3983 case PF_HPCR:
3984 {
3985 GLubyte *ptr1 = (GLubyte *) span->data;
3986 GLuint i;
3987 for (i=0;i<n;i++) {
3988 GLubyte p = *ptr1++;
3989 rgba[i][RCOMP] = p & 0xE0;
3990 rgba[i][GCOMP] = (p & 0x1C) << 3;
3991 rgba[i][BCOMP] = (p & 0x03) << 6;
3992 rgba[i][ACOMP] = 255;
3993 }
3994 }
3995 break;
3996 case PF_Dither:
3997 case PF_Lookup:
3998 case PF_Grayscale:
3999 {
4000 GLubyte *rTable = source->pixel_to_r;
4001 GLubyte *gTable = source->pixel_to_g;
4002 GLubyte *bTable = source->pixel_to_b;
4003 if (GET_VISUAL_DEPTH(xmesa->xm_visual)==8) {
4004 const GLubyte *ptr1 = (GLubyte *) span->data;
4005 GLuint i;
4006 for (i=0;i<n;i++) {
4007 unsigned long p = *ptr1++;
4008 rgba[i][RCOMP] = rTable[p];
4009 rgba[i][GCOMP] = gTable[p];
4010 rgba[i][BCOMP] = bTable[p];
4011 rgba[i][ACOMP] = 255;
4012 }
4013 }
4014 else {
4015 GLuint i;
4016 for (i=0;i<n;i++) {
4017 unsigned long p = XMesaGetPixel( span, i, 0 );
4018 rgba[i][RCOMP] = rTable[p];
4019 rgba[i][GCOMP] = gTable[p];
4020 rgba[i][BCOMP] = bTable[p];
4021 rgba[i][ACOMP] = 255;
4022 }
4023 }
4024 }
4025 break;
4026 case PF_1Bit:
4027 {
4028 int bitFlip = xmesa->xm_visual->bitFlip;
4029 GLuint i;
4030 for (i=0;i<n;i++) {
4031 unsigned long p;
4032 p = XMesaGetPixel( span, i, 0 ) ^ bitFlip;
4033 rgba[i][RCOMP] = (GLubyte) (p * 255);
4034 rgba[i][GCOMP] = (GLubyte) (p * 255);
4035 rgba[i][BCOMP] = (GLubyte) (p * 255);
4036 rgba[i][ACOMP] = 255;
4037 }
4038 }
4039 break;
4040 default:
4041 _mesa_problem(NULL,"Problem in DD.read_color_span (1)");
4042 return;
4043 }
4044 }
4045 else {
4046 /* return black pixels */
4047 GLuint i;
4048 for (i=0;i<n;i++) {
4049 rgba[i][RCOMP] = rgba[i][GCOMP] = rgba[i][BCOMP] = rgba[i][ACOMP] = 0;
4050 }
4051 }
4052 if (span) {
4053 XMesaDestroyImage( span );
4054 }
4055 }
4056 else if (xrb->ximage) {
4057 /* Read from XImage back buffer */
4058 switch (xmesa->pixelformat) {
4059 case PF_Truecolor:
4060 case PF_Dither_True:
4061 {
4062 const GLubyte *pixelToR = xmesa->xm_visual->PixelToR;
4063 const GLubyte *pixelToG = xmesa->xm_visual->PixelToG;
4064 const GLubyte *pixelToB = xmesa->xm_visual->PixelToB;
4065 unsigned long rMask = GET_REDMASK(xmesa->xm_visual);
4066 unsigned long gMask = GET_GREENMASK(xmesa->xm_visual);
4067 unsigned long bMask = GET_BLUEMASK(xmesa->xm_visual);
4068 GLint rShift = xmesa->xm_visual->rshift;
4069 GLint gShift = xmesa->xm_visual->gshift;
4070 GLint bShift = xmesa->xm_visual->bshift;
4071 XMesaImage *img = xrb->ximage;
4072 GLuint i;
4073 y = YFLIP(xrb, y);
4074 for (i=0;i<n;i++) {
4075 unsigned long p;
4076 p = XMesaGetPixel( img, x+i, y );
4077 rgba[i][RCOMP] = pixelToR[(p & rMask) >> rShift];
4078 rgba[i][GCOMP] = pixelToG[(p & gMask) >> gShift];
4079 rgba[i][BCOMP] = pixelToB[(p & bMask) >> bShift];
4080 rgba[i][ACOMP] = 255;
4081 }
4082 }
4083 break;
4084 case PF_5R6G5B:
4085 case PF_Dither_5R6G5B:
4086 {
4087 const GLubyte *pixelToR = xmesa->xm_visual->PixelToR;
4088 const GLubyte *pixelToG = xmesa->xm_visual->PixelToG;
4089 const GLubyte *pixelToB = xmesa->xm_visual->PixelToB;
4090 const GLushort *ptr2 = PIXEL_ADDR2(xrb, x, y);
4091 GLuint i;
4092 #if defined(__i386__) /* word stores don't have to be on 4-byte boundaries */
4093 const GLuint *ptr4 = (const GLuint *) ptr2;
4094 GLuint extraPixel = (n & 1);
4095 n -= extraPixel;
4096 for (i = 0; i < n; i += 2) {
4097 const GLuint p = *ptr4++;
4098 const GLuint p0 = p & 0xffff;
4099 const GLuint p1 = p >> 16;
4100 /* fast, but not quite accurate
4101 rgba[i][RCOMP] = ((p >> 8) & 0xf8);
4102 rgba[i][GCOMP] = ((p >> 3) & 0xfc);
4103 rgba[i][BCOMP] = ((p << 3) & 0xff);
4104 */
4105 rgba[i][RCOMP] = pixelToR[p0 >> 11];
4106 rgba[i][GCOMP] = pixelToG[(p0 >> 5) & 0x3f];
4107 rgba[i][BCOMP] = pixelToB[p0 & 0x1f];
4108 rgba[i][ACOMP] = 255;
4109 rgba[i+1][RCOMP] = pixelToR[p1 >> 11];
4110 rgba[i+1][GCOMP] = pixelToG[(p1 >> 5) & 0x3f];
4111 rgba[i+1][BCOMP] = pixelToB[p1 & 0x1f];
4112 rgba[i+1][ACOMP] = 255;
4113 }
4114 if (extraPixel) {
4115 GLushort p = ptr2[n];
4116 rgba[n][RCOMP] = pixelToR[p >> 11];
4117 rgba[n][GCOMP] = pixelToG[(p >> 5) & 0x3f];
4118 rgba[n][BCOMP] = pixelToB[p & 0x1f];
4119 rgba[n][ACOMP] = 255;
4120 }
4121 #else
4122 for (i = 0; i < n; i++) {
4123 const GLushort p = ptr2[i];
4124 rgba[i][RCOMP] = pixelToR[p >> 11];
4125 rgba[i][GCOMP] = pixelToG[(p >> 5) & 0x3f];
4126 rgba[i][BCOMP] = pixelToB[p & 0x1f];
4127 rgba[i][ACOMP] = 255;
4128 }
4129 #endif
4130 }
4131 break;
4132 case PF_8A8B8G8R:
4133 {
4134 const GLuint *ptr4 = PIXEL_ADDR4(xrb, x, y);
4135 GLuint i;
4136 for (i=0;i<n;i++) {
4137 GLuint p4 = *ptr4++;
4138 rgba[i][RCOMP] = (GLubyte) ( p4 & 0xff);
4139 rgba[i][GCOMP] = (GLubyte) ((p4 >> 8) & 0xff);
4140 rgba[i][BCOMP] = (GLubyte) ((p4 >> 16) & 0xff);
4141 rgba[i][ACOMP] = (GLint) ((p4 >> 24) & 0xff);
4142 }
4143 }
4144 break;
4145 case PF_8A8R8G8B:
4146 {
4147 const GLuint *ptr4 = PIXEL_ADDR4(xrb, x, y);
4148 GLuint i;
4149 for (i=0;i<n;i++) {
4150 GLuint p4 = *ptr4++;
4151 rgba[i][RCOMP] = (GLubyte) ((p4 >> 16) & 0xff);
4152 rgba[i][GCOMP] = (GLubyte) ((p4 >> 8) & 0xff);
4153 rgba[i][BCOMP] = (GLubyte) ( p4 & 0xff);
4154 rgba[i][ACOMP] = (GLint) ((p4 >> 24) & 0xff);
4155 }
4156 }
4157 break;
4158 case PF_8R8G8B:
4159 {
4160 const GLuint *ptr4 = PIXEL_ADDR4(xrb, x, y);
4161 GLuint i;
4162 for (i=0;i<n;i++) {
4163 GLuint p4 = *ptr4++;
4164 rgba[i][RCOMP] = (GLubyte) ((p4 >> 16) & 0xff);
4165 rgba[i][GCOMP] = (GLubyte) ((p4 >> 8) & 0xff);
4166 rgba[i][BCOMP] = (GLubyte) ( p4 & 0xff);
4167 rgba[i][ACOMP] = 255;
4168 }
4169 }
4170 break;
4171 case PF_8R8G8B24:
4172 {
4173 const bgr_t *ptr3 = PIXEL_ADDR3(xrb, x, y);
4174 GLuint i;
4175 for (i=0;i<n;i++) {
4176 rgba[i][RCOMP] = ptr3[i].r;
4177 rgba[i][GCOMP] = ptr3[i].g;
4178 rgba[i][BCOMP] = ptr3[i].b;
4179 rgba[i][ACOMP] = 255;
4180 }
4181 }
4182 break;
4183 case PF_HPCR:
4184 {
4185 const GLubyte *ptr1 = PIXEL_ADDR1(xrb, x, y);
4186 GLuint i;
4187 for (i=0;i<n;i++) {
4188 GLubyte p = *ptr1++;
4189 rgba[i][RCOMP] = p & 0xE0;
4190 rgba[i][GCOMP] = (p & 0x1C) << 3;
4191 rgba[i][BCOMP] = (p & 0x03) << 6;
4192 rgba[i][ACOMP] = 255;
4193 }
4194 }
4195 break;
4196 case PF_Dither:
4197 case PF_Lookup:
4198 case PF_Grayscale:
4199 {
4200 const GLubyte *rTable = source->pixel_to_r;
4201 const GLubyte *gTable = source->pixel_to_g;
4202 const GLubyte *bTable = source->pixel_to_b;
4203 if (GET_VISUAL_DEPTH(xmesa->xm_visual)==8) {
4204 GLubyte *ptr1 = PIXEL_ADDR1(xrb, x, y);
4205 GLuint i;
4206 for (i=0;i<n;i++) {
4207 unsigned long p = *ptr1++;
4208 rgba[i][RCOMP] = rTable[p];
4209 rgba[i][GCOMP] = gTable[p];
4210 rgba[i][BCOMP] = bTable[p];
4211 rgba[i][ACOMP] = 255;
4212 }
4213 }
4214 else {
4215 XMesaImage *img = xrb->ximage;
4216 GLuint i;
4217 y = YFLIP(xrb, y);
4218 for (i=0;i<n;i++,x++) {
4219 unsigned long p = XMesaGetPixel( img, x, y );
4220 rgba[i][RCOMP] = rTable[p];
4221 rgba[i][GCOMP] = gTable[p];
4222 rgba[i][BCOMP] = bTable[p];
4223 rgba[i][ACOMP] = 255;
4224 }
4225 }
4226 }
4227 break;
4228 case PF_1Bit:
4229 {
4230 XMesaImage *img = xrb->ximage;
4231 int bitFlip = xmesa->xm_visual->bitFlip;
4232 GLuint i;
4233 y = YFLIP(xrb, y);
4234 for (i=0;i<n;i++,x++) {
4235 unsigned long p;
4236 p = XMesaGetPixel( img, x, y ) ^ bitFlip;
4237 rgba[i][RCOMP] = (GLubyte) (p * 255);
4238 rgba[i][GCOMP] = (GLubyte) (p * 255);
4239 rgba[i][BCOMP] = (GLubyte) (p * 255);
4240 rgba[i][ACOMP] = 255;
4241 }
4242 }
4243 break;
4244 default:
4245 _mesa_problem(NULL,"Problem in DD.read_color_span (2)");
4246 return;
4247 }
4248 }
4249 }
4250
4251
4252
4253 /*
4254 * Read an array of color index pixels.
4255 */
4256 static void
4257 get_values_ci(GLcontext *ctx, struct gl_renderbuffer *rb,
4258 GLuint n, const GLint x[], const GLint y[], void *values)
4259 {
4260 GLuint *indx = (GLuint *) values;
4261 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
4262 GET_XRB(xrb);
4263 GLuint i;
4264 if (xrb->pixmap) {
4265 for (i=0;i<n;i++) {
4266 indx[i] = (GLuint) read_pixel( xmesa->display, xrb->drawable,
4267 x[i], YFLIP(xrb, y[i]) );
4268 }
4269 }
4270 else if (xrb->ximage) {
4271 XMesaImage *img = xrb->ximage;
4272 for (i=0;i<n;i++) {
4273 indx[i] = (GLuint) XMesaGetPixel( img, x[i], YFLIP(xrb, y[i]) );
4274 }
4275 }
4276 }
4277
4278
4279
4280 static void
4281 get_values_rgba(GLcontext *ctx, struct gl_renderbuffer *rb,
4282 GLuint n, const GLint x[], const GLint y[], void *values)
4283 {
4284 GLubyte (*rgba)[4] = (GLubyte (*)[4]) values;
4285 GET_XRB(xrb);
4286 const XMesaContext xmesa = XMESA_CONTEXT(ctx);
4287 XMesaDisplay *dpy = xmesa->xm_visual->display;
4288 XMesaBuffer source = XMESA_BUFFER(ctx->DrawBuffer);
4289 register GLuint i;
4290
4291 if (xrb->pixmap) {
4292 XMesaDrawable buffer = xrb->drawable;
4293 switch (xmesa->pixelformat) {
4294 case PF_Truecolor:
4295 case PF_Dither_True:
4296 case PF_5R6G5B:
4297 case PF_Dither_5R6G5B:
4298 {
4299 unsigned long rMask = GET_REDMASK(xmesa->xm_visual);
4300 unsigned long gMask = GET_GREENMASK(xmesa->xm_visual);
4301 unsigned long bMask = GET_BLUEMASK(xmesa->xm_visual);
4302 GLubyte *pixelToR = xmesa->xm_visual->PixelToR;
4303 GLubyte *pixelToG = xmesa->xm_visual->PixelToG;
4304 GLubyte *pixelToB = xmesa->xm_visual->PixelToB;
4305 GLint rShift = xmesa->xm_visual->rshift;
4306 GLint gShift = xmesa->xm_visual->gshift;
4307 GLint bShift = xmesa->xm_visual->bshift;
4308 for (i=0;i<n;i++) {
4309 unsigned long p = read_pixel( dpy, buffer,
4310 x[i], YFLIP(xrb, y[i]) );
4311 rgba[i][RCOMP] = pixelToR[(p & rMask) >> rShift];
4312 rgba[i][GCOMP] = pixelToG[(p & gMask) >> gShift];
4313 rgba[i][BCOMP] = pixelToB[(p & bMask) >> bShift];
4314 rgba[i][ACOMP] = 255;
4315 }
4316 }
4317 break;
4318 case PF_8A8B8G8R:
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] = (GLubyte) ( p & 0xff);
4323 rgba[i][GCOMP] = (GLubyte) ((p >> 8) & 0xff);
4324 rgba[i][BCOMP] = (GLubyte) ((p >> 16) & 0xff);
4325 rgba[i][ACOMP] = (GLubyte) ((p >> 24) & 0xff);
4326 }
4327 break;
4328 case PF_8A8R8G8B:
4329 for (i=0;i<n;i++) {
4330 unsigned long p = read_pixel( dpy, buffer,
4331 x[i], YFLIP(xrb, y[i]) );
4332 rgba[i][RCOMP] = (GLubyte) ((p >> 16) & 0xff);
4333 rgba[i][GCOMP] = (GLubyte) ((p >> 8) & 0xff);
4334 rgba[i][BCOMP] = (GLubyte) ( p & 0xff);
4335 rgba[i][ACOMP] = (GLubyte) ((p >> 24) & 0xff);
4336 }
4337 break;
4338 case PF_8R8G8B:
4339 for (i=0;i<n;i++) {
4340 unsigned long p = read_pixel( dpy, buffer,
4341 x[i], YFLIP(xrb, y[i]) );
4342 rgba[i][RCOMP] = (GLubyte) ((p >> 16) & 0xff);
4343 rgba[i][GCOMP] = (GLubyte) ((p >> 8) & 0xff);
4344 rgba[i][BCOMP] = (GLubyte) ( p & 0xff);
4345 rgba[i][ACOMP] = 255;
4346 }
4347 break;
4348 case PF_8R8G8B24:
4349 for (i=0;i<n;i++) {
4350 unsigned long p = read_pixel( dpy, buffer,
4351 x[i], YFLIP(xrb, y[i]) );
4352 rgba[i][RCOMP] = (GLubyte) ((p >> 16) & 0xff);
4353 rgba[i][GCOMP] = (GLubyte) ((p >> 8) & 0xff);
4354 rgba[i][BCOMP] = (GLubyte) ( p & 0xff);
4355 rgba[i][ACOMP] = 255;
4356 }
4357 break;
4358 case PF_HPCR:
4359 for (i=0;i<n;i++) {
4360 unsigned long p = read_pixel( dpy, buffer,
4361 x[i], YFLIP(xrb, y[i]) );
4362 rgba[i][RCOMP] = (GLubyte) ( p & 0xE0 );
4363 rgba[i][GCOMP] = (GLubyte) ((p & 0x1C) << 3);
4364 rgba[i][BCOMP] = (GLubyte) ((p & 0x03) << 6);
4365 rgba[i][ACOMP] = (GLubyte) 255;
4366 }
4367 break;
4368 case PF_Dither:
4369 case PF_Lookup:
4370 case PF_Grayscale:
4371 {
4372 GLubyte *rTable = source->pixel_to_r;
4373 GLubyte *gTable = source->pixel_to_g;
4374 GLubyte *bTable = source->pixel_to_b;
4375 for (i=0;i<n;i++) {
4376 unsigned long p = read_pixel( dpy, buffer,
4377 x[i], YFLIP(xrb, y[i]) );
4378 rgba[i][RCOMP] = rTable[p];
4379 rgba[i][GCOMP] = gTable[p];
4380 rgba[i][BCOMP] = bTable[p];
4381 rgba[i][ACOMP] = 255;
4382 }
4383 }
4384 break;
4385 case PF_1Bit:
4386 {
4387 int bitFlip = xmesa->xm_visual->bitFlip;
4388 for (i=0;i<n;i++) {
4389 unsigned long p = read_pixel( dpy, buffer,
4390 x[i], YFLIP(xrb, y[i])) ^ bitFlip;
4391 rgba[i][RCOMP] = (GLubyte) (p * 255);
4392 rgba[i][GCOMP] = (GLubyte) (p * 255);
4393 rgba[i][BCOMP] = (GLubyte) (p * 255);
4394 rgba[i][ACOMP] = 255;
4395 }
4396 }
4397 break;
4398 default:
4399 _mesa_problem(NULL,"Problem in DD.read_color_pixels (1)");
4400 return;
4401 }
4402 }
4403 else if (xrb->ximage) {
4404 /* Read from XImage back buffer */
4405 switch (xmesa->pixelformat) {
4406 case PF_Truecolor:
4407 case PF_Dither_True:
4408 case PF_5R6G5B:
4409 case PF_Dither_5R6G5B:
4410 {
4411 unsigned long rMask = GET_REDMASK(xmesa->xm_visual);
4412 unsigned long gMask = GET_GREENMASK(xmesa->xm_visual);
4413 unsigned long bMask = GET_BLUEMASK(xmesa->xm_visual);
4414 GLubyte *pixelToR = xmesa->xm_visual->PixelToR;
4415 GLubyte *pixelToG = xmesa->xm_visual->PixelToG;
4416 GLubyte *pixelToB = xmesa->xm_visual->PixelToB;
4417 GLint rShift = xmesa->xm_visual->rshift;
4418 GLint gShift = xmesa->xm_visual->gshift;
4419 GLint bShift = xmesa->xm_visual->bshift;
4420 XMesaImage *img = xrb->ximage;
4421 for (i=0;i<n;i++) {
4422 unsigned long p;
4423 p = XMesaGetPixel( img, x[i], YFLIP(xrb, y[i]) );
4424 rgba[i][RCOMP] = pixelToR[(p & rMask) >> rShift];
4425 rgba[i][GCOMP] = pixelToG[(p & gMask) >> gShift];
4426 rgba[i][BCOMP] = pixelToB[(p & bMask) >> bShift];
4427 rgba[i][ACOMP] = 255;
4428 }
4429 }
4430 break;
4431 case PF_8A8B8G8R:
4432 for (i=0;i<n;i++) {
4433 GLuint *ptr4 = PIXEL_ADDR4(xrb, x[i], y[i]);
4434 GLuint p4 = *ptr4;
4435 rgba[i][RCOMP] = (GLubyte) ( p4 & 0xff);
4436 rgba[i][GCOMP] = (GLubyte) ((p4 >> 8) & 0xff);
4437 rgba[i][BCOMP] = (GLubyte) ((p4 >> 16) & 0xff);
4438 rgba[i][ACOMP] = (GLubyte) ((p4 >> 24) & 0xff);
4439 }
4440 break;
4441 case PF_8A8R8G8B:
4442 for (i=0;i<n;i++) {
4443 GLuint *ptr4 = PIXEL_ADDR4(xrb, x[i], y[i]);
4444 GLuint p4 = *ptr4;
4445 rgba[i][RCOMP] = (GLubyte) ((p4 >> 16) & 0xff);
4446 rgba[i][GCOMP] = (GLubyte) ((p4 >> 8) & 0xff);
4447 rgba[i][BCOMP] = (GLubyte) ( p4 & 0xff);
4448 rgba[i][ACOMP] = (GLubyte) ((p4 >> 24) & 0xff);
4449 }
4450 break;
4451 case PF_8R8G8B:
4452 for (i=0;i<n;i++) {
4453 GLuint *ptr4 = PIXEL_ADDR4(xrb, x[i], y[i]);
4454 GLuint p4 = *ptr4;
4455 rgba[i][RCOMP] = (GLubyte) ((p4 >> 16) & 0xff);
4456 rgba[i][GCOMP] = (GLubyte) ((p4 >> 8) & 0xff);
4457 rgba[i][BCOMP] = (GLubyte) ( p4 & 0xff);
4458 rgba[i][ACOMP] = 255;
4459 }
4460 break;
4461 case PF_8R8G8B24:
4462 for (i=0;i<n;i++) {
4463 bgr_t *ptr3 = PIXEL_ADDR3(xrb, x[i], y[i]);
4464 rgba[i][RCOMP] = ptr3->r;
4465 rgba[i][GCOMP] = ptr3->g;
4466 rgba[i][BCOMP] = ptr3->b;
4467 rgba[i][ACOMP] = 255;
4468 }
4469 break;
4470 case PF_HPCR:
4471 for (i=0;i<n;i++) {
4472 GLubyte *ptr1 = PIXEL_ADDR1(xrb, x[i], y[i]);
4473 GLubyte p = *ptr1;
4474 rgba[i][RCOMP] = p & 0xE0;
4475 rgba[i][GCOMP] = (p & 0x1C) << 3;
4476 rgba[i][BCOMP] = (p & 0x03) << 6;
4477 rgba[i][ACOMP] = 255;
4478 }
4479 break;
4480 case PF_Dither:
4481 case PF_Lookup:
4482 case PF_Grayscale:
4483 {
4484 GLubyte *rTable = source->pixel_to_r;
4485 GLubyte *gTable = source->pixel_to_g;
4486 GLubyte *bTable = source->pixel_to_b;
4487 XMesaImage *img = xrb->ximage;
4488 for (i=0;i<n;i++) {
4489 unsigned long p;
4490 p = XMesaGetPixel( img, x[i], YFLIP(xrb, y[i]) );
4491 rgba[i][RCOMP] = rTable[p];
4492 rgba[i][GCOMP] = gTable[p];
4493 rgba[i][BCOMP] = bTable[p];
4494 rgba[i][ACOMP] = 255;
4495 }
4496 }
4497 break;
4498 case PF_1Bit:
4499 {
4500 XMesaImage *img = xrb->ximage;
4501 int bitFlip = xmesa->xm_visual->bitFlip;
4502 for (i=0;i<n;i++) {
4503 unsigned long p;
4504 p = XMesaGetPixel( img, x[i], YFLIP(xrb, y[i]) ) ^ bitFlip;
4505 rgba[i][RCOMP] = (GLubyte) (p * 255);
4506 rgba[i][GCOMP] = (GLubyte) (p * 255);
4507 rgba[i][BCOMP] = (GLubyte) (p * 255);
4508 rgba[i][ACOMP] = 255;
4509 }
4510 }
4511 break;
4512 default:
4513 _mesa_problem(NULL,"Problem in DD.read_color_pixels (1)");
4514 return;
4515 }
4516 }
4517 }
4518
4519
4520 /**
4521 * Initialize the renderbuffer's PutRow, GetRow, etc. functions.
4522 * This would generally only need to be called once when the renderbuffer
4523 * is created. However, we can change pixel formats on the fly if dithering
4524 * is enabled/disabled. Therefore, we may call this more often than that.
4525 */
4526 void
4527 xmesa_set_renderbuffer_funcs(struct xmesa_renderbuffer *xrb,
4528 enum pixel_format pixelformat, GLint depth)
4529 {
4530 const GLboolean pixmap = xrb->pixmap ? GL_TRUE : GL_FALSE;
4531
4532 switch (pixelformat) {
4533 case PF_Index:
4534 ASSERT(xrb->Base.DataType == GL_UNSIGNED_INT);
4535 if (pixmap) {
4536 xrb->Base.PutRow = put_row_ci_pixmap;
4537 xrb->Base.PutRowRGB = NULL;
4538 xrb->Base.PutMonoRow = put_mono_row_ci_pixmap;
4539 xrb->Base.PutValues = put_values_ci_pixmap;
4540 xrb->Base.PutMonoValues = put_mono_values_ci_pixmap;
4541 }
4542 else {
4543 xrb->Base.PutRow = put_row_ci_ximage;
4544 xrb->Base.PutRowRGB = NULL;
4545 xrb->Base.PutMonoRow = put_mono_row_ci_ximage;
4546 xrb->Base.PutValues = put_values_ci_ximage;
4547 xrb->Base.PutMonoValues = put_mono_values_ci_ximage;
4548 }
4549 break;
4550 case PF_Truecolor:
4551 if (pixmap) {
4552 xrb->Base.PutRow = put_row_TRUECOLOR_pixmap;
4553 xrb->Base.PutRowRGB = put_row_rgb_TRUECOLOR_pixmap;
4554 xrb->Base.PutMonoRow = put_mono_row_pixmap;
4555 xrb->Base.PutValues = put_values_TRUECOLOR_pixmap;
4556 xrb->Base.PutMonoValues = put_mono_values_pixmap;
4557 }
4558 else {
4559 xrb->Base.PutRow = put_row_TRUECOLOR_ximage;
4560 xrb->Base.PutRowRGB = put_row_rgb_TRUECOLOR_ximage;
4561 xrb->Base.PutMonoRow = put_mono_row_ximage;
4562 xrb->Base.PutValues = put_values_TRUECOLOR_ximage;
4563 xrb->Base.PutMonoValues = put_mono_values_ximage;
4564 }
4565 break;
4566 case PF_Dither_True:
4567 if (pixmap) {
4568 xrb->Base.PutRow = put_row_TRUEDITHER_pixmap;
4569 xrb->Base.PutRowRGB = put_row_rgb_TRUEDITHER_pixmap;
4570 xrb->Base.PutMonoRow = put_mono_row_TRUEDITHER_pixmap;
4571 xrb->Base.PutValues = put_values_TRUEDITHER_pixmap;
4572 xrb->Base.PutMonoValues = put_mono_values_TRUEDITHER_pixmap;
4573 }
4574 else {
4575 xrb->Base.PutRow = put_row_TRUEDITHER_ximage;
4576 xrb->Base.PutRowRGB = put_row_rgb_TRUEDITHER_ximage;
4577 xrb->Base.PutMonoRow = put_mono_row_TRUEDITHER_ximage;
4578 xrb->Base.PutValues = put_values_TRUEDITHER_ximage;
4579 xrb->Base.PutMonoValues = put_mono_values_TRUEDITHER_ximage;
4580 }
4581 break;
4582 case PF_8A8B8G8R:
4583 if (pixmap) {
4584 xrb->Base.PutRow = put_row_8A8B8G8R_pixmap;
4585 xrb->Base.PutRowRGB = put_row_rgb_8A8B8G8R_pixmap;
4586 xrb->Base.PutMonoRow = put_mono_row_pixmap;
4587 xrb->Base.PutValues = put_values_8A8B8G8R_pixmap;
4588 xrb->Base.PutMonoValues = put_mono_values_pixmap;
4589 }
4590 else {
4591 xrb->Base.PutRow = put_row_8A8B8G8R_ximage;
4592 xrb->Base.PutRowRGB = put_row_rgb_8A8B8G8R_ximage;
4593 xrb->Base.PutMonoRow = put_mono_row_8A8B8G8R_ximage;
4594 xrb->Base.PutValues = put_values_8A8B8G8R_ximage;
4595 xrb->Base.PutMonoValues = put_mono_values_8A8B8G8R_ximage;
4596 }
4597 break;
4598 case PF_8A8R8G8B:
4599 if (pixmap) {
4600 xrb->Base.PutRow = put_row_8A8R8G8B_pixmap;
4601 xrb->Base.PutRowRGB = put_row_rgb_8A8R8G8B_pixmap;
4602 xrb->Base.PutMonoRow = put_mono_row_pixmap;
4603 xrb->Base.PutValues = put_values_8A8R8G8B_pixmap;
4604 xrb->Base.PutMonoValues = put_mono_values_pixmap;
4605 }
4606 else {
4607 xrb->Base.PutRow = put_row_8A8R8G8B_ximage;
4608 xrb->Base.PutRowRGB = put_row_rgb_8A8R8G8B_ximage;
4609 xrb->Base.PutMonoRow = put_mono_row_8A8R8G8B_ximage;
4610 xrb->Base.PutValues = put_values_8A8R8G8B_ximage;
4611 xrb->Base.PutMonoValues = put_mono_values_8A8R8G8B_ximage;
4612 }
4613 break;
4614 case PF_8R8G8B:
4615 if (pixmap) {
4616 xrb->Base.PutRow = put_row_8R8G8B_pixmap;
4617 xrb->Base.PutRowRGB = put_row_rgb_8R8G8B_pixmap;
4618 xrb->Base.PutMonoRow = put_mono_row_pixmap;
4619 xrb->Base.PutValues = put_values_8R8G8B_pixmap;
4620 xrb->Base.PutMonoValues = put_mono_values_pixmap;
4621 }
4622 else {
4623 xrb->Base.PutRow = put_row_8R8G8B_ximage;
4624 xrb->Base.PutRowRGB = put_row_rgb_8R8G8B_ximage;
4625 xrb->Base.PutMonoRow = put_mono_row_8R8G8B_ximage;
4626 xrb->Base.PutValues = put_values_8R8G8B_ximage;
4627 xrb->Base.PutMonoValues = put_mono_values_8R8G8B_ximage;
4628 }
4629 break;
4630 case PF_8R8G8B24:
4631 if (pixmap) {
4632 xrb->Base.PutRow = put_row_8R8G8B24_pixmap;
4633 xrb->Base.PutRowRGB = put_row_rgb_8R8G8B24_pixmap;
4634 xrb->Base.PutMonoRow = put_mono_row_pixmap;
4635 xrb->Base.PutValues = put_values_8R8G8B24_pixmap;
4636 xrb->Base.PutMonoValues = put_mono_values_pixmap;
4637 }
4638 else {
4639 xrb->Base.PutRow = put_row_8R8G8B24_ximage;
4640 xrb->Base.PutRowRGB = put_row_rgb_8R8G8B24_ximage;
4641 xrb->Base.PutMonoRow = put_mono_row_8R8G8B24_ximage;
4642 xrb->Base.PutValues = put_values_8R8G8B24_ximage;
4643 xrb->Base.PutMonoValues = put_mono_values_8R8G8B24_ximage;
4644 }
4645 break;
4646 case PF_5R6G5B:
4647 if (pixmap) {
4648 xrb->Base.PutRow = put_row_5R6G5B_pixmap;
4649 xrb->Base.PutRowRGB = put_row_rgb_5R6G5B_pixmap;
4650 xrb->Base.PutMonoRow = put_mono_row_pixmap;
4651 xrb->Base.PutValues = put_values_5R6G5B_pixmap;
4652 xrb->Base.PutMonoValues = put_mono_values_pixmap;
4653 }
4654 else {
4655 xrb->Base.PutRow = put_row_5R6G5B_ximage;
4656 xrb->Base.PutRowRGB = put_row_rgb_5R6G5B_ximage;
4657 xrb->Base.PutMonoRow = put_mono_row_ximage;
4658 xrb->Base.PutValues = put_values_5R6G5B_ximage;
4659 xrb->Base.PutMonoValues = put_mono_values_ximage;
4660 }
4661 break;
4662 case PF_Dither_5R6G5B:
4663 if (pixmap) {
4664 xrb->Base.PutRow = put_row_DITHER_5R6G5B_pixmap;
4665 xrb->Base.PutRowRGB = put_row_rgb_DITHER_5R6G5B_pixmap;
4666 xrb->Base.PutMonoRow = put_mono_row_TRUEDITHER_pixmap;
4667 xrb->Base.PutValues = put_values_DITHER_5R6G5B_pixmap;
4668 xrb->Base.PutMonoValues = put_mono_values_TRUEDITHER_pixmap;
4669 }
4670 else {
4671 xrb->Base.PutRow = put_row_DITHER_5R6G5B_ximage;
4672 xrb->Base.PutRowRGB = put_row_rgb_DITHER_5R6G5B_ximage;
4673 xrb->Base.PutMonoRow = put_mono_row_DITHER_5R6G5B_ximage;
4674 xrb->Base.PutValues = put_values_DITHER_5R6G5B_ximage;
4675 xrb->Base.PutMonoValues = put_mono_values_DITHER_5R6G5B_ximage;
4676 }
4677 break;
4678 case PF_Dither:
4679 if (pixmap) {
4680 xrb->Base.PutRow = put_row_DITHER_pixmap;
4681 xrb->Base.PutRowRGB = put_row_rgb_DITHER_pixmap;
4682 xrb->Base.PutMonoRow = put_mono_row_DITHER_pixmap;
4683 xrb->Base.PutValues = put_values_DITHER_pixmap;
4684 xrb->Base.PutMonoValues = put_mono_values_DITHER_pixmap;
4685 }
4686 else {
4687 if (depth == 8) {
4688 xrb->Base.PutRow = put_row_DITHER8_ximage;
4689 xrb->Base.PutRowRGB = put_row_rgb_DITHER8_ximage;
4690 xrb->Base.PutMonoRow = put_mono_row_DITHER8_ximage;
4691 xrb->Base.PutValues = put_values_DITHER8_ximage;
4692 xrb->Base.PutMonoValues = put_mono_values_DITHER8_ximage;
4693 }
4694 else {
4695 xrb->Base.PutRow = put_row_DITHER_ximage;
4696 xrb->Base.PutRowRGB = put_row_rgb_DITHER_ximage;
4697 xrb->Base.PutMonoRow = put_mono_row_DITHER_ximage;
4698 xrb->Base.PutValues = put_values_DITHER_ximage;
4699 xrb->Base.PutMonoValues = put_mono_values_DITHER_ximage;
4700 }
4701 }
4702 break;
4703 case PF_1Bit:
4704 if (pixmap) {
4705 xrb->Base.PutRow = put_row_1BIT_pixmap;
4706 xrb->Base.PutRowRGB = put_row_rgb_1BIT_pixmap;
4707 xrb->Base.PutMonoRow = put_mono_row_1BIT_pixmap;
4708 xrb->Base.PutValues = put_values_1BIT_pixmap;
4709 xrb->Base.PutMonoValues = put_mono_values_1BIT_pixmap;
4710 }
4711 else {
4712 xrb->Base.PutRow = put_row_1BIT_ximage;
4713 xrb->Base.PutRowRGB = put_row_rgb_1BIT_ximage;
4714 xrb->Base.PutMonoRow = put_mono_row_1BIT_ximage;
4715 xrb->Base.PutValues = put_values_1BIT_ximage;
4716 xrb->Base.PutMonoValues = put_mono_values_1BIT_ximage;
4717 }
4718 break;
4719 case PF_HPCR:
4720 if (pixmap) {
4721 xrb->Base.PutRow = put_row_HPCR_pixmap;
4722 xrb->Base.PutRowRGB = put_row_rgb_HPCR_pixmap;
4723 xrb->Base.PutMonoRow = put_mono_row_pixmap;
4724 xrb->Base.PutValues = put_values_HPCR_pixmap;
4725 xrb->Base.PutMonoValues = put_mono_values_pixmap;
4726 }
4727 else {
4728 xrb->Base.PutRow = put_row_HPCR_ximage;
4729 xrb->Base.PutRowRGB = put_row_rgb_HPCR_ximage;
4730 xrb->Base.PutMonoRow = put_mono_row_HPCR_ximage;
4731 xrb->Base.PutValues = put_values_HPCR_ximage;
4732 xrb->Base.PutMonoValues = put_mono_values_HPCR_ximage;
4733 }
4734 break;
4735 case PF_Lookup:
4736 if (pixmap) {
4737 xrb->Base.PutRow = put_row_LOOKUP_pixmap;
4738 xrb->Base.PutRowRGB = put_row_rgb_LOOKUP_pixmap;
4739 xrb->Base.PutMonoRow = put_mono_row_pixmap;
4740 xrb->Base.PutValues = put_values_LOOKUP_pixmap;
4741 xrb->Base.PutMonoValues = put_mono_values_pixmap;
4742 }
4743 else {
4744 if (depth==8) {
4745 xrb->Base.PutRow = put_row_LOOKUP8_ximage;
4746 xrb->Base.PutRowRGB = put_row_rgb_LOOKUP8_ximage;
4747 xrb->Base.PutMonoRow = put_mono_row_LOOKUP8_ximage;
4748 xrb->Base.PutValues = put_values_LOOKUP8_ximage;
4749 xrb->Base.PutMonoValues = put_mono_values_LOOKUP8_ximage;
4750 }
4751 else {
4752 xrb->Base.PutRow = put_row_LOOKUP_ximage;
4753 xrb->Base.PutRowRGB = put_row_rgb_LOOKUP_ximage;
4754 xrb->Base.PutMonoRow = put_mono_row_ximage;
4755 xrb->Base.PutValues = put_values_LOOKUP_ximage;
4756 xrb->Base.PutMonoValues = put_mono_values_ximage;
4757 }
4758 }
4759 break;
4760 case PF_Grayscale:
4761 if (pixmap) {
4762 xrb->Base.PutRow = put_row_GRAYSCALE_pixmap;
4763 xrb->Base.PutRowRGB = put_row_rgb_GRAYSCALE_pixmap;
4764 xrb->Base.PutMonoRow = put_mono_row_pixmap;
4765 xrb->Base.PutValues = put_values_GRAYSCALE_pixmap;
4766 xrb->Base.PutMonoValues = put_mono_values_pixmap;
4767 }
4768 else {
4769 if (depth == 8) {
4770 xrb->Base.PutRow = put_row_GRAYSCALE8_ximage;
4771 xrb->Base.PutRowRGB = put_row_rgb_GRAYSCALE8_ximage;
4772 xrb->Base.PutMonoRow = put_mono_row_GRAYSCALE8_ximage;
4773 xrb->Base.PutValues = put_values_GRAYSCALE8_ximage;
4774 xrb->Base.PutMonoValues = put_mono_values_GRAYSCALE8_ximage;
4775 }
4776 else {
4777 xrb->Base.PutRow = put_row_GRAYSCALE_ximage;
4778 xrb->Base.PutRowRGB = put_row_rgb_GRAYSCALE_ximage;
4779 xrb->Base.PutMonoRow = put_mono_row_ximage;
4780 xrb->Base.PutValues = put_values_GRAYSCALE_ximage;
4781 xrb->Base.PutMonoValues = put_mono_values_ximage;
4782 }
4783 }
4784 break;
4785 default:
4786 _mesa_problem(NULL, "Bad pixel format in xmesa_update_state (1)");
4787 return;
4788 }
4789
4790
4791 /* Get functions */
4792 if (pixelformat == PF_Index) {
4793 xrb->Base.GetRow = get_row_ci;
4794 xrb->Base.GetValues = get_values_ci;
4795 }
4796 else {
4797 xrb->Base.GetRow = get_row_rgba;
4798 xrb->Base.GetValues = get_values_rgba;
4799 }
4800 }
4801