Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/blenlib/intern')
-rw-r--r--source/blender/blenlib/intern/BLI_ghash.c2
-rw-r--r--source/blender/blenlib/intern/BLI_kdopbvh.c2
-rw-r--r--source/blender/blenlib/intern/math_base_inline.c24
-rw-r--r--source/blender/blenlib/intern/math_geom.c27
-rw-r--r--source/blender/blenlib/intern/math_geom_inline.c5
-rw-r--r--source/blender/blenlib/intern/math_interp.c230
-rw-r--r--source/blender/blenlib/intern/math_rotation.c2
-rw-r--r--source/blender/blenlib/intern/math_vector.c27
-rw-r--r--source/blender/blenlib/intern/math_vector_inline.c5
-rw-r--r--source/blender/blenlib/intern/noise.c60
-rw-r--r--source/blender/blenlib/intern/pbvh.c11
-rw-r--r--source/blender/blenlib/intern/scanfill.c2
-rw-r--r--source/blender/blenlib/intern/string.c16
-rw-r--r--source/blender/blenlib/intern/string_utf8.c12
-rw-r--r--source/blender/blenlib/intern/threads.c36
15 files changed, 362 insertions, 99 deletions
diff --git a/source/blender/blenlib/intern/BLI_ghash.c b/source/blender/blenlib/intern/BLI_ghash.c
index 0cae9bab531..c4094920c2a 100644
--- a/source/blender/blenlib/intern/BLI_ghash.c
+++ b/source/blender/blenlib/intern/BLI_ghash.c
@@ -178,7 +178,7 @@ void *BLI_ghash_pop(GHash *gh, void *key, GHashKeyFreeFP keyfreefp)
return NULL;
}
-int BLI_ghash_haskey(GHash *gh, void *key)
+int BLI_ghash_haskey(GHash *gh, const void *key)
{
unsigned int hash = gh->hashfp(key) % gh->nbuckets;
Entry *e;
diff --git a/source/blender/blenlib/intern/BLI_kdopbvh.c b/source/blender/blenlib/intern/BLI_kdopbvh.c
index 7968fcabda6..6cf167b8823 100644
--- a/source/blender/blenlib/intern/BLI_kdopbvh.c
+++ b/source/blender/blenlib/intern/BLI_kdopbvh.c
@@ -1410,7 +1410,7 @@ static float ray_nearest_hit(BVHRayCastData *data, const float bv[6])
* Based on Tactical Optimization of Ray/Box Intersection, by Graham Fyffe
* [http://tog.acm.org/resources/RTNews/html/rtnv21n1.html#art9]
*
- * TODO this doens't has data->ray.radius in consideration */
+ * TODO this doesn't take data->ray.radius into consideration */
static float fast_ray_nearest_hit(const BVHRayCastData *data, const BVHNode *node)
{
const float *bv = node->bv;
diff --git a/source/blender/blenlib/intern/math_base_inline.c b/source/blender/blenlib/intern/math_base_inline.c
index f27da759482..b9866f9c6e6 100644
--- a/source/blender/blenlib/intern/math_base_inline.c
+++ b/source/blender/blenlib/intern/math_base_inline.c
@@ -27,6 +27,8 @@
* \ingroup bli
*/
+#ifndef __MATH_BASE_INLINE_C__
+#define __MATH_BASE_INLINE_C__
#include <float.h>
#include <stdio.h>
@@ -35,9 +37,6 @@
#include "BLI_math.h"
-#ifndef __MATH_BASE_INLINE_C__
-#define __MATH_BASE_INLINE_C__
-
/* A few small defines. Keep'em local! */
#define SMALL_NUMBER 1.e-8f
@@ -139,6 +138,25 @@ MINLINE int power_of_2_min_i(int n)
return n;
}
+MINLINE unsigned int highest_order_bit_i(unsigned int n)
+{
+ n |= (n >> 1);
+ n |= (n >> 2);
+ n |= (n >> 4);
+ n |= (n >> 8);
+ n |= (n >> 16);
+ return n - (n >> 1);
+}
+
+MINLINE unsigned short highest_order_bit_s(unsigned short n)
+{
+ n |= (n >> 1);
+ n |= (n >> 2);
+ n |= (n >> 4);
+ n |= (n >> 8);
+ return n - (n >> 1);
+}
+
MINLINE float min_ff(float a, float b)
{
return (a < b) ? a : b;
diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c
index e10229f11da..cd726179f56 100644
--- a/source/blender/blenlib/intern/math_geom.c
+++ b/source/blender/blenlib/intern/math_geom.c
@@ -2399,6 +2399,33 @@ void resolve_quad_uv(float r_uv[2], const float st[2], const float st0[2], const
#undef IS_ZERO
+/* reverse of the functions above */
+void interp_bilinear_quad_v3(float data[4][3], float u, float v, float res[3])
+{
+ float vec[3];
+
+ copy_v3_v3(res, data[0]);
+ mul_v3_fl(res, (1 - u) * (1 - v));
+ copy_v3_v3(vec, data[1]);
+ mul_v3_fl(vec, u * (1 - v)); add_v3_v3(res, vec);
+ copy_v3_v3(vec, data[2]);
+ mul_v3_fl(vec, u * v); add_v3_v3(res, vec);
+ copy_v3_v3(vec, data[3]);
+ mul_v3_fl(vec, (1 - u) * v); add_v3_v3(res, vec);
+}
+
+void interp_barycentric_tri_v3(float data[3][3], float u, float v, float res[3])
+{
+ float vec[3];
+
+ copy_v3_v3(res, data[0]);
+ mul_v3_fl(res, u);
+ copy_v3_v3(vec, data[1]);
+ mul_v3_fl(vec, v); add_v3_v3(res, vec);
+ copy_v3_v3(vec, data[2]);
+ mul_v3_fl(vec, 1.0f - u - v); add_v3_v3(res, vec);
+}
+
/***************************** View & Projection *****************************/
void orthographic_m4(float matrix[][4], const float left, const float right, const float bottom, const float top,
diff --git a/source/blender/blenlib/intern/math_geom_inline.c b/source/blender/blenlib/intern/math_geom_inline.c
index 01585c93bc8..ba9770e1bd1 100644
--- a/source/blender/blenlib/intern/math_geom_inline.c
+++ b/source/blender/blenlib/intern/math_geom_inline.c
@@ -27,11 +27,12 @@
* \ingroup bli
*/
+#ifndef __MATH_GEOM_INLINE_C__
+#define __MATH_GEOM_INLINE_C__
#include "BLI_math.h"
-#ifndef __MATH_GEOM_INLINE_C__
-#define __MATH_GEOM_INLINE_C__
+#include <string.h>
/****************************** Spherical Harmonics **************************/
diff --git a/source/blender/blenlib/intern/math_interp.c b/source/blender/blenlib/intern/math_interp.c
index 742669354a9..5a9e8244a46 100644
--- a/source/blender/blenlib/intern/math_interp.c
+++ b/source/blender/blenlib/intern/math_interp.c
@@ -60,12 +60,44 @@ static float P(float k)
}
#endif
+static void vector_from_float(const float *data, float vector[4], int components)
+{
+ if (components == 1) {
+ vector[0] = data[0];
+ }
+ else if (components == 3) {
+ copy_v3_v3(vector, data);
+ }
+ else {
+ copy_v4_v4(vector, data);
+ }
+}
+
+static void vector_from_byte(const unsigned char *data, float vector[4], int components)
+{
+ if (components == 1) {
+ vector[0] = data[0];
+ }
+ else if (components == 3) {
+ vector[0] = data[0];
+ vector[1] = data[1];
+ vector[2] = data[2];
+ }
+ else {
+ vector[0] = data[0];
+ vector[1] = data[1];
+ vector[2] = data[2];
+ vector[3] = data[3];
+ }
+}
+
/* BICUBIC INTERPOLATION */
-void BLI_bicubic_interpolation(const float *buffer, float *output, int width, int height, int components, float u, float v)
+BLI_INLINE void bicubic_interpolation(const unsigned char *byte_buffer, const float *float_buffer,
+ unsigned char *byte_output, float *float_output, int width, int height,
+ int components, float u, float v)
{
int i, j, n, m, x1, y1;
float a, b, w, wx, wy[4], out[4];
- const float *data;
/* sample area entirely outside image? */
if (ceil(u) < 0 || floor(u) > width - 1 || ceil(v) < 0 || floor(v) > height - 1) {
@@ -92,6 +124,8 @@ void BLI_bicubic_interpolation(const float *buffer, float *output, int width, in
CLAMP(x1, 0, width - 1);
wx = P(n - a);
for (m = -1; m <= 2; m++) {
+ float data[4];
+
y1 = j + m;
CLAMP(y1, 0, height - 1);
/* normally we could do this */
@@ -99,14 +133,19 @@ void BLI_bicubic_interpolation(const float *buffer, float *output, int width, in
/* except that would call P() 16 times per pixel therefor pow() 64 times, better precalc these */
w = wx * wy[m + 1];
- data = buffer + width * y1 * 4 + 4 * x1;
+ if (float_output) {
+ const float *float_data = float_buffer + width * y1 * components + components * x1;
- if (components == 1) {
- out[0] += data[0] * w;
+ vector_from_float(float_data, data, components);
+ }
+ else {
+ const unsigned char *byte_data = byte_buffer + width * y1 * components + components * x1;
+
+ vector_from_byte(byte_data, data, components);
}
- else if (components == 2) {
+
+ if (components == 1) {
out[0] += data[0] * w;
- out[1] += data[1] * w;
}
else if (components == 3) {
out[0] += data[0] * w;
@@ -131,14 +170,21 @@ void BLI_bicubic_interpolation(const float *buffer, float *output, int width, in
x1 = i + n;
y1 = j + m;
if (x1 > 0 && x1 < width && y1 > 0 && y1 < height) {
- data = in->rect_float + width * y1 * 4 + 4 * x1;
+ float data[4];
- if (components == 1) {
- out[0] += data[0] * P(n - a) * P(b - m);
+ if (float_output) {
+ const float *float_data = float_buffer + width * y1 * components + components * x1;
+
+ vector_from_float(float_data, data, components);
}
- else if (components == 2) {
+ else {
+ const unsigned char *byte_data = byte_buffer + width * y1 * components + components * x1;
+
+ vector_from_byte(byte_data, data, components);
+ }
+
+ if (components == 1) {
out[0] += data[0] * P(n - a) * P(b - m);
- out[1] += data[1] * P(n - a) * P(b - m);
}
else if (components == 3) {
out[0] += data[0] * P(n - a) * P(b - m);
@@ -156,33 +202,54 @@ void BLI_bicubic_interpolation(const float *buffer, float *output, int width, in
}
#endif
- if (components == 1) {
- output[0] = out[0];
- }
- else if (components == 2) {
- output[0] = out[0];
- output[1] = out[1];
- }
- else if (components == 3) {
- output[0] = out[0];
- output[1] = out[1];
- output[2] = out[2];
+ if (float_output) {
+ if (components == 1) {
+ float_output[0] = out[0];
+ }
+ else if (components == 3) {
+ copy_v3_v3(float_output, out);
+ }
+ else {
+ copy_v4_v4(float_output, out);
+ }
}
else {
- output[0] = out[0];
- output[1] = out[1];
- output[2] = out[2];
- output[3] = out[3];
+ if (components == 1) {
+ byte_output[0] = out[0];
+ }
+ else if (components == 3) {
+ byte_output[0] = out[0];
+ byte_output[1] = out[1];
+ byte_output[2] = out[2];
+ }
+ else {
+ byte_output[0] = out[0];
+ byte_output[1] = out[1];
+ byte_output[2] = out[2];
+ byte_output[3] = out[3];
+ }
}
}
+void BLI_bicubic_interpolation_fl(const float *buffer, float *output, int width, int height,
+ int components, float u, float v)
+{
+ bicubic_interpolation(NULL, buffer, NULL, output, width, height, components, u, v);
+}
+
+void BLI_bicubic_interpolation_char(const unsigned char *buffer, unsigned char *output, int width, int height,
+ int components, float u, float v)
+{
+ bicubic_interpolation(buffer, NULL, output, NULL, width, height, components, u, v);
+}
+
/* BILINEAR INTERPOLATION */
-void BLI_bilinear_interpolation(const float *buffer, float *output, int width, int height, int components, float u, float v)
+BLI_INLINE void bilinear_interpolation(const unsigned char *byte_buffer, const float *float_buffer,
+ unsigned char *byte_output, float *float_output, int width, int height,
+ int components, float u, float v)
{
- const float *row1, *row2, *row3, *row4;
float a, b;
float a_b, ma_b, a_mb, ma_mb;
- float empty[4] = {0.0f, 0.0f, 0.0f, 0.0f};
int y1, y2, x1, x2;
/* ImBuf in must have a valid rect or rect_float, assume this is already checked */
@@ -197,39 +264,88 @@ void BLI_bilinear_interpolation(const float *buffer, float *output, int width, i
return;
}
- /* sample including outside of edges of image */
- if (x1 < 0 || y1 < 0) row1 = empty;
- else row1 = buffer + width * y1 * 4 + 4 * x1;
+ if (float_output) {
+ const float *row1, *row2, *row3, *row4;
+ float empty[4] = {0.0f, 0.0f, 0.0f, 0.0f};
- if (x1 < 0 || y2 > height - 1) row2 = empty;
- else row2 = buffer + width * y2 * 4 + 4 * x1;
+ /* sample including outside of edges of image */
+ if (x1 < 0 || y1 < 0) row1 = empty;
+ else row1 = float_buffer + width * y1 * components + components * x1;
- if (x2 > width - 1 || y1 < 0) row3 = empty;
- else row3 = buffer + width * y1 * 4 + 4 * x2;
+ if (x1 < 0 || y2 > height - 1) row2 = empty;
+ else row2 = float_buffer + width * y2 * components + components * x1;
- if (x2 > width - 1 || y2 > height - 1) row4 = empty;
- else row4 = buffer + width * y2 * 4 + 4 * x2;
+ if (x2 > width - 1 || y1 < 0) row3 = empty;
+ else row3 = float_buffer + width * y1 * components + components * x2;
- a = u - floorf(u);
- b = v - floorf(v);
- a_b = a * b; ma_b = (1.0f - a) * b; a_mb = a * (1.0f - b); ma_mb = (1.0f - a) * (1.0f - b);
+ if (x2 > width - 1 || y2 > height - 1) row4 = empty;
+ else row4 = float_buffer + width * y2 * components + components * x2;
- if (components == 1) {
- output[0] = ma_mb * row1[0] + a_mb * row3[0] + ma_b * row2[0] + a_b * row4[0];
- }
- else if (components == 2) {
- output[0] = ma_mb * row1[0] + a_mb * row3[0] + ma_b * row2[0] + a_b * row4[0];
- output[1] = ma_mb * row1[1] + a_mb * row3[1] + ma_b * row2[1] + a_b * row4[1];
- }
- else if (components == 3) {
- output[0] = ma_mb * row1[0] + a_mb * row3[0] + ma_b * row2[0] + a_b * row4[0];
- output[1] = ma_mb * row1[1] + a_mb * row3[1] + ma_b * row2[1] + a_b * row4[1];
- output[2] = ma_mb * row1[2] + a_mb * row3[2] + ma_b * row2[2] + a_b * row4[2];
+ a = u - floorf(u);
+ b = v - floorf(v);
+ a_b = a * b; ma_b = (1.0f - a) * b; a_mb = a * (1.0f - b); ma_mb = (1.0f - a) * (1.0f - b);
+
+ if (components == 1) {
+ float_output[0] = ma_mb * row1[0] + a_mb * row3[0] + ma_b * row2[0] + a_b * row4[0];
+ }
+ else if (components == 3) {
+ float_output[0] = ma_mb * row1[0] + a_mb * row3[0] + ma_b * row2[0] + a_b * row4[0];
+ float_output[1] = ma_mb * row1[1] + a_mb * row3[1] + ma_b * row2[1] + a_b * row4[1];
+ float_output[2] = ma_mb * row1[2] + a_mb * row3[2] + ma_b * row2[2] + a_b * row4[2];
+ }
+ else {
+ float_output[0] = ma_mb * row1[0] + a_mb * row3[0] + ma_b * row2[0] + a_b * row4[0];
+ float_output[1] = ma_mb * row1[1] + a_mb * row3[1] + ma_b * row2[1] + a_b * row4[1];
+ float_output[2] = ma_mb * row1[2] + a_mb * row3[2] + ma_b * row2[2] + a_b * row4[2];
+ float_output[3] = ma_mb * row1[3] + a_mb * row3[3] + ma_b * row2[3] + a_b * row4[3];
+ }
}
else {
- output[0] = ma_mb * row1[0] + a_mb * row3[0] + ma_b * row2[0] + a_b * row4[0];
- output[1] = ma_mb * row1[1] + a_mb * row3[1] + ma_b * row2[1] + a_b * row4[1];
- output[2] = ma_mb * row1[2] + a_mb * row3[2] + ma_b * row2[2] + a_b * row4[2];
- output[3] = ma_mb * row1[3] + a_mb * row3[3] + ma_b * row2[3] + a_b * row4[3];
+ const unsigned char *row1, *row2, *row3, *row4;
+ unsigned char empty[4] = {0, 0, 0, 0};
+
+ /* sample including outside of edges of image */
+ if (x1 < 0 || y1 < 0) row1 = empty;
+ else row1 = byte_buffer + width * y1 * components + components * x1;
+
+ if (x1 < 0 || y2 > height - 1) row2 = empty;
+ else row2 = byte_buffer + width * y2 * components + components * x1;
+
+ if (x2 > width - 1 || y1 < 0) row3 = empty;
+ else row3 = byte_buffer + width * y1 * components + components * x2;
+
+ if (x2 > width - 1 || y2 > height - 1) row4 = empty;
+ else row4 = byte_buffer + width * y2 * components + components * x2;
+
+ a = u - floorf(u);
+ b = v - floorf(v);
+ a_b = a * b; ma_b = (1.0f - a) * b; a_mb = a * (1.0f - b); ma_mb = (1.0f - a) * (1.0f - b);
+
+ if (components == 1) {
+ byte_output[0] = ma_mb * row1[0] + a_mb * row3[0] + ma_b * row2[0] + a_b * row4[0];
+ }
+ else if (components == 3) {
+ byte_output[0] = ma_mb * row1[0] + a_mb * row3[0] + ma_b * row2[0] + a_b * row4[0];
+ byte_output[1] = ma_mb * row1[1] + a_mb * row3[1] + ma_b * row2[1] + a_b * row4[1];
+ byte_output[2] = ma_mb * row1[2] + a_mb * row3[2] + ma_b * row2[2] + a_b * row4[2];
+ }
+ else {
+ byte_output[0] = ma_mb * row1[0] + a_mb * row3[0] + ma_b * row2[0] + a_b * row4[0];
+ byte_output[1] = ma_mb * row1[1] + a_mb * row3[1] + ma_b * row2[1] + a_b * row4[1];
+ byte_output[2] = ma_mb * row1[2] + a_mb * row3[2] + ma_b * row2[2] + a_b * row4[2];
+ byte_output[3] = ma_mb * row1[3] + a_mb * row3[3] + ma_b * row2[3] + a_b * row4[3];
+ }
}
}
+
+void BLI_bilinear_interpolation_fl(const float *buffer, float *output, int width, int height,
+ int components, float u, float v)
+{
+ bilinear_interpolation(NULL, buffer, NULL, output, width, height, components, u, v);
+}
+
+void BLI_bilinear_interpolation_char(const unsigned char *buffer, unsigned char *output, int width, int height,
+ int components, float u, float v)
+{
+ bilinear_interpolation(buffer, NULL, output, NULL, width, height, components, u, v);
+}
diff --git a/source/blender/blenlib/intern/math_rotation.c b/source/blender/blenlib/intern/math_rotation.c
index b0c4724e1ec..3069542107e 100644
--- a/source/blender/blenlib/intern/math_rotation.c
+++ b/source/blender/blenlib/intern/math_rotation.c
@@ -84,7 +84,7 @@ void mul_qt_qtqt(float q[4], const float q1[4], const float q2[4])
* \note:
* Assumes a unit quaternion?
*
- * in fact not, but you may wan't to use a unit quat, read on...
+ * in fact not, but you may want to use a unit quat, read on...
*
* Shortcut for 'q v q*' when \a v is actually a quaternion.
* This removes the need for converting a vector to a quaternion,
diff --git a/source/blender/blenlib/intern/math_vector.c b/source/blender/blenlib/intern/math_vector.c
index 976895fe6fc..812e2b3e63d 100644
--- a/source/blender/blenlib/intern/math_vector.c
+++ b/source/blender/blenlib/intern/math_vector.c
@@ -115,6 +115,13 @@ void mid_v2_v2v2(float v[2], const float v1[2], const float v2[2])
v[1] = 0.5f * (v1[1] + v2[1]);
}
+void mid_v3_v3v3v3(float v[3], const float v1[3], const float v2[3], const float v3[3])
+{
+ v[0] = (v1[0] + v2[0] + v3[0]) / 3.0f;
+ v[1] = (v1[1] + v2[1] + v3[1]) / 3.0f;
+ v[2] = (v1[2] + v2[2] + v3[2]) / 3.0f;
+}
+
/********************************** Angles ***********************************/
/* Return the angle in radians between vecs 1-2 and 2-3 in radians
@@ -201,6 +208,13 @@ float angle_signed_v2v2(const float v1[2], const float v2[2])
float angle_normalized_v3v3(const float v1[3], const float v2[3])
{
+ /* double check they are normalized */
+#ifdef DEBUG
+ float test;
+ BLI_assert(fabsf((test = len_squared_v3(v1)) - 1.0f) < 0.0001f || fabsf(test) < 0.0001f);
+ BLI_assert(fabsf((test = len_squared_v3(v2)) - 1.0f) < 0.0001f || fabsf(test) < 0.0001f);
+#endif
+
/* this is the same as acos(dot_v3v3(v1, v2)), but more accurate */
if (dot_v3v3(v1, v2) < 0.0f) {
float vec[3];
@@ -217,6 +231,13 @@ float angle_normalized_v3v3(const float v1[3], const float v2[3])
float angle_normalized_v2v2(const float v1[2], const float v2[2])
{
+ /* double check they are normalized */
+#ifdef DEBUG
+ float test;
+ BLI_assert(fabsf((test = len_squared_v2(v1)) - 1.0f) < 0.0001f || fabsf(test) < 0.0001f);
+ BLI_assert(fabsf((test = len_squared_v2(v2)) - 1.0f) < 0.0001f || fabsf(test) < 0.0001f);
+#endif
+
/* this is the same as acos(dot_v3v3(v1, v2)), but more accurate */
if (dot_v2v2(v1, v2) < 0.0f) {
float vec[2];
@@ -401,6 +422,12 @@ void rotate_normalized_v3_v3v3fl(float r[3], const float p[3], const float axis[
const float costheta = cos(angle);
const float sintheta = sin(angle);
+ /* double check they are normalized */
+#ifdef DEBUG
+ float test;
+ BLI_assert(fabsf((test = len_squared_v3(axis)) - 1.0f) < 0.0001f || fabsf(test) < 0.0001f);
+#endif
+
r[0] = ((costheta + (1 - costheta) * axis[0] * axis[0]) * p[0]) +
(((1 - costheta) * axis[0] * axis[1] - axis[2] * sintheta) * p[1]) +
(((1 - costheta) * axis[0] * axis[2] + axis[1] * sintheta) * p[2]);
diff --git a/source/blender/blenlib/intern/math_vector_inline.c b/source/blender/blenlib/intern/math_vector_inline.c
index d96beadd63b..84e4c513e12 100644
--- a/source/blender/blenlib/intern/math_vector_inline.c
+++ b/source/blender/blenlib/intern/math_vector_inline.c
@@ -27,12 +27,11 @@
* \ingroup bli
*/
-
-#include "BLI_math.h"
-
#ifndef __MATH_VECTOR_INLINE_C__
#define __MATH_VECTOR_INLINE_C__
+#include "BLI_math.h"
+
/********************************** Init *************************************/
MINLINE void zero_v2(float r[2])
diff --git a/source/blender/blenlib/intern/noise.c b/source/blender/blenlib/intern/noise.c
index fb33d7ce127..f37e1e03f39 100644
--- a/source/blender/blenlib/intern/noise.c
+++ b/source/blender/blenlib/intern/noise.c
@@ -398,7 +398,8 @@ static float orgBlenderNoise(float x, float y, float z)
h = hashvectf + 3 * hash[b21 + b11];
n += i * (h[0] * jx + h[1] * jy + h[2] * jz);
- if (n < 0.0f) n = 0.0f; else if (n > 1.0f) n = 1.0f;
+ if (n < 0.0f) n = 0.0f;
+ else if (n > 1.0f) n = 1.0f;
return n;
}
@@ -456,16 +457,50 @@ float BLI_turbulence1(float noisesize, float x, float y, float z, int nr)
/* ********************* FROM PERLIN HIMSELF: ******************** */
-static char p[512 + 2] = {
- 0xA2, 0xA0, 0x19, 0x3B, 0xF8, 0xEB, 0xAA, 0xEE, 0xF3, 0x1C, 0x67, 0x28, 0x1D, 0xED, 0x0, 0xDE, 0x95, 0x2E, 0xDC, 0x3F, 0x3A, 0x82, 0x35, 0x4D, 0x6C, 0xBA, 0x36, 0xD0, 0xF6, 0xC, 0x79, 0x32, 0xD1, 0x59, 0xF4, 0x8, 0x8B, 0x63, 0x89, 0x2F, 0xB8, 0xB4, 0x97, 0x83, 0xF2, 0x8F, 0x18, 0xC7, 0x51, 0x14, 0x65, 0x87, 0x48, 0x20, 0x42, 0xA8, 0x80, 0xB5, 0x40, 0x13, 0xB2, 0x22, 0x7E, 0x57,
- 0xBC, 0x7F, 0x6B, 0x9D, 0x86, 0x4C, 0xC8, 0xDB, 0x7C, 0xD5, 0x25, 0x4E, 0x5A, 0x55, 0x74, 0x50, 0xCD, 0xB3, 0x7A, 0xBB, 0xC3, 0xCB, 0xB6, 0xE2, 0xE4, 0xEC, 0xFD, 0x98, 0xB, 0x96, 0xD3, 0x9E, 0x5C, 0xA1, 0x64, 0xF1, 0x81, 0x61, 0xE1, 0xC4, 0x24, 0x72, 0x49, 0x8C, 0x90, 0x4B, 0x84, 0x34, 0x38, 0xAB, 0x78, 0xCA, 0x1F, 0x1, 0xD7, 0x93, 0x11, 0xC1, 0x58, 0xA9, 0x31, 0xF9, 0x44, 0x6D,
- 0xBF, 0x33, 0x9C, 0x5F, 0x9, 0x94, 0xA3, 0x85, 0x6, 0xC6, 0x9A, 0x1E, 0x7B, 0x46, 0x15, 0x30, 0x27, 0x2B, 0x1B, 0x71, 0x3C, 0x5B, 0xD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, 0x96, 0xD3, 0x9E, 0x5C, 0xA1, 0x64, 0xF1, 0x81, 0x61, 0xE1, 0xC4,
+ 0x24, 0x72, 0x49, 0x8C, 0x90, 0x4B, 0x84, 0x34, 0x38, 0xAB, 0x78, 0xCA,
+ 0x1F, 0x1, 0xD7, 0x93, 0x11, 0xC1, 0x58, 0xA9, 0x31, 0xF9, 0x44, 0x6D,
+ 0xBF, 0x33, 0x9C, 0x5F, 0x9, 0x94, 0xA3, 0x85, 0x6, 0xC6, 0x9A, 0x1E,
+ 0x7B, 0x46, 0x15, 0x30, 0x27, 0x2B, 0x1B, 0x71, 0x3C, 0x5B, 0xD6, 0x6F,
+ 0x62, 0xAC, 0x4F, 0xC2, 0xC0, 0xE, 0xB1, 0x23, 0xA7, 0xDF, 0x47, 0xB0,
+ 0x77, 0x69, 0x5, 0xE9, 0xE6, 0xE7, 0x76, 0x73, 0xF, 0xFE, 0x6E, 0x9B,
+ 0x56, 0xEF, 0x12, 0xA5, 0x37, 0xFC, 0xAE, 0xD9, 0x3, 0x8E, 0xDD, 0x10,
+ 0xB9, 0xCE, 0xC9, 0x8D, 0xDA, 0x2A, 0xBD, 0x68, 0x17, 0x9F, 0xBE, 0xD4,
+ 0xA, 0xCC, 0xD2, 0xE8, 0x43, 0x3D, 0x70, 0xB7, 0x2, 0x7D, 0x99, 0xD8,
+ 0xD, 0x60, 0x8A, 0x4, 0x2C, 0x3E, 0x92, 0xE5, 0xAF, 0x53, 0x7, 0xE0,
+ 0x29, 0xA6, 0xC5, 0xE3, 0xF5, 0xF7, 0x4A, 0x41, 0x26, 0x6A, 0x16, 0x5E,
+ 0x52, 0x2D, 0x21, 0xAD, 0xF0, 0x91, 0xFF, 0xEA, 0x54, 0xFA, 0x66, 0x1A,
+ 0x45, 0x39, 0xCF, 0x75, 0xA4, 0x88, 0xFB, 0x5D, 0xA2, 0xA0
};
@@ -1856,7 +1891,8 @@ float mg_RidgedMultiFractal(float x, float y, float z, float H, float lacunarity
y *= lacunarity;
z *= lacunarity;
weight = signal * gain;
- if (weight > 1.0f) weight = 1.0f; else if (weight < 0.0f) weight = 0.0f;
+ if (weight > 1.0f) weight = 1.0f;
+ else if (weight < 0.0f) weight = 0.0f;
signal = offset - fabsf(noisefunc(x, y, z));
signal *= signal;
signal *= weight;
diff --git a/source/blender/blenlib/intern/pbvh.c b/source/blender/blenlib/intern/pbvh.c
index 9fd214c0f86..29982fb7744 100644
--- a/source/blender/blenlib/intern/pbvh.c
+++ b/source/blender/blenlib/intern/pbvh.c
@@ -1717,11 +1717,14 @@ void BLI_pbvh_grids_update(PBVH *bvh, CCGElem **grids, DMGridAdjacency *gridadj,
bvh->grids = grids;
bvh->gridadj = gridadj;
bvh->gridfaces = gridfaces;
- bvh->grid_flag_mats = flagmats;
- bvh->grid_hidden = grid_hidden;
- for (a = 0; a < bvh->totnode; ++a)
- BLI_pbvh_node_mark_rebuild_draw(&bvh->nodes[a]);
+ if (flagmats != bvh->grid_flag_mats || bvh->grid_hidden != grid_hidden) {
+ bvh->grid_flag_mats = flagmats;
+ bvh->grid_hidden = grid_hidden;
+
+ for (a = 0; a < bvh->totnode; ++a)
+ BLI_pbvh_node_mark_rebuild_draw(&bvh->nodes[a]);
+ }
}
float (*BLI_pbvh_get_vertCos(PBVH * pbvh))[3]
diff --git a/source/blender/blenlib/intern/scanfill.c b/source/blender/blenlib/intern/scanfill.c
index 362a87782c6..1b7858f7f88 100644
--- a/source/blender/blenlib/intern/scanfill.c
+++ b/source/blender/blenlib/intern/scanfill.c
@@ -985,7 +985,7 @@ int BLI_scanfill_calc_ex(ScanFillContext *sf_ctx, const short do_quad_tri_speedu
/* CURRENT STATUS:
- * - eve->f :1 = availalble in edges
+ * - eve->f :1 = available in edges
* - eve->xs :polynumber
* - eve->h :amount of edges connected to vertex
* - eve->tmp.v :store! original vertex number
diff --git a/source/blender/blenlib/intern/string.c b/source/blender/blenlib/intern/string.c
index ff589764287..14e0dc2f049 100644
--- a/source/blender/blenlib/intern/string.c
+++ b/source/blender/blenlib/intern/string.c
@@ -56,7 +56,7 @@ char *BLI_strdup(const char *str)
return BLI_strdupn(str, strlen(str));
}
-char *BLI_strdupcat(const char *str1, const char *str2)
+char *BLI_strdupcat(const char *__restrict str1, const char *__restrict str2)
{
size_t len;
char *n;
@@ -69,7 +69,7 @@ char *BLI_strdupcat(const char *str1, const char *str2)
return n;
}
-char *BLI_strncpy(char *dst, const char *src, const size_t maxncpy)
+char *BLI_strncpy(char *__restrict dst, const char *__restrict src, const size_t maxncpy)
{
size_t srclen = strlen(src);
size_t cpylen = (srclen > (maxncpy - 1)) ? (maxncpy - 1) : srclen;
@@ -81,7 +81,7 @@ char *BLI_strncpy(char *dst, const char *src, const size_t maxncpy)
return dst;
}
-size_t BLI_vsnprintf(char *buffer, size_t count, const char *format, va_list arg)
+size_t BLI_vsnprintf(char *__restrict buffer, size_t count, const char *__restrict format, va_list arg)
{
size_t n;
@@ -97,7 +97,7 @@ size_t BLI_vsnprintf(char *buffer, size_t count, const char *format, va_list arg
return n;
}
-size_t BLI_snprintf(char *buffer, size_t count, const char *format, ...)
+size_t BLI_snprintf(char *__restrict buffer, size_t count, const char *__restrict format, ...)
{
size_t n;
va_list arg;
@@ -109,7 +109,7 @@ size_t BLI_snprintf(char *buffer, size_t count, const char *format, ...)
return n;
}
-char *BLI_sprintfN(const char *format, ...)
+char *BLI_sprintfN(const char *__restrict format, ...)
{
DynStr *ds;
va_list arg;
@@ -133,7 +133,7 @@ char *BLI_sprintfN(const char *format, ...)
* TODO: support more fancy string escaping. current code is primitive
* this basically is an ascii version of PyUnicode_EncodeUnicodeEscape()
* which is a useful reference. */
-size_t BLI_strescape(char *dst, const char *src, const size_t maxncpy)
+size_t BLI_strescape(char *__restrict dst, const char *__restrict src, const size_t maxncpy)
{
size_t len = 0;
@@ -186,7 +186,7 @@ escape_finish:
*
* TODO, return the offset and a length so as to avoid doing an allocation.
*/
-char *BLI_str_quoted_substrN(const char *str, const char *prefix)
+char *BLI_str_quoted_substrN(const char *__restrict str, const char *__restrict prefix)
{
size_t prefixLen = strlen(prefix);
char *startMatch, *endMatch;
@@ -207,7 +207,7 @@ char *BLI_str_quoted_substrN(const char *str, const char *prefix)
/* A rather wasteful string-replacement utility, though this shall do for now...
* Feel free to replace this with an even safe + nicer alternative */
-char *BLI_replacestr(char *str, const char *oldText, const char *newText)
+char *BLI_replacestr(char *__restrict str, const char *__restrict oldText, const char *__restrict newText)
{
DynStr *ds = NULL;
size_t lenOld = strlen(oldText);
diff --git a/source/blender/blenlib/intern/string_utf8.c b/source/blender/blenlib/intern/string_utf8.c
index e80f96ee0fe..16a5f03095d 100644
--- a/source/blender/blenlib/intern/string_utf8.c
+++ b/source/blender/blenlib/intern/string_utf8.c
@@ -184,7 +184,7 @@ static const size_t utf8_skip_data[256] = {
*dst = '\0'; \
} (void)0
-char *BLI_strncpy_utf8(char *dst, const char *src, size_t maxncpy)
+char *BLI_strncpy_utf8(char *__restrict dst, const char *__restrict src, size_t maxncpy)
{
char *dst_r = dst;
@@ -196,7 +196,7 @@ char *BLI_strncpy_utf8(char *dst, const char *src, size_t maxncpy)
return dst_r;
}
-char *BLI_strncat_utf8(char *dst, const char *src, size_t maxncpy)
+char *BLI_strncat_utf8(char *__restrict dst, const char *__restrict src, size_t maxncpy)
{
while (*dst && maxncpy > 0) {
dst++;
@@ -213,7 +213,7 @@ char *BLI_strncat_utf8(char *dst, const char *src, size_t maxncpy)
/* --------------------------------------------------------------------------*/
/* wchar_t / utf8 functions */
-size_t BLI_strncpy_wchar_as_utf8(char *dst, const wchar_t *src, const size_t maxncpy)
+size_t BLI_strncpy_wchar_as_utf8(char *__restrict dst, const wchar_t *__restrict src, const size_t maxncpy)
{
size_t len = 0;
@@ -289,7 +289,7 @@ size_t BLI_strnlen_utf8(const char *start, const size_t maxlen)
return len;
}
-size_t BLI_strncpy_wchar_from_utf8(wchar_t *dst_w, const char *src_c, const size_t maxncpy)
+size_t BLI_strncpy_wchar_from_utf8(wchar_t *__restrict dst_w, const char *__restrict src_c, const size_t maxncpy)
{
int len = 0;
@@ -419,7 +419,7 @@ unsigned int BLI_str_utf8_as_unicode(const char *p)
}
/* variant that increments the length */
-unsigned int BLI_str_utf8_as_unicode_and_size(const char *p, size_t *index)
+unsigned int BLI_str_utf8_as_unicode_and_size(const char *__restrict p, size_t *__restrict index)
{
int i, mask = 0, len;
unsigned int result;
@@ -435,7 +435,7 @@ unsigned int BLI_str_utf8_as_unicode_and_size(const char *p, size_t *index)
/* another variant that steps over the index,
* note, currently this also falls back to latin1 for text drawing. */
-unsigned int BLI_str_utf8_as_unicode_step(const char *p, size_t *index)
+unsigned int BLI_str_utf8_as_unicode_step(const char *__restrict p, size_t *__restrict index)
{
int i, mask = 0, len;
unsigned int result;
diff --git a/source/blender/blenlib/intern/threads.c b/source/blender/blenlib/intern/threads.c
index 66527b9b92a..146e1d531f1 100644
--- a/source/blender/blenlib/intern/threads.c
+++ b/source/blender/blenlib/intern/threads.c
@@ -400,6 +400,42 @@ void BLI_mutex_end(ThreadMutex *mutex)
pthread_mutex_destroy(mutex);
}
+/* Spin Locks */
+
+void BLI_spin_init(SpinLock *spin)
+{
+#ifdef __APPLE__
+ *spin = OS_SPINLOCK_INIT;
+#else
+ pthread_spin_init(spin, 0);
+#endif
+}
+
+void BLI_spin_lock(SpinLock *spin)
+{
+#ifdef __APPLE__
+ OSSpinLockLock(spin);
+#else
+ pthread_spin_lock(spin);
+#endif
+}
+
+void BLI_spin_unlock(SpinLock *spin)
+{
+#ifdef __APPLE__
+ OSSpinLockUnlock(spin);
+#else
+ pthread_spin_unlock(spin);
+#endif
+}
+
+void BLI_spin_end(SpinLock *spin)
+{
+#ifndef __APPLE__
+ pthread_spin_destroy(spin);
+#endif
+}
+
/* Read/Write Mutex Lock */
void BLI_rw_mutex_init(ThreadRWMutex *mutex)