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