diff options
author | Lars-Dominik Braun <lars@6xq.net> | 2015-03-22 18:05:03 +0100 |
---|---|---|
committer | Lars-Dominik Braun <lars@6xq.net> | 2015-05-02 21:36:45 +0200 |
commit | 3b2c6c5667584b8bd71f3a3c9811e53a1650e2a4 (patch) | |
tree | c6d9f17cbc3ab0fceffae5e36aea2c2357cbbc58 | |
parent | b2cce683d3c84780fd31b16e26b6b85666da2872 (diff) | |
download | pucket-3b2c6c5667584b8bd71f3a3c9811e53a1650e2a4.tar.gz pucket-3b2c6c5667584b8bd71f3a3c9811e53a1650e2a4.tar.bz2 pucket-3b2c6c5667584b8bd71f3a3c9811e53a1650e2a4.zip |
Add interpolation
-rw-r--r-- | flam3.c | 6 | ||||
-rw-r--r-- | flam3.h | 4 | ||||
-rw-r--r-- | interpolation.c | 13 | ||||
-rw-r--r-- | main.c | 94 | ||||
-rw-r--r-- | parser.c | 8 |
5 files changed, 73 insertions, 52 deletions
@@ -341,7 +341,6 @@ void flam3_interpolate(flam3_genome cps[], int ncps, result->time = time; result->interpolation = flam3_interpolation_linear; result->interpolation_type = cpi[0].interpolation_type; - result->palette_interpolation = flam3_palette_interpolation_hsv; if (!smoothflag) { flam3_interpolate_n(result, 2, cpi, c, stagger); @@ -782,7 +781,6 @@ void clear_cp(flam3_genome *cp, int default_flag) { cp->brightness = 4.0; cp->pixels_per_unit = 50; cp->interpolation = flam3_interpolation_linear; - cp->palette_interpolation = flam3_palette_interpolation_hsv; if (default_flag==flam3_defaults_on) { /* If defaults are on, set to reasonable values */ @@ -1018,10 +1016,6 @@ void flam3_print(FILE *f, flam3_genome *cp, char *extra_attributes) { else if (flam3_inttype_older == cp->interpolation_type) fprintf(f, " interpolation_type=\"older\""); - - if (flam3_palette_interpolation_hsv != cp->palette_interpolation) - fprintf(f, " palette_interpolation=\"sweep\""); - if (extra_attributes) fprintf(f, " %s", extra_attributes); @@ -46,9 +46,6 @@ extern char *flam3_variation_names[]; #define flam3_inttype_compat 2 /* Linear and old behaviour */ #define flam3_inttype_older 3 /* rotate padded xforms */ -#define flam3_palette_interpolation_hsv 0 -#define flam3_palette_interpolation_sweep 1 - #define flam3_max_action_length 10000 typedef enum { @@ -422,7 +419,6 @@ typedef struct { double time; int interpolation; int interpolation_type; - int palette_interpolation; int num_xforms; int final_xform_index; int final_xform_enable; diff --git a/interpolation.c b/interpolation.c index f161b4b..600d1d8 100644 --- a/interpolation.c +++ b/interpolation.c @@ -366,7 +366,7 @@ void flam3_interpolate_n(flam3_genome *result, int ncp, flam3_genome *cpi, double *c, double stagger) { int i, j, k, numstd; - if (flam3_palette_interpolation_hsv == cpi[0].palette_interpolation) { + /* HSV palette interpolation */ for (i = 0; i < cpi[0].palette.count; i++) { double4 s, t; @@ -393,17 +393,6 @@ void flam3_interpolate_n(flam3_genome *result, int ncp, ret_color[2], s[3] }); } - } else { - /* XXX: broken */ - assert (0); -#if 0 - /* Sweep - not the best option for float indices */ - for (i = 0; i < cpi[0].palette.count; i++) { - j = (i < (cpi[j].palette.count * c[0])) ? 0 : 1; - palette_add (&result->palette, cpi[j].palette.color[i]); - } -#endif - } result->symmetry = 0; result->palette_mode = cpi[0].palette_mode; @@ -249,7 +249,6 @@ static void do_random (const random_arguments * const arguments) { palette_copy (p, &genome.palette); palette_rotate_hue (&genome.palette, genome.hue_rotation); genome.interpolation = flam3_interpolation_linear; - genome.palette_interpolation = flam3_palette_interpolation_hsv; genome.rotate = rand_d01 (&rc) * 360.0; unsigned int nxforms = rand_mod (&rc, arguments->max_xforms) + 1; @@ -427,32 +426,65 @@ static void do_cross (const cross_arguments * const arguments) { static void do_improvecolors () { flam3_improve_colors(&cp_orig, 100, 0, 10, &rc); } +#endif -static void do_interpolate () { - for (ftime = first_frame; ftime <= last_frame; ftime += 1) { - iscp=0; - for (i=0;i<ncp;i++) { - if ( ftime==cp[i].time ) { - flam3_copy(&interpolated, &(cp[i]) ); - iscp=1; - } +typedef struct { + float time; +} interpolate_arguments; + +static error_t parse_interpolate_opt (int key, char *arg, + struct argp_state * const state) { + interpolate_arguments * const arguments = state->input; + switch (key) { + case 't': { + assert (arg != NULL); + float i = atof (arg); + if (i >= 0.0 && i <= 1.0) { + arguments->time = i; + } else { + argp_error (state, "Time must be between 0 and 1"); + } + break; } - if (iscp==0) { - flam3_interpolate(cp, ncp, (double)ftime, stagger, &interpolated); - for (i=0;i<ncp;i++) { - if ( ftime==cp[i].time-1 ) { - iscp=1; - } + + case ARGP_KEY_ARG: + if (state->arg_num > 0) { + return ARGP_ERR_UNKNOWN; } - if (iscp==0) - interpolated.interpolation_type = flam3_inttype_linear; - } + break; - if (templ) flam3_apply_template(&interpolated, templ); - gprint(&interpolated, 1); + case ARGP_KEY_END: + break; + + default: + return ARGP_ERR_UNKNOWN; + break; } + + return 0; +} + +static void do_interpolate (const interpolate_arguments * const arguments) { + randctx rc; + + rand_seed(&rc); + + int ncps; + flam3_genome * const cps = flam3_parse_xml2 (STDIN_FILENO, + flam3_defaults_on, &ncps, &rc); + if (cps == NULL) { + fprintf(stderr,"error reading genomes from file\n"); + exit(1); + } + assert (ncps == 2); + cps[0].time = 0.0; + cps[1].time = 1.0; + + flam3_genome genome_out; + flam3_interpolate (cps, 2, arguments->time, 0, &genome_out); + + print_genome (&genome_out); } -#endif static void show_help (const char * const argv0) { const char *progname = strrchr (argv0, (int) '/'); @@ -463,10 +495,11 @@ static void show_help (const char * const argv0) { } fprintf (stderr, "Usage: %s cross [OPTION...]\n" + " Or: %s interpolate [OPTION...]\n" " Or: %s mutate [OPTION...]\n" " Or: %s random [OPTION...]\n" " Or: %s render [OPTION...]\n", - progname, progname, progname, progname); + progname, progname, progname, progname, progname); } int main (int argc, char **argv) { @@ -494,6 +527,23 @@ int main (int argc, char **argv) { argp_parse (&argp, argc, argv, 0, NULL, &arguments); do_cross (&arguments); + } else if (streq (command, "interpolate")) { + const struct argp_option options[] = { + {"time", 't', "float", OPTION_ARG_OPTIONAL, "Time step (0.5)" }, + { 0 }, + }; + const char doc[] = PACKAGE "-interpolate -- fractal flame interpolation"; + const struct argp argp = { + .options = options, .parser = parse_interpolate_opt, + .args_doc = NULL, .doc = doc, .children = NULL + }; + + interpolate_arguments arguments = { + .time = 0.5, + }; + + argp_parse (&argp, argc, argv, 0, NULL, &arguments); + do_interpolate (&arguments); #if 0 } else if (streq (command, "mutate")) { const struct argp_option options[] = { @@ -318,14 +318,6 @@ int parse_flame_element(xmlNode *flame_node, flam3_genome *loc_current_cp, } else { fprintf(stderr, "warning: unrecognized interpolation type %s.\n", att_str); } - } else if (!xmlStrcmp(cur_att->name, (const xmlChar *)"palette_interpolation")) { - if (!strcmp("hsv", att_str)) { - cp->palette_interpolation = flam3_palette_interpolation_hsv; - } else if (!strcmp("sweep", att_str)) { - cp->palette_interpolation = flam3_palette_interpolation_sweep; - } else { - fprintf(stderr, "warning: unrecognized palette interpolation type %s.\n", att_str); - } } else if (!xmlStrcmp(cur_att->name, (const xmlChar *)"interpolation_space") || !xmlStrcmp(cur_att->name, (const xmlChar *)"interpolation_type")) { |