Merge branch 'master' into blender2.8

This commit is contained in:
Campbell Barton 2017-09-18 23:56:19 +10:00
commit 533ec46efb
6 changed files with 83 additions and 34 deletions

View File

@ -810,10 +810,10 @@ static void layerInterp_mloopcol(
* although weights should also not cause this situation */
/* also delay writing to the destination incase dest is in sources */
mc->r = CLAMPIS(iroundf(col.r), 0, 255);
mc->g = CLAMPIS(iroundf(col.g), 0, 255);
mc->b = CLAMPIS(iroundf(col.b), 0, 255);
mc->a = CLAMPIS(iroundf(col.a), 0, 255);
mc->r = round_fl_to_uchar_clamp(col.r);
mc->g = round_fl_to_uchar_clamp(col.g);
mc->b = round_fl_to_uchar_clamp(col.b);
mc->a = round_fl_to_uchar_clamp(col.a);
}
static int layerMaxNum_mloopcol(void)
@ -1036,10 +1036,10 @@ static void layerInterp_mcol(
/* Subdivide smooth or fractal can cause problems without clamping
* although weights should also not cause this situation */
mc[j].a = CLAMPIS(iroundf(col[j].a), 0, 255);
mc[j].r = CLAMPIS(iroundf(col[j].r), 0, 255);
mc[j].g = CLAMPIS(iroundf(col[j].g), 0, 255);
mc[j].b = CLAMPIS(iroundf(col[j].b), 0, 255);
mc[j].a = round_fl_to_uchar_clamp(col[j].a);
mc[j].r = round_fl_to_uchar_clamp(col[j].r);
mc[j].g = round_fl_to_uchar_clamp(col[j].g);
mc[j].b = round_fl_to_uchar_clamp(col[j].b);
}
}

View File

@ -153,6 +153,20 @@ MINLINE int iroundf(float a);
MINLINE int divide_round_i(int a, int b);
MINLINE int mod_i(int i, int n);
MINLINE signed char round_fl_to_char_clamp(float a);
MINLINE unsigned char round_fl_to_uchar_clamp(float a);
MINLINE short round_fl_to_short_clamp(float a);
MINLINE unsigned short round_fl_to_ushort_clamp(float a);
MINLINE int round_fl_to_int_clamp(float a);
MINLINE unsigned int round_fl_to_uint_clamp(float a);
MINLINE signed char round_db_to_char_clamp(double a);
MINLINE unsigned char round_db_to_uchar_clamp(double a);
MINLINE short round_db_to_short_clamp(double a);
MINLINE unsigned short round_db_to_ushort_clamp(double a);
MINLINE int round_db_to_int_clamp(double a);
MINLINE unsigned int round_db_to_uint_clamp(double a);
int pow_i(int base, int exp);
double double_round(double x, int ndigits);

View File

@ -33,6 +33,7 @@
#include <float.h>
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#ifdef __SSE2__
# include <emmintrin.h>
@ -181,11 +182,44 @@ MINLINE unsigned power_of_2_min_u(unsigned x)
return x - (x >> 1);
}
/* rounding and clamping */
MINLINE int iroundf(float a)
{
return (int)floorf(a + 0.5f);
}
#define _round_clamp_fl_impl(arg, ty, min, max) { \
float r = floorf(arg + 0.5f); \
if (UNLIKELY(r <= (float)min)) return (ty)min; \
else if (UNLIKELY(r >= (float)max)) return (ty)max; \
else return (ty)r; \
}
#define _round_clamp_db_impl(arg, ty, min, max) { \
double r = floor(arg + 0.5); \
if (UNLIKELY(r <= (double)min)) return (ty)min; \
else if (UNLIKELY(r >= (double)max)) return (ty)max; \
else return (ty)r; \
}
MINLINE signed char round_fl_to_char_clamp(float a) { _round_clamp_fl_impl(a, signed char, SCHAR_MIN, SCHAR_MAX) }
MINLINE unsigned char round_fl_to_uchar_clamp(float a) { _round_clamp_fl_impl(a, unsigned char, 0, UCHAR_MAX) }
MINLINE short round_fl_to_short_clamp(float a) { _round_clamp_fl_impl(a, short, SHRT_MIN, SHRT_MAX) }
MINLINE unsigned short round_fl_to_ushort_clamp(float a) { _round_clamp_fl_impl(a, unsigned short, 0, USHRT_MAX) }
MINLINE int round_fl_to_int_clamp(float a) { _round_clamp_fl_impl(a, int, INT_MIN, INT_MAX) }
MINLINE unsigned int round_fl_to_uint_clamp(float a) { _round_clamp_fl_impl(a, unsigned int, 0, UINT_MAX) }
MINLINE signed char round_db_to_char_clamp(double a) { _round_clamp_db_impl(a, signed char, SCHAR_MIN, SCHAR_MAX) }
MINLINE unsigned char round_db_to_uchar_clamp(double a) { _round_clamp_db_impl(a, unsigned char, 0, UCHAR_MAX) }
MINLINE short round_db_to_short_clamp(double a) { _round_clamp_db_impl(a, short, SHRT_MIN, SHRT_MAX) }
MINLINE unsigned short round_db_to_ushort_clamp(double a) { _round_clamp_db_impl(a, unsigned short, 0, USHRT_MAX) }
MINLINE int round_db_to_int_clamp(double a) { _round_clamp_db_impl(a, int, INT_MIN, INT_MAX) }
MINLINE unsigned int round_db_to_uint_clamp(double a) { _round_clamp_db_impl(a, unsigned int, 0, UINT_MAX) }
#undef _round_clamp_fl_impl
#undef _round_clamp_db_impl
/* integer division that rounds 0.5 up, particularly useful for color blending
* with integers, to avoid gradual darkening when rounding down */
MINLINE int divide_round_i(int a, int b)

View File

@ -1936,13 +1936,14 @@ void ui_but_value_set(uiBut *but, double value)
else {
/* first do rounding */
if (but->pointype == UI_BUT_POIN_CHAR) {
value = (char)floor(value + 0.5);
value = round_db_to_uchar_clamp(value);
}
else if (but->pointype == UI_BUT_POIN_SHORT) {
value = (short)floor(value + 0.5);
value = round_db_to_short_clamp(value);
}
else if (but->pointype == UI_BUT_POIN_INT) {
value = round_db_to_int_clamp(value);
}
else if (but->pointype == UI_BUT_POIN_INT)
value = (int)floor(value + 0.5);
else if (but->pointype == UI_BUT_POIN_FLOAT) {
float fval = (float)value;
if (fval >= -0.00001f && fval <= 0.00001f) fval = 0.0f; /* prevent negative zero */

View File

@ -323,7 +323,7 @@ static float rna_MeshVertex_bevel_weight_get(PointerRNA *ptr)
static void rna_MeshVertex_bevel_weight_set(PointerRNA *ptr, float value)
{
MVert *mvert = (MVert *)ptr->data;
mvert->bweight = (char)(CLAMPIS(value * 255.0f, 0, 255));
mvert->bweight = round_fl_to_uchar_clamp(value * 255.0f);
}
static float rna_MEdge_bevel_weight_get(PointerRNA *ptr)
@ -335,7 +335,7 @@ static float rna_MEdge_bevel_weight_get(PointerRNA *ptr)
static void rna_MEdge_bevel_weight_set(PointerRNA *ptr, float value)
{
MEdge *medge = (MEdge *)ptr->data;
medge->bweight = (char)(CLAMPIS(value * 255.0f, 0, 255));
medge->bweight = round_fl_to_uchar_clamp(value * 255.0f);
}
static float rna_MEdge_crease_get(PointerRNA *ptr)
@ -347,7 +347,7 @@ static float rna_MEdge_crease_get(PointerRNA *ptr)
static void rna_MEdge_crease_set(PointerRNA *ptr, float value)
{
MEdge *medge = (MEdge *)ptr->data;
medge->crease = (char)(CLAMPIS(value * 255.0f, 0, 255));
medge->crease = round_fl_to_uchar_clamp(value * 255.0f);
}
static void rna_MeshLoop_normal_get(PointerRNA *ptr, float *values)
@ -605,9 +605,9 @@ static void rna_MeshColor_color1_set(PointerRNA *ptr, const float *values)
{
MCol *mcol = (MCol *)ptr->data;
(&mcol[0].r)[2] = (char)(CLAMPIS(values[0] * 255.0f, 0, 255));
(&mcol[0].r)[1] = (char)(CLAMPIS(values[1] * 255.0f, 0, 255));
(&mcol[0].r)[0] = (char)(CLAMPIS(values[2] * 255.0f, 0, 255));
(&mcol[0].r)[2] = round_fl_to_uchar_clamp(values[0] * 255.0f);
(&mcol[0].r)[1] = round_fl_to_uchar_clamp(values[1] * 255.0f);
(&mcol[0].r)[0] = round_fl_to_uchar_clamp(values[2] * 255.0f);
}
static void rna_MeshColor_color2_get(PointerRNA *ptr, float *values)
@ -623,9 +623,9 @@ static void rna_MeshColor_color2_set(PointerRNA *ptr, const float *values)
{
MCol *mcol = (MCol *)ptr->data;
(&mcol[1].r)[2] = (char)(CLAMPIS(values[0] * 255.0f, 0, 255));
(&mcol[1].r)[1] = (char)(CLAMPIS(values[1] * 255.0f, 0, 255));
(&mcol[1].r)[0] = (char)(CLAMPIS(values[2] * 255.0f, 0, 255));
(&mcol[1].r)[2] = round_fl_to_uchar_clamp(values[0] * 255.0f);
(&mcol[1].r)[1] = round_fl_to_uchar_clamp(values[1] * 255.0f);
(&mcol[1].r)[0] = round_fl_to_uchar_clamp(values[2] * 255.0f);
}
static void rna_MeshColor_color3_get(PointerRNA *ptr, float *values)
@ -641,9 +641,9 @@ static void rna_MeshColor_color3_set(PointerRNA *ptr, const float *values)
{
MCol *mcol = (MCol *)ptr->data;
(&mcol[2].r)[2] = (char)(CLAMPIS(values[0] * 255.0f, 0, 255));
(&mcol[2].r)[1] = (char)(CLAMPIS(values[1] * 255.0f, 0, 255));
(&mcol[2].r)[0] = (char)(CLAMPIS(values[2] * 255.0f, 0, 255));
(&mcol[2].r)[2] = round_fl_to_uchar_clamp(values[0] * 255.0f);
(&mcol[2].r)[1] = round_fl_to_uchar_clamp(values[1] * 255.0f);
(&mcol[2].r)[0] = round_fl_to_uchar_clamp(values[2] * 255.0f);
}
static void rna_MeshColor_color4_get(PointerRNA *ptr, float *values)
@ -659,9 +659,9 @@ static void rna_MeshColor_color4_set(PointerRNA *ptr, const float *values)
{
MCol *mcol = (MCol *)ptr->data;
(&mcol[3].r)[2] = (char)(CLAMPIS(values[0] * 255.0f, 0, 255));
(&mcol[3].r)[1] = (char)(CLAMPIS(values[1] * 255.0f, 0, 255));
(&mcol[3].r)[0] = (char)(CLAMPIS(values[2] * 255.0f, 0, 255));
(&mcol[3].r)[2] = round_fl_to_uchar_clamp(values[0] * 255.0f);
(&mcol[3].r)[1] = round_fl_to_uchar_clamp(values[1] * 255.0f);
(&mcol[3].r)[0] = round_fl_to_uchar_clamp(values[2] * 255.0f);
}
static void rna_MeshLoopColor_color_get(PointerRNA *ptr, float *values)
@ -677,9 +677,9 @@ static void rna_MeshLoopColor_color_set(PointerRNA *ptr, const float *values)
{
MLoopCol *mcol = (MLoopCol *)ptr->data;
(&mcol->r)[0] = (char)(CLAMPIS(values[0] * 255.0f, 0, 255));
(&mcol->r)[1] = (char)(CLAMPIS(values[1] * 255.0f, 0, 255));
(&mcol->r)[2] = (char)(CLAMPIS(values[2] * 255.0f, 0, 255));
(&mcol->r)[0] = round_fl_to_uchar_clamp(values[0] * 255.0f);
(&mcol->r)[1] = round_fl_to_uchar_clamp(values[1] * 255.0f);
(&mcol->r)[2] = round_fl_to_uchar_clamp(values[2] * 255.0f);
}
static int rna_Mesh_texspace_editable(PointerRNA *ptr, const char **UNUSED(r_info))

View File

@ -393,7 +393,7 @@ static void zbuffillAc4(ZSpan *zspan, int obi, int zvlnr,
zverg-= zspan->polygon_offset;
while (x>=0) {
intzverg= (int)CLAMPIS(zverg, INT_MIN, INT_MAX);
intzverg = round_db_to_int_clamp(zverg);
if ( intzverg < *rz) {
if (!zspan->rectmask || intzverg > *rm) {
@ -1137,7 +1137,7 @@ static void zbuffillGLinv4(ZSpan *zspan, int obi, int zvlnr,
x= sn2-sn1;
while (x>=0) {
intzverg= (int)CLAMPIS(zverg, INT_MIN, INT_MAX);
intzverg = round_db_to_int_clamp(zverg);
if ( intzverg > *rz || *rz==0x7FFFFFFF) { /* UNIQUE LINE: see comment above */
if (!zspan->rectmask || intzverg > *rm) {
@ -1260,7 +1260,7 @@ static void zbuffillGL4(ZSpan *zspan, int obi, int zvlnr,
x= sn2-sn1;
while (x>=0) {
intzverg= (int)CLAMPIS(zverg, INT_MIN, INT_MAX);
intzverg = round_db_to_int_clamp(zverg);
if (intzverg < *rz) { /* ONLY UNIQUE LINE: see comment above */
if (!zspan->rectmask || intzverg > *rm) {
@ -1383,7 +1383,7 @@ static void zbuffillGL_onlyZ(ZSpan *zspan, int UNUSED(obi), int UNUSED(zvlnr),
x= sn2-sn1;
while (x>=0) {
int zvergi= (int)CLAMPIS(zverg, INT_MIN, INT_MAX);
int zvergi = round_db_to_int_clamp(zverg);
/* option: maintain two depth values, closest and 2nd closest */
if (zvergi < *rz) {