From fe108af32ef3b9fceef13cadb20ace9562bb0170 Mon Sep 17 00:00:00 2001 From: castano Date: Tue, 13 Sep 2011 17:08:09 +0000 Subject: [PATCH] Pitch is specified in bytes and always byte aligned. Fixes issue 168. --- src/nvtt/CompressionOptions.cpp | 2 +- src/nvtt/CompressorRGB.cpp | 11 +++++------ src/nvtt/TexImage.cpp | 4 ++-- src/nvtt/TexImage.h | 2 +- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/nvtt/CompressionOptions.cpp b/src/nvtt/CompressionOptions.cpp index 138f06a..187ea4e 100644 --- a/src/nvtt/CompressionOptions.cpp +++ b/src/nvtt/CompressionOptions.cpp @@ -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; diff --git a/src/nvtt/CompressorRGB.cpp b/src/nvtt/CompressorRGB.cpp index 47907b1..4bc59ba 100644 --- a/src/nvtt/CompressorRGB.cpp +++ b/src/nvtt/CompressorRGB.cpp @@ -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(pitchInBytes); + uint8 * const dst = malloc(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); diff --git a/src/nvtt/TexImage.cpp b/src/nvtt/TexImage.cpp index 063b0d3..fd06564 100644 --- a/src/nvtt/TexImage.cpp +++ b/src/nvtt/TexImage.cpp @@ -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. diff --git a/src/nvtt/TexImage.h b/src/nvtt/TexImage.h index 5d8d3b6..7cef68e 100644 --- a/src/nvtt/TexImage.h +++ b/src/nvtt/TexImage.h @@ -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); }