aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile3
-rw-r--r--configs/debug.mk1
-rw-r--r--src/bmp.c2
-rw-r--r--src/gif.c2
-rw-r--r--src/imagemagick.c61
-rw-r--r--src/jpeg.c3
-rw-r--r--src/main.c8
-rw-r--r--src/meh.h9
-rw-r--r--src/netpbm.c11
-rw-r--r--src/png.c2
10 files changed, 93 insertions, 9 deletions
diff --git a/Makefile b/Makefile
index 77fe712..bc9c88c 100644
--- a/Makefile
+++ b/Makefile
@@ -3,7 +3,6 @@ SRCFILES := $(wildcard src/*.c)
OBJFILES := $(SRCFILES:%.c=%.o)
DEPFILES := $(OBJFILES:%.o=%.d)
CLEANFILES := $(CLEANFILES) $(DEPFILES) $(OBJFILES) meh
-CFLAGS ?= -O3
LIBS ?= -lX11 -lXext -ljpeg -lpng -lgif
PREFIX ?= /usr/local
BINDIR = $(PREFIX)/bin
@@ -12,6 +11,8 @@ BINDIR = $(PREFIX)/bin
CONFIG ?= ../config
-include configs/$(CONFIG).mk
+CFLAGS ?= -O3
+
meh: $(OBJFILES)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJFILES) $(LIBS)
diff --git a/configs/debug.mk b/configs/debug.mk
new file mode 100644
index 0000000..2cec38a
--- /dev/null
+++ b/configs/debug.mk
@@ -0,0 +1 @@
+CFLAGS += -O0 -g -Wall
diff --git a/src/bmp.c b/src/bmp.c
index 33ba589..6fea4bf 100644
--- a/src/bmp.c
+++ b/src/bmp.c
@@ -102,6 +102,8 @@ struct image *bmp_open(FILE *f){
b->rowwidth += 4 - (b->rowwidth & 3);
}
+ b->img.fmt = &bmp;
+
return (struct image *)b;
}
diff --git a/src/gif.c b/src/gif.c
index 17e5d4d..8887efd 100644
--- a/src/gif.c
+++ b/src/gif.c
@@ -45,6 +45,8 @@ static struct image *gif_open(FILE *f){
g->img.bufwidth = gif->SWidth;
g->img.bufheight = gif->SHeight;
+ g->img.fmt = &giflib;
+
return (struct image *)g;
}
diff --git a/src/imagemagick.c b/src/imagemagick.c
new file mode 100644
index 0000000..3c4a9cd
--- /dev/null
+++ b/src/imagemagick.c
@@ -0,0 +1,61 @@
+
+#define _GNU_SOURCE
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/wait.h>
+
+#include "meh.h"
+
+struct image *imagemagick_open(FILE *f){
+ char template[] = "/tmp/fileXXXXXX";
+ char *ntmp = mktemp(template);
+ if(!ntmp){
+ perror("mktemp");
+ exit(EXIT_FAILURE);
+ }
+
+ int pid;
+ if(!(pid = fork())){
+ int origfd = fileno(f);
+ if(lseek(origfd, 0, SEEK_SET) != 0){
+ perror("lseek");
+ exit(EXIT_FAILURE);
+ }
+
+ char *argv[6];
+
+ argv[0] = "convert";
+ argv[1] = "-depth";
+ argv[2] = "255";
+ asprintf(&argv[3], "fd:%i", origfd);
+ asprintf(&argv[4], "ppm:%s", ntmp);
+ argv[5] = NULL;
+ execvp(argv[0], argv);
+ perror("exec");
+ exit(EXIT_FAILURE);
+ }else{
+ int status;
+ waitpid(pid, &status, 0);
+ if(status){
+ return NULL;
+ }
+ fclose(f);
+ FILE *ftmp;
+ if(!(ftmp = fopen(ntmp, "rb"))){
+ perror("fopen");
+ exit(EXIT_FAILURE);
+ }
+ return netpbm.open(ftmp);
+ }
+}
+
+struct imageformat imagemagick = {
+ imagemagick_open,
+ NULL,
+ NULL,
+ NULL
+};
+
diff --git a/src/jpeg.c b/src/jpeg.c
index 26e60d1..fbe53f6 100644
--- a/src/jpeg.c
+++ b/src/jpeg.c
@@ -51,6 +51,9 @@ static struct image *jpeg_open(FILE *f){
}
j->jerr.pub.error_exit = error_exit;
+
+ j->img.fmt = &libjpeg;
+
return (struct image *)j;
}
diff --git a/src/main.c b/src/main.c
index 3a669c6..54b5e22 100644
--- a/src/main.c
+++ b/src/main.c
@@ -22,17 +22,13 @@ static int mode;
extern Display *display;
/* Supported Formats */
-extern struct imageformat libjpeg;
-extern struct imageformat giflib;
-extern struct imageformat libpng;
-extern struct imageformat bmp;
-extern struct imageformat netpbm;
struct imageformat *formats[] = {
&libjpeg,
&bmp,
&libpng,
&netpbm,
&giflib, /* HACK! make gif last (uses read()) */
+ &imagemagick,
NULL
};
@@ -50,7 +46,7 @@ struct image *newimage(FILE *f){
struct imageformat **fmt = formats;
for(fmt = formats; *fmt; fmt++){
if((img = (*fmt)->open(f))){
- img->fmt = *fmt;
+ //img->fmt = *fmt;
img->ximg = NULL;
img->state = NONE;
return img;
diff --git a/src/meh.h b/src/meh.h
index 8465887..88f36e3 100644
--- a/src/meh.h
+++ b/src/meh.h
@@ -49,3 +49,12 @@ printf("%s: %li e2 us\n", (x), ((t1.tv_sec - t0.tv_sec) * 1000000 + t1.tv_usec -
#define TDEBUG_END(x)
#endif
+/* Supported Formats */
+extern struct imageformat libjpeg;
+extern struct imageformat giflib;
+extern struct imageformat libpng;
+extern struct imageformat bmp;
+extern struct imageformat netpbm;
+extern struct imageformat imagemagick;
+
+
diff --git a/src/netpbm.c b/src/netpbm.c
index d87872f..ef61c8e 100644
--- a/src/netpbm.c
+++ b/src/netpbm.c
@@ -54,6 +54,7 @@ struct image *netpbm_open(FILE *f){
fgetc(f);
b->f = f;
+ b->img.fmt = &netpbm;
return (struct image *)b;
}
@@ -66,8 +67,14 @@ static unsigned char readvali(struct netpbm_t *b){
}
static unsigned char readvalb(struct netpbm_t *b){
- int val = fgetc(b->f);
- return val * 255 / b->maxval;
+ if(b->maxval == 65535){
+ int val = fgetc(b->f) << 8;
+ val |= fgetc(b->f);
+ return val * 255 / b->maxval;
+ }else{
+ int val = fgetc(b->f);
+ return val * 255 / b->maxval;
+ }
}
int netpbm_read(struct image *img){
diff --git a/src/png.c b/src/png.c
index 9aab2f8..4dea588 100644
--- a/src/png.c
+++ b/src/png.c
@@ -57,6 +57,8 @@ struct image *png_open(FILE *f){
p->img.bufwidth = png_get_image_width(p->png_ptr, p->info_ptr);
p->img.bufheight = png_get_image_height(p->png_ptr, p->info_ptr);
+ p->img.fmt = &libpng;
+
return (struct image *)p;
}