Fix alignment assumptions in DDS loading code. Fixes issue 132.

Merge misc changes from the-witness.
This commit is contained in:
castano
2010-09-07 18:24:50 +00:00
parent 2c969b70a5
commit 276c608f26
6 changed files with 14 additions and 19 deletions

View File

@ -1404,11 +1404,7 @@ uint DirectDrawSurface::mipmapSize(uint mipmap) const
{
nvDebugCheck((header.pf.flags & DDPF_RGB) || (header.pf.flags & DDPF_LUMINANCE));
// Align pixels to bytes.
uint byteCount = (header.pf.bitcount + 7) / 8;
// Align pitch to 4 bytes.
uint pitch = 4 * ((w * byteCount + 3) / 4);
uint pitch = computePitch(w, header.pf.bitcount, 8); // Asuming 8 bit alignment, which is the same D3DX expects.
return pitch * h * d;
}

View File

@ -258,7 +258,7 @@ void FloatImage::exponentiate(uint base_component, uint num, float power)
float * ptr = this->channel(base_component + c);
for(uint i = 0; i < size; i++) {
ptr[i] = pow(ptr[i], power);
ptr[i] = powf(max(0.0f, ptr[i]), power);
}
}
}

View File

@ -20,4 +20,14 @@
#define NVIMAGE_CLASS
#endif
// Some utility functions:
inline uint computePitch(uint w, uint bitsize, uint alignment)
{
return ((w * bitsize + 8 * alignment - 1) / (8 * alignment)) * alignment;
}
#endif // NV_IMAGE_H