FloatImg/tools/fimg2pnm.c

63 lines
1.4 KiB
C

#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) {
fprintf(stderr, "image '%s' is %d x %d\n",
srcname, infos[0], infos[1]);
}
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;
}
/* --------------------------------------------------------------------- */
int main(int argc, char *argv[])
{
int foo;
if (3 != argc) {
fimg_print_version(1);
fprintf(stderr, "usage:\n\t%s foo.fimg bar.pnm\n", argv[0]);
exit(1);
}
if ( 0 != access(argv[1], R_OK|W_OK) ) { /* fimg is NOT readable */
fprintf(stderr, "%s: %s don't exist.\n", argv[0], argv[1]);
exit(2);
}
foo = convertir_fimg_en_pnm(argv[1], argv[2], 0);
if (foo) fprintf(stderr, "conversion -> %d\n", foo);
return 0;
}