better cumulator

This commit is contained in:
tth 2020-09-25 11:43:25 +02:00
parent ac35780f47
commit beedc2e190
4 changed files with 27 additions and 7 deletions

View File

@ -3,7 +3,7 @@
* ugly code from tTh * ugly code from tTh
*/ */
#define FIMG_VERSION 106 #define FIMG_VERSION 107
/* /*
* in memory descriptor * in memory descriptor

View File

@ -70,7 +70,7 @@ for (foo=0; foo<nbb; foo++) {
(src->R[foo] + src->G[foo] + src->B[foo]) / 3.0; (src->R[foo] + src->G[foo] + src->B[foo]) / 3.0;
} }
return -99; return 0;
} }
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */

View File

@ -19,12 +19,12 @@ int foo, numbers[3];
foo = fimg_fileinfos(path, numbers); foo = fimg_fileinfos(path, numbers);
if (foo) { if (foo) {
#if DEBUG_LEVEL #if DEBUG_LEVEL
fprintf(stderr, "%s -> err %d\n", path, foo); fprintf(stderr, "fileinfo of '%s' -> err %d\n", path, foo);
#endif #endif
return foo; return foo;
} }
fprintf(stderr, "%s \t%d x %d\n",path, numbers[0], numbers[1]); if (verbosity) fprintf(stderr, "%-20s %d x %d\n",path, numbers[0], numbers[1]);
if (FIMG_TYPE_RGB != numbers[2]) { if (FIMG_TYPE_RGB != numbers[2]) {
fprintf(stderr, "file %s, %d : bad type\n", path, numbers[2]); fprintf(stderr, "file %s, %d : bad type\n", path, numbers[2]);
@ -39,6 +39,7 @@ void help(int v)
puts("cumulator options :"); puts("cumulator options :");
puts("\t-v\tincrease verbosity"); puts("\t-v\tincrease verbosity");
puts("\t-o\tname of output file"); puts("\t-o\tname of output file");
puts("\t-g\tconvert to gray level");
if (verbosity) { puts(""); fimg_print_version(1); } if (verbosity) { puts(""); fimg_print_version(1); }
exit(0); exit(0);
@ -48,14 +49,17 @@ int main(int argc, char *argv[])
{ {
int foo, idx; int foo, idx;
int opt; int opt;
int to_gray = 0;
char *output_file = "out.fimg"; char *output_file = "out.fimg";
FloatImg accu, temp; FloatImg accu, temp;
int src_loaded = 0; int src_loaded = 0;
g_width = g_height = 0; g_width = g_height = 0;
while ((opt = getopt(argc, argv, "ho:v")) != -1) { while ((opt = getopt(argc, argv, "gho:v")) != -1) {
switch(opt) { switch(opt) {
case 'g': to_gray = 1; break;
case 'h': help(0); break; case 'h': help(0); break;
case 'o': output_file = optarg; break; case 'o': output_file = optarg; break;
case 'v': verbosity++; break; case 'v': verbosity++; break;
@ -73,10 +77,14 @@ fprintf(stderr, "argc = %d, optind = %d\n", argc, optind);
for (idx=optind; idx<argc; idx++) { for (idx=optind; idx<argc; idx++) {
#if DEBUG_LEVEL
fprintf(stderr, "%5d %s\n", idx, argv[idx]); fprintf(stderr, "%5d %s\n", idx, argv[idx]);
#endif
foo = testfile(argv[idx]); foo = testfile(argv[idx]);
if (foo) {
fprintf(stderr, "testfile %s -> %d\n", argv[idx],foo); fprintf(stderr, "testfile %s -> %d\n", argv[idx],foo);
}
if ( ! src_loaded ) { if ( ! src_loaded ) {
foo = fimg_create_from_dump(argv[idx], &accu); foo = fimg_create_from_dump(argv[idx], &accu);
@ -85,12 +93,24 @@ for (idx=optind; idx<argc; idx++) {
} }
else { else {
foo = fimg_load_from_dump(argv[idx], &temp); foo = fimg_load_from_dump(argv[idx], &temp);
if (foo) {
fprintf(stderr, "load from dump -> %d\n", foo);
exit(1);
}
fimg_add_2(&temp, &accu); fimg_add_2(&temp, &accu);
} }
} }
if (to_gray) {
foo = fimg_desaturate(&accu, &accu, 0);
if (foo) {
fprintf(stderr, "desaturate: error %d\n", foo);
}
}
foo = fimg_dump_to_file(&accu, output_file, 0); foo = fimg_dump_to_file(&accu, output_file, 0);
return 0; return 0;

View File

@ -37,7 +37,7 @@ D=" 800 600 "
./mkfimg -v -t vdeg vdeg.fimg $D ./mkfimg -v -t vdeg vdeg.fimg $D
./mkfimg -v -t drand48 rand.fimg $D ./mkfimg -v -t drand48 rand.fimg $D
./cumulfimgs -vv -o foo.fimg hdeg.fimg rand.fimg vdeg.fimg ./cumulfimgs -v -g -o foo.fimg hdeg.fimg rand.fimg vdeg.fimg
} }
# ----------------------------------------------------- # -----------------------------------------------------