2020-09-22 00:43:21 +02:00
|
|
|
/*
|
|
|
|
* This thing is just a mess !
|
|
|
|
*/
|
2019-07-03 18:51:42 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "../floatimg.h"
|
|
|
|
|
|
|
|
int verbosity;
|
2019-07-16 00:19:59 +02:00
|
|
|
|
|
|
|
int g_width, g_height;
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
int testfile(char *path)
|
|
|
|
{
|
|
|
|
int foo, numbers[3];
|
|
|
|
|
|
|
|
foo = fimg_fileinfos(path, numbers);
|
|
|
|
if (foo) {
|
|
|
|
#if DEBUG_LEVEL
|
2020-09-25 11:43:25 +02:00
|
|
|
fprintf(stderr, "fileinfo of '%s' -> err %d\n", path, foo);
|
2019-07-16 00:19:59 +02:00
|
|
|
#endif
|
|
|
|
return foo;
|
|
|
|
}
|
|
|
|
|
2020-09-25 11:43:25 +02:00
|
|
|
if (verbosity) fprintf(stderr, "%-20s %d x %d\n",path, numbers[0], numbers[1]);
|
2019-07-16 00:19:59 +02:00
|
|
|
|
2020-09-22 00:43:21 +02:00
|
|
|
if (FIMG_TYPE_RGB != numbers[2]) {
|
2019-07-16 00:19:59 +02:00
|
|
|
fprintf(stderr, "file %s, %d : bad type\n", path, numbers[2]);
|
|
|
|
return -7;
|
|
|
|
}
|
|
|
|
|
2020-09-22 00:43:21 +02:00
|
|
|
return 0;
|
2019-07-16 00:19:59 +02:00
|
|
|
}
|
2019-07-03 18:51:42 +02:00
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
void help(int v)
|
|
|
|
{
|
2020-09-22 00:43:21 +02:00
|
|
|
puts("cumulator options :");
|
2019-07-03 18:51:42 +02:00
|
|
|
puts("\t-v\tincrease verbosity");
|
|
|
|
puts("\t-o\tname of output file");
|
2020-09-25 11:43:25 +02:00
|
|
|
puts("\t-g\tconvert to gray level");
|
2019-07-03 18:51:42 +02:00
|
|
|
|
|
|
|
if (verbosity) { puts(""); fimg_print_version(1); }
|
2020-09-22 00:43:21 +02:00
|
|
|
exit(0);
|
2019-07-03 18:51:42 +02:00
|
|
|
}
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2019-07-16 00:19:59 +02:00
|
|
|
int foo, idx;
|
2019-07-03 18:51:42 +02:00
|
|
|
int opt;
|
2020-09-25 11:43:25 +02:00
|
|
|
|
|
|
|
int to_gray = 0;
|
2020-09-22 00:43:21 +02:00
|
|
|
char *output_file = "out.fimg";
|
|
|
|
FloatImg accu, temp;
|
|
|
|
int src_loaded = 0;
|
2019-07-03 18:51:42 +02:00
|
|
|
|
2019-07-16 00:19:59 +02:00
|
|
|
g_width = g_height = 0;
|
|
|
|
|
2020-09-25 11:43:25 +02:00
|
|
|
while ((opt = getopt(argc, argv, "gho:v")) != -1) {
|
2019-07-03 18:51:42 +02:00
|
|
|
switch(opt) {
|
2020-09-25 11:43:25 +02:00
|
|
|
case 'g': to_gray = 1; break;
|
2019-07-03 18:51:42 +02:00
|
|
|
case 'h': help(0); break;
|
|
|
|
case 'o': output_file = optarg; break;
|
|
|
|
case 'v': verbosity++; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-22 00:43:21 +02:00
|
|
|
if (verbosity) fprintf(stderr, "------ cumulfimgs ------\n");
|
2019-07-16 00:19:59 +02:00
|
|
|
#if DEBUG_LEVEL
|
|
|
|
fprintf(stderr, "argc = %d, optind = %d\n", argc, optind);
|
|
|
|
#endif
|
|
|
|
|
2020-09-22 00:43:21 +02:00
|
|
|
// foo = testfile(output_file);
|
|
|
|
// fprintf(stderr, "Output %s -> %d\n", output_file, foo);
|
2019-07-16 00:19:59 +02:00
|
|
|
|
|
|
|
|
|
|
|
for (idx=optind; idx<argc; idx++) {
|
|
|
|
|
2020-09-25 11:43:25 +02:00
|
|
|
#if DEBUG_LEVEL
|
2019-07-16 00:19:59 +02:00
|
|
|
fprintf(stderr, "%5d %s\n", idx, argv[idx]);
|
2020-09-25 11:43:25 +02:00
|
|
|
#endif
|
2019-07-16 00:19:59 +02:00
|
|
|
|
|
|
|
foo = testfile(argv[idx]);
|
2020-09-25 11:43:25 +02:00
|
|
|
if (foo) {
|
|
|
|
fprintf(stderr, "testfile %s -> %d\n", argv[idx],foo);
|
|
|
|
}
|
2019-07-16 00:19:59 +02:00
|
|
|
|
2020-09-22 00:43:21 +02:00
|
|
|
if ( ! src_loaded ) {
|
|
|
|
foo = fimg_create_from_dump(argv[idx], &accu);
|
|
|
|
fimg_clone(&accu, &temp, 0);
|
|
|
|
src_loaded = 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
foo = fimg_load_from_dump(argv[idx], &temp);
|
2020-09-25 11:43:25 +02:00
|
|
|
if (foo) {
|
|
|
|
fprintf(stderr, "load from dump -> %d\n", foo);
|
|
|
|
exit(1);
|
|
|
|
}
|
2020-09-22 00:43:21 +02:00
|
|
|
fimg_add_2(&temp, &accu);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-07-16 00:19:59 +02:00
|
|
|
}
|
|
|
|
|
2020-09-25 11:43:25 +02:00
|
|
|
if (to_gray) {
|
|
|
|
|
|
|
|
foo = fimg_desaturate(&accu, &accu, 0);
|
|
|
|
if (foo) {
|
|
|
|
fprintf(stderr, "desaturate: error %d\n", foo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-22 00:43:21 +02:00
|
|
|
foo = fimg_dump_to_file(&accu, output_file, 0);
|
|
|
|
|
2019-07-03 18:51:42 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* --------------------------------------------------------------------- */
|