diff --git a/floatimg.h b/floatimg.h index e6a67cb..dba2cf5 100644 --- a/floatimg.h +++ b/floatimg.h @@ -43,6 +43,7 @@ int fimg_add_rgb(FloatImg *head, int x, int y, float r, float g, float b); /* PNM files module */ int fimg_save_as_pnm(FloatImg *head, char *fname, int notused); +int fimg_load_from_pnm(char *fname, FloatImg *head, int notused); double fimg_timer_set(int whot); double fimg_timer_get(int whot); diff --git a/lib/Makefile b/lib/Makefile index 1106759..8324da0 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -12,6 +12,9 @@ AR=ar all: $(OBJS) ../libfloatimg.a +t: t.c ../libfloatimg.a $(DEPS) + gcc $(COPT) $< ../libfloatimg.a -o $@ + # -------------------------------------------- ../libfloatimg.a: $(OBJS) diff --git a/lib/fimg-pnm.c b/lib/fimg-pnm.c index 80a5396..d01b2af 100644 --- a/lib/fimg-pnm.c +++ b/lib/fimg-pnm.c @@ -7,6 +7,7 @@ #include #include #include + #include "string.h" #include "../floatimg.h" @@ -14,6 +15,67 @@ extern int verbosity; /* must be declared around main() */ /* ---------------------------------------------------------------- */ +/* nouveau juin 2019, pendant la Ravebish */ + +int fimg_load_from_pnm(char *fname, FloatImg *head, int notused) +{ +FILE *fp; +int width, height, maxval; +int foo, line, column; +unsigned char *buffline, *idxrd; +float *Rptr, *Gptr, *Bptr; + +if (NULL==head) { + fprintf(stderr, "%s : head ptr is %p\n", __func__, head); + return -8; + } + +if (NULL==(fp=fopen(fname, "r"))) { + perror(fname); + exit(1); + } + +foo = fscanf(fp, "P6 %d %d %d", &width, &height, &maxval); +if (3 != foo) { + fprintf(stderr, "%s : fscanf -> %d\n", __func__, foo); + return -1; + } + +if (verbosity) { + fprintf(stderr, "%s is %dx%d , max=%d\n",fname, width, height, maxval); + } + +if (NULL==(buffline=calloc(3, width))) { + fprintf(stderr, "%s on %s : memory error\n", __func__, fname); + return -2; + } + +foo = fimg_create(head, width, height, 3); +if (foo) { + fprintf(stderr, "%s : create floatimg -> %d\n", __func__, foo); + exit(1); + } + +fseek(fp, 1L, SEEK_CUR); /* black magic */ + +Rptr = head->R; Gptr = head->G; Bptr = head->B; +for (line=0; line 1 && period) { sleep(period); }