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 | |
parent | b49cf79b57af160ba190fea76d7143cce3428985 (diff) | |
download | dimension-d6cfecdc224e95f1379f918d642074eada40627f.tar.xz |
Implement pigment maps.
Diffstat (limited to 'libdimension')
-rw-r--r-- | libdimension/Makefile.am | 1 | ||||
-rw-r--r-- | libdimension/dimension.h | 6 | ||||
-rw-r--r-- | libdimension/dimension/array.h | 14 | ||||
-rw-r--r-- | libdimension/dimension/map.h | 7 | ||||
-rw-r--r-- | libdimension/dimension/pigments.h | 15 | ||||
-rw-r--r-- | libdimension/map.c | 9 |
6 files changed, 52 insertions, 0 deletions
diff --git a/libdimension/Makefile.am b/libdimension/Makefile.am index e56a22b..8b55e64 100644 --- a/libdimension/Makefile.am +++ b/libdimension/Makefile.am @@ -81,6 +81,7 @@ libdimension_la_SOURCES = $(nobase_include_HEADERS) \ pattern.c \ perspective.c \ phong.c \ + pigment_map.c \ plane.c \ platform.c \ platform.h \ diff --git a/libdimension/dimension.h b/libdimension/dimension.h index fb8efb5..e190de3 100644 --- a/libdimension/dimension.h +++ b/libdimension/dimension.h @@ -47,6 +47,12 @@ extern "C" { /* Common types */ /** + * Generic callback type. + * @param[in,out] ptr A pointer to an object to act on. + */ +typedef void dmnsn_callback_fn(void *ptr); + +/** * Destructor callback type. * @param[in,out] ptr The pointer to free. */ 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 */ diff --git a/libdimension/map.c b/libdimension/map.c index 3ea4b0c..ba1adb6 100644 --- a/libdimension/map.c +++ b/libdimension/map.c @@ -124,3 +124,12 @@ dmnsn_evaluate_map(const dmnsn_map *map, double n, memcpy(obj1, o2, map->obj_size); memcpy(obj2, o2, map->obj_size); } + +void +dmnsn_map_apply(dmnsn_map *map, dmnsn_callback_fn *callback) +{ + for (size_t i = 0; i < dmnsn_array_size(map->array); ++i) { + dmnsn_map_entry *entry = dmnsn_array_at(map->array, i); + (*callback)(entry->object); + } +} |