diff options
-rw-r--r-- | gfx.c | 4 | ||||
-rw-r--r-- | macros.h | 6 | ||||
-rw-r--r-- | screenshot.c | 2 | ||||
-rw-r--r-- | settings.c | 2 | ||||
-rw-r--r-- | video/win32_v.c | 4 |
5 files changed, 12 insertions, 6 deletions
@@ -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; @@ -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; |