aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJohn Hawthorn <john.hawthorn@gmail.com>2009-12-20 09:18:48 -0800
committerJohn Hawthorn <john.hawthorn@gmail.com>2009-12-20 09:18:48 -0800
commitc97d443e62bd27755fa62e3f5dc8836c80ae5fc7 (patch)
tree3a1a95b127c1b2e4773a8d2c08f6a60e833a630c /src
parent2803eebe996da45dc13a593a49a2330c829829c1 (diff)
downloadmirror-meh-c97d443e62bd27755fa62e3f5dc8836c80ae5fc7.tar.gz
mirror-meh-c97d443e62bd27755fa62e3f5dc8836c80ae5fc7.tar.bz2
mirror-meh-c97d443e62bd27755fa62e3f5dc8836c80ae5fc7.zip
add performance tests for scaling.
Diffstat (limited to 'src')
-rw-r--r--src/meh.h6
-rw-r--r--src/scale.c34
-rw-r--r--src/xlib.c5
3 files changed, 23 insertions, 22 deletions
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");