Skip to content
This repository has been archived by the owner on Jun 10, 2018. It is now read-only.

Added bailout support #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION :=0.1.1
VERSION :=0.1.2

PREFIX :=/usr/local
BINDIR :=$(PREFIX)/bin
Expand Down
9 changes: 5 additions & 4 deletions src/coords.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ int mpfr_mul_d(mpfr_t rop, mpfr_t op1, double _op2, mpfr_rnd_t rnd)
#endif


coords* coords_new( int img_width, int img_height,
coords* coords_new( int img_width, int img_height, long bail,
double init_cx, double init_cy, double init_size)
{
coords* c = malloc(sizeof(*c));
Expand All @@ -56,8 +56,8 @@ coords* coords_new( int img_width, int img_height,
return 0;

c->precision = 0;

c->precision = DEFAULT_PRECISION;
c->bail = bail;

mpfr_init2(c->xmin, c->precision);
mpfr_init2(c->xmax, c->precision);
Expand All @@ -83,7 +83,7 @@ coords* coords_new( int img_width, int img_height,

coords* coords_dup(const coords* c)
{
coords* d = coords_new( c->img_width, c->img_height,
coords* d = coords_new( c->img_width, c->img_height, c->bail,
c->init_cx, c->init_cy, c->init_size);

if (!d)
Expand All @@ -106,6 +106,7 @@ coords* coords_cpy(coords* dest, const coords* src)
dest->init_cy = src->init_cy;
dest->init_size = src->init_size;
dest->recommend = src->recommend;
dest->bail = src->bail;

mpfr_set(dest->xmin, src->xmin, GMP_RNDN);
mpfr_set(dest->xmax, src->xmax, GMP_RNDN);
Expand Down Expand Up @@ -164,7 +165,7 @@ int coords_calculate_precision(coords* c)
mpfr_init2(px_size, c->precision);
mpfr_init2(precision, c->precision);

mpfr_set_d( bail, 4.0, GMP_RNDN);
mpfr_set_d( bail, c->bail, GMP_RNDN);
mpfr_div_si(px_size, c->width, c->img_width, GMP_RNDN);
mpfr_div( tmp, bail, px_size, GMP_RNDN);

Expand Down
3 changes: 2 additions & 1 deletion src/coords.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ struct coords
mpfr_t _size;

double aspect;
long bail;

mp_prec_t precision;
mp_prec_t recommend; /* scant minimum */
Expand All @@ -60,7 +61,7 @@ struct coords
typedef struct coords coords;


coords* coords_new( int img_width, int img_height,
coords* coords_new( int img_width, int img_height, long bail,
double init_cx, double init_cy, double init_width);

void coords_set(coords*, int img_width, int img_height);
Expand Down
4 changes: 2 additions & 2 deletions src/frac_burning_ship.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <math.h>


depth_t frac_burning_ship( depth_t depth,
depth_t frac_burning_ship( depth_t depth, long double bail,
long double wim, long double wre,
long double c_im, long double c_re,
long double wim2, long double wre2 )
Expand All @@ -17,7 +17,7 @@ depth_t frac_burning_ship( depth_t depth,
wim2 = wim * wim;
wre2 = wre * wre;

if (wim2 + wre2 > 4.0F)
if (wim2 + wre2 > bail)
return wz;
}
return 0;
Expand Down
2 changes: 1 addition & 1 deletion src/frac_burning_ship.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "types.h"


depth_t frac_burning_ship( depth_t depth,
depth_t frac_burning_ship( depth_t depth, long double bail,
long double wim, long double wre,
long double c_im, long double c_re,
long double wim2, long double wre2 );
Expand Down
4 changes: 2 additions & 2 deletions src/frac_generalized_celtic.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <math.h>


depth_t frac_generalized_celtic(depth_t depth,
depth_t frac_generalized_celtic(depth_t depth, long double bail,
long double wim, long double wre,
long double c_im, long double c_re,
long double wim2, long double wre2 )
Expand All @@ -17,7 +17,7 @@ depth_t frac_generalized_celtic(depth_t depth,
wim2 = wim * wim;
wre2 = wre * wre;

if (wim2 + wre2 > 4.0F)
if (wim2 + wre2 > bail)
return wz;
}
return 0;
Expand Down
2 changes: 1 addition & 1 deletion src/frac_generalized_celtic.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "types.h"


depth_t frac_generalized_celtic(depth_t depth,
depth_t frac_generalized_celtic(depth_t depth, long double bail,
long double wim, long double wre,
long double c_im, long double c_re,
long double wim2, long double wre2 );
Expand Down
4 changes: 2 additions & 2 deletions src/frac_mandel.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <math.h>

depth_t frac_mandel( depth_t depth,
depth_t frac_mandel( depth_t depth, long double bail,
long double wim, long double wre,
long double c_im, long double c_re,
long double wim2, long double wre2 )
Expand All @@ -14,7 +14,7 @@ depth_t frac_mandel( depth_t depth,
wre = wre2 - wim2 + c_re;
wim2 = wim * wim;
wre2 = wre * wre;
if (wim2 + wre2 > 4.0F)
if (wim2 + wre2 > bail)
return wz;
}
return 0;
Expand Down
2 changes: 1 addition & 1 deletion src/frac_mandel.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "types.h"


depth_t frac_mandel( depth_t depth,
depth_t frac_mandel( depth_t depth, long double bail,
long double wim, long double wre,
long double c_im, long double c_re,
long double wim2, long double wre2 );
Expand Down
4 changes: 2 additions & 2 deletions src/frac_variant.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <math.h>

depth_t frac_variant( depth_t depth,
depth_t frac_variant( depth_t depth, long double bail,
long double wim, long double wre,
long double c_im, long double c_re,
long double wim2, long double wre2 )
Expand All @@ -17,7 +17,7 @@ depth_t frac_variant( depth_t depth,
wre = wre2 - wim2 + c_re;
wim2 = wim * wim;
wre2 = wre * wre;
if (wim2 + wre2 > 4.0F)
if (wim2 + wre2 > bail)
return wz;
}
return 0;
Expand Down
2 changes: 1 addition & 1 deletion src/frac_variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "types.h"


depth_t frac_variant( depth_t depth,
depth_t frac_variant( depth_t depth, long double bail,
long double wim, long double wre,
long double c_im, long double c_re,
long double wim2, long double wre2 );
Expand Down
23 changes: 12 additions & 11 deletions src/fractal.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ int fractal_calculate_line(image_info* img, int line)
long double wre, wim;
long double wre2, wim2;
depth_t depth = img->depth;
long double bail = img->bail;

long double xmin, xmax, ymax, width;
long double j_c_re = 0, j_c_im = 0;
Expand Down Expand Up @@ -89,23 +90,23 @@ int fractal_calculate_line(image_info* img, int line)
switch(img->fractal)
{
case BURNING_SHIP:
*raw_data = frac_burning_ship(depth, wim, wre,
*raw_data = frac_burning_ship(depth, bail, wim, wre,
c_im, c_re,
wim2, wre2);
break;
case GENERALIZED_CELTIC:
*raw_data = frac_generalized_celtic(depth, wim, wre,
*raw_data = frac_generalized_celtic(depth, bail, wim, wre,
c_im, c_re,
wim2, wre2);
break;
case VARIANT:
*raw_data = frac_variant(depth, wim, wre,
*raw_data = frac_variant(depth, bail, wim, wre,
c_im, c_re,
wim2, wre2);
break;
case MANDELBROT:
default:
*raw_data = frac_mandel(depth, wim, wre,
*raw_data = frac_mandel(depth, bail, wim, wre,
c_im, c_re,
wim2, wre2);
}
Expand Down Expand Up @@ -156,12 +157,12 @@ int fractal_mpfr_calculate_line(image_info* img, int line)
mpfr_init2(img_xmin,img->precision);
mpfr_init2(t1, img->precision);

mpfr_set_si(frs_bail, 4, GMP_RNDN);
mpfr_set_si(img_rw, img_width, GMP_RNDN);
mpfr_set( img_xmin, img->xmin, GMP_RNDN);
mpfr_set( width, img->width, GMP_RNDN);
mpfr_set_si(frs_bail, img->bail, GMP_RNDN);
mpfr_set_si(img_rw, img_width, GMP_RNDN);
mpfr_set( img_xmin, img->xmin, GMP_RNDN);
mpfr_set( width, img->width, GMP_RNDN);

/* y = img->ymax - ((img->xmax - img->xmin)
/* y = img->ymax - ((img->xmax - img->xmin)
/ (long double)img->real_width)
* (long double)img->lines_done; */
mpfr_div( t1, width, img_rw, GMP_RNDN);
Expand Down Expand Up @@ -296,12 +297,12 @@ int fractal_gmp_calculate_line(image_info* img, int line)
mpf_init2(img_xmin,img->precision);
mpf_init2(t1, img->precision);

mpf_set_si(frs_bail, 4);
mpf_set_si(frs_bail, img->bail);
mpf_set_si(img_rw, img_width);
mpf_set( img_xmin, img->gxmin);
mpf_set( width, img->gwidth);

/* y = img->ymax - ((img->xmax - img->xmin)
/* y = img->ymax - ((img->xmax - img->xmin)
/ (long double)img->real_width)
* (long double)img->lines_done; */
mpf_div( t1, width, img_rw);
Expand Down
15 changes: 14 additions & 1 deletion src/image_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <locale.h>

#define DEFAULT_DEPTH 300
#define DEFAULT_BAIL 4
#define DEFAULT_COLOUR_SCALE 1.0


Expand Down Expand Up @@ -61,7 +62,7 @@ image_info * image_info_create(int family, int fractal)
mpf_init2( img->gymax, DEFAULT_PRECISION);
mpf_init2( img->gwidth, DEFAULT_PRECISION);

img->pcoords = coords_new(img->real_width, img->real_height,
img->pcoords = coords_new(img->real_width, img->real_height, img->bail,
cx, cy, size);
image_info_reset_view(img);

Expand Down Expand Up @@ -268,6 +269,7 @@ void image_info_set_precision(image_info * img, mpfr_prec_t precision)
void image_info_reset_view(image_info* img)
{
img->depth = DEFAULT_DEPTH;
img->bail = DEFAULT_BAIL;

img->precision = DEFAULT_PRECISION;
img->colour_scale = DEFAULT_COLOUR_SCALE;
Expand Down Expand Up @@ -339,6 +341,7 @@ int image_info_save_settings(image_info * img, FILE* fd)
fprintf(fd, "family %s\n", family_str[img->family]);
fprintf(fd, "fractal %s\n", fractal_str[img->fractal]);
fprintf(fd, "depth %ld\n", img->depth);
fprintf(fd, "bailout %ld\n", img->bail);
fprintf(fd, "aspect %0.20lf\n", img->aspect);
fprintf(fd, "colour-scale %0.20lf\n", img->colour_scale);

Expand Down Expand Up @@ -426,6 +429,7 @@ int image_info_load_settings(image_info * img, mdzfile* mf)
{
long precision;
long depth;
long bail;
double aspect;
int use_multi_prec;
int use_rounding;
Expand Down Expand Up @@ -462,6 +466,14 @@ int image_info_load_settings(image_info * img, mdzfile* mf)
if (!mdzfile_get_long(mf, "depth", &depth, MIN_DEPTH, MAX_DEPTH))
return mdzfile_err(mf, "Error in depth setting");

if (mf->version_min >= 1 && mf->version_rev >= 2) /* version 0.1.2 and above */
{
if (!mdzfile_get_long(mf, "bailout", &bail, MIN_BAILOUT, MAX_BAILOUT))
return mdzfile_err(mf, "Error in bailout setting");
}
else
bail = DEFAULT_BAIL;

if (!mdzfile_get_double(mf, "aspect", &aspect, 1e-20f, 1e20f))
return mdzfile_err(mf, "Error in aspect setting");

Expand Down Expand Up @@ -581,6 +593,7 @@ int image_info_load_settings(image_info * img, mdzfile* mf)
img->family = family;
img->fractal = fractal;
img->depth = depth;
img->bail = bail;
image_info_set_multi_prec(img, use_multi_prec, use_rounding);
img->colour_scale = colsc;
img->palette_ip = colip;
Expand Down
6 changes: 5 additions & 1 deletion src/image_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
#define MIN_DEPTH 1
#define MAX_DEPTH INT32_MAX

#define MIN_BAILOUT 1
#define MAX_BAILOUT UINT16_MAX

#define DEFAULT_WIDTH 480
#define DEFAULT_HEIGHT 360
#define MAX_WIDTH 32767
Expand Down Expand Up @@ -73,6 +76,7 @@ typedef struct image_info
coords* pcoords; /* used for updating coords */

depth_t depth;
long bail;

int thread_count;
int draw_lines;
Expand All @@ -86,7 +90,7 @@ typedef struct image_info

random_palette* rnd_pal; /* again... it's handy */

int real_width; /* real size. differs from user_size */
int real_width; /* real size. differs from user_size */
int real_height; /* if anti-aliasing is used */
int user_width;
int user_height;
Expand Down
Loading