[Bf-blender-cvs] [808ea62] master: Cleanup: confusing if statements & alignment

Campbell Barton noreply at git.blender.org
Wed Apr 8 04:25:21 CEST 2015


Commit: 808ea6271a0107cc3df52fb0ef18ccec191f6f15
Author: Campbell Barton
Date:   Wed Apr 8 12:23:38 2015 +1000
Branches: master
https://developer.blender.org/rB808ea6271a0107cc3df52fb0ef18ccec191f6f15

Cleanup: confusing if statements & alignment

===================================================================

M	intern/ghost/intern/GHOST_SystemWin32.cpp
M	source/blender/blenkernel/intern/sequencer.c
M	source/blender/blenloader/intern/versioning_legacy.c
M	source/blender/compositor/operations/COM_GlareGhostOperation.cpp
M	source/blender/editors/interface/interface_widgets.c
M	source/blender/editors/space_sequencer/sequencer_scopes.c
M	source/blender/render/intern/source/pipeline.c

===================================================================

diff --git a/intern/ghost/intern/GHOST_SystemWin32.cpp b/intern/ghost/intern/GHOST_SystemWin32.cpp
index 038e6a0..46ed8bb 100644
--- a/intern/ghost/intern/GHOST_SystemWin32.cpp
+++ b/intern/ghost/intern/GHOST_SystemWin32.cpp
@@ -714,8 +714,8 @@ GHOST_EventWheel *GHOST_SystemWin32::processWheelEvent(GHOST_WindowWin32 *window
 	
 	// zDelta /= WHEEL_DELTA;
 	// temporary fix below: microsoft now has added more precision, making the above division not work
-	if (zDelta <= 0) zDelta = -1; else zDelta = 1;
-	
+	zDelta = (zDelta <= 0) ? -1 : 1;
+
 	// short xPos = (short) LOWORD(lParam);	// horizontal position of pointer
 	// short yPos = (short) HIWORD(lParam);	// vertical position of pointer
 	return new GHOST_EventWheel(getSystem()->getMilliSeconds(), window, zDelta);
diff --git a/source/blender/blenkernel/intern/sequencer.c b/source/blender/blenkernel/intern/sequencer.c
index 4cea8aa..2fde98c 100644
--- a/source/blender/blenkernel/intern/sequencer.c
+++ b/source/blender/blenkernel/intern/sequencer.c
@@ -1161,30 +1161,25 @@ static void make_black_ibuf(ImBuf *ibuf)
 	}
 }
 
-static void multibuf(ImBuf *ibuf, float fmul)
+static void multibuf(ImBuf *ibuf, const float fmul)
 {
 	char *rt;
 	float *rt_float;
 
-	int a, mul, icol;
+	int a;
 
-	mul = (int)(256.0f * fmul);
 	rt = (char *)ibuf->rect;
 	rt_float = ibuf->rect_float;
 
 	if (rt) {
+		const int imul = (int)(256.0f * fmul);
 		a = ibuf->x * ibuf->y;
 		while (a--) {
+			rt[0] = min_ii((imul * rt[0]) >> 8, 255);
+			rt[1] = min_ii((imul * rt[1]) >> 8, 255);
+			rt[2] = min_ii((imul * rt[2]) >> 8, 255);
+			rt[3] = min_ii((imul * rt[3]) >> 8, 255);
 
-			icol = (mul * rt[0]) >> 8;
-			if (icol > 254) rt[0] = 255; else rt[0] = icol;
-			icol = (mul * rt[1]) >> 8;
-			if (icol > 254) rt[1] = 255; else rt[1] = icol;
-			icol = (mul * rt[2]) >> 8;
-			if (icol > 254) rt[2] = 255; else rt[2] = icol;
-			icol = (mul * rt[3]) >> 8;
-			if (icol > 254) rt[3] = 255; else rt[3] = icol;
-			
 			rt += 4;
 		}
 	}
diff --git a/source/blender/blenloader/intern/versioning_legacy.c b/source/blender/blenloader/intern/versioning_legacy.c
index 5dae6fb..94ad348 100644
--- a/source/blender/blenloader/intern/versioning_legacy.c
+++ b/source/blender/blenloader/intern/versioning_legacy.c
@@ -795,22 +795,14 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *main)
 				nr = me->totface;
 				tface = me->tface;
 				while (nr--) {
-					cp = (char *)&tface->col[0];
-					if (cp[1] > 126) cp[1] = 255; else cp[1] *= 2;
-					if (cp[2] > 126) cp[2] = 255; else cp[2] *= 2;
-					if (cp[3] > 126) cp[3] = 255; else cp[3] *= 2;
-					cp = (char *)&tface->col[1];
-					if (cp[1] > 126) cp[1] = 255; else cp[1] *= 2;
-					if (cp[2] > 126) cp[2] = 255; else cp[2] *= 2;
-					if (cp[3] > 126) cp[3] = 255; else cp[3] *= 2;
-					cp = (char *)&tface->col[2];
-					if (cp[1] > 126) cp[1] = 255; else cp[1] *= 2;
-					if (cp[2] > 126) cp[2] = 255; else cp[2] *= 2;
-					if (cp[3] > 126) cp[3] = 255; else cp[3] *= 2;
-					cp = (char *)&tface->col[3];
-					if (cp[1] > 126) cp[1] = 255; else cp[1] *= 2;
-					if (cp[2] > 126) cp[2] = 255; else cp[2] *= 2;
-					if (cp[3] > 126) cp[3] = 255; else cp[3] *= 2;
+					int j;
+					for (j = 0; j < 4; j++) {
+						int k;
+						cp = ((char *)&tface->col[j]) + 1;
+						for (k = 0; k < 3; k++) {
+							cp[k] = (cp[k] > 126) ? 255 : cp[k] * 2;
+						}
+					}
 
 					tface++;
 				}
diff --git a/source/blender/compositor/operations/COM_GlareGhostOperation.cpp b/source/blender/compositor/operations/COM_GlareGhostOperation.cpp
index 69b5bd7..eea6588 100644
--- a/source/blender/compositor/operations/COM_GlareGhostOperation.cpp
+++ b/source/blender/compositor/operations/COM_GlareGhostOperation.cpp
@@ -65,7 +65,7 @@ void GlareGhostOperation::generateGlare(float *data, MemoryBuffer *inputTile, No
 	if (isBreaked()) breaked = true;
 	if (!breaked) FastGaussianBlurOperation::IIR_gauss(tbuf2, s2, 2, 3);
 
-	if (settings->iter & 1) ofs = 0.5f; else ofs = 0.f;
+	ofs = (settings->iter & 1) ? 0.5f : 0.0f;
 	for (x = 0; x < (settings->iter * 4); x++) {
 		y = x & 3;
 		cm[x][0] = cm[x][1] = cm[x][2] = 1;
diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c
index 1cf78e6..51a9823 100644
--- a/source/blender/editors/interface/interface_widgets.c
+++ b/source/blender/editors/interface/interface_widgets.c
@@ -602,10 +602,10 @@ static void round_box_shade_col4_r(unsigned char r_col[4], const char col1[4], c
 	const int faci = FTOCHAR(fac);
 	const int facm = 255 - faci;
 
-	r_col[0] = (faci * col1[0] + facm * col2[0]) >> 8;
-	r_col[1] = (faci * col1[1] + facm * col2[1]) >> 8;
-	r_col[2] = (faci * col1[2] + facm * col2[2]) >> 8;
-	r_col[3] = (faci * col1[3] + facm * col2[3]) >> 8;
+	r_col[0] = (faci * col1[0] + facm * col2[0]) / 256;
+	r_col[1] = (faci * col1[1] + facm * col2[1]) / 256;
+	r_col[2] = (faci * col1[2] + facm * col2[2]) / 256;
+	r_col[3] = (faci * col1[3] + facm * col2[3]) / 256;
 }
 
 static void widget_verts_to_triangle_strip(uiWidgetBase *wtb, const int totvert, float triangle_strip[WIDGET_SIZE_MAX * 2 + 2][2])
diff --git a/source/blender/editors/space_sequencer/sequencer_scopes.c b/source/blender/editors/space_sequencer/sequencer_scopes.c
index b4bcfb4..404671c 100644
--- a/source/blender/editors/space_sequencer/sequencer_scopes.c
+++ b/source/blender/editors/space_sequencer/sequencer_scopes.c
@@ -648,13 +648,13 @@ static ImBuf *make_vectorscope_view_from_ibuf_byte(ImBuf *ibuf)
 		wtable[x] = (unsigned char) (pow(((float) x + 1) / 256, scope_gamma) * 255);
 	}
 
-	for (x = 0; x <= 255; x++) {
-		vectorscope_put_cross(255,     0, 255 - x, tgt, w, h, 1);
-		vectorscope_put_cross(255,     x,      0, tgt, w, h, 1);
-		vectorscope_put_cross(255 - x,   255,      0, tgt, w, h, 1);
-		vectorscope_put_cross(0,        255,      x, tgt, w, h, 1);
-		vectorscope_put_cross(0,    255 - x,    255, tgt, w, h, 1);
-		vectorscope_put_cross(x,          0,    255, tgt, w, h, 1);
+	for (x = 0; x < 256; x++) {
+		vectorscope_put_cross(255,       0, 255 - x, tgt, w, h, 1);
+		vectorscope_put_cross(255,       x,       0, tgt, w, h, 1);
+		vectorscope_put_cross(255 - x, 255,       0, tgt, w, h, 1);
+		vectorscope_put_cross(0,       255,       x, tgt, w, h, 1);
+		vectorscope_put_cross(0,   255 - x,     255, tgt, w, h, 1);
+		vectorscope_put_cross(x,         0,     255, tgt, w, h, 1);
 	}
 
 	for (y = 0; y < ibuf->y; y++) {
@@ -695,12 +695,12 @@ static ImBuf *make_vectorscope_view_from_ibuf_float(ImBuf *ibuf)
 	}
 
 	for (x = 0; x <= 255; x++) {
-		vectorscope_put_cross(255,     0, 255 - x, tgt, w, h, 1);
-		vectorscope_put_cross(255,     x,      0, tgt, w, h, 1);
-		vectorscope_put_cross(255 - x,   255,      0, tgt, w, h, 1);
-		vectorscope_put_cross(0,        255,      x, tgt, w, h, 1);
-		vectorscope_put_cross(0,    255 - x,    255, tgt, w, h, 1);
-		vectorscope_put_cross(x,          0,    255, tgt, w, h, 1);
+		vectorscope_put_cross(255,       0, 255 - x, tgt, w, h, 1);
+		vectorscope_put_cross(255,       x,       0, tgt, w, h, 1);
+		vectorscope_put_cross(255 - x, 255,       0, tgt, w, h, 1);
+		vectorscope_put_cross(0,       255,       x, tgt, w, h, 1);
+		vectorscope_put_cross(0,   255 - x,     255, tgt, w, h, 1);
+		vectorscope_put_cross(x,         0,     255, tgt, w, h, 1);
 	}
 
 	for (y = 0; y < ibuf->y; y++) {
diff --git a/source/blender/render/intern/source/pipeline.c b/source/blender/render/intern/source/pipeline.c
index 4a76718..05bee6f 100644
--- a/source/blender/render/intern/source/pipeline.c
+++ b/source/blender/render/intern/source/pipeline.c
@@ -2249,9 +2249,9 @@ static void do_merge_fullsample(Render *re, bNodeTree *ntree)
 				
 				for (x = 0; x < re->rectx; x++, rf += 4, col += 4) {
 					/* clamping to 1.0 is needed for correct AA */
-					if (col[0] < 0.0f) col[0] = 0.0f; else if (col[0] > 1.0f) col[0] = 1.0f;
-					if (col[1] < 0.0f) col[1] = 0.0f; else if (col[1] > 1.0f) col[1] = 1.0f;
-					if (col[2] < 0.0f) col[2] = 0.0f; else if (col[2] > 1.0f) col[2] = 1.0f;
+					CLAMP(col[0], 0.0, 1.0f);
+					CLAMP(col[1], 0.0, 1.0f);
+					CLAMP(col[2], 0.0, 1.0f);
 					
 					add_filt_fmask_coord(filt, col, rf, re->rectx, re->recty, x, y);
 				}




More information about the Bf-blender-cvs mailing list