Pitch is specified in bytes and always byte aligned. Fixes issue 168.

pull/216/head
castano 13 years ago
parent 8b096b4186
commit fe108af32e

@ -63,7 +63,7 @@ void CompressionOptions::reset()
m.asize = 8;
m.pixelType = PixelType_UnsignedNorm;
m.pitchAlignment = 8;
m.pitchAlignment = 1;
m.enableColorDithering = false;
m.enableAlphaDithering = false;

@ -188,12 +188,11 @@ void PixelFormatConverter::compress(nvtt::AlphaMode /*alphaMode*/, uint w, uint
}
}
const uint pitch = computeBitPitch(w, bitCount, compressionOptions.pitchAlignment);
const uint pitchInBytes = (pitch + 7) / 8;
const uint pitch = computeBytePitch(w, bitCount, compressionOptions.pitchAlignment);
const uint wh = w * h;
// Allocate output scanline.
uint8 * const dst = malloc<uint8>(pitchInBytes);
uint8 * const dst = malloc<uint8>(pitch);
for (uint y = 0; y < h; y++)
{
@ -252,15 +251,15 @@ void PixelFormatConverter::compress(nvtt::AlphaMode /*alphaMode*/, uint w, uint
// Zero padding.
stream.align(compressionOptions.pitchAlignment);
nvDebugCheck(stream.ptr == dst + pitchInBytes);
nvDebugCheck(stream.ptr == dst + pitch);
/*for (uint x = w * byteCount; x < pitchInBytes; x++)
/*for (uint x = w * byteCount; x < pitch; x++)
{
*(dst + x) = 0;
}*/
// @@ This code does not truly support less than byte-aligned textures.
outputOptions.writeData(dst, pitchInBytes);
outputOptions.writeData(dst, pitch);
}
free(dst);

@ -109,10 +109,10 @@ uint nv::countMipmaps(uint w, uint h, uint d)
return mipmap + 1;
}
uint nv::computeImageSize(uint w, uint h, uint d, uint bitCount, uint pitchAlignmentInBits, Format format)
uint nv::computeImageSize(uint w, uint h, uint d, uint bitCount, uint pitchAlignmentInBytes, Format format)
{
if (format == Format_RGBA) {
return d * h * computeBytePitch(w, bitCount, pitchAlignmentInBits);
return d * h * computeBytePitch(w, bitCount, pitchAlignmentInBytes);
}
else {
// @@ Handle 3D textures. DXT and VTC have different behaviors.

@ -79,7 +79,7 @@ namespace nvtt
namespace nv {
uint countMipmaps(uint w, uint h, uint d);
uint computeImageSize(uint w, uint h, uint d, uint bitCount, uint alignment, nvtt::Format format);
uint computeImageSize(uint w, uint h, uint d, uint bitCount, uint alignmentInBytes, nvtt::Format format);
void getTargetExtent(int & w, int & h, int & d, int maxExtent, nvtt::RoundMode roundMode, nvtt::TextureType textureType);
}

Loading…
Cancel
Save