diff --git a/src/utils/xrDXT/DXT.cpp b/src/utils/xrDXT/DXT.cpp index 8dac777f125..336d0beb5b3 100644 --- a/src/utils/xrDXT/DXT.cpp +++ b/src/utils/xrDXT/DXT.cpp @@ -1,71 +1,6 @@ #include "stdafx.h" -#include "dxtlib.h" #include #include "Layers/xrRender/ETextureParams.h" -//#include "dds.h" - -//BOOL APIENTRY DllMain(HANDLE hModule, u32 ul_reason_for_call, LPVOID lpReserved) { return TRUE; } -static HFILE gFileOut; -static HFILE gFileIn; - -/*const u32 fcc_DXT1 = MAKEFOURCC('D', 'X', 'T', '1'); -const u32 fcc_DXT2 = MAKEFOURCC('D', 'X', 'T', '2'); -const u32 fcc_DXT3 = MAKEFOURCC('D', 'X', 'T', '3'); -const u32 fcc_DXT4 = MAKEFOURCC('D', 'X', 'T', '4'); -const u32 fcc_DXT5 = MAKEFOURCC('D', 'X', 'T', '5');*/ - -/*void __cdecl WriteDTXnFile(DWORD count, void* buffer, void* userData) -{ - if (count == sizeof(DDS_HEADER)) - { - DDS_HEADER* hdr = (DDS_HEADER*)buffer; - if (hdr->dwSize == count) - { - switch (hdr->ddspf.dwFourCC) - { - case fcc_DXT1: - case fcc_DXT2: - case fcc_DXT3: - case fcc_DXT4: - case fcc_DXT5: hdr->ddspf.dwRGBBitCount = 0; break; - } - } - } - _write(gFileOut, buffer, count); -}*/ - -class DDSWriter : public nvtt::OutputHandler -{ -public: - HFILE& file; - - DDSWriter(HFILE& file); - virtual void beginImage(int size, int width, int height, int depth, int face, int miplevel) override; - virtual bool writeData(const void* data, int size) override; -}; - -DDSWriter::DDSWriter(HFILE& file) : file(file) {} -void DDSWriter::beginImage(int size, int width, int height, int depth, int face, int miplevel) {} -bool DDSWriter::writeData(const void* data, int size) -{ - /*if (size == sizeof(DDS_HEADER)) - { - DDS_HEADER* hdr = (DDS_HEADER*)data; - if (hdr->dwSize == size) - { - switch (hdr->ddspf.dwFourCC) - { - case fcc_DXT1: - case fcc_DXT2: - case fcc_DXT3: - case fcc_DXT4: - case fcc_DXT5: hdr->ddspf.dwRGBBitCount = 0; break; - } - } - }*/ - _write(file, data, size); - return true; -} class DDSErrorHandler : public nvtt::ErrorHandler { @@ -75,29 +10,10 @@ class DDSErrorHandler : public nvtt::ErrorHandler void DDSErrorHandler::error(nvtt::Error e) { - const char* msg; - switch (e) - { - default: - case nvtt::Error_Unknown: msg = "Unknown error"; break; - case nvtt::Error_InvalidInput: msg = "Invalid input"; break; - case nvtt::Error_UnsupportedFeature: msg = "Unsupported feature"; break; - case nvtt::Error_CudaError: msg = "CUDA error"; break; - case nvtt::Error_FileOpen: msg = "File open error"; break; - case nvtt::Error_FileWrite: msg = "File write error"; break; - } - MessageBox(0, msg, "DXT compress error", MB_ICONERROR | MB_OK); + MessageBox(0, nvtt::errorString(e), "DXT compress error", MB_ICONERROR | MB_OK); } -/*void __cdecl ReadDTXnFile(DWORD count, void* buffer, void* userData) { _read(gFileIn, buffer, count); } -HRESULT WriteCompressedData(void* data, int miplevel, u32 size) -{ - _write(gFileOut, data, size); - FillMemory(data, size, 0xff); - return 0; -}*/ - -/*ENGINE_API*/ u32* Build32MipLevel(u32& _w, u32& _h, u32& _p, u32* pdwPixelSrc, STextureParams* fmt, float blend) +u32* Build32MipLevel(u32& _w, u32& _h, u32& _p, u32* pdwPixelSrc, STextureParams* fmt, float blend) { R_ASSERT(pdwPixelSrc); R_ASSERT(_w % 2 == 0); @@ -184,20 +100,11 @@ void FillRect(u8* data, u8* new_data, u32 offs, u32 pitch, u32 h, u32 full_pitch int DXTCompressImage(LPCSTR out_name, u8* raw_data, u32 w, u32 h, u32 pitch, STextureParams* fmt, u32 depth) { R_ASSERT(0 != w && 0 != h); - gFileOut = _open(out_name, _O_WRONLY | _O_BINARY | _O_CREAT | _O_TRUNC, _S_IWRITE); - if (gFileOut == -1) - { - fprintf(stderr, "Can't open output file %s\n", out_name); - return 0; - } bool result = false; nvtt::InputOptions inOpt; auto layout = fmt->type == STextureParams::ttCubeMap ? nvtt::TextureType_Cube : nvtt::TextureType_2D; inOpt.setTextureLayout(layout, w, h); - if (fmt->flags.is(STextureParams::flGenerateMipMaps)) - inOpt.setMipmapGeneration(true); - else - inOpt.setMipmapGeneration(false); + inOpt.setMipmapGeneration(fmt->flags.is(STextureParams::flGenerateMipMaps)); inOpt.setWrapMode(nvtt::WrapMode_Clamp); inOpt.setNormalMap(false); inOpt.setConvertToNormalMap(false); @@ -205,36 +112,33 @@ int DXTCompressImage(LPCSTR out_name, u8* raw_data, u32 w, u32 h, u32 pitch, STe inOpt.setNormalizeMipmaps(false); nvtt::CompressionOptions compOpt; compOpt.setQuality(nvtt::Quality_Highest); - compOpt.setQuantization( - fmt->flags.is(STextureParams::flDitherColor), false, fmt->flags.is(STextureParams::flBinaryAlpha)); + compOpt.setQuantization(fmt->flags.is(STextureParams::flDitherColor), false, fmt->flags.is(STextureParams::flBinaryAlpha)); switch (fmt->fmt) { - case STextureParams::tfDXT1: compOpt.setFormat(nvtt::Format_DXT1); break; + case STextureParams::tfDXT1: compOpt.setFormat(nvtt::Format_DXT1 ); break; case STextureParams::tfADXT1: compOpt.setFormat(nvtt::Format_DXT1a); break; - case STextureParams::tfDXT3: compOpt.setFormat(nvtt::Format_DXT3); break; - case STextureParams::tfDXT5: compOpt.setFormat(nvtt::Format_DXT5); break; - case STextureParams::tfRGB: compOpt.setFormat(nvtt::Format_RGB); break; - case STextureParams::tfRGBA: compOpt.setFormat(nvtt::Format_RGBA); break; + case STextureParams::tfDXT3: compOpt.setFormat(nvtt::Format_DXT3 ); break; + case STextureParams::tfDXT5: compOpt.setFormat(nvtt::Format_DXT5 ); break; + case STextureParams::tfRGB: compOpt.setFormat(nvtt::Format_RGB ); break; + case STextureParams::tfRGBA: compOpt.setFormat(nvtt::Format_RGBA ); break; } switch (fmt->mip_filter) { case STextureParams::kMIPFilterAdvanced: break; - case STextureParams::kMIPFilterBox: inOpt.setMipmapFilter(nvtt::MipmapFilter_Box); break; + case STextureParams::kMIPFilterBox: inOpt.setMipmapFilter(nvtt::MipmapFilter_Box ); break; case STextureParams::kMIPFilterTriangle: inOpt.setMipmapFilter(nvtt::MipmapFilter_Triangle); break; - case STextureParams::kMIPFilterKaiser: inOpt.setMipmapFilter(nvtt::MipmapFilter_Kaiser); break; + case STextureParams::kMIPFilterKaiser: inOpt.setMipmapFilter(nvtt::MipmapFilter_Kaiser ); break; } nvtt::OutputOptions outOpt; - DDSWriter writer(gFileOut); - outOpt.setOutputHandler(&writer); + outOpt.setFileName(out_name); DDSErrorHandler handler; outOpt.setErrorHandler(&handler); if (fmt->flags.is(STextureParams::flGenerateMipMaps) && STextureParams::kMIPFilterAdvanced == fmt->mip_filter) { inOpt.setMipmapGeneration(false); - u8* pImagePixels = 0; int numMipmaps = GetPowerOf2Plus1(__min(w, h)); u32 line_pitch = w * 2 * 4; - pImagePixels = xr_alloc(line_pitch * h); + u8* pImagePixels = xr_alloc(line_pitch * h); u32 w_offs = 0; u32 dwW = w; u32 dwH = h; @@ -255,28 +159,15 @@ int DXTCompressImage(LPCSTR out_name, u8* raw_data, u32 w, u32 h, u32 pitch, STe w_offs += dwP; } xr_free(pLastMip); - RGBAImage pImage(w * 2, h); - rgba_t* pixels = pImage.pixels(); - u8* pixel = pImagePixels; - for (u32 k = 0; k < w * 2 * h; k++, pixel += 4) - { - pixels[k].set(pixel[0], pixel[1], pixel[2], pixel[3]); - } - inOpt.setMipmapData(pixels, w, h); + inOpt.setMipmapData(pImagePixels, w, h); result = nvtt::Compressor().process(inOpt, compOpt, outOpt); xr_free(pImagePixels); } else { - RGBAImage pImage(w, h); - rgba_t* pixels = pImage.pixels(); - u8* pixel = raw_data; - for (u32 k = 0; k < w * h; k++, pixel += 4) - pixels[k].set(pixel[0], pixel[1], pixel[2], pixel[3]); - inOpt.setMipmapData(pixels, w, h); + inOpt.setMipmapData(raw_data, w, h); result = nvtt::Compressor().process(inOpt, compOpt, outOpt); } - _close(gFileOut); if (!result) { _unlink(out_name); @@ -285,11 +176,9 @@ int DXTCompressImage(LPCSTR out_name, u8* raw_data, u32 w, u32 h, u32 pitch, STe return 1; } -extern int DXTCompressBump( - LPCSTR out_name, u8* raw_data, u8* normal_map, u32 w, u32 h, u32 pitch, STextureParams* fmt, u32 depth); +extern int DXTCompressBump(LPCSTR out_name, u8* raw_data, u8* normal_map, u32 w, u32 h, u32 pitch, STextureParams* fmt, u32 depth); -extern "C" __declspec(dllexport) int __stdcall DXTCompress( - LPCSTR out_name, u8* raw_data, u8* normal_map, u32 w, u32 h, u32 pitch, STextureParams* fmt, u32 depth) +extern "C" __declspec(dllexport) int __stdcall DXTCompress(LPCSTR out_name, u8* raw_data, u8* normal_map, u32 w, u32 h, u32 pitch, STextureParams* fmt, u32 depth) { switch (fmt->type) { @@ -297,9 +186,7 @@ extern "C" __declspec(dllexport) int __stdcall DXTCompress( case STextureParams::ttCubeMap: case STextureParams::ttNormalMap: case STextureParams::ttTerrain: return DXTCompressImage(out_name, raw_data, w, h, pitch, fmt, depth); break; - case STextureParams::ttBumpMap: - return DXTCompressBump(out_name, raw_data, normal_map, w, h, pitch, fmt, depth); - break; + case STextureParams::ttBumpMap: return DXTCompressBump(out_name, raw_data, normal_map, w, h, pitch, fmt, depth); break; default: NODEFAULT; } return -1; diff --git a/src/utils/xrDXT/DXT.vcxproj b/src/utils/xrDXT/DXT.vcxproj index bccd2b4fc41..eebe98eb96f 100644 --- a/src/utils/xrDXT/DXT.vcxproj +++ b/src/utils/xrDXT/DXT.vcxproj @@ -132,17 +132,16 @@ + - - diff --git a/src/utils/xrDXT/DXT.vcxproj.filters b/src/utils/xrDXT/DXT.vcxproj.filters index 7333f44e23a..fc9ce091057 100644 --- a/src/utils/xrDXT/DXT.vcxproj.filters +++ b/src/utils/xrDXT/DXT.vcxproj.filters @@ -24,19 +24,16 @@ NormalMap - - - Convert - Shared + diff --git a/src/utils/xrDXT/StdAfx.h b/src/utils/xrDXT/StdAfx.h index cfaa08c3825..39b1726dc83 100644 --- a/src/utils/xrDXT/StdAfx.h +++ b/src/utils/xrDXT/StdAfx.h @@ -1,9 +1,6 @@ #pragma once -//#define ENGINE_API -//#define XR_EPROPS_API #define ECORE_API #include "Common/Common.hpp" #include "xrCore/xrCore.h" -#include diff --git a/src/utils/xrDXT/dds/nvdxt_options.h b/src/utils/xrDXT/dds/nvdxt_options.h deleted file mode 100644 index 6e57a10673f..00000000000 --- a/src/utils/xrDXT/dds/nvdxt_options.h +++ /dev/null @@ -1,582 +0,0 @@ -/**************************************************************************************** - - Copyright (C) NVIDIA Corporation 2003 - - TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THIS SOFTWARE IS PROVIDED - *AS IS* AND NVIDIA AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES, EITHER EXPRESS - OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY - AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL NVIDIA OR ITS SUPPLIERS - BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES - WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, - BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR ANY OTHER PECUNIARY LOSS) - ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF NVIDIA HAS - BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - -*****************************************************************************************/ -#pragma once - -#include -#include -#include - -inline char* GetDXTCVersion() { return "Version 8.30"; } -// max mip maps -#define MAX_MIP_MAPS 17 - -typedef unsigned char nvBoolean; // for photoshop scripting - -typedef struct nvNormalMap -{ -public: - // do not convert to a normal map - nvBoolean bEnableNormalMapConversion; - // minimum value the z value can attain in the x y z normal keeps normal point "upwards" - int minz; - // height multiplier - float scale; - // kernel used to create normal maps. Done this way to be compatible with plugins - nvNormalMapFilters filterKernel; - // method to convert color to height - nvHeightConversionMethods heightConversionMethod; - nvAlphaResult alphaResult; // what to do with the alpha channel when done - nvBoolean bWrap; - nvBoolean bInvertX; // flip the x direction - nvBoolean bInvertY; // flip the y direction - nvBoolean bInvertZ; // flip the z direction - nvBoolean bAddHeightMap; - nvBoolean bNormalMapSwapRGB; // swap color channels - - nvNormalMap() - { - bEnableNormalMapConversion = false; - minz = 0; - scale = 1; - filterKernel = kFilter3x3; - heightConversionMethod = kAverageRGB; - alphaResult = kAlphaUnchanged; - bWrap = false; - bInvertX = false; - bInvertY = false; - bInvertZ = false; - bAddHeightMap = false; - bNormalMapSwapRGB = false; - } -} nvNormalMap; - -class nvCompressionOptions -{ -public: - nvCompressionOptions() { SetDefaultOptions(); } - void SetDefaultOptions() - { - quality = kQualityProduction; - // in kQualityHighest mode, rms error above which will cause a long search for a better answer - rmsErrorSearchThreshold = 400; - rescaleImageType = kRescaleNone; - rescaleImageFilter = kMipFilterCubic; - scaleX = 1; - scaleY = 1; - bClamp = false; - clampX = 4096; - clampY = 4096; - bClampScale = false; - clampScaleX = 4096; - clampScaleY = 4096; - mipMapGeneration = kGenerateMipMaps; // dNoMipMaps, dUseExistingMipMaps, dGenerateMipMaps - numMipMapsToWrite = 0; // (number of mipmaps to write out) - mipFilterType = kMipFilterTriangle; // for MIP maps - bBinaryAlpha = false; // zero or one alpha channel - bRGBE = false; - bAlphaBorder = false; // make an alpha border - bAlphaBorderLeft = false; - bAlphaBorderRight = false; - bAlphaBorderTop = false; - bAlphaBorderBottom = false; - bBorder = false; // make a color border - borderColor32F.r = 0.0f; // color of border - borderColor32F.g = 0.0f; // color of border - borderColor32F.b = 0.0f; // color of border - borderColor32F.a = 0.0f; // alpha of border - bFadeColor = false; // fade color over MIP maps - bFadeAlpha = false; // fade alpha over MIP maps - fadeToColor32F.r = 0.0f; // color to fade to - fadeToColor32F.g = 0.0f; // color to fade to - fadeToColor32F.b = 0.0f; // color to fade to - fadeToColor32F.a = 0.0f; // alpha to fade to - fadeToDelay = 0; // start fading after 'n' MIP maps - fadeAmount32F = 0.15f; // percentage of color to fade in %15 - alphaThreshold32F = 0.5; // When Binary Alpha is selected, below this value, alpha is zero - bDitherColor = false; // enable dithering during 16 bit conversion - bDitherMip0 = false; // enable dithering during 16 bit conversion for each MIP level (after filtering) - bForceDXT1FourColors = false; // do not let DXT1 use 3 color representation - sharpenFilterType = kSharpenFilterNone; - bErrorDiffusion = false; - errorDiffusionWidth = 1; - weightType = kLuminanceWeighting; - bNormalizeTexels = false; - weight[0] = 0.3086f; // luminance conversion values - weight[1] = 0.6094f; - weight[2] = 0.0820f; - // gamma value for all filters - bEnableFilterGamma = false; - filterGamma = 2.2f; - // alpha value for - filterBlur = 1.0f; - // width of filter - filterWidth = 10.0f; - bOverrideFilterWidth = false; - textureType = kTextureTypeTexture2D; // regular decal, cube or volume - textureFormat = kDXT1; - bSwapRG = false; // swap color positions R and G - bSwapRB = false; // swap color positions R and G - user_data = NULL; // user supplied point passed down to write functions - float default_filter[5][5] = { - 0, 0, 0, 0, 0, 0, 0, -2, 0, 0, 0, -2, 11, -2, 0, 0, 0, -2, 0, 0, 0, 0, 0, 0, 0, - }; - for (int i = 0; i < 5; i++) - { - for (int j = 0; j < 5; j++) - { - custom_filter_data.filter[i][j] = default_filter[i][j]; - } - } - custom_filter_data.div = 3; // div - custom_filter_data.bias = 0; // bias - unsharp_data.radius32F = 5.0; // radius - unsharp_data.amount32F = 0.5; // amount - unsharp_data.threshold32F = 0; // threshold - xsharp_data.strength32F = 1.0f; // xsharp strength - xsharp_data.threshold32F = 1.0f; // xsharp threshold - sharpening_passes_per_mip_level[0] = 0; - for (int i = 1; i < MAX_MIP_MAPS; i++) - sharpening_passes_per_mip_level[i] = 1; - bAlphaFilterModulate = false; - bPreModulateColorWithAlpha = false; - bUserSpecifiedFadingAmounts = false; - for (int i = 0; i < 256; i++) - { - color_palette[i].r = 0; - color_palette[i].g = 0; - color_palette[i].b = 0; - color_palette[i].a = 0; - } - paletteSize = 0; // this will be set by the format read or write - autoGeneratePalette = false; - outputScale.r = 1.0f; // scale and bias when writing output values - outputScale.g = 1.0f; // scale and bias when writing output values - outputScale.b = 1.0f; // scale and bias when writing output values - outputScale.a = 1.0f; // scale and bias when writing output values - outputBias.r = 0.0f; - outputBias.g = 0.0f; - outputBias.b = 0.0f; - outputBias.a = 0.0f; - inputScale.r = 1.0f; // scale and bias after loading data - inputScale.g = 1.0f; // scale and bias - inputScale.b = 1.0f; // scale and bias - inputScale.a = 1.0f; // scale and bias - inputBias.r = 0.0f; - inputBias.g = 0.0f; - inputBias.b = 0.0f; - inputBias.a = 0.0f; - bConvertToGreyScale = false; - greyScaleWeight.r = 0.3086f; // scale and bias after loading data - greyScaleWeight.g = 0.6094f; // scale and bias - greyScaleWeight.b = 0.0820f; // scale and bias - greyScaleWeight.a = 0.0f; // scale and bias - brightness.r = 0.0; // adjust brightness = 0 none - brightness.g = 0.0; // - brightness.b = 0.0; // - brightness.a = 0.0; // - contrast.r = 1; // contrast 1 == none - contrast.g = 1; - contrast.b = 1; - contrast.a = 1; - bCalcLuminance = false; // do not convert to luminance by default - bOutputWrap = false; // wrap the values when outputting to the desired format - bCreateOnePalette = false; - } - - /////////////////////////// COMPRESSION QUALITY ////////////////////////////////// - nvQualitySetting quality; - float rmsErrorSearchThreshold; - - void SetQuality(nvQualitySetting setting, float threshold) - { - quality = setting; - // if setting == kQualityHighest, if the RMS error for a 4x4 block is bigger than - // this, an extended search is performed. In practice this has been equivalent to and - // exhaustive search in the entire domain. aka it doesn't get any better than this. - rmsErrorSearchThreshold = threshold; - } - - /////////////////////////////// COMPRESSION WEIGHTING ////////////////////////////// - nvCompressionWeighting weightType; // weighting type for DXT compressop - float weight[3]; // weights used for compress - - void SetCompressionWeighting(nvCompressionWeighting type, float new_weight[3]) - { - weightType = type; - // if type == kUserDefinedWeighting, then use these weights - weight[0] = new_weight[0]; - weight[1] = new_weight[1]; - weight[2] = new_weight[2]; - } - - nvNormalMap normalMap; // filled when processing normal maps - nvBoolean bNormalizeTexels; // normalize the texels - - /////////////////////////// SCALING IMAGE ///////////////////////////////// - nvRescaleTypes rescaleImageType; // rescaling type before image before compression - nvMipFilterTypes rescaleImageFilter; // rescaling filter - float scaleX; // scale to this if we are prescaling images before compressing - float scaleY; - - // scale the image to this size first - void PreScaleImage(float x, float y, nvMipFilterTypes filter) - { - rescaleImageType = kRescalePreScale; - scaleX = x; - scaleY = y; - rescaleImageFilter = filter; - } - - // relative scaling. 0.5 is half the image size - void RelativeScaling(float x, float y, nvMipFilterTypes filter) - { - rescaleImageType = kRescaleRelScale; - scaleX = x; - scaleY = y; - rescaleImageFilter = filter; - } - - void RescaleToNearestPOW2(nvMipFilterTypes filter) - { - rescaleImageType = kRescaleNearestPower2; - rescaleImageFilter = filter; - } - - void RescaleToNearestBiggestPOW2(nvMipFilterTypes filter) - { - rescaleImageType = kRescaleBiggestPower2; - rescaleImageFilter = filter; - } - - void RescaleToNearestSmallestPOW2(nvMipFilterTypes filter) - { - rescaleImageFilter = filter; - rescaleImageType = kRescaleSmallestPower2; - } - - void RescaleToNearestNextSmallestPOW2(nvMipFilterTypes filter) - { - rescaleImageType = kRescaleNextSmallestPower2; - rescaleImageFilter = filter; - } - - /////////////////// CLAMPING IMAGE SIZE /////////////////////////////////// - nvBoolean bClamp; // Clamp to max size - float clampX; // clamping values - float clampY; - - // image no bigger than... - void ClampMaxImageSize(float maxX, float maxY) - { - bClamp = true; - clampX = maxX; - clampY = maxY; - } - - nvBoolean bClampScale; // maximum value of h or w (retain scale) - float clampScaleX; // clamping values - float clampScaleY; - - // clamp max image size and maintain image proportions. - // Evenly scale down in both directions so that the given image size is not exceeded - void ClampMaxImageSizeContrained(float maxX, float maxY) - { - bClampScale = true; - clampScaleX = maxX; - clampScaleY = maxY; - } - - ///////////////////////////// MIP MAPS /////////////////////////////////// - nvMipMapGeneration mipMapGeneration; // changed MIPMaptype to an enum - long numMipMapsToWrite; // max number of Mip maps to generate - - // 0 = all - void GenerateMIPMaps(int n) - { - mipMapGeneration = kGenerateMipMaps; - numMipMapsToWrite = n; - } - - void DoNotGenerateMIPMaps() { mipMapGeneration = kNoMipMaps; } - void UseExisitingMIPMaps() - { - // what ever is in the image - mipMapGeneration = kUseExistingMipMaps; - // numMipMapsToWrite is ignored - } - - void CompleteMIPMapChain(int n) - { - mipMapGeneration = kCompleteMipMapChain; - numMipMapsToWrite = n; - } - - nvMipFilterTypes mipFilterType; // for MIP map, select from MIPFilterTypes - - /////////////////// ALPHA ////////////////////////////////////////// - nvBoolean bBinaryAlpha; // zero or one alpha channel - // [0,1] - // threshold for alpha transparency DXT1 - // or when Binary Alpha is selected, below this value, alpha is zero - float alphaThreshold32F; - - void SetBinaryAlpha(float threshold) - { - bBinaryAlpha = true; - alphaThreshold32F = threshold; - } - - ////////////////////////// BORDERS ///////////////////////////////////////// - // set any of these to generate an alpha border - nvBoolean bAlphaBorder; // make an alpha border - nvBoolean bAlphaBorderLeft; // make an alpha border on just the left - nvBoolean bAlphaBorderRight; // make an alpha border on just the right - nvBoolean bAlphaBorderTop; // make an alpha border on just the top - nvBoolean bAlphaBorderBottom; // make an alpha - nvBoolean bBorder; // make a color border - fpPixel borderColor32F; // color of border [0,1] - - void SetBorderColor(fpPixel& color) - { - bBorder = true; - borderColor32F = color; - } - - void NoBorderColor() { bBorder = false; } - /////////////////////// FADING MIP LEVELS //////////////////////////// - nvBoolean bFadeColor; // fade color over MIP maps - nvBoolean bFadeAlpha; // fade alpha over MIP maps - fpPixel fadeToColor32F; // color and alpha to fade to - long fadeToDelay; // start fading after 'n' MIP maps - float fadeAmount32F; // percentage of color to fade in - nvBoolean bUserSpecifiedFadingAmounts; - float userFadingAmounts[MAX_MIP_MAPS]; - - // [0,1] - void FadeAlphaInMIPMaps(float alpha) - { - bFadeAlpha = true; - fadeToColor32F.a = alpha; - } - - // 0 - 255 - void FadeColorInMIPMaps(float r, float g, float b) - { - fadeToColor32F.r = r; - fadeToColor32F.g = g; - fadeToColor32F.b = b; - bFadeColor = true; - } - - void SetFadingAsPercentage(float percentPerMIP, int mipLevelToStartFading) - { - bUserSpecifiedFadingAmounts = false; - fadeAmount32F = percentPerMIP; - fadeToDelay = mipLevelToStartFading; - } - - // or - void SpecifyFadingPerMIPLevel(float fadeAmounts[MAX_MIP_MAPS]) - { - bUserSpecifiedFadingAmounts = true; - for (int i = 0; i < MAX_MIP_MAPS; i++) - { - userFadingAmounts[i] = fadeAmounts[i]; - } - } - - /////////////////////////// SHARPENING ///////////////////////////////////// - // sharpening after creating each MIP map level - // used when custom sharping filter is used - // 5x5 filter - struct - { - float filter[5][5]; - float div; - float bias; - - } custom_filter_data; - - // used when unsharpen sharping filter is used - struct - { - float radius32F; // radius - float amount32F; // amount - float threshold32F; // threshold [0,1] - - } unsharp_data; - - // used when xsharpen sharping filter is used - struct - { - // 0 - 1 - float strength32F; - float threshold32F; - } xsharp_data; - - int sharpening_passes_per_mip_level[MAX_MIP_MAPS]; - nvSharpenFilterTypes sharpenFilterType; // post filtering image sharpening - - void SetNumberOfSharpeningPassesPerMIPLevel(int passes[MAX_MIP_MAPS]) - { - for (int i = 0; i < MAX_MIP_MAPS; i++) - { - sharpening_passes_per_mip_level[i] = passes[i]; - } - } - - // [0,1] - void XSharpenImage(float strength, float threshold) - { - sharpenFilterType = kSharpenFilterXSharpen; - xsharp_data.strength32F = strength; - xsharp_data.threshold32F = threshold; - } - - void UnSharpenImage(float radius, float amount, float threshold) - { - sharpenFilterType = kSharpenFilterUnSharp; - unsharp_data.radius32F = radius; - unsharp_data.amount32F = amount; - unsharp_data.threshold32F = threshold; - } - - // roll your own post filter sharpen - void SetCustomFilter(float filter[5][5], float div, float bias) - { - sharpenFilterType = kSharpenFilterCustom; - custom_filter_data.div = div; - custom_filter_data.bias = bias; - for (int i = 0; i < 5; i++) - { - for (int j = 0; j < 5; j++) - { - custom_filter_data.filter[i][j] = filter[i][j]; - } - } - } - - nvBoolean bErrorDiffusion; // diffuse error, used for helping gradient images - int errorDiffusionWidth; // number of texel to include - - void EnableErrorDiffusion(int width) - { - bErrorDiffusion = true; - errorDiffusionWidth = width; - } - - ///////////////////// FILTERING //////////////////////////////////////// - // convert to gamma space before filtering - nvBoolean bEnableFilterGamma; - float filterGamma; // gamma value for filtering (MIP map generation) - float filterBlur; // sharpness or blurriness of filtering - nvBoolean bOverrideFilterWidth; // use the specified width in FilterWidth,instead of the default - float filterWidth; // override fiter width with this value - - // 0 is no gamma correction - void EnableGammaFiltering(float gamma) - { - bEnableFilterGamma = true; - filterGamma = gamma; - } - - void OverrideFilterWidth(float w) - { - bOverrideFilterWidth = true; - filterWidth = w; - } - - void SetFilterSharpness(float sharp) { filterBlur = sharp; } - nvTextureTypes textureType; // what type of texture is this? - nvTextureFormats textureFormat; // format to convert to - - void SetTextureFormat(nvTextureTypes type, nvTextureFormats format) - { - textureType = type; - textureFormat = format; - } - - size_t paletteSize; - rgba_t color_palette[256]; - nvBoolean autoGeneratePalette; // generate palette for p8 and p4 formats - - // for P4 and P8 formats - // set 16 for P4 format and 256 for P8 format - void SetPalette(int n, rgba_t user_palette[256]) - { - paletteSize = n; - for (int i = 0; i < n; i++) - color_palette[i] = user_palette[i]; - - autoGeneratePalette = false; - } - - ////////////////// DATA SCALING ////////////////////// - fpPixel outputScale; // scale and bias when writing output values - fpPixel outputBias; - - void ScaleBiasOutput(fpPixel& scale, fpPixel& bias) - { - outputScale = scale; - outputBias = bias; - } - - fpPixel inputScale; // scale and bias on input to compressor - fpPixel inputBias; - - void ScaleBiasInput(fpPixel& scale, fpPixel& bias) - { - inputScale = scale; - inputBias = bias; - } - - bool bConvertToGreyScale; - fpPixel greyScaleWeight; - - void SetGreyScale(fpPixel& w) - { - bConvertToGreyScale = true; - greyScaleWeight = w; - } - - fpPixel brightness; - fpPixel contrast; - - void SetBrightnessAndContrast(fpPixel& _brightness, fpPixel& _contrast) - { - brightness = _brightness; - contrast = _contrast; - } - - /////////// general enables //////////////////////////////// - nvBoolean bOutputWrap; // wrap the values (before clamping to the format range) - // when outputting to the desired format - nvBoolean bCalcLuminance; // convert color to luminance for 'L' formats - nvBoolean bSwapRB; // swap color positions R and G - nvBoolean bSwapRG; // swap color positions R and G - nvBoolean bForceDXT1FourColors; // do not let DXT1 use 3 color representation - nvBoolean bRGBE; // rgba_t is in RGBE format - nvBoolean bCreateOnePalette; // All 4x4 compression blocks share the same palette - - /////////////////// DISABLED //////////////////////////////// - nvBoolean bDitherColor; // enable dithering during 16 bit conversion - nvBoolean bDitherMip0; // enable dithering during 16 bit conversion for each MIP level (after filtering) - nvBoolean bPreModulateColorWithAlpha; // modulate color by alpha - nvBoolean bAlphaFilterModulate; // modulate color by alpha for filtering only - - ///////////////////////// USER DATA ///////////////////////// - void* user_data; // user supplied values passed down to write functions -}; diff --git a/src/utils/xrDXT/ddsTypes.h b/src/utils/xrDXT/ddsTypes.h deleted file mode 100644 index ab2e9e919cf..00000000000 --- a/src/utils/xrDXT/ddsTypes.h +++ /dev/null @@ -1,108 +0,0 @@ -#pragma once -typedef enum RescaleTypes { - RESCALE_NONE, // no rescale - RESCALE_NEAREST_POWER2, // rescale to nearest power of two - RESCALE_BIGGEST_POWER2, // rescale to next bigger power of 2 - RESCALE_SMALLEST_POWER2, // rescale to smaller power of 2 - RESCALE_NEXT_SMALLEST_POWER2, // rescale to next smaller power of 2 - RESCALE_PRESCALE, // rescale to this size - RESCALE_RELSCALE, // relative rescale - RESCALE_LAST, // - -} RescaleTypes; - -typedef enum SharpenFilterTypes { - kSharpenFilterNone, - kSharpenFilterNegative, - kSharpenFilterLighter, - kSharpenFilterDarker, - kSharpenFilterContrastMore, - kSharpenFilterContrastLess, - kSharpenFilterSmoothen, - kSharpenFilterSharpenSoft, - kSharpenFilterSharpenMedium, - kSharpenFilterSharpenStrong, - kSharpenFilterFindEdges, - kSharpenFilterContour, - kSharpenFilterEdgeDetect, - kSharpenFilterEdgeDetectSoft, - kSharpenFilterEmboss, - kSharpenFilterMeanRemoval, - kSharpenFilterUnSharp, - kSharpenFilterXSharpen, - kSharpenFilterWarpSharp, - kSharpenFilterCustom, - kSharpenFilterLast, -}; - -typedef enum MIPFilterTypes { - kMIPFilterPoint, - kMIPFilterBox, - kMIPFilterTriangle, - kMIPFilterQuadratic, - kMIPFilterCubic, - - kMIPFilterCatrom, - kMIPFilterMitchell, - - kMIPFilterGaussian, - kMIPFilterSinc, - kMIPFilterBessel, - - kMIPFilterHanning, - kMIPFilterHamming, - kMIPFilterBlackman, - kMIPFilterKaiser, - kMIPFilterLast, -}; - -enum TextureFormats -{ - kDXT1, - kDXT1a, // DXT1 with one bit alpha - kDXT3, // explicit alpha - kDXT5, // interpolated alpha - k4444, // a4 r4 g4 b4 - k1555, // a1 r5 g5 b5 - k565, // a0 r5 g6 b5 - k8888, // a8 r8 g8 b8 - k888, // a0 r8 g8 b8 - k555, // a0 r5 g5 b5 - k8, // paletted - kV8U8, // DuDv - kCxV8U8, // normal map - kA8, // alpha only - k4, // 16 bit color - kQ8W8V8U8, - kA8L8, - kR32F, - kA32B32G32R32F, - kA16B16G16R16F, - kL8, // luminance - kTextureFormatLast -}; - -enum TextureTypes -{ - kTextureType2D, - kTextureTypeCube, - kTextureTypeVolume, - kTextureTypeLast, -}; -/* -enum NormalMapTypes -{ -kColorTextureMap, -kTangentSpaceNormalMap, -kObjectSpaceNormalMap, -}; - */ - -enum CompressionWeighting -{ - kLuminanceWeighting, - kGreyScaleWeighting, - kTangentSpaceNormalMapWeighting, - kObjectSpaceNormalMapWeighting, - kUserDefinedWeighting, // used values stored in 'weight' -}; diff --git a/src/utils/xrDXT/dxtlib.h b/src/utils/xrDXT/dxtlib.h deleted file mode 100644 index a73d1d8883c..00000000000 --- a/src/utils/xrDXT/dxtlib.h +++ /dev/null @@ -1,98 +0,0 @@ -/**************************************************************************************** - - Copyright (C) NVIDIA Corporation 2003 - - TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THIS SOFTWARE IS PROVIDED - *AS IS* AND NVIDIA AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES, EITHER EXPRESS - OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY - AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL NVIDIA OR ITS SUPPLIERS - BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES - WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, - BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR ANY OTHER PECUNIARY LOSS) - ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF NVIDIA HAS - BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - -*****************************************************************************************/ -#pragma once - -#ifndef DXTLIB_API -#define DXTLIB_API -#endif - -#include -#include - -struct MIPMapData -{ - size_t mipLevel; - size_t width; - size_t height; - int faceNumber; // current face number for this image - int numFaces; // total number of faces (depth for volume textures, 6 for cube maps) -}; - -// Write callback function. -typedef NV_ERROR_CODE (*DXTReadCallback)(void* buffer, size_t count, void* userData); - -typedef NV_ERROR_CODE (*DXTWriteCallback)(const void* buffer, size_t count, - const MIPMapData* mipMapData, // if nz, this is MIP data - void* userData); - -// Compresses an image with a user supplied callback with the data for each MIP level created -enum nvPixelOrder -{ - nvRGBA, - nvBGRA, - nvRGB, - nvBGR, - nvGREY, // one plance copied to RGB -}; - -namespace nvDDS -{ -DXTLIB_API NV_ERROR_CODE nvDXTcompress(const nvImageContainer& imageContainer, nvCompressionOptions* options, - DXTWriteCallback fileWriteRoutine, // call to .dds write routine - const RECT* rect = 0); - -DXTLIB_API NV_ERROR_CODE nvDXTcompress(const RGBAImage& srcImage, nvCompressionOptions* options, - DXTWriteCallback fileWriteRoutine, // call to .dds write routine - const RECT* rect = 0); - -DXTLIB_API NV_ERROR_CODE nvDXTcompress(const unsigned char* srcImage, size_t width, size_t height, size_t byte_pitch, - nvPixelOrder pixelOrder, nvCompressionOptions* options, - DXTWriteCallback fileWriteRoutine, // call to .dds write routine - const RECT* rect = 0); - -// image with MIP maps -DXTLIB_API NV_ERROR_CODE nvDXTcompress(const RGBAMipMappedImage& srcMIPImage, nvCompressionOptions* options, - DXTWriteCallback fileWriteRoutine, // call to .dds write routine - const RECT* rect = 0); - -DXTLIB_API NV_ERROR_CODE nvDXTcompress(const RGBAMipMappedCubeMap& srcMIPCubeMap, nvCompressionOptions* options, - DXTWriteCallback fileWriteRoutine, // call to .dds write routine - const RECT* rect = 0); - -DXTLIB_API NV_ERROR_CODE nvDXTcompress(const RGBAMipMappedVolumeMap& srcMIPVolumeMap, nvCompressionOptions* options, - DXTWriteCallback fileWriteRoutine, // call to .dds write routine - const RECT* rect = 0); - -DXTLIB_API NV_ERROR_CODE nvDXTcompress( - const fpImage& srcImage, nvCompressionOptions* options, DXTWriteCallback fileWriteRoutine, const RECT* rect = 0); - -DXTLIB_API NV_ERROR_CODE nvDXTcompress(const fpMipMappedImage& srcMIPImage, nvCompressionOptions* options, - DXTWriteCallback fileWriteRoutine, const RECT* rect = 0); - -DXTLIB_API NV_ERROR_CODE nvDXTcompress(const fpMipMappedCubeMap& srcMIPCubeMap, nvCompressionOptions* options, - DXTWriteCallback fileWriteRoutine, const RECT* rect = 0); - -DXTLIB_API NV_ERROR_CODE nvDXTcompress(const fpMipMappedVolumeMap& srcMIPVolumeMap, nvCompressionOptions* options, - DXTWriteCallback fileWriteRoutine, const RECT* rect = 0); - -// array of images for volume map or cube map -DXTLIB_API NV_ERROR_CODE nvDXTcompress(const fpImageArray& srcImageArray, nvCompressionOptions* options, - DXTWriteCallback fileWriteRoutine, const RECT* rect = 0); - -// readMIPMapCount, number of MIP maps to load. 0 is all -DXTLIB_API NV_ERROR_CODE nvDXTdecompress(nvImageContainer& imageData, nvPixelFormat pf, int readMIPMapCount, - DXTReadCallback fileReadRoutine, void* userData); -}; diff --git a/src/utils/xrDXT/tPixel.h b/src/utils/xrDXT/tPixel.h deleted file mode 100644 index 141dfbbdedf..00000000000 --- a/src/utils/xrDXT/tPixel.h +++ /dev/null @@ -1,747 +0,0 @@ -#ifndef TPIXEL_H -#define TPIXEL_H - -#include -#include -#include "tVector.h" - -#pragma pack(push, 4) - -// rad and green -class u16v16_t -{ -public: - union - { - unsigned short rg[4]; - struct - { - unsigned short r; - unsigned short g; - }; - }; - u16v16_t& operator+=(const u16v16_t& v); // incrementation by a Vec4f - - void set(unsigned short _r, unsigned short _g) - { - r = _r; - g = _g; - } -}; - -class r12g12b8_t -{ -public: - union - { - struct - { - unsigned long r : 12; - unsigned long g : 12; - unsigned long b : 8; - }; - }; - r12g12b8_t& operator+=(const r12g12b8_t& v); // incrementation by a Vec4f - - void set(unsigned long _r, unsigned long _g, unsigned long _b) - { - r = _r; - g = _g; - b = _b; - } -}; -inline int iClamp(int a, int lo, int hi) -{ - if (a < lo) - a = lo; - if (a > hi) - a = hi; - return a; -} - -inline float fClamp(float a, float lo, float hi) -{ - if (a < lo) - a = lo; - if (a > hi) - a = hi; - return a; -} - -class rgba_t -{ -public: - union - { - unsigned long u; - unsigned char rgba[4]; - struct - { - unsigned char r; - unsigned char g; - unsigned char b; - unsigned char a; - }; - }; - - rgba_t() {} - rgba_t(unsigned char _r, unsigned char _g, unsigned char _b, unsigned char _a) - { - a = _a; - r = _r; - g = _g; - b = _b; - } - - rgba_t& operator+=(const rgba_t& v) // incrementation by a rgba_t - { - r = iClamp((int)r + (int)v.r, 0, 255); - g = iClamp((int)g + (int)v.g, 0, 255); - b = iClamp((int)b + (int)v.b, 0, 255); - a = iClamp((int)a + (int)v.a, 0, 255); - - return *this; - } - - rgba_t& operator-=(const rgba_t& v); // decrementation by a rgba_t - rgba_t& operator*=(const float d); // multiplication by a constant - rgba_t& operator/=(const float d); // division by a constant - - rgba_t& operator=(const rgba_t& v) - { - r = v.r; - g = v.g; - b = v.b; - a = v.a; - return *this; - } - - friend rgba_t operator+(const rgba_t& v1, const rgba_t& v2) - { - int r, g, b, a; - r = iClamp((int)v1.r + (int)v2.r, 0, 255); - g = iClamp((int)v1.g + (int)v2.g, 0, 255); - b = iClamp((int)v1.b + (int)v2.b, 0, 255); - a = iClamp((int)v1.a + (int)v2.a, 0, 255); - - return rgba_t(r, g, b, a); - } - - friend rgba_t operator/(const rgba_t& v, float s) { return rgba_t(v.r / s, v.g / s, v.b / s, v.a / s); } - friend rgba_t operator/(const rgba_t& v, int s) { return rgba_t(v.r / s, v.g / s, v.b / s, v.a / s); } - void set(unsigned char _r, unsigned char _g, unsigned char _b, unsigned char _a) - { - r = _r; - g = _g; - b = _b; - a = _a; - } -}; - -class rgba16_t -{ -public: - union - { - // unsigned __int64 u; - unsigned short rgba[4]; - struct - { - unsigned short r; - unsigned short g; - unsigned short b; - unsigned short a; - }; - }; - - rgba16_t() {} - rgba16_t(unsigned short _r, unsigned short _g, unsigned short _b, unsigned short _a) - { - a = _a; - r = _r; - g = _g; - b = _b; - } - - rgba16_t& operator+=(const rgba16_t& v) // incrementation by a rgba_t - { - r = iClamp((int)r + (int)v.r, 0, 65535); - g = iClamp((int)g + (int)v.g, 0, 65535); - b = iClamp((int)b + (int)v.b, 0, 65535); - a = iClamp((int)a + (int)v.a, 0, 65535); - - return *this; - } - - rgba16_t& operator-=(const rgba16_t& v); // decrementation by a rgba_t - rgba16_t& operator*=(const float d); // multiplication by a constant - rgba16_t& operator/=(const float d); // division by a constant - - rgba16_t& operator=(const rgba16_t& v) - { - r = v.r; - g = v.g; - b = v.b; - a = v.a; - return *this; - } - - friend rgba16_t operator+(const rgba16_t& v1, const rgba16_t& v2) - { - int r, g, b, a; - r = iClamp((int)v1.r + (int)v2.r, 0, 65535); - g = iClamp((int)v1.g + (int)v2.g, 0, 65535); - b = iClamp((int)v1.b + (int)v2.b, 0, 65535); - a = iClamp((int)v1.a + (int)v2.a, 0, 65535); - - return rgba16_t(r, g, b, a); - } - - friend rgba16_t operator/(const rgba16_t& v, float s) { return rgba16_t(v.r / s, v.g / s, v.b / s, v.a / s); } - friend rgba16_t operator/(const rgba16_t& v, int s) { return rgba16_t(v.r / s, v.g / s, v.b / s, v.a / s); } - void set(unsigned short _r, unsigned short _g, unsigned short _b, unsigned short _a) - { - r = _r; - g = _g; - b = _b; - a = _a; - } -}; - -class urgba_t -{ -public: - union - { - unsigned long u; - char rgba[4]; - struct - { - char r; - char g; - char b; - char a; - }; - }; - urgba_t& operator+=(const urgba_t& v); // incrementation by a Vec4f - - void set(char _r, char _g, char _b, char _a) - { - r = _r; - g = _g; - b = _b; - a = _a; - } -}; - -class q8w8v8u8_t -{ -public: - union - { - char qwvu[4]; - struct - { - char q; - char w; - char v; - char u; - }; - }; - q8w8v8u8_t& operator+=(const q8w8v8u8_t& v); // incrementation by a Vec4f - - void set(char _r, char _g, char _b, char _a) - { - q = _r; - w = _g; - v = _b; - u = _a; - } -}; - -#define _R 0 -#define _G 1 -#define _B 2 -#define _A 3 - -class fpPixel -{ -public: - union - { - float p[4]; - struct - { - float r; - float g; - float b; - float a; - }; - struct - { - float x; - float y; - float z; - float w; - }; - }; - - fpPixel() {} - fpPixel(const float _r, const float _g, const float _b, const float _a) - { - a = _a; - r = _r; - g = _g; - b = _b; - } - - fpPixel(const fpPixel& v) - { - a = v.a; - r = v.r; - g = v.g; - b = v.b; - } // copy constructor - - void set(const float _r, const float _g, const float _b, const float _a) - { - a = _a; - r = _r; - g = _g; - b = _b; - } - - void set(const fpPixel& v) - { - a = v.a; - r = v.r; - g = v.g; - b = v.b; - } - - fpPixel& operator+=(const fpPixel& v); // incrementation by a Vec4f - - fpPixel& operator=(const fpPixel& v); // assignment of a Vec3f - fpPixel& operator-=(const fpPixel& v); // decrementation by a Vec3f - fpPixel& operator*=(const float d); // multiplication by a constant - fpPixel& operator/=(const float d); // division by a constant - - friend fpPixel operator+(const fpPixel& v1, const fpPixel& v2) - { - return fpPixel(v1.r + v2.r, v1.g + v2.g, v1.b + v2.b, v1.a + v2.a); - } - - friend fpPixel operator/(const fpPixel& v, float s) { return fpPixel(v.r / s, v.g / s, v.b / s, v.a / s); } - friend int operator==(const fpPixel& v1, const fpPixel& v2); // v1 == v2 ? - - int normalize() - { - double u; - u = x * x + y * y + z * z; - - if (fabs(u - 1.0) < 1e-12) - return 0; // already normalized - - if (fabs((double)u) < 1e-12) - { - x = y = z = 0.0; - return -1; - } - - u = 1.0 / sqrt(u); - - x *= u; - y *= u; - z *= u; - - return 0; - } -}; - -inline int operator==(const fpPixel& v1, const fpPixel& v2) -{ - return v1.a == v2.a && v1.r == v2.r && v1.b == v2.g && v1.g == v2.b; -} - -inline fpPixel& fpPixel::operator=(const fpPixel& v) -{ - a = v.a; - r = v.r; - g = v.g; - b = v.b; - return *this; -} - -class CNormalData -{ -public: - CNormalData() { normals = 0; } - ~CNormalData() - { - if (normals) - { - delete[] normals; - normals = 0; - } - } - int width; - int height; - - fpPixel* normals; -}; - -template -class CImage -{ - int m_width; - int m_height; - nvVector<_type> m_pixels; - -public: - CImage<_type>& operator=(const CImage<_type>& v) - { - // resize and copy over - resize(v.width(), v.height()); - - m_pixels = v.m_pixels; - - return *this; - } - - _type& operator[](int i) - { -#ifdef _DEBUG - assert(i < m_width * m_height); -#endif - return m_pixels[i]; - }; - - const _type& operator[](int i) const - { -#ifdef _DEBUG - assert(i < m_width * m_height); -#endif - return m_pixels[i]; - } - - int nPlanesInFile; - - int width() const { return m_width; } - int height() const { return m_height; } - _type* pixels() - { - int s = m_pixels.size(); - return &m_pixels[0]; - } - - CImage() - { - m_width = 0; - m_height = 0; - - nPlanesInFile = -1; - - m_pixels.clear(); - }; - ~CImage() {} - void clear() - { - m_width = 0; - m_height = 0; - m_pixels.clear(); - } - - void resize(int width, int height) - { - m_pixels.resize(width * height); - m_width = width; - m_height = height; - } - - CImage<_type>(int width, int height) - { - m_pixels.resize(width * height); - m_width = width; - m_height = height; - nPlanesInFile = -1; - }; - - void SwapRB() - { - _type* p = &m_pixels[0]; - for (int i = 0; i < m_width * m_height; i++) - ; - { - int r = p->r; - p->r = p->b; - p->b = r; - } - } - - void FlipTopToBottom() - { - _type* swap = new _type[m_width]; - - unsigned long row; - - _type* end_row; - _type* start_row; - - int len = sizeof(_type) * m_width; - - for (row = 0; row < m_height / 2; row++) - { - end_row = &m_pixels[m_width * (m_height - row - 1)]; - start_row = &m_pixels[m_width * row]; - - // copy row toward end of image into temporary swap buffer - memcpy(swap, end_row, len); - - // copy row at beginning to row at end - memcpy(end_row, start_row, len); - - // copy old bytes from row at end (in swap) to row at beginning - memcpy(start_row, swap, len); - } - - delete[] swap; - } -}; - -class RGBAImage -{ - int m_width; - int m_height; - nvVector m_pixels; - -public: - RGBAImage& operator=(const RGBAImage& v) - { - // resize and copy over - resize(v.width(), v.height()); - - m_pixels = v.m_pixels; - - return *this; - } - - rgba_t& operator[](int i) - { -#ifdef _DEBUG - assert(i < m_width * m_height); -#endif - return m_pixels[i]; - }; - - const rgba_t& operator[](int i) const - { -#ifdef _DEBUG - assert(i < m_width * m_height); -#endif - return m_pixels[i]; - } - - int nPlanesInFile; - - int width() const { return m_width; } - int height() const { return m_height; } - rgba_t* pixels() - { - int s = m_pixels.size(); - return &m_pixels[0]; - } - - RGBAImage() - { - m_width = 0; - m_height = 0; - - nPlanesInFile = -1; - - m_pixels.clear(); - }; - ~RGBAImage() {} - void clear() - { - m_width = 0; - m_height = 0; - m_pixels.clear(); - } - - void resize(int width, int height) - { - m_pixels.resize(width * height); - m_width = width; - m_height = height; - } - - RGBAImage(int width, int height) - { - m_pixels.resize(width * height); - m_width = width; - m_height = height; - nPlanesInFile = -1; - }; - - void SwapRB() - { - rgba_t* p = &m_pixels[0]; - for (int i = 0; i < m_width * m_height; i++) - ; - { - int r = p->r; - p->r = p->b; - p->b = r; - } - } - - void FlipTopToBottom() - { - rgba_t* swap = new rgba_t[m_width]; - - unsigned long row; - - rgba_t* end_row; - rgba_t* start_row; - - int len = sizeof(rgba_t) * m_width; - - for (row = 0; row < m_height / 2; row++) - { - end_row = &m_pixels[m_width * (m_height - row - 1)]; - start_row = &m_pixels[m_width * row]; - - // copy row toward end of image into temporary swap buffer - memcpy(swap, end_row, len); - - // copy row at beginning to row at end - memcpy(end_row, start_row, len); - - // copy old bytes from row at end (in swap) to row at beginning - memcpy(start_row, swap, len); - } - - delete[] swap; - } -}; - -class fpImage -{ - int m_width; - int m_height; - nvVector m_pixels; - -public: - fpImage& operator=(const fpImage& v) - { - // resize and copy over - resize(v.width(), v.height()); - - m_pixels = v.m_pixels; - return *this; - } - - fpPixel& operator[](int i) - { -#ifdef _DEBUG - assert(i < m_width * m_height); -#endif - return m_pixels[i]; - }; - - const fpPixel& operator[](int i) const - { -#ifdef _DEBUG - assert(i < m_width * m_height); -#endif - return m_pixels[i]; - } - - int nPlanesInFile; - - int width() const { return m_width; } - int height() const { return m_height; } - fpPixel* pixels() { return &m_pixels[0]; } - fpImage() - { - m_width = 0; - m_height = 0; - nPlanesInFile = 0; - m_pixels.clear(); - }; - ~fpImage() {} - void zeroize() - { - fpPixel* p = &m_pixels[0]; - for (int i = 0; i < m_width * m_height; i++) - ; - { - p->r = 0; - p->g = 0; - p->b = 0; - p->a = 0; - } - } - - void resize(int width, int height) - { - m_pixels.resize(width * height); - m_width = width; - m_height = height; - } - - fpImage(int width, int height) - { - m_pixels.resize(width * height); - m_width = width; - m_height = height; - nPlanesInFile = -1; - }; - - void SwapRB() - { - fpPixel* p = &m_pixels[0]; - for (int i = 0; i < m_width * m_height; i++) - ; - { - int r = p->r; - p->r = p->b; - p->b = r; - } - } - - void FlipTopToBottom() - { - fpPixel* swap = new fpPixel[m_width]; - - unsigned long row; - - fpPixel* end_row; - fpPixel* start_row; - - int len = sizeof(rgba_t) * m_width; - - for (row = 0; row < m_height / 2; row++) - { - end_row = &m_pixels[m_width * (m_height - row - 1)]; - start_row = &m_pixels[m_width * row]; - - // copy row toward end of image into temporary swap buffer - memcpy(swap, end_row, len); - - // copy row at beginning to row at end - memcpy(end_row, start_row, len); - - // copy old bytes from row at end (in swap) to row at beginning - memcpy(start_row, swap, len); - } - - delete[] swap; - } -}; - -#pragma pack(pop) - -#include "ColorConvert.h" - -#endif diff --git a/src/utils/xrDXT/tVector.h b/src/utils/xrDXT/tVector.h deleted file mode 100644 index ec3df6b12a0..00000000000 --- a/src/utils/xrDXT/tVector.h +++ /dev/null @@ -1,121 +0,0 @@ -#pragma once -#include -#include - -template -class nvVector -{ - _Type* m_data; - - size_t allocated_size; - size_t current_size; - -public: - void tvfree(_Type*& ptr) - { - if (ptr) - { - delete[] ptr; - ptr = 0; - } - } - - _Type* tvallocate(size_t elements) { return new _Type[elements]; } - nvVector& operator=(const nvVector& v) - { - resize(v.size()); - - for (size_t i = 0; i < v.size(); i++) - { - m_data[i] = v.m_data[i]; - } - return *this; - } - - void FirstAllocation() - { - // start with 256 entries - - tvfree(m_data); - - allocated_size = 256; - current_size = 0; - m_data = tvallocate(allocated_size); - } - - nvVector() - { - m_data = 0; - current_size = 0; - allocated_size = 0; - } - - void resize(size_t newSize) - { - if (newSize != allocated_size) - { - allocated_size = newSize; - - tvfree(m_data); - - m_data = tvallocate(allocated_size); - } - - current_size = newSize; - } - void push_back(_Type item) - { - if (allocated_size == 0) - { - FirstAllocation(); - } - else if (current_size >= allocated_size) - { - allocated_size = allocated_size * 2; - - _Type* temp = tvallocate(allocated_size); - - // copy old data to new area - for (size_t i = 0; i < current_size; i++) - temp[i] = m_data[i]; - - tvfree(m_data); - - m_data = temp; - } - - m_data[current_size] = item; - current_size++; - } - - // indexing - - _Type& operator[](size_t i) - { -#ifdef _DEBUG - assert(i < current_size); - assert(current_size <= allocated_size); -#endif - return m_data[i]; - }; - - const _Type& operator[](size_t i) const - { -#ifdef _DEBUG - assert(i < current_size); - assert(current_size <= allocated_size); -#endif - return m_data[i]; - } - - void Release() - { - tvfree(m_data); - - current_size = 0; - allocated_size = 0; - } - void clear() { Release(); } - size_t size() const { return current_size; } - ~nvVector() { Release(); } -};