diff options
author | Tavian Barnes <tavianator@gmail.com> | 2010-11-23 13:14:16 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2010-11-23 13:14:16 -0500 |
commit | d6cfecdc224e95f1379f918d642074eada40627f (patch) | |
tree | a51324383ad8f1cf5d968ba41690d1f7ac7cbad5 /libdimension/dimension | |
parent | b49cf79b57af160ba190fea76d7143cce3428985 (diff) | |
download | dimension-d6cfecdc224e95f1379f918d642074eada40627f.tar.xz |
Implement pigment maps.
Diffstat (limited to 'libdimension/dimension')
-rw-r--r-- | libdimension/dimension/array.h | 14 | ||||
-rw-r--r-- | libdimension/dimension/map.h | 7 | ||||
-rw-r--r-- | libdimension/dimension/pigments.h | 15 |
3 files changed, 36 insertions, 0 deletions
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 */ |