Imperative api is sort of working now. Fixed various bugs.
This commit is contained in:
@ -107,11 +107,11 @@ void FixedBlockCompressor::compress(nvtt::InputFormat inputFormat, nvtt::AlphaMo
|
||||
|
||||
ColorBlock rgba;
|
||||
if (inputFormat == nvtt::InputFormat_BGRA_8UB) {
|
||||
rgba.init(w, h, (uint *)data, x, y);
|
||||
rgba.init(w, h, (const uint *)data, x, y);
|
||||
}
|
||||
else {
|
||||
nvDebugCheck(inputFormat == nvtt::InputFormat_RGBA_32F);
|
||||
rgba.init(w, h, (float *)data, x, y);
|
||||
rgba.init(w, h, (const float *)data, x, y);
|
||||
}
|
||||
|
||||
compressBlock(rgba, alphaMode, compressionOptions, mem);
|
||||
|
@ -25,12 +25,12 @@
|
||||
#include "CompressionOptions.h"
|
||||
#include "OutputOptions.h"
|
||||
|
||||
#include <nvimage/Image.h>
|
||||
#include <nvimage/FloatImage.h>
|
||||
#include "nvimage/Image.h"
|
||||
#include "nvimage/FloatImage.h"
|
||||
|
||||
#include <nvmath/Color.h>
|
||||
#include "nvmath/Color.h"
|
||||
|
||||
#include <nvcore/Debug.h>
|
||||
#include "nvcore/Debug.h"
|
||||
|
||||
using namespace nv;
|
||||
using namespace nvtt;
|
||||
@ -63,7 +63,7 @@ void CompressorRGBE::compress(nvtt::InputFormat inputFormat, nvtt::AlphaMode alp
|
||||
uint srcPlane = w * h;
|
||||
|
||||
// Allocate output scanline.
|
||||
Color32 * dst = (Color32 *)mem::malloc(w);
|
||||
Color32 * dst = new Color32[w];
|
||||
|
||||
for (uint y = 0; y < h; y++)
|
||||
{
|
||||
@ -83,8 +83,6 @@ void CompressorRGBE::compress(nvtt::InputFormat inputFormat, nvtt::AlphaMode alp
|
||||
else {
|
||||
nvDebugCheck (inputFormat == nvtt::InputFormat_RGBA_32F);
|
||||
|
||||
#pragma message(NV_FILE_LINE "TODO: Interleave color components")
|
||||
|
||||
// Color components not interleaved.
|
||||
r = fsrc[x + 0 * srcPlane];
|
||||
g = fsrc[x + 1 * srcPlane];
|
||||
@ -100,5 +98,5 @@ void CompressorRGBE::compress(nvtt::InputFormat inputFormat, nvtt::AlphaMode alp
|
||||
}
|
||||
}
|
||||
|
||||
mem::free(dst);
|
||||
delete [] dst;
|
||||
}
|
||||
|
@ -337,8 +337,6 @@ bool Compressor::outputHeader(const TexImage & tex, int mipmapCount, const Compr
|
||||
|
||||
bool Compressor::compress(const TexImage & tex, const CompressionOptions & compressionOptions, const OutputOptions & outputOptions) const
|
||||
{
|
||||
// @@ Decide whether to change the swizzling of FloatImage.
|
||||
|
||||
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)) {
|
||||
@ -1493,7 +1491,7 @@ CompressorInterface * Compressor::Private::chooseGpuCompressor(const Compression
|
||||
bool Compressor::Private::compress2D(InputFormat inputFormat, AlphaMode alphaMode, int w, int h, const void * data, const CompressionOptions::Private & compressionOptions, const OutputOptions::Private & outputOptions) const
|
||||
{
|
||||
// Decide what compressor to use.
|
||||
CompressorInterface * compressor = NULL;
|
||||
AutoPtr<CompressorInterface> compressor;
|
||||
#if defined HAVE_CUDA
|
||||
if (cudaEnabled && w * h >= 512)
|
||||
{
|
||||
@ -1512,8 +1510,6 @@ bool Compressor::Private::compress2D(InputFormat inputFormat, AlphaMode alphaMod
|
||||
else
|
||||
{
|
||||
compressor->compress(inputFormat, alphaMode, w, h, data, compressionOptions, outputOptions);
|
||||
|
||||
delete compressor;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -23,15 +23,15 @@
|
||||
|
||||
#include "TexImage.h"
|
||||
|
||||
#include <nvmath/Vector.h>
|
||||
#include <nvmath/Matrix.h>
|
||||
#include <nvmath/Color.h>
|
||||
#include "nvmath/Vector.h"
|
||||
#include "nvmath/Matrix.h"
|
||||
#include "nvmath/Color.h"
|
||||
|
||||
#include <nvimage/Filter.h>
|
||||
#include <nvimage/ImageIO.h>
|
||||
#include <nvimage/NormalMap.h>
|
||||
#include <nvimage/BlockDXT.h>
|
||||
#include <nvimage/ColorBlock.h>
|
||||
#include "nvimage/Filter.h"
|
||||
#include "nvimage/ImageIO.h"
|
||||
#include "nvimage/NormalMap.h"
|
||||
#include "nvimage/BlockDXT.h"
|
||||
#include "nvimage/ColorBlock.h"
|
||||
|
||||
#include <float.h>
|
||||
|
||||
@ -128,6 +128,7 @@ void TexImage::detach()
|
||||
{
|
||||
if (m->refCount() > 1)
|
||||
{
|
||||
m->release();
|
||||
m = new TexImage::Private(*m);
|
||||
m->addRef();
|
||||
nvDebugCheck(m->refCount() == 1);
|
||||
@ -281,6 +282,8 @@ bool TexImage::load(const char * fileName)
|
||||
|
||||
detach();
|
||||
|
||||
#pragma message(NV_FILE_LINE "TODO: Make sure that floating point image has 4 channels.")
|
||||
|
||||
m->imageArray.resize(1);
|
||||
m->imageArray[0] = img.release();
|
||||
|
||||
@ -674,19 +677,21 @@ bool TexImage::buildNextMipmap(MipmapFilter filter)
|
||||
|
||||
foreach (i, m->imageArray)
|
||||
{
|
||||
if (m->imageArray[i] == NULL) continue;
|
||||
FloatImage * img = m->imageArray[i];
|
||||
|
||||
if (img == NULL) continue;
|
||||
|
||||
if (m->alphaMode == AlphaMode_Transparency)
|
||||
{
|
||||
if (filter == MipmapFilter_Box)
|
||||
{
|
||||
BoxFilter filter;
|
||||
m->imageArray[i]->downSample(filter, wrapMode, 3);
|
||||
img = img->downSample(filter, wrapMode, 3);
|
||||
}
|
||||
else if (filter == MipmapFilter_Triangle)
|
||||
{
|
||||
TriangleFilter filter;
|
||||
m->imageArray[i]->downSample(filter, wrapMode, 3);
|
||||
img = img->downSample(filter, wrapMode, 3);
|
||||
}
|
||||
else if (filter == MipmapFilter_Kaiser)
|
||||
{
|
||||
@ -694,19 +699,19 @@ bool TexImage::buildNextMipmap(MipmapFilter filter)
|
||||
//KaiserFilter filter(inputOptions.kaiserWidth);
|
||||
//filter.setParameters(inputOptions.kaiserAlpha, inputOptions.kaiserStretch);
|
||||
KaiserFilter filter(3);
|
||||
m->imageArray[i]->downSample(filter, wrapMode, 3);
|
||||
img = img->downSample(filter, wrapMode, 3);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (filter == MipmapFilter_Box)
|
||||
{
|
||||
m->imageArray[i]->fastDownSample();
|
||||
img = img->fastDownSample();
|
||||
}
|
||||
else if (filter == MipmapFilter_Triangle)
|
||||
{
|
||||
TriangleFilter filter;
|
||||
m->imageArray[i]->downSample(filter, wrapMode);
|
||||
img = img->downSample(filter, wrapMode);
|
||||
}
|
||||
else //if (filter == MipmapFilter_Kaiser)
|
||||
{
|
||||
@ -714,9 +719,12 @@ bool TexImage::buildNextMipmap(MipmapFilter filter)
|
||||
//KaiserFilter filter(inputOptions.kaiserWidth);
|
||||
//filter.setParameters(inputOptions.kaiserAlpha, inputOptions.kaiserStretch);
|
||||
KaiserFilter filter(3);
|
||||
m->imageArray[i]->downSample(filter, wrapMode);
|
||||
img = img->downSample(filter, wrapMode);
|
||||
}
|
||||
}
|
||||
|
||||
delete m->imageArray[i];
|
||||
m->imageArray[i] = img;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -56,7 +56,10 @@ namespace nvtt
|
||||
alphaMode = p.alphaMode;
|
||||
isNormalMap = p.isNormalMap;
|
||||
|
||||
imageArray = p.imageArray;
|
||||
imageArray.reserve(p.imageArray.count());
|
||||
foreach(i, p.imageArray) {
|
||||
imageArray.append(p.imageArray[i]->clone());
|
||||
}
|
||||
}
|
||||
~Private()
|
||||
{
|
||||
|
@ -48,7 +48,7 @@
|
||||
# define NVTT_API
|
||||
#endif
|
||||
|
||||
#define NVTT_VERSION 201
|
||||
#define NVTT_VERSION 020100
|
||||
|
||||
#define NVTT_FORBID_COPY(Class) \
|
||||
private: \
|
||||
|
@ -47,7 +47,7 @@
|
||||
# define NVTT_API
|
||||
#endif
|
||||
|
||||
#define NVTT_VERSION 201
|
||||
#define NVTT_VERSION 020100
|
||||
|
||||
#ifdef __cplusplus
|
||||
typedef struct nvtt::InputOptions NvttInputOptions;
|
||||
|
@ -21,6 +21,7 @@
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
#include <nvcore/StrLib.h>
|
||||
#include <nvtt/nvtt.h>
|
||||
|
||||
#include <stdlib.h> // EXIT_SUCCESS, EXIT_FAILURE
|
||||
@ -30,30 +31,54 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
if (argc != 2) return EXIT_FAILURE;
|
||||
|
||||
nvtt::CompressionOptions compressionOptions;
|
||||
compressionOptions.setFormat(nvtt::Format_BC1);
|
||||
|
||||
nvtt::OutputOptions outputOptions;
|
||||
outputOptions.setFileName("output.dds");
|
||||
const char * inputFileName = argv[1];
|
||||
|
||||
// Init context.
|
||||
nvtt::Context context;
|
||||
context.enableCudaAcceleration(false);
|
||||
|
||||
// Load input image.
|
||||
nvtt::TexImage image = context.createTexImage();
|
||||
if (!image.load(inputFileName)) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
image.load(argv[1]);
|
||||
// Setup compression options.
|
||||
nvtt::CompressionOptions compressionOptions;
|
||||
compressionOptions.setFormat(nvtt::Format_BC3);
|
||||
//compressionOptions.setFormat(nvtt::Format_RGBA);
|
||||
|
||||
context.outputHeader(image, image.countMipmaps(), compressionOptions, outputOptions);
|
||||
// Setup output options.
|
||||
nvtt::OutputOptions outputOptions;
|
||||
|
||||
nv::Path outputFileName(inputFileName);
|
||||
outputFileName.stripExtension();
|
||||
outputFileName.append(".dds");
|
||||
|
||||
outputOptions.setFileName(outputFileName);
|
||||
|
||||
// Output compressed image.
|
||||
context.outputHeader(image, image.countMipmaps(), compressionOptions, outputOptions);
|
||||
|
||||
image.flipVertically();
|
||||
image.setAlphaMode(nvtt::AlphaMode_Transparency);
|
||||
|
||||
// Output first mipmap.
|
||||
context.compress(image, compressionOptions, outputOptions);
|
||||
|
||||
float gamma = 2.2f;
|
||||
image.toLinear(gamma);
|
||||
|
||||
float coverage = image.alphaTestCoverage();
|
||||
float alphaRef = 0.95;
|
||||
float coverage = image.alphaTestCoverage(alphaRef);
|
||||
|
||||
while (image.buildNextMipmap(nvtt::MipmapFilter_Box))
|
||||
// Build mimaps.
|
||||
while (image.buildNextMipmap(nvtt::MipmapFilter_Kaiser))
|
||||
{
|
||||
nvtt::TexImage tmpImage = image;
|
||||
tmpImage.toGamma(gamma);
|
||||
|
||||
tmpImage.scaleAlphaToCoverage(coverage);
|
||||
tmpImage.scaleAlphaToCoverage(coverage, alphaRef);
|
||||
|
||||
context.compress(tmpImage, compressionOptions, outputOptions);
|
||||
}
|
||||
|
Reference in New Issue
Block a user