From 46334cb96a21b120d662f53ace2cb09de6ce37ca Mon Sep 17 00:00:00 2001 From: castano Date: Tue, 11 Mar 2008 21:22:54 +0000 Subject: [PATCH] Merge Viktor Linder patch into 2.0 and trunk. Fixes RGB modes with less than 32 bpp. --- ChangeLog | 1 + src/nvimage/DirectDrawSurface.cpp | 6 +++--- src/nvtt/CompressRGB.cpp | 10 ++++++++-- src/nvtt/Compressor.cpp | 2 +- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1df2ebd..cb25b3d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,7 @@ NVIDIA Texture Tools version 2.0.2 * Fix copy ctor error reported by Richard Sim. * Fix indexMirror error reported by Chris Lambert. * Fix vc8 post build command, reported by Richard Sim. + * Fix RGBA modes with less than 32 bpp by Viktor Linder. NVIDIA Texture Tools version 2.0.1 * Fix memory leaks. diff --git a/src/nvimage/DirectDrawSurface.cpp b/src/nvimage/DirectDrawSurface.cpp index 7827d16..c75ce22 100644 --- a/src/nvimage/DirectDrawSurface.cpp +++ b/src/nvimage/DirectDrawSurface.cpp @@ -530,9 +530,9 @@ void DDSHeader::setPixelFormat(uint bitcount, uint rmask, uint gmask, uint bmask nvCheck(bitcount > 0 && bitcount <= 32); // Align to 8. - if (bitcount < 8) bitcount = 8; - else if (bitcount < 16) bitcount = 16; - else if (bitcount < 24) bitcount = 24; + if (bitcount <= 8) bitcount = 8; + else if (bitcount <= 16) bitcount = 16; + else if (bitcount <= 24) bitcount = 24; else bitcount = 32; this->pf.fourcc = 0; //findD3D9Format(bitcount, rmask, gmask, bmask, amask); diff --git a/src/nvtt/CompressRGB.cpp b/src/nvtt/CompressRGB.cpp index 33b41e5..f45f5b6 100644 --- a/src/nvtt/CompressRGB.cpp +++ b/src/nvtt/CompressRGB.cpp @@ -115,12 +115,18 @@ void nv::compressRGB(const Image * image, const OutputOptions::Private & outputO c |= PixelFormat::convert(src[x].b, 8, bsize) << bshift; c |= PixelFormat::convert(src[x].a, 8, asize) << ashift; - // Output one byte at a time. @@ Not tested... Does this work on LE and BE? + // Output one byte at a time. for (uint i = 0; i < byteCount; i++) { - *(dst + x * byteCount) = (c >> (i * 8)) & 0xFF; + *(dst + x * byteCount + i) = (c >> (i * 8)) & 0xFF; } } + + // Zero padding. + for (uint x = w; x < pitch; x++) + { + *(dst + x) = 0; + } } if (outputOptions.outputHandler != NULL) diff --git a/src/nvtt/Compressor.cpp b/src/nvtt/Compressor.cpp index a74a1dc..8833a41 100644 --- a/src/nvtt/Compressor.cpp +++ b/src/nvtt/Compressor.cpp @@ -338,7 +338,7 @@ bool Compressor::Private::outputHeader(const InputOptions::Private & inputOption if (compressionOptions.format == Format_RGBA) { - header.setPitch(4 * inputOptions.targetWidth); + header.setPitch(computePitch(inputOptions.targetWidth, compressionOptions.bitcount)); header.setPixelFormat(compressionOptions.bitcount, compressionOptions.rmask, compressionOptions.gmask, compressionOptions.bmask, compressionOptions.amask); } else