aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Hawthorn <jhawthor@uvic.ca>2009-07-24 23:15:51 -0700
committerJohn Hawthorn <jhawthor@uvic.ca>2009-07-24 23:15:51 -0700
commit368db221a74763c53025e1c93b81784cd73b9b31 (patch)
tree6e10f742ac46a8401cfc59775ae91e70c0b2c9b8
parent61781aecb368bdf5f28c7e0a46879ab6e4b31ae0 (diff)
downloadmirror-meh-368db221a74763c53025e1c93b81784cd73b9b31.tar.gz
mirror-meh-368db221a74763c53025e1c93b81784cd73b9b31.tar.bz2
mirror-meh-368db221a74763c53025e1c93b81784cd73b9b31.zip
implement the rest of netpbm
-rw-r--r--src/netpbm.c56
1 files changed, 48 insertions, 8 deletions
diff --git a/src/netpbm.c b/src/netpbm.c
index e6f6851..0cf4ca6 100644
--- a/src/netpbm.c
+++ b/src/netpbm.c
@@ -58,15 +58,49 @@ struct image *netpbm_open(FILE *f){
return (struct image *)b;
}
+static unsigned char readvali(struct netpbm_t *b){
+ skipspace(b->f);
+ int val;
+ fscanf(b->f, "%i", &val);
+ return val * 255 / b->maxval;
+}
+
+static unsigned char readvalb(struct netpbm_t *b){
+ int val = fgetc(b->f);
+ return val * 255 / b->maxval;
+}
+
int netpbm_read(struct image *img){
struct netpbm_t *b = (struct netpbm_t *)img;
FILE *f = b->f;
int a = 0;
int left = img->bufwidth * img->bufheight;
- int j, c;
-
- if(b->format == '4'){
+ int j, c, val;
+
+ if(b->format == '1'){
+ while(left--){
+ skipspace(f);
+ val = fgetc(f);
+ val = val == '1' ? 0 : 255;
+ img->buf[a++] = val;
+ img->buf[a++] = val;
+ img->buf[a++] = val;
+ }
+ }else if(b->format == '2'){
+ while(left--){
+ val = readvali(b);
+ img->buf[a++] = val;
+ img->buf[a++] = val;
+ img->buf[a++] = val;
+ }
+ }else if(b->format == '3'){
+ while(left--){
+ img->buf[a++] = readvali(b);
+ img->buf[a++] = readvali(b);
+ img->buf[a++] = readvali(b);
+ }
+ }else if(b->format == '4'){
while(left){
c = fgetc(f);
for(j = 0; j < 8 && left; j++){
@@ -78,12 +112,18 @@ int netpbm_read(struct image *img){
left--;
}
}
+ }else if(b->format == '5'){
+ while(left--){
+ val = readvalb(b);
+ img->buf[a++] = val;
+ img->buf[a++] = val;
+ img->buf[a++] = val;
+ }
}else if(b->format == '6'){
- while(left){
- img->buf[a++] = fgetc(f);
- img->buf[a++] = fgetc(f);
- img->buf[a++] = fgetc(f);
- left--;
+ while(left--){
+ img->buf[a++] = readvalb(b);
+ img->buf[a++] = readvalb(b);
+ img->buf[a++] = readvalb(b);
}
}