terom@12: terom@12: #include "common.h" terom@18: #include "render_struct.h" terom@12: #include "render_mandelbrot.h" terom@12: terom@12: #define DETAIL 255 terom@12: terom@12: #define absdelta(a, b) (a>b ? a-b : b-a) terom@12: terom@12: int render_mandelbrot (struct render *ctx) { terom@12: // render algorithm vars terom@12: u_int32_t img_x, img_y; terom@12: double x0, y0, x, y, _x, _y, w_scale, h_scale; terom@12: u_int8_t iter; terom@12: terom@12: // calcluate the scale factors terom@12: w_scale = ctx->img_w/absdelta(ctx->x1, ctx->x2); terom@12: h_scale = ctx->img_h/absdelta(ctx->y1, ctx->y2); terom@12: terom@12: // start rendering! terom@22: for (img_y=ctx->img_top; img_y < ctx->img_bottom; img_y += ctx->img_y_step) { terom@12: // render the current row terom@22: for (img_x=ctx->img_left; img_x < ctx->img_right; img_x += ctx->img_x_step) { terom@12: x = 0; terom@12: y = 0; terom@12: x0 = img_x/w_scale + ctx->x1; terom@12: y0 = img_y/h_scale + ctx->y1; terom@12: iter = DETAIL; terom@12: terom@12: while (x*x + y*y < (2*2) && iter > 0) { terom@12: _x = x*x - y*y + x0; terom@12: _y = 2*x*y + y0; terom@12: terom@12: x = _x; terom@12: y = _y; terom@12: terom@12: iter--; terom@12: } terom@12: terom@22: (*ctx->local_rowbuf_addr)[img_x - ctx->img_left] = iter; terom@12: } terom@12: terom@12: // row cb terom@12: if (ctx->local_row_fn(ctx->cb_arg, (*ctx->local_rowbuf_addr))) terom@12: ERROR("local_row_fn"); terom@12: } terom@12: terom@12: // return succesfully terom@12: return 0; terom@12: terom@12: error: terom@12: return -1; terom@12: } terom@12: