RWS@ZERMATT.LCS.MIT.EDU (Robert Scheifler) (10/11/87)
VERSION: X11 release 1 SYNOPSIS: XPutImage was pretty broken on Z format images DESCRIPTION: It basically didn't work, particularly for sub images, but also for 1-bit z format wrt bit order. REPEAT-BY: xwd|xwud on almost any display and window FIX: for lib/X/XPutImage.c: (included as well are various reformats and lint cleanups, and a simple speedup for certain XY and Z subimages) *** /tmp/,RCSt1023871 Sun Oct 11 15:36:32 1987 --- XPutImage.c Sun Oct 11 14:56:51 1987 *************** *** 1,6 **** #include "copyright.h" ! /* $Header: XPutImage.c,v 11.34 87/09/11 15:46:16 rws Exp $ */ /* Copyright Massachusetts Institute of Technology 1986 */ #include <stdio.h> --- 1,6 ---- #include "copyright.h" ! /* $Header: XPutImage.c,v 11.36 87/10/11 14:56:23 rws Exp $ */ /* Copyright Massachusetts Institute of Technology 1986 */ #include <stdio.h> *************** *** 72,83 **** &&(dpy->byte_order == image->byte_order) &&(dpy->bitmap_bit_order == image->bitmap_bit_order) &&(image->width == req_width) ! &&(total_xoffset < dpy->bitmap_pad) ! &&(req_yoffset == 0)) { length = image->bytes_per_line * req_height; req->length += length >> 2; req->leftPad = total_xoffset; ! _XSend (dpy, image->data, length); } else { long nbytes; --- 72,82 ---- &&(dpy->byte_order == image->byte_order) &&(dpy->bitmap_bit_order == image->bitmap_bit_order) &&(image->width == req_width) ! &&(total_xoffset < dpy->bitmap_pad)) { length = image->bytes_per_line * req_height; req->length += length >> 2; req->leftPad = total_xoffset; ! _XSend (dpy, image->data + req_yoffset * image->bytes_per_line, length); } else { long nbytes; *************** *** 109,117 **** for (i = 0; i < req_height; i++, row_addr += image->bytes_per_line,p+=nbytes) { bcopy (row_addr, p, (int)nbytes); ! if (image->bitmap_bit_order ! != dpy->bitmap_bit_order) _swapbits ( ! (unsigned char *)p, image->bytes_per_line); #ifdef notdef if ((image->byte_order != image->bitmap_bit_order) || (dpy->byte_order != dpy->bitmap_bit_order)) --- 108,116 ---- for (i = 0; i < req_height; i++, row_addr += image->bytes_per_line,p+=nbytes) { bcopy (row_addr, p, (int)nbytes); ! if (image->bitmap_bit_order != dpy->bitmap_bit_order) ! _swapbits ((unsigned char *)p, ! (long)image->bytes_per_line); #ifdef notdef if ((image->byte_order != image->bitmap_bit_order) || (dpy->byte_order != dpy->bitmap_bit_order)) *************** *** 125,131 **** break; ! case XYPixmap: /* not yet implemented */ /* * If the client side format matches the screen, we win! */ --- 124,130 ---- break; ! case XYPixmap: /* * If the client side format matches the screen, we win! */ *************** *** 146,152 **** long nbytes; char *row_addr; register char *p; ! char* tempbuf; int bytes_per_plane,j; /* * compute length of image data; round up to next length --- 145,151 ---- long nbytes; char *row_addr; register char *p; ! char *tempbuf; int bytes_per_plane,j; /* * compute length of image data; round up to next length *************** *** 180,188 **** for (i = 0; i < req_height; i++, row_addr += image->bytes_per_line,p+=nbytes) { bcopy (row_addr, p, (int)nbytes); ! if (image->bitmap_bit_order ! != dpy->bitmap_bit_order) _swapbits ( ! (unsigned char *)p, nbytes); #ifdef notdef if ((image->byte_order != image->bitmap_bit_order) || (dpy->byte_order != dpy->bitmap_bit_order)) --- 179,186 ---- for (i = 0; i < req_height; i++, row_addr += image->bytes_per_line,p+=nbytes) { bcopy (row_addr, p, (int)nbytes); ! if (image->bitmap_bit_order != dpy->bitmap_bit_order) ! _swapbits ((unsigned char *)p, nbytes); #ifdef notdef if ((image->byte_order != image->bitmap_bit_order) || (dpy->byte_order != dpy->bitmap_bit_order)) *************** *** 201,214 **** /* * If the client side format matches the screen, we win! */ - /* XXX is this right? */ req->leftPad = 0; if ((dpy->byte_order == image->byte_order) ! &&(dpy->bitmap_pad == image->bitmap_pad)) { ! length = image->bytes_per_line * image->height; req->length += length >> 2; ! _XSend (dpy, image->data, length); } else { /* --- 199,213 ---- /* * If the client side format matches the screen, we win! */ req->leftPad = 0; if ((dpy->byte_order == image->byte_order) ! &&(dpy->bitmap_pad == image->bitmap_pad) ! &&(image->width == req_width) ! &&(total_xoffset == 0)) { ! length = image->bytes_per_line * req_height; req->length += length >> 2; ! _XSend (dpy, image->data + req_yoffset * image->bytes_per_line, length); } else { /* *************** *** 218,232 **** */ long nbytes; unsigned char *row = (unsigned char *) (image->data + req_yoffset * image->bytes_per_line); ! unsigned char *tempbuf, *p; int bit_xoffset, pseudoLeftPad, byte_xoffset; - int j; nbytes = length = ROUNDUP(req_width * image->bits_per_pixel, dpy->bitmap_pad) >> 3; - tempbuf = p = (unsigned char *)_XAllocScratch(dpy, (unsigned long)nbytes * req_height); - length *= req_height; req->length += length >> 2; bit_xoffset = req_xoffset * image->bits_per_pixel; --- 217,230 ---- */ long nbytes; unsigned char *row = (unsigned char *) (image->data + req_yoffset * image->bytes_per_line); ! char *tempbuf, *p; int bit_xoffset, pseudoLeftPad, byte_xoffset; nbytes = length = ROUNDUP(req_width * image->bits_per_pixel, dpy->bitmap_pad) >> 3; length *= req_height; + tempbuf = p = _XAllocScratch(dpy, (unsigned long)length); + req->length += length >> 2; bit_xoffset = req_xoffset * image->bits_per_pixel; *************** *** 240,256 **** */ ! if (pseudoLeftPad != 0) ! { ! for ( j=0; j < nbytes; j++) { ! p[j] = (row[byte_xoffset + j] >> (pseudoLeftPad)) | (row[byte_xoffset + j + 1] << ( 8 - pseudoLeftPad)); } ! ! } ! else ! bcopy (row + ((req_xoffset * image->bits_per_pixel) >> 3), p, (int)nbytes); ! if (image->byte_order != dpy->byte_order) { if(image->bits_per_pixel == 32) _swaplong(p, nbytes); else if (image->bits_per_pixel == 24) _swapthree (p, nbytes); --- 238,271 ---- */ ! if (pseudoLeftPad != 0) { ! register unsigned char *pp = (unsigned char *)p; ! register unsigned char *rp = row + byte_xoffset; ! register unsigned char *endp = pp + nbytes; ! register int pseudoRightPad = 8 - pseudoLeftPad; ! if (image->bitmap_bit_order == MSBFirst) ! for (; pp < endp; pp++, rp++) ! *pp = *rp << pseudoLeftPad | ! *(rp+1) >> pseudoRightPad; ! else ! for (; pp < endp; pp++, rp++) ! *pp = *rp >> pseudoLeftPad | ! *(rp+1) << pseudoRightPad; } ! else ! bcopy ((char *) (row + byte_xoffset), p, (int)nbytes); ! if (image->bits_per_pixel == 1) { ! if (image->bitmap_bit_order != dpy->bitmap_bit_order) ! _swapbits ((unsigned char *)p, nbytes); ! #ifdef notdef ! if ((image->byte_order != image->bitmap_bit_order) || ! (dpy->byte_order != dpy->bitmap_bit_order)) ! { ! /* XXX swapping missing XXX */ ! } ! #endif ! } else if (image->byte_order != dpy->byte_order) { if(image->bits_per_pixel == 32) _swaplong(p, nbytes); else if (image->bits_per_pixel == 24) _swapthree (p, nbytes); *************** *** 257,263 **** else if (image->bits_per_pixel == 16) _swapshort (p, nbytes); } ! } _XSend(dpy, tempbuf, length); } break; --- 272,278 ---- else if (image->bits_per_pixel == 16) _swapshort (p, nbytes); } ! } _XSend(dpy, tempbuf, length); } break; *************** *** 457,463 **** if (SubImageHeight < 1) SubImageHeight = 1; PutSubImage(dpy, d, gc, image, req_xoffset, req_yoffset, x, y, ! req_width, SubImageHeight); PutSubImage(dpy, d, gc, image, req_xoffset, req_yoffset + SubImageHeight, x, y + SubImageHeight, req_width, --- 472,478 ---- if (SubImageHeight < 1) SubImageHeight = 1; PutSubImage(dpy, d, gc, image, req_xoffset, req_yoffset, x, y, ! req_width, (unsigned int) SubImageHeight); PutSubImage(dpy, d, gc, image, req_xoffset, req_yoffset + SubImageHeight, x, y + SubImageHeight, req_width, *************** *** 469,475 **** dpy->bitmap_pad) * dpy->bitmap_pad - left_pad; PutSubImage(dpy, d, gc, image, req_xoffset, req_yoffset, x, y, ! SubImageWidth, req_height); PutSubImage(dpy, d, gc, image, req_xoffset + SubImageWidth, req_yoffset, x + SubImageWidth, y, req_width - SubImageWidth, --- 484,490 ---- dpy->bitmap_pad) * dpy->bitmap_pad - left_pad; PutSubImage(dpy, d, gc, image, req_xoffset, req_yoffset, x, y, ! (unsigned int) SubImageWidth, req_height); PutSubImage(dpy, d, gc, image, req_xoffset + SubImageWidth, req_yoffset, x + SubImageWidth, y, req_width - SubImageWidth,
black@masscomp.UUCP (Sam Black) (10/15/87)
The bug fixes posted by Bob Scheifler will not work for servers where the ZPixmap padding rules are different from the bitmap padding rules. This is because 'dpy->bitmap_pad' is used everywhere, instead of using _XGetScanlinePad() to define the padding. Is there (or is there going to be) a "blessed" solution to this problem? - sam -------------------------------------- I'm pink, therefore I'm Spam. ...!{cca,decvax,seismo}!masscomp!black UUCP black%masscomp.uucp@<internet gateway> Internet --------------------------------------