Align rows to 8 bits only.
This commit is contained in:
parent
9ce42ecfa4
commit
e2ac16f100
@ -37,23 +37,21 @@ using namespace nvtt;
|
||||
namespace
|
||||
{
|
||||
|
||||
inline uint computePitch(uint w, uint bitsize)
|
||||
{
|
||||
uint p = w * ((bitsize + 7) / 8);
|
||||
inline uint computePitch(uint w, uint bitsize)
|
||||
{
|
||||
// Align to 8 bits.
|
||||
return w * ((bitsize + 7) / 8);
|
||||
}
|
||||
|
||||
// Align to 32 bits.
|
||||
return ((p + 3) / 4) * 4;
|
||||
}
|
||||
inline void convert_to_a8r8g8b8(const void * src, void * dst, uint w)
|
||||
{
|
||||
memcpy(dst, src, 4 * w);
|
||||
}
|
||||
|
||||
inline void convert_to_a8r8g8b8(const void * src, void * dst, uint w)
|
||||
{
|
||||
memcpy(dst, src, 4 * w);
|
||||
}
|
||||
|
||||
inline void convert_to_x8r8g8b8(const void * src, void * dst, uint w)
|
||||
{
|
||||
memcpy(dst, src, 4 * w);
|
||||
}
|
||||
inline void convert_to_x8r8g8b8(const void * src, void * dst, uint w)
|
||||
{
|
||||
memcpy(dst, src, 4 * w);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@ -61,80 +59,80 @@ namespace
|
||||
// Pixel format converter.
|
||||
void nv::compressRGB(const Image * image, const OutputOptions::Private & outputOptions, const CompressionOptions::Private & compressionOptions)
|
||||
{
|
||||
nvCheck(image != NULL);
|
||||
nvCheck(image != NULL);
|
||||
|
||||
const uint w = image->width();
|
||||
const uint h = image->height();
|
||||
const uint w = image->width();
|
||||
const uint h = image->height();
|
||||
|
||||
const uint bitCount = compressionOptions.bitcount;
|
||||
nvCheck(bitCount == 8 || bitCount == 16 || bitCount == 24 || bitCount == 32);
|
||||
const uint bitCount = compressionOptions.bitcount;
|
||||
nvCheck(bitCount == 8 || bitCount == 16 || bitCount == 24 || bitCount == 32);
|
||||
|
||||
const uint byteCount = bitCount / 8;
|
||||
const uint byteCount = bitCount / 8;
|
||||
|
||||
const uint rmask = compressionOptions.rmask;
|
||||
uint rshift, rsize;
|
||||
PixelFormat::maskShiftAndSize(rmask, &rshift, &rsize);
|
||||
|
||||
const uint gmask = compressionOptions.gmask;
|
||||
uint gshift, gsize;
|
||||
PixelFormat::maskShiftAndSize(gmask, &gshift, &gsize);
|
||||
|
||||
const uint bmask = compressionOptions.bmask;
|
||||
uint bshift, bsize;
|
||||
PixelFormat::maskShiftAndSize(bmask, &bshift, &bsize);
|
||||
|
||||
const uint amask = compressionOptions.amask;
|
||||
uint ashift, asize;
|
||||
PixelFormat::maskShiftAndSize(amask, &ashift, &asize);
|
||||
const uint rmask = compressionOptions.rmask;
|
||||
uint rshift, rsize;
|
||||
PixelFormat::maskShiftAndSize(rmask, &rshift, &rsize);
|
||||
|
||||
// Determine pitch.
|
||||
uint pitch = computePitch(w, compressionOptions.bitcount);
|
||||
const uint gmask = compressionOptions.gmask;
|
||||
uint gshift, gsize;
|
||||
PixelFormat::maskShiftAndSize(gmask, &gshift, &gsize);
|
||||
|
||||
uint8 * dst = (uint8 *)mem::malloc(pitch + 4);
|
||||
const uint bmask = compressionOptions.bmask;
|
||||
uint bshift, bsize;
|
||||
PixelFormat::maskShiftAndSize(bmask, &bshift, &bsize);
|
||||
|
||||
for (uint y = 0; y < h; y++)
|
||||
{
|
||||
const Color32 * src = image->scanline(y);
|
||||
const uint amask = compressionOptions.amask;
|
||||
uint ashift, asize;
|
||||
PixelFormat::maskShiftAndSize(amask, &ashift, &asize);
|
||||
|
||||
if (bitCount == 32 && rmask == 0xFF0000 && gmask == 0xFF00 && bmask == 0xFF && amask == 0xFF000000)
|
||||
{
|
||||
convert_to_a8r8g8b8(src, dst, w);
|
||||
}
|
||||
else if (bitCount == 32 && rmask == 0xFF0000 && gmask == 0xFF00 && bmask == 0xFF && amask == 0)
|
||||
{
|
||||
convert_to_x8r8g8b8(src, dst, w);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Generic pixel format conversion.
|
||||
for (uint x = 0; x < w; x++)
|
||||
{
|
||||
uint c = 0;
|
||||
c |= PixelFormat::convert(src[x].r, 8, rsize) << rshift;
|
||||
c |= PixelFormat::convert(src[x].g, 8, gsize) << gshift;
|
||||
c |= PixelFormat::convert(src[x].b, 8, bsize) << bshift;
|
||||
c |= PixelFormat::convert(src[x].a, 8, asize) << ashift;
|
||||
|
||||
// Output one byte at a time.
|
||||
for (uint i = 0; i < byteCount; i++)
|
||||
{
|
||||
*(dst + x * byteCount + i) = (c >> (i * 8)) & 0xFF;
|
||||
}
|
||||
}
|
||||
|
||||
// Zero padding.
|
||||
for (uint x = w * byteCount; x < pitch; x++)
|
||||
{
|
||||
*(dst + x) = 0;
|
||||
}
|
||||
}
|
||||
// Determine pitch.
|
||||
uint pitch = computePitch(w, compressionOptions.bitcount);
|
||||
|
||||
if (outputOptions.outputHandler != NULL)
|
||||
{
|
||||
outputOptions.outputHandler->writeData(dst, pitch);
|
||||
}
|
||||
}
|
||||
uint8 * dst = (uint8 *)mem::malloc(pitch + 4);
|
||||
|
||||
mem::free(dst);
|
||||
for (uint y = 0; y < h; y++)
|
||||
{
|
||||
const Color32 * src = image->scanline(y);
|
||||
|
||||
if (bitCount == 32 && rmask == 0xFF0000 && gmask == 0xFF00 && bmask == 0xFF && amask == 0xFF000000)
|
||||
{
|
||||
convert_to_a8r8g8b8(src, dst, w);
|
||||
}
|
||||
else if (bitCount == 32 && rmask == 0xFF0000 && gmask == 0xFF00 && bmask == 0xFF && amask == 0)
|
||||
{
|
||||
convert_to_x8r8g8b8(src, dst, w);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Generic pixel format conversion.
|
||||
for (uint x = 0; x < w; x++)
|
||||
{
|
||||
uint c = 0;
|
||||
c |= PixelFormat::convert(src[x].r, 8, rsize) << rshift;
|
||||
c |= PixelFormat::convert(src[x].g, 8, gsize) << gshift;
|
||||
c |= PixelFormat::convert(src[x].b, 8, bsize) << bshift;
|
||||
c |= PixelFormat::convert(src[x].a, 8, asize) << ashift;
|
||||
|
||||
// Output one byte at a time.
|
||||
for (uint i = 0; i < byteCount; i++)
|
||||
{
|
||||
*(dst + x * byteCount + i) = (c >> (i * 8)) & 0xFF;
|
||||
}
|
||||
}
|
||||
|
||||
// Zero padding.
|
||||
for (uint x = w * byteCount; x < pitch; x++)
|
||||
{
|
||||
*(dst + x) = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (outputOptions.outputHandler != NULL)
|
||||
{
|
||||
outputOptions.outputHandler->writeData(dst, pitch);
|
||||
}
|
||||
}
|
||||
|
||||
mem::free(dst);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user