Some pitch alignment fixes. Fixes issue 168.

pull/216/head
castano 13 years ago
parent 2952480d30
commit 5d19ff392a

@ -1419,7 +1419,7 @@ uint DirectDrawSurface::mipmapSize(uint mipmap) const
{
nvDebugCheck((header.pf.flags & DDPF_RGB) || (header.pf.flags & DDPF_LUMINANCE));
uint pitch = computePitch(w, header.pf.bitcount, 8); // Asuming 8 bit alignment, which is the same D3DX expects.
uint pitch = computeBytePitch(w, header.pf.bitcount, 8); // Asuming 8 bit alignment, which is the same D3DX expects.
return pitch * h * d;
}

@ -321,6 +321,7 @@ float nv::spatialCieLabError(const FloatImage * img0, const FloatImage * img1)
*/
// @@ Measure Delta E between lab0 and lab1.
return 0.0f;
}

@ -4,7 +4,9 @@
#ifndef NV_IMAGE_H
#define NV_IMAGE_H
#include <nvcore/nvcore.h>
#include "nvcore/nvcore.h"
#include "nvcore/Debug.h" // nvDebugCheck
#include "nvcore/Utils.h" // isPowerOfTwo
// Function linkage
#if NVIMAGE_SHARED
@ -21,13 +23,27 @@
#endif
// Some utility functions:
namespace nv {
inline uint computePitch(uint w, uint bitsize, uint alignment)
{
return ((w * bitsize + 8 * alignment - 1) / (8 * alignment)) * alignment;
}
// Some utility functions:
inline uint computeBitPitch(uint w, uint bitsize, uint alignmentInBits)
{
nvDebugCheck(isPowerOfTwo(alignmentInBits));
return ((w * bitsize + alignmentInBits - 1) / alignmentInBits) * alignmentInBits;
}
inline uint computeBytePitch(uint w, uint bitsize, uint alignmentInBits)
{
nvDebugCheck(alignmentInBits >= 8);
uint pitch = computeBitPitch(w, bitsize, alignmentInBits);
return (pitch + 7) / 8;
}
} // nv namespace
#endif // NV_IMAGE_H

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

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

@ -479,7 +479,7 @@ bool Compressor::Private::outputHeader(nvtt::TextureType textureType, int w, int
if (compressionOptions.format == Format_RGBA)
{
// Get output bit count.
header.setPitch(computePitch(w, compressionOptions.getBitCount(), compressionOptions.pitchAlignment));
header.setPitch(computeBytePitch(w, compressionOptions.getBitCount(), compressionOptions.pitchAlignment));
if (compressionOptions.pixelType == PixelType_Float)
{

@ -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 alignment, Format format)
uint nv::computeImageSize(uint w, uint h, uint d, uint bitCount, uint pitchAlignmentInBits, Format format)
{
if (format == Format_RGBA) {
return d * h * computePitch(w, bitCount, alignment);
return d * h * computeBytePitch(w, bitCount, pitchAlignmentInBits);
}
else {
// @@ Handle 3D textures. DXT and VTC have different behaviors.

Loading…
Cancel
Save