RGB conversion fixes.
This commit is contained in:
parent
2cc70162dd
commit
1308795378
@ -72,13 +72,13 @@ namespace
|
|||||||
{
|
{
|
||||||
*shift = 0;
|
*shift = 0;
|
||||||
while((mask & 1) == 0) {
|
while((mask & 1) == 0) {
|
||||||
*shift++;
|
++(*shift);
|
||||||
mask >>= 1;
|
mask >>= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
*size = 0;
|
*size = 0;
|
||||||
while((mask & 1) == 1) {
|
while((mask & 1) == 1) {
|
||||||
*size++;
|
++(*size);
|
||||||
mask >>= 1;
|
mask >>= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -120,7 +120,7 @@ void nv::compressRGB(const Image * image, const OutputOptions & outputOptions, c
|
|||||||
// Determine pitch.
|
// Determine pitch.
|
||||||
uint pitch = computePitch(w, compressionOptions.bitcount);
|
uint pitch = computePitch(w, compressionOptions.bitcount);
|
||||||
|
|
||||||
void * dst = mem::malloc(pitch);
|
uint8 * dst = (uint8 *)mem::malloc(pitch + 4);
|
||||||
|
|
||||||
for (uint y = 0; y < h; y++)
|
for (uint y = 0; y < h; y++)
|
||||||
{
|
{
|
||||||
@ -145,10 +145,7 @@ void nv::compressRGB(const Image * image, const OutputOptions & outputOptions, c
|
|||||||
c |= convert(src[x].b, 8, bsize) << bshift;
|
c |= convert(src[x].b, 8, bsize) << bshift;
|
||||||
c |= convert(src[x].a, 8, asize) << ashift;
|
c |= convert(src[x].a, 8, asize) << ashift;
|
||||||
|
|
||||||
*(uint *)dst = c;
|
*(uint *)(dst + x * byteCount) = c;
|
||||||
|
|
||||||
++src;
|
|
||||||
dst = (uint8 *)dst + byteCount;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,6 +108,15 @@ void CompressionOptions::setPixelFormat(uint bitcount, uint rmask, uint gmask, u
|
|||||||
nvCheck((gmask & amask) == 0);
|
nvCheck((gmask & amask) == 0);
|
||||||
nvCheck((bmask & amask) == 0);
|
nvCheck((bmask & amask) == 0);
|
||||||
|
|
||||||
|
if (bitcount != 32)
|
||||||
|
{
|
||||||
|
uint maxMask = (1 << bitcount);
|
||||||
|
nvCheck(maxMask > rmask);
|
||||||
|
nvCheck(maxMask > gmask);
|
||||||
|
nvCheck(maxMask > bmask);
|
||||||
|
nvCheck(maxMask > amask);
|
||||||
|
}
|
||||||
|
|
||||||
m.bitcount = bitcount;
|
m.bitcount = bitcount;
|
||||||
m.rmask = rmask;
|
m.rmask = rmask;
|
||||||
m.gmask = gmask;
|
m.gmask = gmask;
|
||||||
|
@ -67,11 +67,19 @@ namespace
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int computeImageSize(int w, int h, Format format)
|
inline uint computePitch(uint w, uint bitsize)
|
||||||
|
{
|
||||||
|
uint p = w * ((bitsize + 7) / 8);
|
||||||
|
|
||||||
|
// Align to 32 bits.
|
||||||
|
return ((p + 3) / 4) * 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int computeImageSize(uint w, uint h, uint bitCount, Format format)
|
||||||
{
|
{
|
||||||
if (format == Format_RGBA) {
|
if (format == Format_RGBA) {
|
||||||
return w * h * sizeof(Color32);
|
return h * computePitch(w, bitCount);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return ((w + 3) / 4) * ((h + 3) / 4) * blockSize(format);
|
return ((w + 3) / 4) * ((h + 3) / 4) * blockSize(format);
|
||||||
@ -124,7 +132,7 @@ static void outputHeader(const InputOptions::Private & inputOptions, const Outpu
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
header.setLinearSize(computeImageSize(img->width, img->height, compressionOptions.format));
|
header.setLinearSize(computeImageSize(img->width, img->height, compressionOptions.bitcount, compressionOptions.format));
|
||||||
|
|
||||||
if (compressionOptions.format == Format_DXT1 /*|| compressionOptions.format == Format_DXT1a*/) {
|
if (compressionOptions.format == Format_DXT1 /*|| compressionOptions.format == Format_DXT1a*/) {
|
||||||
header.setFourCC('D', 'X', 'T', '1');
|
header.setFourCC('D', 'X', 'T', '1');
|
||||||
@ -376,6 +384,7 @@ bool nvtt::compress(const InputOptions & inputOptions, const OutputOptions & out
|
|||||||
outputHeader(inputOptions.m, outputOptions, compressionOptions.m);
|
outputHeader(inputOptions.m, outputOptions, compressionOptions.m);
|
||||||
|
|
||||||
Format format = compressionOptions.m.format;
|
Format format = compressionOptions.m.format;
|
||||||
|
const uint bitCount = compressionOptions.m.bitcount;
|
||||||
|
|
||||||
for (int f = 0; f < inputOptions.m.faceCount; f++)
|
for (int f = 0; f < inputOptions.m.faceCount; f++)
|
||||||
{
|
{
|
||||||
@ -389,7 +398,7 @@ bool nvtt::compress(const InputOptions & inputOptions, const OutputOptions & out
|
|||||||
|
|
||||||
if (outputOptions.outputHandler)
|
if (outputOptions.outputHandler)
|
||||||
{
|
{
|
||||||
int size = computeImageSize(mipmap.width, mipmap.height, format);
|
int size = computeImageSize(mipmap.width, mipmap.height, bitCount, format);
|
||||||
outputOptions.outputHandler->mipmap(size, mipmap.width, mipmap.height, mipmap.depth, mipmap.face, mipmap.mipLevel);
|
outputOptions.outputHandler->mipmap(size, mipmap.width, mipmap.height, mipmap.depth, mipmap.face, mipmap.mipLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -460,6 +469,7 @@ bool nvtt::compress(const InputOptions & inputOptions, const OutputOptions & out
|
|||||||
int nvtt::estimateSize(const InputOptions & inputOptions, const CompressionOptions & compressionOptions)
|
int nvtt::estimateSize(const InputOptions & inputOptions, const CompressionOptions & compressionOptions)
|
||||||
{
|
{
|
||||||
Format format = compressionOptions.m.format;
|
Format format = compressionOptions.m.format;
|
||||||
|
const uint bitCount = compressionOptions.m.bitcount;
|
||||||
|
|
||||||
int size = 0;
|
int size = 0;
|
||||||
|
|
||||||
@ -470,7 +480,7 @@ int nvtt::estimateSize(const InputOptions & inputOptions, const CompressionOptio
|
|||||||
int idx = f * inputOptions.m.mipmapCount + m;
|
int idx = f * inputOptions.m.mipmapCount + m;
|
||||||
const InputOptions::Private::Image & img = inputOptions.m.images[idx];
|
const InputOptions::Private::Image & img = inputOptions.m.images[idx];
|
||||||
|
|
||||||
size += computeImageSize(img.width, img.height, format);
|
size += computeImageSize(img.width, img.height, bitCount, format);
|
||||||
|
|
||||||
if (!inputOptions.m.generateMipmaps || (inputOptions.m.maxLevel >= 0 && m >= inputOptions.m.maxLevel)) {
|
if (!inputOptions.m.generateMipmaps || (inputOptions.m.maxLevel >= 0 && m >= inputOptions.m.maxLevel)) {
|
||||||
// continue with next face.
|
// continue with next face.
|
||||||
|
Loading…
Reference in New Issue
Block a user