forked from tTh/FloatImg
added a new tool : fimgfx
This commit is contained in:
@@ -9,7 +9,7 @@ DEPS = ../floatimg.h ../libfloatimg.a Makefile
|
||||
# ----------
|
||||
|
||||
all: fimg2pnm mkfimg png2fimg fimgstats fimg2png \
|
||||
addpnm2fimg cumulfimgs fimgops
|
||||
addpnm2fimg cumulfimgs fimgops fimgfx
|
||||
|
||||
fimgstats: fimgstats.c $(DEPS)
|
||||
gcc $(COPT) $< ../libfloatimg.a -o $@
|
||||
@@ -23,6 +23,9 @@ mkfimg: mkfimg.c $(DEPS)
|
||||
fimgops: fimgops.c $(DEPS)
|
||||
gcc $(COPT) $< ../libfloatimg.a -o $@
|
||||
|
||||
fimgfx: fimgfx.c $(DEPS)
|
||||
gcc $(COPT) $< ../libfloatimg.a -o $@
|
||||
|
||||
fimg2pnm: fimg2pnm.c $(DEPS)
|
||||
gcc $(COPT) $< ../libfloatimg.a -o $@
|
||||
|
||||
|
||||
168
tools/fimgfx.c
Normal file
168
tools/fimgfx.c
Normal file
@@ -0,0 +1,168 @@
|
||||
/*
|
||||
FIMGFX
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "../floatimg.h"
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
int verbosity;
|
||||
float global_fvalue;
|
||||
|
||||
typedef struct {
|
||||
char *name;
|
||||
int id;
|
||||
int nbarg;
|
||||
} Fx;
|
||||
|
||||
enum fxid { Fx_cos01, Fx_pow2, Fx_sqrt };
|
||||
|
||||
Fx fx_list[] = {
|
||||
{ "cos01", Fx_cos01, 0 },
|
||||
{ "pow2", Fx_pow2, 0 },
|
||||
{ "sqrt", Fx_sqrt, 0 },
|
||||
{ NULL, 0, 0 }
|
||||
};
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
int lookup_fx(char *txt)
|
||||
{
|
||||
Fx *fx;
|
||||
int n;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( '%s' )\n", __func__, txt);
|
||||
#endif
|
||||
|
||||
for (n=0, fx=fx_list; fx->name; fx++, n++) {
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "-> %3d %s\n", n, fx->name);
|
||||
#endif
|
||||
if (!strcmp(fx->name, txt)) {
|
||||
return n;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
static void help(int lvl)
|
||||
{
|
||||
|
||||
printf("fimg special effects (%d)\n", lvl);
|
||||
|
||||
|
||||
|
||||
exit(0);
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
int do_an_effect(char *sf, int act, char *df)
|
||||
{
|
||||
FloatImg src, dest;
|
||||
int foo;
|
||||
double maxval;
|
||||
|
||||
#if 1
|
||||
fprintf(stderr, ">>> %s ( '%s' %d '%s' )\n", __func__,
|
||||
sf, act, df);
|
||||
#endif
|
||||
|
||||
foo = fimg_create_from_dump(sf, &src);
|
||||
if (foo) {
|
||||
fprintf(stderr, "err load '%s' : %d\n", sf, foo);
|
||||
return foo;
|
||||
}
|
||||
|
||||
maxval = (double)fimg_get_maxvalue(&src);
|
||||
|
||||
foo = fimg_clone(&src, &dest, 0);
|
||||
if (foo) {
|
||||
fprintf(stderr, "err clone %p : %d\n", &src, foo);
|
||||
return foo;
|
||||
}
|
||||
|
||||
switch (act) {
|
||||
case Fx_cos01:
|
||||
fimg_cos_01(&src, &dest, maxval); break;
|
||||
case Fx_pow2:
|
||||
fimg_power_2(&src, &dest, maxval); break;
|
||||
case Fx_sqrt:
|
||||
fimg_square_root(&src, &dest, maxval); break;
|
||||
|
||||
default:
|
||||
fprintf(stderr, "*** %s : %d is bad action\n", __func__, act);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
foo = fimg_dump_to_file(&dest, df, 0);
|
||||
if (foo) {
|
||||
fprintf(stderr, "dumping datas to file give us a %d\n", foo);
|
||||
return foo;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int foo, opt, action;
|
||||
int nba;
|
||||
char *operator;
|
||||
|
||||
char *srcname = "";
|
||||
char *dstname = "out.fimg";
|
||||
|
||||
while ((opt = getopt(argc, argv, "hk:v")) != -1) {
|
||||
switch(opt) {
|
||||
case 'h': help(0); break;
|
||||
case 'k': global_fvalue = atof(optarg); break;
|
||||
case 'v': verbosity++; break;
|
||||
}
|
||||
}
|
||||
|
||||
#if 1
|
||||
fprintf(stderr, "argc %d optind %d\n", argc, optind);
|
||||
for (foo=0; foo<argc; foo++)
|
||||
fprintf(stderr, "%3d %c %s\n", foo, foo==optind?'*':' ', argv[foo]);
|
||||
#endif
|
||||
|
||||
if (3 > argc-optind) {
|
||||
fprintf(stderr, "%s need some arguments...\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
operator = argv[optind];
|
||||
action = lookup_fx(operator);
|
||||
if (action < 0) {
|
||||
fprintf(stderr, "garbage found in opcode field : %s\n", operator);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (verbosity) {
|
||||
fprintf(stderr, "global fvalue %f\n", global_fvalue);
|
||||
fprintf(stderr, "action %d\n", action);
|
||||
fprintf(stderr, "verbosity %d\n", verbosity);
|
||||
}
|
||||
|
||||
if ((nba=fx_list[action].nbarg)) {
|
||||
fprintf(stderr, "action '%s' need %d arg\n", operator, nba);
|
||||
}
|
||||
|
||||
srcname = argv[optind+1];
|
||||
dstname = argv[optind+2];
|
||||
fprintf(stderr, "%s ==> %s\n", srcname, dstname);
|
||||
|
||||
foo = do_an_effect(srcname, action, dstname);
|
||||
fprintf(stderr, "do an effect -> %d\n", foo);
|
||||
|
||||
|
||||
fprintf(stderr, "\n%s [done]\n", argv[0]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* --------------------------------------------------------------------- */
|
||||
Reference in New Issue
Block a user