diff --git a/src/nvtt/InputOptions.cpp b/src/nvtt/InputOptions.cpp index 26139ca..1f79662 100644 --- a/src/nvtt/InputOptions.cpp +++ b/src/nvtt/InputOptions.cpp @@ -297,7 +297,7 @@ void InputOptions::setColorTransform(ColorTransform t) } // Set linear transform for the given channel. -void InputOptions::setLinearTransfrom(int channel, float w0, float w1, float w2, float w3) +void InputOptions::setLinearTransform(int channel, float w0, float w1, float w2, float w3) { nvCheck(channel >= 0 && channel < 4); diff --git a/src/nvtt/nvtt.cs b/src/nvtt/nvtt.cs index 9349fe0..812de25 100644 --- a/src/nvtt/nvtt.cs +++ b/src/nvtt/nvtt.cs @@ -1,16 +1,16 @@ - using System; -using System.Runtime.InteropServices; - -namespace Nvidia.TextureTools -{ +using System.Security; +using System.Runtime.InteropServices; + +namespace Nvidia.TextureTools +{ #region Enums - - #region enum Format - /// - /// Compression format. + + #region public enum Format + /// + /// Compression format. /// - enum Format + public enum Format { // No compression. RGB, @@ -22,7 +22,7 @@ namespace Nvidia.TextureTools DXT3, DXT5, DXT5n, - + // DX10 formats. BC1 = DXT1, BC1a = DXT1a, @@ -34,11 +34,11 @@ namespace Nvidia.TextureTools } #endregion - #region enum Quality - /// - /// Quality modes. + #region public enum Quality + /// + /// Quality modes. /// - enum Quality + public enum Quality { Fastest, Normal, @@ -47,54 +47,184 @@ namespace Nvidia.TextureTools } #endregion - #region enum TextureType - /// - /// Texture types. + #region public enum WrapMode + /// + /// Wrap modes. + /// + public enum WrapMode + { + Clamp, + Repeat, + Mirror, + } + #endregion + + #region public enum TextureType + /// + /// Texture types. /// - enum TextureType + public enum TextureType { Texture2D, TextureCube, } #endregion - + + #region public enum InputFormat + /// + /// Input formats. + /// + public enum InputFormat + { + BGRA_8UB + } + #endregion + + #region public enum MipmapFilter + /// + /// Mipmap downsampling filters. + /// + public enum MipmapFilter + { + Box, + Triangle, + Kaiser + } + #endregion + + #region public enum ColorTransform + /// + /// Color transformation. + /// + public enum ColorTransform + { + None, + Linear + } + #endregion + + #region public enum RoundMode + /// + /// Extents rounding mode. + /// + public enum RoundMode + { + None, + ToNextPowerOfTwo, + ToNearestPowerOfTwo, + ToPreviousPowerOfTwo + } #endregion + #region public enum AlphaMode + /// + /// Alpha mode. + /// + public enum AlphaMode + { + None, + Transparency, + Premultiplied + } + #endregion - #region public class InputOptions - /// - /// Input options. + #region public enum Error + /// + /// Error codes. + /// + public enum Error + { + InvalidInput, + UserInterruption, + UnsupportedFeature, + CudaError, + Unknown, + FileOpen, + FileWrite, + } + #endregion + + #endregion + + #region public class InputOptions + /// + /// Input options. /// public class InputOptions - { - #region Bindings - [DllImport("nvtt")] + { + #region Bindings + [DllImport("nvtt"), SuppressUnmanagedCodeSecurity] private extern static IntPtr nvttCreateInputOptions(); - - [DllImport("nvtt")] + + [DllImport("nvtt"), SuppressUnmanagedCodeSecurity] private extern static void nvttDestroyInputOptions(IntPtr inputOptions); - - [DllImport("nvtt")] - private extern static void nvttSetInputOptionsTextureLayout(IntPtr inputOptions, TextureType type, int w, int h, int d); - - [DllImport("nvtt")] - private extern static void nvttResetInputOptionsTextureLayout(IntPtr inputOptions); - - [DllImport("nvtt")] - private extern static bool nvttSetInputOptionsMipmapData(IntPtr inputOptions, IntPtr data, int w, int h, int d, int face, int mipmap); + + [DllImport("nvtt"), SuppressUnmanagedCodeSecurity] + private extern static void nvttSetInputOptionsTextureLayout(IntPtr inputOptions, TextureType type, int w, int h, int d); + + [DllImport("nvtt"), SuppressUnmanagedCodeSecurity] + private extern static void nvttResetInputOptionsTextureLayout(IntPtr inputOptions); + + [DllImport("nvtt"), SuppressUnmanagedCodeSecurity] + private extern static bool nvttSetInputOptionsMipmapData(IntPtr inputOptions, IntPtr data, int w, int h, int d, int face, int mipmap); + + [DllImport("nvtt"), SuppressUnmanagedCodeSecurity] + private extern static void nvttSetInputOptionsFormat(IntPtr inputOptions, InputFormat format); + + [DllImport("nvtt"), SuppressUnmanagedCodeSecurity] + private extern static void nvttSetInputOptionsAlphaMode(IntPtr inputOptions, AlphaMode alphaMode); + + [DllImport("nvtt"), SuppressUnmanagedCodeSecurity] + private extern static void nvttSetInputOptionsGamma(IntPtr inputOptions, float inputGamma, float outputGamma); + + [DllImport("nvtt"), SuppressUnmanagedCodeSecurity] + private extern static void nvttSetInputOptionsWrapMode(IntPtr inputOptions, WrapMode mode); + + [DllImport("nvtt"), SuppressUnmanagedCodeSecurity] + private extern static void nvttSetInputOptionsMipmapping(IntPtr inputOptions, bool generateMipmaps, MipmapFilter filter, int maxLevel); + + [DllImport("nvtt"), SuppressUnmanagedCodeSecurity] + private extern static void nvttSetInputOptionsKaiserParameters(IntPtr inputOptions, float width, float alpha, float stretch); + + [DllImport("nvtt"), SuppressUnmanagedCodeSecurity] + private extern static void nvttSetInputOptionsNormalMap(IntPtr inputOptions, bool b); + + [DllImport("nvtt"), SuppressUnmanagedCodeSecurity] + private extern static void nvttSetInputOptionsConvertToNormalMap(IntPtr inputOptions, bool convert); + + [DllImport("nvtt"), SuppressUnmanagedCodeSecurity] + private extern static void nvttSetInputOptionsHeightEvaluation(IntPtr inputOptions, float redScale, float greenScale, float blueScale, float alphaScale); + + [DllImport("nvtt"), SuppressUnmanagedCodeSecurity] + private extern static void nvttSetInputOptionsNormalFilter(IntPtr inputOptions, float small, float medium, float big, float large); + + [DllImport("nvtt"), SuppressUnmanagedCodeSecurity] + private extern static void nvttSetInputOptionsNormalizeMipmaps(IntPtr inputOptions, bool b); + + [DllImport("nvtt"), SuppressUnmanagedCodeSecurity] + private extern static void nvttSetInputOptionsColorTransform(IntPtr inputOptions, ColorTransform t); + + [DllImport("nvtt"), SuppressUnmanagedCodeSecurity] + private extern static void nvttSetInputOptionsLinearTransfrom(IntPtr inputOptions, int channel, float w0, float w1, float w2, float w3); + + [DllImport("nvtt"), SuppressUnmanagedCodeSecurity] + private extern static void nvttSetInputOptionsMaxExtents(IntPtr inputOptions, int d); + + [DllImport("nvtt"), SuppressUnmanagedCodeSecurity] + private extern static void nvttSetInputOptionsRoundMode(IntPtr inputOptions, RoundMode mode); #endregion - - internal IntPtr options; - + + internal IntPtr options; + public InputOptions() { options = nvttCreateInputOptions(); } - public ~InputOptions() - { + ~InputOptions() + { nvttDestroyInputOptions(options); } - + public void SetTextureLayout(TextureType type, int w, int h, int d) { nvttSetInputOptionsTextureLayout(options, type, w, h, d); @@ -103,121 +233,276 @@ namespace Nvidia.TextureTools { nvttResetInputOptionsTextureLayout(options); } - + public void SetMipmapData(IntPtr data, int width, int height, int depth, int face, int mipmap) { nvttSetInputOptionsMipmapData(options, data, width, height, depth, face, mipmap); } + + public void SetFormat(InputFormat format) + { + nvttSetInputOptionsFormat(options, format); + } + + public void SetAlphaMode(AlphaMode alphaMode) + { + nvttSetInputOptionsAlphaMode(options, alphaMode); + } + + public void SetGamma(float inputGamma, float outputGamma) + { + nvttSetInputOptionsGamma(options, inputGamma, outputGamma); + } + + public void SetWrapMode(WrapMode wrapMode) + { + nvttSetInputOptionsWrapMode(options, wrapMode); + } + + public void SetMipmapping(bool generateMipmaps) + { + nvttSetInputOptionsMipmapping(options, generateMipmaps, MipmapFilter.Box, -1); + } + + public void SetMipmapping(bool generateMipmaps, MipmapFilter filter) + { + nvttSetInputOptionsMipmapping(options, generateMipmaps, filter, -1); + } + + public void SetMipmapping(bool generateMipmaps, MipmapFilter filter, int maxLevel) + { + nvttSetInputOptionsMipmapping(options, generateMipmaps, filter, maxLevel); + } + + public void SetKaiserParameters(float width, float alpha, float stretch) + { + nvttSetInputOptionsKaiserParameters(options, width, alpha, stretch); + } + + public void SetNormalMap(bool b) + { + nvttSetInputOptionsNormalMap(options, b); + } + + public void SetConvertToNormalMap(bool convert) + { + nvttSetInputOptionsConvertToNormalMap(options, convert); + } + + public void SetHeightEvaluation(float redScale, float greenScale, float blueScale, float alphaScale) + { + nvttSetInputOptionsHeightEvaluation(options, redScale, greenScale, blueScale, alphaScale); + } + + public void SetNormalFilter(float small, float medium, float big, float large) + { + nvttSetInputOptionsNormalFilter(options, small, medium, big, large); + } + + public void SetNormalizeMipmaps(bool b) + { + nvttSetInputOptionsNormalizeMipmaps(options, b); + } + + public void SetColorTransform(ColorTransform t) + { + nvttSetInputOptionsColorTransform(options, t); + } + + public void SetLinearTransfrom(int channel, float w0, float w1, float w2, float w3) + { + nvttSetInputOptionsLinearTransfrom(options, channel, w0, w1, w2, w3); + } + + public void SetMaxExtents(int dim) + { + nvttSetInputOptionsMaxExtents(options, dim); + } + + public void SetRoundMode(RoundMode mode) + { + nvttSetInputOptionsRoundMode(options, mode); + } } #endregion - #region public class CompressionOptions - /// - /// Compression options. + #region public class CompressionOptions + /// + /// Compression options. /// public class CompressionOptions - { - #region Bindings - [DllImport("nvtt")] + { + #region Bindings + [DllImport("nvtt"), SuppressUnmanagedCodeSecurity] private extern static IntPtr nvttCreateCompressionOptions(); - - [DllImport("nvtt")] + + [DllImport("nvtt"), SuppressUnmanagedCodeSecurity] private extern static void nvttDestroyCompressionOptions(IntPtr compressionOptions); - - [DllImport("nvtt")] - private extern static void nvttSetCompressionOptionsFormat(IntPtr compressionOptions, Format format); - - [DllImport("nvtt")] - private extern static void nvttSetCompressionOptionsQuality(IntPtr compressionOptions, Quality quality); - - [DllImport("nvtt")] - private extern static void nvttSetCompressionOptionsPixelFormat(IntPtr compressionOptions, uint bitcount, uint rmask, uint gmask, uint bmask, uint amask); + + [DllImport("nvtt"), SuppressUnmanagedCodeSecurity] + private extern static void nvttSetCompressionOptionsFormat(IntPtr compressionOptions, Format format); + + [DllImport("nvtt"), SuppressUnmanagedCodeSecurity] + private extern static void nvttSetCompressionOptionsQuality(IntPtr compressionOptions, Quality quality); + + [DllImport("nvtt"), SuppressUnmanagedCodeSecurity] + private extern static void nvttSetCompressionOptionsColorWeights(IntPtr compressionOptions, float red, float green, float blue, float alpha); + + [DllImport("nvtt"), SuppressUnmanagedCodeSecurity] + private extern static void nvttEnableCompressionOptionsCudaCompression(IntPtr compressionOptions, bool enable); + + [DllImport("nvtt"), SuppressUnmanagedCodeSecurity] + private extern static void nvttSetCompressionOptionsPixelFormat(IntPtr compressionOptions, uint bitcount, uint rmask, uint gmask, uint bmask, uint amask); + + [DllImport("nvtt"), SuppressUnmanagedCodeSecurity] + private extern static void nvttSetCompressionOptionsQuantization(IntPtr compressionOptions, bool colorDithering, bool alphaDithering, bool binaryAlpha, int alphaThreshold); #endregion - - internal IntPtr options; - + + internal IntPtr options; + public CompressionOptions() { options = nvttCreateCompressionOptions(); } - public ~CompressionOptions() + ~CompressionOptions() { nvttDestroyCompressionOptions(options); } - + public void SetFormat(Format format) { nvttSetCompressionOptionsFormat(options, format); } + public void SetQuality(Quality quality) { nvttSetCompressionOptionsQuality(options, quality); } + + public void SetColorWeights(float red, float green, float blue) + { + nvttSetCompressionOptionsColorWeights(options, red, green, blue, 1.0f); + } + + public void SetColorWeights(float red, float green, float blue, float alpha) + { + nvttSetCompressionOptionsColorWeights(options, red, green, blue, alpha); + } + + public void EnableCudaCompression(bool enable) + { + nvttEnableCompressionOptionsCudaCompression(options, enable); + } + public void SetPixelFormat(uint bitcount, uint rmask, uint gmask, uint bmask, uint amask) { nvttSetCompressionOptionsPixelFormat(options, bitcount, rmask, gmask, bmask, amask); } + + public void SetQuantization(bool colorDithering, bool alphaDithering, bool binaryAlpha) + { + nvttSetCompressionOptionsQuantization(options, colorDithering, alphaDithering, binaryAlpha, 127); + } + + public void SetQuantization(bool colorDithering, bool alphaDithering, bool binaryAlpha, int alphaThreshold) + { + nvttSetCompressionOptionsQuantization(options, colorDithering, alphaDithering, binaryAlpha, alphaThreshold); + } } #endregion - #region public class OutputOptions - /// - /// Output options. + #region public class OutputOptions + /// + /// Output options. /// public class OutputOptions - { - #region Bindings - [DllImport("nvtt")] + { + #region Delegates + public delegate void ErrorHandler(Error error); + private delegate void WriteDataDelegate(IntPtr data, int size); + private delegate void ImageDelegate(int size, int width, int height, int depth, int face, int miplevel); + #endregion + + #region Bindings + [DllImport("nvtt"), SuppressUnmanagedCodeSecurity] private extern static IntPtr nvttCreateOutputOptions(); - - [DllImport("nvtt")] + + [DllImport("nvtt"), SuppressUnmanagedCodeSecurity] private extern static void nvttDestroyOutputOptions(IntPtr outputOptions); - - [DllImport("nvtt", CharSet = CharSet.Ansi)] - private extern static void nvttSetOutputOptionsFileName(IntPtr outputOptions, string fileName); - + + [DllImport("nvtt", CharSet = CharSet.Ansi), SuppressUnmanagedCodeSecurity] + private extern static void nvttSetOutputOptionsFileName(IntPtr outputOptions, string fileName); + + [DllImport("nvtt"), SuppressUnmanagedCodeSecurity] + private extern static void nvttSetOutputOptionsErrorHandler(IntPtr outputOptions, ErrorHandler errorHandler); + + private void ErrorCallback(Error error) + { + if (Error != null) Error(error); + } + + [DllImport("nvtt"), SuppressUnmanagedCodeSecurity] + private extern static void nvttSetOutputOptionsOutputHeader(IntPtr outputOptions, bool b); + + [DllImport("nvtt"), SuppressUnmanagedCodeSecurity] + private extern static void nvttSetOutputOptionsOutputHandler(IntPtr outputOptions, WriteDataDelegate writeData, ImageDelegate image); + #endregion - - internal IntPtr options; - + + internal IntPtr options; + public OutputOptions() { options = nvttCreateOutputOptions(); + nvttSetOutputOptionsErrorHandler(options, new ErrorHandler(ErrorCallback)); } - public ~OutputOptions() + ~OutputOptions() { nvttDestroyOutputOptions(options); } - + public void SetFileName(string fileName) - { + { nvttSetOutputOptionsFileName(options, fileName); } + + public event ErrorHandler Error; + + // @@ Add OutputHandler interface. } #endregion #region public static class Compressor public static class Compressor - { - #region Bindings - [DllImport("nvtt")] + { + #region Bindings + [DllImport("nvtt"), SuppressUnmanagedCodeSecurity] private extern static bool nvttCompress(IntPtr inputOptions, IntPtr compressionOptions, IntPtr outputOptions); - - [DllImport("nvtt")] - private extern static void nvttEstimateSize(IntPtr inputOptions, IntPtr compressionOptions); - + + [DllImport("nvtt"), SuppressUnmanagedCodeSecurity] + private extern static int nvttEstimateSize(IntPtr inputOptions, IntPtr compressionOptions); + + [DllImport("nvtt"), SuppressUnmanagedCodeSecurity] + private static extern IntPtr nvttErrorString(Error error); + #endregion - - public bool Compress(InputOptions inputOptions, CompressionOptions compressionOptions, OutputOptions outputOptions) + + public static bool Compress(InputOptions inputOptions, CompressionOptions compressionOptions, OutputOptions outputOptions) { - nvttCompress(inputOptions.options, compressionOptions.options, outputOptions.options); + return nvttCompress(inputOptions.options, compressionOptions.options, outputOptions.options); } - - public bool EstimateSize(InputOptions inputOptions, CompressionOptions compressionOptions) + + public static int EstimateSize(InputOptions inputOptions, CompressionOptions compressionOptions) { - nvttEstimateSize(inputOptions.options, compressionOptions.options); + return nvttEstimateSize(inputOptions.options, compressionOptions.options); } + + public static string ErrorString(Error error) + { + return Marshal.PtrToStringAnsi(nvttErrorString(error)); + } + } - #endregion - -} // Nvidia.TextureTools namespace \ No newline at end of file + #endregion + +} // Nvidia.TextureTools namespace diff --git a/src/nvtt/nvtt.h b/src/nvtt/nvtt.h index 8d87f6a..907813d 100644 --- a/src/nvtt/nvtt.h +++ b/src/nvtt/nvtt.h @@ -87,9 +87,8 @@ namespace nvtt }; /// Compression options. This class describes the desired compression format and other compression settings. - class CompressionOptions + struct CompressionOptions { - public: NVTT_API CompressionOptions(); NVTT_API ~CompressionOptions(); @@ -107,7 +106,7 @@ namespace nvtt // Set color mask to describe the RGB/RGBA format. NVTT_API void setPixelFormat(unsigned int bitcount, unsigned int rmask, unsigned int gmask, unsigned int bmask, unsigned int amask); - NVTT_API void setQuantization(bool colorDithering, bool alphaDithering, bool binaryAlpha, int alphaThreshold/*= 127*/); + NVTT_API void setQuantization(bool colorDithering, bool alphaDithering, bool binaryAlpha, int alphaThreshold = 127); //private: struct Private; @@ -216,7 +215,7 @@ namespace nvtt // Set color transforms. @@ Not implemented! NVTT_API void setColorTransform(ColorTransform t); - NVTT_API void setLinearTransfrom(int channel, float w0, float w1, float w2, float w3); + NVTT_API void setLinearTransform(int channel, float w0, float w1, float w2, float w3); // Set resizing options. @@ Not fully tested! NVTT_API void setMaxExtents(int d); diff --git a/src/nvtt/nvtt_wrapper.cpp b/src/nvtt/nvtt_wrapper.cpp index ade02f5..daa68c5 100644 --- a/src/nvtt/nvtt_wrapper.cpp +++ b/src/nvtt/nvtt_wrapper.cpp @@ -29,6 +29,82 @@ NvttBoolean nvttSetInputOptionsMipmapData(NvttInputOptions * inputOptions, const return (NvttBoolean)inputOptions->setMipmapData(data, w, h, d, face, mipmap); } +void nvttSetInputOptionsFormat(NvttInputOptions * inputOptions, NvttInputFormat format) +{ + inputOptions->setFormat((nvtt::InputFormat)format); +} + +void nvttSetInputOptionsAlphaMode(NvttInputOptions * inputOptions, NvttAlphaMode alphaMode) +{ + inputOptions->setAlphaMode((nvtt::AlphaMode)alphaMode); +} + +void nvttSetInputOptionsGamma(NvttInputOptions * inputOptions, float inputGamma, float outputGamma) +{ + inputOptions->setGamma(inputGamma, outputGamma); +} + + +void nvttSetInputOptionsWrapMode(NvttInputOptions * inputOptions, NvttWrapMode mode) +{ + inputOptions->setWrapMode((nvtt::WrapMode)mode); +} + +void nvttSetInputOptionsMipmapping(NvttInputOptions * inputOptions, NvttBoolean generateMipmaps, NvttMipmapFilter filter, int maxLevel) +{ + inputOptions->setMipmapping(generateMipmaps != NVTT_False, (nvtt::MipmapFilter)filter, maxLevel); +} + +void nvttSetInputOptionsKaiserParameters(NvttInputOptions * inputOptions, float width, float alpha, float stretch) +{ + inputOptions->setKaiserParameters(width, alpha, stretch); +} + +void nvttSetInputOptionsNormalMap(NvttInputOptions * inputOptions, NvttBoolean b) +{ + inputOptions->setNormalMap(b != NVTT_False); +} + +void nvttSetInputOptionsConvertToNormalMap(NvttInputOptions * inputOptions, NvttBoolean convert) +{ + inputOptions->setConvertToNormalMap(convert != NVTT_False); +} + +void nvttSetInputOptionsHeightEvaluation(NvttInputOptions * inputOptions, float redScale, float greenScale, float blueScale, float alphaScale) +{ + inputOptions->setHeightEvaluation(redScale, greenScale, blueScale, alphaScale); +} + +void nvttSetInputOptionsNormalFilter(NvttInputOptions * inputOptions, float small, float medium, float big, float large) +{ + inputOptions->setNormalFilter(small, medium, big, large); +} + +void nvttSetInputOptionsNormalizeMipmaps(NvttInputOptions * inputOptions, NvttBoolean b) +{ + inputOptions->setNormalizeMipmaps(b != NVTT_False); +} + +void nvttSetInputOptionsColorTransform(NvttInputOptions * inputOptions, NvttColorTransform t) +{ + inputOptions->setColorTransform((nvtt::ColorTransform)t); +} + +void nvttSetInputOptionsLinearTransfrom(NvttInputOptions * inputOptions, int channel, float w0, float w1, float w2, float w3) +{ + inputOptions->setLinearTransform(channel, w0, w1, w2, w3); +} + +void nvttSetInputOptionsMaxExtents(NvttInputOptions * inputOptions, int dim) +{ + inputOptions->setMaxExtents(dim); +} + +void nvttSetInputOptionsRoundMode(NvttInputOptions * inputOptions, NvttRoundMode mode) +{ + inputOptions->setRoundMode((nvtt::RoundMode)mode); +} + // Compression Options NvttCompressionOptions * nvttCreateCompressionOptions() @@ -51,11 +127,26 @@ void nvttSetCompressionOptionsQuality(NvttCompressionOptions * compressionOption compressionOptions->setQuality((nvtt::Quality)quality); } +void nvttSetCompressionOptionsColorWeights(NvttCompressionOptions * compressionOptions, float red, float green, float blue, float alpha) +{ + compressionOptions->setColorWeights(red, green, blue, alpha); +} + +void nvttEnableCompressionOptionsCudaCompression(NvttCompressionOptions * compressionOptions, NvttBoolean enable) +{ + compressionOptions->enableCudaCompression(enable != NVTT_False); +} + void nvttSetCompressionOptionsPixelFormat(NvttCompressionOptions * compressionOptions, unsigned int bitcount, unsigned int rmask, unsigned int gmask, unsigned int bmask, unsigned int amask) { compressionOptions->setPixelFormat(bitcount, rmask, gmask, bmask, amask); } - + +void nvttSetCompressionOptionsQuantization(NvttCompressionOptions * compressionOptions, NvttBoolean colorDithering, NvttBoolean alphaDithering, NvttBoolean binaryAlpha, int alphaThreshold) +{ + compressionOptions->setQuantization(colorDithering != NVTT_False, alphaDithering != NVTT_False, binaryAlpha != NVTT_False, alphaThreshold); +} + // Output Options NvttOutputOptions * nvttCreateOutputOptions() @@ -73,16 +164,34 @@ void nvttSetOutputOptionsFileName(NvttOutputOptions * outputOptions, const char outputOptions->setFileName(fileName); } +void nvttSetOutputOptionsOutputHeader(NvttOutputOptions * outputOptions, NvttBoolean b) +{ + outputOptions->setOutputHeader(b != NVTT_False); +} +/* +void nvttSetOutputOptionsErrorHandler(NvttOutputOptions * outputOptions, nvttErrorHandler errorHandler) +{ + outputOptions->setErrorHandler(errorHandler); +} + +void nvttSetOutputOptionsOutputHandler(NvttOutputOptions * outputOptions, nvttOutputHandler outputHandler, nvttImageHandler imageHandler) +{ +} +*/ + -// Main entrypoint of the compression library. +// Main entrypoints. NvttBoolean nvttCompress(const NvttInputOptions * inputOptions, const NvttCompressionOptions * compressionOptions, const NvttOutputOptions * outputOptions) { return (NvttBoolean)nvtt::compress(*inputOptions, *outputOptions, *compressionOptions); } -// Estimate the size of compressing the input with the given options. int nvttEstimateSize(const NvttInputOptions * inputOptions, const NvttCompressionOptions * compressionOptions) { return nvtt::estimateSize(*inputOptions, *compressionOptions); } +const char * nvttErrorString(NvttError e) +{ + return nvtt::errorString((nvtt::Error)e); +} diff --git a/src/nvtt/nvtt_wrapper.h b/src/nvtt/nvtt_wrapper.h index 72315bb..93c3a24 100644 --- a/src/nvtt/nvtt_wrapper.h +++ b/src/nvtt/nvtt_wrapper.h @@ -24,20 +24,27 @@ #ifndef NVTT_WRAPPER_H #define NVTT_WRAPPER_H -#include - // Function linkage #if NVTT_SHARED -#ifdef NVTT_EXPORTS -#define NVTT_API DLL_EXPORT -#define NVTT_CLASS DLL_EXPORT_CLASS -#else -#define NVTT_API DLL_IMPORT -#define NVTT_CLASS DLL_IMPORT + +#if defined _WIN32 || defined WIN32 || defined __NT__ || defined __WIN32__ || defined __MINGW32__ +# ifdef NVTT_EXPORTS +# define NVTT_API __declspec(dllexport) +# else +# define NVTT_API __declspec(dllimport) +# endif #endif -#else -#define NVTT_API -#define NVTT_CLASS + +#if defined __GNUC__ >= 4 +# ifdef NVTT_EXPORTS +# define NVTT_API __attribute__((visibility("default"))) +# endif +#endif + +#endif // NVTT_SHARED + +#if !defined NVTT_API +# define NVTT_API #endif #ifdef __cplusplus @@ -83,6 +90,14 @@ typedef enum NVTT_Quality_Highest, } NvttQuality; +/// Wrap modes. +typedef enum +{ + NVTT_WrapMode_Clamp, + NVTT_WrapMode_Repeat, + NVTT_WrapMode_Mirror, +} NvttWrapMode; + /// Texture types. typedef enum { @@ -90,10 +105,59 @@ typedef enum NVTT_TextureType_Cube, } NvttTextureType; +/// Input formats. +typedef enum +{ + NVTT_InputFormat_BGRA_8UB, +} NvttInputFormat; + +/// Mipmap downsampling filters. +typedef enum +{ + NVTT_MipmapFilter_Box, + NVTT_MipmapFilter_Triangle, + NVTT_MipmapFilter_Kaiser, +} NvttMipmapFilter; + +/// Color transformation. +typedef enum +{ + NVTT_ColorTransform_None, + NVTT_ColorTransform_Linear, +} NvttColorTransform; + +/// Extents rounding mode. +typedef enum +{ + NVTT_RoundMode_None, + NVTT_RoundMode_ToNextPowerOfTwo, + NVTT_RoundMode_ToNearestPowerOfTwo, + NVTT_RoundMode_ToPreviousPowerOfTwo, +} NvttRoundMode; + +/// Alpha mode. +typedef enum +{ + NVTT_AlphaMode_None, + NVTT_AlphaMode_Transparency, + NVTT_AlphaMode_Premultiplied, +} NvttAlphaMode; + +typedef enum +{ + NVTT_Error_InvalidInput, + NVTT_Error_UserInterruption, + NVTT_Error_UnsupportedFeature, + NVTT_Error_CudaError, + NVTT_Error_Unknown, + NVTT_Error_FileOpen, + NVTT_Error_FileWrite, +} NvttError; + typedef enum { - NVTT_True, NVTT_False, + NVTT_True, } NvttBoolean; @@ -101,6 +165,11 @@ typedef enum extern "C" { #endif +// Callbacks +//typedef void (* nvttErrorHandler)(NvttError e); +//typedef void (* nvttOutputHandler)(const void * data, int size); +//typedef void (* nvttImageHandler)(int size, int width, int height, int depth, int face, int miplevel); + // Input Options NVTT_API NvttInputOptions * nvttCreateInputOptions(); NVTT_API void nvttDestroyInputOptions(NvttInputOptions * inputOptions); @@ -108,6 +177,21 @@ NVTT_API void nvttDestroyInputOptions(NvttInputOptions * inputOptions); NVTT_API void nvttSetInputOptionsTextureLayout(NvttInputOptions * inputOptions, NvttTextureType type, int w, int h, int d); NVTT_API void nvttResetInputOptionsTextureLayout(NvttInputOptions * inputOptions); NVTT_API NvttBoolean nvttSetInputOptionsMipmapData(NvttInputOptions * inputOptions, const void * data, int w, int h, int d, int face, int mipmap); +NVTT_API void nvttSetInputOptionsFormat(NvttInputOptions * inputOptions, NvttInputFormat format); +NVTT_API void nvttSetInputOptionsAlphaMode(NvttInputOptions * inputOptions, NvttAlphaMode alphaMode); +NVTT_API void nvttSetInputOptionsGamma(NvttInputOptions * inputOptions, float inputGamma, float outputGamma); +NVTT_API void nvttSetInputOptionsWrapMode(NvttInputOptions * inputOptions, NvttWrapMode mode); +NVTT_API void nvttSetInputOptionsMipmapping(NvttInputOptions * inputOptions, NvttBoolean generateMipmaps, NvttMipmapFilter filter, int maxLevel); +NVTT_API void nvttSetInputOptionsKaiserParameters(NvttInputOptions * inputOptions, float width, float alpha, float stretch); +NVTT_API void nvttSetInputOptionsNormalMap(NvttInputOptions * inputOptions, NvttBoolean b); +NVTT_API void nvttSetInputOptionsConvertToNormalMap(NvttInputOptions * inputOptions, NvttBoolean convert); +NVTT_API void nvttSetInputOptionsHeightEvaluation(NvttInputOptions * inputOptions, float redScale, float greenScale, float blueScale, float alphaScale); +NVTT_API void nvttSetInputOptionsNormalFilter(NvttInputOptions * inputOptions, float small, float medium, float big, float large); +NVTT_API void nvttSetInputOptionsNormalizeMipmaps(NvttInputOptions * inputOptions, NvttBoolean b); +NVTT_API void nvttSetInputOptionsColorTransform(NvttInputOptions * inputOptions, NvttColorTransform t); +NVTT_API void nvttSetInputOptionsLinearTransform(NvttInputOptions * inputOptions, int channel, float w0, float w1, float w2, float w3); +NVTT_API void nvttSetInputOptionsMaxExtents(NvttInputOptions * inputOptions, int dim); +NVTT_API void nvttSetInputOptionsRoundMode(NvttInputOptions * inputOptions, NvttRoundMode mode); // Compression Options @@ -116,14 +200,20 @@ NVTT_API void nvttDestroyCompressionOptions(NvttCompressionOptions * compression NVTT_API void nvttSetCompressionOptionsFormat(NvttCompressionOptions * compressionOptions, NvttFormat format); NVTT_API void nvttSetCompressionOptionsQuality(NvttCompressionOptions * compressionOptions, NvttQuality quality); +NVTT_API void nvttSetCompressionOptionsColorWeights(NvttCompressionOptions * compressionOptions, float red, float green, float blue, float alpha); +NVTT_API void nvttEnableCompressionOptionsCudaCompression(NvttCompressionOptions * compressionOptions, NvttBoolean enable); NVTT_API void nvttSetCompressionOptionsPixelFormat(NvttCompressionOptions * compressionOptions, unsigned int bitcount, unsigned int rmask, unsigned int gmask, unsigned int bmask, unsigned int amask); - +NVTT_API void nvttSetCompressionOptionsQuantization(NvttCompressionOptions * compressionOptions, NvttBoolean colorDithering, NvttBoolean alphaDithering, NvttBoolean binaryAlpha, int alphaThreshold); + // Output Options NVTT_API NvttOutputOptions * nvttCreateOutputOptions(); NVTT_API void nvttDestroyOutputOptions(NvttOutputOptions * outputOptions); NVTT_API void nvttSetOutputOptionsFileName(NvttOutputOptions * outputOptions, const char * fileName); +NVTT_API void nvttSetOutputOptionsOutputHeader(NvttOutputOptions * outputOptions, NvttBoolean b); +//NVTT_API void nvttSetOutputOptionsErrorHandler(NvttOutputOptions * outputOptions, nvttErrorHandler errorHandler); +//NVTT_API void nvttSetOutputOptionsOutputHandler(NvttOutputOptions * outputOptions, nvttOutputHandler outputHandler, nvttImageHandler imageHandler); // Main entrypoint of the compression library. @@ -132,6 +222,8 @@ NVTT_API NvttBoolean nvttCompress(NvttInputOptions * inputOptions, NvttCompressi // Estimate the size of compressing the input with the given options. NVTT_API int nvttEstimateSize(NvttInputOptions * inputOptions, NvttCompressionOptions * compressionOptions); +// Return string for the given error. +NVTT_API const char * nvttErrorString(NvttError e); #ifdef __cplusplus } // extern "C"