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 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) (limited to 'libdimension/dimension/canvas.h') 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 */ -- cgit v1.2.3