forked from tTh/FloatImg
119 lines
2.7 KiB
C
119 lines
2.7 KiB
C
|
/*
|
||
|
* This thing is just a mess !
|
||
|
* ***************************
|
||
|
*/
|
||
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <unistd.h>
|
||
|
#include <stdint.h>
|
||
|
|
||
|
#include "../floatimg.h"
|
||
|
|
||
|
int verbosity; // nasty global var.
|
||
|
|
||
|
/* --------------------------------------------------------------------- */
|
||
|
/* nouveau ~ 2 octobre 2022 */
|
||
|
int extractor(char *srcname, char *dstname, FimgArea51 *rect)
|
||
|
{
|
||
|
FloatImg src, dst;
|
||
|
int foo;
|
||
|
|
||
|
fprintf(stderr, ">>> %s ( %s %s %p )\n", __func__, srcname, dstname, rect);
|
||
|
|
||
|
if (verbosity) {
|
||
|
print_rectangle((char *)__func__, rect);
|
||
|
}
|
||
|
|
||
|
foo = fimg_create_from_dump(srcname, &src);
|
||
|
if (foo) {
|
||
|
fprintf(stderr, "%s: load %s from dump --> %d\n", __func__,
|
||
|
srcname, foo);
|
||
|
return foo;
|
||
|
}
|
||
|
|
||
|
foo = fimg_create(&dst, rect->w, rect->h, 3);
|
||
|
if (foo) {
|
||
|
fprintf(stderr, "%s: fimg create dst --> %d\n", __func__, foo);
|
||
|
return foo;
|
||
|
}
|
||
|
|
||
|
/* REAL operation was here ! */
|
||
|
foo = fimg_extractor(&src, &dst, rect);
|
||
|
if (foo) {
|
||
|
fprintf(stderr, "%s: fimg extractor --> %d\n", __func__, foo);
|
||
|
#ifdef MUST_ABORT
|
||
|
abort(); // kill me hardly !
|
||
|
#endif
|
||
|
return foo;
|
||
|
}
|
||
|
|
||
|
// debug code XXX (void)fimg_save_as_pnm(&dst, "f.pnm", 0);
|
||
|
|
||
|
foo = fimg_dump_to_file(&dst, dstname, 0);
|
||
|
if (foo) {
|
||
|
fprintf(stderr, "%s: dumping datas to '%s' give us a %d\n",
|
||
|
__func__, dstname, foo);
|
||
|
return foo;
|
||
|
}
|
||
|
|
||
|
return 0;
|
||
|
}
|
||
|
/* --------------------------------------------------------------------- */
|
||
|
void help(void)
|
||
|
{
|
||
|
|
||
|
printf("-- Fimg Extractor -- lib v%d -- %s %s\n", FIMG_VERSION,
|
||
|
__DATE__, __TIME__);
|
||
|
|
||
|
puts("usage:\n\tfimgextract [options] source.fimg width,height,xpos,ypos");
|
||
|
puts("options:");
|
||
|
puts("\t-o out.fimg\tname the output file");
|
||
|
puts("\t-v\t\tmake be a blabla box");
|
||
|
puts("\t-x\t\tenable crashy feature");
|
||
|
exit(0);
|
||
|
}
|
||
|
/* --------------------------------------------------------------------- */
|
||
|
|
||
|
int main(int argc, char *argv[])
|
||
|
{
|
||
|
int foo, idx;
|
||
|
int opt;
|
||
|
int experiment = 0;
|
||
|
FimgArea51 area;
|
||
|
char *output_file = "out.fimg";
|
||
|
|
||
|
while ((opt = getopt(argc, argv, "ho:vx")) != -1) {
|
||
|
switch(opt) {
|
||
|
case 'h': help(); break;
|
||
|
case 'o': output_file = optarg; break;
|
||
|
case 'v': verbosity++; break;
|
||
|
case 'x': experiment++; break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
fprintf(stderr, "argc = %d optind = %d\n", argc, optind);
|
||
|
for (idx=optind; idx<argc; idx++) {
|
||
|
fprintf(stderr, " %5d %s\n", idx, argv[idx]);
|
||
|
}
|
||
|
|
||
|
if (argc==optind) {
|
||
|
fprintf(stderr, "wuh ?\n");
|
||
|
exit(0);
|
||
|
}
|
||
|
|
||
|
foo = parse_rectangle(argv[argc-1], &area, 0);
|
||
|
if (4 != foo) {
|
||
|
fprintf(stderr, "%s: parse_rectangle --> %d\n", argv[0], foo);
|
||
|
exit(1);
|
||
|
}
|
||
|
|
||
|
foo = extractor(argv[argc-2], output_file, &area);
|
||
|
if (foo) {
|
||
|
fprintf(stderr, "%s: extractor --> %d\n", __func__, foo);
|
||
|
exit(1);
|
||
|
}
|
||
|
|
||
|
return 0;
|
||
|
}
|
||
|
/* --------------------------------------------------------------------- */
|