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 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;
}

View File

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