diff --git a/.gitignore b/.gitignore index 9f1d4f21..f8e5937f 100644 --- a/.gitignore +++ b/.gitignore @@ -47,6 +47,7 @@ v4l2/nc-camcontrol tools/fimg2png tools/fimg2pnm +tools/fimg2tiff tools/fimgstats tools/mkfimg tools/png2fimg diff --git a/tools/Makefile b/tools/Makefile index bdf820a6..a02efbb7 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -9,6 +9,7 @@ DEPS = ../floatimg.h ../libfloatimg.a Makefile # ---------- all: fimg2pnm mkfimg png2fimg fimgstats fimg2png \ + fimg2tiff \ addpnm2fimg cumulfimgs fimgops fimgfx fimgstats: fimgstats.c $(DEPS) @@ -32,6 +33,9 @@ fimg2pnm: fimg2pnm.c $(DEPS) fimg2png: fimg2png.c $(DEPS) gcc $(COPT) $< ../libfloatimg.a -lpnglite -lz -o $@ +fimg2tiff: fimg2tiff.c $(DEPS) + gcc $(COPT) $< ../libfloatimg.a -ltiff -o $@ + # # this tool require an external library # http://la.buvette.org/devel/libimage/libimage.html diff --git a/tools/fimg2tiff.c b/tools/fimg2tiff.c new file mode 100644 index 00000000..b65c1ef3 --- /dev/null +++ b/tools/fimg2tiff.c @@ -0,0 +1,97 @@ +/* + * converting a floatimg to a TIFF + */ + +#include +#include +#include + +#include "../floatimg.h" + +int verbosity; + +/* ----------------------------------------------------------------- */ +int convertir_fimg_en_TIFF(char *srcname, char *dstname, int grisaille) +{ +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) { + if (verbosity) fprintf(stderr, "'%s' get dims -> %d\n", srcname, foo); + return foo; + } + +if (verbosity) { + fprintf(stderr, "%s: image '%s' is %d x %d %s\n", + __func__, + 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; + } + +if (grisaille) { + foo = fimg_desaturate(&fimg, &fimg, 0); + } + +foo = fimg_write_as_tiff(&fimg, dstname, 0); +if (foo) { + fprintf(stderr, "%s: saving as png '%s' -> %d\n", __func__, + dstname, foo); + return -1; + } + +fimg_destroy(&fimg); + +return 0; +} +/* ----------------------------------------------------------------- */ +void help(int k) +{ + +puts("usage:\n\tfimg2tiff [options] foo.fimg bar.png"); +puts("options:"); +puts("\t-g\tconvert to gray"); +puts("\t-v\tincrease verbosity"); +if (verbosity) fimg_print_version(1); + +exit(0); +} +/* ----------------------------------------------------------------- */ + +int main(int argc, char *argv[]) +{ +int foo, opt; +int to_gray = 0; + +while ((opt = getopt(argc, argv, "ghv")) != -1) { + switch(opt) { + case 'g': to_gray = 1; break; + case 'v': verbosity++; break; + case 'h': help(1); exit(1); + } + } + +if (2 != argc-optind) { + fprintf(stderr, "error: %s need two filenames\n", argv[0]); + exit(1); + } + +foo = convertir_fimg_en_TIFF(argv[optind], argv[optind+1], to_gray); +if (foo) + fprintf(stderr, "%s : got a %d from convertor\n", argv[0], foo); + +return 0; +} +/* ----------------------------------------------------------------- */ +