From b162454f815c35ddef0b60001f7f7a0e9c63b801 Mon Sep 17 00:00:00 2001 From: "\"John Hawthorn ext:(%22)" Date: Wed, 31 Dec 2008 15:13:59 -0800 Subject: removed overflow and other tweaks in scale() --- src/scale.c | 73 ++++++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 51 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/scale.c b/src/scale.c index cbda1ad..19186dc 100644 --- a/src/scale.c +++ b/src/scale.c @@ -3,6 +3,9 @@ #include #include "meh.h" +#define TDEBUG 0 + +#define GETVAL0(x, c) ((ibuf[(x) * 3 + (c)] * (ur) + ibuf[(x) * 3 + 3+(c)] * (u)) * (vr) >> 20) #define GETVAL(x, c) (( \ ( \ ibuf[(x) * 3 + (c)] * (ur) + \ @@ -14,16 +17,23 @@ ) * (v)) >> 20) +#if TDEBUG +struct timeval t0; +struct timeval t1; +#endif + void scale(struct image *img, XImage *ximg){ int x, y; unsigned char * __restrict__ ibuf; unsigned char * __restrict__ ibufn; + unsigned char * const bufend = &img->buf[img->bufwidth * img->bufheight * 3]; char* __restrict__ newBuf = ximg->data; unsigned int jdy = ximg->bytes_per_line / 4 - ximg->width; + unsigned int dy = img->bufwidth * 3; -// struct timeval t0; -// struct timeval t1; -// gettimeofday(&t0, NULL); +#if TDEBUG + gettimeofday(&t0, NULL); +#endif unsigned int bufxs[ximg->width]; unsigned int us[ximg->width]; @@ -36,28 +46,45 @@ void scale(struct image *img, XImage *ximg){ bufx += dx; } } - - for(y = 0; y < ximg->height; y++){ + y = 0; + ibuf = img->buf; + ibufn = img->buf + dy; + for(; y < ximg->height; y++){ unsigned int bufy = (y << 10) * img->bufheight / ximg->height; unsigned int v = (bufy & 1023); unsigned int vr = 1023^(bufy & 1023); ibuf = &img->buf[y * img->bufheight / ximg->height * img->bufwidth * 3]; - ibufn = &img->buf[(y * img->bufheight / ximg->height + 1) * img->bufwidth * 3]; - for(x = 0; x < ximg->width; x++){ - unsigned int bufx = bufxs[x]; - unsigned int u = us[x]; - unsigned int ur = 1023^u; - - *newBuf++ = GETVAL(bufx, 2); - *newBuf++ = GETVAL(bufx, 1); - *newBuf++ = GETVAL(bufx, 0); - newBuf++; + ibufn = ibuf + dy; + if(ibufn >= bufend){ + for(x = 0; x < ximg->width; x++){ + unsigned int bufx = bufxs[x]; + unsigned int u = us[x]; + unsigned int ur = 1023^u; + + *newBuf++ = GETVAL0(bufx, 2); + *newBuf++ = GETVAL0(bufx, 1); + *newBuf++ = GETVAL0(bufx, 0); + newBuf++; + } + }else{ + for(x = 0; x < ximg->width; x++){ + unsigned int bufx = bufxs[x]; + unsigned int u = us[x]; + unsigned int ur = 1023^u; + + *newBuf++ = GETVAL(bufx, 2); + *newBuf++ = GETVAL(bufx, 1); + *newBuf++ = GETVAL(bufx, 0); + newBuf++; + } } newBuf += jdy; } -// gettimeofday(&t1, NULL); -// printf("%li ms\n", ((t1.tv_sec - t0.tv_sec) * 1000000 + t1.tv_usec - t0.tv_usec) / 1000); +#if TDEBUG + gettimeofday(&t1, NULL); + printf("%li x100us\n", ((t1.tv_sec - t0.tv_sec) * 1000000 + t1.tv_usec - t0.tv_usec) / 100); +#endif } void linearscale(struct image *img, XImage *ximg){ @@ -67,9 +94,9 @@ void linearscale(struct image *img, XImage *ximg){ unsigned int jdy = ximg->bytes_per_line / 4 - ximg->width; unsigned int dx = (img->bufwidth << 10) / ximg->width; -// struct timeval t0; -// struct timeval t1; -// gettimeofday(&t0, NULL); + struct timeval t0; + struct timeval t1; + gettimeofday(&t0, NULL); for(y = 0; y < ximg->height; y++){ unsigned int bufx = img->bufwidth / ximg->width; @@ -85,8 +112,10 @@ void linearscale(struct image *img, XImage *ximg){ newBuf += jdy; } -// gettimeofday(&t1, NULL); -// printf("%i\n", ((t1.tv_sec - t0.tv_sec) * 1000000 + t1.tv_usec - t0.tv_usec) / 10); +#if TDEBUG + gettimeofday(&t1, NULL); + printf("%li x100us\n", ((t1.tv_sec - t0.tv_sec) * 1000000 + t1.tv_usec - t0.tv_usec) / 100); +#endif } -- cgit v1.2.3