aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
author"John Hawthorn ext:(%22) <jhawthor@uvic.ca>2008-12-21 19:26:08 -0800
committer"John Hawthorn ext:(%22) <jhawthor@uvic.ca>2008-12-21 19:26:08 -0800
commit6f208d6c757e03784c768774dfa2fa568444877c (patch)
treefe4f056f804b51e640a28c0bfc0156902eeda786
parentd9e9f33c3210b71c07c4268415ff9b1555819b3f (diff)
downloadmirror-meh-6f208d6c757e03784c768774dfa2fa568444877c.tar.gz
mirror-meh-6f208d6c757e03784c768774dfa2fa568444877c.tar.bz2
mirror-meh-6f208d6c757e03784c768774dfa2fa568444877c.zip
cleanup
-rw-r--r--src/jpeg.c12
-rw-r--r--src/main.c8
-rw-r--r--src/xlib.c75
3 files changed, 15 insertions, 80 deletions
diff --git a/src/jpeg.c b/src/jpeg.c
index 5745541..11e9898 100644
--- a/src/jpeg.c
+++ b/src/jpeg.c
@@ -14,12 +14,6 @@ struct error_mgr{
jmp_buf jmp_buffer;
};
-static void error_exit(j_common_ptr cinfo){
- (void) cinfo;
- printf("\nerror!\n");
- exit(1);
-}
-
struct jpeg_t{
struct image img;
FILE *f;
@@ -27,6 +21,12 @@ struct jpeg_t{
struct error_mgr jerr;
};
+static void error_exit(j_common_ptr cinfo){
+ (void) cinfo;
+ printf("\nerror!\n");
+ exit(1);
+}
+
static struct image *jpeg_open(FILE *f){
struct jpeg_t *j;
diff --git a/src/main.c b/src/main.c
index 99fedbb..872ec7a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -98,14 +98,14 @@ void handlekeypress(XEvent *event){
exit(0);
break;
case XK_Return:
- // puts(filename);
+ puts(images[imageidx]);
fflush(stdout);
break;
- case XK_t:
- case XK_n:
+ case XK_j:
+ case XK_k:
if(mode == MODE_CTL)
return;
- direction = key == XK_t ? nextimage : previmage;
+ direction = key == XK_j ? nextimage : previmage;
direction();
/* Pass through */
freeimage(img);
diff --git a/src/xlib.c b/src/xlib.c
index 511e740..e1730aa 100644
--- a/src/xlib.c
+++ b/src/xlib.c
@@ -21,75 +21,8 @@ GC gc;
int xshm = 0;
-#define GETVAL(x, c) (ibuf[(x) * 3 + (c)])
-#define GETLVAL(x, y, u, v, c) (( \
- (GETVAL((x), (c)) * (1023^(u)) + GETVAL((x)+1, (c)) * (u)) * (1023^(v)) + \
- (GETVAL((x)+img->bufwidth, (c)) * (1023^(u)) + GETVAL((x)+img->bufwidth+1, (c)) * (u)) * (v)) >> 20)
-
-void scale(struct image *img, XImage *ximg){
- 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;
-
- struct timeval t0;
- struct timeval t1;
- gettimeofday(&t0, NULL);
-
- for(y = 0; y < ximg->height; y++){
- unsigned int bufy = (y << 10) * img->bufheight / ximg->height;
- unsigned int v_ratio = (bufy & 1023);
- unsigned int bufx = img->bufwidth / ximg->width;
- unsigned char *ibuf = &img->buf[y * img->bufheight / ximg->height * img->bufwidth * 3];
- for(x = ximg->width; x; x--){
- unsigned int u_ratio = (bufx & 1023);
-
- *newBuf++ = GETLVAL(bufx >> 10, bufy >> 10, u_ratio, v_ratio, 2);
- *newBuf++ = GETLVAL(bufx >> 10, bufy >> 10, u_ratio, v_ratio, 1);
- *newBuf++ = GETLVAL(bufx >> 10, bufy >> 10, u_ratio, v_ratio, 0);
- newBuf++;
-
- bufx += dx;
- }
- newBuf += jdy;
- }
-
- gettimeofday(&t1, NULL);
- printf("%i ms\n", ((t1.tv_sec - t0.tv_sec) * 1000000 + t1.tv_usec - t0.tv_usec) / 1000);
-}
-
-
-void linearscale(struct image *img, XImage *ximg){
- unsigned int i;
- int x, y;
- unsigned int dx;
- unsigned char * __restrict__ ibuf;
- char* __restrict__ newBuf = ximg->data;
- unsigned int jdy = ximg->bytes_per_line / 4 - ximg->width;
- dx = (img->bufwidth << 10) / ximg->width;
-
- struct timeval t0;
- struct timeval t1;
- gettimeofday(&t0, NULL);
-
- for(y = 0; y < ximg->height; y++){
- i = 0;
- ibuf = &img->buf[y * img->bufheight / ximg->height * img->bufwidth * 3];
- for(x = 0; x < ximg->width; x++){
- *newBuf++ = (ibuf[(i >> 10)*3+2]);
- *newBuf++ = (ibuf[(i >> 10)*3+1]);
- *newBuf++ = (ibuf[(i >> 10)*3]);
- newBuf++;
-
- i += dx;
- }
- newBuf += jdy;
- }
-
- gettimeofday(&t1, NULL);
- printf("%i ms\n", ((t1.tv_sec - t0.tv_sec) * 1000000 + t1.tv_usec - t0.tv_usec) / 1000);
-}
+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) {
@@ -110,6 +43,8 @@ XImage *ximage(struct image *img, unsigned int width, unsigned int height) {
shminfo,
width, height
))){
+ fprintf(stderr, "XShm problems\n");
+ exit(1);
}
if((shminfo->shmid = shmget(IPC_PRIVATE, ximg->bytes_per_line * ximg->height, IPC_CREAT|0777)) == -1){
fprintf(stderr, "XShm problems\n");
@@ -133,7 +68,7 @@ XImage *ximage(struct image *img, unsigned int width, unsigned int height) {
width, height,
32, 0
);
- ximg->data = malloc(ximg->bytes_per_line * ximg->height + /*HACK*/(ximg->bytes_per_line+1));
+ ximg->data = malloc(ximg->bytes_per_line * ximg->height);
XInitImage(ximg);
}
scale(img, ximg);