Cleanup: use clamped rounding functions

This commit is contained in:
Campbell Barton 2017-09-18 21:11:41 +10:00
parent c4fc9c4a8e
commit d0344d7b7d
4 changed files with 35 additions and 34 deletions

View File

@ -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);
}
}

View File

@ -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 */

View File

@ -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))

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) {