summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libdimension/canvas.c7
-rw-r--r--libdimension/dimension/canvas.h20
-rw-r--r--libdimension/rgba16.c10
-rw-r--r--libdimension/rgba16.h5
4 files changed, 19 insertions, 23 deletions
diff --git a/libdimension/canvas.c b/libdimension/canvas.c
index 8671402..c7c1994 100644
--- a/libdimension/canvas.c
+++ b/libdimension/canvas.c
@@ -60,9 +60,10 @@ dmnsn_delete_canvas(dmnsn_canvas *canvas)
/* Set a canvas optimizer */
void
-dmnsn_canvas_optimize(dmnsn_canvas *canvas, dmnsn_canvas_optimizer optimizer)
+dmnsn_canvas_optimize(dmnsn_canvas *canvas,
+ const dmnsn_canvas_optimizer *optimizer)
{
- dmnsn_array_push(canvas->optimizers, &optimizer);
+ dmnsn_array_push(canvas->optimizers, optimizer);
}
/* Set the value of a pixel */
@@ -79,7 +80,7 @@ dmnsn_canvas_set_pixel(dmnsn_canvas *canvas, size_t x, size_t y,
/* Call the optimizers */
DMNSN_ARRAY_FOREACH (dmnsn_canvas_optimizer *, i, canvas->optimizers) {
- i->optimizer_fn(canvas, *i, x, y);
+ i->optimizer_fn(canvas, i->ptr, x, y);
}
}
diff --git a/libdimension/dimension/canvas.h b/libdimension/dimension/canvas.h
index 6c6ff86..2000141 100644
--- a/libdimension/dimension/canvas.h
+++ b/libdimension/dimension/canvas.h
@@ -43,27 +43,23 @@ typedef struct dmnsn_canvas {
DMNSN_REFCOUNT; /**< Reference count. */
} dmnsn_canvas;
-/* Forward-declare dmnsn_canvas_optimizer */
-typedef struct dmnsn_canvas_optimizer dmnsn_canvas_optimizer;
-
/**
* Canvas optimizer callback type.
- * @param[in] canvas The canvas that was just updated.
- * @param[in] optimizer The canvas optimizer itself.
- * @param[in] x The x-coordinate that was just updated.
- * @param[in] y The y-coordinate that was just updated.
+ * @param[in] canvas The canvas that was just updated.
+ * @param[in] ptr The canvas optimizer's data pointer.
+ * @param[in] x The x-coordinate that was just updated.
+ * @param[in] y The y-coordinate that was just updated.
*/
-typedef void dmnsn_canvas_optimizer_fn(const dmnsn_canvas *canvas,
- dmnsn_canvas_optimizer optimizer,
+typedef void dmnsn_canvas_optimizer_fn(const dmnsn_canvas *canvas, void *ptr,
size_t x, size_t y);
/** Canvas optimizer. */
-struct dmnsn_canvas_optimizer {
+typedef struct dmnsn_canvas_optimizer {
dmnsn_canvas_optimizer_fn *optimizer_fn; /**< Optimizer callback. */
dmnsn_free_fn *free_fn; /**< Destructor callback. */
void *ptr; /**< Generic pointer. */
-};
+} dmnsn_canvas_optimizer;
/**
* Allocate a new canvas.
@@ -85,7 +81,7 @@ void dmnsn_delete_canvas(dmnsn_canvas *canvas);
* @param[in] optimizer The optimizer to use.
*/
void dmnsn_canvas_optimize(dmnsn_canvas *canvas,
- dmnsn_canvas_optimizer optimizer);
+ const dmnsn_canvas_optimizer *optimizer);
/* Pixel accessors */
diff --git a/libdimension/rgba16.c b/libdimension/rgba16.c
index 2c7a8d5..2198677 100644
--- a/libdimension/rgba16.c
+++ b/libdimension/rgba16.c
@@ -41,15 +41,15 @@ dmnsn_rgba16_optimize_canvas(dmnsn_canvas *canvas)
optimizer.free_fn = dmnsn_free;
optimizer.ptr = dmnsn_malloc(4*canvas->width*canvas->height*sizeof(uint16_t));
- dmnsn_canvas_optimize(canvas, optimizer);
+ dmnsn_canvas_optimize(canvas, &optimizer);
}
-/* PNG optimizer callback */
+/* RGBA16 optimizer callback */
void
-dmnsn_rgba16_optimizer_fn(const dmnsn_canvas *canvas,
- dmnsn_canvas_optimizer optimizer, size_t x, size_t y)
+dmnsn_rgba16_optimizer_fn(const dmnsn_canvas *canvas, void *ptr,
+ size_t x, size_t y)
{
- uint16_t *pixel = (uint16_t *)optimizer.ptr + 4*(y*canvas->width + x);
+ uint16_t *pixel = (uint16_t *)ptr + 4*(y*canvas->width + x);
dmnsn_tcolor tcolor = dmnsn_canvas_get_pixel(canvas, x, y);
tcolor = dmnsn_tcolor_remove_filter(tcolor);
tcolor.c = dmnsn_color_to_sRGB(tcolor.c);
diff --git a/libdimension/rgba16.h b/libdimension/rgba16.h
index 24af74a..86f5bf7 100644
--- a/libdimension/rgba16.h
+++ b/libdimension/rgba16.h
@@ -20,13 +20,12 @@
/**
* @file
- * 16-bit RGBA canvas optimizer interface, shared between PNG and GL optimizers.
+ * 16-bit RGBA canvas optimizer interface, used by image optimizers.
*/
/** Apply the rgba16 optimizer to a canvas. */
void dmnsn_rgba16_optimize_canvas(dmnsn_canvas *canvas);
/** RGBA16 optimizer callback. */
-void dmnsn_rgba16_optimizer_fn(const dmnsn_canvas *canvas,
- dmnsn_canvas_optimizer optimizer,
+void dmnsn_rgba16_optimizer_fn(const dmnsn_canvas *canvas, void *ptr,
size_t x, size_t y);