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:
authorCampbell Barton <ideasman42@gmail.com>2017-09-18 14:11:41 +0300
committerCampbell Barton <ideasman42@gmail.com>2017-09-18 16:55:41 +0300
commitd0344d7b7d619e62bc852c4d00df52cfbfdda544 (patch)
tree713d7bfd2faa3d77ef1f67a8072abf8a05a29256
parentc4fc9c4a8ecc421fdbf1f5d06d3b67ac4c8c1895 (diff)
Cleanup: use clamped rounding functions
-rw-r--r--source/blender/blenkernel/intern/customdata.c16
-rw-r--r--source/blender/editors/interface/interface.c9
-rw-r--r--source/blender/makesrna/intern/rna_mesh.c36
-rw-r--r--source/blender/render/intern/source/zbuf.c8
4 files changed, 35 insertions, 34 deletions
diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c
index 0939d35ed8d..68acb60f21a 100644
--- a/source/blender/blenkernel/intern/customdata.c
+++ b/source/blender/blenkernel/intern/customdata.c
@@ -828,10 +828,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)
@@ -1054,10 +1054,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);
}
}
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index 427291e713a..fd5159bb76c 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -1937,13 +1937,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 */
diff --git a/source/blender/makesrna/intern/rna_mesh.c b/source/blender/makesrna/intern/rna_mesh.c
index c25a70cea20..3d6dd9a5f35 100644
--- a/source/blender/makesrna/intern/rna_mesh.c
+++ b/source/blender/makesrna/intern/rna_mesh.c
@@ -304,7 +304,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)
@@ -316,7 +316,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)
@@ -328,7 +328,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)
@@ -586,9 +586,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)
@@ -604,9 +604,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)
@@ -622,9 +622,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)
@@ -640,9 +640,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)
@@ -658,9 +658,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))
diff --git a/source/blender/render/intern/source/zbuf.c b/source/blender/render/intern/source/zbuf.c
index 0b6d31ef902..1481e7a8059 100644
--- a/source/blender/render/intern/source/zbuf.c
+++ b/source/blender/render/intern/source/zbuf.c
@@ -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) {