diff --git a/.gitignore b/.gitignore index d73467d..78d1411 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,7 @@ doc/*.ilg doc/*.ind funcs/t +funcs/*.png scripts/*.fimg scripts/*.pnm diff --git a/floatimg.h b/floatimg.h index fc87e49..de7692b 100644 --- a/floatimg.h +++ b/floatimg.h @@ -2,7 +2,7 @@ * floatimg.h */ -#define FIMG_VERSION 80 +#define FIMG_VERSION 81 /* * in memory descriptor diff --git a/funcs/Makefile b/funcs/Makefile index ca69a5d..765f181 100644 --- a/funcs/Makefile +++ b/funcs/Makefile @@ -8,7 +8,7 @@ OBJS = fimg-png.o fimg-tiff.o misc-plots.o filtrage.o utils.o \ #--------------------------------------------------------------- t: t.c $(DEPS) ../libfloatimg.a - gcc $(COPT) $< ../libfloatimg.a -lnetpbm -o $@ + gcc $(COPT) $< ../libfloatimg.a -lnetpbm -lpnglite -lm -o $@ #--------------------------------------------------------------- diff --git a/funcs/fimg-png.c b/funcs/fimg-png.c index e1ec15f..6daa482 100644 --- a/funcs/fimg-png.c +++ b/funcs/fimg-png.c @@ -1,5 +1,6 @@ /* * Lecture des images PNG + * L'ecriture est en chantier :} */ #include @@ -175,13 +176,59 @@ png_close_file(&png); return 0; } /* --------------------------------------------------------------------- */ - +/* nouveau 13 decembre 2019 */ int fimg_save_as_png(FloatImg *src, char *outname, int flags) { -png_t png; +png_t png; +int foo, sz, idx; +unsigned char *bytes, *bptr; +double maximum, fk; +#if DEBUG_LEVEL +fprintf(stderr, ">>> %-25s ( %p '%s' %x )\n", __func__, src, outname, flags); +#endif +/* convert ou floating datas to a byte/rgb array */ + /* first, alloc a buffer */ +sz = src->width * src->height; +bytes = calloc(sz, 3); +if (NULL==bytes) { + fprintf(stderr, "%s : no mem ?\n", __func__); + exit(3); + } + /* compute max value */ +maximum = (double)fimg_get_maxvalue(src); +fk = maximum / 255.0; +fprintf(stderr, " max values %g fk %g\n", maximum, fk); + /* massage des pixels */ +bptr = bytes; +for (idx=0; idxR[idx] / fk); + *bptr++ = (unsigned char) (src->G[idx] / fk); + *bptr++ = (unsigned char) (src->B[idx] / fk); + } -return -1; +memset(&png, 0, sizeof(png_t)); +png_init(NULL, NULL); /* this is VITAL ! */ + +foo = png_open_file_write(&png, outname); +if (PNG_NO_ERROR != foo) { + fprintf(stderr, "error in '%s' : open_file_write -> %d\n", + __func__, foo); + return foo; + } + +foo = png_set_data(&png, src->width, src->height, 8, PNG_TRUECOLOR, bytes); +if (PNG_NO_ERROR != foo) { + fprintf(stderr, "error in '%s' : set_data -> %d\n", + __func__, foo); + return foo; + } + +png_close_file(&png); + +free(bytes); /* yolo ? */ + +return 0; } /* --------------------------------------------------------------------- */ diff --git a/funcs/t.c b/funcs/t.c index 98f58b1..d4ab3f2 100644 --- a/funcs/t.c +++ b/funcs/t.c @@ -51,11 +51,30 @@ printf("%-10s %d\n\n", fname, foo); return 0; } /* --------------------------------------------------------------------- */ -int main(int argc, char *argv[]) +int essai_ecrire_png(char *fname) { +FloatImg fimg; int foo; -foo = essai_detect_type(); +fimg_create(&fimg, 512, 512, FIMG_TYPE_RGB); +for (foo=0; foo<512; foo++) { + fimg_plot_rgb(&fimg, foo, foo, 17000.0, 8000.0, 11111.1); + } + +fimg_save_as_pnm(&fimg, "quux.pnm", 0); + +foo = fimg_save_as_png(&fimg, fname, 0); + +return 0; +} +/* --------------------------------------------------------------------- */ +int main(int argc, char *argv[]) +{ +int foo; + +puts("++++++++++++++++++++++++++++++++"); + +foo = essai_ecrire_png("dessin.png"); return 0; } diff --git a/install.sh b/install.sh index 2a29004..ca6cd2b 100755 --- a/install.sh +++ b/install.sh @@ -4,6 +4,7 @@ cp libfloatimg.a /usr/local/lib cp floatimg.h /usr/local/include cp tools/mkfimg tools/fimg2pnm tools/fimgops \ + tools/fimg2png \ tools/png2fimg tools/fimgstats tools/fimgfx \ /usr/local/bin diff --git a/tools/Makefile b/tools/Makefile index d389817..088d54f 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -30,7 +30,7 @@ fimg2pnm: fimg2pnm.c $(DEPS) gcc $(COPT) $< ../libfloatimg.a -o $@ fimg2png: fimg2png.c $(DEPS) - gcc $(COPT) $< ../libfloatimg.a -o $@ + gcc $(COPT) $< ../libfloatimg.a -lpnglite -o $@ addtga2fimg: addtga2fimg.c $(DEPS) gcc $(COPT) $< ../libfloatimg.a -limageSO -lm -o $@ diff --git a/tools/fimg2png.c b/tools/fimg2png.c index 6546142..db6bba5 100644 --- a/tools/fimg2png.c +++ b/tools/fimg2png.c @@ -1,13 +1,56 @@ +/* + * converting a floatimg to a PNG + */ + #include #include #include #include "../floatimg.h" -/* --------------------------------------------------------------------- */ +int verbosity; + +/* ----------------------------------------------------------------- */ +int convertir_fimg_en_PNG(char *srcname, char *dstname, int notused) +{ +int foo, infos[3]; +FloatImg fimg; + +#if DEBUG_LEVEL +fprintf(stderr, ">>> %25s ( '%s' '%s' %d )\n", __func__, + srcname, dstname, notused); +#endif + +foo = fimg_fileinfos(srcname, infos); +if (foo) { fprintf(stderr, "'%s' get dims -> %d\n", srcname, foo); } + +if (verbosity) { + fprintf(stderr, "image '%s' is %d x %d %s\n", + srcname, infos[0], infos[1], + fimg_str_type(infos[2])); + } + +foo = fimg_create_from_dump(srcname, &fimg); +if (foo) { + fprintf(stderr, "create fimg from '%s' -> %d\n", srcname, foo); + return -1; + } + +foo = fimg_save_as_png(&fimg, dstname, 0); +if (foo) { + fprintf(stderr, "saving as png '%s' -> %d\n", dstname, foo); + return -1; + } + +fimg_destroy(&fimg); + +return -1; +} +/* ----------------------------------------------------------------- */ + int main(int argc, char *argv[]) { -// int foo; +int foo; if (3 != argc) { fimg_print_version(1); @@ -15,9 +58,10 @@ if (3 != argc) { exit(1); } -fprintf(stderr, "ah ah ah, no working code here !\n"); +foo = convertir_fimg_en_PNG(argv[1], argv[2], 0); +fprintf(stderr, "%s : got a %d from convertor\n", argv[0], foo); return 0; } -/* --------------------------------------------------------------------- */ +/* ----------------------------------------------------------------- */ diff --git a/v4l2/Makefile b/v4l2/Makefile index 690aa7a..d81028f 100644 --- a/v4l2/Makefile +++ b/v4l2/Makefile @@ -1,6 +1,6 @@ -COPT = -Wall -fpic -g -no-pie -DDEBUG_LEVEL=1 +COPT = -Wall -fpic -g -no-pie -DDEBUG_LEVEL=0 DEPS = ../floatimg.h ../libfloatimg.a Makefile all: grabvidseq t