#ifndef RENDER_H
#define RENDER_H
#include <sys/types.h>
#include <stdio.h>
/*
* This module provides various ways to render mandelbrot images in various formats
*/
/*
* Custom callbacks
*
* These should return non-zero on error, whereupon the rendering will be aborted, or zero on success
*/
typedef int (*render_ctx_write_cb)(const unsigned char *data, size_t length, void *arg);
typedef int (*render_ctx_flush_cb)(void *arg);
typedef int (*render_ctx_row_cb)(void *arg, unsigned char *rowbuf);
typedef int (*render_ctx_done_cb)(void *arg);
// include render_internal.h first if you need it
struct render;
// output types
enum {
RENDER_RAW, // raw pixel data
RENDER_PNG, // a png image
};
/*
* Alloc a new render context
*/
struct render *render_alloc ();
void render_free(struct render *ctx);
/*
* Clear out the value of the given render context
*/
int render_init (struct render *ctx);
/*
* What kind of image to render, PNG or RAW?
*/
int render_set_mode (struct render *ctx, int mode);
/*
* What size of image to render
*/
int render_set_size (struct render *ctx, u_int32_t img_w, u_int32_t img_h);
int render_get_size (struct render *ctx, u_int32_t *img_w, u_int32_t *img_h);
/*
* Select what region to render
*/
// the "full" mandelbrot region
#define REGION_X1 -2.0
#define REGION_Y1 -1.5
#define REGION_X2 1.0
#define REGION_Y2 1.5
#define REGION_W (REGION_X2 - REGION_X1)
#define REGION_H (REGION_Y2 - REGION_Y1)
int render_region_full (struct render *ctx);
int render_region_raw (struct render *ctx, double x1, double y1, double x2, double y2);
/*
* Render raw pixel data directly to local memory.
*
* rowbuf_addr should point to a memory address that the mandelbrot will be
* rendered into. This memory address should have room for <img_w> bytes.
*
* row_fn will be called after each row has been written, passing in arg and
* *rowbuf_addr as arguments.
*
*/
int render_local_mem (struct render *ctx, unsigned char **rowbuf_addr, render_ctx_row_cb row_fn, void *arg);
/*
* How to handle the I/O
*/
int render_io_custom (struct render *ctx, render_ctx_write_cb write_fn, render_ctx_flush_cb flush_fn, void *arg);
int render_io_stream (struct render *ctx, FILE *fh);
#endif /* RENDER_H */