ALIGN macro aligns up instead of down;

So you don't have to add (n - 1).  Hopefully this turns out to be
the common case.
This commit is contained in:
bjorn 2020-08-04 12:23:45 -06:00
parent 86fee211f1
commit 83ff4783c2
2 changed files with 2 additions and 2 deletions

View File

@ -32,7 +32,7 @@
#define MAX(a, b) (a > b ? a : b)
#define MIN(a, b) (a < b ? a : b)
#define CLAMP(x, min, max) MAX(min, MIN(max, x))
#define ALIGN(p, n) ((uintptr_t) (p) & -n)
#define ALIGN(p, n) (((uintptr_t) (p) + (n - 1)) & -n)
#define CHECK_SIZEOF(T) int(*_o)[sizeof(T)]=1
typedef struct Color { float r, g, b, a; } Color;

View File

@ -388,7 +388,7 @@ static bool parseKTX(uint8_t* bytes, size_t size, TextureData* textureData) {
textureData->mipmaps[i] = (Mipmap) { .width = width, .height = height, .data = data.u8 + sizeof(uint32_t), .size = *data.u32 };
width = MAX(width >> 1, 1u);
height = MAX(height >> 1, 1u);
data.u8 = (uint8_t*) ALIGN(data.u8 + sizeof(uint32_t) + *data.u32 + 3, 4);
data.u8 = (uint8_t*) ALIGN(data.u8 + sizeof(uint32_t) + *data.u32, 4);
}
return true;