summaryrefslogtreecommitdiffstats
path: root/libdimension/canvas.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2009-07-04 21:53:55 +0000
committerTavian Barnes <tavianator@gmail.com>2009-07-04 21:53:55 +0000
commit8085395acc28d8c77901615f8862ceeda5773b09 (patch)
treec8261638a486191a3c2cea1ed91590f8104878c7 /libdimension/canvas.c
parentd3ad0b6a25146318d153ecd6c792e41a9a0a6025 (diff)
downloaddimension-8085395acc28d8c77901615f8862ceeda5773b09.tar.xz
New interface for optimizing canvas conversions by registering
dmnsn_set_pixel() callbacks.
Diffstat (limited to 'libdimension/canvas.c')
-rw-r--r--libdimension/canvas.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/libdimension/canvas.c b/libdimension/canvas.c
index 8d37c73..d53c7ef 100644
--- a/libdimension/canvas.c
+++ b/libdimension/canvas.c
@@ -40,6 +40,9 @@ dmnsn_new_canvas(unsigned int x, unsigned int y)
free(canvas);
return NULL;
}
+
+ /* Allocate room for the optimizers */
+ canvas->optimizers = dmnsn_new_array(sizeof(dmnsn_canvas_optimizer));
}
return canvas;
@@ -49,9 +52,45 @@ dmnsn_new_canvas(unsigned int x, unsigned int y)
void
dmnsn_delete_canvas(dmnsn_canvas *canvas)
{
+ unsigned int i;
+ dmnsn_canvas_optimizer optimizer;
+
if (canvas) {
+ /* Free the optimizers */
+ for (i = 0; i < dmnsn_array_size(canvas->optimizers); ++i) {
+ dmnsn_array_get(canvas->optimizers, i, &optimizer);
+ if (optimizer.free_fn) {
+ optimizer.free_fn(optimizer.ptr);
+ }
+ }
+
/* Free the pixels and canvas */
free(canvas->pixels);
free(canvas);
}
}
+
+/* Set a canvas optimizer */
+void
+dmnsn_optimize_canvas(dmnsn_canvas *canvas, dmnsn_canvas_optimizer optimizer)
+{
+ dmnsn_array_push(canvas->optimizers, &optimizer);
+}
+
+/* Set the color of a pixel */
+void
+dmnsn_set_pixel(dmnsn_canvas *canvas, unsigned int x, unsigned int y,
+ dmnsn_color color)
+{
+ unsigned int i;
+ dmnsn_canvas_optimizer optimizer;
+
+ /* Set the pixel */
+ canvas->pixels[y*canvas->x + x] = color;
+
+ /* Call the optimizers */
+ for (i = 0; i < dmnsn_array_size(canvas->optimizers); ++i) {
+ dmnsn_array_get(canvas->optimizers, i, &optimizer);
+ optimizer.optimizer_fn(canvas, optimizer, x, y);
+ }
+}