MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / ComputeMandelbrot

Function ComputeMandelbrot

test/pthread/test_pthread_mandelbrot.cpp:115–156  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

113}
114
115unsigned long long ComputeMandelbrot(float *srcReal, float *srcImag, uint32_t *dst, int strideSrc, int strideDst, int x, int y, int yIncr, int w, int h, float left, float top, float incrX, float incrY, unsigned int numItersBefore, unsigned int numIters)
116{
117 for(int Y = y; Y < h; Y += yIncr)
118 {
119 float *sr = (float*)((uintptr_t)srcReal + strideSrc * Y) + x;
120 float *si = (float*)((uintptr_t)srcImag + strideSrc * Y) + x;
121 uint32_t *d = (uint32_t*)((uintptr_t)dst + strideDst * Y) + x;
122 float imag = top + Y * incrY;
123 for(int X = 0; X < w; ++X)
124 {
125 float real = left + (x + X) * incrX;
126 float v_real = sr[X];
127 if (v_real != INFINITY)
128 {
129 float v_imag = si[X];
130 for(unsigned int i = 0; i < numIters; ++i)
131 {
132 // (x+yi)^2 = x^2 - y^2 + 2xyi
133 // ||x_+yi||^2 = x^2+y^2
134 float new_real = v_real*v_real - v_imag*v_imag + real;
135 v_imag = 2.f * v_real * v_imag + imag;
136 v_real = new_real;
137
138/*
139 new_real = v_real*v_real - v_imag*v_imag + real;
140 v_imag = 2.f * v_real * v_imag + imag;
141 v_real = new_real;
142*/
143 if (v_real*v_real + v_imag*v_imag > 4.f)
144 {
145 d[X] = ColorMap(numItersBefore + i);
146 v_real = INFINITY;
147 break;
148 }
149 }
150 sr[X] = v_real;
151 si[X] = v_imag;
152 }
153 }
154 }
155 return (unsigned long long)((h-y)/yIncr)*w*numIters;
156}
157
158#ifdef __SSE__
159// Not strictly correct anyzero_ps, but faster, and depends on that color alpha channel is always either 0xFF or 0.

Callers 2

mandelbrot_threadFunction · 0.85
register_tasksFunction · 0.85

Calls 1

ColorMapFunction · 0.85

Tested by

no test coverage detected