diff options
author | John Hawthorn <jhawthor@uvic.ca> | 2008-06-23 21:39:16 -0700 |
---|---|---|
committer | John Hawthorn <jhawthor@uvic.ca> | 2008-06-23 21:39:16 -0700 |
commit | 76f3c8cbcb490ded0d5fdf639b555aa389b25624 (patch) | |
tree | 95801b31ed4349f474cc1f51951c105fe88ef22d | |
parent | 97c9966422d672c28aac39bb0ef6e5fb1c3fd3e1 (diff) | |
download | mirror-meh-76f3c8cbcb490ded0d5fdf639b555aa389b25624.tar.gz mirror-meh-76f3c8cbcb490ded0d5fdf639b555aa389b25624.tar.bz2 mirror-meh-76f3c8cbcb490ded0d5fdf639b555aa389b25624.zip |
fixed overflow in ximage and added a little speed
-rw-r--r-- | src/xlib.c | 41 |
1 files changed, 10 insertions, 31 deletions
@@ -45,19 +45,23 @@ XImage *ximage(struct image *img, unsigned int width, unsigned int height) { gshift = getshift(vis->green_mask); bshift = getshift(vis->blue_mask); + struct timeval tv0, tv1; + if (depth >= 24) { + unsigned char *ibuf; unsigned int dx; size_t numNewBufBytes = ((sizeof(u_int32_t)) * (width) * (height)); u_int32_t *newBuf = malloc(numNewBufBytes); dx = 1024 * img->width / width; for(y = 0; y < height; y++){ - i = (y * img->height / height * img->width) * 1024; + i = 0; + ibuf = &img->buf[y * img->height / height * img->width * 3]; for(x = 0; x < width; x++){ unsigned int r, g, b; - r = (img->buf[(i >> 10)*3] << rshift) & vis->red_mask; - g = (img->buf[(i >> 10)*3+1] << gshift) & vis->green_mask; - b = (img->buf[(i >> 10)*3+2] << bshift) & vis->blue_mask; + r = (ibuf[(i >> 10)*3] << rshift) & vis->red_mask; + g = (ibuf[(i >> 10)*3+1] << gshift) & vis->green_mask; + b = (ibuf[(i >> 10)*3+2] << bshift) & vis->blue_mask; newBuf[j++] = r | g | b; i += dx; @@ -71,34 +75,9 @@ XImage *ximage(struct image *img, unsigned int width, unsigned int height) { width, height, 32, 0 ); - }else if(depth >= 15){ - unsigned int dx; - size_t numNewBufBytes = (2 * width * height); - u_int16_t *newBuf = malloc (numNewBufBytes); - - dx = 1024 * img->width / width; - for(y = 0; y < height; y++){ - i = (y * img->height / height * img->width) * 1024; - for(x = 0; x < width; x++){ - unsigned int r, g, b; - r = (img->buf[i++] << rshift) & vis->red_mask; - g = (img->buf[i++] << gshift) & vis->green_mask; - b = (img->buf[i++] << bshift) & vis->blue_mask; - - newBuf[y * width + x] = r | g | b; - i += dx; - } - } - - ximg = XCreateImage(display, - CopyFromParent, depth, - ZPixmap, 0, - (char *) newBuf, - width, height, - 16, 0 - ); }else{ - fprintf(stderr, "This program does not support displays with a depth less than 15.\n"); + /* TODO other depths */ + fprintf(stderr, "This program does not support display depths less than 24.\n"); exit(1); return NULL; } |