FloatImg/tools/fimghalfsize.c

99 lines
1.9 KiB
C
Raw Normal View History

2021-04-05 19:20:36 +02:00
/*
2021-05-05 19:29:15 +02:00
* halfsizing an fimg picture.
2021-04-05 19:20:36 +02:00
*/
#include <stdio.h>
#include <unistd.h> /* pour getopt */
2021-05-20 09:31:28 +02:00
#include <stdint.h>
2021-04-05 19:20:36 +02:00
#include <stdlib.h>
2021-04-05 19:26:10 +02:00
#include <string.h>
2021-04-05 19:20:36 +02:00
#include "../floatimg.h"
int verbosity;
/* ------------------------------------------------------------- */
2021-04-05 20:49:01 +02:00
int faire_un_halfsize(char *iname, char *oname, int to_gray)
2021-04-05 19:20:36 +02: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-09 19:23:12 +02:00
foo = fimg_halfsize_1(&src, &dst, 0);
2021-04-05 19:20:36 +02:00
if (foo) {
2021-04-09 19:23:12 +02:00
fprintf(stderr, "halfize 1 fail -> %d\n", foo);
2021-04-05 19:20:36 +02:00
return -1;
}
2021-04-05 20:49:01 +02:00
if (to_gray) {
foo = fimg_to_gray(&dst);
2021-04-09 19:23:12 +02:00
/* and ? */
2021-04-05 20:49:01 +02:00
}
2021-04-05 19:20:36 +02:00
foo = fimg_dump_to_file(&dst, oname, 0);
if (foo) {
fprintf(stderr, "save to '%s' -> %d\n", oname, foo);
return -1;
}
2021-05-05 19:29:15 +02:00
return 0;
2021-04-05 19:20:36 +02:00
}
/* ------------------------------------------------------------- */
void help(int u)
{
2021-04-09 19:23:12 +02:00
puts("Usage:\n\tfimghalfsize [options] in.fimg out.fimg");
puts("Options:");
puts("\t-g\tconvert output to gray");
2022-07-06 10:27:55 +02:00
fimg_print_version(u);
2021-04-09 19:23:12 +02:00
exit(0);
2021-04-05 19:20:36 +02:00
}
/* ------------------------------------------------------------- */
int main(int argc, char *argv[])
{
2021-04-05 20:49:01 +02:00
int foo, opt;
2021-04-05 19:20:36 +02:00
char *srcname = "";
char *dstname = "out.fimg";
2021-04-05 20:49:01 +02:00
int grayed = 0;
2021-04-05 19:20:36 +02:00
2021-04-05 20:49:01 +02:00
while ((opt = getopt(argc, argv, "ghv")) != -1) {
2021-04-05 19:20:36 +02:00
switch(opt) {
2021-04-05 20:49:01 +02:00
case 'g': grayed = 1; break;
2021-04-05 19:20:36 +02:00
case 'h': help(0); break;
case 'v': verbosity++; break;
2023-05-29 09:06:57 +02:00
default: exit(1);
2021-04-05 19:20:36 +02:00
}
}
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-05 20:49:01 +02:00
if (verbosity) {
fprintf(stderr, "%s: src: %s dst: %s\n", argv[0],
2021-04-05 19:20:36 +02:00
srcname, dstname);
2021-04-05 20:49:01 +02:00
}
2021-04-05 19:20:36 +02:00
2021-04-05 20:49:01 +02:00
foo = faire_un_halfsize(srcname, dstname, grayed);
2021-04-28 00:21:45 +02:00
if (foo) {
fprintf(stderr, "in %s: make halfsize give a %d\n", argv[0], foo);
exit(1);
}
2021-04-05 19:20:36 +02:00
return 0;
}
/* ------------------------------------------------------------- */