summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortron <tron@openttd.org>2005-09-08 12:48:26 +0000
committertron <tron@openttd.org>2005-09-08 12:48:26 +0000
commitc20b5883bd7e917dee83367eeea9e795d16bfc63 (patch)
tree3f41cacc0471e60af369fc95349585751ff00335
parent0f08a1c69421f2d0ec718d8b53404c53fb65606a (diff)
downloadopenttd-c20b5883bd7e917dee83367eeea9e795d16bfc63.tar.xz
(svn r2924) Introduce the ALIGN() macro which aligns values to multiples of a power of 2, for exact semantics see the commment in macros.h
-rw-r--r--gfx.c4
-rw-r--r--macros.h6
-rw-r--r--screenshot.c2
-rw-r--r--settings.c2
-rw-r--r--video/win32_v.c4
5 files changed, 12 insertions, 6 deletions
diff --git a/gfx.c b/gfx.c
index d22d864c7..38c6cd009 100644
--- a/gfx.c
+++ b/gfx.c
@@ -1755,8 +1755,8 @@ void RedrawScreenRect(int left, int top, int right, int bottom)
void DrawDirtyBlocks(void)
{
byte *b = _dirty_blocks;
- const int w = (_screen.width + 63) & ~63;
- const int h = (_screen.height + 7) & ~7;
+ const int w = ALIGN(_screen.width, 64);
+ const int h = ALIGN(_screen.height, 8);
int x;
int y;
diff --git a/macros.h b/macros.h
index 1232005cd..26c4d9985 100644
--- a/macros.h
+++ b/macros.h
@@ -158,6 +158,12 @@ static inline void swap_tile(TileIndex *a, TileIndex *b) { TileIndex t = *a; *a
#define ROL(x, n) ((x) << (n) | (x) >> (sizeof(x) * 8 - (n)))
#define ROR(x, n) ((x) >> (n) | (x) << (sizeof(x) * 8 - (n)))
+/**
+ * Return the smallest multiple of n equal or greater than x
+ * @note n must be a power of 2
+ */
+#define ALIGN(x, n) (((x) + (n) - 1) & ~((n) - 1))
+
/* IS_INT_INSIDE = filter for ascii-function codes like BELL and so on [we need an special filter here later] */
static inline bool IsValidAsciiChar(byte key)
{
diff --git a/screenshot.c b/screenshot.c
index ee5153d3b..ac9a4433f 100644
--- a/screenshot.c
+++ b/screenshot.c
@@ -78,7 +78,7 @@ static bool MakeBmpImage(const char *name, ScreenshotCallback *callb, void *user
if (f == NULL) return false;
// each scanline must be aligned on a 32bit boundary
- padw = (w + 3) & ~3;
+ padw = ALIGN(w, 4);
// setup the file header
bfh.type = TO_LE16('MB');
diff --git a/settings.c b/settings.c
index 65eef0544..9e3580299 100644
--- a/settings.c
+++ b/settings.c
@@ -50,7 +50,7 @@ static void *pool_alloc(SettingsMemoryPool **pool, uint size)
uint pos;
SettingsMemoryPool *p = *pool;
- size = (size + 3) & ~3; // align everything to a 32 bit boundary
+ size = ALIGN(size, 4); // align everything to a 32 bit boundary
// first check if there's memory in the next pool
if (p->next && p->next->pos + size <= p->next->size) {
diff --git a/video/win32_v.c b/video/win32_v.c
index 3656e66ad..90997804a 100644
--- a/video/win32_v.c
+++ b/video/win32_v.c
@@ -536,7 +536,7 @@ static bool AllocateDibSection(int w, int h)
return false;
_screen.width = w;
- _screen.pitch = (w + 3) & ~0x3;
+ _screen.pitch = ALIGN(w, 4);
_screen.height = h;
if (_wnd.alloced_bits) {
@@ -549,7 +549,7 @@ static bool AllocateDibSection(int w, int h)
bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
if (_wnd.double_size) {
- w = (w + 3) & ~0x3;
+ w = ALIGN(w, 4);
_wnd.alloced_bits = _wnd.buffer_bits = malloc(w * h);
w *= 2;
h *= 2;