From 8085395acc28d8c77901615f8862ceeda5773b09 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Sat, 4 Jul 2009 21:53:55 +0000 Subject: New interface for optimizing canvas conversions by registering dmnsn_set_pixel() callbacks. --- libdimension/dimension/canvas.h | 36 ++++++++++++++++++++++++------------ libdimension/dimension/gl.h | 3 ++- libdimension/dimension/png.h | 3 +++ 3 files changed, 29 insertions(+), 13 deletions(-) (limited to 'libdimension/dimension') diff --git a/libdimension/dimension/canvas.h b/libdimension/dimension/canvas.h index 4c94c33..a14333d 100644 --- a/libdimension/dimension/canvas.h +++ b/libdimension/dimension/canvas.h @@ -34,12 +34,34 @@ typedef struct { * at (a,b) is accessible as pixels[b*x + a]. */ dmnsn_color *pixels; + + /* An array of dmnsn_canvas_optimizer's */ + dmnsn_array *optimizers; } dmnsn_canvas; +typedef struct dmnsn_canvas_optimizer dmnsn_canvas_optimizer; + +/* Canvas optimizer callback types */ +typedef void dmnsn_canvas_optimizer_fn(dmnsn_canvas *canvas, + dmnsn_canvas_optimizer optimizer, + unsigned int x, unsigned int y); +typedef void dmnsn_canvas_optimizer_free_fn(void *ptr); + +/* Canvas optimizer */ +struct dmnsn_canvas_optimizer { + dmnsn_canvas_optimizer_fn *optimizer_fn; + dmnsn_canvas_optimizer_free_fn *free_fn; + void *ptr; +}; + /* Allocate and free a canvas */ dmnsn_canvas *dmnsn_new_canvas(unsigned int x, unsigned int y); void dmnsn_delete_canvas(dmnsn_canvas *canvas); +/* Set a canvas optimizer */ +void dmnsn_optimize_canvas(dmnsn_canvas *canvas, + dmnsn_canvas_optimizer optimizer); + /* Pixel accessors */ DMNSN_INLINE dmnsn_color @@ -48,17 +70,7 @@ dmnsn_get_pixel(const dmnsn_canvas *canvas, unsigned int x, unsigned int y) return canvas->pixels[y*canvas->x + x]; } -DMNSN_INLINE void -dmnsn_set_pixel(dmnsn_canvas *canvas, - unsigned int x, unsigned int y, dmnsn_color color) -{ - canvas->pixels[y*canvas->x + x] = color; -} - -DMNSN_INLINE dmnsn_color * -dmnsn_pixel_at(dmnsn_canvas *canvas, unsigned int x, unsigned int y) -{ - return canvas->pixels + y*canvas->x + x; -} +void dmnsn_set_pixel(dmnsn_canvas *canvas, unsigned int x, unsigned int y, + dmnsn_color color); #endif /* DIMENSION_CANVAS_H */ diff --git a/libdimension/dimension/gl.h b/libdimension/dimension/gl.h index f7de782..f81f662 100644 --- a/libdimension/dimension/gl.h +++ b/libdimension/dimension/gl.h @@ -26,7 +26,8 @@ #ifndef DIMENSION_GL_H #define DIMENSION_GL_H -#include +/* Optimize canvas for GL drawing */ +int dmnsn_gl_optimize_canvas(dmnsn_canvas *canvas); /* Write canvas to GL framebuffer. Returns 0 on success, nonzero on failure. */ int dmnsn_gl_write_canvas(const dmnsn_canvas *canvas); diff --git a/libdimension/dimension/png.h b/libdimension/dimension/png.h index 858f79f..f1b1470 100644 --- a/libdimension/dimension/png.h +++ b/libdimension/dimension/png.h @@ -27,6 +27,9 @@ #include +/* Optimize canvas for PNG exporting */ +int dmnsn_png_optimize_canvas(dmnsn_canvas *canvas); + /* Write canvas to file in PNG format. Returns 0 on success, nonzero on failure */ int dmnsn_png_write_canvas(const dmnsn_canvas *canvas, FILE *file); -- cgit v1.2.3