(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
--- a/gfx.c Thu Sep 08 12:33:25 2005 +0000
+++ b/gfx.c Thu Sep 08 12:48:26 2005 +0000
@@ -1755,8 +1755,8 @@
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;
--- a/macros.h Thu Sep 08 12:33:25 2005 +0000
+++ b/macros.h Thu Sep 08 12:48:26 2005 +0000
@@ -158,6 +158,12 @@
#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)
{
--- a/screenshot.c Thu Sep 08 12:33:25 2005 +0000
+++ b/screenshot.c Thu Sep 08 12:48:26 2005 +0000
@@ -78,7 +78,7 @@
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');
--- a/settings.c Thu Sep 08 12:33:25 2005 +0000
+++ b/settings.c Thu Sep 08 12:48:26 2005 +0000
@@ -50,7 +50,7 @@
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) {
--- a/video/win32_v.c Thu Sep 08 12:33:25 2005 +0000
+++ b/video/win32_v.c Thu Sep 08 12:48:26 2005 +0000
@@ -536,7 +536,7 @@
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 @@
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;