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

Merge misc changes from the-witness.
pull/216/head
castano 14 years ago
parent 2c969b70a5
commit 276c608f26

@ -30,7 +30,7 @@ void TextWriter::write(const char * format, ...)
{
va_list arg;
va_start(arg,format);
str.format(format, arg);
str.formatList(format, arg);
writeString(str.str(), str.length());
va_end(arg);
}
@ -39,7 +39,7 @@ void TextWriter::write(const char * format, va_list arg)
{
va_list tmp;
va_copy(tmp, arg);
str.format(format, arg);
str.formatList(format, arg);
writeString(str.str(), str.length());
va_end(tmp);
}

@ -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;
}

@ -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);
}
}
}

@ -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

@ -39,12 +39,6 @@ using namespace nvtt;
namespace
{
inline uint computePitch(uint w, uint bitsize, uint alignment)
{
return ((w * bitsize + 8 * alignment - 1) / (8 * alignment)) * alignment;
}
inline void convert_to_a8r8g8b8(const void * src, void * dst, uint w)
{
memcpy(dst, src, 4 * w);

@ -89,11 +89,6 @@ namespace
return 0;
}
inline uint computePitch(uint w, uint bitsize, uint alignment)
{
return ((w * bitsize + 8 * alignment - 1) / (8 * alignment)) * alignment;
}
static int computeImageSize(uint w, uint h, uint d, uint bitCount, uint alignment, Format format)
{
if (format == Format_RGBA) {

Loading…
Cancel
Save