--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/render_mandelbrot.c Fri Jun 06 23:37:45 2008 +0300
@@ -0,0 +1,54 @@
+
+#include "common.h"
+#include "render_internal.h"
+#include "render_mandelbrot.h"
+
+#define DETAIL 255
+
+#define absdelta(a, b) (a>b ? a-b : b-a)
+
+int render_mandelbrot (struct render *ctx) {
+ // render algorithm vars
+ u_int32_t img_x, img_y;
+ double x0, y0, x, y, _x, _y, w_scale, h_scale;
+ u_int8_t iter;
+
+ // calcluate the scale factors
+ w_scale = ctx->img_w/absdelta(ctx->x1, ctx->x2);
+ h_scale = ctx->img_h/absdelta(ctx->y1, ctx->y2);
+
+ // start rendering!
+ for (img_y=0; img_y < ctx->img_h; img_y++) {
+ // render the current row
+ for (img_x=0; img_x < ctx->img_w; img_x++) {
+ x = 0;
+ y = 0;
+ x0 = img_x/w_scale + ctx->x1;
+ y0 = img_y/h_scale + ctx->y1;
+ iter = DETAIL;
+
+ while (x*x + y*y < (2*2) && iter > 0) {
+ _x = x*x - y*y + x0;
+ _y = 2*x*y + y0;
+
+ x = _x;
+ y = _y;
+
+ iter--;
+ }
+
+ (*ctx->local_rowbuf_addr)[img_x] = iter;
+ }
+
+ // row cb
+ if (ctx->local_row_fn(ctx->cb_arg, (*ctx->local_rowbuf_addr)))
+ ERROR("local_row_fn");
+ }
+
+ // return succesfully
+ return 0;
+
+error:
+ return -1;
+}
+