terom@11: #include terom@1: #include terom@1: terom@18: #include "render_struct.h" terom@1: #include "render.h" terom@1: terom@23: int render_init (struct render *ctx) { terom@1: memset(ctx, 0, sizeof(*ctx)); terom@23: terom@23: return 0; terom@1: } terom@1: terom@11: struct render *render_alloc () { terom@11: struct render *ctx; terom@11: terom@11: if (!(ctx = calloc(1, sizeof(struct render)))) terom@11: return NULL; terom@11: terom@11: return ctx; terom@11: } terom@11: terom@21: void render_free(struct render *ctx) { terom@21: free(ctx); terom@21: } terom@21: terom@11: int render_set_mode (struct render *ctx, int mode) { terom@1: if (mode != RENDER_RAW && mode != RENDER_PNG) terom@11: return -1; terom@1: terom@1: ctx->mode = mode; terom@1: terom@11: return 0; terom@1: } terom@1: terom@11: int render_set_size (struct render *ctx, u_int32_t img_w, u_int32_t img_h) { terom@1: if (img_w == 0 || img_h == 0) terom@11: return -1; terom@1: terom@1: ctx->img_w = img_w; terom@1: ctx->img_h = img_h; terom@1: terom@22: // default render region... terom@22: ctx->img_left = ctx->img_top = 0; terom@22: ctx->img_right = img_w; terom@22: ctx->img_bottom = img_h; terom@22: ctx->img_x_step = ctx->img_y_step = 1; terom@22: terom@11: return 0; terom@1: } terom@1: terom@11: int render_get_size (struct render *ctx, u_int32_t *img_w, u_int32_t *img_h) { terom@11: *img_w = ctx->img_w; terom@11: *img_h = ctx->img_h; terom@11: terom@11: return 0; terom@11: } terom@11: terom@11: int render_region_full (struct render *ctx) { terom@1: return render_region_raw(ctx, REGION_X1, REGION_Y1, REGION_X2, REGION_Y2); terom@1: } terom@1: terom@11: int render_region_raw (struct render *ctx, double x1, double y1, double x2, double y2) { terom@1: if ((x1 >= x2) || (y1 >= y2)) terom@11: return -1; terom@1: terom@1: ctx->x1 = x1; terom@1: ctx->y1 = y1; terom@1: ctx->x2 = x2; terom@1: ctx->y2 = y2; terom@1: terom@11: return 0; terom@1: } terom@1: terom@11: int render_io_custom (struct render *ctx, render_ctx_write_cb write_fn, render_ctx_flush_cb flush_fn, void *arg) { terom@1: if (!write_fn) terom@11: return -1; terom@1: terom@1: ctx->io_write_fn = write_fn; terom@1: ctx->io_flush_fn = flush_fn; terom@11: ctx->cb_arg = arg; terom@1: terom@11: return 0; terom@1: } terom@1: terom@11: int render_io_stream (struct render *ctx, FILE *fh) { terom@1: if (!fh) terom@11: return -1; terom@1: terom@1: ctx->io_stream = fh; terom@1: terom@11: return 0; terom@1: } terom@1: terom@11: int render_local_mem (struct render *ctx, unsigned char **rowbuf_addr, render_ctx_row_cb row_fn, void *arg) { terom@11: ctx->local_rowbuf_addr = rowbuf_addr; terom@11: ctx->local_row_fn = row_fn; terom@11: ctx->cb_arg = arg; terom@11: terom@11: return 0; terom@11: } terom@11: