pimping fimg2png

This commit is contained in:
tonton Th 2020-01-22 18:53:55 +01:00
parent 57ef940536
commit a811beee8a
2 changed files with 37 additions and 8 deletions

View File

@ -11,7 +11,7 @@
int verbosity; 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]; int foo, infos[3];
FloatImg fimg; FloatImg fimg;
@ -22,7 +22,10 @@ fprintf(stderr, ">>> %25s ( '%s' '%s' %d )\n", __func__,
#endif #endif
foo = fimg_fileinfos(srcname, infos); 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) { if (verbosity) {
fprintf(stderr, "image '%s' is %d x %d %s\n", fprintf(stderr, "image '%s' is %d x %d %s\n",
@ -36,6 +39,10 @@ if (foo) {
return -1; return -1;
} }
if (grisaille) {
foo = fimg_desaturate(&fimg, &fimg, 0);
}
foo = fimg_save_as_png(&fimg, dstname, 0); foo = fimg_save_as_png(&fimg, dstname, 0);
if (foo) { if (foo) {
fprintf(stderr, "saving as png '%s' -> %d\n", dstname, foo); fprintf(stderr, "saving as png '%s' -> %d\n", dstname, foo);
@ -47,19 +54,40 @@ fimg_destroy(&fimg);
return 0; 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 main(int argc, char *argv[])
{ {
int foo; int foo, opt;
int to_gray = 0;
if (3 != argc) { while ((opt = getopt(argc, argv, "ghv")) != -1) {
fimg_print_version(1); switch(opt) {
fprintf(stderr, "usage:\n\t%s foo.fimg bar.png\n", argv[0]); 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); exit(1);
} }
foo = convertir_fimg_en_PNG(argv[1], argv[2], 0); foo = convertir_fimg_en_PNG(argv[optind], argv[optind+1], to_gray);
fprintf(stderr, "%s : got a %d from convertor\n", argv[0], foo); if (verbosity)
fprintf(stderr, "%s : got a %d from convertor\n", argv[0], foo);
return 0; return 0;
} }

View File

@ -43,6 +43,7 @@ if (0 != foo) {
pr_v4l2_format("after ioctl VIDIOC_G_FMT", &fmt); pr_v4l2_format("after ioctl VIDIOC_G_FMT", &fmt);
/* this function is bugged */
return k; return k;
} }