From c97d443e62bd27755fa62e3f5dc8836c80ae5fc7 Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Sun, 20 Dec 2009 09:18:48 -0800 Subject: add performance tests for scaling. --- src/meh.h | 6 ++++++ src/scale.c | 34 ++++++++++++++++------------------ src/xlib.c | 5 +---- 3 files changed, 23 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/meh.h b/src/meh.h index 4333f51..f2d5e3c 100644 --- a/src/meh.h +++ b/src/meh.h @@ -31,6 +31,12 @@ struct image{ XImage *ximg; }; + +/* scale */ +void scale(struct image *img, int width, int height, int bytesperline, char* __restrict__ newBuf); +void nearestscale(struct image *img, int width, int height, int bytesperline, char* __restrict__ newBuf); + +/* XLib */ void setaspect(unsigned int w, unsigned int h); void xinit(); void drawimage(XImage *ximg, unsigned int width, unsigned int height); diff --git a/src/scale.c b/src/scale.c index 4cd62f3..21fa505 100644 --- a/src/scale.c +++ b/src/scale.c @@ -16,7 +16,7 @@ ) * (v)) >> 20) #define XLOOP(F) \ - for(x = 0; x < ximg->width*4;){ \ + for(x = 0; x < width*4;){ \ const unsigned int x0 = a[x++];\ const unsigned int x1 = a[x++];\ const unsigned int u = a[x++];\ @@ -28,29 +28,28 @@ } #define YITER \ - const unsigned int bufy = (y << 10) * img->bufheight / ximg->height;\ + const unsigned int bufy = (y << 10) * img->bufheight / height;\ const unsigned int v = (bufy & 1023);\ const unsigned int vr = 1023^v;\ - ibuf = &img->buf[y * img->bufheight / ximg->height * img->bufwidth * 3];\ + ibuf = &img->buf[y * img->bufheight / height * img->bufwidth * 3];\ ibufn = ibuf + dy; -void scale(struct image *img, XImage *ximg){ +void scale(struct image *img, int width, int height, int bytesperline, char* __restrict__ newBuf){ int x, y; const unsigned char * __restrict__ ibuf; const unsigned char * __restrict__ ibufn; const unsigned char * const bufend = &img->buf[img->bufwidth * img->bufheight * 3]; - char* __restrict__ newBuf = ximg->data; - const unsigned int jdy = ximg->bytes_per_line / 4 - ximg->width; + const unsigned int jdy = bytesperline / 4 - width; const unsigned int dy = img->bufwidth * 3; TDEBUG_START - unsigned int a[ximg->width * 4]; + unsigned int a[width * 4]; { - unsigned int dx = (img->bufwidth << 10) / ximg->width; - unsigned int bufx = img->bufwidth / ximg->width; - for(x = 0; x < ximg->width * 4;){ + unsigned int dx = (img->bufwidth << 10) / width; + unsigned int bufx = img->bufwidth / width; + for(x = 0; x < width * 4;){ if((bufx >> 10) >= img->bufwidth - 1){ a[x++] = (img->bufwidth - 1) * 3; a[x++] = (img->bufwidth - 1) * 3; @@ -90,20 +89,19 @@ void scale(struct image *img, XImage *ximg){ TDEBUG_END("scale") } -void linearscale(struct image *img, XImage *ximg){ +void nearestscale(struct image *img, int width, int height, int bytesperline, char* __restrict__ newBuf){ int x, y; unsigned char * __restrict__ ibuf; - char* __restrict__ newBuf = ximg->data; - unsigned int jdy = ximg->bytes_per_line / 4 - ximg->width; - unsigned int dx = (img->bufwidth << 10) / ximg->width; + unsigned int jdy = bytesperline / 4 - width; + unsigned int dx = (img->bufwidth << 10) / width; TDEBUG_START - for(y = 0; y < ximg->height; y++){ - unsigned int bufx = img->bufwidth / ximg->width; - ibuf = &img->buf[y * img->bufheight / ximg->height * img->bufwidth * 3]; + for(y = 0; y < height; y++){ + unsigned int bufx = img->bufwidth / width; + ibuf = &img->buf[y * img->bufheight / height * img->bufwidth * 3]; - for(x = 0; x < ximg->width; x++){ + for(x = 0; x < width; x++){ *newBuf++ = (ibuf[(bufx >> 10)*3+2]); *newBuf++ = (ibuf[(bufx >> 10)*3+1]); *newBuf++ = (ibuf[(bufx >> 10)*3+0]); diff --git a/src/xlib.c b/src/xlib.c index ca0a1b5..a407f15 100644 --- a/src/xlib.c +++ b/src/xlib.c @@ -21,9 +21,6 @@ GC gc; int xshm = 0; -void scale(struct image *img, XImage *ximg); -void linearscale(struct image *img, XImage *ximg); - XShmSegmentInfo *shminfo; XImage *ximage(struct image *img, unsigned int width, unsigned int height, int fast){ int depth; @@ -71,7 +68,7 @@ XImage *ximage(struct image *img, unsigned int width, unsigned int height, int f ximg->data = malloc(ximg->bytes_per_line * ximg->height); XInitImage(ximg); } - (fast ? linearscale : scale)(img, ximg); + (fast ? nearestscale : scale)(img, ximg->width, ximg->height, ximg->bytes_per_line, ximg->data); }else{ /* TODO other depths */ fprintf(stderr, "This program does not yet support display depths <24.\n"); -- cgit v1.2.3