From 2253b63c979fbfbbb6f06c93ede85d9b9b6caddf Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 16 Dec 2011 09:25:07 +0000 Subject: static functions for getting power of 2 values were being copied about too much, add to the BLI_math api. - is_power_of_2_i - power_of_2_min_i - power_of_2_max_i --- source/blender/windowmanager/intern/wm_draw.c | 35 +++++---------------------- 1 file changed, 6 insertions(+), 29 deletions(-) (limited to 'source/blender/windowmanager/intern/wm_draw.c') diff --git a/source/blender/windowmanager/intern/wm_draw.c b/source/blender/windowmanager/intern/wm_draw.c index f03680852ea..4fe11044d30 100644 --- a/source/blender/windowmanager/intern/wm_draw.c +++ b/source/blender/windowmanager/intern/wm_draw.c @@ -43,6 +43,7 @@ #include "BLI_blenlib.h" #include "BLI_utildefines.h" +#include "BLI_math_base.h" #include "BKE_context.h" #include "BKE_global.h" @@ -355,36 +356,12 @@ typedef struct wmDrawTriple { GLenum target; } wmDrawTriple; -static int is_pow2(int n) -{ - return ((n)&(n-1))==0; -} - -static int smaller_pow2(int n) -{ - while (!is_pow2(n)) - n= n&(n-1); - - return n; -} - -static int larger_pow2(int n) -{ - if (is_pow2(n)) - return n; - - while(!is_pow2(n)) - n= n&(n-1); - - return n*2; -} - static void split_width(int x, int n, int *splitx, int *nx) { int a, newnx, waste; /* if already power of two just use it */ - if(is_pow2(x)) { + if(is_power_of_2_i(x)) { splitx[0]= x; (*nx)++; return; @@ -392,12 +369,12 @@ static void split_width(int x, int n, int *splitx, int *nx) if(n == 1) { /* last part, we have to go larger */ - splitx[0]= larger_pow2(x); + splitx[0]= power_of_2_max_i(x); (*nx)++; } else { /* two or more parts to go, use smaller part */ - splitx[0]= smaller_pow2(x); + splitx[0]= power_of_2_min_i(x); newnx= ++(*nx); split_width(x-splitx[0], n-1, splitx+1, &newnx); @@ -406,8 +383,8 @@ static void split_width(int x, int n, int *splitx, int *nx) /* if we waste more space or use the same amount, * revert deeper splits and just use larger */ - if(waste >= larger_pow2(x)) { - splitx[0]= larger_pow2(x); + if(waste >= power_of_2_max_i(x)) { + splitx[0]= power_of_2_max_i(x); memset(splitx+1, 0, sizeof(int)*(n-1)); } else -- cgit v1.2.3