2009-03-02 07:32:00 +00:00
|
|
|
// Copyright NVIDIA Corporation 2007 -- Ignacio Castano <icastano@nvidia.com>
|
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person
|
|
|
|
// obtaining a copy of this software and associated documentation
|
|
|
|
// files (the "Software"), to deal in the Software without
|
|
|
|
// restriction, including without limitation the rights to use,
|
|
|
|
// copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
// copies of the Software, and to permit persons to whom the
|
|
|
|
// Software is furnished to do so, subject to the following
|
|
|
|
// conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be
|
|
|
|
// included in all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
|
|
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
|
|
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
|
|
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
|
|
// OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
2010-06-01 02:04:33 +00:00
|
|
|
#include <nvcore/StrLib.h>
|
2009-03-02 07:32:00 +00:00
|
|
|
#include <nvtt/nvtt.h>
|
|
|
|
|
2010-05-28 23:16:06 +00:00
|
|
|
#include <stdlib.h> // EXIT_SUCCESS, EXIT_FAILURE
|
2009-03-02 07:32:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2010-05-28 23:16:06 +00:00
|
|
|
if (argc != 2) return EXIT_FAILURE;
|
|
|
|
|
2010-06-01 02:04:33 +00:00
|
|
|
const char * inputFileName = argv[1];
|
|
|
|
|
|
|
|
// Init context.
|
2010-06-03 00:32:49 +00:00
|
|
|
nvtt::Context context;
|
2010-06-01 02:04:33 +00:00
|
|
|
context.enableCudaAcceleration(false);
|
|
|
|
|
|
|
|
// Load input image.
|
2011-09-28 16:40:59 +00:00
|
|
|
nvtt::Surface image;
|
2010-06-01 02:04:33 +00:00
|
|
|
if (!image.load(inputFileName)) {
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Setup compression options.
|
2010-06-03 00:32:49 +00:00
|
|
|
nvtt::CompressionOptions compressionOptions;
|
|
|
|
compressionOptions.setFormat(nvtt::Format_BC3);
|
2010-06-01 02:04:33 +00:00
|
|
|
//compressionOptions.setFormat(nvtt::Format_RGBA);
|
2009-03-15 10:18:54 +00:00
|
|
|
|
2010-06-01 02:04:33 +00:00
|
|
|
// Setup output options.
|
2010-06-03 00:32:49 +00:00
|
|
|
nvtt::OutputOptions outputOptions;
|
2009-03-05 05:34:28 +00:00
|
|
|
|
2010-06-01 02:04:33 +00:00
|
|
|
nv::Path outputFileName(inputFileName);
|
|
|
|
outputFileName.stripExtension();
|
|
|
|
outputFileName.append(".dds");
|
|
|
|
|
2010-08-31 01:39:08 +00:00
|
|
|
outputOptions.setFileName(outputFileName.str());
|
2010-06-01 02:04:33 +00:00
|
|
|
|
|
|
|
// Output compressed image.
|
|
|
|
context.outputHeader(image, image.countMipmaps(), compressionOptions, outputOptions);
|
2009-03-05 05:34:28 +00:00
|
|
|
|
2011-09-27 05:17:01 +00:00
|
|
|
image.flipY();
|
2010-06-01 02:04:33 +00:00
|
|
|
image.setAlphaMode(nvtt::AlphaMode_Transparency);
|
2009-03-05 05:34:28 +00:00
|
|
|
|
2010-06-01 02:04:33 +00:00
|
|
|
// Output first mipmap.
|
2010-11-06 02:34:34 +00:00
|
|
|
context.compress(image, 0, 0, compressionOptions, outputOptions);
|
2009-10-12 07:56:02 +00:00
|
|
|
|
2010-06-03 00:32:49 +00:00
|
|
|
float gamma = 2.2f;
|
|
|
|
image.toLinear(gamma);
|
2009-03-05 05:34:28 +00:00
|
|
|
|
2010-07-13 03:08:45 +00:00
|
|
|
float alphaRef = 0.95f;
|
2010-06-01 02:04:33 +00:00
|
|
|
float coverage = image.alphaTestCoverage(alphaRef);
|
2010-05-28 23:16:06 +00:00
|
|
|
|
2010-06-01 02:04:33 +00:00
|
|
|
// Build mimaps.
|
2010-11-06 02:34:34 +00:00
|
|
|
int m = 1;
|
2010-06-01 02:04:33 +00:00
|
|
|
while (image.buildNextMipmap(nvtt::MipmapFilter_Kaiser))
|
2010-06-03 00:32:49 +00:00
|
|
|
{
|
2011-09-28 16:40:59 +00:00
|
|
|
nvtt::Surface tmpImage = image;
|
2010-06-03 00:32:49 +00:00
|
|
|
tmpImage.toGamma(gamma);
|
2009-03-07 07:14:00 +00:00
|
|
|
|
2010-06-01 02:04:33 +00:00
|
|
|
tmpImage.scaleAlphaToCoverage(coverage, alphaRef);
|
2010-05-28 23:16:06 +00:00
|
|
|
|
2010-11-06 02:34:34 +00:00
|
|
|
context.compress(tmpImage, 0, m, compressionOptions, outputOptions);
|
|
|
|
m++;
|
2010-06-03 00:32:49 +00:00
|
|
|
}
|
2009-03-05 05:34:28 +00:00
|
|
|
|
2010-06-03 00:32:49 +00:00
|
|
|
return EXIT_SUCCESS;
|
2009-03-02 07:32:00 +00:00
|
|
|
}
|
|
|
|
|