From ea70dd78f68ce1dbe2fe83b76fc7b829f0596d68 Mon Sep 17 00:00:00 2001 From: Tonton Th Date: Sat, 29 Jun 2019 19:33:23 +0200 Subject: [PATCH] i can now read a few portable pixmap, the P6 type --- floatimg.h | 1 + lib/Makefile | 3 +++ lib/fimg-pnm.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++ v4l2/grabvidseq.c | 1 + 4 files changed, 67 insertions(+) diff --git a/floatimg.h b/floatimg.h index e6a67cb4..dba2cf55 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 1106759f..8324da04 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 80a5396b..d01b2af1 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); }