Browse Source

i can now read a few portable pixmap, the P6 type

master
Tonton Th 3 years ago
parent
commit
ea70dd78f6
  1. 1
      floatimg.h
  2. 3
      lib/Makefile
  3. 62
      lib/fimg-pnm.c
  4. 1
      v4l2/grabvidseq.c

1
floatimg.h

@ -43,6 +43,7 @@ int fimg_add_rgb(FloatImg *head, int x, int y, float r, float g, float b); @@ -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);

3
lib/Makefile

@ -12,6 +12,9 @@ AR=ar @@ -12,6 +12,9 @@ AR=ar
all: $(OBJS) ../libfloatimg.a
t: t.c ../libfloatimg.a $(DEPS)
gcc $(COPT) $< ../libfloatimg.a -o $@
# --------------------------------------------
../libfloatimg.a: $(OBJS)

62
lib/fimg-pnm.c

@ -7,6 +7,7 @@ @@ -7,6 +7,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "string.h"
#include "../floatimg.h"
@ -14,6 +15,67 @@ @@ -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<height; line++) {
foo = fread(buffline, 3, width, fp);
fprintf(stderr, "line %d read %d\n", line, width);
idxrd = buffline;
for (column=0; column<width; column++)
{
*Rptr++ = (float)*idxrd++;
*Gptr++ = (float)*idxrd++;
*Bptr++ = (float)*idxrd++;
}
}
fclose(fp);
return 0;
}
/* ---------------------------------------------------------------- */
int fimg_save_as_pnm(FloatImg *head, char *fname, int notused)

1
v4l2/grabvidseq.c

@ -194,6 +194,7 @@ for (i = 0; i < nbre_capt; i++) { @@ -194,6 +194,7 @@ for (i = 0; i < nbre_capt; i++) {
fmt.fmt.pix.width, fmt.fmt.pix.height);
fwrite(buffers[buf.index].start, buf.bytesused, 1, fout);
fclose(fout);
if (nbre_capt > 1 && period) {
sleep(period);
}

Loading…
Cancel
Save