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

This commit is contained in:
Tonton Th 2019-06-29 19:33:23 +02:00
parent 998aee43fb
commit ea70dd78f6
4 changed files with 67 additions and 0 deletions

View File

@ -43,6 +43,7 @@ int fimg_add_rgb(FloatImg *head, int x, int y, float r, float g, float b);
/* PNM files module */ /* PNM files module */
int fimg_save_as_pnm(FloatImg *head, char *fname, int notused); 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_set(int whot);
double fimg_timer_get(int whot); double fimg_timer_get(int whot);

View File

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

View File

@ -7,6 +7,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include "string.h" #include "string.h"
#include "../floatimg.h" #include "../floatimg.h"
@ -14,6 +15,67 @@
extern int verbosity; /* must be declared around main() */ 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) int fimg_save_as_pnm(FloatImg *head, char *fname, int notused)

View File

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