2021-04-06 04:20:36 +11:00
|
|
|
/*
|
2021-05-06 04:29:15 +11:00
|
|
|
* halfsizing an fimg picture.
|
2021-04-06 04:20:36 +11:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h> /* pour getopt */
|
2021-05-20 18:31:28 +11:00
|
|
|
#include <stdint.h>
|
2021-04-06 04:20:36 +11:00
|
|
|
#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;
|
|
|
|
}
|
|
|
|
|
2021-05-06 04:29:15 +11:00
|
|
|
return 0;
|
2021-04-06 04:20:36 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------- */
|
|
|
|
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");
|
2022-07-06 19:27:55 +11:00
|
|
|
fimg_print_version(u);
|
2021-04-10 04:23:12 +11:00
|
|
|
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;
|
2023-05-29 18:06:57 +11:00
|
|
|
default: exit(1);
|
2021-04-06 04:20:36 +11: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-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;
|
|
|
|
}
|
|
|
|
/* ------------------------------------------------------------- */
|