Mandelbrot: out-of-bounds access to the palette.

Fixes #8812, #10920

At the edge of the fractal, we can get a value between 0 and the number
of iterations. Since the palette is only 256 colors, this was previously
using random colors for any setting with more than 256 iterations, and
ended up crashing the program with very high numbers.

The palette is now looped, which avoids the crash. Looping the palette
allows finer details at the higher zoom levels to be provided using the
full color range, however with some of the palettes this will look quite
noisy.
This commit is contained in:
Adrien Destugues 2014-08-09 16:33:02 +02:00
parent d53fe46d17
commit ac1272a5e2
1 changed files with 10 additions and 15 deletions

View File

@ -180,7 +180,6 @@ int iterate_double(double a, double b)
double y;
double xsq;
double ysq;
double ctwo = 2.0, cfour = 4.0;
int i = 0, iter = niter;
x = 0.0;
@ -189,11 +188,11 @@ int iterate_double(double a, double b)
while (i < iter) {
xsq = x * x;
ysq = y * y;
y = (ctwo * x * y) + b;
y = (2.0 * x * y) + b;
i++;
x = a + (xsq - ysq);
if ((xsq + ysq) > cfour)
if ((xsq + ysq) > 4.0)
return(i);
}
return(i);
@ -209,10 +208,6 @@ int iterate_float(float a, float b)
float y;
float xsq;
float ysq;
// These are variables, because the metaware compiler would reload the
// constants from memory each time through the loop rather than leave them
// in registers. Lovely.
float ctwo = 2.0, cfour = 4.0;
long i;
int iter = niter;
@ -223,11 +218,11 @@ int iterate_float(float a, float b)
while (i < iter) {
xsq = x * x;
ysq = y * y;
y = (ctwo * x * y) + b;
y = (2.0f * x * y) + b;
i++;
x = a + (xsq - ysq);
if ((xsq + ysq) > cfour)
if ((xsq + ysq) > 4.0f)
return(i);
}
return(i);
@ -359,7 +354,7 @@ void TShowBit::mandb(double vx, double vy, double sx, double sy)
v == pc[x12-2][y12]) {
for (x = bx; x < (bx+12); x++) {
cx += sx;
*b0++ = palette[v];
*b0++ = palette[v & 0xff];
}
}
else {
@ -367,14 +362,14 @@ void TShowBit::mandb(double vx, double vy, double sx, double sy)
for (x = bx; x < (bx+12); x++) {
cx += sx;
v = iterate_double(cx, cy);
*b0++ = palette[v];
*b0++ = palette[v & 0xff];
}
}
else
for (x = bx; x < (bx+12); x++) {
cx += sx;
v = iterate_float(cx, cy);
*b0++ = palette[v];
*b0++ = palette[v & 0xff];
}
}
}
@ -421,7 +416,7 @@ void TShowBit::manda(double vx, double vy, double sx, double sy)
v == pc[x12-2][y12]) {
for (x = bx; x < (bx+12); x++) {
cx += sx;
*b0++ = palette[v];
*b0++ = palette[v & 0xff];
}
}
else {
@ -429,14 +424,14 @@ void TShowBit::manda(double vx, double vy, double sx, double sy)
for (x = bx; x < (bx+12); x++) {
cx += sx;
v = iterate_double(cx, cy);
*b0++ = palette[v];
*b0++ = palette[v & 0xff];
}
}
else
for (x = bx; x < (bx+12); x++) {
cx += sx;
v = iterate_float(cx, cy);
*b0++ = palette[v];
*b0++ = palette[v & 0xff];
}
}
}