diff options
author | kraxel <kraxel> | 2005-01-14 08:53:06 +0000 |
---|---|---|
committer | kraxel <kraxel> | 2005-01-14 08:53:06 +0000 |
commit | f356778e6134001ac1543918f77d7d1217a1a3e7 (patch) | |
tree | b4dfa615f304876dcbc979052f148af17e5886ad | |
parent | 41699c6af92100078c301fe958d1da0d3ff290f5 (diff) | |
download | fbida-f356778e6134001ac1543918f77d7d1217a1a3e7.tar.gz |
- add pbm loader.
-rw-r--r-- | rd/read-ppm.c | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/rd/read-ppm.c b/rd/read-ppm.c index b7eb326..210e4c3 100644 --- a/rd/read-ppm.c +++ b/rd/read-ppm.c @@ -20,17 +20,20 @@ pnm_init(FILE *fp, char *filename, unsigned int page, { struct ppm_state *h; char line[1024]; + char p; h = malloc(sizeof(*h)); memset(h,0,sizeof(*h)); h->infile = fp; - fgets(line,sizeof(line),fp); /* Px */ + fgets(line,sizeof(line),fp); /* P[456] */ + p = line[1]; fgets(line,sizeof(line),fp); /* width height */ while ('#' == line[0]) fgets(line,sizeof(line),fp); /* skip comments */ sscanf(line,"%d %d",&h->width,&h->height); - fgets(line,sizeof(line),fp); /* ??? */ + if (p != '4') + fgets(line,sizeof(line),fp); /* depth ??? */ if (0 == h->width || 0 == h->height) goto oops; i->width = h->width; @@ -73,6 +76,17 @@ pgm_read(unsigned char *dst, unsigned int line, void *data) } static void +pbm_read(unsigned char *dst, unsigned int line, void *data) +{ + struct ppm_state *h = data; + int bpl; + + bpl = ((h->width+7) >> 3); + fread(h->row,bpl,1,h->infile); + load_bits_msb(dst,(unsigned char*)(h->row),h->width,255,0); +} + +static void pnm_done(void *data) { struct ppm_state *h = data; @@ -102,9 +116,20 @@ static struct ida_loader pgm_loader = { done: pnm_done, }; +static struct ida_loader pbm_loader = { + magic: "P4", + moff: 0, + mlen: 2, + name: "pbm parser", + init: pnm_init, + read: pbm_read, + done: pnm_done, +}; + static void __init init_rd(void) { load_register(&ppm_loader); load_register(&pgm_loader); + load_register(&pbm_loader); } |