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

This commit is contained in:
castano 2011-09-13 17:08:09 +00:00
parent 8b096b4186
commit fe108af32e
4 changed files with 9 additions and 10 deletions

View File

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

View File

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

View File

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

View File

@ -79,7 +79,7 @@ namespace nvtt
namespace nv { namespace nv {
uint countMipmaps(uint w, uint h, uint d); 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); void getTargetExtent(int & w, int & h, int & d, int maxExtent, nvtt::RoundMode roundMode, nvtt::TextureType textureType);
} }