From 2e9e5a1502b3998dd2e2b63576ae11155fe0ed21 Mon Sep 17 00:00:00 2001 From: Bill Meltsner Date: Sun, 15 May 2011 16:33:38 -0400 Subject: [PATCH] make po2 stuff better --- src/common/math.h | 10 ++++++++++ src/modules/image/devil/ImageData.cpp | 18 ++++-------------- src/modules/image/devil/ImageData.h | 7 ------- 3 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/common/math.h b/src/common/math.h index 4115f44d7..ae8e4aaa5 100644 --- a/src/common/math.h +++ b/src/common/math.h @@ -21,6 +21,8 @@ #ifndef LOVE_MATH_H #define LOVE_MATH_H +#include // for CHAR_BIT + /* Definitions of useful mathematical constants * M_E - e * M_LOG2E - log2(e) @@ -64,6 +66,14 @@ struct vertex float x, y; float s, t; }; + +inline int next_p2(int x) +{ + x += (x == 0); + x--; + for (unsigned int i = 1; i < sizeof(int)*CHAR_BIT; i <<= 1) x |= x >> i; + return ++x; +} } // love diff --git a/src/modules/image/devil/ImageData.cpp b/src/modules/image/devil/ImageData.cpp index 99a46b2e5..2f2e5834c 100644 --- a/src/modules/image/devil/ImageData.cpp +++ b/src/modules/image/devil/ImageData.cpp @@ -21,24 +21,14 @@ #include "ImageData.h" // STD +#include #include // LOVE #include +#include #include -int toPo2(int n) -{ - n -= 1; - n |= n >> 1; - n |= n >> 2; - n |= n >> 4; - n |= n >> 8; - n |= n >> 16; - n |= n >> 32; - return n+1; -} - namespace love { namespace image @@ -54,8 +44,8 @@ namespace devil ilBindImage(image); //scale to nearest bigger po2 - width = toPo2(width); - height = toPo2(height); + width = next_p2(width); + height = next_p2(height); //create and populate the image bool success = (ilTexImage(width, height, 1, bpp, IL_RGBA, IL_UNSIGNED_BYTE, data) == IL_TRUE); diff --git a/src/modules/image/devil/ImageData.h b/src/modules/image/devil/ImageData.h index 4c6ae1da6..055e7d864 100644 --- a/src/modules/image/devil/ImageData.h +++ b/src/modules/image/devil/ImageData.h @@ -23,18 +23,11 @@ // LOVE #include -#include #include // DevIL #include -// String -#include - -// Math -#include - namespace love { namespace image