From 0d94e9469bc3e6080a71145f35efa559f8f2e522 Mon Sep 17 00:00:00 2001 From: Chuck Walbourn Date: Tue, 12 Jun 2018 18:07:34 -0700 Subject: [PATCH] Fix compiler errors (Clang 6) (#37) --- DirectXTex/BC.cpp | 57 +++++++-------- DirectXTex/BC.h | 2 +- DirectXTex/BC4BC5.cpp | 28 ++++---- DirectXTex/BC6HBC7.cpp | 73 +++++++++---------- DirectXTex/BCDirectCompute.cpp | 6 +- DirectXTex/DDS.h | 8 ++- DirectXTex/DirectXTexCompress.cpp | 2 +- DirectXTex/DirectXTexCompressGPU.cpp | 2 +- DirectXTex/DirectXTexConvert.cpp | 101 +++++++++++++-------------- DirectXTex/DirectXTexD3D11.cpp | 12 ++-- DirectXTex/DirectXTexD3D12.cpp | 26 +++---- DirectXTex/DirectXTexDDS.cpp | 43 +++++++----- DirectXTex/DirectXTexFlipRotate.cpp | 2 +- DirectXTex/DirectXTexHDR.cpp | 18 ++--- DirectXTex/DirectXTexImage.cpp | 2 +- DirectXTex/DirectXTexMipmaps.cpp | 8 +-- DirectXTex/DirectXTexMisc.cpp | 2 +- DirectXTex/DirectXTexNormalMaps.cpp | 3 +- DirectXTex/DirectXTexP.h | 2 + DirectXTex/DirectXTexPMAlpha.cpp | 2 +- DirectXTex/DirectXTexResize.cpp | 4 +- DirectXTex/DirectXTexTGA.cpp | 24 +++---- DirectXTex/DirectXTexUtil.cpp | 89 +++++++++++------------ DirectXTex/DirectXTexWIC.cpp | 8 +-- DirectXTex/Filters.h | 6 +- 25 files changed, 266 insertions(+), 264 deletions(-) diff --git a/DirectXTex/BC.cpp b/DirectXTex/BC.cpp index 0ae366c..8088001 100644 --- a/DirectXTex/BC.cpp +++ b/DirectXTex/BC.cpp @@ -9,7 +9,7 @@ // http://go.microsoft.com/fwlink/?LinkId=248926 //------------------------------------------------------------------------------------- -#include "directxtexp.h" +#include "DirectXTexp.h" // Experiemental encoding variants, not enabled by default //#define COLOR_WEIGHTS @@ -35,9 +35,9 @@ namespace //------------------------------------------------------------------------------------- inline void Decode565(_Out_ HDRColorA *pColor, _In_ const uint16_t w565) { - pColor->r = (float)((w565 >> 11) & 31) * (1.0f / 31.0f); - pColor->g = (float)((w565 >> 5) & 63) * (1.0f / 63.0f); - pColor->b = (float)((w565 >> 0) & 31) * (1.0f / 31.0f); + pColor->r = static_cast((w565 >> 11) & 31) * (1.0f / 31.0f); + pColor->g = static_cast((w565 >> 5) & 63) * (1.0f / 63.0f); + pColor->b = static_cast((w565 >> 0) & 31) * (1.0f / 31.0f); pColor->a = 1.0f; } @@ -51,9 +51,10 @@ namespace uint16_t w; - w = (uint16_t)((static_cast(Color.r * 31.0f + 0.5f) << 11) | - (static_cast(Color.g * 63.0f + 0.5f) << 5) | - (static_cast(Color.b * 31.0f + 0.5f) << 0)); + w = static_cast( + (static_cast(Color.r * 31.0f + 0.5f) << 11) + | (static_cast(Color.g * 63.0f + 0.5f) << 5) + | (static_cast(Color.b * 31.0f + 0.5f) << 0)); return w; } @@ -208,7 +209,7 @@ namespace } // Use Newton's Method to find local minima of sum-of-squares error. - float fSteps = (float)(cSteps - 1); + auto fSteps = static_cast(cSteps - 1); for (size_t iIteration = 0; iIteration < 8; iIteration++) { @@ -431,9 +432,9 @@ namespace Clr.b += Error[i].b; } - Color[i].r = (float) static_cast(Clr.r * 31.0f + 0.5f) * (1.0f / 31.0f); - Color[i].g = (float) static_cast(Clr.g * 63.0f + 0.5f) * (1.0f / 63.0f); - Color[i].b = (float) static_cast(Clr.b * 31.0f + 0.5f) * (1.0f / 31.0f); + Color[i].r = static_cast(static_cast(Clr.r * 31.0f + 0.5f) * (1.0f / 31.0f)); + Color[i].g = static_cast(static_cast(Clr.g * 63.0f + 0.5f) * (1.0f / 63.0f)); + Color[i].b = static_cast(static_cast(Clr.b * 31.0f + 0.5f) * (1.0f / 31.0f)); #ifdef COLOR_WEIGHTS Color[i].a = pColor[i].a; @@ -586,7 +587,7 @@ namespace Dir.g = Step[1].g - Step[0].g; Dir.b = Step[1].b - Step[0].b; - float fSteps = (float)(uSteps - 1); + auto fSteps = static_cast(uSteps - 1); float fScale = (wColorA != wColorB) ? (fSteps / (Dir.r * Dir.r + Dir.g * Dir.g + Dir.b * Dir.b)) : 0.0f; Dir.r *= fScale; @@ -602,7 +603,7 @@ namespace { if ((3 == uSteps) && (pColor[i].a < threshold)) { - dw = (3 << 30) | (dw >> 2); + dw = (3u << 30) | (dw >> 2); } else { @@ -751,7 +752,7 @@ void DirectX::D3DXEncodeBC1(uint8_t *pBC, const XMVECTOR *pColor, float threshol Color[i].r = clr.r; Color[i].g = clr.g; Color[i].b = clr.b; - Color[i].a = (float) static_cast(clr.a + fError[i] + 0.5f); + Color[i].a = static_cast(static_cast(clr.a + fError[i] + 0.5f)); float fDiff = fAlph - Color[i].a; @@ -811,13 +812,13 @@ void DirectX::D3DXDecodeBC2(XMVECTOR *pColor, const uint8_t *pBC) for (size_t i = 0; i < 8; ++i, dw >>= 4) { #pragma prefast(suppress:22103, "writing blocks in two halves confuses tool") - pColor[i] = XMVectorSetW(pColor[i], (float)(dw & 0xf) * (1.0f / 15.0f)); + pColor[i] = XMVectorSetW(pColor[i], static_cast(dw & 0xf) * (1.0f / 15.0f)); } dw = pBC2->bitmap[1]; for (size_t i = 8; i < NUM_PIXELS_PER_BLOCK; ++i, dw >>= 4) - pColor[i] = XMVectorSetW(pColor[i], (float)(dw & 0xf) * (1.0f / 15.0f)); + pColor[i] = XMVectorSetW(pColor[i], static_cast(dw & 0xf) * (1.0f / 15.0f)); } _Use_decl_annotations_ @@ -845,14 +846,14 @@ void DirectX::D3DXEncodeBC2(uint8_t *pBC, const XMVECTOR *pColor, DWORD flags) if (flags & BC_FLAGS_DITHER_A) fAlph += fError[i]; - uint32_t u = (uint32_t) static_cast(fAlph * 15.0f + 0.5f); + auto u = static_cast(fAlph * 15.0f + 0.5f); pBC2->bitmap[i >> 3] >>= 4; pBC2->bitmap[i >> 3] |= (u << 28); if (flags & BC_FLAGS_DITHER_A) { - float fDiff = fAlph - (float)u * (1.0f / 15.0f); + float fDiff = fAlph - float(u) * (1.0f / 15.0f); if (3 != (i & 3)) { @@ -908,8 +909,8 @@ void DirectX::D3DXDecodeBC3(XMVECTOR *pColor, const uint8_t *pBC) // Adaptive 3-bit alpha part float fAlpha[8]; - fAlpha[0] = ((float)pBC3->alpha[0]) * (1.0f / 255.0f); - fAlpha[1] = ((float)pBC3->alpha[1]) * (1.0f / 255.0f); + fAlpha[0] = static_cast(pBC3->alpha[0]) * (1.0f / 255.0f); + fAlpha[1] = static_cast(pBC3->alpha[1]) * (1.0f / 255.0f); if (pBC3->alpha[0] > pBC3->alpha[1]) { @@ -1028,11 +1029,11 @@ void DirectX::D3DXEncodeBC3(uint8_t *pBC, const XMVECTOR *pColor, DWORD flags) float fAlphaA, fAlphaB; OptimizeAlpha(&fAlphaA, &fAlphaB, fAlpha, uSteps); - uint8_t bAlphaA = (uint8_t) static_cast(fAlphaA * 255.0f + 0.5f); - uint8_t bAlphaB = (uint8_t) static_cast(fAlphaB * 255.0f + 0.5f); + auto bAlphaA = static_cast(static_cast(fAlphaA * 255.0f + 0.5f)); + auto bAlphaB = static_cast(static_cast(fAlphaB * 255.0f + 0.5f)); - fAlphaA = (float)bAlphaA * (1.0f / 255.0f); - fAlphaB = (float)bAlphaB * (1.0f / 255.0f); + fAlphaA = static_cast(bAlphaA) * (1.0f / 255.0f); + fAlphaB = static_cast(bAlphaB) * (1.0f / 255.0f); // Setup block if ((8 == uSteps) && (bAlphaA == bAlphaB)) @@ -1080,7 +1081,7 @@ void DirectX::D3DXEncodeBC3(uint8_t *pBC, const XMVECTOR *pColor, DWORD flags) } // Encode alpha bitmap - float fSteps = (float)(uSteps - 1); + auto fSteps = static_cast(uSteps - 1); float fScale = (fStep[0] != fStep[1]) ? (fSteps / (fStep[1] - fStep[0])) : 0.0f; if (flags & BC_FLAGS_DITHER_A) @@ -1130,8 +1131,8 @@ void DirectX::D3DXEncodeBC3(uint8_t *pBC, const XMVECTOR *pColor, DWORD flags) } } - pBC3->bitmap[0 + iSet * 3] = ((uint8_t *)&dw)[0]; - pBC3->bitmap[1 + iSet * 3] = ((uint8_t *)&dw)[1]; - pBC3->bitmap[2 + iSet * 3] = ((uint8_t *)&dw)[2]; + pBC3->bitmap[0 + iSet * 3] = reinterpret_cast(&dw)[0]; + pBC3->bitmap[1 + iSet * 3] = reinterpret_cast(&dw)[1]; + pBC3->bitmap[2 + iSet * 3] = reinterpret_cast(&dw)[2]; } } diff --git a/DirectXTex/BC.h b/DirectXTex/BC.h index 64978e2..3d5a004 100644 --- a/DirectXTex/BC.h +++ b/DirectXTex/BC.h @@ -216,7 +216,7 @@ template void OptimizeAlpha(float *pX, float *pY, const float *pPo } // Use Newton's Method to find local minima of sum-of-squares error. - float fSteps = (float)(cSteps - 1); + auto fSteps = static_cast(cSteps - 1); for (size_t iIteration = 0; iIteration < 8; iIteration++) { diff --git a/DirectXTex/BC4BC5.cpp b/DirectXTex/BC4BC5.cpp index dcfe465..d485bff 100644 --- a/DirectXTex/BC4BC5.cpp +++ b/DirectXTex/BC4BC5.cpp @@ -9,7 +9,7 @@ // http://go.microsoft.com/fwlink/?LinkId=248926 //------------------------------------------------------------------------------------- -#include "directxtexp.h" +#include "DirectXTexp.h" #include "BC.h" @@ -70,13 +70,13 @@ namespace size_t GetIndex(size_t uOffset) const { - return (size_t)((data >> (3 * uOffset + 16)) & 0x07); + return static_cast((data >> (3 * uOffset + 16)) & 0x07); } void SetIndex(size_t uOffset, size_t uIndex) { - data &= ~((uint64_t)0x07 << (3 * uOffset + 16)); - data |= ((uint64_t)uIndex << (3 * uOffset + 16)); + data &= ~(uint64_t(0x07) << (3 * uOffset + 16)); + data |= (uint64_t(uIndex) << (3 * uOffset + 16)); } union @@ -129,13 +129,13 @@ namespace size_t GetIndex(size_t uOffset) const { - return (size_t)((data >> (3 * uOffset + 16)) & 0x07); + return static_cast((data >> (3 * uOffset + 16)) & 0x07); } void SetIndex(size_t uOffset, size_t uIndex) { - data &= ~((uint64_t)0x07 << (3 * uOffset + 16)); - data |= ((uint64_t)uIndex << (3 * uOffset + 16)); + data &= ~(uint64_t(0x07) << (3 * uOffset + 16)); + data |= (uint64_t(uIndex) << (3 * uOffset + 16)); } union @@ -168,14 +168,14 @@ namespace if (fVal < -1) fVal = -1; // Clamp to -1 - fVal = fVal * (int8_t)(dwMostNeg - 1); + fVal = fVal * static_cast(dwMostNeg - 1); if (fVal >= 0) fVal += .5f; else fVal -= .5f; - *piSNorm = (int8_t)(fVal); + *piSNorm = static_cast(fVal); } @@ -216,8 +216,8 @@ namespace // 6 interpolated color values OptimizeAlpha(&fStart, &fEnd, theTexelsU, 8); - uint8_t iStart = static_cast(fStart * 255.0f); - uint8_t iEnd = static_cast(fEnd * 255.0f); + auto iStart = static_cast(fStart * 255.0f); + auto iEnd = static_cast(fEnd * 255.0f); endpointU_0 = iEnd; endpointU_1 = iStart; @@ -227,8 +227,8 @@ namespace // 4 interpolated color values OptimizeAlpha(&fStart, &fEnd, theTexelsU, 6); - uint8_t iStart = static_cast(fStart * 255.0f); - uint8_t iEnd = static_cast(fEnd * 255.0f); + auto iStart = static_cast(fStart * 255.0f); + auto iEnd = static_cast(fEnd * 255.0f); endpointU_1 = iEnd; endpointU_0 = iStart; @@ -559,4 +559,4 @@ void DirectX::D3DXEncodeBC5S(uint8_t *pBC, const XMVECTOR *pColor, DWORD flags) FindClosestSNORM(pBCR, theTexelsU); FindClosestSNORM(pBCG, theTexelsV); -} \ No newline at end of file +} diff --git a/DirectXTex/BC6HBC7.cpp b/DirectXTex/BC6HBC7.cpp index 2fabbaa..23b4d73 100644 --- a/DirectXTex/BC6HBC7.cpp +++ b/DirectXTex/BC6HBC7.cpp @@ -9,7 +9,7 @@ // http://go.microsoft.com/fwlink/?LinkId=248926 //------------------------------------------------------------------------------------- -#include "directxtexp.h" +#include "DirectXTexp.h" #include "BC.h" @@ -428,16 +428,16 @@ namespace DirectX inline HDRColorA& HDRColorA::operator = (const LDRColorA& c) { - r = (float)c.r; - g = (float)c.g; - b = (float)c.b; - a = (float)c.a; + r = static_cast(c.r); + g = static_cast(c.g); + b = static_cast(c.b); + a = static_cast(c.a); return *this; } inline LDRColorA HDRColorA::ToLDRColorA() const { - return LDRColorA((uint8_t)(r + 0.01f), (uint8_t)(g + 0.01f), (uint8_t)(b + 0.01f), (uint8_t)(a + 0.01f)); + return LDRColorA(static_cast(r + 0.01f), static_cast(g + 0.01f), static_cast(b + 0.01f), static_cast(a + 0.01f)); } } @@ -454,11 +454,6 @@ namespace INTColor(int nr, int ng, int nb) : pad(0) { r = nr; g = ng; b = nb; } INTColor(const INTColor& c) : pad(0) { r = c.r; g = c.g; b = c.b; } - INTColor operator - (_In_ const INTColor& c) const - { - return INTColor(r - c.r, g - c.g, b - c.b); - } - INTColor& operator += (_In_ const INTColor& c) { r += c.r; @@ -487,14 +482,14 @@ namespace { assert(i < sizeof(INTColor) / sizeof(int)); _Analysis_assume_(i < sizeof(INTColor) / sizeof(int)); - return ((int*) this)[i]; + return reinterpret_cast(this)[i]; } void Set(_In_ const HDRColorA& c, _In_ bool bSigned) { PackedVector::XMHALF4 aF16; - XMVECTOR v = XMLoadFloat4((const XMFLOAT4*)& c); + XMVECTOR v = XMLoadFloat4(reinterpret_cast(&c)); XMStoreHalf4(&aF16, v); r = F16ToINT(aF16.x, bSigned); @@ -528,7 +523,7 @@ namespace private: static int F16ToINT(_In_ const PackedVector::HALF& f, _In_ bool bSigned) { - uint16_t input = *((const uint16_t*)&f); + uint16_t input = *reinterpret_cast(&f); int out, s; if (bSigned) { @@ -563,10 +558,10 @@ namespace else { assert(input >= 0 && input <= F16MAX); - out = (uint16_t)input; + out = static_cast(input); } - *((uint16_t*)&h) = out; + *reinterpret_cast(&h) = out; return h; } }; @@ -605,7 +600,7 @@ namespace { size_t uFirstIndexBits = 8 - uBase; size_t uNextIndexBits = uNumBits - uFirstIndexBits; - ret = (m_uBits[uIndex] >> uBase) | ((m_uBits[uIndex + 1] & ((1 << uNextIndexBits) - 1)) << uFirstIndexBits); + ret = static_cast((unsigned(m_uBits[uIndex]) >> uBase) | ((unsigned(m_uBits[uIndex + 1]) & ((1u << uNextIndexBits) - 1)) << uFirstIndexBits)); } else { @@ -798,7 +793,7 @@ namespace static uint8_t Quantize(_In_ uint8_t comp, _In_ uint8_t uPrec) { assert(0 < uPrec && uPrec <= 8); - uint8_t rnd = (uint8_t)std::min(255, uint16_t(comp) + (1 << (7 - uPrec))); + uint8_t rnd = std::min(255u, static_cast(unsigned(comp) + (1u << (7 - uPrec)))); return rnd >> (8 - uPrec); } @@ -818,7 +813,7 @@ namespace static uint8_t Unquantize(_In_ uint8_t comp, _In_ size_t uPrec) { assert(0 < uPrec && uPrec <= 8); - comp = comp << (8 - uPrec); + comp = static_cast(unsigned(comp) << (8 - uPrec)); return comp | (comp >> uPrec); } @@ -1280,7 +1275,7 @@ namespace } // Use Newton's Method to find local minima of sum-of-squares error. - float fSteps = (float)(cSteps - 1); + auto fSteps = static_cast(cSteps - 1); for (size_t iIteration = 0; iIteration < 8; iIteration++) { @@ -1472,7 +1467,7 @@ namespace } // Use Newton's Method to find local minima of sum-of-squares error. - float fSteps = (float)(cSteps - 1); + auto fSteps = static_cast(cSteps - 1); for (size_t iIteration = 0; iIteration < 8 && fError > 0.0f; iIteration++) { @@ -1656,7 +1651,7 @@ void D3DX_BC6H::Decode(bool bSigned, HDRColorA* pOut) const uint8_t uMode = GetBits(uStartBit, 2); if (uMode != 0x00 && uMode != 0x01) { - uMode = (GetBits(uStartBit, 3) << 2) | uMode; + uMode = static_cast((unsigned(GetBits(uStartBit, 3)) << 2) | uMode); } assert(uMode < 32); @@ -2035,7 +2030,7 @@ float D3DX_BC6H::MapColorsQuantized(const EncodeParams* pEP, const INTColor aCol assert(pEP); const uint8_t uIndexPrec = ms_aInfo[pEP->uMode].uIndexPrec; - const uint8_t uNumIndices = 1 << uIndexPrec; + auto uNumIndices = static_cast(1u << uIndexPrec); INTColor aPalette[BC6H_MAX_INDICES]; GeneratePaletteQuantized(pEP, endPts, aPalette); @@ -2239,7 +2234,7 @@ void D3DX_BC6H::AssignIndices(const EncodeParams* pEP, const INTEndPntPair aEndP { assert(pEP); const uint8_t uPartitions = ms_aInfo[pEP->uMode].uPartitions; - const uint8_t uNumIndices = 1 << ms_aInfo[pEP->uMode].uIndexPrec; + auto uNumIndices = static_cast(1u << ms_aInfo[pEP->uMode].uIndexPrec); assert(uPartitions < BC6H_MAX_REGIONS && pEP->uShape < BC6H_MAX_SHAPES); _Analysis_assume_(uPartitions < BC6H_MAX_REGIONS && pEP->uShape < BC6H_MAX_SHAPES); @@ -2400,7 +2395,7 @@ void D3DX_BC6H::GeneratePaletteUnquantized(const EncodeParams* pEP, size_t uRegi _Analysis_assume_(uRegion < BC6H_MAX_REGIONS && pEP->uShape < BC6H_MAX_SHAPES); const INTEndPntPair& endPts = pEP->aUnqEndPts[pEP->uShape][uRegion]; const uint8_t uIndexPrec = ms_aInfo[pEP->uMode].uIndexPrec; - const uint8_t uNumIndices = 1 << uIndexPrec; + auto uNumIndices = static_cast(1u << uIndexPrec); assert(uNumIndices > 0); _Analysis_assume_(uNumIndices > 0); @@ -2433,7 +2428,7 @@ float D3DX_BC6H::MapColors(const EncodeParams* pEP, size_t uRegion, size_t np, c { assert(pEP); const uint8_t uIndexPrec = ms_aInfo[pEP->uMode].uIndexPrec; - const uint8_t uNumIndices = 1 << uIndexPrec; + auto uNumIndices = static_cast(1u << uIndexPrec); INTColor aPalette[BC6H_MAX_INDICES]; GeneratePaletteUnquantized(pEP, uRegion, aPalette); @@ -2535,7 +2530,7 @@ void D3DX_BC7::Decode(HDRColorA* pOut) const assert(uPartitions < BC7_MAX_REGIONS); _Analysis_assume_(uPartitions < BC7_MAX_REGIONS); - const uint8_t uNumEndPts = (uPartitions + 1) << 1; + auto uNumEndPts = static_cast((unsigned(uPartitions) + 1u) << 1); const uint8_t uIndexPrec = ms_aInfo[uMode].uIndexPrec; const uint8_t uIndexPrec2 = ms_aInfo[uMode].uIndexPrec2; size_t i; @@ -2643,7 +2638,7 @@ void D3DX_BC7::Decode(HDRColorA* pOut) const { if (RGBAPrec[ch] != RGBAPrecWithP[ch]) { - c[i][ch] = (c[i][ch] << 1) | P[pi]; + c[i][ch] = static_cast((unsigned(c[i][ch]) << 1) | P[pi]); } } } @@ -2879,7 +2874,7 @@ float D3DX_BC7::PerturbOne(const EncodeParams* pEP, const LDRColorA aColors[], s if (tmp < 0 || tmp >= (1 << prec)) continue; else - *ptmp_c = (uint8_t)tmp; + *ptmp_c = static_cast(tmp); float fTotalErr = MapColors(pEP, aColors, np, uIndexMode, tmp_endPts, fMinErr); if (fTotalErr < fMinErr) @@ -2928,8 +2923,8 @@ void D3DX_BC7::Exhaustive(const EncodeParams* pEP, const LDRColorA aColors[], si { for (int b = std::max(a, blow); b < bhigh; ++b) { - tmpEndPt.A[ch] = (uint8_t)a; - tmpEndPt.B[ch] = (uint8_t)b; + tmpEndPt.A[ch] = static_cast(a); + tmpEndPt.B[ch] = static_cast(b); float fErr = MapColors(pEP, aColors, np, uIndexMode, tmpEndPt, fBestErr); if (fErr < fBestErr) @@ -2948,8 +2943,8 @@ void D3DX_BC7::Exhaustive(const EncodeParams* pEP, const LDRColorA aColors[], si { for (int a = std::max(b, alow); a <= ahigh; ++a) { - tmpEndPt.A[ch] = (uint8_t)a; - tmpEndPt.B[ch] = (uint8_t)b; + tmpEndPt.A[ch] = static_cast(a); + tmpEndPt.B[ch] = static_cast(b); float fErr = MapColors(pEP, aColors, np, uIndexMode, tmpEndPt, fBestErr); if (fErr < fBestErr) @@ -2964,8 +2959,8 @@ void D3DX_BC7::Exhaustive(const EncodeParams* pEP, const LDRColorA aColors[], si if (fBestErr < fOrgErr) { - optEndPt.A[ch] = (uint8_t)amin; - optEndPt.B[ch] = (uint8_t)bmin; + optEndPt.A[ch] = static_cast(amin); + optEndPt.B[ch] = static_cast(bmin); fOrgErr = fBestErr; } } @@ -3073,8 +3068,8 @@ void D3DX_BC7::AssignIndices(const EncodeParams* pEP, size_t uShape, size_t uInd const uint8_t uIndexPrec = uIndexMode ? ms_aInfo[pEP->uMode].uIndexPrec2 : ms_aInfo[pEP->uMode].uIndexPrec; const uint8_t uIndexPrec2 = uIndexMode ? ms_aInfo[pEP->uMode].uIndexPrec : ms_aInfo[pEP->uMode].uIndexPrec2; - const uint8_t uNumIndices = 1 << uIndexPrec; - const uint8_t uNumIndices2 = 1 << uIndexPrec2; + auto uNumIndices = static_cast(1u << uIndexPrec); + auto uNumIndices2 = static_cast(1u << uIndexPrec2); assert((uNumIndices <= BC7_MAX_INDICES) && (uNumIndices2 <= BC7_MAX_INDICES)); _Analysis_assume_((uNumIndices <= BC7_MAX_INDICES) && (uNumIndices2 <= BC7_MAX_INDICES)); @@ -3312,8 +3307,8 @@ float D3DX_BC7::RoughMSE(EncodeParams* pEP, size_t uShape, size_t uIndexMode) const uint8_t uIndexPrec = uIndexMode ? ms_aInfo[pEP->uMode].uIndexPrec2 : ms_aInfo[pEP->uMode].uIndexPrec; const uint8_t uIndexPrec2 = uIndexMode ? ms_aInfo[pEP->uMode].uIndexPrec : ms_aInfo[pEP->uMode].uIndexPrec2; - const uint8_t uNumIndices = 1 << uIndexPrec; - const uint8_t uNumIndices2 = 1 << uIndexPrec2; + auto uNumIndices = static_cast(1u << uIndexPrec); + auto uNumIndices2 = static_cast(1u << uIndexPrec2); size_t auPixIdx[NUM_PIXELS_PER_BLOCK]; LDRColorA aPalette[BC7_MAX_REGIONS][BC7_MAX_INDICES]; diff --git a/DirectXTex/BCDirectCompute.cpp b/DirectXTex/BCDirectCompute.cpp index 3e0d0fb..940618c 100644 --- a/DirectXTex/BCDirectCompute.cpp +++ b/DirectXTex/BCDirectCompute.cpp @@ -7,7 +7,7 @@ // Licensed under the MIT License. //------------------------------------------------------------------------------------- -#include "directxtexp.h" +#include "DirectXTexp.h" #include "BCDirectCompute.h" @@ -427,7 +427,7 @@ HRESULT GPUCompressBC::Compress(const Image& srcImage, const Image& destImage) size_t xblocks = std::max(1, (m_width + 3) >> 2); size_t yblocks = std::max(1, (m_height + 3) >> 2); - UINT num_total_blocks = static_cast(xblocks * yblocks); + auto num_total_blocks = static_cast(xblocks * yblocks); UINT num_blocks = num_total_blocks; int start_block_id = 0; while (num_blocks > 0) @@ -608,4 +608,4 @@ HRESULT GPUCompressBC::Compress(const Image& srcImage, const Image& destImage) } return hr; -} \ No newline at end of file +} diff --git a/DirectXTex/DDS.h b/DirectXTex/DDS.h index 81fc348..59a274c 100644 --- a/DirectXTex/DDS.h +++ b/DirectXTex/DDS.h @@ -50,9 +50,11 @@ struct DDS_PIXELFORMAT #define DDS_BUMPDUDV 0x00080000 // DDPF_BUMPDUDV #ifndef MAKEFOURCC - #define MAKEFOURCC(ch0, ch1, ch2, ch3) \ - ((uint32_t)(uint8_t)(ch0) | ((uint32_t)(uint8_t)(ch1) << 8) | \ - ((uint32_t)(uint8_t)(ch2) << 16) | ((uint32_t)(uint8_t)(ch3) << 24 )) + #define MAKEFOURCC(ch0, ch1, ch2, ch3) \ + (static_cast(static_cast(ch0)) \ + | (static_cast(static_cast(ch1)) << 8) \ + | (static_cast(static_cast(ch2)) << 16) \ + | (static_cast(static_cast(ch3)) << 24)) #endif /* defined(MAKEFOURCC) */ extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_DXT1 = diff --git a/DirectXTex/DirectXTexCompress.cpp b/DirectXTex/DirectXTexCompress.cpp index f0b51f1..b6ab056 100644 --- a/DirectXTex/DirectXTexCompress.cpp +++ b/DirectXTex/DirectXTexCompress.cpp @@ -9,7 +9,7 @@ // http://go.microsoft.com/fwlink/?LinkId=248926 //------------------------------------------------------------------------------------- -#include "directxtexp.h" +#include "DirectXTexp.h" #ifdef _OPENMP #include diff --git a/DirectXTex/DirectXTexCompressGPU.cpp b/DirectXTex/DirectXTexCompressGPU.cpp index c058e67..799ee55 100644 --- a/DirectXTex/DirectXTexCompressGPU.cpp +++ b/DirectXTex/DirectXTexCompressGPU.cpp @@ -9,7 +9,7 @@ // http://go.microsoft.com/fwlink/?LinkId=248926 //------------------------------------------------------------------------------------- -#include "directxtexp.h" +#include "DirectXTexp.h" #include "bcdirectcompute.h" diff --git a/DirectXTex/DirectXTexConvert.cpp b/DirectXTex/DirectXTexConvert.cpp index 901a8f3..61cf7cf 100644 --- a/DirectXTex/DirectXTexConvert.cpp +++ b/DirectXTex/DirectXTexConvert.cpp @@ -9,7 +9,7 @@ // http://go.microsoft.com/fwlink/?LinkId=248926 //------------------------------------------------------------------------------------- -#include "directxtexp.h" +#include "DirectXTexp.h" using namespace DirectX; using namespace DirectX::PackedVector; @@ -52,12 +52,12 @@ namespace inline float FloatFrom7e3(uint32_t Value) { - uint32_t Mantissa = (uint32_t)(Value & 0x7F); + auto Mantissa = static_cast(Value & 0x7F); uint32_t Exponent = (Value & 0x380); if (Exponent != 0) // The value is normalized { - Exponent = (uint32_t)((Value >> 7) & 0x7); + Exponent = static_cast((Value >> 7) & 0x7); } else if (Mantissa != 0) // The value is denormalized { @@ -74,7 +74,7 @@ namespace } else // The value is zero { - Exponent = (uint32_t)-124; + Exponent = uint32_t(-124); } uint32_t Result = ((Exponent + 124) << 23) | // Exponent @@ -118,12 +118,12 @@ namespace inline float FloatFrom6e4(uint32_t Value) { - uint32_t Mantissa = (uint32_t)(Value & 0x3F); + uint32_t Mantissa = static_cast(Value & 0x3F); uint32_t Exponent = (Value & 0x3C0); if (Exponent != 0) // The value is normalized { - Exponent = (uint32_t)((Value >> 6) & 0xF); + Exponent = static_cast((Value >> 6) & 0xF); } else if (Mantissa != 0) // The value is denormalized { @@ -140,7 +140,7 @@ namespace } else // The value is zero { - Exponent = (uint32_t)-120; + Exponent = uint32_t(-120); } uint32_t Result = ((Exponent + 120) << 23) | // Exponent @@ -762,7 +762,7 @@ _Use_decl_annotations_ bool DirectX::_LoadScanline( size_t size, DXGI_FORMAT format) { - assert(pDestination && count > 0 && (((uintptr_t)pDestination & 0xF) == 0)); + assert(pDestination && count > 0 && ((reinterpret_cast(pDestination) & 0xF) == 0)); assert(pSource && size > 0); assert(IsValid(format) && !IsTypeless(format, false) && !IsCompressed(format) && !IsPlanar(format) && !IsPalettized(format)); @@ -828,7 +828,7 @@ _Use_decl_annotations_ bool DirectX::_LoadScanline( auto sPtr = static_cast(pSource); for (size_t icount = 0; icount < (size - psize + 1); icount += psize) { - const uint8_t* ps8 = reinterpret_cast(&sPtr[1]); + auto ps8 = reinterpret_cast(&sPtr[1]); if (dPtr >= ePtr) break; *(dPtr++) = XMVectorSet(sPtr[0], static_cast(*ps8), 0.f, 1.f); sPtr += 2; @@ -863,7 +863,7 @@ _Use_decl_annotations_ bool DirectX::_LoadScanline( auto sPtr = static_cast(pSource); for (size_t icount = 0; icount < (size - psize + 1); icount += psize) { - const uint8_t* pg8 = reinterpret_cast(&sPtr[1]); + auto pg8 = reinterpret_cast(&sPtr[1]); if (dPtr >= ePtr) break; *(dPtr++) = XMVectorSet(0.f /* typeless component assumed zero */, static_cast(*pg8), 0.f, 1.f); sPtr += 2; @@ -964,8 +964,8 @@ _Use_decl_annotations_ bool DirectX::_LoadScanline( auto sPtr = static_cast(pSource); for (size_t icount = 0; icount < (size - sizeof(uint32_t) + 1); icount += sizeof(uint32_t)) { - float d = static_cast(*sPtr & 0xFFFFFF) / 16777215.f; - float s = static_cast((*sPtr & 0xFF000000) >> 24); + auto d = static_cast(*sPtr & 0xFFFFFF) / 16777215.f; + auto s = static_cast((*sPtr & 0xFF000000) >> 24); ++sPtr; if (dPtr >= ePtr) break; *(dPtr++) = XMVectorSet(d, s, 0.f, 1.f); @@ -980,7 +980,7 @@ _Use_decl_annotations_ bool DirectX::_LoadScanline( auto sPtr = static_cast(pSource); for (size_t icount = 0; icount < (size - sizeof(uint32_t) + 1); icount += sizeof(uint32_t)) { - float r = static_cast(*sPtr & 0xFFFFFF) / 16777215.f; + auto r = static_cast(*sPtr & 0xFFFFFF) / 16777215.f; ++sPtr; if (dPtr >= ePtr) break; *(dPtr++) = XMVectorSet(r, 0.f /* typeless component assumed zero */, 0.f, 1.f); @@ -995,7 +995,7 @@ _Use_decl_annotations_ bool DirectX::_LoadScanline( auto sPtr = static_cast(pSource); for (size_t icount = 0; icount < (size - sizeof(uint32_t) + 1); icount += sizeof(uint32_t)) { - float g = static_cast((*sPtr & 0xFF000000) >> 24); + auto g = static_cast((*sPtr & 0xFF000000) >> 24); ++sPtr; if (dPtr >= ePtr) break; *(dPtr++) = XMVectorSet(0.f /* typeless component assumed zero */, g, 0.f, 1.f); @@ -1325,9 +1325,9 @@ _Use_decl_annotations_ bool DirectX::_LoadScanline( // G = 1.1678Y' - 0.3929Cb' - 0.8152Cr' // B = 1.1678Y' + 2.0232Cb' - int r = static_cast((76533 * y + 104905 * v + 32768) >> 16); - int g = static_cast((76533 * y - 25747 * u - 53425 * v + 32768) >> 16); - int b = static_cast((76533 * y + 132590 * u + 32768) >> 16); + auto r = static_cast((76533 * y + 104905 * v + 32768) >> 16); + auto g = static_cast((76533 * y - 25747 * u - 53425 * v + 32768) >> 16); + auto b = static_cast((76533 * y + 132590 * u + 32768) >> 16); if (dPtr >= ePtr) break; *(dPtr++) = XMVectorSet(float(std::min(std::max(r, 0), 1023)) / 1023.f, @@ -1426,9 +1426,9 @@ _Use_decl_annotations_ bool DirectX::_LoadScanline( ++sPtr; // See Y410 - int r = static_cast((76533 * y0 + 104905 * v + 32768) >> 16); - int g = static_cast((76533 * y0 - 25747 * u - 53425 * v + 32768) >> 16); - int b = static_cast((76533 * y0 + 132590 * u + 32768) >> 16); + auto r = static_cast((76533 * y0 + 104905 * v + 32768) >> 16); + auto g = static_cast((76533 * y0 - 25747 * u - 53425 * v + 32768) >> 16); + auto b = static_cast((76533 * y0 + 132590 * u + 32768) >> 16); if (dPtr >= ePtr) break; *(dPtr++) = XMVectorSet(float(std::min(std::max(r, 0), 1023)) / 1023.f, @@ -1463,9 +1463,9 @@ _Use_decl_annotations_ bool DirectX::_LoadScanline( ++sPtr; // See Y416 - int r = static_cast((76607 * y0 + 105006 * v + 32768) >> 16); - int g = static_cast((76607 * y0 - 25772 * u - 53477 * v + 32768) >> 16); - int b = static_cast((76607 * y0 + 132718 * u + 32768) >> 16); + auto r = static_cast((76607 * y0 + 105006 * v + 32768) >> 16); + auto g = static_cast((76607 * y0 - 25772 * u - 53477 * v + 32768) >> 16); + auto b = static_cast((76607 * y0 + 132718 * u + 32768) >> 16); if (dPtr >= ePtr) break; *(dPtr++) = XMVectorSet(float(std::min(std::max(r, 0), 65535)) / 65535.f, @@ -1516,7 +1516,7 @@ _Use_decl_annotations_ bool DirectX::_LoadScanline( FloatFrom7e3(sPtr->x), FloatFrom7e3(sPtr->y), FloatFrom7e3(sPtr->z), - (float)(sPtr->v >> 30) / 3.0f + static_cast(sPtr->v >> 30) / 3.0f } } }; ++sPtr; @@ -1540,7 +1540,7 @@ _Use_decl_annotations_ bool DirectX::_LoadScanline( FloatFrom6e4(sPtr->x), FloatFrom6e4(sPtr->y), FloatFrom6e4(sPtr->z), - (float)(sPtr->v >> 30) / 3.0f + static_cast(sPtr->v >> 30) / 3.0f } } }; ++sPtr; @@ -1612,7 +1612,7 @@ bool DirectX::_StoreScanline( float threshold) { assert(pDestination && size > 0); - assert(pSource && count > 0 && (((uintptr_t)pSource & 0xF) == 0)); + assert(pSource && count > 0 && ((reinterpret_cast(pSource) & 0xF) == 0)); assert(IsValid(format) && !IsTypeless(format) && !IsCompressed(format) && !IsPlanar(format) && !IsPalettized(format)); const XMVECTOR* __restrict sPtr = pSource; @@ -1689,7 +1689,7 @@ bool DirectX::_StoreScanline( XMFLOAT4 f; XMStoreFloat4(&f, *sPtr++); dPtr[0] = f.x; - uint8_t* ps8 = reinterpret_cast(&dPtr[1]); + auto ps8 = reinterpret_cast(&dPtr[1]); ps8[0] = static_cast(std::min(255.f, std::max(0.f, f.y))); ps8[1] = ps8[2] = ps8[3] = 0; dPtr += 2; @@ -2417,7 +2417,7 @@ bool DirectX::_StoreScanline( dPtr->x = FloatTo6e4(tmp.x); dPtr->y = FloatTo6e4(tmp.y); dPtr->z = FloatTo6e4(tmp.z); - dPtr->w = (uint32_t)tmp.w; + dPtr->w = static_cast(tmp.w); ++dPtr; } return true; @@ -2645,7 +2645,7 @@ bool DirectX::_StoreScanlineLinear( float threshold) { assert(pDestination && size > 0); - assert(pSource && count > 0 && (((uintptr_t)pSource & 0xF) == 0)); + assert(pSource && count > 0 && ((reinterpret_cast(pSource) & 0xF) == 0)); assert(IsValid(format) && !IsTypeless(format) && !IsCompressed(format) && !IsPlanar(format) && !IsPalettized(format)); switch (format) @@ -2719,7 +2719,7 @@ bool DirectX::_LoadScanlineLinear( DXGI_FORMAT format, DWORD flags) { - assert(pDestination && count > 0 && (((uintptr_t)pDestination & 0xF) == 0)); + assert(pDestination && count > 0 && ((reinterpret_cast(pDestination) & 0xF) == 0)); assert(pSource && size > 0); assert(IsValid(format) && !IsTypeless(format, false) && !IsCompressed(format) && !IsPlanar(format) && !IsPalettized(format)); @@ -2906,9 +2906,9 @@ DWORD DirectX::_GetConvertFlags(DXGI_FORMAT format) } #endif - ConvertData key = { format, 0 }; - const ConvertData* in = (const ConvertData*)bsearch_s(&key, g_ConvertTable, _countof(g_ConvertTable), sizeof(ConvertData), - ConvertCompare, nullptr); + ConvertData key = { format, 0, 0 }; + auto in = reinterpret_cast(bsearch_s(&key, g_ConvertTable, _countof(g_ConvertTable), sizeof(ConvertData), + ConvertCompare, nullptr)); return (in) ? in->flags : 0; } @@ -2920,7 +2920,7 @@ void DirectX::_ConvertScanline( DXGI_FORMAT inFormat, DWORD flags) { - assert(pBuffer && count > 0 && (((uintptr_t)pBuffer & 0xF) == 0)); + assert(pBuffer && count > 0 && ((reinterpret_cast(pBuffer) & 0xF) == 0)); assert(IsValid(outFormat) && !IsTypeless(outFormat) && !IsPlanar(outFormat) && !IsPalettized(outFormat)); assert(IsValid(inFormat) && !IsTypeless(inFormat) && !IsPlanar(inFormat) && !IsPalettized(inFormat)); @@ -2939,12 +2939,12 @@ void DirectX::_ConvertScanline( #endif // Determine conversion details about source and dest formats - ConvertData key = { inFormat, 0 }; - const ConvertData* in = (const ConvertData*)bsearch_s(&key, g_ConvertTable, _countof(g_ConvertTable), sizeof(ConvertData), - ConvertCompare, nullptr); + ConvertData key = { inFormat, 0, 0 }; + auto in = reinterpret_cast( + bsearch_s(&key, g_ConvertTable, _countof(g_ConvertTable), sizeof(ConvertData), ConvertCompare, nullptr)); key.format = outFormat; - const ConvertData* out = (const ConvertData*)bsearch_s(&key, g_ConvertTable, _countof(g_ConvertTable), sizeof(ConvertData), - ConvertCompare, nullptr); + auto out = reinterpret_cast( + bsearch_s(&key, g_ConvertTable, _countof(g_ConvertTable), sizeof(ConvertData), ConvertCompare, nullptr)); if (!in || !out) { assert(false); @@ -3637,7 +3637,7 @@ namespace type * __restrict dest = reinterpret_cast(pDestination); \ for(size_t i = 0; i < count; ++i) \ { \ - ptrdiff_t index = static_cast((row & 1) ? (count - i - 1) : i ); \ + auto index = static_cast((row & 1) ? (count - i - 1) : i ); \ ptrdiff_t delta = (row & 1) ? -2 : 0; \ \ XMVECTOR v = sPtr[ index ]; \ @@ -3693,7 +3693,7 @@ namespace type * __restrict dest = reinterpret_cast(pDestination); \ for(size_t i = 0; i < count; ++i) \ { \ - ptrdiff_t index = static_cast((row & 1) ? (count - i - 1) : i ); \ + auto index = static_cast((row & 1) ? (count - i - 1) : i ); \ ptrdiff_t delta = (row & 1) ? -2 : 0; \ \ XMVECTOR v = sPtr[ index ]; \ @@ -3746,7 +3746,7 @@ namespace type * __restrict dest = reinterpret_cast(pDestination); \ for(size_t i = 0; i < count; ++i) \ { \ - ptrdiff_t index = static_cast((row & 1) ? (count - i - 1) : i ); \ + auto index = static_cast((row & 1) ? (count - i - 1) : i ); \ ptrdiff_t delta = (row & 1) ? -2 : 0; \ \ XMVECTOR v = sPtr[ index ]; \ @@ -3805,7 +3805,7 @@ bool DirectX::_StoreScanlineDither( XMVECTOR* pDiffusionErrors) { assert(pDestination && size > 0); - assert(pSource && count > 0 && (((uintptr_t)pSource & 0xF) == 0)); + assert(pSource && count > 0 && ((reinterpret_cast(pSource) & 0xF) == 0)); assert(IsValid(format) && !IsTypeless(format) && !IsCompressed(format) && !IsPlanar(format) && !IsPalettized(format)); XMVECTOR ordered[4]; @@ -3879,7 +3879,7 @@ bool DirectX::_StoreScanlineDither( XMUDEC4 * __restrict dest = static_cast(pDestination); for (size_t i = 0; i < count; ++i) { - ptrdiff_t index = static_cast((y & 1) ? (count - i - 1) : i); + auto index = static_cast((y & 1) ? (count - i - 1) : i); ptrdiff_t delta = (y & 1) ? -2 : 0; XMVECTOR v = XMVectorClamp(sPtr[index], MinXR, MaxXR); @@ -3957,7 +3957,7 @@ bool DirectX::_StoreScanlineDither( uint32_t * __restrict dest = static_cast(pDestination); for (size_t i = 0; i < count; ++i) { - ptrdiff_t index = static_cast((y & 1) ? (count - i - 1) : i); + auto index = static_cast((y & 1) ? (count - i - 1) : i); ptrdiff_t delta = (y & 1) ? -2 : 0; XMVECTOR v = XMVectorClamp(sPtr[index], g_XMZero, Clamp); @@ -4044,7 +4044,7 @@ bool DirectX::_StoreScanlineDither( XMU565 * __restrict dest = static_cast(pDestination); for (size_t i = 0; i < count; ++i) { - ptrdiff_t index = static_cast((y & 1) ? (count - i - 1) : i); + auto index = static_cast((y & 1) ? (count - i - 1) : i); ptrdiff_t delta = (y & 1) ? -2 : 0; XMVECTOR v = XMVectorSwizzle<2, 1, 0, 3>(sPtr[index]); @@ -4093,7 +4093,7 @@ bool DirectX::_StoreScanlineDither( XMU555 * __restrict dest = static_cast(pDestination); for (size_t i = 0; i < count; ++i) { - ptrdiff_t index = static_cast((y & 1) ? (count - i - 1) : i); + auto index = static_cast((y & 1) ? (count - i - 1) : i); ptrdiff_t delta = (y & 1) ? -2 : 0; XMVECTOR v = XMVectorSwizzle<2, 1, 0, 3>(sPtr[index]); @@ -4148,7 +4148,7 @@ bool DirectX::_StoreScanlineDither( XMUBYTEN4 * __restrict dest = static_cast(pDestination); for (size_t i = 0; i < count; ++i) { - ptrdiff_t index = static_cast((y & 1) ? (count - i - 1) : i); + auto index = static_cast((y & 1) ? (count - i - 1) : i); ptrdiff_t delta = (y & 1) ? -2 : 0; XMVECTOR v = XMVectorSwizzle<2, 1, 0, 3>(sPtr[index]); @@ -4204,7 +4204,7 @@ bool DirectX::_StoreScanlineDither( uint8_t * __restrict dest = static_cast(pDestination); for (size_t i = 0; i < count; ++i) { - ptrdiff_t index = static_cast((y & 1) ? (count - i - 1) : i); + auto index = static_cast((y & 1) ? (count - i - 1) : i); ptrdiff_t delta = (y & 1) ? -2 : 0; XMVECTOR v = XMVectorSaturate(sPtr[index]); @@ -4238,8 +4238,7 @@ bool DirectX::_StoreScanlineDither( auto dPtr = &dest[index]; if (dPtr >= ePtr) break; - *dPtr = (static_cast(tmp.x) & 0xF) - | ((static_cast(tmp.y) & 0xF) << 4); + *dPtr = static_cast((unsigned(tmp.x) & 0xF) | ((unsigned(tmp.y) & 0xF) << 4)); } return true; } diff --git a/DirectXTex/DirectXTexD3D11.cpp b/DirectXTex/DirectXTexD3D11.cpp index 257d9c0..ede4eed 100644 --- a/DirectXTex/DirectXTexD3D11.cpp +++ b/DirectXTex/DirectXTexD3D11.cpp @@ -9,7 +9,7 @@ // http://go.microsoft.com/fwlink/?LinkId=248926 //------------------------------------------------------------------------------------- -#include "directxtexp.h" +#include "DirectXTexp.h" #if !defined(_XBOX_ONE) || !defined(_TITLE) #include @@ -763,7 +763,7 @@ HRESULT DirectX::CaptureTexture( desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ; desc.Usage = D3D11_USAGE_STAGING; - hr = pDevice->CreateTexture1D(&desc, 0, pStaging.GetAddressOf()); + hr = pDevice->CreateTexture1D(&desc, nullptr, pStaging.GetAddressOf()); if (FAILED(hr)) break; @@ -809,7 +809,7 @@ HRESULT DirectX::CaptureTexture( desc.SampleDesc.Quality = 0; ComPtr pTemp; - hr = pDevice->CreateTexture2D(&desc, 0, pTemp.GetAddressOf()); + hr = pDevice->CreateTexture2D(&desc, nullptr, pTemp.GetAddressOf()); if (FAILED(hr)) break; @@ -848,7 +848,7 @@ HRESULT DirectX::CaptureTexture( desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ; desc.Usage = D3D11_USAGE_STAGING; - hr = pDevice->CreateTexture2D(&desc, 0, pStaging.GetAddressOf()); + hr = pDevice->CreateTexture2D(&desc, nullptr, pStaging.GetAddressOf()); if (FAILED(hr)) break; @@ -868,7 +868,7 @@ HRESULT DirectX::CaptureTexture( desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ; desc.Usage = D3D11_USAGE_STAGING; - hr = pDevice->CreateTexture2D(&desc, 0, &pStaging); + hr = pDevice->CreateTexture2D(&desc, nullptr, &pStaging); if (FAILED(hr)) break; @@ -921,7 +921,7 @@ HRESULT DirectX::CaptureTexture( desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ; desc.Usage = D3D11_USAGE_STAGING; - hr = pDevice->CreateTexture3D(&desc, 0, pStaging.GetAddressOf()); + hr = pDevice->CreateTexture3D(&desc, nullptr, pStaging.GetAddressOf()); if (FAILED(hr)) break; diff --git a/DirectXTex/DirectXTexD3D12.cpp b/DirectXTex/DirectXTexD3D12.cpp index a8d2ba0..de43850 100644 --- a/DirectXTex/DirectXTexD3D12.cpp +++ b/DirectXTex/DirectXTexD3D12.cpp @@ -9,7 +9,7 @@ // http://go.microsoft.com/fwlink/?LinkId=248926 //------------------------------------------------------------------------------------- -#include "directxtexp.h" +#include "DirectXTexp.h" #if defined(_XBOX_ONE) && defined(_TITLE) #include "d3dx12_x.h" @@ -52,7 +52,7 @@ namespace else { // Plane 1 - res.pData = (uint8_t*)(res.pData) + res.RowPitch * height; + res.pData = const_cast(reinterpret_cast(res.pData) + res.RowPitch * height); res.SlicePitch = res.RowPitch * ((height + 1) >> 1); } break; @@ -66,7 +66,7 @@ namespace else { // Plane 1 - res.pData = (uint8_t*)(res.pData) + res.RowPitch * height; + res.pData = const_cast(reinterpret_cast(res.pData) + res.RowPitch * height); res.RowPitch = (res.RowPitch >> 1); res.SlicePitch = res.RowPitch * height; } @@ -82,8 +82,8 @@ namespace _In_ D3D12_RESOURCE_STATES stateBefore, _In_ D3D12_RESOURCE_STATES stateAfter) { - assert(commandList != 0); - assert(resource != 0); + assert(commandList != nullptr); + assert(resource != nullptr); if (stateBefore == stateAfter) return; @@ -223,7 +223,7 @@ namespace fmt = MakeTypelessFLOAT(fmt); } - D3D12_FEATURE_DATA_FORMAT_SUPPORT formatInfo = { fmt }; + D3D12_FEATURE_DATA_FORMAT_SUPPORT formatInfo = { fmt, D3D12_FORMAT_SUPPORT1_NONE, D3D12_FORMAT_SUPPORT2_NONE }; hr = device->CheckFeatureSupport(D3D12_FEATURE_FORMAT_SUPPORT, &formatInfo, sizeof(formatInfo)); if (FAILED(hr)) return hr; @@ -278,7 +278,7 @@ namespace return hr; // Execute the command list - pCommandQ->ExecuteCommandLists(1, (ID3D12CommandList**)commandList.GetAddressOf()); + pCommandQ->ExecuteCommandLists(1, CommandListCast(commandList.GetAddressOf())); // Signal the fence hr = pCommandQ->Signal(fence.Get(), 1); @@ -326,7 +326,7 @@ bool DirectX::IsSupportedTexture( size_t iDepth = metadata.depth; // Most cases are known apriori based on feature level, but we use this for robustness to handle the few optional cases - D3D12_FEATURE_DATA_FORMAT_SUPPORT formatSupport = { fmt }; + D3D12_FEATURE_DATA_FORMAT_SUPPORT formatSupport = { fmt, D3D12_FORMAT_SUPPORT1_NONE, D3D12_FORMAT_SUPPORT2_NONE }; HRESULT hr = pDevice->CheckFeatureSupport(D3D12_FEATURE_FORMAT_SUPPORT, &formatSupport, sizeof(formatSupport)); if (FAILED(hr)) { @@ -349,7 +349,7 @@ bool DirectX::IsSupportedTexture( return false; { - UINT numberOfResources = static_cast(arraySize * metadata.mipLevels); + auto numberOfResources = static_cast(arraySize * metadata.mipLevels); if (numberOfResources > D3D12_REQ_SUBRESOURCES) return false; } @@ -378,7 +378,7 @@ bool DirectX::IsSupportedTexture( } { - UINT numberOfResources = static_cast(arraySize * metadata.mipLevels); + auto numberOfResources = static_cast(arraySize * metadata.mipLevels); if (numberOfResources > D3D12_REQ_SUBRESOURCES) return false; } @@ -395,7 +395,7 @@ bool DirectX::IsSupportedTexture( return false; { - UINT numberOfResources = static_cast(metadata.mipLevels); + auto numberOfResources = static_cast(metadata.mipLevels); if (numberOfResources > D3D12_REQ_SUBRESOURCES) return false; } @@ -785,7 +785,7 @@ HRESULT DirectX::CaptureTexture( static_cast(pLayout[dindex].Footprint.RowPitch * pNumRows[dindex]) }; - if (pRowSizesInBytes[dindex] > (SIZE_T)-1) + if (pRowSizesInBytes[dindex] > SIZE_T(-1)) { pStaging->Unmap(0, nullptr); result.Release(); @@ -793,7 +793,7 @@ HRESULT DirectX::CaptureTexture( } MemcpySubresource(&destData, &srcData, - (SIZE_T)pRowSizesInBytes[dindex], + static_cast(pRowSizesInBytes[dindex]), pNumRows[dindex], pLayout[dindex].Footprint.Depth); } diff --git a/DirectXTex/DirectXTexDDS.cpp b/DirectXTex/DirectXTexDDS.cpp index d46d03d..8044339 100644 --- a/DirectXTex/DirectXTexDDS.cpp +++ b/DirectXTex/DirectXTexDDS.cpp @@ -9,7 +9,7 @@ // http://go.microsoft.com/fwlink/?LinkId=248926 //------------------------------------------------------------------------------------- -#include "directxtexp.h" +#include "DirectXTexp.h" #include "dds.h" @@ -287,7 +287,7 @@ namespace return E_FAIL; } - auto pHeader = reinterpret_cast((const uint8_t*)pSource + sizeof(uint32_t)); + auto pHeader = reinterpret_cast(static_cast(pSource) + sizeof(uint32_t)); // Verify header to validate DDS file if (pHeader->size != sizeof(DDS_HEADER) @@ -310,7 +310,7 @@ namespace return E_FAIL; } - auto d3d10ext = reinterpret_cast((const uint8_t*)pSource + sizeof(uint32_t) + sizeof(DDS_HEADER)); + auto d3d10ext = reinterpret_cast(static_cast(pSource) + sizeof(uint32_t) + sizeof(DDS_HEADER)); convFlags |= CONV_FLAGS_DX10; metadata.arraySize = d3d10ext->arraySize; @@ -504,6 +504,7 @@ namespace convFlags |= CONV_FLAGS_EXPAND; if (metadata.format == DXGI_FORMAT_B5G6R5_UNORM) convFlags |= CONV_FLAGS_NOALPHA; + break; default: break; @@ -877,13 +878,13 @@ namespace for (size_t ocount = 0, icount = 0; ((icount < inSize) && (ocount < (outSize - 1))); ++icount, ocount += 2) { - uint8_t t = *(sPtr++); + unsigned t = *(sPtr++); - uint16_t t1 = ((t & 0xe0) << 8) | ((t & 0xc0) << 5); - uint16_t t2 = ((t & 0x1c) << 6) | ((t & 0x1c) << 3); - uint16_t t3 = ((t & 0x03) << 3) | ((t & 0x03) << 1) | ((t & 0x02) >> 1); + unsigned t1 = ((t & 0xe0u) << 8) | ((t & 0xc0u) << 5); + unsigned t2 = ((t & 0x1cu) << 6) | ((t & 0x1cu) << 3); + unsigned t3 = ((t & 0x03u) << 3) | ((t & 0x03u) << 1) | ((t & 0x02) >> 1); - *(dPtr++) = t1 | t2 | t3; + *(dPtr++) = static_cast(t1 | t2 | t3); } return true; } @@ -892,7 +893,6 @@ namespace default: return false; } - break; case TEXP_LEGACY_A8R3G3B2: if (outFormat != DXGI_FORMAT_R8G8B8A8_UNORM) @@ -974,12 +974,12 @@ namespace for (size_t ocount = 0, icount = 0; ((icount < inSize) && (ocount < (outSize - 1))); ++icount, ocount += 2) { - uint8_t t = *(sPtr++); + unsigned t = *(sPtr++); - uint16_t t1 = (t & 0x0f); - uint16_t ta = (flags & TEXP_SCANLINE_SETALPHA) ? 0xf000 : ((t & 0xf0) << 8); + unsigned t1 = (t & 0x0fu); + unsigned ta = (flags & TEXP_SCANLINE_SETALPHA) ? 0xf000u : ((t & 0xf0u) << 8); - *(dPtr++) = t1 | (t1 << 4) | (t1 << 8) | ta; + *(dPtr++) = static_cast(t1 | (t1 << 4) | (t1 << 8) | ta); } return true; } @@ -1008,7 +1008,6 @@ namespace default: return false; } - break; case TEXP_LEGACY_B4G4R4A4: if (outFormat != DXGI_FORMAT_R8G8B8A8_UNORM) @@ -1158,7 +1157,13 @@ namespace return E_OUTOFMEMORY; } - if (!_SetupImageArray((uint8_t*)pPixels, pixelSize, metadata, cpFlags, timages.get(), nimages)) + if (!_SetupImageArray( + const_cast(reinterpret_cast(pPixels)), + pixelSize, + metadata, + cpFlags, + timages.get(), + nimages)) { return E_FAIL; } @@ -1646,7 +1651,7 @@ HRESULT DirectX::LoadFromDDSFile( { // Must reset file position since we read more than the standard header above LARGE_INTEGER filePos = { { sizeof(uint32_t) + sizeof(DDS_HEADER), 0 } }; - if (!SetFilePointerEx(hFile.get(), filePos, 0, FILE_BEGIN)) + if (!SetFilePointerEx(hFile.get(), filePos, nullptr, FILE_BEGIN)) { return HRESULT_FROM_WIN32(GetLastError()); } @@ -1777,7 +1782,7 @@ HRESULT DirectX::SaveToDDSMemory( // Determine memory required size_t required = 0; - HRESULT hr = _EncodeDDSHeader(metadata, flags, 0, 0, required); + HRESULT hr = _EncodeDDSHeader(metadata, flags, nullptr, 0, required); if (FAILED(hr)) return hr; @@ -1832,7 +1837,7 @@ HRESULT DirectX::SaveToDDSMemory( return E_FAIL; } - switch (metadata.dimension) + switch (static_cast(metadata.dimension)) { case DDS_DIMENSION_TEXTURE1D: case DDS_DIMENSION_TEXTURE2D: @@ -2024,7 +2029,7 @@ HRESULT DirectX::SaveToDDSFile( } // Write images - switch (metadata.dimension) + switch (static_cast(metadata.dimension)) { case DDS_DIMENSION_TEXTURE1D: case DDS_DIMENSION_TEXTURE2D: diff --git a/DirectXTex/DirectXTexFlipRotate.cpp b/DirectXTex/DirectXTexFlipRotate.cpp index aead5e8..50d6dd3 100644 --- a/DirectXTex/DirectXTexFlipRotate.cpp +++ b/DirectXTex/DirectXTexFlipRotate.cpp @@ -9,7 +9,7 @@ // http://go.microsoft.com/fwlink/?LinkId=248926 //------------------------------------------------------------------------------------- -#include "directxtexp.h" +#include "DirectXTexp.h" using namespace DirectX; using Microsoft::WRL::ComPtr; diff --git a/DirectXTex/DirectXTexHDR.cpp b/DirectXTex/DirectXTexHDR.cpp index ddf6bfd..eb0788b 100644 --- a/DirectXTex/DirectXTexHDR.cpp +++ b/DirectXTex/DirectXTexHDR.cpp @@ -9,7 +9,7 @@ // http://go.microsoft.com/fwlink/?LinkId=248926 //------------------------------------------------------------------------------------- -#include "directxtexp.h" +#include "DirectXTexp.h" // // In theory HDR (RGBE) Radiance files can have any of the following data orientations @@ -175,7 +175,7 @@ namespace char buff[32] = {}; strncpy_s(buff, info, std::min(31, len)); - float newExposure = static_cast(atof(buff)); + auto newExposure = static_cast(atof(buff)); if ((newExposure >= 1e-12) && (newExposure <= 1e12)) { // Note that we ignore strange exposure values (like EXPOSURE=0) @@ -347,7 +347,7 @@ namespace for (size_t pixelCount = 0; pixelCount < width;) { size_t spanLen = 1; - const uint32_t* spanPtr = reinterpret_cast(scanPtr); + auto spanPtr = reinterpret_cast(scanPtr); while (pixelCount + spanLen < width && spanLen < 32767) { if (spanPtr[spanLen] == *spanPtr) @@ -368,7 +368,7 @@ namespace if (encSize + 8 > rowPitch) return 0; - uint8_t rleLen = static_cast(std::min(spanLen - 1, 255)); + auto rleLen = static_cast(std::min(spanLen - 1, 255)); enc[0] = scanPtr[0]; enc[1] = scanPtr[1]; @@ -676,7 +676,7 @@ HRESULT DirectX::LoadFromHDRMemory(const void* pSource, size_t size, TexMetadata return E_FAIL; } - float val = static_cast(sourcePtr[1]); + auto val = static_cast(sourcePtr[1]); for (uint8_t j = 0; j < runLen; ++j) { *pixelLoc = val; @@ -696,7 +696,7 @@ HRESULT DirectX::LoadFromHDRMemory(const void* pSource, size_t size, TexMetadata ++sourcePtr; for (uint8_t j = 0; j < runLen; ++j) { - float val = static_cast(*sourcePtr++); + auto val = static_cast(*sourcePtr++); *pixelLoc = val; pixelLoc += 4; } @@ -782,7 +782,7 @@ HRESULT DirectX::LoadFromHDRMemory(const void* pSource, size_t size, TexMetadata for (size_t j = 0; j < image.GetPixelsSize(); j += 16) { - int exponent = static_cast(fdata[3]); + auto exponent = static_cast(fdata[3]); fdata[0] = 1.0f / exposure*ldexpf((fdata[0] + 0.5f), exponent - (128 + 8)); fdata[1] = 1.0f / exposure*ldexpf((fdata[1] + 0.5f), exponent - (128 + 8)); fdata[2] = 1.0f / exposure*ldexpf((fdata[2] + 0.5f), exponent - (128 + 8)); @@ -909,7 +909,7 @@ HRESULT DirectX::SaveToHDRMemory(const Image& image, Blob& blob) // Copy header auto dPtr = static_cast(blob.GetBufferPointer()); - assert(dPtr != 0); + assert(dPtr != nullptr); memcpy_s(dPtr, blob.GetBufferSize(), header, headerLen); dPtr += headerLen; @@ -1024,7 +1024,7 @@ HRESULT DirectX::SaveToHDRFile(const Image& image, const wchar_t* szFile) return hr; // Write blob - const DWORD bytesToWrite = static_cast(blob.GetBufferSize()); + auto bytesToWrite = static_cast(blob.GetBufferSize()); DWORD bytesWritten; if (!WriteFile(hFile.get(), blob.GetBufferPointer(), bytesToWrite, &bytesWritten, nullptr)) { diff --git a/DirectXTex/DirectXTexImage.cpp b/DirectXTex/DirectXTexImage.cpp index 8067fbd..4c82e94 100644 --- a/DirectXTex/DirectXTexImage.cpp +++ b/DirectXTex/DirectXTexImage.cpp @@ -9,7 +9,7 @@ // http://go.microsoft.com/fwlink/?LinkId=248926 //------------------------------------------------------------------------------------- -#include "directxtexp.h" +#include "DirectXTexp.h" namespace DirectX { diff --git a/DirectXTex/DirectXTexMipmaps.cpp b/DirectXTex/DirectXTexMipmaps.cpp index 7b7b7a8..ae1c9c7 100644 --- a/DirectXTex/DirectXTexMipmaps.cpp +++ b/DirectXTex/DirectXTexMipmaps.cpp @@ -9,7 +9,7 @@ // http://go.microsoft.com/fwlink/?LinkId=248926 //------------------------------------------------------------------------------------- -#include "directxtexp.h" +#include "DirectXTexp.h" #include "filters.h" @@ -1214,7 +1214,7 @@ namespace { // Steal and reuse scanline from 'free row' list // (it will always be at least as wide as nwidth due to loop decending order) - assert(rowFree->scanline != 0); + assert(rowFree->scanline != nullptr); rowAcc->scanline.reset(rowFree->scanline.release()); rowFree = rowFree->next; } @@ -2368,7 +2368,7 @@ namespace { // Steal and reuse scanline from 'free slice' list // (it will always be at least as large as nwidth*nheight due to loop decending order) - assert(sliceFree->scanline != 0); + assert(sliceFree->scanline != nullptr); sliceAcc->scanline.reset(sliceFree->scanline.release()); sliceFree = sliceFree->next; } @@ -2609,7 +2609,6 @@ HRESULT DirectX::GenerateMipMaps( return _ConvertFromR32G32B32A32(tMipChain.GetImages(), tMipChain.GetImageCount(), tMipChain.GetMetadata(), baseImage.format, mipChain); } } - break; default: return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED); @@ -2815,7 +2814,6 @@ HRESULT DirectX::GenerateMipMaps( return _ConvertFromR32G32B32A32(tMipChain.GetImages(), tMipChain.GetImageCount(), tMipChain.GetMetadata(), metadata.format, mipChain); } } - break; default: return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED); diff --git a/DirectXTex/DirectXTexMisc.cpp b/DirectXTex/DirectXTexMisc.cpp index 10bcf13..1f6dfdc 100644 --- a/DirectXTex/DirectXTexMisc.cpp +++ b/DirectXTex/DirectXTexMisc.cpp @@ -9,7 +9,7 @@ // http://go.microsoft.com/fwlink/?LinkId=248926 //------------------------------------------------------------------------------------- -#include "directxtexp.h" +#include "DirectXTexp.h" using namespace DirectX; diff --git a/DirectXTex/DirectXTexNormalMaps.cpp b/DirectXTex/DirectXTexNormalMaps.cpp index 9d3ae8e..6c0d729 100644 --- a/DirectXTex/DirectXTexNormalMaps.cpp +++ b/DirectXTex/DirectXTexNormalMaps.cpp @@ -9,7 +9,7 @@ // http://go.microsoft.com/fwlink/?LinkId=248926 //------------------------------------------------------------------------------------- -#include "directxtexp.h" +#include "DirectXTexp.h" using namespace DirectX; @@ -38,7 +38,6 @@ namespace XMStoreFloat4A(&f, v); return f.x + f.y + f.z; } - break; default: assert(false); diff --git a/DirectXTex/DirectXTexP.h b/DirectXTex/DirectXTexP.h index 5cb5bc9..407d7d1 100644 --- a/DirectXTex/DirectXTexP.h +++ b/DirectXTex/DirectXTexP.h @@ -75,6 +75,8 @@ #include #endif +#define _XM_NO_XMVECTOR_OVERLOADS_ + #include #include #include diff --git a/DirectXTex/DirectXTexPMAlpha.cpp b/DirectXTex/DirectXTexPMAlpha.cpp index 8937e7b..acd8d12 100644 --- a/DirectXTex/DirectXTexPMAlpha.cpp +++ b/DirectXTex/DirectXTexPMAlpha.cpp @@ -9,7 +9,7 @@ // http://go.microsoft.com/fwlink/?LinkId=248926 //------------------------------------------------------------------------------------- -#include "directxtexp.h" +#include "DirectXTexp.h" using namespace DirectX; diff --git a/DirectXTex/DirectXTexResize.cpp b/DirectXTex/DirectXTexResize.cpp index e21919c..d4db78e 100644 --- a/DirectXTex/DirectXTexResize.cpp +++ b/DirectXTex/DirectXTexResize.cpp @@ -9,7 +9,7 @@ // http://go.microsoft.com/fwlink/?LinkId=248926 //------------------------------------------------------------------------------------- -#include "directxtexp.h" +#include "DirectXTexp.h" #include "filters.h" @@ -678,7 +678,7 @@ namespace if (rowFree) { // Steal and reuse scanline from 'free row' list - assert(rowFree->scanline != 0); + assert(rowFree->scanline != nullptr); rowAcc->scanline.reset(rowFree->scanline.release()); rowFree = rowFree->next; } diff --git a/DirectXTex/DirectXTexTGA.cpp b/DirectXTex/DirectXTexTGA.cpp index 8c40c7f..62a256f 100644 --- a/DirectXTex/DirectXTexTGA.cpp +++ b/DirectXTex/DirectXTexTGA.cpp @@ -9,7 +9,7 @@ // http://go.microsoft.com/fwlink/?LinkId=248926 //------------------------------------------------------------------------------------- -#include "directxtexp.h" +#include "DirectXTexp.h" // // The implementation here has the following limitations: @@ -42,8 +42,6 @@ namespace TGA_FLAGS_INTERLEAVED_4WAY = 0x80, // Deprecated }; - const char* g_TGA20_Signature = "TRUEVISION-XFILE."; - #pragma pack(push,1) struct TGA_HEADER { @@ -373,7 +371,7 @@ namespace if (sPtr + 1 >= endPtr) return E_FAIL; - uint16_t t = *sPtr | (*(sPtr + 1) << 8); + auto t = static_cast(unsigned(*sPtr) | (*(sPtr + 1u) << 8)); if (t & 0x8000) nonzeroa = true; sPtr += 2; @@ -405,7 +403,7 @@ namespace if (x >= image->width) return E_FAIL; - uint16_t t = *sPtr | (*(sPtr + 1) << 8); + auto t = static_cast(unsigned(*sPtr) | (*(sPtr + 1u) << 8)); if (t & 0x8000) nonzeroa = true; sPtr += 2; @@ -650,7 +648,7 @@ namespace if (sPtr + 1 >= endPtr) return E_FAIL; - uint16_t t = *sPtr | (*(sPtr + 1) << 8); + auto t = static_cast(unsigned(*sPtr) | (*(sPtr + 1u) << 8)); sPtr += 2; *dPtr = t; @@ -860,7 +858,7 @@ HRESULT DirectX::GetMetadataFromTGAMemory( return E_INVALIDARG; size_t offset; - return DecodeTGAHeader(pSource, size, metadata, offset, 0); + return DecodeTGAHeader(pSource, size, metadata, offset, nullptr); } _Use_decl_annotations_ @@ -908,7 +906,7 @@ HRESULT DirectX::GetMetadataFromTGAFile(const wchar_t* szFile, TexMetadata& meta } size_t offset; - return DecodeTGAHeader(header, bytesRead, metadata, offset, 0); + return DecodeTGAHeader(header, bytesRead, metadata, offset, nullptr); } @@ -1029,7 +1027,7 @@ HRESULT DirectX::LoadFromTGAFile( return hr; // Read the pixels - DWORD remaining = static_cast(fileInfo.EndOfFile.LowPart - offset); + auto remaining = static_cast(fileInfo.EndOfFile.LowPart - offset); if (remaining == 0) return E_FAIL; @@ -1037,7 +1035,7 @@ HRESULT DirectX::LoadFromTGAFile( { // Skip past the id string LARGE_INTEGER filePos = { { static_cast(offset), 0 } }; - if (!SetFilePointerEx(hFile.get(), filePos, 0, FILE_BEGIN)) + if (!SetFilePointerEx(hFile.get(), filePos, nullptr, FILE_BEGIN)) { return HRESULT_FROM_WIN32(GetLastError()); } @@ -1091,7 +1089,7 @@ HRESULT DirectX::LoadFromTGAFile( for (size_t h = 0; h < img->height; ++h) { - const uint32_t* sPtr = reinterpret_cast(pPixels); + auto sPtr = reinterpret_cast(pPixels); for (size_t x = 0; x < img->width; ++x) { @@ -1149,7 +1147,7 @@ HRESULT DirectX::LoadFromTGAFile( for (size_t h = 0; h < img->height; ++h) { - const uint16_t* sPtr = reinterpret_cast(pPixels); + auto sPtr = reinterpret_cast(pPixels); for (size_t x = 0; x < img->width; ++x) { @@ -1264,7 +1262,7 @@ HRESULT DirectX::SaveToTGAMemory(const Image& image, Blob& blob) // Copy header auto dPtr = static_cast(blob.GetBufferPointer()); - assert(dPtr != 0); + assert(dPtr != nullptr); memcpy_s(dPtr, blob.GetBufferSize(), &tga_header, sizeof(TGA_HEADER)); dPtr += sizeof(TGA_HEADER); diff --git a/DirectXTex/DirectXTexUtil.cpp b/DirectXTex/DirectXTexUtil.cpp index d6f4c89..57a936d 100644 --- a/DirectXTex/DirectXTexUtil.cpp +++ b/DirectXTex/DirectXTexUtil.cpp @@ -9,7 +9,7 @@ // http://go.microsoft.com/fwlink/?LinkId=248926 //------------------------------------------------------------------------------------- -#include "directxtexp.h" +#include "DirectXTexp.h" #if defined(_XBOX_ONE) && defined(_TITLE) static_assert(XBOX_DXGI_FORMAT_R10G10B10_7E3_A2_FLOAT == DXGI_FORMAT_R10G10B10_7E3_A2_FLOAT, "Xbox One XDK mismatch detected"); @@ -71,6 +71,48 @@ namespace bool g_WIC2 = false; IWICImagingFactory* g_Factory = nullptr; + + BOOL WINAPI InitializeWICFactory(PINIT_ONCE, PVOID, PVOID *ifactory) noexcept + { + #if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE) + HRESULT hr = CoCreateInstance( + CLSID_WICImagingFactory2, + nullptr, + CLSCTX_INPROC_SERVER, + __uuidof(IWICImagingFactory2), + ifactory + ); + + if (SUCCEEDED(hr)) + { + // WIC2 is available on Windows 10, Windows 8.x, and Windows 7 SP1 with KB 2670838 installed + g_WIC2 = true; + return TRUE; + } + else + { + g_WIC2 = false; + + hr = CoCreateInstance( + CLSID_WICImagingFactory1, + nullptr, + CLSCTX_INPROC_SERVER, + __uuidof(IWICImagingFactory), + ifactory + ); + return SUCCEEDED(hr) ? TRUE : FALSE; + } + #else + g_WIC2 = false; + + return SUCCEEDED(CoCreateInstance( + CLSID_WICImagingFactory, + nullptr, + CLSCTX_INPROC_SERVER, + __uuidof(IWICImagingFactory), + ifactory)) ? TRUE : FALSE; + #endif + } } @@ -236,47 +278,9 @@ IWICImagingFactory* DirectX::GetWICFactory(bool& iswic2) static INIT_ONCE s_initOnce = INIT_ONCE_STATIC_INIT; InitOnceExecuteOnce(&s_initOnce, - [](PINIT_ONCE, PVOID, LPVOID *factory) noexcept -> BOOL - { -#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE) - HRESULT hr = CoCreateInstance( - CLSID_WICImagingFactory2, - nullptr, - CLSCTX_INPROC_SERVER, - __uuidof(IWICImagingFactory2), - factory - ); - - if (SUCCEEDED(hr)) - { - // WIC2 is available on Windows 10, Windows 8.x, and Windows 7 SP1 with KB 2670838 installed - g_WIC2 = true; - return TRUE; - } - else - { - g_WIC2 = false; - - hr = CoCreateInstance( - CLSID_WICImagingFactory1, - nullptr, - CLSCTX_INPROC_SERVER, - __uuidof(IWICImagingFactory), - factory - ); - return SUCCEEDED(hr) ? TRUE : FALSE; - } -#else - g_WIC2 = false; - - return SUCCEEDED(CoCreateInstance( - CLSID_WICImagingFactory, - nullptr, - CLSCTX_INPROC_SERVER, - __uuidof(IWICImagingFactory), - factory)) ? TRUE : FALSE; -#endif - }, nullptr, reinterpret_cast(&g_Factory)); + InitializeWICFactory, + nullptr, + reinterpret_cast(&g_Factory)); iswic2 = g_WIC2; return g_Factory; @@ -1401,7 +1405,6 @@ size_t TexMetadata::ComputeIndex(size_t mip, size_t item, size_t slice) const return index; } - break; default: return size_t(-1); diff --git a/DirectXTex/DirectXTexWIC.cpp b/DirectXTex/DirectXTexWIC.cpp index ba76722..446c059 100644 --- a/DirectXTex/DirectXTexWIC.cpp +++ b/DirectXTex/DirectXTexWIC.cpp @@ -9,7 +9,7 @@ // http://go.microsoft.com/fwlink/?LinkId=248926 //------------------------------------------------------------------------------------- -#include "directxtexp.h" +#include "DirectXTexp.h" //------------------------------------------------------------------------------------- // IStream support for WIC Memory routines @@ -62,7 +62,7 @@ #pragma prefast(suppress:6387 28196, "a simple wrapper around an existing annotated function" ); static inline HRESULT CreateMemoryStream(_Outptr_ IStream** stream) { - return CreateStreamOnHGlobal(0, TRUE, stream); + return CreateStreamOnHGlobal(nullptr, TRUE, stream); } #endif @@ -1167,7 +1167,7 @@ HRESULT DirectX::SaveToWICMemory( return hr; LARGE_INTEGER li = {}; - hr = stream->Seek(li, STREAM_SEEK_SET, 0); + hr = stream->Seek(li, STREAM_SEEK_SET, nullptr); if (FAILED(hr)) return hr; @@ -1224,7 +1224,7 @@ HRESULT DirectX::SaveToWICMemory( return hr; LARGE_INTEGER li = {}; - hr = stream->Seek(li, STREAM_SEEK_SET, 0); + hr = stream->Seek(li, STREAM_SEEK_SET, nullptr); if (FAILED(hr)) return hr; diff --git a/DirectXTex/Filters.h b/DirectXTex/Filters.h index 00e66d8..182ee1e 100644 --- a/DirectXTex/Filters.h +++ b/DirectXTex/Filters.h @@ -63,7 +63,7 @@ inline void _CreateLinearFilter(_In_ size_t source, _In_ size_t dest, _In_ bool { assert(source > 0); assert(dest > 0); - assert(lf != 0); + assert(lf != nullptr); float scale = float(source) / float(dest); @@ -163,7 +163,7 @@ inline void _CreateCubicFilter(_In_ size_t source, _In_ size_t dest, _In_ bool w { assert(source > 0); assert(dest > 0); - assert(cf != 0); + assert(cf != nullptr); float scale = float(source) / float(dest); @@ -294,7 +294,7 @@ namespace TriangleFilter tf->totalSize = totalSize; } - assert(pFilter != 0); + assert(pFilter != nullptr); _Analysis_assume_(pFilter != 0); // Filter setup