Fix alignment assumption. Fixes issue 132.
This commit is contained in:
parent
2ea2b40c72
commit
66a8237215
@ -1196,13 +1196,9 @@ 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);
|
||||
|
||||
return pitch * h * d;
|
||||
uint pitch = computePitch(w, header.pf.bitcount, 8); // Asuming 8 bit alignment, which is the same D3DX expects.
|
||||
|
||||
return pitch * h * d;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,4 +19,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
|
||||
|
@ -37,12 +37,6 @@ using namespace nvtt;
|
||||
namespace
|
||||
{
|
||||
|
||||
inline uint computePitch(uint w, uint bitsize)
|
||||
{
|
||||
// Align to 8 bits.
|
||||
return w * ((bitsize + 7) / 8);
|
||||
}
|
||||
|
||||
inline void convert_to_a8r8g8b8(const void * src, void * dst, uint w)
|
||||
{
|
||||
memcpy(dst, src, 4 * w);
|
||||
@ -86,7 +80,7 @@ void nv::compressRGB(const Image * image, const OutputOptions::Private & outputO
|
||||
PixelFormat::maskShiftAndSize(amask, &ashift, &asize);
|
||||
|
||||
// Determine pitch.
|
||||
uint pitch = computePitch(w, compressionOptions.bitcount);
|
||||
uint pitch = computePitch(w, compressionOptions.bitcount, 8);
|
||||
|
||||
uint8 * dst = (uint8 *)mem::malloc(pitch + 4);
|
||||
|
||||
|
@ -74,18 +74,10 @@ namespace
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline uint computePitch(uint w, uint bitsize)
|
||||
{
|
||||
uint p = w * ((bitsize + 7) / 8);
|
||||
|
||||
// Align to 32 bits.
|
||||
return ((p + 3) / 4) * 4;
|
||||
}
|
||||
|
||||
static int computeImageSize(uint w, uint h, uint d, uint bitCount, Format format)
|
||||
{
|
||||
if (format == Format_RGBA) {
|
||||
return d * h * computePitch(w, bitCount);
|
||||
return d * h * computePitch(w, bitCount, 8);
|
||||
}
|
||||
else {
|
||||
// @@ Handle 3D textures. DXT and VTC have different behaviors.
|
||||
@ -346,7 +338,7 @@ bool Compressor::Private::outputHeader(const InputOptions::Private & inputOption
|
||||
|
||||
if (compressionOptions.format == Format_RGBA)
|
||||
{
|
||||
header.setPitch(computePitch(inputOptions.targetWidth, compressionOptions.bitcount));
|
||||
header.setPitch(computePitch(inputOptions.targetWidth, compressionOptions.bitcount, 8));
|
||||
header.setPixelFormat(compressionOptions.bitcount, compressionOptions.rmask, compressionOptions.gmask, compressionOptions.bmask, compressionOptions.amask);
|
||||
}
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user