From d6cfecdc224e95f1379f918d642074eada40627f Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Tue, 23 Nov 2010 13:14:16 -0500 Subject: Implement pigment maps. --- libdimension/dimension/array.h | 14 ++++++++++++++ libdimension/dimension/map.h | 7 +++++++ libdimension/dimension/pigments.h | 15 +++++++++++++++ 3 files changed, 36 insertions(+) (limited to 'libdimension/dimension') diff --git a/libdimension/dimension/array.h b/libdimension/dimension/array.h index 10afa9c..c789eed 100644 --- a/libdimension/dimension/array.h +++ b/libdimension/dimension/array.h @@ -227,6 +227,20 @@ dmnsn_array_remove(dmnsn_array *array, size_t i) dmnsn_array_resize(array, size - 1); } +/** + * Apply a callback to each element of an array. + * @param[in,out] array The array. + * @param[in] callback The callback to apply to the elements. + */ +DMNSN_INLINE void +dmnsn_array_apply(dmnsn_array *array, dmnsn_callback_fn *callback) +{ + char *i, *last = (char *)dmnsn_array_last(array); + for (i = (char *)dmnsn_array_first(array); i <= last; i += array->obj_size) { + (*callback)((void *)i); + } +} + /* Macros to shorten array iteration */ /** diff --git a/libdimension/dimension/map.h b/libdimension/dimension/map.h index 1cd0f55..5e7134d 100644 --- a/libdimension/dimension/map.h +++ b/libdimension/dimension/map.h @@ -73,4 +73,11 @@ size_t dmnsn_map_size(const dmnsn_map *map); void dmnsn_evaluate_map(const dmnsn_map *map, double n, double *val, void *obj1, void *obj2); +/** + * Apply a callback to each element of a map. + * @param[in,out] map The map. + * @param[in] callback The callback to apply to the elements. + */ +void dmnsn_map_apply(dmnsn_map *map, dmnsn_callback_fn *callback); + #endif /* DIMENSION_MAP_H */ diff --git a/libdimension/dimension/pigments.h b/libdimension/dimension/pigments.h index 687080f..aa2c7c3 100644 --- a/libdimension/dimension/pigments.h +++ b/libdimension/dimension/pigments.h @@ -56,4 +56,19 @@ dmnsn_map *dmnsn_new_color_map(); dmnsn_pigment *dmnsn_new_color_map_pigment(dmnsn_pattern *pattern, dmnsn_map *map); +/** + * Construct a pigment map. + * @return An empty pigment map. + */ +dmnsn_map *dmnsn_new_pigment_map(); + +/** + * A pigment-mapped pigment. + * @param[in,out] pattern The pattern of the pigment. + * @param[in,out] map The pigment map to apply to the pattern. + * @return A pigment mapping the pattern to other pigments. + */ +dmnsn_pigment *dmnsn_new_pigment_map_pigment(dmnsn_pattern *pattern, + dmnsn_map *map); + #endif /* DIMENSION_PIGMENTS_H */ -- cgit v1.2.3