FloatImg4PythonBinding/tools/fimghalfsize.c

95 lines
1.8 KiB
C
Raw Normal View History

2021-04-06 04:20:36 +11:00
/*
*/
#include <stdio.h>
#include <unistd.h> /* pour getopt */
#include <stdlib.h>
2021-04-06 04:26:10 +11:00
#include <string.h>
2021-04-06 04:20:36 +11:00
#include "../floatimg.h"
int verbosity;
/* ------------------------------------------------------------- */
2021-04-06 05:49:01 +11:00
int faire_un_halfsize(char *iname, char *oname, int to_gray)
2021-04-06 04:20:36 +11:00
{
FloatImg src, dst;
int foo;
foo = fimg_create_from_dump(iname, &src);
if (foo) {
fprintf(stderr, "create fimg from '%s' -> %d\n", iname, foo);
return -1;
}
memset(&dst, 0, sizeof(FloatImg));
2021-04-10 04:23:12 +11:00
foo = fimg_halfsize_1(&src, &dst, 0);
2021-04-06 04:20:36 +11:00
if (foo) {
2021-04-10 04:23:12 +11:00
fprintf(stderr, "halfize 1 fail -> %d\n", foo);
2021-04-06 04:20:36 +11:00
return -1;
}
2021-04-06 05:49:01 +11:00
if (to_gray) {
foo = fimg_to_gray(&dst);
2021-04-10 04:23:12 +11:00
/* and ? */
2021-04-06 05:49:01 +11:00
}
2021-04-06 04:20:36 +11:00
foo = fimg_dump_to_file(&dst, oname, 0);
if (foo) {
fprintf(stderr, "save to '%s' -> %d\n", oname, foo);
return -1;
}
return -1;
}
/* ------------------------------------------------------------- */
void help(int u)
{
2021-04-10 04:23:12 +11:00
puts("Usage:\n\tfimghalfsize [options] in.fimg out.fimg");
puts("Options:");
puts("\t-g\tconvert output to gray");
exit(0);
2021-04-06 04:20:36 +11:00
}
/* ------------------------------------------------------------- */
int main(int argc, char *argv[])
{
2021-04-06 05:49:01 +11:00
int foo, opt;
2021-04-06 04:20:36 +11:00
char *srcname = "";
char *dstname = "out.fimg";
2021-04-06 05:49:01 +11:00
int grayed = 0;
2021-04-06 04:20:36 +11:00
2021-04-06 05:49:01 +11:00
while ((opt = getopt(argc, argv, "ghv")) != -1) {
2021-04-06 04:20:36 +11:00
switch(opt) {
2021-04-06 05:49:01 +11:00
case 'g': grayed = 1; break;
2021-04-06 04:20:36 +11:00
case 'h': help(0); break;
case 'v': verbosity++; break;
}
}
if (2 != argc-optind) {
fprintf(stderr, "error: %s need two filenames\n", argv[0]);
exit(1);
}
srcname = argv[optind];
dstname = argv[optind+1];
2021-04-06 05:49:01 +11:00
if (verbosity) {
fprintf(stderr, "%s: src: %s dst: %s\n", argv[0],
2021-04-06 04:20:36 +11:00
srcname, dstname);
2021-04-06 05:49:01 +11:00
}
2021-04-06 04:20:36 +11:00
2021-04-06 05:49:01 +11:00
foo = faire_un_halfsize(srcname, dstname, grayed);
2021-04-28 09:21:45 +11:00
if (foo) {
fprintf(stderr, "in %s: make halfsize give a %d\n", argv[0], foo);
exit(1);
}
2021-04-06 04:20:36 +11:00
return 0;
}
/* ------------------------------------------------------------- */