aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Hawthorn <jhawthor@uvic.ca>2008-06-16 22:16:10 -0700
committerJohn Hawthorn <jhawthor@uvic.ca>2008-06-16 22:16:10 -0700
commite0e1ecc20ada06a1c1cfea359b01b61cdfb44acd (patch)
tree619e612877bf617a9c8b9a80c89be3648a1aef96
parentf5b1ed2faf007ac9c8ef12b2db2ea4bb725f19b0 (diff)
downloadmirror-meh-e0e1ecc20ada06a1c1cfea359b01b61cdfb44acd.tar.gz
mirror-meh-e0e1ecc20ada06a1c1cfea359b01b61cdfb44acd.tar.bz2
mirror-meh-e0e1ecc20ada06a1c1cfea359b01b61cdfb44acd.zip
improved speed of scale
-rw-r--r--src/gif.c2
-rw-r--r--src/main.c26
-rw-r--r--src/png.c4
3 files changed, 23 insertions, 9 deletions
diff --git a/src/gif.c b/src/gif.c
index a6a13d6..78400f2 100644
--- a/src/gif.c
+++ b/src/gif.c
@@ -64,6 +64,8 @@ static int gif_read(struct image *img){
img->buf[j++] = colormap[idx].Blue;
}
+ DGifCloseFile(g->gif);
+
return 0;
}
diff --git a/src/main.c b/src/main.c
index f093b91..35d322d 100644
--- a/src/main.c
+++ b/src/main.c
@@ -64,7 +64,7 @@ XImage *ximage(struct image *img, int width, int height) {
unsigned int rshift, gshift, bshift;
int i;
int x,y;
-
+
depth = DefaultDepth(display, screen);
vis = DefaultVisual(display, screen);
@@ -73,21 +73,24 @@ XImage *ximage(struct image *img, int width, int height) {
bshift = getshift(vis->blue_mask);
if (depth >= 24) {
+ unsigned int dx;
size_t numNewBufBytes = (4 * 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;
for(x = 0; x < width; x++){
unsigned int r, g, b;
- i = (y * img->height / height * img->width + x * img->width / width) * 3;
- r = (img->buf[i++] << rshift) & vis->red_mask;
- g = (img->buf[i++] << gshift) & vis->green_mask;
- b = (img->buf[i++] << bshift) & vis->blue_mask;
+ 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;
newBuf[y * width + x] = r | g | b;
+ i += dx;
}
}
-
+
ximg = XCreateImage (display,
CopyFromParent, depth,
ZPixmap, 0,
@@ -96,18 +99,21 @@ XImage *ximage(struct image *img, int width, int 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;
- i = (y * img->height / height * img->width + x * img->width / width) * 3;
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;
}
}
@@ -283,7 +289,9 @@ void run(struct imagenode *image){
}
if(!img->buf){
img->buf = malloc(3 * img->width * img->height);
- img->fmt->read(img);
+ if(img->fmt->read(img)){
+ fprintf(stderr, "read error!\n");
+ }
continue; /* Allow for some events to be read, read is slow */
}
if(!ximg){
diff --git a/src/png.c b/src/png.c
index 6631708..bd461c5 100644
--- a/src/png.c
+++ b/src/png.c
@@ -69,6 +69,10 @@ struct image *png_open(FILE *f){
int png_read(struct image *img){
struct png_t *p = (struct png_t *)img;
+ if(setjmp(png_jmpbuf(p->png_ptr))){
+ png_destroy_read_struct(&p->png_ptr, &p->info_ptr, &p->end_info);
+ return 1;
+ }
int y;
while(p->numpasses--){
for(y = 0; y < img->height; y++)