FloatImg/tools/fimg2png.c

101 lines
2.0 KiB
C
Raw Normal View History

2019-12-13 18:18:07 +01:00
/*
* converting a floatimg to a PNG
*/
2019-03-03 16:22:55 +01:00
#include <stdio.h>
#include <stdlib.h>
2021-05-20 09:31:28 +02:00
#include <stdint.h>
2019-03-03 16:22:55 +01:00
#include <unistd.h>
#include "../floatimg.h"
2019-12-13 18:18:07 +01:00
int verbosity;
/* ----------------------------------------------------------------- */
2020-01-22 18:53:55 +01:00
int convertir_fimg_en_PNG(char *srcname, char *dstname, int grisaille)
2019-12-13 18:18:07 +01:00
{
int foo, infos[3];
FloatImg fimg;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %25s ( '%s' '%s' %d )\n", __func__,
2022-02-09 22:59:58 +01:00
srcname, dstname, grisaille);
2019-12-13 18:18:07 +01:00
#endif
foo = fimg_fileinfos(srcname, infos);
2020-01-22 18:53:55 +01:00
if (foo) {
if (verbosity) fprintf(stderr, "'%s' get dims -> %d\n", srcname, foo);
return foo;
}
2019-12-13 18:18:07 +01:00
if (verbosity) {
2021-04-02 09:10:29 +02:00
fprintf(stderr, "%s: image '%s' is %dx%d %s\n",
2020-02-26 12:06:11 +01:00
__func__,
2019-12-13 18:18:07 +01:00
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;
}
2020-01-22 18:53:55 +01:00
if (grisaille) {
foo = fimg_desaturate(&fimg, &fimg, 0);
}
2019-12-13 18:18:07 +01:00
foo = fimg_save_as_png(&fimg, dstname, 0);
if (foo) {
2020-02-26 12:06:11 +01:00
fprintf(stderr, "%s: saving as png '%s' -> %d\n", __func__,
dstname, foo);
2019-12-13 18:18:07 +01:00
return -1;
}
fimg_destroy(&fimg);
2019-12-14 15:19:35 +01:00
return 0;
2019-12-13 18:18:07 +01:00
}
/* ----------------------------------------------------------------- */
2020-01-22 18:53:55 +01:00
void help(int k)
{
2022-10-27 21:32:02 +02:00
puts("usage:\n\tfimg2png [options] from.fimg to.png");
2020-01-22 18:53:55 +01:00
puts("options:");
puts("\t-g\tconvert to gray");
puts("\t-v\tincrease verbosity");
2022-07-06 10:27:55 +02:00
if (verbosity) fimg_print_version(k);
2020-01-22 18:53:55 +01:00
exit(0);
}
/* ----------------------------------------------------------------- */
2019-12-13 18:18:07 +01:00
2019-03-03 16:22:55 +01:00
int main(int argc, char *argv[])
{
2020-01-22 18:53:55 +01:00
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);
2023-05-29 09:06:57 +02:00
default: exit(1);
2020-01-22 18:53:55 +01:00
}
}
2019-03-03 16:22:55 +01:00
2020-01-22 18:53:55 +01:00
if (2 != argc-optind) {
fprintf(stderr, "error: %s need two filenames\n", argv[0]);
2019-03-03 16:22:55 +01:00
exit(1);
}
2020-01-22 18:53:55 +01:00
foo = convertir_fimg_en_PNG(argv[optind], argv[optind+1], to_gray);
2021-02-27 10:56:42 +01:00
if (foo) {
2020-01-22 18:53:55 +01:00
fprintf(stderr, "%s : got a %d from convertor\n", argv[0], foo);
2021-02-27 10:56:42 +01:00
}
2019-08-12 01:53:17 +02:00
2019-03-03 16:22:55 +01:00
return 0;
}
2019-12-13 18:18:07 +01:00
/* ----------------------------------------------------------------- */
2019-03-03 16:22:55 +01:00