[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [59700] trunk/blender/source/blender/ blenfont/intern/blf_font.c: Mingw Compiling Fix - Conversion from int to unsigned char...

Joshua Leung aligorith at gmail.com
Sun Sep 1 07:36:30 CEST 2013


Revision: 59700
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=59700
Author:   aligorith
Date:     2013-09-01 05:36:29 +0000 (Sun, 01 Sep 2013)
Log Message:
-----------
Mingw Compiling Fix - Conversion from int to unsigned char...

Apparently mingw/gcc is too stupid to recognise that the values
in alphatest will only be used if they're within the range of 
unsigned char (i.e. 0 <= x < 255) when this is done using a ternary
operator. Then again, it's quite hard for humans to immediately
parse what is going on here either! Converting this clever code
back to a more obvious form that mere mortals (and compilers it 
seems) can handle with ease ;)

Modified Paths:
--------------
    trunk/blender/source/blender/blenfont/intern/blf_font.c

Modified: trunk/blender/source/blender/blenfont/intern/blf_font.c
===================================================================
--- trunk/blender/source/blender/blenfont/intern/blf_font.c	2013-09-01 05:12:36 UTC (rev 59699)
+++ trunk/blender/source/blender/blenfont/intern/blf_font.c	2013-09-01 05:36:29 UTC (rev 59700)
@@ -376,15 +376,27 @@
 								cbuf[0] = b_col_char[0];
 								cbuf[1] = b_col_char[1];
 								cbuf[2] = b_col_char[2];
-								cbuf[3] = (alphatest = ((int)cbuf[3] + (int)b_col_char[3])) < 255 ?
-								          (unsigned char)(alphatest) : 255;
+								
+								alphatest = (int)cbuf[3] + (int)b_col_char[3];
+								if (alphatest < 255) {
+									cbuf[3] = (unsigned char)(alphatest);
+								}
+								else {
+									cbuf[3] = 255;
+								}
 							}
 							else {
 								cbuf[0] = (unsigned char)((b_col_char[0] * a) + (cbuf[0] * (1.0f - a)));
 								cbuf[1] = (unsigned char)((b_col_char[1] * a) + (cbuf[1] * (1.0f - a)));
 								cbuf[2] = (unsigned char)((b_col_char[2] * a) + (cbuf[2] * (1.0f - a)));
-								cbuf[3] = (alphatest = ((int)cbuf[3] + (int)((b_col_float[3] * a) * 255.0f))) < 255 ?
-								          (unsigned char)(alphatest) : 255;
+								
+								alphatest = ((int)cbuf[3] + (int)((b_col_float[3] * a) * 255.0f));
+								if (alphatest < 255) {
+									cbuf[3] = (unsigned char)(alphatest);
+								}
+								else {
+									cbuf[3] = 255;
+								}
 							}
 						}
 					}




More information about the Bf-blender-cvs mailing list