2019-07-03 18:51:42 +02:00
|
|
|
/*
|
|
|
|
* conversion vers le format PNM
|
|
|
|
*
|
|
|
|
*/
|
2019-03-03 16:22:55 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "../floatimg.h"
|
|
|
|
|
|
|
|
int verbosity;
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
int convertir_fimg_en_pnm(char *srcname, char *dstname, int notused)
|
|
|
|
{
|
|
|
|
int foo, infos[3];
|
|
|
|
FloatImg fimg;
|
|
|
|
|
|
|
|
#if DEBUG_LEVEL
|
|
|
|
fprintf(stderr, ">>> %25s ( '%s' '%s' )\n", __func__, srcname, dstname);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
foo = fimg_fileinfos(srcname, infos);
|
|
|
|
if (foo) { fprintf(stderr, "'%s' get dims -> %d\n", srcname, foo); }
|
|
|
|
|
|
|
|
if (verbosity) {
|
2019-09-10 12:18:02 +02:00
|
|
|
fprintf(stderr, "image '%s' is %d x %d %s\n",
|
|
|
|
srcname, infos[0], infos[1],
|
|
|
|
fimg_str_type(infos[2]));
|
2019-03-03 16:22:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
foo = fimg_create_from_dump(srcname, &fimg);
|
|
|
|
if (foo) {
|
|
|
|
fprintf(stderr, "create fimg from '%s' -> %d\n", srcname, foo);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if DEBUG_LEVEL > 1
|
|
|
|
print_floatimg(&fimg, "created fimg");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
foo = fimg_save_as_pnm(&fimg, dstname, 0);
|
|
|
|
if(foo) { fprintf(stderr, "%p to '%s' -> %d\n", &fimg, dstname, foo); }
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* --------------------------------------------------------------------- */
|
2019-09-10 12:18:02 +02:00
|
|
|
static void help(int flag)
|
|
|
|
{
|
|
|
|
if (flag) {
|
|
|
|
fprintf(stderr, "conversion FIMG -> PNM 16 bits\n");
|
|
|
|
fimg_print_version(1);
|
|
|
|
}
|
|
|
|
puts("usage :");
|
|
|
|
puts("\tfimg2pnm [flags] infile.fimg outfile.pnm");
|
|
|
|
}
|
|
|
|
/* --------------------------------------------------------------------- */
|
2019-03-03 16:22:55 +01:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2019-09-10 12:18:02 +02:00
|
|
|
int foo, opt;
|
2019-03-03 16:22:55 +01:00
|
|
|
|
2019-09-10 12:18:02 +02:00
|
|
|
if (argc == 1) {
|
|
|
|
help(0);
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
while ((opt = getopt(argc, argv, "v")) != -1) {
|
|
|
|
switch(opt) {
|
|
|
|
case 'v': verbosity++; break;
|
|
|
|
case 'h': help(1); exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if DEBUG_LEVEL
|
|
|
|
/* mmmm, is it the good way ? */
|
|
|
|
printf("argc %d -> %d\n", argc, argc-optind);
|
|
|
|
for (foo=optind; foo<argc; foo++) {
|
|
|
|
printf(" %d %s\n", foo, argv[foo]);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (2 != argc-optind) {
|
|
|
|
fprintf(stderr, "error: %s need two filenames\n", argv[0]);
|
2019-03-03 16:22:55 +01:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2019-09-10 12:18:02 +02:00
|
|
|
if ( 0 != access(argv[optind], R_OK) ) { /* fimg is NOT readable */
|
|
|
|
fprintf(stderr, "%s: %s don't exist.\n", argv[0], argv[optind]);
|
2019-03-03 16:22:55 +01:00
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
|
2019-09-10 12:18:02 +02:00
|
|
|
foo = convertir_fimg_en_pnm(argv[optind], argv[optind+1], 0);
|
2019-03-03 16:22:55 +01:00
|
|
|
if (foo) fprintf(stderr, "conversion -> %d\n", foo);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2019-07-03 18:51:42 +02:00
|
|
|
/* --------------------------------------------------------------------- */
|