summaryrefslogtreecommitdiffstats
path: root/libdimension/pigment.c
diff options
context:
space:
mode:
Diffstat (limited to 'libdimension/pigment.c')
-rw-r--r--libdimension/pigment.c30
1 files changed, 20 insertions, 10 deletions
diff --git a/libdimension/pigment.c b/libdimension/pigment.c
index 6134c2b..e392d7b 100644
--- a/libdimension/pigment.c
+++ b/libdimension/pigment.c
@@ -25,19 +25,32 @@
#include "dimension-internal.h"
+static void
+dmnsn_default_pigment_free_fn(dmnsn_pigment *pigment)
+{
+ dmnsn_free(pigment);
+}
+
/* Allocate a dummy pigment */
dmnsn_pigment *
dmnsn_new_pigment(void)
{
dmnsn_pigment *pigment = DMNSN_MALLOC(dmnsn_pigment);
- pigment->pigment_fn = NULL;
+ dmnsn_init_pigment(pigment);
+ return pigment;
+}
+
+/* Initialize a pigment */
+void
+dmnsn_init_pigment(dmnsn_pigment *pigment)
+{
+ pigment->pigment_fn = NULL;
pigment->initialize_fn = NULL;
- pigment->free_fn = NULL;
- pigment->trans = dmnsn_identity_matrix();
- pigment->quick_color = DMNSN_TCOLOR(dmnsn_black);
- pigment->initialized = false;
+ pigment->free_fn = dmnsn_default_pigment_free_fn;
+ pigment->trans = dmnsn_identity_matrix();
+ pigment->quick_color = DMNSN_TCOLOR(dmnsn_black);
+ pigment->initialized = false;
DMNSN_REFCOUNT_INIT(pigment);
- return pigment;
}
/* Free a pigment */
@@ -45,10 +58,7 @@ void
dmnsn_delete_pigment(dmnsn_pigment *pigment)
{
if (DMNSN_DECREF(pigment)) {
- if (pigment->free_fn) {
- pigment->free_fn(pigment->ptr);
- }
- dmnsn_free(pigment);
+ pigment->free_fn(pigment);
}
}