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