diff options
Diffstat (limited to 'source/blender/blenlib')
26 files changed, 325 insertions, 253 deletions
diff --git a/source/blender/blenlib/BLI_array.h b/source/blender/blenlib/BLI_array.h index 825acb18e91..8e94b8197ef 100644 --- a/source/blender/blenlib/BLI_array.h +++ b/source/blender/blenlib/BLI_array.h @@ -62,9 +62,10 @@ * Doing the realloc in a macro isn't so simple, * so use a function the macros can use. */ -void _bli_array_grow_func(void **arr_p, const void *arr_static, - const int sizeof_arr_p, const int arr_count, const int num, - const char *alloc_str); +void _bli_array_grow_func( + void **arr_p, const void *arr_static, + const int sizeof_arr_p, const int arr_len, const int num, + const char *alloc_str); /* -------------------------------------------------------------------- */ @@ -74,18 +75,18 @@ void _bli_array_grow_func(void **arr_p, const void *arr_static, /** use ``sizeof(*(arr))`` to ensure the array exists and is an array */ #define BLI_array_declare(arr) \ - int _##arr##_count = ((void)(sizeof(*(arr))), 0); \ + int _##arr##_len = ((void)(sizeof(*(arr))), 0); \ void *_##arr##_static = NULL /** * this will use stack space, up to maxstatic array elements, before * switching to dynamic heap allocation */ #define BLI_array_staticdeclare(arr, maxstatic) \ - int _##arr##_count = 0; \ + int _##arr##_len = 0; \ char _##arr##_static[maxstatic * sizeof(*(arr))] /** returns the logical size of the array, not including buffering. */ -#define BLI_array_count(arr) ((void)0, _##arr##_count) +#define BLI_array_len(arr) ((void)0, _##arr##_len) /** * Grow the array by a fixed number of items. @@ -95,23 +96,23 @@ void _bli_array_grow_func(void **arr_p, const void *arr_static, #define BLI_array_reserve(arr, num) (void)( \ (((void *)(arr) == NULL) && \ ((void *)(_##arr##_static) != NULL) && \ - /* don't add _##arr##_count below because it must be zero */ \ - (_bli_array_totalsize_static(arr) >= _##arr##_count + (num))) ? \ + /* don't add _##arr##_len below because it must be zero */ \ + (_bli_array_totalsize_static(arr) >= _##arr##_len + (num))) ? \ /* we have an empty array and a static var big enough */ \ (void)(arr = (void *)_##arr##_static) \ : \ /* use existing static array or allocate */ \ - (LIKELY(_bli_array_totalsize(arr) >= _##arr##_count + (num)) ? \ + (LIKELY(_bli_array_totalsize(arr) >= _##arr##_len + (num)) ? \ (void)0 /* do nothing */ : \ _bli_array_grow_func((void **)&(arr), _##arr##_static, \ - sizeof(*(arr)), _##arr##_count, num, \ + sizeof(*(arr)), _##arr##_len, num, \ "BLI_array." #arr)) \ ) /** returns length of array */ #define BLI_array_grow_items(arr, num) \ - (BLI_array_reserve(arr, num), (_##arr##_count += num)) + (BLI_array_reserve(arr, num), (_##arr##_len += num)) #define BLI_array_grow_one(arr) \ BLI_array_grow_items(arr, 1) @@ -119,7 +120,7 @@ void _bli_array_grow_func(void **arr_p, const void *arr_static, /** appends an item to the array. */ #define BLI_array_append(arr, item) ( \ (void) BLI_array_grow_one(arr), \ - (void) (arr[_##arr##_count - 1] = item) \ + (void) (arr[_##arr##_len - 1] = item) \ ) /** @@ -127,13 +128,13 @@ void _bli_array_grow_func(void **arr_p, const void *arr_static, * item is not a pointer, but actual data value.*/ #define BLI_array_append_r(arr, item) ( \ (void) BLI_array_grow_one(arr), \ - (void) (arr[_##arr##_count - 1] = item), \ - (&arr[_##arr##_count - 1]) \ + (void) (arr[_##arr##_len - 1] = item), \ + (&arr[_##arr##_len - 1]) \ ) /** appends (grows) & returns a pointer to the uninitialized memory */ #define BLI_array_append_ret(arr) \ - (BLI_array_reserve(arr, 1), &arr[(_##arr##_count++)]) + (BLI_array_reserve(arr, 1), &arr[(_##arr##_len++)]) #define BLI_array_free(arr) { \ if (arr && (char *)arr != _##arr##_static) { \ @@ -143,26 +144,26 @@ void _bli_array_grow_func(void **arr_p, const void *arr_static, } ((void)0) #define BLI_array_pop(arr) ( \ - (arr && _##arr##_count) ? \ - arr[--_##arr##_count] : \ + (arr && _##arr##_len) ? \ + arr[--_##arr##_len] : \ NULL \ ) /** - * resets the logical size of an array to zero, but doesn't + * Resets the logical size of an array to zero, but doesn't * free the memory. */ #define BLI_array_clear(arr) \ - { _##arr##_count = 0; } (void)0 + { _##arr##_len = 0; } ((void)0) /** - * set the count of the array, doesn't actually increase the allocated array + * Set the length of the array, doesn't actually increase the allocated array * size. don't use this unless you know what you're doing. */ -#define BLI_array_count_set(arr, count) \ - { _##arr##_count = (count); }(void)0 +#define BLI_array_len_set(arr, len) \ + { _##arr##_len = (len); } ((void)0) /** only to prevent unused warnings */ #define BLI_array_fake_user(arr) \ - ((void)_##arr##_count, \ + ((void)_##arr##_len, \ (void)_##arr##_static) /** \} */ @@ -191,7 +192,7 @@ void _bli_array_grow_func(void **arr_p, const void *arr_static, #define BLI_array_fixedstack_free(arr) \ if (_##arr##_is_static) { \ MEM_freeN(arr); \ - } (void)0 + } ((void)0) /** \} */ diff --git a/source/blender/blenlib/BLI_assert.h b/source/blender/blenlib/BLI_assert.h new file mode 100644 index 00000000000..9fb0954e77f --- /dev/null +++ b/source/blender/blenlib/BLI_assert.h @@ -0,0 +1,111 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#ifndef __BLI_ASSERT_H__ +#define __BLI_ASSERT_H__ + +/** \file BLI_assert.h + * \ingroup bli + * + * Defines: + * - #BLI_assert + * - #BLI_STATIC_ASSERT + * - #BLI_STATIC_ASSERT_ALIGN + */ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef NDEBUG /* for BLI_assert */ +#include <stdio.h> +#endif + +/* BLI_assert(), default only to print + * for aborting need to define WITH_ASSERT_ABORT + */ +/* For 'abort' only. */ +#include <stdlib.h> + +#ifndef NDEBUG +# include "BLI_system.h" +# ifdef WITH_ASSERT_ABORT +# define _BLI_DUMMY_ABORT abort +# else +# define _BLI_DUMMY_ABORT() (void)0 +# endif +# if defined(__GNUC__) || defined(_MSC_VER) /* check __func__ is available */ +# define BLI_assert(a) \ + (void)((!(a)) ? ( \ + ( \ + BLI_system_backtrace(stderr), \ + fprintf(stderr, \ + "BLI_assert failed: %s:%d, %s(), at \'%s\'\n", \ + __FILE__, __LINE__, __func__, "" #a), \ + _BLI_DUMMY_ABORT(), \ + NULL)) : NULL) +# else +# define BLI_assert(a) \ + (void)((!(a)) ? ( \ + ( \ + fprintf(stderr, \ + "BLI_assert failed: %s:%d, at \'%s\'\n", \ + __FILE__, __LINE__, "" #a), \ + _BLI_DUMMY_ABORT(), \ + NULL)) : NULL) +# endif +#else +# define BLI_assert(a) (void)0 +#endif + +/* C++ can't use _Static_assert, expects static_assert() but c++0x only, + * Coverity also errors out. */ +#if (!defined(__cplusplus)) && \ + (!defined(__COVERITY__)) && \ + (defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 406)) /* gcc4.6+ only */ +# define BLI_STATIC_ASSERT(a, msg) __extension__ _Static_assert(a, msg); +#else +/* Code adapted from http://www.pixelbeat.org/programming/gcc/static_assert.html */ +/* Note we need the two concats below because arguments to ## are not expanded, so we need to + * expand __LINE__ with one indirection before doing the actual concatenation. */ +# define ASSERT_CONCAT_(a, b) a##b +# define ASSERT_CONCAT(a, b) ASSERT_CONCAT_(a, b) + /* These can't be used after statements in c89. */ +# if defined(__COUNTER__) /* MSVC */ +# define BLI_STATIC_ASSERT(a, msg) \ + ; enum { ASSERT_CONCAT(static_assert_, __COUNTER__) = 1 / (int)(!!(a)) }; +# else /* older gcc, clang... */ + /* This can't be used twice on the same line so ensure if using in headers + * that the headers are not included twice (by wrapping in #ifndef...#endif) + * Note it doesn't cause an issue when used on same line of separate modules + * compiled with gcc -combine -fwhole-program. */ +# define BLI_STATIC_ASSERT(a, msg) \ + ; enum { ASSERT_CONCAT(assert_line_, __LINE__) = 1 / (int)(!!(a)) }; +# endif +#endif + +#define BLI_STATIC_ASSERT_ALIGN(st, align) \ + BLI_STATIC_ASSERT((sizeof(st) % (align) == 0), "Structure must be strictly aligned") + +#ifdef __cplusplus +} +#endif + +#endif /* __BLI_ASSERT_H__ */ diff --git a/source/blender/blenlib/BLI_console.h b/source/blender/blenlib/BLI_console.h new file mode 100644 index 00000000000..bf433f78f70 --- /dev/null +++ b/source/blender/blenlib/BLI_console.h @@ -0,0 +1,42 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2018 Blender Foundation. + * All rights reserved. + * + * Contributor(s): Srrgey Sharybin. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#ifndef __BLI_CONSOLE_H__ +#define __BLI_CONSOLE_H__ + +/** \file BLI_console.h + * \ingroup bli + * \brief Set of utility functions and constants to work with consoles. + */ + +/* Format string where one could BLI_snprintf() R, G and B values + * and get proper marker to start colored output in the console. + */ +#define TRUECOLOR_ANSI_COLOR_FORMAT "\x1b[38;2;%d;%d;%dm" + +/* Marker which indicates that colored output is finished. */ +#define TRUECOLOR_ANSI_COLOR_FINISH "\x1b[0m" + +#endif /* __BLI_CONSOLE_H__ */ diff --git a/source/blender/blenlib/BLI_ghash.h b/source/blender/blenlib/BLI_ghash.h index ec591c6bb48..7003eb039dd 100644 --- a/source/blender/blenlib/BLI_ghash.h +++ b/source/blender/blenlib/BLI_ghash.h @@ -199,6 +199,8 @@ void BLI_gset_clear(GSet *gs, GSetKeyFreeFP keyfreefp); void *BLI_gset_lookup(GSet *gh, const void *key) ATTR_WARN_UNUSED_RESULT; void *BLI_gset_pop_key(GSet *gs, const void *key) ATTR_WARN_UNUSED_RESULT; +/** \} */ + /** \name GSet Iterator * \{ */ @@ -286,7 +288,7 @@ double BLI_gset_calc_quality(GSet *gs); * * \note '_p' suffix denotes void pointer arg, * so we can have functions that take correctly typed args too. - * \{ */ + */ unsigned int BLI_ghashutil_ptrhash(const void *key); bool BLI_ghashutil_ptrcmp(const void *a, const void *b); diff --git a/source/blender/blenlib/BLI_hash.h b/source/blender/blenlib/BLI_hash.h index fa79481e25c..f74010479a9 100644 --- a/source/blender/blenlib/BLI_hash.h +++ b/source/blender/blenlib/BLI_hash.h @@ -68,4 +68,16 @@ BLI_INLINE float BLI_hash_int_01(unsigned int k) return (float)BLI_hash_int(k) * (1.0f / (float)0xFFFFFFFF); } +BLI_INLINE void BLI_hash_pointer_to_color(const void *ptr, int *r, int *g, int *b) +{ + size_t val = (size_t)ptr; + const size_t hash_a = BLI_hash_int(val & 0x0000ffff); + const size_t hash_b = BLI_hash_int((uint)((val & 0xffff0000) >> 32)); + const size_t hash = + hash_a ^ (hash_b + 0x9e3779b9 + (hash_a << 6) + (hash_a >> 2)); + *r = (hash & 0xff0000) >> 16; + *g = (hash & 0x00ff00) >> 8; + *b = hash & 0x0000ff; +} + #endif // __BLI_HASH_H__ diff --git a/source/blender/blenlib/BLI_iterator.h b/source/blender/blenlib/BLI_iterator.h index 49a3cea58bc..d3d375122a1 100644 --- a/source/blender/blenlib/BLI_iterator.h +++ b/source/blender/blenlib/BLI_iterator.h @@ -57,6 +57,6 @@ typedef void (*IteratorBeginCb)(BLI_Iterator *iter, void *data_in); #define ITER_END \ } \ callback_end_func(&iter_macro); \ -} +} ((void)0) #endif /* __BLI_ITERATOR_H__ */ diff --git a/source/blender/blenlib/BLI_link_utils.h b/source/blender/blenlib/BLI_link_utils.h index d469b105f93..5322547ac08 100644 --- a/source/blender/blenlib/BLI_link_utils.h +++ b/source/blender/blenlib/BLI_link_utils.h @@ -35,6 +35,18 @@ list = link; \ } (void)0 +/* Use for append (single linked list, storing the last element). */ +#define BLI_LINKS_APPEND(list, link) { \ + (link)->next = NULL; \ + if ((list)->first) { \ + (list)->last->next = link; \ + } \ + else { \ + (list)->first = link; \ + } \ + (list)->last = link; \ +} (void)0 + #define BLI_LINKS_FREE(list) { \ while (list) { \ void *next = list->next; \ diff --git a/source/blender/blenlib/BLI_math_base.h b/source/blender/blenlib/BLI_math_base.h index 3b24cae018d..6f8e48d83b2 100644 --- a/source/blender/blenlib/BLI_math_base.h +++ b/source/blender/blenlib/BLI_math_base.h @@ -35,6 +35,7 @@ #endif #include <math.h> +#include "BLI_assert.h" #include "BLI_math_inline.h" #ifndef M_PI diff --git a/source/blender/blenlib/BLI_polyfill_2d_beautify.h b/source/blender/blenlib/BLI_polyfill_2d_beautify.h index 278771e9611..73b52125904 100644 --- a/source/blender/blenlib/BLI_polyfill_2d_beautify.h +++ b/source/blender/blenlib/BLI_polyfill_2d_beautify.h @@ -18,8 +18,8 @@ * ***** END GPL LICENSE BLOCK ***** */ -#ifndef __BLI_POLYFILL2D_BEAUTIFY_H__ -#define __BLI_POLYFILL2D_BEAUTIFY_H__ +#ifndef __BLI_POLYFILL_2D_BEAUTIFY_H__ +#define __BLI_POLYFILL_2D_BEAUTIFY_H__ struct Heap; struct MemArena; @@ -42,4 +42,4 @@ float BLI_polyfill_beautify_quad_rotate_calc_ex( /* avoid realloc's when creating new structures for polyfill ngons */ #define BLI_POLYFILL_ALLOC_NGON_RESERVE 64 -#endif /* __BLI_POLYFILL2D_BEAUTIFY_H__ */ +#endif /* __BLI_POLYFILL_2D_BEAUTIFY_H__ */ diff --git a/source/blender/blenlib/BLI_utildefines.h b/source/blender/blenlib/BLI_utildefines.h index ee1acc5afdd..11c8a586784 100644 --- a/source/blender/blenlib/BLI_utildefines.h +++ b/source/blender/blenlib/BLI_utildefines.h @@ -41,9 +41,8 @@ extern "C" { #include "BLI_compiler_compat.h" #include "BLI_utildefines_variadic.h" -#ifndef NDEBUG /* for BLI_assert */ -#include <stdio.h> -#endif +/* We could remove in future. */ +#include "BLI_assert.h" /* useful for finding bad use of min/max */ #if 0 @@ -615,74 +614,6 @@ extern bool BLI_memory_is_zero(const void *arr, const size_t arr_size); # define UNUSED_VARS_NDEBUG UNUSED_VARS #endif - -/* BLI_assert(), default only to print - * for aborting need to define WITH_ASSERT_ABORT - */ -/* For 'abort' only. */ -#include <stdlib.h> - -#ifndef NDEBUG -# include "BLI_system.h" -# ifdef WITH_ASSERT_ABORT -# define _BLI_DUMMY_ABORT abort -# else -# define _BLI_DUMMY_ABORT() (void)0 -# endif -# if defined(__GNUC__) || defined(_MSC_VER) /* check __func__ is available */ -# define BLI_assert(a) \ - (void)((!(a)) ? ( \ - ( \ - BLI_system_backtrace(stderr), \ - fprintf(stderr, \ - "BLI_assert failed: %s:%d, %s(), at \'%s\'\n", \ - __FILE__, __LINE__, __func__, STRINGIFY(a)), \ - _BLI_DUMMY_ABORT(), \ - NULL)) : NULL) -# else -# define BLI_assert(a) \ - (void)((!(a)) ? ( \ - ( \ - fprintf(stderr, \ - "BLI_assert failed: %s:%d, at \'%s\'\n", \ - __FILE__, __LINE__, STRINGIFY(a)), \ - _BLI_DUMMY_ABORT(), \ - NULL)) : NULL) -# endif -#else -# define BLI_assert(a) (void)0 -#endif - -/* C++ can't use _Static_assert, expects static_assert() but c++0x only, - * Coverity also errors out. */ -#if (!defined(__cplusplus)) && \ - (!defined(__COVERITY__)) && \ - (defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 406)) /* gcc4.6+ only */ -# define BLI_STATIC_ASSERT(a, msg) __extension__ _Static_assert(a, msg); -#else -/* Code adapted from http://www.pixelbeat.org/programming/gcc/static_assert.html */ -/* Note we need the two concats below because arguments to ## are not expanded, so we need to - * expand __LINE__ with one indirection before doing the actual concatenation. */ -# define ASSERT_CONCAT_(a, b) a##b -# define ASSERT_CONCAT(a, b) ASSERT_CONCAT_(a, b) - /* These can't be used after statements in c89. */ -# if defined(__COUNTER__) /* MSVC */ -# define BLI_STATIC_ASSERT(a, msg) \ - ; enum { ASSERT_CONCAT(static_assert_, __COUNTER__) = 1 / (int)(!!(a)) }; -# else /* older gcc, clang... */ - /* This can't be used twice on the same line so ensure if using in headers - * that the headers are not included twice (by wrapping in #ifndef...#endif) - * Note it doesn't cause an issue when used on same line of separate modules - * compiled with gcc -combine -fwhole-program. */ -# define BLI_STATIC_ASSERT(a, msg) \ - ; enum { ASSERT_CONCAT(assert_line_, __LINE__) = 1 / (int)(!!(a)) }; -# endif -#endif - - -#define BLI_STATIC_ASSERT_ALIGN(st, align) \ - BLI_STATIC_ASSERT((sizeof(st) % (align) == 0), "Structure must be strictly aligned") - /* hints for branch prediction, only use in code that runs a _lot_ where */ #ifdef __GNUC__ # define LIKELY(x) __builtin_expect(!!(x), 1) diff --git a/source/blender/blenlib/BLI_voronoi_2d.h b/source/blender/blenlib/BLI_voronoi_2d.h index 51d1d5aa88e..8d1ff2d4c2b 100644 --- a/source/blender/blenlib/BLI_voronoi_2d.h +++ b/source/blender/blenlib/BLI_voronoi_2d.h @@ -23,8 +23,8 @@ * ***** END GPL LICENSE BLOCK ***** */ -#ifndef __BLI_VORONOI_H__ -#define __BLI_VORONOI_H__ +#ifndef __BLI_VORONOI_2D_H__ +#define __BLI_VORONOI_2D_H__ struct ListBase; @@ -67,4 +67,4 @@ void BLI_voronoi_triangulate(const VoronoiSite *sites, int sites_total, struct L VoronoiTriangulationPoint **triangulated_points_r, int *triangulated_points_total_r, int (**triangles_r)[3], int *triangles_total_r); -#endif /* __BLI_VORONOI_H__ */ +#endif /* __BLI_VORONOI_2D_H__ */ diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt index ef36b5ac6bd..5bcf4303a84 100644 --- a/source/blender/blenlib/CMakeLists.txt +++ b/source/blender/blenlib/CMakeLists.txt @@ -139,6 +139,7 @@ set(SRC BLI_compiler_attrs.h BLI_compiler_compat.h BLI_compiler_typecheck.h + BLI_console.h BLI_convexhull_2d.h BLI_dial_2d.h BLI_dlrbTree.h diff --git a/source/blender/blenlib/intern/BLI_array.c b/source/blender/blenlib/intern/BLI_array.c index f681d222e69..d16dd36763d 100644 --- a/source/blender/blenlib/intern/BLI_array.c +++ b/source/blender/blenlib/intern/BLI_array.c @@ -66,21 +66,23 @@ /** * This function is only to be called via macros. * - * \note The caller must adjust \a arr_count + * \note The caller must adjust \a arr_len */ -void _bli_array_grow_func(void **arr_p, const void *arr_static, - const int sizeof_arr_p, const int arr_count, const int num, - const char *alloc_str) +void _bli_array_grow_func( + void **arr_p, const void *arr_static, + const int sizeof_arr_p, const int arr_len, const int num, + const char *alloc_str) { void *arr = *arr_p; void *arr_tmp; - arr_tmp = MEM_mallocN(sizeof_arr_p * - ((num < arr_count) ? - (arr_count * 2 + 2) : (arr_count + num)), alloc_str); + arr_tmp = MEM_mallocN( + sizeof_arr_p * + ((num < arr_len) ? + (arr_len * 2 + 2) : (arr_len + num)), alloc_str); if (arr) { - memcpy(arr_tmp, arr, sizeof_arr_p * arr_count); + memcpy(arr_tmp, arr, sizeof_arr_p * arr_len); if (arr != arr_static) { MEM_freeN(arr); @@ -91,6 +93,6 @@ void _bli_array_grow_func(void **arr_p, const void *arr_static, /* caller must do */ #if 0 - arr_count += num; + arr_len += num; #endif } diff --git a/source/blender/blenlib/intern/BLI_ghash.c b/source/blender/blenlib/intern/BLI_ghash.c index fc8e786e5ff..ec75c140159 100644 --- a/source/blender/blenlib/intern/BLI_ghash.c +++ b/source/blender/blenlib/intern/BLI_ghash.c @@ -1345,7 +1345,7 @@ void *BLI_gset_lookup(GSet *gs, const void *key) /** * Returns the pointer to the key if it's found, removing it from the GSet. - * \node Caller must handle freeing. + * \note Caller must handle freeing. */ void *BLI_gset_pop_key(GSet *gs, const void *key) { diff --git a/source/blender/blenlib/intern/BLI_kdopbvh.c b/source/blender/blenlib/intern/BLI_kdopbvh.c index d6c58780603..06e8ade68a2 100644 --- a/source/blender/blenlib/intern/BLI_kdopbvh.c +++ b/source/blender/blenlib/intern/BLI_kdopbvh.c @@ -856,9 +856,8 @@ static void non_recursive_bvh_div_nodes_task_cb( else { break; } - - parent->totnode = (char)(k + 1); } + parent->totnode = (char)k; } /** @@ -1924,6 +1923,7 @@ void BLI_bvhtree_ray_cast_all( BLI_bvhtree_ray_cast_all_ex(tree, co, dir, radius, hit_dist, callback, userdata, BVH_RAYCAST_DEFAULT); } +/** \} */ /* -------------------------------------------------------------------- */ diff --git a/source/blender/blenlib/intern/array_store.c b/source/blender/blenlib/intern/array_store.c index acf15b1c892..df93dad4c32 100644 --- a/source/blender/blenlib/intern/array_store.c +++ b/source/blender/blenlib/intern/array_store.c @@ -299,7 +299,7 @@ typedef struct BChunk { } BChunk; /** - * Links to store #BChunk data in #BChunkList.chunks. + * Links to store #BChunk data in #BChunkList.chunk_refs. */ typedef struct BChunkRef { struct BChunkRef *next, *prev; @@ -749,6 +749,7 @@ static void bchunk_list_fill_from_array( ASSERT_CHUNKLIST_DATA(chunk_list, data); } +/** \} */ /* --------------------------------------------------------------------------- * Internal Table Lookup Functions @@ -1013,6 +1014,10 @@ static const BChunkRef *table_lookup( /** \} */ +/** \name Main Data De-Duplication Function + * + * \{ */ + /** * \param data: Data to store in the returned value. * \param data_len_original: Length of data in bytes. @@ -1504,6 +1509,8 @@ void BLI_array_store_clear( BLI_mempool_clear(bs->memory.chunk); } +/** \} */ + /** \name BArrayStore Statistics * \{ */ diff --git a/source/blender/blenlib/intern/boxpack_2d.c b/source/blender/blenlib/intern/boxpack_2d.c index b3beff0b78b..cf9e29209fb 100644 --- a/source/blender/blenlib/intern/boxpack_2d.c +++ b/source/blender/blenlib/intern/boxpack_2d.c @@ -20,7 +20,7 @@ * ***** END GPL LICENSE BLOCK ***** */ -/** \file blender/blenlib/intern/boxpack2d.c +/** \file blender/blenlib/intern/boxpack_2d.c * \ingroup bli */ diff --git a/source/blender/blenlib/intern/jitter_2d.c b/source/blender/blenlib/intern/jitter_2d.c index 6c51eeb36d9..26351f52c7f 100644 --- a/source/blender/blenlib/intern/jitter_2d.c +++ b/source/blender/blenlib/intern/jitter_2d.c @@ -25,7 +25,7 @@ * ***** END GPL LICENSE BLOCK ***** */ -/** \file blender/blenlib/intern/jitter.c +/** \file blender/blenlib/intern/jitter_2d.c * \ingroup bli * \brief Jitter offset table */ diff --git a/source/blender/blenlib/intern/math_base_inline.c b/source/blender/blenlib/intern/math_base_inline.c index 1f517471407..eed06c7841b 100644 --- a/source/blender/blenlib/intern/math_base_inline.c +++ b/source/blender/blenlib/intern/math_base_inline.c @@ -368,10 +368,8 @@ MINLINE int compare_ff_relative(float a, float b, const float max_diff, const in { union {float f; int i;} ua, ub; -#if 0 /* No BLI_assert in INLINE :/ */ BLI_assert(sizeof(float) == sizeof(int)); BLI_assert(max_ulps < (1 << 22)); -#endif if (fabsf(a - b) <= max_diff) { return 1; diff --git a/source/blender/blenlib/intern/math_bits_inline.c b/source/blender/blenlib/intern/math_bits_inline.c index 37fdcd7878a..9b16756134e 100644 --- a/source/blender/blenlib/intern/math_bits_inline.c +++ b/source/blender/blenlib/intern/math_bits_inline.c @@ -34,7 +34,7 @@ MINLINE int bitscan_forward_i(int a) { BLI_assert(a != 0); -# ifdef _MSC_VER +#ifdef _MSC_VER unsigned long ctz; _BitScanForward(&ctz, a); return ctz; @@ -63,7 +63,7 @@ MINLINE unsigned int bitscan_forward_clear_uint(unsigned int *a) MINLINE int bitscan_reverse_i(int a) { BLI_assert(a != 0); -# ifdef _MSC_VER +#ifdef _MSC_VER unsigned long clz; _BitScanReverse(&clz, a); return clz; diff --git a/source/blender/blenlib/intern/math_color.c b/source/blender/blenlib/intern/math_color.c index cb39134af45..534abeb913d 100644 --- a/source/blender/blenlib/intern/math_color.c +++ b/source/blender/blenlib/intern/math_color.c @@ -656,135 +656,80 @@ void rgb_to_lab(float r, float g, float b, float *ll, float *la, float *lb) xyz_to_lab(x, y, z, ll, la, lb); } -static void xyz_to_lms(float x, float y, float z, float *l, float *m, float *s) -{ - *l = 0.3897f * x + 0.6890f * y - 0.0787f * z; - *m = -0.2298f * x + 1.1834f * y + 0.0464f * z; - *s = z; -} - -static void lms_to_xyz(float l, float m, float s, float *x, float *y, float *z) -{ - *x = 1.9102f * l - 1.1121f * m + 0.2019f * s; - *y = 0.3709f * l + 0.6290f * m + 0.0000f * s; - *z = s; -} - -static void normalize_rgb(float rgb[3]) -{ - const float max = max_fff(rgb[0], rgb[1], rgb[2]); +/* ****************************** blackbody ******************************** */ - if (max > 0.0f) { - mul_v3_fl(rgb, 1.0f / max); - } -} - -/* Color rendering of spectra, adapted from public domain code by John Walker, - * http://www.fourmilab.ch/ +/* Calculate color in range 800..12000 using an approximation + * a/x+bx+c for R and G and ((at + b)t + c)t + d) for B + * Max absolute error for RGB is (0.00095, 0.00077, 0.00057), + * which is enough to get the same 8 bit/channel color. */ -static void spectrum_to_xyz(float temperature, float xyz[3]) -{ - int i; - float lambda, x = 0.0f, y = 0.0f, z = 0.0f, xyz_sum; - - /* CIE colour matching functions xBar, yBar, and zBar for wavelengths from - * 380 through 780 nanometers, every 5 nanometers. - * For a wavelength lambda in this range: - * - * cie_colour_match[(lambda - 380) / 5][0] = xBar - * cie_colour_match[(lambda - 380) / 5][1] = yBar - * cie_colour_match[(lambda - 380) / 5][2] = zBar - */ - - const float cie_colour_match[81][3] = { - {0.0014f, 0.0000f, 0.0065f}, {0.0022f, 0.0001f, 0.0105f}, {0.0042f, 0.0001f, 0.0201f}, - {0.0076f, 0.0002f, 0.0362f}, {0.0143f, 0.0004f, 0.0679f}, {0.0232f, 0.0006f, 0.1102f}, - {0.0435f, 0.0012f, 0.2074f}, {0.0776f, 0.0022f, 0.3713f}, {0.1344f, 0.0040f, 0.6456f}, - {0.2148f, 0.0073f, 1.0391f}, {0.2839f, 0.0116f, 1.3856f}, {0.3285f, 0.0168f, 1.6230f}, - {0.3483f, 0.0230f, 1.7471f}, {0.3481f, 0.0298f, 1.7826f}, {0.3362f, 0.0380f, 1.7721f}, - {0.3187f, 0.0480f, 1.7441f}, {0.2908f, 0.0600f, 1.6692f}, {0.2511f, 0.0739f, 1.5281f}, - {0.1954f, 0.0910f, 1.2876f}, {0.1421f, 0.1126f, 1.0419f}, {0.0956f, 0.1390f, 0.8130f}, - {0.0580f, 0.1693f, 0.6162f}, {0.0320f, 0.2080f, 0.4652f}, {0.0147f, 0.2586f, 0.3533f}, - {0.0049f, 0.3230f, 0.2720f}, {0.0024f, 0.4073f, 0.2123f}, {0.0093f, 0.5030f, 0.1582f}, - {0.0291f, 0.6082f, 0.1117f}, {0.0633f, 0.7100f, 0.0782f}, {0.1096f, 0.7932f, 0.0573f}, - {0.1655f, 0.8620f, 0.0422f}, {0.2257f, 0.9149f, 0.0298f}, {0.2904f, 0.9540f, 0.0203f}, - {0.3597f, 0.9803f, 0.0134f}, {0.4334f, 0.9950f, 0.0087f}, {0.5121f, 1.0000f, 0.0057f}, - {0.5945f, 0.9950f, 0.0039f}, {0.6784f, 0.9786f, 0.0027f}, {0.7621f, 0.9520f, 0.0021f}, - {0.8425f, 0.9154f, 0.0018f}, {0.9163f, 0.8700f, 0.0017f}, {0.9786f, 0.8163f, 0.0014f}, - {1.0263f, 0.7570f, 0.0011f}, {1.0567f, 0.6949f, 0.0010f}, {1.0622f, 0.6310f, 0.0008f}, - {1.0456f, 0.5668f, 0.0006f}, {1.0026f, 0.5030f, 0.0003f}, {0.9384f, 0.4412f, 0.0002f}, - {0.8544f, 0.3810f, 0.0002f}, {0.7514f, 0.3210f, 0.0001f}, {0.6424f, 0.2650f, 0.0000f}, - {0.5419f, 0.2170f, 0.0000f}, {0.4479f, 0.1750f, 0.0000f}, {0.3608f, 0.1382f, 0.0000f}, - {0.2835f, 0.1070f, 0.0000f}, {0.2187f, 0.0816f, 0.0000f}, {0.1649f, 0.0610f, 0.0000f}, - {0.1212f, 0.0446f, 0.0000f}, {0.0874f, 0.0320f, 0.0000f}, {0.0636f, 0.0232f, 0.0000f}, - {0.0468f, 0.0170f, 0.0000f}, {0.0329f, 0.0119f, 0.0000f}, {0.0227f, 0.0082f, 0.0000f}, - {0.0158f, 0.0057f, 0.0000f}, {0.0114f, 0.0041f, 0.0000f}, {0.0081f, 0.0029f, 0.0000f}, - {0.0058f, 0.0021f, 0.0000f}, {0.0041f, 0.0015f, 0.0000f}, {0.0029f, 0.0010f, 0.0000f}, - {0.0020f, 0.0007f, 0.0000f}, {0.0014f, 0.0005f, 0.0000f}, {0.0010f, 0.0004f, 0.0000f}, - {0.0007f, 0.0002f, 0.0000f}, {0.0005f, 0.0002f, 0.0000f}, {0.0003f, 0.0001f, 0.0000f}, - {0.0002f, 0.0001f, 0.0000f}, {0.0002f, 0.0001f, 0.0000f}, {0.0001f, 0.0000f, 0.0000f}, - {0.0001f, 0.0000f, 0.0000f}, {0.0001f, 0.0000f, 0.0000f}, {0.0000f, 0.0000f, 0.0000f} - }; - - for (i = 0, lambda = 380.0f; lambda < 780.1f; i++, lambda += 5.0f) { - /* wavelength in meter */ - const float wlm = lambda * 1e-9f; - const float Me = (3.74183e-16f * powf(wlm, -5.0f)) / (expf(1.4388e-2f / (wlm * temperature)) - 1.0f); - - x += Me * cie_colour_match[i][0]; - y += Me * cie_colour_match[i][1]; - z += Me * cie_colour_match[i][2]; +static const float blackbody_table_r[6][3] = { + { 2.52432244e+03f, -1.06185848e-03f, 3.11067539e+00f }, + { 3.37763626e+03f, -4.34581697e-04f, 1.64843306e+00f }, + { 4.10671449e+03f, -8.61949938e-05f, 6.41423749e-01f }, + { 4.66849800e+03f, 2.85655028e-05f, 1.29075375e-01f }, + { 4.60124770e+03f, 2.89727618e-05f, 1.48001316e-01f }, + { 3.78765709e+03f, 9.36026367e-06f, 3.98995841e-01f }, +}; + +static const float blackbody_table_g[6][3] = { + { -7.50343014e+02f, 3.15679613e-04f, 4.73464526e-01f }, + { -1.00402363e+03f, 1.29189794e-04f, 9.08181524e-01f }, + { -1.22075471e+03f, 2.56245413e-05f, 1.20753416e+00f }, + { -1.42546105e+03f, -4.01730887e-05f, 1.44002695e+00f }, + { -1.18134453e+03f, -2.18913373e-05f, 1.30656109e+00f }, + { -5.00279505e+02f, -4.59745390e-06f, 1.09090465e+00f }, +}; + +static const float blackbody_table_b[6][4] = { + { 0.0f, 0.0f, 0.0f, 0.0f }, + { 0.0f, 0.0f, 0.0f, 0.0f }, + { 0.0f, 0.0f, 0.0f, 0.0f }, + { -2.02524603e-11f, 1.79435860e-07f, -2.60561875e-04f, -1.41761141e-02f }, + { -2.22463426e-13f, -1.55078698e-08f, 3.81675160e-04f, -7.30646033e-01f }, + { 6.72595954e-13f, -2.73059993e-08f, 4.24068546e-04f, -7.52204323e-01f }, +}; + +static void blackbody_temperature_to_rgb(float rgb[3], float t) +{ + if(t >= 12000.0f) { + rgb[0] = 0.826270103f; + rgb[1] = 0.994478524f; + rgb[2] = 1.56626022f; + } + else if(t < 965.0f) { + rgb[0] = 4.70366907f; + rgb[1] = 0.0f; + rgb[2] = 0.0f; + } + else { + int i = (t >= 6365.0f)? 5: + (t >= 3315.0f)? 4: + (t >= 1902.0f)? 3: + (t >= 1449.0f)? 2: + (t >= 1167.0f)? 1: 0; + + const float *r = blackbody_table_r[i]; + const float *g = blackbody_table_g[i]; + const float *b = blackbody_table_b[i]; + + const float t_inv = 1.0f / t; + rgb[0] = r[0] * t_inv + r[1] * t + r[2]; + rgb[1] = g[0] * t_inv + g[1] * t + g[2]; + rgb[2] = ((b[0] * t + b[1]) * t + b[2]) * t + b[3]; } - - xyz_sum = (x + y + z); - - xyz[0] = x / xyz_sum; - xyz[1] = y / xyz_sum; - xyz[2] = z / xyz_sum; } void blackbody_temperature_to_rgb_table(float *r_table, int width, float min, float max) { - int i, j = 0, dj = 1; - float rgb[3], xyz[3], lms[3], lms_w[3]; - float bb_temp; - - if (min < max) { - SWAP(float, min, max); - j = width - 1; - dj = -1; - } + for (int i = 0; i < width; i++) { + float temperature = min + (max - min) / (float)width * (float)i; - for (i = 0; i < width; i++, j += dj) { - bb_temp = min + (max - min) / (float)width * (float)i; + float rgb[3]; + blackbody_temperature_to_rgb(rgb, temperature); - /* integrate blackbody radiation spectrum to XYZ */ - spectrum_to_xyz(bb_temp, xyz); - - /* normalize highest temperature to white (in LMS system) */ - xyz_to_lms(xyz[0], xyz[1], xyz[2], &lms[0], &lms[1], &lms[2]); - - if (i == 0) { - lms_w[0] = 1.0f / lms[0]; - lms_w[1] = 1.0f / lms[1]; - lms_w[2] = 1.0f / lms[2]; - } - - mul_v3_v3(lms, lms_w); - - lms_to_xyz(lms[0], lms[1], lms[2], &xyz[0], &xyz[1], &xyz[2]); - - /* convert to RGB */ - xyz_to_rgb(xyz[0], xyz[1], xyz[2], &rgb[0], &rgb[1], &rgb[2], BLI_XYZ_CIE); - constrain_rgb(&rgb[0], &rgb[1], &rgb[2]); - normalize_rgb(rgb); - - copy_v3_v3(&r_table[(j << 2)], rgb); - - if (rgb[2] > 0.1f) - r_table[(j << 2) + 3] = rgb[2]; - else - r_table[(j << 2) + 3] = 0.0f; + copy_v3_v3(&r_table[i * 4], rgb); + r_table[i * 4 + 3] = 0.0f; } } diff --git a/source/blender/blenlib/intern/polyfill_2d_beautify.c b/source/blender/blenlib/intern/polyfill_2d_beautify.c index 93bfb02bce4..17f3205aaff 100644 --- a/source/blender/blenlib/intern/polyfill_2d_beautify.c +++ b/source/blender/blenlib/intern/polyfill_2d_beautify.c @@ -18,7 +18,7 @@ * ***** END GPL LICENSE BLOCK ***** */ -/** \file blender/blenlib/intern/polyfill2d_beautify.c +/** \file blender/blenlib/intern/polyfill_2d_beautify.c * \ingroup bli * * This function is to improve the tessellation resulting from polyfill2d, @@ -265,7 +265,8 @@ static void polyedge_rotate( struct HalfEdge *e) { /** CCW winding, rotate internal edge to new vertical state. - * <pre> + * + * \code{.unparsed} * Before After * X X * / \ /|\ @@ -276,7 +277,7 @@ static void polyedge_rotate( * e2\ /e1 e2\ | /e1 * \ / \|/ * X X - * </pre> + * \endcode */ struct HalfEdge *ed[6]; uint ed_index[6]; diff --git a/source/blender/blenlib/intern/rand.c b/source/blender/blenlib/intern/rand.c index 1a178db1413..700524965f0 100644 --- a/source/blender/blenlib/intern/rand.c +++ b/source/blender/blenlib/intern/rand.c @@ -386,6 +386,8 @@ void BLI_halton_1D(unsigned int prime, double offset, int n, double *r) { const double invprime = 1.0 / (double)prime; + *r = 0.0; + for (int s = 0; s < n; s++) { *r = halton_ex(invprime, &offset); } @@ -395,6 +397,8 @@ void BLI_halton_2D(unsigned int prime[2], double offset[2], int n, double *r) { const double invprimes[2] = {1.0 / (double)prime[0], 1.0 / (double)prime[1]}; + r[0] = r[1] = 0.0; + for (int s = 0; s < n; s++) { for (int i = 0; i < 2; i++) { r[i] = halton_ex(invprimes[i], &offset[i]); @@ -406,6 +410,8 @@ void BLI_halton_3D(unsigned int prime[3], double offset[3], int n, double *r) { const double invprimes[3] = {1.0 / (double)prime[0], 1.0 / (double)prime[1], 1.0 / (double)prime[2]}; + r[0] = r[1] = r[2] = 0.0; + for (int s = 0; s < n; s++) { for (int i = 0; i < 3; i++) { r[i] = halton_ex(invprimes[i], &offset[i]); diff --git a/source/blender/blenlib/intern/storage.c b/source/blender/blenlib/intern/storage.c index c08329ef34f..f69b35ce5a9 100644 --- a/source/blender/blenlib/intern/storage.c +++ b/source/blender/blenlib/intern/storage.c @@ -185,7 +185,7 @@ size_t BLI_file_size(const char *path) } /** - * Returns the st_mode from statting the specified path name, or 0 if it couldn't be statted + * Returns the st_mode from stat-ing the specified path name, or 0 if stat fails * (most likely doesn't exist or no access). */ int BLI_exists(const char *name) diff --git a/source/blender/blenlib/intern/string.c b/source/blender/blenlib/intern/string.c index 6022732025b..c0e4b8f8168 100644 --- a/source/blender/blenlib/intern/string.c +++ b/source/blender/blenlib/intern/string.c @@ -208,7 +208,7 @@ size_t BLI_strcpy_rlen(char *__restrict dst, const char *__restrict src) } /** - * Portable replacement for #vsnprintf + * Portable replacement for `vsnprintf`. */ size_t BLI_vsnprintf(char *__restrict buffer, size_t maxncpy, const char *__restrict format, va_list arg) { @@ -503,7 +503,7 @@ int BLI_strcaseeq(const char *a, const char *b) } /** - * Portable replacement for #strcasestr (not available in MSVC) + * Portable replacement for `strcasestr` (not available in MSVC) */ char *BLI_strcasestr(const char *s, const char *find) { diff --git a/source/blender/blenlib/intern/task.c b/source/blender/blenlib/intern/task.c index 53c0c560c0d..5d3c6b35ac1 100644 --- a/source/blender/blenlib/intern/task.c +++ b/source/blender/blenlib/intern/task.c @@ -1310,11 +1310,11 @@ static void parallel_mempool_func( /** * This function allows to parallelize for loops over Mempool items. * - * \param pool The iterable BLI_mempool to loop over. - * \param userdata Common userdata passed to all instances of \a func. - * \param func Callback function. - * \param use_threading If \a true, actually split-execute loop in threads, else just do a sequential forloop - * (allows caller to use any kind of test to switch on parallelization or not). + * \param mempool: The iterable BLI_mempool to loop over. + * \param userdata: Common userdata passed to all instances of \a func. + * \param func: Callback function. + * \param use_threading: If \a true, actually split-execute loop in threads, else just do a sequential for loop + * (allows caller to use any kind of test to switch on parallelization or not). * * \note There is no static scheduling here. */ |