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>
|
|
|
|
#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__,
|
|
|
|
srcname, dstname, notused);
|
|
|
|
#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) {
|
2020-02-26 12:06:11 +01:00
|
|
|
fprintf(stderr, "%s: image '%s' is %d x %d %s\n",
|
|
|
|
__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)
|
|
|
|
{
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
/* ----------------------------------------------------------------- */
|
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);
|
|
|
|
}
|
|
|
|
}
|
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);
|
2020-03-26 08:41:00 +01:00
|
|
|
if (foo)
|
2020-01-22 18:53:55 +01:00
|
|
|
fprintf(stderr, "%s : got a %d from convertor\n", argv[0], foo);
|
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
|
|
|
|