| 1 | // Copyright (c) 2009-2011 Ignacio Castano <castano@gmail.com>
|
| 2 | // Copyright (c) 2007-2009 NVIDIA Corporation -- Ignacio Castano <icastano@nvidia.com>
|
| 3 | //
|
| 4 | // Permission is hereby granted, free of charge, to any person
|
| 5 | // obtaining a copy of this software and associated documentation
|
| 6 | // files (the "Software"), to deal in the Software without
|
| 7 | // restriction, including without limitation the rights to use,
|
| 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 9 | // copies of the Software, and to permit persons to whom the
|
| 10 | // Software is furnished to do so, subject to the following
|
| 11 | // conditions:
|
| 12 | //
|
| 13 | // The above copyright notice and this permission notice shall be
|
| 14 | // included in all copies or substantial portions of the Software.
|
| 15 | //
|
| 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
| 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
| 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
| 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
| 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
| 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
| 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
| 23 | // OTHER DEALINGS IN THE SOFTWARE.
|
| 24 |
|
| 25 | #pragma once
|
| 26 | #ifndef NVTT_H
|
| 27 | #define NVTT_H
|
| 28 |
|
| 29 | // Function linkage
|
| 30 | #if NVTT_SHARED
|
| 31 |
|
| 32 | #if defined _WIN32 || defined WIN32 || defined __NT__ || defined __WIN32__ || defined __MINGW32__
|
| 33 | # ifdef NVTT_EXPORTS
|
| 34 | # define NVTT_API __declspec(dllexport)
|
| 35 | # else
|
| 36 | # define NVTT_API __declspec(dllimport)
|
| 37 | # endif
|
| 38 | #endif
|
| 39 |
|
| 40 | #if defined __GNUC__ >= 4
|
| 41 | # ifdef NVTT_EXPORTS
|
| 42 | # define NVTT_API __attribute__((visibility("default")))
|
| 43 | # endif
|
| 44 | #endif
|
| 45 |
|
| 46 | #endif // NVTT_SHARED
|
| 47 |
|
| 48 | #if !defined NVTT_API
|
| 49 | # define NVTT_API
|
| 50 | #endif
|
| 51 |
|
| 52 | #define NVTT_VERSION 20100
|
| 53 |
|
| 54 | #define NVTT_FORBID_COPY(Class) \
|
| 55 | private: \
|
| 56 | Class(const Class &); \
|
| 57 | void operator=(const Class &); \
|
| 58 | public:
|
| 59 |
|
| 60 | #define NVTT_DECLARE_PIMPL(Class) \
|
| 61 | public: \
|
| 62 | struct Private; \
|
| 63 | Private & m
|
| 64 |
|
| 65 |
|
| 66 | // Public interface.
|
| 67 | namespace nvtt
|
| 68 | {
|
| 69 | // Forward declarations.
|
| 70 | struct Surface;
|
| 71 | struct CubeSurface;
|
| 72 |
|
| 73 |
|
| 74 | // Supported block-compression formats.
|
| 75 | // @@ I wish I had distinguished between "formats" and compressors.
|
| 76 | // That is:
|
| 77 | // - 'DXT1' is a format 'DXT1a' and 'DXT1n' are DXT1 compressors.
|
| 78 | // - 'DXT3' is a format 'DXT3n' is a DXT3 compressor.
|
| 79 | // Having multiple enums for the same ids only creates confusion. Clean this up.
|
| 80 | enum Format
|
| 81 | {
|
| 82 | // No block-compression (linear).
|
| 83 | Format_RGB,
|
| 84 | Format_RGBA = Format_RGB,
|
| 85 |
|
| 86 | // DX9 formats.
|
| 87 | Format_DXT1,
|
| 88 | Format_DXT1a, // DXT1 with binary alpha.
|
| 89 | Format_DXT3,
|
| 90 | Format_DXT5,
|
| 91 | Format_DXT5n, // Compressed HILO: R=1, G=y, B=0, A=x
|
| 92 |
|
| 93 | // DX10 formats.
|
| 94 | Format_BC1 = Format_DXT1,
|
| 95 | Format_BC1a = Format_DXT1a,
|
| 96 | Format_BC2 = Format_DXT3,
|
| 97 | Format_BC3 = Format_DXT5,
|
| 98 | Format_BC3n = Format_DXT5n,
|
| 99 | Format_BC4, // ATI1
|
| 100 | Format_BC5, // 3DC, ATI2
|
| 101 |
|
| 102 | Format_DXT1n, // Not supported.
|
| 103 | Format_CTX1, // Not supported.
|
| 104 |
|
| 105 | Format_BC6,
|
| 106 | Format_BC7,
|
| 107 |
|
| 108 | Format_BC3_RGBM, //
|
| 109 |
|
| 110 | Format_Count
|
| 111 | };
|
| 112 |
|
| 113 | // Pixel types. These basically indicate how the output should be interpreted, but do not have any influence over the input. They are only relevant in RGBA mode.
|
| 114 | enum PixelType
|
| 115 | {
|
| 116 | PixelType_UnsignedNorm = 0,
|
| 117 | PixelType_SignedNorm = 1, // Not supported yet.
|
| 118 | PixelType_UnsignedInt = 2, // Not supported yet.
|
| 119 | PixelType_SignedInt = 3, // Not supported yet.
|
| 120 | PixelType_Float = 4,
|
| 121 | PixelType_UnsignedFloat = 5,
|
| 122 | PixelType_SharedExp = 6, // Shared exponent.
|
| 123 | };
|
| 124 |
|
| 125 | // Quality modes.
|
| 126 | enum Quality
|
| 127 | {
|
| 128 | Quality_Fastest,
|
| 129 | Quality_Normal,
|
| 130 | Quality_Production,
|
| 131 | Quality_Highest,
|
| 132 | };
|
| 133 |
|
| 134 | // DXT decoder.
|
| 135 | enum Decoder
|
| 136 | {
|
| 137 | Decoder_D3D10,
|
| 138 | Decoder_D3D9,
|
| 139 | Decoder_NV5x,
|
| 140 | //Decoder_RSX, // To take advantage of DXT5 bug.
|
| 141 | };
|
| 142 |
|
| 143 |
|
| 144 | // Compression options. This class describes the desired compression format and other compression settings.
|
| 145 | struct CompressionOptions
|
| 146 | {
|
| 147 | NVTT_FORBID_COPY(CompressionOptions);
|
| 148 | NVTT_DECLARE_PIMPL(CompressionOptions);
|
| 149 |
|
| 150 | NVTT_API CompressionOptions();
|
| 151 | NVTT_API ~CompressionOptions();
|
| 152 |
|
| 153 | NVTT_API void reset();
|
| 154 |
|
| 155 | NVTT_API void setFormat(Format format);
|
| 156 | NVTT_API void setQuality(Quality quality);
|
| 157 | NVTT_API void setColorWeights(float red, float green, float blue, float alpha = 1.0f);
|
| 158 |
|
| 159 | NVTT_API void setExternalCompressor(const char * name);
|
| 160 |
|
| 161 | // Set color mask to describe the RGB/RGBA format.
|
| 162 | NVTT_API void setPixelFormat(unsigned int bitcount, unsigned int rmask, unsigned int gmask, unsigned int bmask, unsigned int amask);
|
| 163 | NVTT_API void setPixelFormat(unsigned char rsize, unsigned char gsize, unsigned char bsize, unsigned char asize);
|
| 164 |
|
| 165 | NVTT_API void setPixelType(PixelType pixelType);
|
| 166 |
|
| 167 | NVTT_API void setPitchAlignment(int pitchAlignment);
|
| 168 |
|
| 169 | // @@ I wish this wasn't part of the compression options. Quantization is applied before compression. We don't have compressors with error diffusion.
|
| 170 | // @@ These options are only taken into account when using the InputOptions API.
|
| 171 | NVTT_API void setQuantization(bool colorDithering, bool alphaDithering, bool binaryAlpha, int alphaThreshold = 127);
|
| 172 |
|
| 173 | NVTT_API void setTargetDecoder(Decoder decoder);
|
| 174 |
|
| 175 | // Translate to and from D3D formats.
|
| 176 | NVTT_API unsigned int d3d9Format() const;
|
| 177 | //NVTT_API bool setD3D9Format(unsigned int format);
|
| 178 | //NVTT_API unsigned int dxgiFormat() const;
|
| 179 | //NVTT_API bool setDxgiFormat(unsigned int format);
|
| 180 | };
|
| 181 |
|
| 182 | /*
|
| 183 | // DXGI_FORMAT_R16G16_FLOAT
|
| 184 | compressionOptions.setPixelType(PixelType_Float);
|
| 185 | compressionOptions.setPixelFormat2(16, 16, 0, 0);
|
| 186 |
|
| 187 | // DXGI_FORMAT_R32G32B32A32_FLOAT
|
| 188 | compressionOptions.setPixelType(PixelType_Float);
|
| 189 | compressionOptions.setPixelFormat2(32, 32, 32, 32);
|
| 190 | */
|
| 191 |
|
| 192 |
|
| 193 | // Wrap modes.
|
| 194 | enum WrapMode
|
| 195 | {
|
| 196 | WrapMode_Clamp,
|
| 197 | WrapMode_Repeat,
|
| 198 | WrapMode_Mirror,
|
| 199 | };
|
| 200 |
|
| 201 | // Texture types.
|
| 202 | enum TextureType
|
| 203 | {
|
| 204 | TextureType_2D,
|
| 205 | TextureType_Cube,
|
| 206 | TextureType_3D,
|
| 207 | TextureType_Array,
|
| 208 | };
|
| 209 |
|
| 210 | // Input formats.
|
| 211 | enum InputFormat
|
| 212 | {
|
| 213 | InputFormat_BGRA_8UB, // Normalized [0, 1] 8 bit fixed point.
|
| 214 | InputFormat_RGBA_16F, // 16 bit floating point.
|
| 215 | InputFormat_RGBA_32F, // 32 bit floating point.
|
| 216 | InputFormat_R_32F, // Single channel 32 bit floating point.
|
| 217 | };
|
| 218 |
|
| 219 | // Mipmap downsampling filters.
|
| 220 | enum MipmapFilter
|
| 221 | {
|
| 222 | MipmapFilter_Box, // Box filter is quite good and very fast.
|
| 223 | MipmapFilter_Triangle, // Triangle filter blurs the results too much, but that might be what you want.
|
| 224 | MipmapFilter_Kaiser, // Kaiser-windowed Sinc filter is the best downsampling filter.
|
| 225 | };
|
| 226 |
|
| 227 | // Texture resize filters.
|
| 228 | enum ResizeFilter
|
| 229 | {
|
| 230 | ResizeFilter_Box,
|
| 231 | ResizeFilter_Triangle,
|
| 232 | ResizeFilter_Kaiser,
|
| 233 | ResizeFilter_Mitchell,
|
| 234 | };
|
| 235 |
|
| 236 | // Extents rounding mode.
|
| 237 | enum RoundMode
|
| 238 | {
|
| 239 | RoundMode_None,
|
| 240 | RoundMode_ToNextPowerOfTwo,
|
| 241 | RoundMode_ToNearestPowerOfTwo,
|
| 242 | RoundMode_ToPreviousPowerOfTwo,
|
| 243 | RoundMode_ToNextMultipleOfFour, // (New in NVTT 2.1)
|
| 244 | RoundMode_ToNearestMultipleOfFour, // (New in NVTT 2.1)
|
| 245 | RoundMode_ToPreviousMultipleOfFour, // (New in NVTT 2.1)
|
| 246 | };
|
| 247 |
|
| 248 | // Alpha mode.
|
| 249 | enum AlphaMode
|
| 250 | {
|
| 251 | AlphaMode_None,
|
| 252 | AlphaMode_Transparency,
|
| 253 | AlphaMode_Premultiplied,
|
| 254 | };
|
| 255 |
|
| 256 | // Input options. Specify format and layout of the input texture. (Deprecated in NVTT 2.1)
|
| 257 | struct InputOptions
|
| 258 | {
|
| 259 | NVTT_FORBID_COPY(InputOptions);
|
| 260 | NVTT_DECLARE_PIMPL(InputOptions);
|
| 261 |
|
| 262 | NVTT_API InputOptions();
|
| 263 | NVTT_API ~InputOptions();
|
| 264 |
|
| 265 | // Set default options.
|
| 266 | NVTT_API void reset();
|
| 267 |
|
| 268 | // Setup input layout.
|
| 269 | NVTT_API void setTextureLayout(TextureType type, int w, int h, int d = 1, int arraySize = 1);
|
| 270 | NVTT_API void resetTextureLayout();
|
| 271 |
|
| 272 | // Set mipmap data. Copies the data.
|
| 273 | NVTT_API bool setMipmapData(const void * data, int w, int h, int d = 1, int face = 0, int mipmap = 0);
|
| 274 |
|
| 275 | // Describe the format of the input.
|
| 276 | NVTT_API void setFormat(InputFormat format);
|
| 277 |
|
| 278 | // Set the way the input alpha channel is interpreted. @@ Not implemented!
|
| 279 | NVTT_API void setAlphaMode(AlphaMode alphaMode);
|
| 280 |
|
| 281 | // Set gamma settings.
|
| 282 | NVTT_API void setGamma(float inputGamma, float outputGamma);
|
| 283 |
|
| 284 | // Set texture wrapping mode.
|
| 285 | NVTT_API void setWrapMode(WrapMode mode);
|
| 286 |
|
| 287 | // Set mipmapping options.
|
| 288 | NVTT_API void setMipmapFilter(MipmapFilter filter);
|
| 289 | NVTT_API void setMipmapGeneration(bool enabled, int maxLevel = -1);
|
| 290 | NVTT_API void setKaiserParameters(float width, float alpha, float stretch);
|
| 291 |
|
| 292 | // Set normal map options.
|
| 293 | NVTT_API void setNormalMap(bool b);
|
| 294 | NVTT_API void setConvertToNormalMap(bool convert);
|
| 295 | NVTT_API void setHeightEvaluation(float redScale, float greenScale, float blueScale, float alphaScale);
|
| 296 | NVTT_API void setNormalFilter(float sm, float medium, float big, float large);
|
| 297 | NVTT_API void setNormalizeMipmaps(bool b);
|
| 298 |
|
| 299 | // Set resizing options.
|
| 300 | NVTT_API void setMaxExtents(int d);
|
| 301 | NVTT_API void setRoundMode(RoundMode mode);
|
| 302 | };
|
| 303 |
|
| 304 |
|
| 305 | // Output handler.
|
| 306 | struct OutputHandler
|
| 307 | {
|
| 308 | virtual ~OutputHandler() {}
|
| 309 |
|
| 310 | // Indicate the start of a new compressed image that's part of the final texture.
|
| 311 | virtual void beginImage(int size, int width, int height, int depth, int face, int miplevel) = 0;
|
| 312 |
|
| 313 | // Output data. Compressed data is output as soon as it's generated to minimize memory allocations.
|
| 314 | virtual bool writeData(const void * data, int size) = 0;
|
| 315 |
|
| 316 | // Indicate the end of the compressed image. (New in NVTT 2.1)
|
| 317 | virtual void endImage() = 0;
|
| 318 | };
|
| 319 |
|
| 320 | // Error codes.
|
| 321 | enum Error
|
| 322 | {
|
| 323 | Error_Unknown,
|
| 324 | Error_InvalidInput,
|
| 325 | Error_UnsupportedFeature,
|
| 326 | Error_CudaError,
|
| 327 | Error_FileOpen,
|
| 328 | Error_FileWrite,
|
| 329 | Error_UnsupportedOutputFormat,
|
| 330 | Error_Count
|
| 331 | };
|
| 332 |
|
| 333 | // Error handler.
|
| 334 | struct ErrorHandler
|
| 335 | {
|
| 336 | virtual ~ErrorHandler() {}
|
| 337 |
|
| 338 | // Signal error.
|
| 339 | virtual void error(Error e) = 0;
|
| 340 | };
|
| 341 |
|
| 342 | // Container.
|
| 343 | enum Container
|
| 344 | {
|
| 345 | Container_DDS,
|
| 346 | Container_DDS10,
|
| 347 | // Container_KTX, // Khronos Texture: http://www.khronos.org/opengles/sdk/tools/KTX/
|
| 348 | // Container_VTF, // Valve Texture Format: http://developer.valvesoftware.com/wiki/Valve_Texture_Format
|
| 349 | };
|
| 350 |
|
| 351 |
|
| 352 | // Output Options. This class holds pointers to the interfaces that are used to report the output of
|
| 353 | // the compressor to the user.
|
| 354 | struct OutputOptions
|
| 355 | {
|
| 356 | NVTT_FORBID_COPY(OutputOptions);
|
| 357 | NVTT_DECLARE_PIMPL(OutputOptions);
|
| 358 |
|
| 359 | NVTT_API OutputOptions();
|
| 360 | NVTT_API ~OutputOptions();
|
| 361 |
|
| 362 | // Set default options.
|
| 363 | NVTT_API void reset();
|
| 364 |
|
| 365 | NVTT_API void setFileName(const char * fileName);
|
| 366 | NVTT_API void setFileHandle(void * fp);
|
| 367 |
|
| 368 | NVTT_API void setOutputHandler(OutputHandler * outputHandler);
|
| 369 | NVTT_API void setErrorHandler(ErrorHandler * errorHandler);
|
| 370 |
|
| 371 | NVTT_API void (bool );
|
| 372 | NVTT_API void setContainer(Container container);
|
| 373 | NVTT_API void setUserVersion(int version);
|
| 374 | NVTT_API void setSrgbFlag(bool b);
|
| 375 | };
|
| 376 |
|
| 377 | // (New in NVTT 2.1)
|
| 378 | typedef void Task(void * context, int id);
|
| 379 |
|
| 380 | // (New in NVTT 2.1)
|
| 381 | struct TaskDispatcher
|
| 382 | {
|
| 383 | virtual ~TaskDispatcher() {}
|
| 384 |
|
| 385 | virtual void dispatch(Task * task, void * context, int count) = 0;
|
| 386 | };
|
| 387 |
|
| 388 | // Context.
|
| 389 | struct Compressor
|
| 390 | {
|
| 391 | NVTT_FORBID_COPY(Compressor);
|
| 392 | NVTT_DECLARE_PIMPL(Compressor);
|
| 393 |
|
| 394 | NVTT_API Compressor();
|
| 395 | NVTT_API ~Compressor();
|
| 396 |
|
| 397 | // Context settings.
|
| 398 | NVTT_API void enableCudaAcceleration(bool enable);
|
| 399 | NVTT_API bool isCudaAccelerationEnabled() const;
|
| 400 | NVTT_API void setTaskDispatcher(TaskDispatcher * disp); // (New in NVTT 2.1)
|
| 401 |
|
| 402 | // InputOptions API.
|
| 403 | NVTT_API bool process(const InputOptions & inputOptions, const CompressionOptions & compressionOptions, const OutputOptions & outputOptions) const;
|
| 404 | NVTT_API int estimateSize(const InputOptions & inputOptions, const CompressionOptions & compressionOptions) const;
|
| 405 |
|
| 406 | // Surface API. (New in NVTT 2.1)
|
| 407 | NVTT_API bool (const Surface & img, int mipmapCount, const CompressionOptions & compressionOptions, const OutputOptions & outputOptions) const;
|
| 408 | NVTT_API bool compress(const Surface & img, int face, int mipmap, const CompressionOptions & compressionOptions, const OutputOptions & outputOptions) const;
|
| 409 | NVTT_API int estimateSize(const Surface & img, int mipmapCount, const CompressionOptions & compressionOptions) const;
|
| 410 |
|
| 411 | // CubeSurface API. (New in NVTT 2.1)
|
| 412 | NVTT_API bool (const CubeSurface & cube, int mipmapCount, const CompressionOptions & compressionOptions, const OutputOptions & outputOptions) const;
|
| 413 | NVTT_API bool compress(const CubeSurface & cube, int mipmap, const CompressionOptions & compressionOptions, const OutputOptions & outputOptions) const;
|
| 414 | NVTT_API int estimateSize(const CubeSurface & cube, int mipmapCount, const CompressionOptions & compressionOptions) const;
|
| 415 |
|
| 416 | // Raw API. (New in NVTT 2.1)
|
| 417 | NVTT_API bool (TextureType type, int w, int h, int d, int arraySize, int mipmapCount, bool isNormalMap, const CompressionOptions & compressionOptions, const OutputOptions & outputOptions) const;
|
| 418 | NVTT_API bool compress(int w, int h, int d, int face, int mipmap, const float * rgba, const CompressionOptions & compressionOptions, const OutputOptions & outputOptions) const;
|
| 419 | NVTT_API int estimateSize(int w, int h, int d, int mipmapCount, const CompressionOptions & compressionOptions) const;
|
| 420 | };
|
| 421 |
|
| 422 | // "Compressor" is deprecated. This should have been called "Context"
|
| 423 | typedef Compressor Context;
|
| 424 |
|
| 425 | // (New in NVTT 2.1)
|
| 426 | enum NormalTransform {
|
| 427 | NormalTransform_Orthographic,
|
| 428 | NormalTransform_Stereographic,
|
| 429 | NormalTransform_Paraboloid,
|
| 430 | NormalTransform_Quartic
|
| 431 | //NormalTransform_DualParaboloid,
|
| 432 | };
|
| 433 |
|
| 434 | // (New in NVTT 2.1)
|
| 435 | enum ToneMapper {
|
| 436 | ToneMapper_Linear,
|
| 437 | ToneMapper_Reindhart,
|
| 438 | ToneMapper_Halo,
|
| 439 | ToneMapper_Lightmap,
|
| 440 | };
|
| 441 |
|
| 442 |
|
| 443 | // A surface is one level of a 2D or 3D texture. (New in NVTT 2.1)
|
| 444 | // @@ It would be nice to add support for texture borders for correct resizing of tiled textures and constrained DXT compression.
|
| 445 | struct Surface
|
| 446 | {
|
| 447 | NVTT_API Surface();
|
| 448 | NVTT_API Surface(const Surface & img);
|
| 449 | NVTT_API ~Surface();
|
| 450 |
|
| 451 | NVTT_API void operator=(const Surface & img);
|
| 452 |
|
| 453 | // Texture parameters.
|
| 454 | NVTT_API void setWrapMode(WrapMode mode);
|
| 455 | NVTT_API void setAlphaMode(AlphaMode alphaMode);
|
| 456 | NVTT_API void setNormalMap(bool isNormalMap);
|
| 457 |
|
| 458 | // Queries.
|
| 459 | NVTT_API bool isNull() const;
|
| 460 | NVTT_API int width() const;
|
| 461 | NVTT_API int height() const;
|
| 462 | NVTT_API int depth() const;
|
| 463 | NVTT_API TextureType type() const;
|
| 464 | NVTT_API WrapMode wrapMode() const;
|
| 465 | NVTT_API AlphaMode alphaMode() const;
|
| 466 | NVTT_API bool isNormalMap() const;
|
| 467 | NVTT_API int countMipmaps() const;
|
| 468 | NVTT_API int countMipmaps(int min_size) const;
|
| 469 | NVTT_API float alphaTestCoverage(float alphaRef = 0.5, int alpha_channel = 3) const;
|
| 470 | NVTT_API float average(int channel, int alpha_channel = -1, float gamma = 2.2f) const;
|
| 471 | NVTT_API const float * data() const;
|
| 472 | NVTT_API const float * channel(int i) const;
|
| 473 | NVTT_API void histogram(int channel, float rangeMin, float rangeMax, int binCount, int * binPtr) const;
|
| 474 | NVTT_API void range(int channel, float * rangeMin, float * rangeMax, int alpha_channel = -1, float alpha_ref = 0.f) const;
|
| 475 |
|
| 476 | // Texture data.
|
| 477 | NVTT_API bool load(const char * fileName, bool * hasAlpha = 0);
|
| 478 | NVTT_API bool save(const char * fileName, bool hasAlpha = 0, bool hdr = 0) const;
|
| 479 | NVTT_API bool setImage(int w, int h, int d);
|
| 480 | NVTT_API bool setImage(InputFormat format, int w, int h, int d, const void * data);
|
| 481 | NVTT_API bool setImage(InputFormat format, int w, int h, int d, const void * r, const void * g, const void * b, const void * a);
|
| 482 | NVTT_API bool setImage2D(Format format, Decoder decoder, int w, int h, const void * data);
|
| 483 |
|
| 484 | // Resizing methods.
|
| 485 | NVTT_API void resize(int w, int h, int d, ResizeFilter filter);
|
| 486 | NVTT_API void resize(int w, int h, int d, ResizeFilter filter, float filterWidth, const float * params = 0);
|
| 487 | NVTT_API void resize(int maxExtent, RoundMode mode, ResizeFilter filter);
|
| 488 | NVTT_API void resize(int maxExtent, RoundMode mode, ResizeFilter filter, float filterWidth, const float * params = 0);
|
| 489 | NVTT_API void resize_make_square(int maxExtent, RoundMode roundMode, ResizeFilter filter);
|
| 490 |
|
| 491 | NVTT_API bool buildNextMipmap(MipmapFilter filter, int min_size = 1);
|
| 492 | NVTT_API bool buildNextMipmap(MipmapFilter filter, float filterWidth, const float * params = 0, int min_size = 1);
|
| 493 | NVTT_API bool buildNextMipmapSolidColor(const float * const color_components);
|
| 494 | NVTT_API void canvasSize(int w, int h, int d);
|
| 495 | // associated to resizing:
|
| 496 | NVTT_API bool canMakeNextMipmap(int min_size = 1);
|
| 497 |
|
| 498 | // Color transforms.
|
| 499 | NVTT_API void toLinear(float gamma);
|
| 500 | NVTT_API void toGamma(float gamma);
|
| 501 | NVTT_API void toLinear(int channel, float gamma);
|
| 502 | NVTT_API void toGamma(int channel, float gamma);
|
| 503 | NVTT_API void toSrgb();
|
| 504 | NVTT_API void toLinearFromSrgb();
|
| 505 | NVTT_API void toXenonSrgb();
|
| 506 | NVTT_API void transform(const float w0[4], const float w1[4], const float w2[4], const float w3[4], const float offset[4]);
|
| 507 | NVTT_API void swizzle(int r, int g, int b, int a);
|
| 508 | NVTT_API void scaleBias(int channel, float scale, float bias);
|
| 509 | NVTT_API void clamp(int channel, float low = 0.0f, float high = 1.0f);
|
| 510 | NVTT_API void blend(float r, float g, float b, float a, float t);
|
| 511 | NVTT_API void premultiplyAlpha();
|
| 512 | NVTT_API void toGreyScale(float redScale, float greenScale, float blueScale, float alphaScale);
|
| 513 | NVTT_API void setBorder(float r, float g, float b, float a);
|
| 514 | NVTT_API void fill(float r, float g, float b, float a);
|
| 515 | NVTT_API void scaleAlphaToCoverage(float coverage, float alphaRef = 0.5f, int alpha_channel = 3);
|
| 516 | NVTT_API void toRGBM(float range = 1.0f, float threshold = 0.25f);
|
| 517 | NVTT_API void fromRGBM(float range = 1.0f, float threshold = 0.25f);
|
| 518 | NVTT_API void toLM(float range = 1.0f, float threshold = 0.0f);
|
| 519 | NVTT_API void toRGBE(int mantissaBits, int exponentBits);
|
| 520 | NVTT_API void fromRGBE(int mantissaBits, int exponentBits);
|
| 521 | NVTT_API void toYCoCg();
|
| 522 | NVTT_API void blockScaleCoCg(int bits = 5, float threshold = 0.0f);
|
| 523 | NVTT_API void fromYCoCg();
|
| 524 | NVTT_API void toLUVW(float range = 1.0f);
|
| 525 | NVTT_API void fromLUVW(float range = 1.0f);
|
| 526 | NVTT_API void abs(int channel);
|
| 527 | NVTT_API void convolve(int channel, int kernelSize, float * kernelData);
|
| 528 | NVTT_API void toLogScale(int channel, float base);
|
| 529 | NVTT_API void fromLogScale(int channel, float base);
|
| 530 | NVTT_API void setAtlasBorder(int w, int h, float r, float g, float b, float a);
|
| 531 |
|
| 532 | NVTT_API void toneMap(ToneMapper tm, float * parameters);
|
| 533 |
|
| 534 | //NVTT_API void blockLuminanceScale(float scale);
|
| 535 |
|
| 536 | // Color quantization.
|
| 537 | NVTT_API void binarize(int channel, float threshold, bool dither);
|
| 538 | NVTT_API void quantize(int channel, int bits, bool exactEndPoints, bool dither);
|
| 539 |
|
| 540 | // Normal map transforms.
|
| 541 | NVTT_API void toNormalMap(float sm, float medium, float big, float large);
|
| 542 | NVTT_API void normalizeNormalMap();
|
| 543 | NVTT_API void transformNormals(NormalTransform xform);
|
| 544 | NVTT_API void reconstructNormals(NormalTransform xform);
|
| 545 | NVTT_API void toCleanNormalMap();
|
| 546 | NVTT_API void packNormals(float scale = 0.5f, float bias = 0.5f); // [-1,1] -> [ 0,1]
|
| 547 | NVTT_API void expandNormals(float scale = 2.0f, float bias = -1.0f); // [ 0,1] -> [-1,1]
|
| 548 | NVTT_API Surface createToksvigMap(float power) const;
|
| 549 | NVTT_API Surface createCleanMap() const;
|
| 550 |
|
| 551 | // Geometric transforms.
|
| 552 | NVTT_API void flipX();
|
| 553 | NVTT_API void flipY();
|
| 554 | NVTT_API void flipZ();
|
| 555 | NVTT_API Surface createSubImage(int x0, int x1, int y0, int y1, int z0, int z1) const;
|
| 556 |
|
| 557 | // Copy image data.
|
| 558 | NVTT_API bool copyChannel(const Surface & srcImage, int srcChannel);
|
| 559 | NVTT_API bool copyChannel(const Surface & srcImage, int srcChannel, int dstChannel);
|
| 560 |
|
| 561 | NVTT_API bool addChannel(const Surface & img, int srcChannel, int dstChannel, float scale);
|
| 562 |
|
| 563 | NVTT_API bool copy(const Surface & src, int xsrc, int ysrc, int zsrc, int xsize, int ysize, int zsize, int xdst, int ydst, int zdst);
|
| 564 |
|
| 565 |
|
| 566 | //private:
|
| 567 | void detach();
|
| 568 |
|
| 569 | struct Private;
|
| 570 | Private * m;
|
| 571 | };
|
| 572 |
|
| 573 |
|
| 574 | // Cube layout formats. (New in NVTT 2.1)
|
| 575 | enum CubeLayout {
|
| 576 | CubeLayout_VerticalCross,
|
| 577 | CubeLayout_HorizontalCross,
|
| 578 | CubeLayout_Column,
|
| 579 | CubeLayout_Row,
|
| 580 | CubeLayout_LatitudeLongitude
|
| 581 | };
|
| 582 |
|
| 583 | // (New in NVTT 2.1)
|
| 584 | enum EdgeFixup {
|
| 585 | EdgeFixup_None,
|
| 586 | EdgeFixup_Stretch,
|
| 587 | EdgeFixup_Warp,
|
| 588 | EdgeFixup_Average,
|
| 589 | };
|
| 590 |
|
| 591 | // A CubeSurface is one level of a cube map texture. (New in NVTT 2.1)
|
| 592 | struct CubeSurface
|
| 593 | {
|
| 594 | NVTT_API CubeSurface();
|
| 595 | NVTT_API CubeSurface(const CubeSurface & img);
|
| 596 | NVTT_API ~CubeSurface();
|
| 597 |
|
| 598 | NVTT_API void operator=(const CubeSurface & img);
|
| 599 |
|
| 600 | // Queries.
|
| 601 | NVTT_API bool isNull() const;
|
| 602 | NVTT_API int edgeLength() const;
|
| 603 | NVTT_API int countMipmaps() const;
|
| 604 |
|
| 605 | // Texture data.
|
| 606 | NVTT_API bool load(const char * fileName, int mipmap);
|
| 607 | NVTT_API bool save(const char * fileName) const;
|
| 608 |
|
| 609 | NVTT_API Surface & face(int face);
|
| 610 | NVTT_API const Surface & face(int face) const;
|
| 611 |
|
| 612 | // Layout conversion. @@ Not implemented.
|
| 613 | NVTT_API void fold(const Surface & img, CubeLayout layout);
|
| 614 | NVTT_API Surface unfold(CubeLayout layout) const;
|
| 615 |
|
| 616 | // @@ Angular extent filtering.
|
| 617 |
|
| 618 | // @@ Add resizing methods.
|
| 619 |
|
| 620 | // @@ Add edge fixup methods.
|
| 621 |
|
| 622 | NVTT_API float average(int channel) const;
|
| 623 | NVTT_API void range(int channel, float * minimum_ptr, float * maximum_ptr) const;
|
| 624 | NVTT_API void clamp(int channel, float low = 0.0f, float high = 1.0f);
|
| 625 |
|
| 626 |
|
| 627 | // Filtering.
|
| 628 | NVTT_API CubeSurface irradianceFilter(int size, EdgeFixup fixupMethod) const;
|
| 629 | NVTT_API CubeSurface cosinePowerFilter(int size, float cosinePower, EdgeFixup fixupMethod) const;
|
| 630 |
|
| 631 | NVTT_API CubeSurface fastResample(int size, EdgeFixup fixupMethod) const;
|
| 632 |
|
| 633 |
|
| 634 | /*
|
| 635 | NVTT_API void resize(int w, int h, ResizeFilter filter);
|
| 636 | NVTT_API void resize(int w, int h, ResizeFilter filter, float filterWidth, const float * params = 0);
|
| 637 | NVTT_API void resize(int maxExtent, RoundMode mode, ResizeFilter filter);
|
| 638 | NVTT_API void resize(int maxExtent, RoundMode mode, ResizeFilter filter, float filterWidth, const float * params = 0);
|
| 639 | NVTT_API bool buildNextMipmap(MipmapFilter filter);
|
| 640 | NVTT_API bool buildNextMipmap(MipmapFilter filter, float filterWidth, const float * params = 0);
|
| 641 | */
|
| 642 |
|
| 643 | // Color transforms.
|
| 644 | NVTT_API void toLinear(float gamma);
|
| 645 | NVTT_API void toGamma(float gamma);
|
| 646 |
|
| 647 | //private:
|
| 648 | void detach();
|
| 649 |
|
| 650 | struct Private;
|
| 651 | Private * m;
|
| 652 | };
|
| 653 |
|
| 654 |
|
| 655 | // Return string for the given error code.
|
| 656 | NVTT_API const char * errorString(Error e);
|
| 657 |
|
| 658 | // Return NVTT version.
|
| 659 | NVTT_API unsigned int version();
|
| 660 |
|
| 661 | // Image comparison and error measurement functions. (New in NVTT 2.1)
|
| 662 | NVTT_API float rmsError(const Surface & reference, const Surface & img);
|
| 663 | NVTT_API float rmsAlphaError(const Surface & reference, const Surface & img);
|
| 664 | NVTT_API float cieLabError(const Surface & reference, const Surface & img);
|
| 665 | NVTT_API float angularError(const Surface & reference, const Surface & img);
|
| 666 | NVTT_API Surface diff(const Surface & reference, const Surface & img, float scale);
|
| 667 |
|
| 668 | NVTT_API float rmsToneMappedError(const Surface & reference, const Surface & img, float exposure);
|
| 669 |
|
| 670 |
|
| 671 | NVTT_API Surface histogram(const Surface & img, int width, int height);
|
| 672 | NVTT_API Surface histogram(const Surface & img, float minRange, float maxRange, int width, int height);
|
| 673 |
|
| 674 | } // nvtt namespace
|
| 675 |
|
| 676 | #endif // NVTT_H
|
| 677 | |