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