[haiku-commits] haiku: hrev47657 - src/apps/mandelbrot

  • From: pulkomandy@xxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sat, 9 Aug 2014 16:39:21 +0200 (CEST)

hrev47657 adds 1 changeset to branch 'master'
old head: d53fe46d17d17c1f93f671be65f9ccb36d7f4cca
new head: ac1272a5e2a5104cd007c4fc0a7a62c78e95e324
overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=ac1272a+%5Ed53fe46

----------------------------------------------------------------------------

ac1272a: 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.

                             [ Adrien Destugues <pulkomandy@xxxxxxxxxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev47657
Commit:      ac1272a5e2a5104cd007c4fc0a7a62c78e95e324
URL:         http://cgit.haiku-os.org/haiku/commit/?id=ac1272a
Author:      Adrien Destugues <pulkomandy@xxxxxxxxxxxxx>
Date:        Sat Aug  9 14:33:02 2014 UTC

Ticket:      https://dev.haiku-os.org/ticket/8812
Ticket:      https://dev.haiku-os.org/ticket/10920

----------------------------------------------------------------------------

1 file changed, 10 insertions(+), 15 deletions(-)
src/apps/mandelbrot/tsb.cpp | 25 ++++++++++---------------

----------------------------------------------------------------------------

diff --git a/src/apps/mandelbrot/tsb.cpp b/src/apps/mandelbrot/tsb.cpp
index f62daf1..7ea11b1 100644
--- a/src/apps/mandelbrot/tsb.cpp
+++ b/src/apps/mandelbrot/tsb.cpp
@@ -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];
                                }
                        }
                }


Other related posts:

  • » [haiku-commits] haiku: hrev47657 - src/apps/mandelbrot - pulkomandy