From a811beee8ab0d047f2a35a5486afb2d677f94539 Mon Sep 17 00:00:00 2001 From: tonton Th Date: Wed, 22 Jan 2020 18:53:55 +0100 Subject: [PATCH] pimping fimg2png --- tools/fimg2png.c | 44 ++++++++++++++++++++++++++++++++++++-------- v4l2/t.c | 1 + 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/tools/fimg2png.c b/tools/fimg2png.c index f732279..b546c1e 100644 --- a/tools/fimg2png.c +++ b/tools/fimg2png.c @@ -11,7 +11,7 @@ int verbosity; /* ----------------------------------------------------------------- */ -int convertir_fimg_en_PNG(char *srcname, char *dstname, int notused) +int convertir_fimg_en_PNG(char *srcname, char *dstname, int grisaille) { int foo, infos[3]; FloatImg fimg; @@ -22,7 +22,10 @@ fprintf(stderr, ">>> %25s ( '%s' '%s' %d )\n", __func__, #endif foo = fimg_fileinfos(srcname, infos); -if (foo) { fprintf(stderr, "'%s' get dims -> %d\n", srcname, foo); } +if (foo) { + if (verbosity) fprintf(stderr, "'%s' get dims -> %d\n", srcname, foo); + return foo; + } if (verbosity) { fprintf(stderr, "image '%s' is %d x %d %s\n", @@ -36,6 +39,10 @@ if (foo) { return -1; } +if (grisaille) { + foo = fimg_desaturate(&fimg, &fimg, 0); + } + foo = fimg_save_as_png(&fimg, dstname, 0); if (foo) { fprintf(stderr, "saving as png '%s' -> %d\n", dstname, foo); @@ -47,19 +54,40 @@ fimg_destroy(&fimg); return 0; } /* ----------------------------------------------------------------- */ +void help(int k) +{ + +puts("usage:\n\tfimg2png [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; +int foo, opt; +int to_gray = 0; -if (3 != argc) { - fimg_print_version(1); - fprintf(stderr, "usage:\n\t%s foo.fimg bar.png\n", argv[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_PNG(argv[1], argv[2], 0); -fprintf(stderr, "%s : got a %d from convertor\n", argv[0], foo); +foo = convertir_fimg_en_PNG(argv[optind], argv[optind+1], to_gray); +if (verbosity) + fprintf(stderr, "%s : got a %d from convertor\n", argv[0], foo); return 0; } diff --git a/v4l2/t.c b/v4l2/t.c index 08cb6a4..bf537fa 100644 --- a/v4l2/t.c +++ b/v4l2/t.c @@ -43,6 +43,7 @@ if (0 != foo) { pr_v4l2_format("after ioctl VIDIOC_G_FMT", &fmt); +/* this function is bugged */ return k; }