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/math_color_inline.c8
-rw-r--r--source/blender/blenlib/intern/math_geom.c44
-rw-r--r--source/blender/blenlib/intern/polyfill_2d.c5
-rw-r--r--source/blender/blenlib/intern/string_utf8.c50
4 files changed, 102 insertions, 5 deletions
diff --git a/source/blender/blenlib/intern/math_color_inline.c b/source/blender/blenlib/intern/math_color_inline.c
index d7a2d681f33..f5aaddc0ea3 100644
--- a/source/blender/blenlib/intern/math_color_inline.c
+++ b/source/blender/blenlib/intern/math_color_inline.c
@@ -225,8 +225,8 @@ MINLINE void srgb_to_linearrgb_uchar4_predivide(float linear[4], const unsigned
srgb_to_linearrgb_predivide_v4(linear, fsrgb);
}
-MINLINE void rgba_char_args_set(
- char col[4], const char r, const char g, const char b, const char a)
+MINLINE void rgba_uchar_args_set(
+ uchar col[4], const uchar r, const uchar g, const uchar b, const uchar a)
{
col[0] = r;
col[1] = g;
@@ -243,8 +243,8 @@ MINLINE void rgba_float_args_set(
col[3] = a;
}
-MINLINE void rgba_char_args_test_set(
- char col[4], const char r, const char g, const char b, const char a)
+MINLINE void rgba_uchar_args_test_set(
+ uchar col[4], const uchar r, const uchar g, const uchar b, const uchar a)
{
if (col[3] == 0) {
col[0] = r;
diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c
index 7cdac6b1497..b4a96ff316a 100644
--- a/source/blender/blenlib/intern/math_geom.c
+++ b/source/blender/blenlib/intern/math_geom.c
@@ -4481,6 +4481,50 @@ void projmat_dimensions(const float projmat[4][4],
}
}
+/**
+ * Creates a projection matrix for a small region of the viewport.
+ *
+ * \param projmat: Projection Matrix.
+ * \param win_size: Viewport Size.
+ * \param x_min, x_max, y_min, y_max: Coordinates of the subregion.
+ * \return r_projmat: Resulting Projection Matrix.
+ */
+void projmat_from_subregion(const float projmat[4][4],
+ const int win_size[2],
+ const int x_min,
+ const int x_max,
+ const int y_min,
+ const int y_max,
+ float r_projmat[4][4])
+{
+ float rect_width = (float)(x_max - x_min);
+ float rect_height = (float)(y_max - y_min);
+
+ float x_fac = (float)((x_min + x_max) - win_size[0]) / rect_width;
+ float y_fac = (float)((y_min + y_max) - win_size[1]) / rect_height;
+
+ copy_m4_m4(r_projmat, projmat);
+ r_projmat[0][0] *= (float)win_size[0] / rect_width;
+ r_projmat[1][1] *= (float)win_size[1] / rect_height;
+
+#if 0 /* TODO: check if this is more efficient. */
+ r_projmat[2][0] -= x_fac * r_projmat[2][3];
+ r_projmat[2][1] -= y_fac * r_projmat[2][3];
+
+ r_projmat[3][0] -= x_fac * r_projmat[3][3];
+ r_projmat[3][1] -= y_fac * r_projmat[3][3];
+#else
+ if (projmat[3][3] == 0.0f) {
+ r_projmat[2][0] += x_fac;
+ r_projmat[2][1] += y_fac;
+ }
+ else {
+ r_projmat[3][0] -= x_fac;
+ r_projmat[3][1] -= y_fac;
+ }
+#endif
+}
+
static void i_multmatrix(float icand[4][4], float Vm[4][4])
{
int row, col;
diff --git a/source/blender/blenlib/intern/polyfill_2d.c b/source/blender/blenlib/intern/polyfill_2d.c
index 575a4a06d6a..31b18079c73 100644
--- a/source/blender/blenlib/intern/polyfill_2d.c
+++ b/source/blender/blenlib/intern/polyfill_2d.c
@@ -193,7 +193,10 @@ BLI_INLINE eSign signum_enum(float a)
*/
BLI_INLINE float area_tri_signed_v2_alt_2x(const float v1[2], const float v2[2], const float v3[2])
{
- return ((v1[0] * (v2[1] - v3[1])) + (v2[0] * (v3[1] - v1[1])) + (v3[0] * (v1[1] - v2[1])));
+ float d2[2], d3[2];
+ sub_v2_v2v2(d2, v2, v1);
+ sub_v2_v2v2(d3, v3, v1);
+ return (d2[0] * d3[1]) - (d3[0] * d2[1]);
}
static eSign span_tri_v2_sign(const float v1[2], const float v2[2], const float v3[2])
diff --git a/source/blender/blenlib/intern/string_utf8.c b/source/blender/blenlib/intern/string_utf8.c
index 01412416854..22c23727d76 100644
--- a/source/blender/blenlib/intern/string_utf8.c
+++ b/source/blender/blenlib/intern/string_utf8.c
@@ -868,3 +868,53 @@ size_t BLI_str_partition_ex_utf8(const char *str,
*suf = *sep = NULL;
return str_len;
}
+
+/* -------------------------------------------------------------------- */
+/** \name Offset Conversion in Strings
+ * \{ */
+
+int BLI_str_utf8_offset_to_index(const char *str, int offset)
+{
+ int index = 0, pos = 0;
+ while (pos != offset) {
+ pos += BLI_str_utf8_size(str + pos);
+ index++;
+ }
+ return index;
+}
+
+int BLI_str_utf8_offset_from_index(const char *str, int index)
+{
+ int offset = 0, pos = 0;
+ while (pos != index) {
+ offset += BLI_str_utf8_size(str + offset);
+ pos++;
+ }
+ return offset;
+}
+
+int BLI_str_utf8_offset_to_column(const char *str, int offset)
+{
+ int column = 0, pos = 0;
+ while (pos < offset) {
+ column += BLI_str_utf8_char_width_safe(str + pos);
+ pos += BLI_str_utf8_size_safe(str + pos);
+ }
+ return column;
+}
+
+int BLI_str_utf8_offset_from_column(const char *str, int column)
+{
+ int offset = 0, pos = 0, col;
+ while (*(str + offset) && pos < column) {
+ col = BLI_str_utf8_char_width_safe(str + offset);
+ if (pos + col > column) {
+ break;
+ }
+ offset += BLI_str_utf8_size_safe(str + offset);
+ pos += col;
+ }
+ return offset;
+}
+
+/** \} */