summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars-Dominik Braun <lars@6xq.net>2015-03-30 20:56:31 +0200
committerLars-Dominik Braun <lars@6xq.net>2015-05-02 21:36:45 +0200
commit83818b18a1fa1e8a00332489e31d346101b6fe9e (patch)
tree3ccd2826a1f8bb39c6b9e6f1d9f61eae520f8052
parenta7842df438eda518325138b2207c9a898171ba47 (diff)
downloadpucket-83818b18a1fa1e8a00332489e31d346101b6fe9e.tar.gz
pucket-83818b18a1fa1e8a00332489e31d346101b6fe9e.tar.bz2
pucket-83818b18a1fa1e8a00332489e31d346101b6fe9e.zip
Another massive cleanup
Drops unused functions, fixes function visibility.
-rw-r--r--flam3.c168
-rw-r--r--flam3.h50
-rw-r--r--img.h17
-rw-r--r--interpolation.c110
-rw-r--r--interpolation.h34
-rw-r--r--main.c5
-rw-r--r--math.h2
-rw-r--r--palettes.c71
-rw-r--r--palettes.h8
-rw-r--r--parser.c19
-rw-r--r--parser.h16
-rw-r--r--png.c3
-rw-r--r--private.h49
-rw-r--r--random.h1
-rw-r--r--rect.c68
-rw-r--r--rect.h20
-rw-r--r--variations.c7
-rw-r--r--variations.h7
18 files changed, 178 insertions, 477 deletions
diff --git a/flam3.c b/flam3.c
index da420e9..7d0a18d 100644
--- a/flam3.c
+++ b/flam3.c
@@ -15,7 +15,6 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "private.h"
#include "rect.h"
#include "img.h"
#include "build/config.h"
@@ -25,21 +24,15 @@
#include "palettes.h"
#include "random.h"
#include "math.h"
-#include <limits.h>
+#include <string.h>
#include <locale.h>
-#include <math.h>
-#ifdef HAVE_STDINT_H
-#include <stdint.h>
-#endif
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#include <errno.h>
#include <assert.h>
#define CHOOSE_XFORM_GRAIN 16384
#define CHOOSE_XFORM_GRAIN_M1 16383
+static void flam3_print_xform(FILE *f, flam3_xform *x, int final_flag, int numstd, double *chaos_row);
+
unsigned short *flam3_create_xform_distrib(flam3_genome *cp) {
/* Xform distrib is created in this function */
@@ -218,54 +211,6 @@ int flam3_iterate(flam3_genome *cp, int n, int fuse, const double4 in, double4 *
return(badvals);
}
-/* BY is angle in degrees */
-void flam3_rotate(flam3_genome *cp, double by, int interpolation_type) {
- int i;
- for (i = 0; i < cp->num_xforms; i++) {
- double r[2][2];
- double T[2][2];
- double U[2][2];
- double dtheta = by * 2.0 * M_PI / 360.0;
-
- /* Don't rotate xforms with > 0 animate values */
- if (cp->xform[i].animate == 0.0)
- continue;
-
- if (cp->xform[i].padding == 1) {
- if (interpolation_type == flam3_inttype_compat) {
- /* gen 202 era flam3 did not rotate padded xforms */
- continue;
- } else if (interpolation_type == flam3_inttype_older) {
- /* not sure if 198 era flam3 rotated padded xforms */
- continue;
- } else if (interpolation_type == flam3_inttype_linear) {
- /* don't rotate for prettier symsings */
- continue;
- } else if (interpolation_type == flam3_inttype_log) {
- /* Current flam3: what do we prefer? */
- //continue;
- }
- }
-
- /* Do NOT rotate final xforms */
- if (cp->final_xform_enable==1 && cp->final_xform_index==i)
- continue;
-
- r[1][1] = r[0][0] = cos(dtheta);
- r[0][1] = sin(dtheta);
- r[1][0] = -r[0][1];
- T[0][0] = cp->xform[i].c[0][0];
- T[1][0] = cp->xform[i].c[1][0];
- T[0][1] = cp->xform[i].c[0][1];
- T[1][1] = cp->xform[i].c[1][1];
- mult_matrix(r, T, U);
- cp->xform[i].c[0][0] = U[0][0];
- cp->xform[i].c[1][0] = U[1][0];
- cp->xform[i].c[0][1] = U[0][1];
- cp->xform[i].c[1][1] = U[1][1];
- }
-}
-
/*
* create a control point that interpolates between the control points
* passed in CPS. CPS must be sorted by time.
@@ -901,63 +846,6 @@ flam3_genome *flam3_parse_xml2(const int fd, int default_flag, int *ncps,
return loc_all_cp;
}
-void flam3_apply_template(flam3_genome *cp, flam3_genome *templ) {
-
- /* Check for invalid values - only replace those with valid ones */
- if (templ->zoom < 999999998)
- cp->zoom = templ->zoom;
- if (templ->width > 0) {
- /* preserving scale should be an option */
- cp->pixels_per_unit = cp->pixels_per_unit * templ->width / cp->width;
- cp->width = templ->width;
- }
- if (templ->height > 0)
- cp->height = templ->height;
- if (templ->gam_lin_thresh >= 0)
- cp->gam_lin_thresh = templ->gam_lin_thresh;
- if (templ->interpolation >= 0)
- cp->interpolation = templ->interpolation;
- if (templ->interpolation_type >= 0)
- cp->interpolation_type = templ->interpolation_type;
- if (templ->highlight_power >=0)
- cp->highlight_power = templ->highlight_power;
- if (templ->palette_mode >= 0)
- cp->palette_mode = templ->palette_mode;
-
-}
-
-char *flam3_print_to_string(flam3_genome *cp) {
-
- FILE *tmpflame;
- long stringbytes;
- char *genome_string;
-
- int using_tmpdir = 0;
- char tmpnam[256];
-
- tmpflame = tmpfile();
- if (NULL==tmpflame) {
- if (using_tmpdir == 0) {
- perror("opening temporary file");
- return (NULL);
- }
- }
- flam3_print(tmpflame,cp,NULL);
- stringbytes = ftell(tmpflame);
- fseek(tmpflame,0L, SEEK_SET);
- genome_string = (char *)calloc(stringbytes+1,1);
- if (stringbytes != fread(genome_string, 1, stringbytes, tmpflame)) {
- perror("reading string from temp file");
- }
- fclose(tmpflame);
-
- if (using_tmpdir)
- unlink(tmpnam);
-
- return(genome_string);
-}
-
-
void flam3_print(FILE *f, flam3_genome *cp, char *extra_attributes) {
int i,numstd;
@@ -1065,7 +953,7 @@ void flam3_print(FILE *f, flam3_genome *cp, char *extra_attributes) {
#define PRINTNON(p) do { if (x->p != 0.0) fprintf(f, #p "=\"%f\" ",x->p); } while(0)
-void flam3_print_xform(FILE *f, flam3_xform *x, int final_flag, int numstd, double *chaos_row) {
+static void flam3_print_xform(FILE *f, flam3_xform *x, int final_flag, int numstd, double *chaos_row) {
int blob_var=0,pdj_var=0,fan2_var=0,rings2_var=0,perspective_var=0;
int juliaN_var=0,juliaScope_var=0,radialBlur_var=0,pie_var=0,disc2_var=0;
@@ -1447,6 +1335,38 @@ static double round6(double x) {
return 1e-6*(int)(x+0.5);
}
+static int compare_xforms(const void *av, const void *bv) {
+ flam3_xform *a = (flam3_xform *) av;
+ flam3_xform *b = (flam3_xform *) bv;
+ double aa[2][2];
+ double bb[2][2];
+ double ad, bd;
+
+ aa[0][0] = a->c[0][0];
+ aa[0][1] = a->c[0][1];
+ aa[1][0] = a->c[1][0];
+ aa[1][1] = a->c[1][1];
+ bb[0][0] = b->c[0][0];
+ bb[0][1] = b->c[0][1];
+ bb[1][0] = b->c[1][0];
+ bb[1][1] = b->c[1][1];
+ ad = det_matrix(aa);
+ bd = det_matrix(bb);
+
+ if (a->color_speed > b->color_speed) return 1;
+ if (a->color_speed < b->color_speed) return -1;
+ if (a->color_speed) {
+ if (ad < 0) return -1;
+ if (bd < 0) return 1;
+ ad = atan2(a->c[0][0], a->c[0][1]);
+ bd = atan2(b->c[0][0], b->c[0][1]);
+ }
+
+ if (ad < bd) return -1;
+ if (ad > bd) return 1;
+ return 0;
+}
+
/* sym=2 or more means rotational
sym=1 means identity, ie no symmetry
sym=0 means pick a random symmetry (maybe none)
@@ -1538,22 +1458,6 @@ void flam3_add_symmetry(flam3_genome *cp, int sym, randctx * const rc) {
}
-void add_to_action(char *action, char *addtoaction) {
-
- /* action is a flam3_max_action_length array */
- if (action != NULL) {
-
- int alen = strlen(action);
- int addlen = strlen(addtoaction);
-
- if (alen+addlen < flam3_max_action_length)
- strcat(action,addtoaction);
- else
- fprintf(stderr,"action string too long, truncating...\n");
- }
-}
-
-
void flam3_cross(flam3_genome *cp0, flam3_genome *cp1, flam3_genome *out, int cross_mode, randctx *rc) {
int i,j, rb;
diff --git a/flam3.h b/flam3.h
index 46286a4..e816ba1 100644
--- a/flam3.h
+++ b/flam3.h
@@ -15,9 +15,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-
-#ifndef flam3_included
-#define flam3_included
+#pragma once
#include <stdio.h>
#include <libxml/parser.h>
@@ -30,10 +28,6 @@
#define flam3_name_len 64
-#include "vector.h"
-
-#include "random.h"
-
extern char *flam3_variation_names[];
#define flam3_nvariations 99
@@ -46,8 +40,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_max_action_length 10000
-
typedef enum {
PALETTE_MODE_STEP = 0,
PALETTE_MODE_LINEAR = 1,
@@ -153,33 +145,8 @@ typedef enum {
#define VAR_FLUX 97
#define VAR_MOBIUS 98
-typedef struct {
-
- double badvals;
- long int num_iters;
-
-} stat_struct;
-
-typedef struct {
-
- unsigned int width, height;
- int version;
- int id;
-
- /* There are 256 levels of gray to work with */
- double intensity_weight[256];
- unsigned int bin_size[256];
- unsigned int bin_offset[256];
-
- /* Pointer to newly allocated memory; we will be allocating */
- /* 2*w*h ushorts for this storage. The bin offset will */
- /* provide the starting point for a random selection from */
- /* (bin size) ordered pairs */
- unsigned short *rowcols;
-
-} flam3_image_store;
-
#include "vector.h"
+#include "random.h"
typedef struct xform {
double var[flam3_nvariations]; /* interp coefs between variations */
@@ -490,14 +457,10 @@ void flam3_interpolate(flam3_genome *genomes, int ngenomes, double time, double
/* print genome to given file with extra_attributes if not NULL */
void flam3_print(FILE *f, flam3_genome *g, char *extra_attributes);
-void flam3_print_xform(FILE *f, flam3_xform *x, int final_flag, int numstd, double *chaos_row);
-char *flam3_print_to_string(flam3_genome *cp);
void flam3_random(flam3_genome *cp, const unsigned int max_xform,
const palette_collection * const pc, randctx * const rc);
-void add_to_action(char *action, char *addtoaction);
-
void flam3_mutate(flam3_genome *cp, int mutate_mode, int *ivars, int ivars_n, int sym, double speed, const palette_collection * const pc, randctx *rc);
void flam3_cross(flam3_genome *cp0, flam3_genome *cp1, flam3_genome *out, int cross_mode, randctx *rc);
@@ -507,15 +470,8 @@ flam3_genome *flam3_parse_xml2(const int, int default_flag, int *ncps, randctx *
void flam3_add_symmetry(flam3_genome *cp, int sym, randctx * const rc);
void flam3_improve_colors(flam3_genome *g, int ntries, int change_palette, int color_resolution, const palette_collection * const pc, randctx * const rc);
-int flam3_colorhist(flam3_genome *cp, int num_batches, randctx *rc, double *hist);
int flam3_estimate_bounding_box(flam3_genome *g, double eps, int nsamples,
double *bmin, double *bmax, randctx *rc);
-void flam3_rotate(flam3_genome *g, double angle, int interp_type); /* angle in degrees */
-
-double flam3_dimension(flam3_genome *g, int ntries, int clip_to_camera);
-double flam3_lyapunov(flam3_genome *g, int ntries);
-
-void flam3_apply_template(flam3_genome *cp, flam3_genome *templ);
typedef struct {
double pixel_aspect_ratio; /* width over height of each pixel */
@@ -530,7 +486,6 @@ typedef struct {
int sub_batch_size;
} flam3_frame;
-
/* Motion function indices */
#define MOTION_SIN 1
#define MOTION_TRIANGLE 2
@@ -552,4 +507,3 @@ typedef struct {
#define CROSS_INTERPOLATE 1
#define CROSS_ALTERNATE 2
-#endif
diff --git a/img.h b/img.h
index 6bdf88b..385b3ac 100644
--- a/img.h
+++ b/img.h
@@ -15,23 +15,10 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#pragma once
#include <stdio.h>
#include "flam3.h"
-#define FLAM3_PNG_COM 8
+void write_png(FILE *file, void *image, int width, int height, int bpc);
-typedef struct {
-
- char *genome;
- char *badvals;
- char *numiters;
- char *rtime;
-
-} flam3_img_comments;
-
-
-void write_png(FILE *file, void *image, int width, int height, flam3_img_comments *fpc, int bpc);
-
-/* returns RGBA pixel array or NULL on failure */
-unsigned char *read_png(FILE *file, int *width, int *height);
diff --git a/interpolation.c b/interpolation.c
index a316116..aaa9145 100644
--- a/interpolation.c
+++ b/interpolation.c
@@ -20,39 +20,12 @@
#include <assert.h>
-double adjust_percentage(double in) {
+#define INTERP(x) do { result->x = 0.0; \
+ for (k = 0; k < ncp; k++) result->x += c[k] * cpi[k].x; } while(0)
- if (in==0.0)
- return(0.0);
- else
- return(pow(10.0, -log(1.0/in)/log(2)));
-
-}
-
-double motion_funcs(int funcnum, double timeval) {
-
- /* motion funcs should be cyclic, and equal to 0 at integral time values */
- /* abs peak values should be not be greater than 1 */
- if (funcnum==MOTION_SIN) {
- return (sin(2.0*M_PI*timeval));
- } else if (funcnum==MOTION_TRIANGLE) {
- double fr = fmod(timeval,1.0);
-
- if (fr<0) fr+= 1.0;
-
- if (fr<=.25)
- fr = 4.0 * fr;
- else if (fr<=.75)
- fr = -4.0 * fr + 2.0;
- else
- fr = 4.0 * fr - 4.0;
-
- return(fr);
- } else { //if (funcnum==MOTION_HILL) {
- return( (1.0-cos(2.0*M_PI*timeval)) * 0.5);
- }
-
-}
+#define INTERI(x) do { double tt = 0.0; \
+ for (k = 0; k < ncp; k++) tt += c[k] * cpi[k].x; \
+ result->x = (int)rint(tt); } while(0)
double det_matrix(double s[2][2]) {
return s[0][0] * s[1][1] - s[0][1] * s[1][0];
@@ -68,79 +41,20 @@ int id_matrix(double2 s[3]) {
(s[2][1] == 0.0);
}
-int zero_matrix(double2 s[3]) {
- return
- (s[0][0] == 0.0) &&
- (s[0][1] == 0.0) &&
- (s[1][0] == 0.0) &&
- (s[1][1] == 0.0) &&
- (s[2][0] == 0.0) &&
- (s[2][1] == 0.0);
-}
-
-void copy_matrix(double to[3][2], double from[3][2]) {
-
- to[0][0] = from[0][0];
- to[0][1] = from[0][1];
- to[1][0] = from[1][0];
- to[1][1] = from[1][1];
- to[2][0] = from[2][0];
- to[2][1] = from[2][1];
-}
-
-
-void clear_matrix(double2 m[3]) {
+static void clear_matrix(double2 m[3]) {
const double2 zero = (double2) { 0.0, 0.0 };
m[0] = zero;
m[1] = zero;
m[2] = zero;
}
-void sum_matrix(double s, const double2 m1[3], double2 m2[3]) {
+static void sum_matrix(double s, const double2 m1[3], double2 m2[3]) {
m2[0] += s * m1[0];
m2[1] += s * m1[1];
m2[2] += s * m1[2];
}
-void mult_matrix(double s1[2][2], double s2[2][2], double d[2][2]) {
- d[0][0] = s1[0][0] * s2[0][0] + s1[1][0] * s2[0][1];
- d[1][0] = s1[0][0] * s2[1][0] + s1[1][0] * s2[1][1];
- d[0][1] = s1[0][1] * s2[0][0] + s1[1][1] * s2[0][1];
- d[1][1] = s1[0][1] * s2[1][0] + s1[1][1] * s2[1][1];
-}
-
-int compare_xforms(const void *av, const void *bv) {
- flam3_xform *a = (flam3_xform *) av;
- flam3_xform *b = (flam3_xform *) bv;
- double aa[2][2];
- double bb[2][2];
- double ad, bd;
-
- aa[0][0] = a->c[0][0];
- aa[0][1] = a->c[0][1];
- aa[1][0] = a->c[1][0];
- aa[1][1] = a->c[1][1];
- bb[0][0] = b->c[0][0];
- bb[0][1] = b->c[0][1];
- bb[1][0] = b->c[1][0];
- bb[1][1] = b->c[1][1];
- ad = det_matrix(aa);
- bd = det_matrix(bb);
-
- if (a->color_speed > b->color_speed) return 1;
- if (a->color_speed < b->color_speed) return -1;
- if (a->color_speed) {
- if (ad < 0) return -1;
- if (bd < 0) return 1;
- ad = atan2(a->c[0][0], a->c[0][1]);
- bd = atan2(b->c[0][0], b->c[0][1]);
- }
-
- if (ad < bd) return -1;
- if (ad > bd) return 1;
- return 0;
-}
#if 0
void interpolate_cmap(flam3_palette cmap, double blend,
@@ -184,7 +98,7 @@ void interpolate_cmap(flam3_palette cmap, double blend,
}
#endif
-void interp_and_convert_back(double *c, int ncps, int xfi, double cxang[4][2],
+static void interp_and_convert_back(double *c, int ncps, int xfi, double cxang[4][2],
double cxmag[4][2], double cxtrn[4][2],double store_array[3][2]) {
int i,col;
@@ -237,7 +151,7 @@ void interp_and_convert_back(double *c, int ncps, int xfi, double cxang[4][2],
}
-void convert_linear_to_polar(flam3_genome *cp, int ncps, int xfi, int cflag,
+static void convert_linear_to_polar(flam3_genome *cp, int ncps, int xfi, int cflag,
double cxang[4][2], double cxmag[4][2], double cxtrn[4][2]) {
double c1[2],d,t,refang;
@@ -329,11 +243,11 @@ void interpolate_catmull_rom(flam3_genome cps[], double t, flam3_genome *result)
flam3_interpolate_n(result, 4, cps, cmc, 0);
}
-double smoother(double t) {
+static double smoother(double t) {
return 3*t*t - 2*t*t*t;
}
-double get_stagger_coef(double t, double stagger_prc, int num_xforms, int this_xform) {
+static double get_stagger_coef(double t, double stagger_prc, int num_xforms, int this_xform) {
/* max_stag is the spacing between xform start times if stagger_prc = 1.0 */
double max_stag = (double)(num_xforms-1)/num_xforms;
@@ -620,7 +534,7 @@ void flam3_interpolate_n(flam3_genome *result, int ncp,
}
-void establish_asymmetric_refangles(flam3_genome *cp, int ncps) {
+static void establish_asymmetric_refangles(flam3_genome *cp, int ncps) {
int k, xfi, col;
diff --git a/interpolation.h b/interpolation.h
index 21e333e..747d029 100644
--- a/interpolation.h
+++ b/interpolation.h
@@ -15,45 +15,19 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef interpolation_included
-#define interpolation_included
+#pragma once
-#include "private.h"
+#include "math.h"
+#include "flam3.h"
-#define INTERP(x) do { result->x = 0.0; \
- for (k = 0; k < ncp; k++) result->x += c[k] * cpi[k].x; } while(0)
-
-#define INTERI(x) do { double tt = 0.0; \
- for (k = 0; k < ncp; k++) tt += c[k] * cpi[k].x; \
- result->x = (int)rint(tt); } while(0)
-
-double adjust_percentage(double in);
-double motion_funcs(int funcnum, double timeval);
-
-double smoother(double t);
-double get_stagger_coef(double t, double stagger_prc, int num_xforms, int this_xform);
-
-double det_matrix(double s[2][2]);
int id_matrix(double2 s[3]);
-int zero_matrix(double2 s[3]);
-void copy_matrix(double to[3][2], double from[3][2]);
-void clear_matrix(double2 m[3]);
-void sum_matrix(double s, const double2 m1[3], double2 m2[3]);
-void mult_matrix(double s1[2][2], double s2[2][2], double d[2][2]);
-
-int compare_xforms(const void *av, const void *bv);
+double det_matrix(double s[2][2]);
#if 0
void interpolate_cmap(flam3_palette cmap, double blend,
int index0, double hue0, int index1, double hue1, randctx * const);
#endif
-void interp_and_convert_back(double *c, int ncps, int xfi, double cxang[4][2],
- double cxmag[4][2], double cxtrn[4][2],double store_array[3][2]);
-void convert_linear_to_polar(flam3_genome *cp, int ncps, int xfi, int cflag,
- double cxang[4][2], double cxmag[4][2], double cxtrn[4][2]);
void interpolate_catmull_rom(flam3_genome cps[], double t, flam3_genome *result);
void flam3_interpolate_n(flam3_genome *result, int ncp, flam3_genome *cpi, double *c, double stagger);
-void establish_asymmetric_refangles(flam3_genome *cp, int ncps);
void flam3_align(flam3_genome *dst, flam3_genome *src, int nsrc);
-#endif
diff --git a/main.c b/main.c
index 61ed4d9..ce9999f 100644
--- a/main.c
+++ b/main.c
@@ -19,10 +19,10 @@
#include <string.h>
#include <stdbool.h>
#include <stdlib.h>
+#include <unistd.h>
#include <argp.h>
#include "random.h"
-#include "private.h"
#include "img.h"
#include "rect.h"
#include "math.h"
@@ -131,8 +131,7 @@ static void do_render (const render_arguments * const arguments) {
bucket.samples, bucket.badvals);
render_image (genome, &bucket, image, bytes_per_channel);
- flam3_img_comments fpc;
- write_png (stdout, image, genome->width, genome->height, &fpc,
+ write_png (stdout, image, genome->width, genome->height,
bytes_per_channel);
}
diff --git a/math.h b/math.h
index d6e3211..a7a658e 100644
--- a/math.h
+++ b/math.h
@@ -22,6 +22,7 @@
#include <assert.h>
#include "build/config.h"
+#include "vector.h"
#ifdef HAVE_AMDLIBM
#define REPLACE_WITH_AMDLIBM
@@ -31,6 +32,7 @@
#endif
#define clamp(a,min,max) (a > max ? max : (a < min ? min : a))
+#define EPS (1e-10)
/* Apply affine coordinate transformation
*/
diff --git a/palettes.c b/palettes.c
index 03b2c08..92ddc79 100644
--- a/palettes.c
+++ b/palettes.c
@@ -17,8 +17,9 @@
*/
#include <assert.h>
+#include <string.h>
-#include "private.h"
+#include "math.h"
#include "palettes.h"
#include "rect.h"
@@ -207,73 +208,6 @@ double4 hsv2rgb(double4 hsv)
return (double4) { rd, gd, bd, hsv[3] };
}
-double flam3_calc_alpha(double density, double gamma, double linrange) {
-
- double dnorm = density;
- double funcval = pow(linrange, gamma);
- double frac,alpha;
-
- if (dnorm>0) {
- if (dnorm < linrange) {
- frac = dnorm/linrange;
- alpha = (1.0-frac) * dnorm * (funcval / linrange) + frac * pow(dnorm,gamma);
- } else
- alpha = pow(dnorm,gamma);
- } else
- alpha = 0;
-
- return(alpha);
-}
-
-double4 flam3_calc_newrgb(double4 cbuf, double ls, double highpow) {
-
- int rgbi;
- double newls,lsratio;
- double a, maxa=-1.0, maxc=0;
- double adjhlp;
-
- if (ls==0.0 || (cbuf[0]==0.0 && cbuf[1]==0.0 && cbuf[2]==0.0)) {
- return (double4) { 0, 0, 0, 0 };
- }
-
- /* Identify the most saturated channel */
- for (rgbi=0;rgbi<3;rgbi++) {
- a = ls * (cbuf[rgbi]);
- if (a>maxa) {
- maxa = a;
- maxc = cbuf[rgbi];
- }
- }
-
- /* If a channel is saturated and we have a non-negative highlight power */
- /* modify the color to prevent hue shift */
- if (maxa > 1.0 && highpow>=0.0) {
- newls = 1.0/maxc;
- lsratio = pow(newls/ls,highpow);
-
- /* Calculate the max-value color (ranged 0 - 1) */
- double4 newrgb = newls*(cbuf);
-
- /* Reduce saturation by the lsratio */
- double4 newhsv = rgb2hsv(newrgb);
- newhsv[1] *= lsratio;
-
- return hsv2rgb(newhsv);
- } else {
- newls = 1.0/maxc;
- adjhlp = -highpow;
- if (adjhlp>1)
- adjhlp=1;
- if (maxa<=1.0)
- adjhlp=1.0;
-
- /* Calculate the max-value color (ranged 0 - 1) interpolated with the old
- * behaviour */
-
- return ((1.0-adjhlp)*newls + adjhlp*ls)*(cbuf);
- }
-}
-
static int random_xform(flam3_genome *g, int excluded, randctx * const rc) {
int ntries = 0;
while (ntries++ < 100) {
@@ -284,7 +218,6 @@ static int random_xform(flam3_genome *g, int excluded, randctx * const rc) {
return -1;
}
-
static double try_colors(flam3_genome *g, int color_resolution) {
int *hist;
int i, hits, res = color_resolution;
diff --git a/palettes.h b/palettes.h
index 2603c99..86e4eb1 100644
--- a/palettes.h
+++ b/palettes.h
@@ -21,7 +21,7 @@
#include <stdlib.h>
#include <stdbool.h>
-#include "flam3.h"
+#include "vector.h"
/* One palette */
typedef struct {
@@ -38,13 +38,11 @@ typedef struct {
palette *p;
} palette_collection;
-#include "vector.h"
-
double4 rgb2hsv(double4);
double4 hsv2rgb(double4);
-double flam3_calc_alpha(double density, double gamma, double linrange);
-double4 flam3_calc_newrgb(double4 cbuf, double ls, double highpow);
+#include "flam3.h"
+
void palette_add (palette * const p, const double4 c);
const palette *palette_random (const palette_collection * const pc, randctx * const rc);
void palette_copy (const palette * const src, palette * const dest);
diff --git a/parser.c b/parser.c
index cafada0..db43c68 100644
--- a/parser.c
+++ b/parser.c
@@ -19,10 +19,17 @@
#include "interpolation.h"
#include <errno.h>
#include <assert.h>
+#include <string.h>
+#include <ctype.h>
+
+static int parse_flame_element(xmlNode *flame_node, flam3_genome *loc_current_cp,
+ randctx * const rc);
+static int parse_xform_xml(xmlNode *chld_node,flam3_xform *this_xform, int *num_xaos,
+ flam3_chaos_entry **xaos, int numstd, int motionxf);
static int flam3_conversion_failed;
-int flam3_atoi(char *nstr) {
+static int flam3_atoi(char *nstr) {
/* Note that this is NOT thread-safe, but simplifies things significantly. */
int res;
@@ -46,7 +53,7 @@ int flam3_atoi(char *nstr) {
return(res);
}
-double flam3_atof(char *nstr) {
+static double flam3_atof(char *nstr) {
/* Note that this is NOT thread-safe, but simplifies things significantly. */
double res;
@@ -70,7 +77,9 @@ double flam3_atof(char *nstr) {
return(res);
}
-int var2n(const char *s) {
+#define flam3_variation_none (-1)
+
+static int var2n(const char *s) {
int i;
for (i = 0; i < flam3_nvariations; i++)
@@ -272,7 +281,7 @@ void scan_for_flame_nodes(xmlNode *cur_node, int default_flag, flam3_genome **al
}
-int parse_flame_element(xmlNode *flame_node, flam3_genome *loc_current_cp,
+static int parse_flame_element(xmlNode *flame_node, flam3_genome *loc_current_cp,
randctx * const rc) {
flam3_genome *cp = loc_current_cp;
xmlNode *chld_node;
@@ -689,7 +698,7 @@ int parse_flame_element(xmlNode *flame_node, flam3_genome *loc_current_cp,
}
-int parse_xform_xml(xmlNode *chld_node,flam3_xform *this_xform, int *num_xaos,
+static int parse_xform_xml(xmlNode *chld_node,flam3_xform *this_xform, int *num_xaos,
flam3_chaos_entry **xaos, int numstd, int motionxf) {
xmlAttrPtr att_ptr, cur_att;
diff --git a/parser.h b/parser.h
index 5fa1923..4b7dc45 100644
--- a/parser.h
+++ b/parser.h
@@ -17,21 +17,7 @@
#pragma once
-#include "private.h"
-
-int flam3_atoi(char *nstr);
-double flam3_atof(char *nstr);
-int var2n(const char *s);
-#if 0
-int flam3_parse_hexformat_colors(char *colstr, flam3_genome *cp, int numcolors, int chan);
-#endif
+#include "flam3.h"
void scan_for_flame_nodes(xmlNode *cur_node, int default_flag, flam3_genome **all_cp, int *all_ncps, randctx * const);
-int parse_flame_element(xmlNode *flame_node, flam3_genome *loc_current_cp, randctx * const);
-int parse_xform_xml(xmlNode *chld_node,flam3_xform *this_xform, int *num_xaos,
- flam3_chaos_entry **xaos, int numstd, int motionxf);
-void flam3_edit_print(FILE *f, xmlNodePtr editNode, int tabs, int formatting);
-#if 0
-int flam3_interp_missing_colors(flam3_genome *cp);
-#endif
diff --git a/png.c b/png.c
index 0316e0c..dce96bc 100644
--- a/png.c
+++ b/png.c
@@ -24,11 +24,10 @@
#include "build/config.h"
#include "img.h"
#include "flam3.h"
-#include "private.h"
#include <arpa/inet.h>
-void write_png(FILE *file, void *image, int width, int height, flam3_img_comments *fpc, int bpc) {
+void write_png(FILE *file, void *image, int width, int height, int bpc) {
png_structp png_ptr;
png_infop info_ptr;
size_t i;
diff --git a/private.h b/private.h
deleted file mode 100644
index 4521146..0000000
--- a/private.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- Copyright (C) 1992-2009 Spotworks LLC
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#ifndef private_included
-#define private_included
-
-#include "flam3.h"
-#include "build/config.h"
-#include <stdlib.h>
-
-#include <ctype.h>
-#include <time.h>
-#include <string.h>
-#include <libxml/parser.h>
-
-#include <unistd.h>
-#include <libgen.h>
-
-#include <math.h>
-
-#define EPS (1e-10)
-#define CMAP_SIZE 256
-#define CMAP_SIZE_M1 255
-#define rbit() (flam3_random_bit())
-#define flam3_variation_none (-1)
-#define max_specified_vars (100)
-#define vlen(x) (sizeof(x)/sizeof(*x))
-
-double flam3_sinc(double x);
-
-#define flam3_mitchell_b (1.0 / 3.0)
-#define flam3_mitchell_c (1.0 / 3.0)
-
-
-#endif
diff --git a/random.h b/random.h
index 4e0b8c9..29d63cb 100644
--- a/random.h
+++ b/random.h
@@ -15,6 +15,7 @@ double rand_d01 (randctx * const st);
double rand_d11 (randctx * const st);
int rand_bool (randctx * const st);
+#define vlen(x) (sizeof(x)/sizeof(*x))
#define rand_distrib(st,v) ((v)[rand_u64(st)%vlen(v)])
#define rand_mod(st,max) (rand_u64(st)%(max))
diff --git a/rect.c b/rect.c
index 7c12b2e..13a76c6 100644
--- a/rect.c
+++ b/rect.c
@@ -17,9 +17,9 @@
#include <assert.h>
#include <stdlib.h>
+#include <string.h>
#include <omp.h>
-#include "private.h"
#include "variations.h"
#include "palettes.h"
#include "math.h"
@@ -147,6 +147,72 @@ static void iter_thread (flam3_genome * const input_genome,
free (iter_storage);
}
+static double flam3_calc_alpha(double density, double gamma, double linrange) {
+
+ double dnorm = density;
+ double funcval = pow(linrange, gamma);
+ double frac,alpha;
+
+ if (dnorm>0) {
+ if (dnorm < linrange) {
+ frac = dnorm/linrange;
+ alpha = (1.0-frac) * dnorm * (funcval / linrange) + frac * pow(dnorm,gamma);
+ } else
+ alpha = pow(dnorm,gamma);
+ } else
+ alpha = 0;
+
+ return(alpha);
+}
+
+static double4 flam3_calc_newrgb(double4 cbuf, double ls, double highpow) {
+ int rgbi;
+ double newls,lsratio;
+ double a, maxa=-1.0, maxc=0;
+ double adjhlp;
+
+ if (ls==0.0 || (cbuf[0]==0.0 && cbuf[1]==0.0 && cbuf[2]==0.0)) {
+ return (double4) { 0, 0, 0, 0 };
+ }
+
+ /* Identify the most saturated channel */
+ for (rgbi=0;rgbi<3;rgbi++) {
+ a = ls * (cbuf[rgbi]);
+ if (a>maxa) {
+ maxa = a;
+ maxc = cbuf[rgbi];
+ }
+ }
+
+ /* If a channel is saturated and we have a non-negative highlight power */
+ /* modify the color to prevent hue shift */
+ if (maxa > 1.0 && highpow>=0.0) {
+ newls = 1.0/maxc;
+ lsratio = pow(newls/ls,highpow);
+
+ /* Calculate the max-value color (ranged 0 - 1) */
+ double4 newrgb = newls*(cbuf);
+
+ /* Reduce saturation by the lsratio */
+ double4 newhsv = rgb2hsv(newrgb);
+ newhsv[1] *= lsratio;
+
+ return hsv2rgb(newhsv);
+ } else {
+ newls = 1.0/maxc;
+ adjhlp = -highpow;
+ if (adjhlp>1)
+ adjhlp=1;
+ if (maxa<=1.0)
+ adjhlp=1.0;
+
+ /* Calculate the max-value color (ranged 0 - 1) interpolated with the old
+ * behaviour */
+
+ return ((1.0-adjhlp)*newls + adjhlp*ls)*(cbuf);
+ }
+}
+
/* Perform clipping
*/
static double4 clip (const double4 in, const double g, const double linrange,
diff --git a/rect.h b/rect.h
index 5b3dd62..c6b98f8 100644
--- a/rect.h
+++ b/rect.h
@@ -1,7 +1,25 @@
+/*
+ Copyright (C) 1992-2009 Spotworks LLC
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
#pragma once
-#include <stdbool.h>
+#include <stdbool.h>
#include "vector.h"
+#include "flam3.h"
typedef struct {
/* bucket width/height */
diff --git a/variations.c b/variations.c
index 219e342..8c28a0c 100644
--- a/variations.c
+++ b/variations.c
@@ -1912,6 +1912,13 @@ void xform_precalc(flam3_genome *cp, int xi) {
wedgeJulia_precalc(&(cp->xform[xi]));
}
+static double adjust_percentage(double in) {
+ if (in==0.0)
+ return(0.0);
+ else
+ return(pow(10.0, -log(1.0/in)/log(2)));
+}
+
int prepare_precalc_flags(flam3_genome *cp) {
double d;
diff --git a/variations.h b/variations.h
index 97c9440..f6cade7 100644
--- a/variations.h
+++ b/variations.h
@@ -15,14 +15,13 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef variations_included
-#define variations_included
+#pragma once
-#include "private.h"
+#include "flam3.h"
void xform_precalc(flam3_genome *cp, int xi);
int prepare_precalc_flags(flam3_genome *);
int apply_xform(flam3_genome *cp, int fn, const double4 p, double4 *, randctx *rc);
void initialize_xforms(flam3_genome *thiscp, int start_here);
-#endif
+