Minor changes.
This commit is contained in:
parent
1454cbac14
commit
035231a928
@ -88,10 +88,10 @@ namespace nv
|
||||
NVIMAGE_API void applyKernelVertical(const PolyphaseKernel & k, int x, uint c, uint a, WrapMode wm, float * output) const;
|
||||
NVIMAGE_API void applyKernelHorizontal(const PolyphaseKernel & k, int y, uint c, uint a, WrapMode wm, float * output) const;
|
||||
|
||||
NVIMAGE_API void flip();
|
||||
|
||||
NVIMAGE_API float alphaTestCoverage(float alphaRef, int alphaChannel) const;
|
||||
NVIMAGE_API void scaleAlphaToCoverage(float coverage, float alphaRef, int alphaChannel);
|
||||
NVIMAGE_API void flip();
|
||||
|
||||
NVIMAGE_API float alphaTestCoverage(float alphaRef, int alphaChannel) const;
|
||||
NVIMAGE_API void scaleAlphaToCoverage(float coverage, float alphaRef, int alphaChannel);
|
||||
|
||||
|
||||
uint width() const { return m_width; }
|
||||
|
@ -145,80 +145,87 @@ void PixelFormatConverter::compress(nvtt::InputFormat inputFormat, nvtt::AlphaMo
|
||||
const uint * src = (const uint *)data + y * srcPitch;
|
||||
const float * fsrc = (const float *)data + y * srcPitch;
|
||||
|
||||
uint8 * ptr = dst;
|
||||
|
||||
for (uint x = 0; x < w; x++)
|
||||
{
|
||||
float r, g, b, a;
|
||||
|
||||
if (inputFormat == nvtt::InputFormat_BGRA_8UB) {
|
||||
Color32 c = Color32(src[x]);
|
||||
r = float(c.r) / 255.0f;
|
||||
g = float(c.g) / 255.0f;
|
||||
b = float(c.b) / 255.0f;
|
||||
a = float(c.a) / 255.0f;
|
||||
}
|
||||
else {
|
||||
nvDebugCheck (inputFormat == nvtt::InputFormat_RGBA_32F);
|
||||
|
||||
//r = ((float *)src)[4 * x + 0]; // Color components not interleaved.
|
||||
//g = ((float *)src)[4 * x + 1];
|
||||
//b = ((float *)src)[4 * x + 2];
|
||||
//a = ((float *)src)[4 * x + 3];
|
||||
r = fsrc[x + 0 * srcPlane];
|
||||
g = fsrc[x + 1 * srcPlane];
|
||||
b = fsrc[x + 2 * srcPlane];
|
||||
a = fsrc[x + 3 * srcPlane];
|
||||
}
|
||||
|
||||
if (compressionOptions.pixelType == nvtt::PixelType_Float)
|
||||
{
|
||||
if (rsize == 32) *((float *)ptr) = r;
|
||||
else if (rsize == 16) *((uint16 *)ptr) = to_half(r);
|
||||
ptr += rsize / 8;
|
||||
|
||||
if (gsize == 32) *((float *)ptr) = g;
|
||||
else if (gsize == 16) *((uint16 *)ptr) = to_half(g);
|
||||
ptr += gsize / 8;
|
||||
|
||||
if (bsize == 32) *((float *)ptr) = b;
|
||||
else if (bsize == 16) *((uint16 *)ptr) = to_half(b);
|
||||
ptr += bsize / 8;
|
||||
|
||||
if (asize == 32) *((float *)ptr) = a;
|
||||
else if (asize == 16) *((uint16 *)ptr) = to_half(a);
|
||||
ptr += asize / 8;
|
||||
}
|
||||
else
|
||||
{
|
||||
Color32 c;
|
||||
if (compressionOptions.pixelType == nvtt::PixelType_UnsignedNorm) {
|
||||
c.r = uint8(clamp(r * 255, 0.0f, 255.0f));
|
||||
c.g = uint8(clamp(g * 255, 0.0f, 255.0f));
|
||||
c.b = uint8(clamp(b * 255, 0.0f, 255.0f));
|
||||
c.a = uint8(clamp(a * 255, 0.0f, 255.0f));
|
||||
}
|
||||
// @@ Add support for nvtt::PixelType_SignedInt, nvtt::PixelType_SignedNorm, nvtt::PixelType_UnsignedInt
|
||||
|
||||
uint p = 0;
|
||||
p |= PixelFormat::convert(c.r, 8, rsize) << rshift;
|
||||
p |= PixelFormat::convert(c.g, 8, gsize) << gshift;
|
||||
p |= PixelFormat::convert(c.b, 8, bsize) << bshift;
|
||||
p |= PixelFormat::convert(c.a, 8, asize) << ashift;
|
||||
|
||||
// Output one byte at a time.
|
||||
for (uint i = 0; i < byteCount; i++)
|
||||
{
|
||||
*(dst + x * byteCount + i) = (p >> (i * 8)) & 0xFF;
|
||||
}
|
||||
}
|
||||
if (inputFormat == nvtt::InputFormat_BGRA_8UB && compressionOptions.pixelType == nvtt::PixelType_UnsignedNorm && bitCount == 32 && rmask == 0xFF0000 && gmask == 0xFF00 && bmask == 0xFF && amask == 0xFF000000)
|
||||
{
|
||||
convert_to_a8r8g8b8(src, dst, w);
|
||||
}
|
||||
else
|
||||
{
|
||||
uint8 * ptr = dst;
|
||||
|
||||
// Zero padding.
|
||||
for (uint x = w * byteCount; x < pitch; x++)
|
||||
{
|
||||
*(dst + x) = 0;
|
||||
}
|
||||
for (uint x = 0; x < w; x++)
|
||||
{
|
||||
float r, g, b, a;
|
||||
|
||||
if (inputFormat == nvtt::InputFormat_BGRA_8UB) {
|
||||
Color32 c = Color32(src[x]);
|
||||
r = float(c.r) / 255.0f;
|
||||
g = float(c.g) / 255.0f;
|
||||
b = float(c.b) / 255.0f;
|
||||
a = float(c.a) / 255.0f;
|
||||
}
|
||||
else {
|
||||
nvDebugCheck (inputFormat == nvtt::InputFormat_RGBA_32F);
|
||||
|
||||
//r = ((float *)src)[4 * x + 0]; // Color components not interleaved.
|
||||
//g = ((float *)src)[4 * x + 1];
|
||||
//b = ((float *)src)[4 * x + 2];
|
||||
//a = ((float *)src)[4 * x + 3];
|
||||
r = fsrc[x + 0 * srcPlane];
|
||||
g = fsrc[x + 1 * srcPlane];
|
||||
b = fsrc[x + 2 * srcPlane];
|
||||
a = fsrc[x + 3 * srcPlane];
|
||||
}
|
||||
|
||||
if (compressionOptions.pixelType == nvtt::PixelType_Float)
|
||||
{
|
||||
if (rsize == 32) *((float *)ptr) = r;
|
||||
else if (rsize == 16) *((uint16 *)ptr) = to_half(r);
|
||||
ptr += rsize / 8;
|
||||
|
||||
if (gsize == 32) *((float *)ptr) = g;
|
||||
else if (gsize == 16) *((uint16 *)ptr) = to_half(g);
|
||||
ptr += gsize / 8;
|
||||
|
||||
if (bsize == 32) *((float *)ptr) = b;
|
||||
else if (bsize == 16) *((uint16 *)ptr) = to_half(b);
|
||||
ptr += bsize / 8;
|
||||
|
||||
if (asize == 32) *((float *)ptr) = a;
|
||||
else if (asize == 16) *((uint16 *)ptr) = to_half(a);
|
||||
ptr += asize / 8;
|
||||
}
|
||||
else
|
||||
{
|
||||
Color32 c;
|
||||
if (compressionOptions.pixelType == nvtt::PixelType_UnsignedNorm) {
|
||||
c.r = uint8(clamp(r * 255, 0.0f, 255.0f));
|
||||
c.g = uint8(clamp(g * 255, 0.0f, 255.0f));
|
||||
c.b = uint8(clamp(b * 255, 0.0f, 255.0f));
|
||||
c.a = uint8(clamp(a * 255, 0.0f, 255.0f));
|
||||
}
|
||||
// @@ Add support for nvtt::PixelType_SignedInt, nvtt::PixelType_SignedNorm, nvtt::PixelType_UnsignedInt
|
||||
|
||||
uint p = 0;
|
||||
p |= PixelFormat::convert(c.r, 8, rsize) << rshift;
|
||||
p |= PixelFormat::convert(c.g, 8, gsize) << gshift;
|
||||
p |= PixelFormat::convert(c.b, 8, bsize) << bshift;
|
||||
p |= PixelFormat::convert(c.a, 8, asize) << ashift;
|
||||
|
||||
// Output one byte at a time.
|
||||
for (uint i = 0; i < byteCount; i++)
|
||||
{
|
||||
*(dst + x * byteCount + i) = (p >> (i * 8)) & 0xFF;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Zero padding.
|
||||
for (uint x = w * byteCount; x < pitch; x++)
|
||||
{
|
||||
*(dst + x) = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (outputOptions.outputHandler != NULL)
|
||||
{
|
||||
|
@ -42,6 +42,7 @@
|
||||
#include "InputOptions.h"
|
||||
#include "CompressionOptions.h"
|
||||
#include "OutputOptions.h"
|
||||
#include "TexImage.h"
|
||||
|
||||
#include "CompressorDXT.h"
|
||||
#include "CompressorRGB.h"
|
||||
@ -334,10 +335,16 @@ bool Compressor::outputHeader(const TexImage & tex, int mipmapCount, const Compr
|
||||
|
||||
bool Compressor::compress(const TexImage & tex, const CompressionOptions & compressionOptions, const OutputOptions & outputOptions) const
|
||||
{
|
||||
#pragma message(NV_FILE_LINE "TODO: Implement TexImage compress api")
|
||||
// @@ Decide whether to change the swizzling of FloatImage.
|
||||
|
||||
// @@ Convert to fixed point and call compress2D for each face.
|
||||
return false;
|
||||
foreach(i, tex.m->imageArray) {
|
||||
FloatImage * image = tex.m->imageArray[i];
|
||||
if (!m.compress2D(InputFormat_RGBA_32F, tex.m->alphaMode, image->width(), image->height(), image->channel(0), compressionOptions.m, outputOptions.m)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Estimate the size of compressing the given texture.
|
||||
|
@ -246,7 +246,7 @@ int TexImage::countMipmaps() const
|
||||
|
||||
float TexImage::alphaTestCoverage(float alphaRef/*= 0.5*/) const
|
||||
{
|
||||
int imageCount = 0.0f;
|
||||
int imageCount = 0;
|
||||
float coverage = 0.0f;
|
||||
|
||||
foreach (i, m->imageArray)
|
||||
|
@ -26,53 +26,55 @@
|
||||
|
||||
#include "nvtt.h"
|
||||
|
||||
#include <nvcore/Array.h>
|
||||
#include <nvcore/RefCounted.h>
|
||||
#include <nvcore/Ptr.h>
|
||||
#include "nvcore/Array.h"
|
||||
#include "nvcore/RefCounted.h"
|
||||
#include "nvcore/Ptr.h"
|
||||
|
||||
#include <nvimage/Image.h>
|
||||
#include <nvimage/FloatImage.h>
|
||||
#include "nvimage/Image.h"
|
||||
#include "nvimage/FloatImage.h"
|
||||
|
||||
namespace nvtt
|
||||
{
|
||||
|
||||
struct TexImage::Private : public nv::RefCounted
|
||||
{
|
||||
Private()
|
||||
{
|
||||
type = TextureType_2D;
|
||||
wrapMode = WrapMode_Mirror;
|
||||
alphaMode = AlphaMode_None;
|
||||
isNormalMap = false;
|
||||
struct TexImage::Private : public nv::RefCounted
|
||||
{
|
||||
void operator=(const Private &);
|
||||
public:
|
||||
Private()
|
||||
{
|
||||
type = TextureType_2D;
|
||||
wrapMode = WrapMode_Mirror;
|
||||
alphaMode = AlphaMode_None;
|
||||
isNormalMap = false;
|
||||
|
||||
imageArray.resize(1, NULL);
|
||||
}
|
||||
Private(const Private & p) // Copy ctor. inits refcount to 0.
|
||||
{
|
||||
type = p.type;
|
||||
wrapMode = p.wrapMode;
|
||||
alphaMode = p.alphaMode;
|
||||
isNormalMap = p.isNormalMap;
|
||||
imageArray.resize(1, NULL);
|
||||
}
|
||||
Private(const Private & p) // Copy ctor. inits refcount to 0.
|
||||
{
|
||||
type = p.type;
|
||||
wrapMode = p.wrapMode;
|
||||
alphaMode = p.alphaMode;
|
||||
isNormalMap = p.isNormalMap;
|
||||
|
||||
imageArray = p.imageArray;
|
||||
}
|
||||
~Private()
|
||||
{
|
||||
const uint count = imageArray.count();
|
||||
for (uint i = 0; i < count; i++) {
|
||||
delete imageArray[i];
|
||||
}
|
||||
}
|
||||
imageArray = p.imageArray;
|
||||
}
|
||||
~Private()
|
||||
{
|
||||
const uint count = imageArray.count();
|
||||
for (uint i = 0; i < count; i++) {
|
||||
delete imageArray[i];
|
||||
}
|
||||
}
|
||||
|
||||
TextureType type;
|
||||
WrapMode wrapMode;
|
||||
AlphaMode alphaMode;
|
||||
bool isNormalMap;
|
||||
TextureType type;
|
||||
WrapMode wrapMode;
|
||||
AlphaMode alphaMode;
|
||||
bool isNormalMap;
|
||||
|
||||
nv::Array<nv::FloatImage *> imageArray;
|
||||
};
|
||||
|
||||
nv::Array<nv::FloatImage *> imageArray;
|
||||
};
|
||||
|
||||
|
||||
} // nvtt namespace
|
||||
|
||||
|
||||
|
@ -25,7 +25,6 @@
|
||||
#include "CudaUtils.h"
|
||||
|
||||
#include <nvcore/Debug.h>
|
||||
#include <nvcore/Utils.h>
|
||||
#include <nvmath/Color.h>
|
||||
#include <nvimage/Image.h>
|
||||
#include <nvimage/ColorBlock.h>
|
||||
@ -35,6 +34,7 @@
|
||||
#include <nvtt/QuickCompressDXT.h>
|
||||
#include <nvtt/OptimalCompressDXT.h>
|
||||
|
||||
|
||||
#if defined HAVE_CUDA
|
||||
#include <cuda_runtime_api.h>
|
||||
#endif
|
||||
|
@ -456,6 +456,7 @@ namespace nvtt
|
||||
private:
|
||||
void detach();
|
||||
|
||||
friend struct Compressor;
|
||||
struct Private;
|
||||
Private * m;
|
||||
};
|
||||
|
@ -23,11 +23,13 @@
|
||||
|
||||
#include <nvtt/nvtt.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdlib.h> // EXIT_SUCCESS, EXIT_FAILURE
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
if (argc != 2) return EXIT_FAILURE;
|
||||
|
||||
nvtt::CompressionOptions compressionOptions;
|
||||
compressionOptions.setFormat(nvtt::Format_BC1);
|
||||
|
||||
@ -37,20 +39,23 @@ int main(int argc, char *argv[])
|
||||
nvtt::Context context;
|
||||
nvtt::TexImage image = context.createTexImage();
|
||||
|
||||
image.load("kodim01.png");
|
||||
image.load(argv[1]);
|
||||
|
||||
context.outputHeader(image, image.countMipmaps(), compressionOptions, outputOptions);
|
||||
|
||||
float gamma = 2.2;
|
||||
float gamma = 2.2f;
|
||||
image.toLinear(gamma);
|
||||
|
||||
float coverage = image.alphaTestCoverage();
|
||||
|
||||
while (image.buildNextMipmap(nvtt::MipmapFilter_Box))
|
||||
{
|
||||
nvtt::TexImage tmpImage = image;
|
||||
tmpImage.toGamma(gamma);
|
||||
|
||||
tmpImage.scaleAlphaToCoverage(coverage);
|
||||
|
||||
context.compress(tmpImage, compressionOptions, outputOptions);
|
||||
// tmpImage.compress(compressionOptions, outputOptions);
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
@ -406,7 +406,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
for (uint i = 0; i < image->componentNum(); i++)
|
||||
{
|
||||
inputOptions.setMipmapChannelData(image->channel(i), i, image->width(), image->height());
|
||||
inputOptions.setMipmapChannelData(image->channel(i), i, image->width(), image->height());
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -168,7 +168,8 @@ int main(int argc, char *argv[])
|
||||
|
||||
nv::FloatImage fimage(&image);
|
||||
fimage.toLinear(0, 3, gamma);
|
||||
|
||||
|
||||
#if 0
|
||||
nv::AutoPtr<nv::FloatImage> fresult(fimage.resize(*filter, uint(image.width() * scale), uint(image.height() * scale), wrapMode));
|
||||
|
||||
nv::AutoPtr<nv::Image> result(fresult->createImageGammaCorrect(gamma));
|
||||
@ -176,7 +177,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
nv::StdOutputStream stream(output);
|
||||
nv::ImageIO::save(output, stream, result.ptr());
|
||||
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user