diff --git a/DirectXTex/BC.cpp b/DirectXTex/BC.cpp index a0dade7..d037567 100644 --- a/DirectXTex/BC.cpp +++ b/DirectXTex/BC.cpp @@ -109,9 +109,9 @@ namespace } // Diagonal axis - HDRColorA AB(Y.r - X.r, Y.g - X.g, Y.b - X.b, 0.0f); + const HDRColorA AB(Y.r - X.r, Y.g - X.g, Y.b - X.b, 0.0f); - float fAB = AB.r * AB.r + AB.g * AB.g + AB.b * AB.b; + const float fAB = AB.r * AB.r + AB.g * AB.g + AB.b * AB.b; // Single color block.. no need to root-find if (fAB < FLT_MIN) @@ -122,11 +122,11 @@ namespace } // Try all four axis directions, to determine which diagonal best fits data - float fABInv = 1.0f / fAB; + const float fABInv = 1.0f / fAB; HDRColorA Dir(AB.r * fABInv, AB.g * fABInv, AB.b * fABInv, 0.0f); - HDRColorA Mid( + const HDRColorA Mid( (X.r + Y.r) * 0.5f, (X.g + Y.g) * 0.5f, (X.b + Y.b) * 0.5f, @@ -185,12 +185,12 @@ namespace if (iDirMax & 2) { - float f = X.g; X.g = Y.g; Y.g = f; + const float f = X.g; X.g = Y.g; Y.g = f; } if (iDirMax & 1) { - float f = X.b; X.b = Y.b; Y.b = f; + const float f = X.b; X.b = Y.b; Y.b = f; } @@ -203,7 +203,7 @@ namespace } // Use Newton's Method to find local minima of sum-of-squares error. - auto fSteps = static_cast(cSteps - 1); + auto const fSteps = static_cast(cSteps - 1); for (size_t iIteration = 0; iIteration < 8; iIteration++) { @@ -224,12 +224,12 @@ namespace Dir.g = Y.g - X.g; Dir.b = Y.b - X.b; - float fLen = (Dir.r * Dir.r + Dir.g * Dir.g + Dir.b * Dir.b); + const float fLen = (Dir.r * Dir.r + Dir.g * Dir.g + Dir.b * Dir.b); if (fLen < (1.0f / 4096.0f)) break; - float fScale = fSteps / fLen; + const float fScale = fSteps / fLen; Dir.r *= fScale; Dir.g *= fScale; @@ -244,7 +244,7 @@ namespace for (size_t iPoint = 0; iPoint < NUM_PIXELS_PER_BLOCK; iPoint++) { - float fDot = (pPoints[iPoint].r - X.r) * Dir.r + + const float fDot = (pPoints[iPoint].r - X.r) * Dir.r + (pPoints[iPoint].g - X.g) * Dir.g + (pPoints[iPoint].b - X.b) * Dir.b; @@ -265,11 +265,11 @@ namespace Diff.a = 0.0f; #ifdef COLOR_WEIGHTS - float fC = pC[iStep] * pPoints[iPoint].a * (1.0f / 8.0f); - float fD = pD[iStep] * pPoints[iPoint].a * (1.0f / 8.0f); + const float fC = pC[iStep] * pPoints[iPoint].a * (1.0f / 8.0f); + const float fD = pD[iStep] * pPoints[iPoint].a * (1.0f / 8.0f); #else - float fC = pC[iStep] * (1.0f / 8.0f); - float fD = pD[iStep] * (1.0f / 8.0f); + const float fC = pC[iStep] * (1.0f / 8.0f); + const float fD = pD[iStep] * (1.0f / 8.0f); #endif // COLOR_WEIGHTS d2X += fC * pC[iStep]; @@ -286,7 +286,7 @@ namespace // Move endpoints if (d2X > 0.0f) { - float f = -1.0f / d2X; + const float f = -1.0f / d2X; X.r += dX.r * f; X.g += dX.g * f; @@ -295,7 +295,7 @@ namespace if (d2Y > 0.0f) { - float f = -1.0f / d2Y; + const float f = -1.0f / d2Y; Y.r += dY.r * f; Y.g += dY.g * f; @@ -513,8 +513,8 @@ namespace ColorD.a = ColorB.a; } - uint16_t wColorA = Encode565(&ColorC); - uint16_t wColorB = Encode565(&ColorD); + const uint16_t wColorA = Encode565(&ColorC); + const uint16_t wColorB = Encode565(&ColorD); if ((uSteps == 4) && (wColorA == wColorB)) { @@ -588,8 +588,8 @@ namespace Dir.b = Step[1].b - Step[0].b; Dir.a = 0.0f; - 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; + const auto fSteps = static_cast(uSteps - 1); + const float fScale = (wColorA != wColorB) ? (fSteps / (Dir.r * Dir.r + Dir.g * Dir.g + Dir.b * Dir.b)) : 0.0f; Dir.r *= fScale; Dir.g *= fScale; @@ -630,7 +630,7 @@ namespace Clr.b += Error[i].b; } - float fDot = (Clr.r - Step[0].r) * Dir.r + (Clr.g - Step[0].g) * Dir.g + (Clr.b - Step[0].b) * Dir.b; + const float fDot = (Clr.r - Step[0].r) * Dir.r + (Clr.g - Step[0].g) * Dir.g + (Clr.b - Step[0].b) * Dir.b; uint32_t iStep; if (fDot <= 0.0f) @@ -706,9 +706,9 @@ namespace Color.g *= 1.0f / 16.0f; Color.b *= 1.0f / 16.0f; - uint16_t wColor = Encode565(&Color); + const uint16_t wColor = Encode565(&Color); #else - uint16_t wColor = 0x0000; + const uint16_t wColor = 0x0000; #endif // COLOR_AVG_0WEIGHTS // Encode solid block @@ -750,14 +750,14 @@ void DirectX::D3DXEncodeBC1(uint8_t *pBC, const XMVECTOR *pColor, float threshol HDRColorA clr; XMStoreFloat4(reinterpret_cast(&clr), pColor[i]); - float fAlph = clr.a + fError[i]; + const float fAlph = clr.a + fError[i]; Color[i].r = clr.r; Color[i].g = clr.g; Color[i].b = clr.b; Color[i].a = static_cast(static_cast(clr.a + fError[i] + 0.5f)); - float fDiff = fAlph - Color[i].a; + const float fDiff = fAlph - Color[i].a; if (3 != (i & 3)) { @@ -849,14 +849,14 @@ void DirectX::D3DXEncodeBC2(uint8_t *pBC, const XMVECTOR *pColor, uint32_t flags if (flags & BC_FLAGS_DITHER_A) fAlph += fError[i]; - auto u = static_cast(fAlph * 15.0f + 0.5f); + const 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); + const float fDiff = fAlph - float(u) * (1.0f / 15.0f); if (3 != (i & 3)) { @@ -978,7 +978,7 @@ void DirectX::D3DXEncodeBC3(uint8_t *pBC, const XMVECTOR *pColor, uint32_t flags if (flags & BC_FLAGS_DITHER_A) { - float fDiff = fAlph - fAlpha[i]; + const float fDiff = fAlph - fAlpha[i]; if (3 != (i & 3)) { @@ -1027,13 +1027,13 @@ void DirectX::D3DXEncodeBC3(uint8_t *pBC, const XMVECTOR *pColor, uint32_t flags } // Optimize and Quantize Min and Max values - uint32_t uSteps = ((0.0f == fMinAlpha) || (1.0f == fMaxAlpha)) ? 6u : 8u; + const uint32_t uSteps = ((0.0f == fMinAlpha) || (1.0f == fMaxAlpha)) ? 6u : 8u; float fAlphaA, fAlphaB; OptimizeAlpha(&fAlphaA, &fAlphaB, fAlpha, uSteps); - auto bAlphaA = static_cast(static_cast(fAlphaA * 255.0f + 0.5f)); - auto bAlphaB = static_cast(static_cast(fAlphaB * 255.0f + 0.5f)); + auto const bAlphaA = static_cast(static_cast(fAlphaA * 255.0f + 0.5f)); + auto const bAlphaB = static_cast(static_cast(fAlphaB * 255.0f + 0.5f)); fAlphaA = static_cast(bAlphaA) * (1.0f / 255.0f); fAlphaB = static_cast(bAlphaB) * (1.0f / 255.0f); @@ -1084,8 +1084,8 @@ void DirectX::D3DXEncodeBC3(uint8_t *pBC, const XMVECTOR *pColor, uint32_t flags } // Encode alpha bitmap - auto fSteps = static_cast(uSteps - 1); - float fScale = (fStep[0] != fStep[1]) ? (fSteps / (fStep[1] - fStep[0])) : 0.0f; + auto const fSteps = static_cast(uSteps - 1); + const float fScale = (fStep[0] != fStep[1]) ? (fSteps / (fStep[1] - fStep[0])) : 0.0f; if (flags & BC_FLAGS_DITHER_A) memset(fError, 0x00, NUM_PIXELS_PER_BLOCK * sizeof(float)); @@ -1094,15 +1094,15 @@ void DirectX::D3DXEncodeBC3(uint8_t *pBC, const XMVECTOR *pColor, uint32_t flags { uint32_t dw = 0; - size_t iMin = iSet * 8; - size_t iLim = iMin + 8; + const size_t iMin = iSet * 8; + const size_t iLim = iMin + 8; for (size_t i = iMin; i < iLim; ++i) { float fAlph = Color[i].a; if (flags & BC_FLAGS_DITHER_A) fAlph += fError[i]; - float fDot = (fAlph - fStep[0]) * fScale; + const float fDot = (fAlph - fStep[0]) * fScale; uint32_t iStep; if (fDot <= 0.0f) @@ -1116,7 +1116,7 @@ void DirectX::D3DXEncodeBC3(uint8_t *pBC, const XMVECTOR *pColor, uint32_t flags if (flags & BC_FLAGS_DITHER_A) { - float fDiff = (fAlph - fStep[iStep]); + const float fDiff = (fAlph - fStep[iStep]); if (3 != (i & 3)) fError[i + 1] += fDiff * (7.0f / 16.0f); diff --git a/DirectXTex/BC.h b/DirectXTex/BC.h index d722b60..aff2f7a 100644 --- a/DirectXTex/BC.h +++ b/DirectXTex/BC.h @@ -70,7 +70,7 @@ public: HDRColorA operator / (float f) const noexcept { - float fInv = 1.0f / f; + const float fInv = 1.0f / f; return HDRColorA(r * fInv, g * fInv, b * fInv, a * fInv); } @@ -109,7 +109,7 @@ public: HDRColorA& operator /= (float f) noexcept { - float fInv = 1.0f / f; + const float fInv = 1.0f / f; r *= fInv; g *= fInv; b *= fInv; @@ -179,8 +179,8 @@ template void OptimizeAlpha(float *pX, float *pY, const float *pPo const float *pC = (6 == cSteps) ? pC6 : pC8; const float *pD = (6 == cSteps) ? pD6 : pD8; - const float MAX_VALUE = 1.0f; - const float MIN_VALUE = (bRange) ? -1.0f : 0.0f; + constexpr float MAX_VALUE = 1.0f; + constexpr float MIN_VALUE = (bRange) ? -1.0f : 0.0f; // Find Min and Max points, as starting point float fX = MAX_VALUE; @@ -215,14 +215,14 @@ template void OptimizeAlpha(float *pX, float *pY, const float *pPo } // Use Newton's Method to find local minima of sum-of-squares error. - auto fSteps = static_cast(cSteps - 1); + auto const fSteps = static_cast(cSteps - 1); for (size_t iIteration = 0; iIteration < 8; iIteration++) { if ((fY - fX) < (1.0f / 256.0f)) break; - float fScale = fSteps / (fY - fX); + float const fScale = fSteps / (fY - fX); // Calculate new steps float pSteps[8]; @@ -244,7 +244,7 @@ template void OptimizeAlpha(float *pX, float *pY, const float *pPo for (size_t iPoint = 0; iPoint < NUM_PIXELS_PER_BLOCK; iPoint++) { - float fDot = (pPoints[iPoint] - fX) * fScale; + const float fDot = (pPoints[iPoint] - fX) * fScale; uint32_t iStep; if (fDot <= 0.0f) @@ -265,7 +265,7 @@ template void OptimizeAlpha(float *pX, float *pY, const float *pPo { // D3DX had this computation backwards (pPoints[iPoint] - pSteps[iStep]) // this fix improves RMS of the alpha component - float fDiff = pSteps[iStep] - pPoints[iPoint]; + const float fDiff = pSteps[iStep] - pPoints[iPoint]; dX += pC[iStep] * fDiff; d2X += pC[iStep] * pC[iStep]; @@ -284,7 +284,7 @@ template void OptimizeAlpha(float *pX, float *pY, const float *pPo if (fX > fY) { - float f = fX; fX = fY; fY = f; + const float f = fX; fX = fY; fY = f; } if ((dX * dX < (1.0f / 64.0f)) && (dY * dY < (1.0f / 64.0f))) diff --git a/DirectXTex/BC4BC5.cpp b/DirectXTex/BC4BC5.cpp index 596cfd1..7f533bd 100644 --- a/DirectXTex/BC4BC5.cpp +++ b/DirectXTex/BC4BC5.cpp @@ -40,7 +40,7 @@ namespace { float R(size_t uOffset) const noexcept { - size_t uIndex = GetIndex(uOffset); + const size_t uIndex = GetIndex(uOffset); return DecodeFromIndex(uIndex); } @@ -50,8 +50,8 @@ namespace return float(red_0) / 255.0f; if (uIndex == 1) return float(red_1) / 255.0f; - float fred_0 = float(red_0) / 255.0f; - float fred_1 = float(red_1) / 255.0f; + const float fred_0 = float(red_0) / 255.0f; + const float fred_1 = float(red_1) / 255.0f; if (red_0 > red_1) { uIndex -= 1; @@ -96,21 +96,21 @@ namespace { float R(size_t uOffset) const noexcept { - size_t uIndex = GetIndex(uOffset); + const size_t uIndex = GetIndex(uOffset); return DecodeFromIndex(uIndex); } float DecodeFromIndex(size_t uIndex) const noexcept { - int8_t sred_0 = (red_0 == -128) ? -127 : red_0; - int8_t sred_1 = (red_1 == -128) ? -127 : red_1; + const int8_t sred_0 = (red_0 == -128) ? -127 : red_0; + const int8_t sred_1 = (red_1 == -128) ? -127 : red_1; if (uIndex == 0) return float(sred_0) / 127.0f; if (uIndex == 1) return float(sred_1) / 127.0f; - float fred_0 = float(sred_0) / 127.0f; - float fred_1 = float(sred_1) / 127.0f; + const float fred_0 = float(sred_0) / 127.0f; + const float fred_1 = float(sred_1) / 127.0f; if (red_0 > red_1) { uIndex -= 1; @@ -157,7 +157,7 @@ namespace //------------------------------------------------------------------------------------- void inline FloatToSNorm(_In_ float fVal, _Out_ int8_t *piSNorm) noexcept { - const uint32_t dwMostNeg = (1 << (8 * sizeof(int8_t) - 1)); + constexpr uint32_t dwMostNeg = (1 << (8 * sizeof(int8_t) - 1)); if (isnan(fVal)) fVal = 0; @@ -186,8 +186,8 @@ namespace _Out_ uint8_t &endpointU_1) noexcept { // The boundary of codec for signed/unsigned format - const float MIN_NORM = 0.f; - const float MAX_NORM = 1.f; + constexpr float MIN_NORM = 0.f; + constexpr float MAX_NORM = 1.f; // Find max/min of input texels float fBlockMax = theTexelsU[0]; @@ -206,7 +206,7 @@ namespace // If there are boundary values in input texels, should use 4 interpolated color values to guarantee // the exact code of the boundary values. - bool bUsing4BlockCodec = (MIN_NORM == fBlockMin || MAX_NORM == fBlockMax); + const bool bUsing4BlockCodec = (MIN_NORM == fBlockMin || MAX_NORM == fBlockMax); // Using Optimize float fStart, fEnd; @@ -241,8 +241,8 @@ namespace _Out_ int8_t &endpointU_1) noexcept { // The boundary of codec for signed/unsigned format - const float MIN_NORM = -1.f; - const float MAX_NORM = 1.f; + constexpr float MIN_NORM = -1.f; + constexpr float MAX_NORM = 1.f; // Find max/min of input texels float fBlockMax = theTexelsU[0]; @@ -261,7 +261,7 @@ namespace // If there are boundary values in input texels, should use 4 interpolated color values to guarantee // the exact code of the boundary values. - bool bUsing4BlockCodec = (MIN_NORM == fBlockMin || MAX_NORM == fBlockMax); + const bool bUsing4BlockCodec = (MIN_NORM == fBlockMin || MAX_NORM == fBlockMax); // Using Optimize float fStart, fEnd; @@ -338,7 +338,7 @@ namespace float fBestDelta = 100000; for (size_t uIndex = 0; uIndex < 8; uIndex++) { - float fCurrentDelta = fabsf(rGradient[uIndex] - theTexelsU[i]); + const float fCurrentDelta = fabsf(rGradient[uIndex] - theTexelsU[i]); if (fCurrentDelta < fBestDelta) { uBestIndex = uIndex; @@ -365,7 +365,7 @@ namespace float fBestDelta = 100000; for (size_t uIndex = 0; uIndex < 8; uIndex++) { - float fCurrentDelta = fabsf(rGradient[uIndex] - theTexelsU[i]); + const float fCurrentDelta = fabsf(rGradient[uIndex] - theTexelsU[i]); if (fCurrentDelta < fBestDelta) { uBestIndex = uIndex; diff --git a/DirectXTex/BC6HBC7.cpp b/DirectXTex/BC6HBC7.cpp index d75c672..e813862 100644 --- a/DirectXTex/BC6HBC7.cpp +++ b/DirectXTex/BC6HBC7.cpp @@ -489,7 +489,7 @@ namespace { PackedVector::XMHALF4 aF16; - XMVECTOR v = XMLoadFloat4(reinterpret_cast(&c)); + const XMVECTOR v = XMLoadFloat4(reinterpret_cast(&c)); XMStoreHalf4(&aF16, v); r = F16ToINT(aF16.x, bSigned); @@ -582,8 +582,8 @@ namespace { assert(uStartBit < 128); _Analysis_assume_(uStartBit < 128); - size_t uIndex = uStartBit >> 3; - auto ret = static_cast((m_uBits[uIndex] >> (uStartBit - (uIndex << 3))) & 0x01); + const size_t uIndex = uStartBit >> 3; + auto const ret = static_cast((m_uBits[uIndex] >> (uStartBit - (uIndex << 3))) & 0x01); uStartBit++; return ret; } @@ -594,12 +594,12 @@ namespace assert(uStartBit + uNumBits <= 128 && uNumBits <= 8); _Analysis_assume_(uStartBit + uNumBits <= 128 && uNumBits <= 8); uint8_t ret; - size_t uIndex = uStartBit >> 3; - size_t uBase = uStartBit - (uIndex << 3); + const size_t uIndex = uStartBit >> 3; + const size_t uBase = uStartBit - (uIndex << 3); if (uBase + uNumBits > 8) { - size_t uFirstIndexBits = 8 - uBase; - size_t uNextIndexBits = uNumBits - uFirstIndexBits; + const size_t uFirstIndexBits = 8 - uBase; + const size_t uNextIndexBits = uNumBits - uFirstIndexBits; ret = static_cast((unsigned(m_uBits[uIndex]) >> uBase) | ((unsigned(m_uBits[uIndex + 1]) & ((1u << uNextIndexBits) - 1)) << uFirstIndexBits)); } else @@ -616,7 +616,7 @@ namespace assert(uStartBit < 128 && uValue < 2); _Analysis_assume_(uStartBit < 128 && uValue < 2); size_t uIndex = uStartBit >> 3; - size_t uBase = uStartBit - (uIndex << 3); + const size_t uBase = uStartBit - (uIndex << 3); m_uBits[uIndex] &= ~(1 << uBase); m_uBits[uIndex] |= uValue << uBase; uStartBit++; @@ -630,11 +630,11 @@ namespace _Analysis_assume_(uStartBit + uNumBits <= 128 && uNumBits <= 8); assert(uValue < (1 << uNumBits)); size_t uIndex = uStartBit >> 3; - size_t uBase = uStartBit - (uIndex << 3); + const size_t uBase = uStartBit - (uIndex << 3); if (uBase + uNumBits > 8) { - size_t uFirstIndexBits = 8 - uBase; - size_t uNextIndexBits = uNumBits - uFirstIndexBits; + const size_t uFirstIndexBits = 8 - uBase; + const size_t uNextIndexBits = uNumBits - uFirstIndexBits; m_uBits[uIndex] &= ~(((1 << uFirstIndexBits) - 1) << uBase); m_uBits[uIndex] |= uValue << uBase; m_uBits[uIndex + 1] &= ~((1 << uNextIndexBits) - 1); @@ -793,7 +793,7 @@ namespace static uint8_t Quantize(_In_ uint8_t comp, _In_ uint8_t uPrec) noexcept { assert(0 < uPrec && uPrec <= 8); - uint8_t rnd = std::min(255u, static_cast(unsigned(comp) + (1u << (7 - uPrec)))); + const uint8_t rnd = std::min(255u, static_cast(unsigned(comp) + (1u << (7 - uPrec)))); return uint8_t(rnd >> (8u - uPrec)); } @@ -1137,7 +1137,7 @@ namespace inline void TransformInverse(_Inout_updates_all_(BC6H_MAX_REGIONS) INTEndPntPair aEndPts[], _In_ const LDRColorA& Prec, _In_ bool bSigned) noexcept { - INTColor WrapMask((1 << Prec.r) - 1, (1 << Prec.g) - 1, (1 << Prec.b) - 1); + const INTColor WrapMask((1 << Prec.r) - 1, (1 << Prec.g) - 1, (1 << Prec.b) - 1); aEndPts[0].B += aEndPts[0].A; aEndPts[0].B &= WrapMask; aEndPts[1].A += aEndPts[0].A; aEndPts[1].A &= WrapMask; aEndPts[1].B += aEndPts[0].A; aEndPts[1].B &= WrapMask; @@ -1151,9 +1151,9 @@ namespace inline float Norm(_In_ const INTColor& a, _In_ const INTColor& b) noexcept { - float dr = float(a.r) - float(b.r); - float dg = float(a.g) - float(b.g); - float db = float(a.b) - float(b.b); + const float dr = float(a.r) - float(b.r); + const float dg = float(a.g) - float(b.g); + const float db = float(a.b) - float(b.b); return dr * dr + dg * dg + db * db; } @@ -1188,7 +1188,7 @@ namespace size_t cPixels, _In_reads_(cPixels) const size_t* pIndex) noexcept { - float fError = FLT_MAX; + constexpr float fError = FLT_MAX; const float *pC = (3 == cSteps) ? pC3 : pC4; const float *pD = (3 == cSteps) ? pD3 : pD4; @@ -1212,7 +1212,7 @@ namespace AB.g = Y.g - X.g; AB.b = Y.b - X.b; - float fAB = AB.r * AB.r + AB.g * AB.g + AB.b * AB.b; + const float fAB = AB.r * AB.r + AB.g * AB.g + AB.b * AB.b; // Single color block.. no need to root-find if (fAB < FLT_MIN) @@ -1223,7 +1223,7 @@ namespace } // Try all four axis directions, to determine which diagonal best fits data - float fABInv = 1.0f / fAB; + const float fABInv = 1.0f / fAB; HDRColorA Dir; Dir.r = AB.r * fABInv; @@ -1276,7 +1276,7 @@ namespace } // Use Newton's Method to find local minima of sum-of-squares error. - auto fSteps = static_cast(cSteps - 1); + auto const fSteps = static_cast(cSteps - 1); for (size_t iIteration = 0; iIteration < 8; iIteration++) { @@ -1295,12 +1295,12 @@ namespace Dir.g = Y.g - X.g; Dir.b = Y.b - X.b; - float fLen = (Dir.r * Dir.r + Dir.g * Dir.g + Dir.b * Dir.b); + const float fLen = (Dir.r * Dir.r + Dir.g * Dir.g + Dir.b * Dir.b); if (fLen < (1.0f / 4096.0f)) break; - float fScale = fSteps / fLen; + const float fScale = fSteps / fLen; Dir.r *= fScale; Dir.g *= fScale; @@ -1312,7 +1312,7 @@ namespace for (size_t iPoint = 0; iPoint < cPixels; iPoint++) { - float fDot = (pPoints[pIndex[iPoint]].r - X.r) * Dir.r + + const float fDot = (pPoints[pIndex[iPoint]].r - X.r) * Dir.r + (pPoints[pIndex[iPoint]].g - X.g) * Dir.g + (pPoints[pIndex[iPoint]].b - X.b) * Dir.b; @@ -1329,8 +1329,8 @@ namespace Diff.g = pSteps[iStep].g - pPoints[pIndex[iPoint]].g; Diff.b = pSteps[iStep].b - pPoints[pIndex[iPoint]].b; - float fC = pC[iStep] * (1.0f / 8.0f); - float fD = pD[iStep] * (1.0f / 8.0f); + const float fC = pC[iStep] * (1.0f / 8.0f); + const float fD = pD[iStep] * (1.0f / 8.0f); d2X += fC * pC[iStep]; dX.r += fC * Diff.r; @@ -1346,7 +1346,7 @@ namespace // Move endpoints if (d2X > 0.0f) { - float f = -1.0f / d2X; + const float f = -1.0f / d2X; X.r += dX.r * f; X.g += dX.g * f; @@ -1355,7 +1355,7 @@ namespace if (d2Y > 0.0f) { - float f = -1.0f / d2Y; + const float f = -1.0f / d2Y; Y.r += dY.r * f; Y.g += dY.g * f; @@ -1384,7 +1384,7 @@ namespace size_t cPixels, _In_reads_(cPixels) const size_t* pIndex) noexcept { - float fError = FLT_MAX; + constexpr float fError = FLT_MAX; const float *pC = (3 == cSteps) ? pC3 : pC4; const float *pD = (3 == cSteps) ? pD3 : pD4; @@ -1405,8 +1405,8 @@ namespace } // Diagonal axis - HDRColorA AB = Y - X; - float fAB = AB * AB; + const HDRColorA AB = Y - X; + const float fAB = AB * AB; // Single color block.. no need to root-find if (fAB < FLT_MIN) @@ -1417,9 +1417,9 @@ namespace } // Try all four axis directions, to determine which diagonal best fits data - float fABInv = 1.0f / fAB; + const float fABInv = 1.0f / fAB; HDRColorA Dir = AB * fABInv; - HDRColorA Mid = (X + Y) * 0.5f; + const HDRColorA Mid = (X + Y) * 0.5f; float fDir[8]; fDir[0] = fDir[1] = fDir[2] = fDir[3] = fDir[4] = fDir[5] = fDir[6] = fDir[7] = 0.0f; @@ -1468,7 +1468,7 @@ namespace } // Use Newton's Method to find local minima of sum-of-squares error. - auto fSteps = static_cast(cSteps - 1); + const auto fSteps = static_cast(cSteps - 1u); for (size_t iIteration = 0; iIteration < 8 && fError > 0.0f; iIteration++) { @@ -1487,11 +1487,11 @@ namespace // Calculate color direction Dir = Y - X; - float fLen = Dir * Dir; + const float fLen = Dir * Dir; if (fLen < (1.0f / 4096.0f)) break; - float fScale = fSteps / fLen; + const float fScale = fSteps / fLen; Dir *= fScale; // Evaluate function, and derivatives @@ -1500,7 +1500,7 @@ namespace for (size_t iPoint = 0; iPoint < cPixels; ++iPoint) { - float fDot = (pPoints[pIndex[iPoint]] - X) * Dir; + const float fDot = (pPoints[pIndex[iPoint]] - X) * Dir; uint32_t iStep; if (fDot <= 0.0f) @@ -1510,9 +1510,9 @@ namespace else iStep = uint32_t(fDot + 0.5f); - HDRColorA Diff = pSteps[iStep] - pPoints[pIndex[iPoint]]; - float fC = pC[iStep] * (1.0f / 8.0f); - float fD = pD[iStep] * (1.0f / 8.0f); + const HDRColorA Diff = pSteps[iStep] - pPoints[pIndex[iPoint]]; + const float fC = pC[iStep] * (1.0f / 8.0f); + const float fD = pD[iStep] * (1.0f / 8.0f); d2X += fC * pC[iStep]; dX += Diff * fC; @@ -1524,13 +1524,13 @@ namespace // Move endpoints if (d2X > 0.0f) { - float f = -1.0f / d2X; + const float f = -1.0f / d2X; X += dX * f; } if (d2Y > 0.0f) { - float f = -1.0f / d2Y; + const float f = -1.0f / d2Y; Y += dY * f; } @@ -1563,7 +1563,7 @@ namespace if (pBestIndex2) *pBestIndex2 = 0; - XMVECTOR vpixel = XMLoadUByte4(reinterpret_cast(&pixel)); + const XMVECTOR vpixel = XMLoadUByte4(reinterpret_cast(&pixel)); if (uIndexPrec2 == 0) { @@ -1572,7 +1572,7 @@ namespace XMVECTOR tpixel = XMLoadUByte4(reinterpret_cast(&aPalette[i])); // Compute ErrorMetric tpixel = XMVectorSubtract(vpixel, tpixel); - float fErr = XMVectorGetX(XMVector4Dot(tpixel, tpixel)); + const float fErr = XMVectorGetX(XMVector4Dot(tpixel, tpixel)); if (fErr > fBestErr) // error increased, so we're done searching break; if (fErr < fBestErr) @@ -1591,7 +1591,7 @@ namespace XMVECTOR tpixel = XMLoadUByte4(reinterpret_cast(&aPalette[i])); // Compute ErrorMetricRGB tpixel = XMVectorSubtract(vpixel, tpixel); - float fErr = XMVectorGetX(XMVector3Dot(tpixel, tpixel)); + const float fErr = XMVectorGetX(XMVector3Dot(tpixel, tpixel)); if (fErr > fBestErr) // error increased, so we're done searching break; if (fErr < fBestErr) @@ -1606,8 +1606,8 @@ namespace for (size_t i = 0; i < uNumIndices2 && fBestErr > 0; i++) { // Compute ErrorMetricAlpha - float ea = float(pixel.a) - float(aPalette[i].a); - float fErr = ea*ea; + const float ea = float(pixel.a) - float(aPalette[i].a); + const float fErr = ea*ea; if (fErr > fBestErr) // error increased, so we're done searching break; if (fErr < fBestErr) @@ -1675,7 +1675,7 @@ void D3DX_BC6H::Decode(bool bSigned, HDRColorA* pOut) const noexcept const size_t uHeaderBits = info.uPartitions > 0 ? 82u : 65u; while (uStartBit < uHeaderBits) { - size_t uCurBit = uStartBit; + const size_t uCurBit = uStartBit; if (GetBit(uStartBit)) { switch (desc[uCurBit].m_eField) @@ -1736,7 +1736,7 @@ void D3DX_BC6H::Decode(bool bSigned, HDRColorA* pOut) const noexcept // Read indices for (size_t i = 0; i < NUM_PIXELS_PER_BLOCK; ++i) { - size_t uNumBits = IsFixUpOffset(info.uPartitions, uShape, i) ? info.uIndexPrec - 1u : info.uIndexPrec; + const size_t uNumBits = IsFixUpOffset(info.uPartitions, uShape, i) ? info.uIndexPrec - 1u : info.uIndexPrec; if (uStartBit + uNumBits > 128) { #ifdef _DEBUG @@ -1745,7 +1745,7 @@ void D3DX_BC6H::Decode(bool bSigned, HDRColorA* pOut) const noexcept FillWithErrorColors(pOut); return; } - uint8_t uIndex = GetBits(uStartBit, uNumBits); + const uint8_t uIndex = GetBits(uStartBit, uNumBits); if (uIndex >= ((info.uPartitions > 0) ? 8 : 16)) { @@ -1756,17 +1756,17 @@ void D3DX_BC6H::Decode(bool bSigned, HDRColorA* pOut) const noexcept return; } - size_t uRegion = g_aPartitionTable[info.uPartitions][uShape][i]; + const size_t uRegion = g_aPartitionTable[info.uPartitions][uShape][i]; assert(uRegion < BC6H_MAX_REGIONS); _Analysis_assume_(uRegion < BC6H_MAX_REGIONS); // Unquantize endpoints and interpolate - int r1 = Unquantize(aEndPts[uRegion].A.r, info.RGBAPrec[0][0].r, bSigned); - int g1 = Unquantize(aEndPts[uRegion].A.g, info.RGBAPrec[0][0].g, bSigned); - int b1 = Unquantize(aEndPts[uRegion].A.b, info.RGBAPrec[0][0].b, bSigned); - int r2 = Unquantize(aEndPts[uRegion].B.r, info.RGBAPrec[0][0].r, bSigned); - int g2 = Unquantize(aEndPts[uRegion].B.g, info.RGBAPrec[0][0].g, bSigned); - int b2 = Unquantize(aEndPts[uRegion].B.b, info.RGBAPrec[0][0].b, bSigned); + const int r1 = Unquantize(aEndPts[uRegion].A.r, info.RGBAPrec[0][0].r, bSigned); + const int g1 = Unquantize(aEndPts[uRegion].A.g, info.RGBAPrec[0][0].g, bSigned); + const int b1 = Unquantize(aEndPts[uRegion].A.b, info.RGBAPrec[0][0].b, bSigned); + const int r2 = Unquantize(aEndPts[uRegion].B.r, info.RGBAPrec[0][0].r, bSigned); + const int g2 = Unquantize(aEndPts[uRegion].B.g, info.RGBAPrec[0][0].g, bSigned); + const int b2 = Unquantize(aEndPts[uRegion].B.b, info.RGBAPrec[0][0].b, bSigned); const int* aWeights = info.uPartitions > 0 ? g_aWeights3 : g_aWeights4; INTColor fc; fc.r = FinishUnquantize((r1 * (BC67_WEIGHT_MAX - aWeights[uIndex]) + r2 * aWeights[uIndex] + BC67_WEIGHT_ROUND) >> BC67_WEIGHT_SHIFT, bSigned); @@ -2031,14 +2031,14 @@ float D3DX_BC6H::MapColorsQuantized(const EncodeParams* pEP, const INTColor aCol assert(pEP); const uint8_t uIndexPrec = ms_aInfo[pEP->uMode].uIndexPrec; - auto uNumIndices = static_cast(1u << uIndexPrec); + auto const uNumIndices = static_cast(1u << uIndexPrec); INTColor aPalette[BC6H_MAX_INDICES]; GeneratePaletteQuantized(pEP, endPts, aPalette); float fTotErr = 0; for (size_t i = 0; i < np; ++i) { - XMVECTOR vcolors = XMLoadSInt4(reinterpret_cast(&aColors[i])); + const XMVECTOR vcolors = XMLoadSInt4(reinterpret_cast(&aColors[i])); // Compute ErrorMetricRGB XMVECTOR tpal = XMLoadSInt4(reinterpret_cast(&aPalette[0])); @@ -2050,7 +2050,7 @@ float D3DX_BC6H::MapColorsQuantized(const EncodeParams* pEP, const INTColor aCol // Compute ErrorMetricRGB tpal = XMLoadSInt4(reinterpret_cast(&aPalette[j])); tpal = XMVectorSubtract(vcolors, tpal); - float fErr = XMVectorGetX(XMVector3Dot(tpal, tpal)); + const float fErr = XMVectorGetX(XMVector3Dot(tpal, tpal)); if (fErr > fBestErr) break; // error increased, so we're done searching if (fErr < fBestErr) fBestErr = fErr; } @@ -2099,7 +2099,7 @@ float D3DX_BC6H::PerturbOne(const EncodeParams* pEP, const INTColor aColors[], s continue; } - float fErr = MapColorsQuantized(pEP, aColors, np, tmpEndPts); + const float fErr = MapColorsQuantized(pEP, aColors, np, tmpEndPts); if (fErr < fMinErr) { @@ -2139,8 +2139,8 @@ void D3DX_BC6H::OptimizeOne(const EncodeParams* pEP, const INTColor aColors[], s { // figure out which endpoint when perturbed gives the most improvement and start there // if we just alternate, we can easily end up in a local minima - float fErr0 = PerturbOne(pEP, aColors, np, ch, aOptEndPts, new_a, aOptErr, 0); // perturb endpt A - float fErr1 = PerturbOne(pEP, aColors, np, ch, aOptEndPts, new_b, aOptErr, 1); // perturb endpt B + const float fErr0 = PerturbOne(pEP, aColors, np, ch, aOptEndPts, new_a, aOptErr, 0); // perturb endpt A + const float fErr1 = PerturbOne(pEP, aColors, np, ch, aOptEndPts, new_b, aOptErr, 1); // perturb endpt B if (fErr0 < fErr1) { @@ -2160,7 +2160,7 @@ void D3DX_BC6H::OptimizeOne(const EncodeParams* pEP, const INTColor aColors[], s // now alternate endpoints and keep trying until there is no improvement for (;;) { - float fErr = PerturbOne(pEP, aColors, np, ch, aOptEndPts, newEndPts, aOptErr, do_b); + const float fErr = PerturbOne(pEP, aColors, np, ch, aOptEndPts, newEndPts, aOptErr, do_b); if (fErr >= aOptErr) break; if (do_b == 0) @@ -2214,7 +2214,7 @@ void D3DX_BC6H::SwapIndices(const EncodeParams* pEP, INTEndPntPair aEndPts[], si for (size_t p = 0; p <= uPartitions; ++p) { - size_t i = g_aFixUp[uPartitions][pEP->uShape][p]; + const size_t i = g_aFixUp[uPartitions][pEP->uShape][p]; assert(g_aPartitionTable[uPartitions][pEP->uShape][i] == p); if (aIndices[i] & uHighIndexBit) { @@ -2235,7 +2235,7 @@ void D3DX_BC6H::AssignIndices(const EncodeParams* pEP, const INTEndPntPair aEndP { assert(pEP); const uint8_t uPartitions = ms_aInfo[pEP->uMode].uPartitions; - auto uNumIndices = static_cast(1u << ms_aInfo[pEP->uMode].uIndexPrec); + auto const 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); @@ -2259,7 +2259,7 @@ void D3DX_BC6H::AssignIndices(const EncodeParams* pEP, const INTEndPntPair aEndP for (uint8_t j = 1; j < uNumIndices && fBestErr > 0; ++j) { - float fErr = Norm(pEP->aIPixels[i], aPalette[uRegion][j]); + const float fErr = Norm(pEP->aIPixels[i], aPalette[uRegion][j]); if (fErr > fBestErr) break; // error increased, so we're done searching if (fErr < fBestErr) { @@ -2396,7 +2396,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; - auto uNumIndices = static_cast(1u << uIndexPrec); + auto const uNumIndices = static_cast(1u << uIndexPrec); assert(uNumIndices > 0); _Analysis_assume_(uNumIndices > 0); @@ -2429,7 +2429,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; - auto uNumIndices = static_cast(1u << uIndexPrec); + auto const uNumIndices = static_cast(1u << uIndexPrec); INTColor aPalette[BC6H_MAX_INDICES]; GeneratePaletteUnquantized(pEP, uRegion, aPalette); @@ -2439,7 +2439,7 @@ float D3DX_BC6H::MapColors(const EncodeParams* pEP, size_t uRegion, size_t np, c float fBestErr = Norm(pEP->aIPixels[auIndex[i]], aPalette[0]); for (uint8_t j = 1; j < uNumIndices && fBestErr > 0.0f; ++j) { - float fErr = Norm(pEP->aIPixels[auIndex[i]], aPalette[j]); + const float fErr = Norm(pEP->aIPixels[auIndex[i]], aPalette[j]); if (fErr > fBestErr) break; // error increased, so we're done searching if (fErr < fBestErr) fBestErr = fErr; } @@ -2523,7 +2523,7 @@ void D3DX_BC7::Decode(HDRColorA* pOut) const noexcept size_t uFirst = 0; while (uFirst < 128 && !GetBit(uFirst)) {} - uint8_t uMode = uint8_t(uFirst - 1); + const uint8_t uMode = uint8_t(uFirst - 1); if (uMode < 8) { @@ -2531,20 +2531,20 @@ void D3DX_BC7::Decode(HDRColorA* pOut) const noexcept assert(uPartitions < BC7_MAX_REGIONS); _Analysis_assume_(uPartitions < BC7_MAX_REGIONS); - auto uNumEndPts = static_cast((unsigned(uPartitions) + 1u) << 1); + auto const 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; size_t uStartBit = size_t(uMode) + 1; uint8_t P[6]; - uint8_t uShape = GetBits(uStartBit, ms_aInfo[uMode].uPartitionBits); + const uint8_t uShape = GetBits(uStartBit, ms_aInfo[uMode].uPartitionBits); assert(uShape < BC7_MAX_SHAPES); _Analysis_assume_(uShape < BC7_MAX_SHAPES); - uint8_t uRotation = GetBits(uStartBit, ms_aInfo[uMode].uRotationBits); + const uint8_t uRotation = GetBits(uStartBit, ms_aInfo[uMode].uRotationBits); assert(uRotation < 4); - uint8_t uIndexMode = GetBits(uStartBit, ms_aInfo[uMode].uIndexModeBits); + const uint8_t uIndexMode = GetBits(uStartBit, ms_aInfo[uMode].uIndexModeBits); assert(uIndexMode < 2); LDRColorA c[BC7_MAX_REGIONS << 1]; @@ -2655,7 +2655,7 @@ void D3DX_BC7::Decode(HDRColorA* pOut) const noexcept // read color indices for (i = 0; i < NUM_PIXELS_PER_BLOCK; i++) { - size_t uNumBits = IsFixUpOffset(ms_aInfo[uMode].uPartitions, uShape, i) ? uIndexPrec - 1u : uIndexPrec; + const size_t uNumBits = IsFixUpOffset(ms_aInfo[uMode].uPartitions, uShape, i) ? uIndexPrec - 1u : uIndexPrec; if (uStartBit + uNumBits > 128) { #ifdef _DEBUG @@ -2672,7 +2672,7 @@ void D3DX_BC7::Decode(HDRColorA* pOut) const noexcept { for (i = 0; i < NUM_PIXELS_PER_BLOCK; i++) { - size_t uNumBits = i ? uIndexPrec2 : uIndexPrec2 - 1u; + const size_t uNumBits = i ? uIndexPrec2 : uIndexPrec2 - 1u; if (uStartBit + uNumBits > 128) { #ifdef _DEBUG @@ -2687,7 +2687,7 @@ void D3DX_BC7::Decode(HDRColorA* pOut) const noexcept for (i = 0; i < NUM_PIXELS_PER_BLOCK; ++i) { - uint8_t uRegion = g_aPartitionTable[uPartitions][uShape][i]; + const uint8_t uRegion = g_aPartitionTable[uPartitions][uShape][i]; LDRColorA outPixel; if (uIndexPrec2 == 0) { @@ -2811,7 +2811,7 @@ void D3DX_BC7::Encode(uint32_t flags, const HDRColorA* const pIn) noexcept for (size_t i = 0; i < uItems && fMSEBest > 0; i++) { - float fMSE = Refine(&EP, auShape[i], r, im); + const float fMSE = Refine(&EP, auShape[i], r, im); if (fMSE < fMSEBest) { final = *this; @@ -2847,8 +2847,8 @@ void D3DX_BC7::GeneratePaletteQuantized(const EncodeParams* pEP, size_t uIndexMo assert((uNumIndices <= BC7_MAX_INDICES) && (uNumIndices2 <= BC7_MAX_INDICES)); _Analysis_assume_((uNumIndices <= BC7_MAX_INDICES) && (uNumIndices2 <= BC7_MAX_INDICES)); - LDRColorA a = Unquantize(endPts.A, ms_aInfo[pEP->uMode].RGBAPrecWithP); - LDRColorA b = Unquantize(endPts.B, ms_aInfo[pEP->uMode].RGBAPrecWithP); + const LDRColorA a = Unquantize(endPts.A, ms_aInfo[pEP->uMode].RGBAPrecWithP); + const LDRColorA b = Unquantize(endPts.B, ms_aInfo[pEP->uMode].RGBAPrecWithP); if (uIndexPrec2 == 0) { for (size_t i = 0; i < uNumIndices; i++) @@ -2887,7 +2887,7 @@ float D3DX_BC7::PerturbOne(const EncodeParams* pEP, const LDRColorA aColors[], s else *ptmp_c = static_cast(tmp); - float fTotalErr = MapColors(pEP, aColors, np, uIndexMode, tmp_endPts, fMinErr); + const float fTotalErr = MapColors(pEP, aColors, np, uIndexMode, tmp_endPts, fMinErr); if (fTotalErr < fMinErr) { bImproved = true; @@ -2915,14 +2915,14 @@ void D3DX_BC7::Exhaustive(const EncodeParams* pEP, const LDRColorA aColors[], si if (fOrgErr == 0) return; - int delta = 5; + constexpr int delta = 5; // ok figure out the range of A and B tmpEndPt = optEndPt; - int alow = std::max(0, int(optEndPt.A[ch]) - delta); - int ahigh = std::min((1 << uPrec) - 1, int(optEndPt.A[ch]) + delta); - int blow = std::max(0, int(optEndPt.B[ch]) - delta); - int bhigh = std::min((1 << uPrec) - 1, int(optEndPt.B[ch]) + delta); + const int alow = std::max(0, int(optEndPt.A[ch]) - delta); + const int ahigh = std::min((1 << uPrec) - 1, int(optEndPt.A[ch]) + delta); + const int blow = std::max(0, int(optEndPt.B[ch]) - delta); + const int bhigh = std::min((1 << uPrec) - 1, int(optEndPt.B[ch]) + delta); int amin = 0; int bmin = 0; @@ -2937,7 +2937,7 @@ void D3DX_BC7::Exhaustive(const EncodeParams* pEP, const LDRColorA aColors[], si tmpEndPt.A[ch] = static_cast(a); tmpEndPt.B[ch] = static_cast(b); - float fErr = MapColors(pEP, aColors, np, uIndexMode, tmpEndPt, fBestErr); + const float fErr = MapColors(pEP, aColors, np, uIndexMode, tmpEndPt, fBestErr); if (fErr < fBestErr) { amin = a; @@ -2957,7 +2957,7 @@ void D3DX_BC7::Exhaustive(const EncodeParams* pEP, const LDRColorA aColors[], si tmpEndPt.A[ch] = static_cast(a); tmpEndPt.B[ch] = static_cast(b); - float fErr = MapColors(pEP, aColors, np, uIndexMode, tmpEndPt, fBestErr); + const float fErr = MapColors(pEP, aColors, np, uIndexMode, tmpEndPt, fBestErr); if (fErr < fBestErr) { amin = a; @@ -2997,8 +2997,8 @@ void D3DX_BC7::OptimizeOne(const EncodeParams* pEP, const LDRColorA aColors[], s // figure out which endpoint when perturbed gives the most improvement and start there // if we just alternate, we can easily end up in a local minima - float fErr0 = PerturbOne(pEP, aColors, np, uIndexMode, ch, opt, new_a, fOptErr, 0); // perturb endpt A - float fErr1 = PerturbOne(pEP, aColors, np, uIndexMode, ch, opt, new_b, fOptErr, 1); // perturb endpt B + const float fErr0 = PerturbOne(pEP, aColors, np, uIndexMode, ch, opt, new_a, fOptErr, 0); // perturb endpt A + const float fErr1 = PerturbOne(pEP, aColors, np, uIndexMode, ch, opt, new_b, fOptErr, 1); // perturb endpt B uint8_t& copt_a = opt.A[ch]; uint8_t& copt_b = opt.B[ch]; @@ -3025,7 +3025,7 @@ void D3DX_BC7::OptimizeOne(const EncodeParams* pEP, const LDRColorA aColors[], s // now alternate endpoints and keep trying until there is no improvement for (; ; ) { - float fErr = PerturbOne(pEP, aColors, np, uIndexMode, ch, opt, newEndPts, fOptErr, do_b); + const float fErr = PerturbOne(pEP, aColors, np, uIndexMode, ch, opt, newEndPts, fOptErr, do_b); if (fErr >= fOptErr) break; if (do_b == 0) @@ -3079,8 +3079,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; - auto uNumIndices = static_cast(1u << uIndexPrec); - auto uNumIndices2 = static_cast(1u << uIndexPrec2); + auto const uNumIndices = static_cast(1u << uIndexPrec); + auto const uNumIndices2 = static_cast(1u << uIndexPrec2); assert((uNumIndices <= BC7_MAX_INDICES) && (uNumIndices2 <= BC7_MAX_INDICES)); _Analysis_assume_((uNumIndices <= BC7_MAX_INDICES) && (uNumIndices2 <= BC7_MAX_INDICES)); @@ -3412,8 +3412,8 @@ float D3DX_BC7::RoughMSE(EncodeParams* pEP, size_t uShape, size_t uIndexMode) no 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; - auto uNumIndices = static_cast(1u << uIndexPrec); - auto uNumIndices2 = static_cast(1u << uIndexPrec2); + auto const uNumIndices = static_cast(1u << uIndexPrec); + auto const uNumIndices2 = static_cast(1u << uIndexPrec2); size_t auPixIdx[NUM_PIXELS_PER_BLOCK]; LDRColorA aPalette[BC7_MAX_REGIONS][BC7_MAX_INDICES]; @@ -3496,7 +3496,7 @@ float D3DX_BC7::RoughMSE(EncodeParams* pEP, size_t uShape, size_t uIndexMode) no float fTotalErr = 0; for (size_t i = 0; i < NUM_PIXELS_PER_BLOCK; i++) { - uint8_t uRegion = g_aPartitionTable[uPartitions][uShape][i]; + const uint8_t uRegion = g_aPartitionTable[uPartitions][uShape][i]; fTotalErr += ComputeError(pEP->aLDRPixels[i], aPalette[uRegion], uIndexPrec, uIndexPrec2); } diff --git a/DirectXTex/BCDirectCompute.cpp b/DirectXTex/BCDirectCompute.cpp index 61a9c3f..b7aaa09 100644 --- a/DirectXTex/BCDirectCompute.cpp +++ b/DirectXTex/BCDirectCompute.cpp @@ -99,7 +99,7 @@ HRESULT GPUCompressBC::Initialize(ID3D11Device* pDevice) return E_INVALIDARG; // Check for DirectCompute support - D3D_FEATURE_LEVEL fl = pDevice->GetFeatureLevel(); + const D3D_FEATURE_LEVEL fl = pDevice->GetFeatureLevel(); if (fl < D3D_FEATURE_LEVEL_10_0) { @@ -197,9 +197,9 @@ HRESULT GPUCompressBC::Prepare(size_t width, size_t height, uint32_t flags, DXGI m_bc7_mode137 = true; } - size_t xblocks = std::max(1, (width + 3) >> 2); - size_t yblocks = std::max(1, (height + 3) >> 2); - size_t num_blocks = xblocks * yblocks; + const size_t xblocks = std::max(1, (width + 3) >> 2); + const size_t yblocks = std::max(1, (height + 3) >> 2); + const size_t num_blocks = xblocks * yblocks; switch (format) { @@ -232,11 +232,11 @@ HRESULT GPUCompressBC::Prepare(size_t width, size_t height, uint32_t flags, DXGI return E_POINTER; // Create structured buffers - uint64_t sizeInBytes = uint64_t(num_blocks) * sizeof(BufferBC6HBC7); + const uint64_t sizeInBytes = uint64_t(num_blocks) * sizeof(BufferBC6HBC7); if (sizeInBytes >= UINT32_MAX) return HRESULT_E_ARITHMETIC_OVERFLOW; - auto bufferSize = static_cast(sizeInBytes); + auto const bufferSize = static_cast(sizeInBytes); { D3D11_BUFFER_DESC desc = {}; @@ -364,7 +364,7 @@ HRESULT GPUCompressBC::Compress(const Image& srcImage, const Image& destImage) return E_POINTER; // We need to avoid the hardware doing additional colorspace conversion - DXGI_FORMAT inputFormat = (m_srcformat == DXGI_FORMAT_R8G8B8A8_UNORM_SRGB) ? DXGI_FORMAT_R8G8B8A8_UNORM : m_srcformat; + const DXGI_FORMAT inputFormat = (m_srcformat == DXGI_FORMAT_R8G8B8A8_UNORM_SRGB) ? DXGI_FORMAT_R8G8B8A8_UNORM : m_srcformat; ComPtr sourceTex; { @@ -423,22 +423,22 @@ HRESULT GPUCompressBC::Compress(const Image& srcImage, const Image& destImage) return E_UNEXPECTED; } - const UINT MAX_BLOCK_BATCH = 64; + constexpr UINT MAX_BLOCK_BATCH = 64u; auto pContext = m_context.Get(); if (!pContext) return E_UNEXPECTED; - size_t xblocks = std::max(1, (m_width + 3) >> 2); - size_t yblocks = std::max(1, (m_height + 3) >> 2); + const size_t xblocks = std::max(1, (m_width + 3) >> 2); + const size_t yblocks = std::max(1, (m_height + 3) >> 2); - auto num_total_blocks = static_cast(xblocks * yblocks); + auto const num_total_blocks = static_cast(xblocks * yblocks); UINT num_blocks = num_total_blocks; UINT start_block_id = 0; while (num_blocks > 0) { - UINT n = std::min(num_blocks, MAX_BLOCK_BATCH); - UINT uThreadGroupCount = n; + const UINT n = std::min(num_blocks, MAX_BLOCK_BATCH); + const UINT uThreadGroupCount = n; { D3D11_MAPPED_SUBRESOURCE mapped; @@ -597,9 +597,9 @@ HRESULT GPUCompressBC::Compress(const Image& srcImage, const Image& destImage) auto pSrc = static_cast(mapped.pData); uint8_t *pDest = destImage.pixels; - size_t pitch = xblocks * sizeof(BufferBC6HBC7); + const size_t pitch = xblocks * sizeof(BufferBC6HBC7); - size_t rows = std::max(1, (destImage.height + 3) >> 2); + const size_t rows = std::max(1, (destImage.height + 3) >> 2); for (size_t h = 0; h < rows; ++h) { diff --git a/DirectXTex/DirectXTex.h b/DirectXTex/DirectXTex.h index 7a82975..896d288 100644 --- a/DirectXTex/DirectXTex.h +++ b/DirectXTex/DirectXTex.h @@ -598,7 +598,7 @@ namespace DirectX // Resize the image to width x height. Defaults to Fant filtering. // Note for a complex resize, the result will always have mipLevels == 1 - const float TEX_THRESHOLD_DEFAULT = 0.5f; + constexpr float TEX_THRESHOLD_DEFAULT = 0.5f; // Default value for alpha threshold used when converting to 1-bit alpha HRESULT __cdecl Convert( diff --git a/DirectXTex/DirectXTexCompress.cpp b/DirectXTex/DirectXTexCompress.cpp index b57f913..af6a9a2 100644 --- a/DirectXTex/DirectXTexCompress.cpp +++ b/DirectXTex/DirectXTexCompress.cpp @@ -23,7 +23,7 @@ using namespace DirectX::Internal; namespace { - inline uint32_t GetBCFlags(_In_ TEX_COMPRESS_FLAGS compress) noexcept + constexpr uint32_t GetBCFlags(_In_ TEX_COMPRESS_FLAGS compress) noexcept { static_assert(static_cast(TEX_COMPRESS_RGB_DITHER) == static_cast(BC_FLAGS_DITHER_RGB), "TEX_COMPRESS_* flags should match BC_FLAGS_*"); static_assert(static_cast(TEX_COMPRESS_A_DITHER) == static_cast(BC_FLAGS_DITHER_A), "TEX_COMPRESS_* flags should match BC_FLAGS_*"); @@ -34,7 +34,7 @@ namespace return (compress & (BC_FLAGS_DITHER_RGB | BC_FLAGS_DITHER_A | BC_FLAGS_UNIFORM | BC_FLAGS_USE_3SUBSETS | BC_FLAGS_FORCE_BC7_MODE6)); } - inline TEX_FILTER_FLAGS GetSRGBFlags(_In_ TEX_COMPRESS_FLAGS compress) noexcept + constexpr TEX_FILTER_FLAGS GetSRGBFlags(_In_ TEX_COMPRESS_FLAGS compress) noexcept { static_assert(TEX_FILTER_SRGB_IN == 0x1000000, "TEX_FILTER_SRGB flag values don't match TEX_FILTER_SRGB_MASK"); static_assert(static_cast(TEX_COMPRESS_SRGB_IN) == static_cast(TEX_FILTER_SRGB_IN), "TEX_COMPRESS_SRGB* should match TEX_FILTER_SRGB*"); @@ -113,14 +113,14 @@ namespace { const uint8_t *sptr = pSrc; uint8_t* dptr = pDest; - size_t ph = std::min(4, image.height - h); + const size_t ph = std::min(4, image.height - h); size_t w = 0; for (size_t count = 0; (count < result.rowPitch) && (w < image.width); count += blocksize, w += 4) { - size_t pw = std::min(4, image.width - w); + const size_t pw = std::min(4, image.width - w); assert(pw > 0 && ph > 0); - ptrdiff_t bytesLeft = pEnd - sptr; + const ptrdiff_t bytesLeft = pEnd - sptr; assert(bytesLeft > 0); size_t bytesToRead = std::min(rowPitch, static_cast(bytesLeft)); if (!LoadScanline(&temp[0], pw, sptr, bytesToRead, format)) @@ -242,25 +242,25 @@ namespace #pragma omp parallel for for (int nb = 0; nb < static_cast(nBlocks); ++nb) { - int nbWidth = std::max(1, int((image.width + 3) / 4)); + const int nbWidth = std::max(1, int((image.width + 3) / 4)); int y = nb / nbWidth; - int x = (nb - (y*nbWidth)) * 4; + const int x = (nb - (y*nbWidth)) * 4; y *= 4; assert((x >= 0) && (x < int(image.width))); assert((y >= 0) && (y < int(image.height))); - size_t rowPitch = image.rowPitch; + const size_t rowPitch = image.rowPitch; const uint8_t *pSrc = image.pixels + (size_t(y)*rowPitch) + (size_t(x)*sbpp); uint8_t *pDest = result.pixels + (size_t(nb)*blocksize); - size_t ph = std::min(4, image.height - size_t(y)); - size_t pw = std::min(4, image.width - size_t(x)); + const size_t ph = std::min(4, image.height - size_t(y)); + const size_t pw = std::min(4, image.width - size_t(x)); assert(pw > 0 && ph > 0); - ptrdiff_t bytesLeft = pEnd - pSrc; + const ptrdiff_t bytesLeft = pEnd - pSrc; assert(bytesLeft > 0); size_t bytesToRead = std::min(rowPitch, size_t(bytesLeft)); @@ -449,14 +449,14 @@ namespace { const uint8_t *sptr = pSrc; uint8_t* dptr = pDest; - size_t ph = std::min(4, cImage.height - h); + const size_t ph = std::min(4, cImage.height - h); size_t w = 0; for (size_t count = 0; (count < cImage.rowPitch) && (w < cImage.width); count += sbpp, w += 4) { pfDecode(temp, sptr); ConvertScanline(temp, 16, format, cformat, TEX_FILTER_DEFAULT); - size_t pw = std::min(4, cImage.width - w); + const size_t pw = std::min(4, cImage.width - w); assert(pw > 0 && ph > 0); if (!StoreScanline(dptr, rowPitch, format, &temp[0], pw)) @@ -535,13 +535,13 @@ bool DirectX::Internal::IsAlphaAllOpaqueBC(_In_ const Image& cImage) noexcept for (size_t h = 0; h < cImage.height; h += 4) { const uint8_t* ptr = pPixels; - size_t ph = std::min(4, cImage.height - h); + const size_t ph = std::min(4, cImage.height - h); size_t w = 0; for (size_t count = 0; (count < cImage.rowPitch) && (w < cImage.width); count += sbpp, w += 4) { pfDecode(temp, ptr); - size_t pw = std::min(4, cImage.width - w); + const size_t pw = std::min(4, cImage.width - w); assert(pw > 0 && ph > 0); if (pw == 4 && ph == 4) @@ -549,7 +549,7 @@ bool DirectX::Internal::IsAlphaAllOpaqueBC(_In_ const Image& cImage) noexcept // Full blocks for (size_t j = 0; j < 16; ++j) { - XMVECTOR alpha = XMVectorSplatW(temp[j]); + const XMVECTOR alpha = XMVectorSplatW(temp[j]); if (XMVector4Less(alpha, threshold)) return false; } @@ -561,7 +561,7 @@ bool DirectX::Internal::IsAlphaAllOpaqueBC(_In_ const Image& cImage) noexcept { for (size_t x = 0; x < pw; ++x) { - XMVECTOR alpha = XMVectorSplatW(temp[y * 4 + x]); + const XMVECTOR alpha = XMVectorSplatW(temp[y * 4 + x]); if (XMVector4Less(alpha, threshold)) return false; } diff --git a/DirectXTex/DirectXTexCompressGPU.cpp b/DirectXTex/DirectXTexCompressGPU.cpp index 2c89d59..e4575e0 100644 --- a/DirectXTex/DirectXTexCompressGPU.cpp +++ b/DirectXTex/DirectXTexCompressGPU.cpp @@ -18,7 +18,7 @@ using namespace DirectX::Internal; namespace { - inline TEX_FILTER_FLAGS GetSRGBFlags(_In_ TEX_COMPRESS_FLAGS compress) noexcept + constexpr TEX_FILTER_FLAGS GetSRGBFlags(_In_ TEX_COMPRESS_FLAGS compress) noexcept { static_assert(TEX_FILTER_SRGB_IN == 0x1000000, "TEX_FILTER_SRGB flag values don't match TEX_FILTER_SRGB_MASK"); static_assert(static_cast(TEX_COMPRESS_SRGB_IN) == static_cast(TEX_FILTER_SRGB_IN), "TEX_COMPRESS_SRGB* should match TEX_FILTER_SRGB*"); @@ -40,7 +40,7 @@ namespace if (!srcImage.pixels) return E_POINTER; - DXGI_FORMAT format = srgb ? DXGI_FORMAT_R8G8B8A8_UNORM_SRGB : DXGI_FORMAT_R8G8B8A8_UNORM; + const DXGI_FORMAT format = srgb ? DXGI_FORMAT_R8G8B8A8_UNORM_SRGB : DXGI_FORMAT_R8G8B8A8_UNORM; HRESULT hr = image.Initialize2D(format, srcImage.width, srcImage.height, 1, 1); if (FAILED(hr)) @@ -154,7 +154,7 @@ namespace assert(srcImage.pixels && destImage.pixels); - DXGI_FORMAT format = gpubc->GetSourceFormat(); + const DXGI_FORMAT format = gpubc->GetSourceFormat(); if (srcImage.format == format) { @@ -167,7 +167,7 @@ namespace ScratchImage image; HRESULT hr = E_UNEXPECTED; - auto srgb = GetSRGBFlags(compress); + auto const srgb = GetSRGBFlags(compress); switch (format) { @@ -326,7 +326,7 @@ HRESULT DirectX::Compress( for (size_t item = 0; item < metadata.arraySize; ++item) { - size_t index = metadata.ComputeIndex(level, item, 0); + const size_t index = metadata.ComputeIndex(level, item, 0); if (index >= nimages) { cImages.Release(); @@ -377,7 +377,7 @@ HRESULT DirectX::Compress( for (size_t slice = 0; slice < d; ++slice) { - size_t index = metadata.ComputeIndex(level, 0, slice); + const size_t index = metadata.ComputeIndex(level, 0, slice); if (index >= nimages) { cImages.Release(); diff --git a/DirectXTex/DirectXTexConvert.cpp b/DirectXTex/DirectXTexConvert.cpp index 8c7a2c2..e75b8c4 100644 --- a/DirectXTex/DirectXTexConvert.cpp +++ b/DirectXTex/DirectXTexConvert.cpp @@ -38,7 +38,7 @@ namespace { // The number is too small to be represented as a normalized 7e3. // Convert it to a denormalized value. - uint32_t Shift = std::min(125U - (IValue >> 23U), 24U); + const uint32_t Shift = std::min(125U - (IValue >> 23U), 24U); IValue = (0x800000U | (IValue & 0x7FFFFFU)) >> Shift; } else @@ -78,10 +78,10 @@ namespace Exponent = uint32_t(-124); } - uint32_t Result = ((Exponent + 124) << 23) | // Exponent + const uint32_t Result = ((Exponent + 124) << 23) | // Exponent (Mantissa << 16); // Mantissa - return reinterpret_cast(&Result)[0]; + return reinterpret_cast(&Result)[0]; } inline uint32_t FloatTo6e4(float Value) noexcept @@ -104,7 +104,7 @@ namespace { // The number is too small to be represented as a normalized 6e4. // Convert it to a denormalized value. - uint32_t Shift = std::min(121U - (IValue >> 23U), 24U); + const uint32_t Shift = std::min(121U - (IValue >> 23U), 24U); IValue = (0x800000U | (IValue & 0x7FFFFFU)) >> Shift; } else @@ -144,10 +144,10 @@ namespace Exponent = uint32_t(-120); } - uint32_t Result = ((Exponent + 120) << 23) | // Exponent + const uint32_t Result = ((Exponent + 120) << 23) | // Exponent (Mantissa << 17); // Mantissa - return reinterpret_cast(&Result)[0]; + return reinterpret_cast(&Result)[0]; } #if DIRECTX_MATH_VERSION >= 310 @@ -244,7 +244,7 @@ void DirectX::Internal::CopyScanline( { const uint32_t * __restrict sPtr = static_cast(pSource); uint32_t * __restrict dPtr = static_cast(pDestination); - size_t size = std::min(outSize, inSize); + const size_t size = std::min(outSize, inSize); for (size_t count = 0; count < (size - 15); count += 16) { *(dPtr++) = *(sPtr++); @@ -288,7 +288,7 @@ void DirectX::Internal::CopyScanline( { const uint16_t * __restrict sPtr = static_cast(pSource); uint16_t * __restrict dPtr = static_cast(pDestination); - size_t size = std::min(outSize, inSize); + const size_t size = std::min(outSize, inSize); for (size_t count = 0; count < (size - 7); count += 8) { *(dPtr++) = *(sPtr++); @@ -325,7 +325,7 @@ void DirectX::Internal::CopyScanline( { const uint32_t * __restrict sPtr = static_cast(pSource); uint32_t * __restrict dPtr = static_cast(pDestination); - size_t size = std::min(outSize, inSize); + const size_t size = std::min(outSize, inSize); for (size_t count = 0; count < (size - 3); count += 4) { *(dPtr++) = *(sPtr++) | 0xC0000000; @@ -363,7 +363,7 @@ void DirectX::Internal::CopyScanline( { const uint32_t * __restrict sPtr = static_cast(pSource); uint32_t * __restrict dPtr = static_cast(pDestination); - size_t size = std::min(outSize, inSize); + const size_t size = std::min(outSize, inSize); for (size_t count = 0; count < (size - 3); count += 4) { uint32_t t = *(sPtr++) & 0xFFFFFF; @@ -390,7 +390,7 @@ void DirectX::Internal::CopyScanline( { const uint16_t * __restrict sPtr = static_cast(pSource); uint16_t * __restrict dPtr = static_cast(pDestination); - size_t size = std::min(outSize, inSize); + const size_t size = std::min(outSize, inSize); for (size_t count = 0; count < (size - 1); count += 2) { *(dPtr++) = uint16_t(*(sPtr++) | 0x8000); @@ -420,7 +420,7 @@ void DirectX::Internal::CopyScanline( { const uint16_t * __restrict sPtr = static_cast(pSource); uint16_t * __restrict dPtr = static_cast(pDestination); - size_t size = std::min(outSize, inSize); + const size_t size = std::min(outSize, inSize); for (size_t count = 0; count < (size - 1); count += 2) { *(dPtr++) = uint16_t(*(sPtr++) | 0xF000); @@ -435,7 +435,7 @@ void DirectX::Internal::CopyScanline( if (pDestination == pSource) return; - size_t size = std::min(outSize, inSize); + const size_t size = std::min(outSize, inSize); memcpy(pDestination, pSource, size); } @@ -475,7 +475,7 @@ void DirectX::Internal::SwizzleScanline( auto dPtr = static_cast(pDestination); for (size_t count = 0; count < (outSize - 3); count += 4) { - uint32_t t = *dPtr; + const uint32_t t = *dPtr; uint32_t t1 = (t & 0x3ff00000) >> 20; uint32_t t2 = (t & 0x000003ff) << 20; @@ -489,10 +489,10 @@ void DirectX::Internal::SwizzleScanline( { const uint32_t * __restrict sPtr = static_cast(pSource); uint32_t * __restrict dPtr = static_cast(pDestination); - size_t size = std::min(outSize, inSize); + const size_t size = std::min(outSize, inSize); for (size_t count = 0; count < (size - 3); count += 4) { - uint32_t t = *(sPtr++); + const uint32_t t = *(sPtr++); uint32_t t1 = (t & 0x3ff00000) >> 20; uint32_t t2 = (t & 0x000003ff) << 20; @@ -525,7 +525,7 @@ void DirectX::Internal::SwizzleScanline( auto dPtr = static_cast(pDestination); for (size_t count = 0; count < (outSize - 3); count += 4) { - uint32_t t = *dPtr; + const uint32_t t = *dPtr; uint32_t t1 = (t & 0x00ff0000) >> 16; uint32_t t2 = (t & 0x000000ff) << 16; @@ -539,10 +539,10 @@ void DirectX::Internal::SwizzleScanline( { const uint32_t * __restrict sPtr = static_cast(pSource); uint32_t * __restrict dPtr = static_cast(pDestination); - size_t size = std::min(outSize, inSize); + const size_t size = std::min(outSize, inSize); for (size_t count = 0; count < (size - 3); count += 4) { - uint32_t t = *(sPtr++); + const uint32_t t = *(sPtr++); uint32_t t1 = (t & 0x00ff0000) >> 16; uint32_t t2 = (t & 0x000000ff) << 16; @@ -568,7 +568,7 @@ void DirectX::Internal::SwizzleScanline( auto dPtr = static_cast(pDestination); for (size_t count = 0; count < (outSize - 3); count += 4) { - uint32_t t = *dPtr; + const uint32_t t = *dPtr; uint32_t t1 = (t & 0x000000ff) << 8; uint32_t t2 = (t & 0x0000ff00) >> 8; @@ -582,10 +582,10 @@ void DirectX::Internal::SwizzleScanline( { const uint32_t * __restrict sPtr = static_cast(pSource); uint32_t * __restrict dPtr = static_cast(pDestination); - size_t size = std::min(outSize, inSize); + const size_t size = std::min(outSize, inSize); for (size_t count = 0; count < (size - 3); count += 4) { - uint32_t t = *(sPtr++); + const uint32_t t = *(sPtr++); uint32_t t1 = (t & 0x000000ff) << 8; uint32_t t2 = (t & 0x0000ff00) >> 8; @@ -605,7 +605,7 @@ void DirectX::Internal::SwizzleScanline( if (pDestination == pSource) return; - size_t size = std::min(outSize, inSize); + const size_t size = std::min(outSize, inSize); memcpy(pDestination, pSource, size); } @@ -643,7 +643,7 @@ bool DirectX::Internal::ExpandScanline( for (size_t ocount = 0, icount = 0; ((icount < (inSize - 1)) && (ocount < (outSize - 3))); icount += 2, ocount += 4) { - uint16_t t = *(sPtr++); + const uint16_t t = *(sPtr++); uint32_t t1 = uint32_t(((t & 0xf800) >> 8) | ((t & 0xe000) >> 13)); uint32_t t2 = uint32_t(((t & 0x07e0) << 5) | ((t & 0x0600) >> 5)); @@ -667,7 +667,7 @@ bool DirectX::Internal::ExpandScanline( for (size_t ocount = 0, icount = 0; ((icount < (inSize - 1)) && (ocount < (outSize - 3))); icount += 2, ocount += 4) { - uint16_t t = *(sPtr++); + const uint16_t t = *(sPtr++); uint32_t t1 = uint32_t(((t & 0x7c00) >> 7) | ((t & 0x7000) >> 12)); uint32_t t2 = uint32_t(((t & 0x03e0) << 6) | ((t & 0x0380) << 1)); @@ -692,7 +692,7 @@ bool DirectX::Internal::ExpandScanline( for (size_t ocount = 0, icount = 0; ((icount < (inSize - 1)) && (ocount < (outSize - 3))); icount += 2, ocount += 4) { - uint16_t t = *(sPtr++); + const uint16_t t = *(sPtr++); uint32_t t1 = uint32_t(((t & 0x0f00) >> 4) | ((t & 0x0f00) >> 8)); uint32_t t2 = uint32_t(((t & 0x00f0) << 8) | ((t & 0x00f0) << 4)); @@ -733,7 +733,7 @@ bool DirectX::Internal::ExpandScanline( const type * __restrict sPtr = reinterpret_cast(pSource);\ for(size_t icount = 0; icount < (size - sizeof(type) + 1); icount += sizeof(type))\ {\ - XMVECTOR v = func(sPtr++);\ + const XMVECTOR v = func(sPtr++);\ if (dPtr >= ePtr) break;\ *(dPtr++) = XMVectorSelect(defvec, v, g_XMSelect1110);\ }\ @@ -747,7 +747,7 @@ bool DirectX::Internal::ExpandScanline( const type * __restrict sPtr = reinterpret_cast(pSource);\ for(size_t icount = 0; icount < (size - sizeof(type) + 1); icount += sizeof(type))\ {\ - XMVECTOR v = func(sPtr++);\ + const XMVECTOR v = func(sPtr++);\ if (dPtr >= ePtr) break;\ *(dPtr++) = XMVectorSelect(defvec, v, g_XMSelect1100);\ }\ @@ -777,7 +777,7 @@ _Use_decl_annotations_ bool DirectX::Internal::LoadScanline( { case DXGI_FORMAT_R32G32B32A32_FLOAT: { - size_t msize = (size > (sizeof(XMVECTOR)*count)) ? (sizeof(XMVECTOR)*count) : size; + const size_t msize = (size > (sizeof(XMVECTOR)*count)) ? (sizeof(XMVECTOR)*count) : size; memcpy(dPtr, pSource, msize); } return true; @@ -823,7 +823,7 @@ _Use_decl_annotations_ bool DirectX::Internal::LoadScanline( case DXGI_FORMAT_D32_FLOAT_S8X24_UINT: { - const size_t psize = sizeof(float) + sizeof(uint32_t); + constexpr size_t psize = sizeof(float) + sizeof(uint32_t); if (size >= psize) { auto sPtr = static_cast(pSource); @@ -841,7 +841,7 @@ _Use_decl_annotations_ bool DirectX::Internal::LoadScanline( case DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS: { - const size_t psize = sizeof(float) + sizeof(uint32_t); + constexpr size_t psize = sizeof(float) + sizeof(uint32_t); if (size >= psize) { auto sPtr = static_cast(pSource); @@ -858,7 +858,7 @@ _Use_decl_annotations_ bool DirectX::Internal::LoadScanline( case DXGI_FORMAT_X32_TYPELESS_G8X24_UINT: { - const size_t psize = sizeof(float) + sizeof(uint32_t); + constexpr size_t psize = sizeof(float) + sizeof(uint32_t); if (size >= psize) { auto sPtr = static_cast(pSource); @@ -921,7 +921,7 @@ _Use_decl_annotations_ bool DirectX::Internal::LoadScanline( const float* __restrict sPtr = static_cast(pSource); for (size_t icount = 0; icount < (size - sizeof(float) + 1); icount += sizeof(float)) { - XMVECTOR v = XMLoadFloat(sPtr++); + const XMVECTOR v = XMLoadFloat(sPtr++); if (dPtr >= ePtr) break; *(dPtr++) = XMVectorSelect(g_XMIdentityR3, v, g_XMSelect1000); } @@ -965,8 +965,8 @@ _Use_decl_annotations_ bool DirectX::Internal::LoadScanline( auto sPtr = static_cast(pSource); for (size_t icount = 0; icount < (size - sizeof(uint32_t) + 1); icount += sizeof(uint32_t)) { - auto d = static_cast(*sPtr & 0xFFFFFF) / 16777215.f; - auto s = static_cast((*sPtr & 0xFF000000) >> 24); + auto const d = static_cast(*sPtr & 0xFFFFFF) / 16777215.f; + auto const s = static_cast((*sPtr & 0xFF000000) >> 24); ++sPtr; if (dPtr >= ePtr) break; *(dPtr++) = XMVectorSet(d, s, 0.f, 1.f); @@ -981,7 +981,7 @@ _Use_decl_annotations_ bool DirectX::Internal::LoadScanline( auto sPtr = static_cast(pSource); for (size_t icount = 0; icount < (size - sizeof(uint32_t) + 1); icount += sizeof(uint32_t)) { - auto r = static_cast(*sPtr & 0xFFFFFF) / 16777215.f; + auto const 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); @@ -996,7 +996,7 @@ _Use_decl_annotations_ bool DirectX::Internal::LoadScanline( auto sPtr = static_cast(pSource); for (size_t icount = 0; icount < (size - sizeof(uint32_t) + 1); icount += sizeof(uint32_t)) { - auto g = static_cast((*sPtr & 0xFF000000) >> 24); + auto const g = static_cast((*sPtr & 0xFF000000) >> 24); ++sPtr; if (dPtr >= ePtr) break; *(dPtr++) = XMVectorSet(0.f /* typeless component assumed zero */, g, 0.f, 1.f); @@ -1175,8 +1175,8 @@ _Use_decl_annotations_ bool DirectX::Internal::LoadScanline( const XMUBYTEN4 * __restrict sPtr = static_cast(pSource); for (size_t icount = 0; icount < (size - sizeof(XMUBYTEN4) + 1); icount += sizeof(XMUBYTEN4)) { - XMVECTOR v = XMLoadUByteN4(sPtr++); - XMVECTOR v1 = XMVectorSwizzle<0, 3, 2, 1>(v); + const XMVECTOR v = XMLoadUByteN4(sPtr++); + const XMVECTOR v1 = XMVectorSwizzle<0, 3, 2, 1>(v); if (dPtr >= ePtr) break; *(dPtr++) = XMVectorSelect(g_XMIdentityR3, v, g_XMSelect1110); if (dPtr >= ePtr) break; @@ -1192,9 +1192,9 @@ _Use_decl_annotations_ bool DirectX::Internal::LoadScanline( const XMUBYTEN4 * __restrict sPtr = static_cast(pSource); for (size_t icount = 0; icount < (size - sizeof(XMUBYTEN4) + 1); icount += sizeof(XMUBYTEN4)) { - XMVECTOR v = XMLoadUByteN4(sPtr++); - XMVECTOR v0 = XMVectorSwizzle<1, 0, 3, 2>(v); - XMVECTOR v1 = XMVectorSwizzle<1, 2, 3, 0>(v); + const XMVECTOR v = XMLoadUByteN4(sPtr++); + const XMVECTOR v0 = XMVectorSwizzle<1, 0, 3, 2>(v); + const XMVECTOR v1 = XMVectorSwizzle<1, 2, 3, 0>(v); if (dPtr >= ePtr) break; *(dPtr++) = XMVectorSelect(g_XMIdentityR3, v0, g_XMSelect1110); if (dPtr >= ePtr) break; @@ -1244,7 +1244,7 @@ _Use_decl_annotations_ bool DirectX::Internal::LoadScanline( const XMUBYTEN4 * __restrict sPtr = static_cast(pSource); for (size_t icount = 0; icount < (size - sizeof(XMUBYTEN4) + 1); icount += sizeof(XMUBYTEN4)) { - XMVECTOR v = XMLoadUByteN4(sPtr++); + const XMVECTOR v = XMLoadUByteN4(sPtr++); if (dPtr >= ePtr) break; *(dPtr++) = XMVectorSwizzle<2, 1, 0, 3>(v); } @@ -1274,10 +1274,10 @@ _Use_decl_annotations_ bool DirectX::Internal::LoadScanline( const XMUBYTEN4 * __restrict sPtr = static_cast(pSource); for (size_t icount = 0; icount < (size - sizeof(XMUBYTEN4) + 1); icount += sizeof(XMUBYTEN4)) { - int v = int(sPtr->x) - 128; - int u = int(sPtr->y) - 128; - int y = int(sPtr->z) - 16; - unsigned int a = sPtr->w; + const int v = int(sPtr->x) - 128; + const int u = int(sPtr->y) - 128; + const int y = int(sPtr->z) - 16; + const unsigned int a = sPtr->w; ++sPtr; // http://msdn.microsoft.com/en-us/library/windows/desktop/dd206750.aspx @@ -1290,9 +1290,9 @@ _Use_decl_annotations_ bool DirectX::Internal::LoadScanline( // G = 1.1644Y' - 0.3917Cb' - 0.8128Cr' // B = 1.1644Y' + 2.0172Cb' - int r = (298 * y + 409 * v + 128) >> 8; - int g = (298 * y - 100 * u - 208 * v + 128) >> 8; - int b = (298 * y + 516 * u + 128) >> 8; + const int r = (298 * y + 409 * v + 128) >> 8; + const int g = (298 * y - 100 * u - 208 * v + 128) >> 8; + const int b = (298 * y + 516 * u + 128) >> 8; if (dPtr >= ePtr) break; *(dPtr++) = XMVectorSet(float(std::min(std::max(r, 0), 255)) / 255.f, @@ -1310,10 +1310,10 @@ _Use_decl_annotations_ bool DirectX::Internal::LoadScanline( const XMUDECN4 * __restrict sPtr = static_cast(pSource); for (size_t icount = 0; icount < (size - sizeof(XMUDECN4) + 1); icount += sizeof(XMUDECN4)) { - int64_t u = int(sPtr->x) - 512; - int64_t y = int(sPtr->y) - 64; - int64_t v = int(sPtr->z) - 512; - unsigned int a = sPtr->w; + const int64_t u = int(sPtr->x) - 512; + const int64_t y = int(sPtr->y) - 64; + const int64_t v = int(sPtr->z) - 512; + const unsigned int a = sPtr->w; ++sPtr; // http://msdn.microsoft.com/en-us/library/windows/desktop/bb970578.aspx @@ -1326,9 +1326,9 @@ _Use_decl_annotations_ bool DirectX::Internal::LoadScanline( // G = 1.1678Y' - 0.3929Cb' - 0.8152Cr' // B = 1.1678Y' + 2.0232Cb' - 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); + auto const r = static_cast((76533 * y + 104905 * v + 32768) >> 16); + auto const g = static_cast((76533 * y - 25747 * u - 53425 * v + 32768) >> 16); + auto const 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, @@ -1346,10 +1346,10 @@ _Use_decl_annotations_ bool DirectX::Internal::LoadScanline( const XMUSHORTN4 * __restrict sPtr = static_cast(pSource); for (size_t icount = 0; icount < (size - sizeof(XMUSHORTN4) + 1); icount += sizeof(XMUSHORTN4)) { - int64_t u = int64_t(sPtr->x) - 32768; - int64_t y = int64_t(sPtr->y) - 4096; - int64_t v = int64_t(sPtr->z) - 32768; - auto a = static_cast(sPtr->w); + const int64_t u = int64_t(sPtr->x) - 32768; + const int64_t y = int64_t(sPtr->y) - 4096; + const int64_t v = int64_t(sPtr->z) - 32768; + auto const a = static_cast(sPtr->w); ++sPtr; // http://msdn.microsoft.com/en-us/library/windows/desktop/bb970578.aspx @@ -1362,9 +1362,9 @@ _Use_decl_annotations_ bool DirectX::Internal::LoadScanline( // G = 1.1689Y' - 0.3933Cb' - 0.8160Cr' // B = 1.1689Y'+ 2.0251Cb' - int r = static_cast((76607 * y + 105006 * v + 32768) >> 16); - int g = static_cast((76607 * y - 25772 * u - 53477 * v + 32768) >> 16); - int b = static_cast((76607 * y + 132718 * u + 32768) >> 16); + auto const r = static_cast((76607 * y + 105006 * v + 32768) >> 16); + auto const g = static_cast((76607 * y - 25772 * u - 53477 * v + 32768) >> 16); + auto const b = static_cast((76607 * y + 132718 * u + 32768) >> 16); if (dPtr >= ePtr) break; *(dPtr++) = XMVectorSet(float(std::min(std::max(r, 0), 65535)) / 65535.f, @@ -1382,10 +1382,10 @@ _Use_decl_annotations_ bool DirectX::Internal::LoadScanline( const XMUBYTEN4 * __restrict sPtr = static_cast(pSource); for (size_t icount = 0; icount < (size - sizeof(XMUBYTEN4) + 1); icount += sizeof(XMUBYTEN4)) { - int y0 = int(sPtr->x) - 16; - int u = int(sPtr->y) - 128; - int y1 = int(sPtr->z) - 16; - int v = int(sPtr->w) - 128; + const int y0 = int(sPtr->x) - 16; + const int u = int(sPtr->y) - 128; + const int y1 = int(sPtr->z) - 16; + const int v = int(sPtr->w) - 128; ++sPtr; // See AYUV @@ -1420,10 +1420,10 @@ _Use_decl_annotations_ bool DirectX::Internal::LoadScanline( const XMUSHORTN4 * __restrict sPtr = static_cast(pSource); for (size_t icount = 0; icount < (size - sizeof(XMUSHORTN4) + 1); icount += sizeof(XMUSHORTN4)) { - int64_t y0 = int64_t(sPtr->x >> 6) - 64; - int64_t u = int64_t(sPtr->y >> 6) - 512; - int64_t y1 = int64_t(sPtr->z >> 6) - 64; - int64_t v = int64_t(sPtr->w >> 6) - 512; + const int64_t y0 = int64_t(sPtr->x >> 6) - 64; + const int64_t u = int64_t(sPtr->y >> 6) - 512; + const int64_t y1 = int64_t(sPtr->z >> 6) - 64; + const int64_t v = int64_t(sPtr->w >> 6) - 512; ++sPtr; // See Y410 @@ -1457,10 +1457,10 @@ _Use_decl_annotations_ bool DirectX::Internal::LoadScanline( const XMUSHORTN4 * __restrict sPtr = static_cast(pSource); for (size_t icount = 0; icount < (size - sizeof(XMUSHORTN4) + 1); icount += sizeof(XMUSHORTN4)) { - int64_t y0 = int64_t(sPtr->x) - 4096; - int64_t u = int64_t(sPtr->y) - 32768; - int64_t y1 = int64_t(sPtr->z) - 4096; - int64_t v = int64_t(sPtr->w) - 32768; + const int64_t y0 = int64_t(sPtr->x) - 4096; + const int64_t u = int64_t(sPtr->y) - 32768; + const int64_t y1 = int64_t(sPtr->z) - 4096; + const int64_t v = int64_t(sPtr->w) - 32768; ++sPtr; // See Y416 @@ -1688,7 +1688,7 @@ bool DirectX::Internal::StoreScanline( case DXGI_FORMAT_D32_FLOAT_S8X24_UINT: { - const size_t psize = sizeof(float) + sizeof(uint32_t); + constexpr size_t psize = sizeof(float) + sizeof(uint32_t); if (size >= psize) { auto dPtr = static_cast(pDestination); @@ -1728,7 +1728,7 @@ bool DirectX::Internal::StoreScanline( for (size_t icount = 0; icount < (size - sizeof(XMUBYTEN4) + 1); icount += sizeof(XMUBYTEN4)) { if (sPtr >= ePtr) break; - XMVECTOR v = XMVectorAdd(*sPtr++, g_8BitBias); + const XMVECTOR v = XMVectorAdd(*sPtr++, g_8BitBias); XMStoreUByteN4(dPtr++, v); } return true; @@ -1792,7 +1792,7 @@ bool DirectX::Internal::StoreScanline( for (size_t icount = 0; icount < (size - sizeof(uint32_t) + 1); icount += sizeof(uint32_t)) { if (sPtr >= ePtr) break; - XMVECTOR v = XMConvertVectorFloatToUInt(*(sPtr++), 0); + const XMVECTOR v = XMConvertVectorFloatToUInt(*(sPtr++), 0); XMStoreInt(dPtr++, v); } return true; @@ -1806,7 +1806,7 @@ bool DirectX::Internal::StoreScanline( for (size_t icount = 0; icount < (size - sizeof(int32_t) + 1); icount += sizeof(int32_t)) { if (sPtr >= ePtr) break; - XMVECTOR v = XMConvertVectorFloatToInt(*(sPtr++), 0); + const XMVECTOR v = XMConvertVectorFloatToInt(*(sPtr++), 0); XMStoreInt(dPtr++, v); } return true; @@ -1817,7 +1817,7 @@ bool DirectX::Internal::StoreScanline( if (size >= sizeof(uint32_t)) { static const XMVECTORF32 clamp = { { { 1.f, 255.f, 0.f, 0.f } } }; - XMVECTOR zero = XMVectorZero(); + const XMVECTOR zero = XMVectorZero(); auto dPtr = static_cast(pDestination); for (size_t icount = 0; icount < (size - sizeof(uint32_t) + 1); icount += sizeof(uint32_t)) { @@ -2004,7 +2004,7 @@ bool DirectX::Internal::StoreScanline( for (size_t bcount = 8; bcount > 0; --bcount) { if (sPtr >= ePtr) break; - float v = XMVectorGetX(*sPtr++); + const float v = XMVectorGetX(*sPtr++); // Absolute thresholding generally doesn't give good results for all images // Picking the 'right' threshold automatically requires whole-image analysis @@ -2028,8 +2028,8 @@ bool DirectX::Internal::StoreScanline( for (size_t icount = 0; icount < (size - sizeof(XMUBYTEN4) + 1); icount += sizeof(XMUBYTEN4)) { if (sPtr >= ePtr) break; - XMVECTOR v0 = *sPtr++; - XMVECTOR v1 = (sPtr < ePtr) ? XMVectorSplatY(*sPtr++) : XMVectorZero(); + const XMVECTOR v0 = *sPtr++; + const XMVECTOR v1 = (sPtr < ePtr) ? XMVectorSplatY(*sPtr++) : XMVectorZero(); XMVECTOR v = XMVectorSelect(v1, v0, g_XMSelect1110); v = XMVectorAdd(v, g_8BitBias); XMStoreUByteN4(dPtr++, v); @@ -2047,8 +2047,8 @@ bool DirectX::Internal::StoreScanline( for (size_t icount = 0; icount < (size - sizeof(XMUBYTEN4) + 1); icount += sizeof(XMUBYTEN4)) { if (sPtr >= ePtr) break; - XMVECTOR v0 = XMVectorSwizzle<1, 0, 3, 2>(*sPtr++); - XMVECTOR v1 = (sPtr < ePtr) ? XMVectorSplatY(*sPtr++) : XMVectorZero(); + const XMVECTOR v0 = XMVectorSwizzle<1, 0, 3, 2>(*sPtr++); + const XMVECTOR v1 = (sPtr < ePtr) ? XMVectorSplatY(*sPtr++) : XMVectorZero(); XMVECTOR v = XMVectorSelect(v1, v0, select1101); v = XMVectorAdd(v, g_8BitBias); XMStoreUByteN4(dPtr++, v); @@ -2140,9 +2140,9 @@ bool DirectX::Internal::StoreScanline( // Cb = -0.1482R - 0.2910G + 0.4392B + 128 // Cr = 0.4392R - 0.3678G - 0.0714B + 128 - int y = ((66 * rgba.x + 129 * rgba.y + 25 * rgba.z + 128) >> 8) + 16; - int u = ((-38 * rgba.x - 74 * rgba.y + 112 * rgba.z + 128) >> 8) + 128; - int v = ((112 * rgba.x - 94 * rgba.y - 18 * rgba.z + 128) >> 8) + 128; + const int y = ((66 * rgba.x + 129 * rgba.y + 25 * rgba.z + 128) >> 8) + 16; + const int u = ((-38 * rgba.x - 74 * rgba.y + 112 * rgba.z + 128) >> 8) + 128; + const int v = ((112 * rgba.x - 94 * rgba.y - 18 * rgba.z + 128) >> 8) + 128; dPtr->x = static_cast(std::min(std::max(v, 0), 255)); dPtr->y = static_cast(std::min(std::max(u, 0), 255)); @@ -2171,13 +2171,13 @@ bool DirectX::Internal::StoreScanline( // Cb = -0.1478R - 0.2902G + 0.4379B + 512 // Cr = 0.4379R - 0.3667G - 0.0712B + 512 - int64_t r = rgba.x; - int64_t g = rgba.y; - int64_t b = rgba.z; + const int64_t r = rgba.x; + const int64_t g = rgba.y; + const int64_t b = rgba.z; - int y = static_cast((16780 * r + 32942 * g + 6544 * b + 32768) >> 16) + 64; - int u = static_cast((-9683 * r - 19017 * g + 28700 * b + 32768) >> 16) + 512; - int v = static_cast((28700 * r - 24033 * g - 4667 * b + 32768) >> 16) + 512; + const int y = static_cast((16780 * r + 32942 * g + 6544 * b + 32768) >> 16) + 64; + const int u = static_cast((-9683 * r - 19017 * g + 28700 * b + 32768) >> 16) + 512; + const int v = static_cast((28700 * r - 24033 * g - 4667 * b + 32768) >> 16) + 512; dPtr->x = static_cast(std::min(std::max(u, 0), 1023)); dPtr->y = static_cast(std::min(std::max(y, 0), 1023)); @@ -2206,13 +2206,13 @@ bool DirectX::Internal::StoreScanline( // Cb = -0.1476R - 0.2899G + 0.4375B + 32768 // Cr = 0.4375R - 0.3664G - 0.0711B + 32768 - int64_t r = int64_t(rgba.x); - int64_t g = int64_t(rgba.y); - int64_t b = int64_t(rgba.z); + const int64_t r = int64_t(rgba.x); + const int64_t g = int64_t(rgba.y); + const int64_t b = int64_t(rgba.z); - int y = static_cast((16763 * r + 32910 * g + 6537 * b + 32768) >> 16) + 4096; - int u = static_cast((-9674 * r - 18998 * g + 28672 * b + 32768) >> 16) + 32768; - int v = static_cast((28672 * r - 24010 * g - 4662 * b + 32768) >> 16) + 32768; + const int y = static_cast((16763 * r + 32910 * g + 6537 * b + 32768) >> 16) + 4096; + const int u = static_cast((-9674 * r - 18998 * g + 28672 * b + 32768) >> 16) + 32768; + const int v = static_cast((28672 * r - 24010 * g - 4662 * b + 32768) >> 16) + 32768; dPtr->x = static_cast(std::min(std::max(u, 0), 65535)); dPtr->y = static_cast(std::min(std::max(y, 0), 65535)); @@ -2236,9 +2236,9 @@ bool DirectX::Internal::StoreScanline( XMStoreUByteN4(&rgb1, *sPtr++); // See AYUV - int y0 = ((66 * rgb1.x + 129 * rgb1.y + 25 * rgb1.z + 128) >> 8) + 16; - int u0 = ((-38 * rgb1.x - 74 * rgb1.y + 112 * rgb1.z + 128) >> 8) + 128; - int v0 = ((112 * rgb1.x - 94 * rgb1.y - 18 * rgb1.z + 128) >> 8) + 128; + const int y0 = ((66 * rgb1.x + 129 * rgb1.y + 25 * rgb1.z + 128) >> 8) + 16; + const int u0 = ((-38 * rgb1.x - 74 * rgb1.y + 112 * rgb1.z + 128) >> 8) + 128; + const int v0 = ((112 * rgb1.x - 94 * rgb1.y - 18 * rgb1.z + 128) >> 8) + 128; XMUBYTEN4 rgb2; if (sPtr < ePtr) @@ -2250,9 +2250,9 @@ bool DirectX::Internal::StoreScanline( rgb2.x = rgb2.y = rgb2.z = rgb2.w = 0; } - int y1 = ((66 * rgb2.x + 129 * rgb2.y + 25 * rgb2.z + 128) >> 8) + 16; - int u1 = ((-38 * rgb2.x - 74 * rgb2.y + 112 * rgb2.z + 128) >> 8) + 128; - int v1 = ((112 * rgb2.x - 94 * rgb2.y - 18 * rgb2.z + 128) >> 8) + 128; + const int y1 = ((66 * rgb2.x + 129 * rgb2.y + 25 * rgb2.z + 128) >> 8) + 16; + const int u1 = ((-38 * rgb2.x - 74 * rgb2.y + 112 * rgb2.z + 128) >> 8) + 128; + const int v1 = ((112 * rgb2.x - 94 * rgb2.y - 18 * rgb2.z + 128) >> 8) + 128; dPtr->x = static_cast(std::min(std::max(y0, 0), 255)); dPtr->y = static_cast(std::min(std::max((u0 + u1) >> 1, 0), 255)); @@ -2281,9 +2281,9 @@ bool DirectX::Internal::StoreScanline( int64_t g = rgb1.y; int64_t b = rgb1.z; - int y0 = static_cast((16780 * r + 32942 * g + 6544 * b + 32768) >> 16) + 64; - int u0 = static_cast((-9683 * r - 19017 * g + 28700 * b + 32768) >> 16) + 512; - int v0 = static_cast((28700 * r - 24033 * g - 4667 * b + 32768) >> 16) + 512; + const int y0 = static_cast((16780 * r + 32942 * g + 6544 * b + 32768) >> 16) + 64; + const int u0 = static_cast((-9683 * r - 19017 * g + 28700 * b + 32768) >> 16) + 512; + const int v0 = static_cast((28700 * r - 24033 * g - 4667 * b + 32768) >> 16) + 512; XMUDECN4 rgb2; if (sPtr < ePtr) @@ -2299,9 +2299,9 @@ bool DirectX::Internal::StoreScanline( g = rgb2.y; b = rgb2.z; - int y1 = static_cast((16780 * r + 32942 * g + 6544 * b + 32768) >> 16) + 64; - int u1 = static_cast((-9683 * r - 19017 * g + 28700 * b + 32768) >> 16) + 512; - int v1 = static_cast((28700 * r - 24033 * g - 4667 * b + 32768) >> 16) + 512; + const int y1 = static_cast((16780 * r + 32942 * g + 6544 * b + 32768) >> 16) + 64; + const int u1 = static_cast((-9683 * r - 19017 * g + 28700 * b + 32768) >> 16) + 512; + const int v1 = static_cast((28700 * r - 24033 * g - 4667 * b + 32768) >> 16) + 512; dPtr->x = static_cast(std::min(std::max(y0, 0), 1023) << 6); dPtr->y = static_cast(std::min(std::max((u0 + u1) >> 1, 0), 1023) << 6); @@ -2329,9 +2329,9 @@ bool DirectX::Internal::StoreScanline( int64_t g = int64_t(rgb1.y); int64_t b = int64_t(rgb1.z); - int y0 = static_cast((16763 * r + 32910 * g + 6537 * b + 32768) >> 16) + 4096; - int u0 = static_cast((-9674 * r - 18998 * g + 28672 * b + 32768) >> 16) + 32768; - int v0 = static_cast((28672 * r - 24010 * g - 4662 * b + 32768) >> 16) + 32768; + const int y0 = static_cast((16763 * r + 32910 * g + 6537 * b + 32768) >> 16) + 4096; + const int u0 = static_cast((-9674 * r - 18998 * g + 28672 * b + 32768) >> 16) + 32768; + const int v0 = static_cast((28672 * r - 24010 * g - 4662 * b + 32768) >> 16) + 32768; XMUSHORTN4 rgb2; if (sPtr < ePtr) @@ -2347,9 +2347,9 @@ bool DirectX::Internal::StoreScanline( g = int64_t(rgb2.y); b = int64_t(rgb2.z); - int y1 = static_cast((16763 * r + 32910 * g + 6537 * b + 32768) >> 16) + 4096; - int u1 = static_cast((-9674 * r - 18998 * g + 28672 * b + 32768) >> 16) + 32768; - int v1 = static_cast((28672 * r - 24010 * g - 4662 * b + 32768) >> 16) + 32768; + const int y1 = static_cast((16763 * r + 32910 * g + 6537 * b + 32768) >> 16) + 4096; + const int u1 = static_cast((-9674 * r - 18998 * g + 28672 * b + 32768) >> 16) + 32768; + const int v1 = static_cast((28672 * r - 24010 * g - 4662 * b + 32768) >> 16) + 32768; dPtr->x = static_cast(std::min(std::max(y0, 0), 65535)); dPtr->y = static_cast(std::min(std::max((u0 + u1) >> 1, 0), 65535)); @@ -2446,7 +2446,7 @@ bool DirectX::Internal::StoreScanline( for (size_t icount = 0; icount < (size - sizeof(uint8_t) + 1); icount += sizeof(uint8_t)) { if (sPtr >= ePtr) break; - XMVECTOR v = XMVectorMultiply(*sPtr++, s_Scale); + const XMVECTOR v = XMVectorMultiply(*sPtr++, s_Scale); XMUNIBBLE4 nibble; XMStoreUNibble4(&nibble, v); @@ -3115,7 +3115,7 @@ void DirectX::Internal::ConvertScanline( } // Handle conversion special cases - uint32_t diffFlags = in->flags ^ out->flags; + const uint32_t diffFlags = in->flags ^ out->flags; if (diffFlags != 0) { if (diffFlags & CONVF_DEPTH) @@ -3135,7 +3135,7 @@ void DirectX::Internal::ConvertScanline( XMVECTOR* ptr = pBuffer; for (size_t i = 0; i < count; ++i) { - XMVECTOR v = *ptr; + const XMVECTOR v = *ptr; XMVECTOR v1 = XMVectorSplatY(v); v1 = XMVectorClamp(v1, g_XMZero, S); v1 = XMVectorDivide(v1, S); @@ -3148,7 +3148,7 @@ void DirectX::Internal::ConvertScanline( XMVECTOR* ptr = pBuffer; for (size_t i = 0; i < count; ++i) { - XMVECTOR v = *ptr; + const XMVECTOR v = *ptr; XMVECTOR v1 = XMVectorSplatY(v); v1 = XMVectorClamp(v1, g_XMZero, S); v1 = XMVectorDivide(v1, S); @@ -3161,8 +3161,8 @@ void DirectX::Internal::ConvertScanline( XMVECTOR* ptr = pBuffer; for (size_t i = 0; i < count; ++i) { - XMVECTOR v = *ptr; - XMVECTOR v1 = XMVectorSplatY(v); + const XMVECTOR v = *ptr; + const XMVECTOR v1 = XMVectorSplatY(v); *ptr++ = XMVectorSelect(v1, v, g_XMSelect1110); } } @@ -3175,7 +3175,7 @@ void DirectX::Internal::ConvertScanline( XMVECTOR* ptr = pBuffer; for (size_t i = 0; i < count; ++i) { - XMVECTOR v = *ptr; + const XMVECTOR v = *ptr; XMVECTOR v1 = XMVectorSaturate(v); v1 = XMVectorSplatX(v1); *ptr++ = XMVectorSelect(v, v1, g_XMSelect1110); @@ -3189,7 +3189,7 @@ void DirectX::Internal::ConvertScanline( XMVECTOR* ptr = pBuffer; for (size_t i = 0; i < count; ++i) { - XMVECTOR v = *ptr; + const XMVECTOR v = *ptr; XMVECTOR v1 = XMVectorMultiplyAdd(v, g_XMTwo, g_XMNegativeOne); v1 = XMVectorSplatX(v1); *ptr++ = XMVectorSelect(v, v1, g_XMSelect1110); @@ -3201,7 +3201,7 @@ void DirectX::Internal::ConvertScanline( XMVECTOR* ptr = pBuffer; for (size_t i = 0; i < count; ++i) { - XMVECTOR v = *ptr; + const XMVECTOR v = *ptr; XMVECTOR v1 = XMVectorClamp(v, g_XMNegativeOne, g_XMOne); v1 = XMVectorSplatX(v1); *ptr++ = XMVectorSelect(v, v1, g_XMSelect1110); @@ -3213,8 +3213,8 @@ void DirectX::Internal::ConvertScanline( XMVECTOR* ptr = pBuffer; for (size_t i = 0; i < count; ++i) { - XMVECTOR v = *ptr; - XMVECTOR v1 = XMVectorSplatX(v); + const XMVECTOR v = *ptr; + const XMVECTOR v1 = XMVectorSplatX(v); *ptr++ = XMVectorSelect(v, v1, g_XMSelect1110); } } @@ -3231,8 +3231,8 @@ void DirectX::Internal::ConvertScanline( XMVECTOR* ptr = pBuffer; for (size_t i = 0; i < count; ++i) { - XMVECTOR v = *ptr; - XMVECTOR v1 = XMVectorSplatY(v); + const XMVECTOR v = *ptr; + const XMVECTOR v1 = XMVectorSplatY(v); *ptr++ = XMVectorSelect(v, v1, g_XMSelect1000); } } @@ -3243,8 +3243,8 @@ void DirectX::Internal::ConvertScanline( XMVECTOR* ptr = pBuffer; for (size_t i = 0; i < count; ++i) { - XMVECTOR v = *ptr; - XMVECTOR v1 = XMVectorSplatZ(v); + const XMVECTOR v = *ptr; + const XMVECTOR v1 = XMVectorSplatZ(v); *ptr++ = XMVectorSelect(v, v1, g_XMSelect1000); } } @@ -3256,8 +3256,8 @@ void DirectX::Internal::ConvertScanline( XMVECTOR* ptr = pBuffer; for (size_t i = 0; i < count; ++i) { - XMVECTOR v = *ptr; - XMVECTOR v1 = XMVector3Dot(v, g_Grayscale); + const XMVECTOR v = *ptr; + const XMVECTOR v1 = XMVector3Dot(v, g_Grayscale); *ptr++ = XMVectorSelect(v, v1, g_XMSelect1000); } break; @@ -3275,8 +3275,8 @@ void DirectX::Internal::ConvertScanline( XMVECTOR* ptr = pBuffer; for (size_t i = 0; i < count; ++i) { - XMVECTOR v = *ptr; - XMVECTOR v1 = XMVectorSplatX(v); + const XMVECTOR v = *ptr; + const XMVECTOR v1 = XMVectorSplatX(v); *ptr++ = XMVectorSelect(v, v1, g_XMSelect1000); } } @@ -3292,8 +3292,8 @@ void DirectX::Internal::ConvertScanline( XMVECTOR* ptr = pBuffer; for (size_t i = 0; i < count; ++i) { - XMVECTOR v = *ptr; - XMVECTOR v1 = XMVectorMultiplyAdd(v, g_XMOneHalf, g_XMOneHalf); + const XMVECTOR v = *ptr; + const XMVECTOR v1 = XMVectorMultiplyAdd(v, g_XMOneHalf, g_XMOneHalf); *ptr++ = XMVectorSelect(v, v1, g_XMSelect1000); } } @@ -3303,8 +3303,8 @@ void DirectX::Internal::ConvertScanline( XMVECTOR* ptr = pBuffer; for (size_t i = 0; i < count; ++i) { - XMVECTOR v = *ptr; - XMVECTOR v1 = XMVectorSaturate(v); + const XMVECTOR v = *ptr; + const XMVECTOR v1 = XMVectorSaturate(v); *ptr++ = XMVectorSelect(v, v1, g_XMSelect1000); } } @@ -3322,7 +3322,7 @@ void DirectX::Internal::ConvertScanline( XMVECTOR* ptr = pBuffer; for (size_t i = 0; i < count; ++i) { - XMVECTOR v = *ptr; + const XMVECTOR v = *ptr; XMVECTOR v1 = XMVectorMultiply(v, S); v1 = XMVectorSplatW(v1); *ptr++ = XMVectorSelect(v, v1, select0100); @@ -3334,7 +3334,7 @@ void DirectX::Internal::ConvertScanline( XMVECTOR* ptr = pBuffer; for (size_t i = 0; i < count; ++i) { - XMVECTOR v = *ptr; + const XMVECTOR v = *ptr; XMVECTOR v1 = XMVectorMultiplyAdd(v, g_XMOneHalf, g_XMOneHalf); v1 = XMVectorMultiply(v1, S); v1 = XMVectorSplatW(v1); @@ -3346,8 +3346,8 @@ void DirectX::Internal::ConvertScanline( XMVECTOR* ptr = pBuffer; for (size_t i = 0; i < count; ++i) { - XMVECTOR v = *ptr; - XMVECTOR v1 = XMVectorSplatW(v); + const XMVECTOR v = *ptr; + const XMVECTOR v1 = XMVectorSplatW(v); *ptr++ = XMVectorSelect(v, v1, select0100); } } @@ -3365,8 +3365,8 @@ void DirectX::Internal::ConvertScanline( XMVECTOR* ptr = pBuffer; for (size_t i = 0; i < count; ++i) { - XMVECTOR v = *ptr; - XMVECTOR v1 = XMVectorSaturate(v); + const XMVECTOR v = *ptr; + const XMVECTOR v1 = XMVectorSaturate(v); *ptr++ = XMVectorSelect(v, v1, g_XMSelect1000); } } @@ -3381,7 +3381,7 @@ void DirectX::Internal::ConvertScanline( XMVECTOR* ptr = pBuffer; for (size_t i = 0; i < count; ++i) { - XMVECTOR v = *ptr; + const XMVECTOR v = *ptr; *ptr++ = XMVectorMultiplyAdd(v, g_XMOneHalf, g_XMOneHalf); } } @@ -3403,7 +3403,7 @@ void DirectX::Internal::ConvertScanline( // FLOAT -> UNORM for (size_t i = 0; i < count; ++i) { - XMVECTOR v = *ptr; + const XMVECTOR v = *ptr; *ptr++ = XMVectorSaturate(v); } } @@ -3418,7 +3418,7 @@ void DirectX::Internal::ConvertScanline( XMVECTOR* ptr = pBuffer; for (size_t i = 0; i < count; ++i) { - XMVECTOR v = *ptr; + const XMVECTOR v = *ptr; *ptr++ = XMVectorMultiplyAdd(v, g_XMTwo, g_XMNegativeOne); } } @@ -3440,7 +3440,7 @@ void DirectX::Internal::ConvertScanline( // FLOAT -> SNORM for (size_t i = 0; i < count; ++i) { - XMVECTOR v = *ptr; + const XMVECTOR v = *ptr; *ptr++ = XMVectorClamp(v, g_XMNegativeOne, g_XMOne); } } @@ -3458,7 +3458,7 @@ void DirectX::Internal::ConvertScanline( XMVECTOR* ptr = pBuffer; for (size_t i = 0; i < count; ++i) { - XMVECTOR v = *ptr; + const XMVECTOR v = *ptr; *ptr++ = XMVectorMultiplyAdd(v, g_XMTwo, g_XMNegativeOne); } } @@ -3501,7 +3501,7 @@ void DirectX::Internal::ConvertScanline( XMVECTOR* ptr = pBuffer; for (size_t i = 0; i < count; ++i) { - XMVECTOR v = *ptr; + const XMVECTOR v = *ptr; *ptr++ = XMVectorMultiplyAdd(v, g_XMOneHalf, g_XMOneHalf); } } @@ -3523,7 +3523,7 @@ void DirectX::Internal::ConvertScanline( XMVECTOR* ptr = pBuffer; for (size_t i = 0; i < count; ++i) { - XMVECTOR v = *ptr; + const XMVECTOR v = *ptr; *ptr++ = XMVectorSplatY(v); } } @@ -3534,7 +3534,7 @@ void DirectX::Internal::ConvertScanline( XMVECTOR* ptr = pBuffer; for (size_t i = 0; i < count; ++i) { - XMVECTOR v = *ptr; + const XMVECTOR v = *ptr; *ptr++ = XMVectorSplatZ(v); } } @@ -3546,7 +3546,7 @@ void DirectX::Internal::ConvertScanline( XMVECTOR* ptr = pBuffer; for (size_t i = 0; i < count; ++i) { - XMVECTOR v = *ptr; + const XMVECTOR v = *ptr; *ptr++ = XMVector3Dot(v, g_Grayscale); } break; @@ -3564,7 +3564,7 @@ void DirectX::Internal::ConvertScanline( XMVECTOR* ptr = pBuffer; for (size_t i = 0; i < count; ++i) { - XMVECTOR v = *ptr; + const XMVECTOR v = *ptr; *ptr++ = XMVectorSplatX(v); } } @@ -3577,7 +3577,7 @@ void DirectX::Internal::ConvertScanline( XMVECTOR* ptr = pBuffer; for (size_t i = 0; i < count; ++i) { - XMVECTOR v = *ptr; + const XMVECTOR v = *ptr; *ptr++ = XMVectorSplatW(v); } } @@ -3589,8 +3589,8 @@ void DirectX::Internal::ConvertScanline( XMVECTOR* ptr = pBuffer; for (size_t i = 0; i < count; ++i) { - XMVECTOR v = *ptr; - XMVECTOR v1 = XMVectorSplatX(v); + const XMVECTOR v = *ptr; + const XMVECTOR v1 = XMVectorSplatX(v); *ptr++ = XMVectorSelect(v, v1, g_XMSelect1110); } } @@ -3600,8 +3600,8 @@ void DirectX::Internal::ConvertScanline( XMVECTOR* ptr = pBuffer; for (size_t i = 0; i < count; ++i) { - XMVECTOR v = *ptr; - XMVECTOR v1 = XMVectorSplatX(v); + const XMVECTOR v = *ptr; + const XMVECTOR v1 = XMVectorSplatX(v); *ptr++ = XMVectorSelect(v, v1, g_XMSelect1100); } } @@ -3618,8 +3618,8 @@ void DirectX::Internal::ConvertScanline( XMVECTOR* ptr = pBuffer; for (size_t i = 0; i < count; ++i) { - XMVECTOR v = *ptr; - XMVECTOR v1 = XMVectorSplatY(v); + const XMVECTOR v = *ptr; + const XMVECTOR v1 = XMVectorSplatY(v); *ptr++ = XMVectorSelect(v, v1, g_XMSelect1110); } } @@ -3630,8 +3630,8 @@ void DirectX::Internal::ConvertScanline( XMVECTOR* ptr = pBuffer; for (size_t i = 0; i < count; ++i) { - XMVECTOR v = *ptr; - XMVECTOR v1 = XMVectorSplatZ(v); + const XMVECTOR v = *ptr; + const XMVECTOR v1 = XMVectorSplatZ(v); *ptr++ = XMVectorSelect(v, v1, g_XMSelect1110); } } @@ -3643,8 +3643,8 @@ void DirectX::Internal::ConvertScanline( XMVECTOR* ptr = pBuffer; for (size_t i = 0; i < count; ++i) { - XMVECTOR v = *ptr; - XMVECTOR v1 = XMVector3Dot(v, g_Grayscale); + const XMVECTOR v = *ptr; + const XMVECTOR v1 = XMVector3Dot(v, g_Grayscale); *ptr++ = XMVectorSelect(v, v1, g_XMSelect1110); } break; @@ -3672,8 +3672,8 @@ void DirectX::Internal::ConvertScanline( XMVECTOR* ptr = pBuffer; for (size_t i = 0; i < count; ++i) { - XMVECTOR v = *ptr; - XMVECTOR v1 = XMVectorSwizzle<0, 2, 0, 2>(v); + const XMVECTOR v = *ptr; + const XMVECTOR v1 = XMVectorSwizzle<0, 2, 0, 2>(v); *ptr++ = XMVectorSelect(v, v1, g_XMSelect1100); } } @@ -3684,8 +3684,8 @@ void DirectX::Internal::ConvertScanline( XMVECTOR* ptr = pBuffer; for (size_t i = 0; i < count; ++i) { - XMVECTOR v = *ptr; - XMVECTOR v1 = XMVectorSwizzle<1, 2, 3, 0>(v); + const XMVECTOR v = *ptr; + const XMVECTOR v1 = XMVectorSwizzle<1, 2, 3, 0>(v); *ptr++ = XMVectorSelect(v, v1, g_XMSelect1100); } } @@ -3954,7 +3954,7 @@ bool DirectX::Internal::StoreScanlineDither( { // If pDiffusionErrors == 0, then this function performs ordered dithering - XMVECTOR dither = XMLoadFloat4(reinterpret_cast(g_Dither + (z & 3) + ((y & 3) * 8))); + const XMVECTOR dither = XMLoadFloat4(reinterpret_cast(g_Dither + (z & 3) + ((y & 3) * 8))); ordered[0] = XMVectorSplatX(dither); ordered[1] = XMVectorSplatY(dither); @@ -4529,7 +4529,7 @@ namespace filter &= ~(TEX_FILTER_SRGB_IN | TEX_FILTER_SRGB_OUT); } - auto wicsrgb = CheckWICColorSpace(pfGUID, targetGUID); + auto const wicsrgb = CheckWICColorSpace(pfGUID, targetGUID); if (wicsrgb != (filter & (TEX_FILTER_SRGB_IN | TEX_FILTER_SRGB_OUT))) { @@ -4729,9 +4729,9 @@ namespace //------------------------------------------------------------------------------------- #define CONVERT_420_TO_422( srcType, destType )\ {\ - size_t rowPitch = srcImage.rowPitch;\ + const size_t rowPitch = srcImage.rowPitch;\ \ - auto sourceE = reinterpret_cast(pSrc + srcImage.slicePitch);\ + auto const sourceE = reinterpret_cast(pSrc + srcImage.slicePitch);\ auto pSrcUV = pSrc + (srcImage.height * rowPitch);\ \ for(size_t y = 0; y < srcImage.height; y+= 2)\ @@ -4747,8 +4747,8 @@ namespace {\ if ((sPtrUV+1) >= sourceE) break;\ \ - srcType u = *(sPtrUV++);\ - srcType v = *(sPtrUV++);\ + const srcType u = *(sPtrUV++);\ + const srcType v = *(sPtrUV++);\ \ dPtr0->x = *(sPtrY0++);\ dPtr0->y = u;\ @@ -4801,7 +4801,7 @@ namespace assert(destImage.format == DXGI_FORMAT_YUY2); // Convert 4:1:1 to 4:2:2 { - size_t rowPitch = srcImage.rowPitch; + const size_t rowPitch = srcImage.rowPitch; const uint8_t* sourceE = pSrc + srcImage.slicePitch; const uint8_t* pSrcUV = pSrc + (srcImage.height * rowPitch); @@ -4817,8 +4817,8 @@ namespace { if ((sPtrUV + 1) >= sourceE) break; - uint8_t u = *(sPtrUV++); - uint8_t v = *(sPtrUV++); + const uint8_t u = *(sPtrUV++); + const uint8_t v = *(sPtrUV++); dPtr->x = *(sPtrY++); dPtr->y = u; @@ -4956,7 +4956,7 @@ HRESULT DirectX::Convert( } WICPixelFormatGUID pfGUID, targetGUID; - bool usewic = !metadata.IsPMAlpha() && UseWICConversion(filter, metadata.format, format, pfGUID, targetGUID); + const bool usewic = !metadata.IsPMAlpha() && UseWICConversion(filter, metadata.format, format, pfGUID, targetGUID); switch (metadata.dimension) { @@ -5082,7 +5082,7 @@ HRESULT DirectX::ConvertToSinglePlane(const Image& srcImage, ScratchImage& image if (!srcImage.pixels) return E_POINTER; - DXGI_FORMAT format = PlanarToSingle(srcImage.format); + const DXGI_FORMAT format = PlanarToSingle(srcImage.format); if (format == DXGI_FORMAT_UNKNOWN) return HRESULT_E_NOT_SUPPORTED; @@ -5130,7 +5130,7 @@ HRESULT DirectX::ConvertToSinglePlane( return HRESULT_E_NOT_SUPPORTED; } - DXGI_FORMAT format = PlanarToSingle(metadata.format); + const DXGI_FORMAT format = PlanarToSingle(metadata.format); if (format == DXGI_FORMAT_UNKNOWN) return HRESULT_E_NOT_SUPPORTED; diff --git a/DirectXTex/DirectXTexD3D11.cpp b/DirectXTex/DirectXTexD3D11.cpp index 71be0a3..54fb2c8 100644 --- a/DirectXTex/DirectXTexD3D11.cpp +++ b/DirectXTex/DirectXTexD3D11.cpp @@ -76,7 +76,7 @@ namespace for (size_t level = 0; level < metadata.mipLevels; ++level) { - UINT dindex = D3D11CalcSubresource(static_cast(level), 0, static_cast(metadata.mipLevels)); + const UINT dindex = D3D11CalcSubresource(static_cast(level), 0, static_cast(metadata.mipLevels)); D3D11_MAPPED_SUBRESOURCE mapped; HRESULT hr = pContext->Map(pSource, dindex, D3D11_MAP_READ, 0, &mapped); @@ -90,7 +90,7 @@ namespace return E_POINTER; } - size_t lines = ComputeScanlines(metadata.format, height); + const size_t lines = ComputeScanlines(metadata.format, height); if (!lines) { pContext->Unmap(pSource, dindex); @@ -116,7 +116,7 @@ namespace uint8_t* dptr = img->pixels; for (size_t h = 0; h < lines; ++h) { - size_t msize = std::min(img->rowPitch, mapped.RowPitch); + const size_t msize = std::min(img->rowPitch, mapped.RowPitch); memcpy(dptr, sptr, msize); sptr += mapped.RowPitch; dptr += img->rowPitch; @@ -144,7 +144,7 @@ namespace for (size_t level = 0; level < metadata.mipLevels; ++level) { - UINT dindex = D3D11CalcSubresource(static_cast(level), static_cast(item), static_cast(metadata.mipLevels)); + const UINT dindex = D3D11CalcSubresource(static_cast(level), static_cast(item), static_cast(metadata.mipLevels)); D3D11_MAPPED_SUBRESOURCE mapped; HRESULT hr = pContext->Map(pSource, dindex, D3D11_MAP_READ, 0, &mapped); @@ -164,7 +164,7 @@ namespace return E_POINTER; } - size_t lines = ComputeScanlines(metadata.format, height); + const size_t lines = ComputeScanlines(metadata.format, height); if (!lines) { pContext->Unmap(pSource, dindex); @@ -175,7 +175,7 @@ namespace uint8_t* dptr = img->pixels; for (size_t h = 0; h < lines; ++h) { - size_t msize = std::min(img->rowPitch, mapped.RowPitch); + const size_t msize = std::min(img->rowPitch, mapped.RowPitch); memcpy(dptr, sptr, msize); sptr += mapped.RowPitch; dptr += img->rowPitch; @@ -209,10 +209,10 @@ bool DirectX::IsSupportedTexture( if (!pDevice) return false; - D3D_FEATURE_LEVEL fl = pDevice->GetFeatureLevel(); + const D3D_FEATURE_LEVEL fl = pDevice->GetFeatureLevel(); // Validate format - DXGI_FORMAT fmt = metadata.format; + const DXGI_FORMAT fmt = metadata.format; if (!IsValid(fmt)) return false; @@ -248,10 +248,10 @@ bool DirectX::IsSupportedTexture( return false; // Validate array size, dimension, and width/height - size_t arraySize = metadata.arraySize; - size_t iWidth = metadata.width; - size_t iHeight = metadata.height; - size_t iDepth = metadata.depth; + const size_t arraySize = metadata.arraySize; + const size_t iWidth = metadata.width; + const size_t iHeight = metadata.height; + const 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 UINT formatSupport = 0; @@ -461,7 +461,7 @@ HRESULT DirectX::CreateTextureEx( size_t idx = 0; for (size_t level = 0; level < metadata.mipLevels; ++level) { - size_t index = metadata.ComputeIndex(level, 0, 0); + const size_t index = metadata.ComputeIndex(level, 0, 0); if (index >= nimages) return E_FAIL; @@ -479,7 +479,7 @@ HRESULT DirectX::CreateTextureEx( const uint8_t* pSlice = img.pixels + img.slicePitch; for (size_t slice = 1; slice < depth; ++slice) { - size_t tindex = metadata.ComputeIndex(level, 0, slice); + const size_t tindex = metadata.ComputeIndex(level, 0, slice); if (tindex >= nimages) return E_FAIL; @@ -516,7 +516,7 @@ HRESULT DirectX::CreateTextureEx( { for (size_t level = 0; level < metadata.mipLevels; ++level) { - size_t index = metadata.ComputeIndex(level, item, 0); + const size_t index = metadata.ComputeIndex(level, item, 0); if (index >= nimages) return E_FAIL; @@ -541,7 +541,7 @@ HRESULT DirectX::CreateTextureEx( // Create texture using static initialization data HRESULT hr = E_UNEXPECTED; - DXGI_FORMAT tformat = (forceSRGB) ? MakeSRGB(metadata.format) : metadata.format; + const DXGI_FORMAT tformat = (forceSRGB) ? MakeSRGB(metadata.format) : metadata.format; switch (metadata.dimension) { @@ -843,7 +843,7 @@ HRESULT DirectX::CaptureTexture( { for (UINT level = 0; level < desc.MipLevels; ++level) { - UINT index = D3D11CalcSubresource(level, item, desc.MipLevels); + const UINT index = D3D11CalcSubresource(level, item, desc.MipLevels); pContext->ResolveSubresource(pTemp.Get(), index, pSource, index, fmt); } } diff --git a/DirectXTex/DirectXTexD3D12.cpp b/DirectXTex/DirectXTexD3D12.cpp index a3d109e..a0c9a25 100644 --- a/DirectXTex/DirectXTexD3D12.cpp +++ b/DirectXTex/DirectXTexD3D12.cpp @@ -151,7 +151,7 @@ namespace if (numberOfResources > D3D12_REQ_SUBRESOURCES) return E_UNEXPECTED; - size_t memAlloc = (sizeof(D3D12_PLACED_SUBRESOURCE_FOOTPRINT) + sizeof(UINT) + sizeof(UINT64)) * numberOfResources; + const size_t memAlloc = (sizeof(D3D12_PLACED_SUBRESOURCE_FOOTPRINT) + sizeof(UINT) + sizeof(UINT64)) * numberOfResources; if (memAlloc > SIZE_MAX) return E_UNEXPECTED; @@ -194,8 +194,8 @@ namespace if (FAILED(hr)) return hr; - CD3DX12_HEAP_PROPERTIES defaultHeapProperties(D3D12_HEAP_TYPE_DEFAULT); - CD3DX12_HEAP_PROPERTIES readBackHeapProperties(D3D12_HEAP_TYPE_READBACK); + const CD3DX12_HEAP_PROPERTIES defaultHeapProperties(D3D12_HEAP_TYPE_DEFAULT); + const CD3DX12_HEAP_PROPERTIES readBackHeapProperties(D3D12_HEAP_TYPE_READBACK); // Readback resources must be buffers D3D12_RESOURCE_DESC bufferDesc = {}; @@ -253,7 +253,7 @@ namespace { for (UINT level = 0; level < desc.MipLevels; ++level) { - UINT index = D3D12CalcSubresource(level, item, plane, desc.MipLevels, desc.DepthOrArraySize); + const UINT index = D3D12CalcSubresource(level, item, plane, desc.MipLevels, desc.DepthOrArraySize); commandList->ResolveSubresource(pTemp.Get(), index, pSource, index, fmt); } } @@ -281,8 +281,8 @@ namespace // Get the copy target location for (UINT j = 0; j < numberOfResources; ++j) { - CD3DX12_TEXTURE_COPY_LOCATION copyDest(pStaging.Get(), pLayout[j]); - CD3DX12_TEXTURE_COPY_LOCATION copySrc(copySource.Get(), j); + const CD3DX12_TEXTURE_COPY_LOCATION copyDest(pStaging.Get(), pLayout[j]); + const CD3DX12_TEXTURE_COPY_LOCATION copySrc(copySource.Get(), j); commandList->CopyTextureRegion(©Dest, 0, 0, 0, ©Src, nullptr); } @@ -332,7 +332,7 @@ bool DirectX::IsSupportedTexture( return false; // Validate format - DXGI_FORMAT fmt = metadata.format; + const DXGI_FORMAT fmt = metadata.format; if (!IsValid(fmt)) return false; @@ -342,10 +342,10 @@ bool DirectX::IsSupportedTexture( return false; // Validate array size, dimension, and width/height - size_t arraySize = metadata.arraySize; - size_t iWidth = metadata.width; - size_t iHeight = metadata.height; - size_t iDepth = metadata.depth; + const size_t arraySize = metadata.arraySize; + const size_t iWidth = metadata.width; + const size_t iHeight = metadata.height; + const 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_FORMAT_SUPPORT1_NONE, D3D12_FORMAT_SUPPORT2_NONE }; @@ -371,7 +371,7 @@ bool DirectX::IsSupportedTexture( return false; { - uint64_t numberOfResources = uint64_t(arraySize) * uint64_t(metadata.mipLevels); + const uint64_t numberOfResources = uint64_t(arraySize) * uint64_t(metadata.mipLevels); if (numberOfResources > D3D12_REQ_SUBRESOURCES) return false; } @@ -400,7 +400,7 @@ bool DirectX::IsSupportedTexture( } { - uint64_t numberOfResources = uint64_t(arraySize) * uint64_t(metadata.mipLevels); + const uint64_t numberOfResources = uint64_t(arraySize) * uint64_t(metadata.mipLevels); if (numberOfResources > D3D12_REQ_SUBRESOURCES) return false; } @@ -484,7 +484,7 @@ HRESULT DirectX::CreateTextureEx( desc.SampleDesc.Count = 1; desc.Dimension = static_cast(metadata.dimension); - CD3DX12_HEAP_PROPERTIES defaultHeapProperties(D3D12_HEAP_TYPE_DEFAULT); + const CD3DX12_HEAP_PROPERTIES defaultHeapProperties(D3D12_HEAP_TYPE_DEFAULT); HRESULT hr = pDevice->CreateCommittedResource( &defaultHeapProperties, @@ -513,7 +513,7 @@ HRESULT DirectX::PrepareUpload( if (!pDevice || !srcImages || !nimages || !metadata.mipLevels || !metadata.arraySize) return E_INVALIDARG; - UINT numberOfPlanes = D3D12GetFormatPlaneCount(pDevice, metadata.format); + const UINT numberOfPlanes = D3D12GetFormatPlaneCount(pDevice, metadata.format); if (!numberOfPlanes) return E_INVALIDARG; @@ -554,7 +554,7 @@ HRESULT DirectX::PrepareUpload( for (size_t level = 0; level < metadata.mipLevels; ++level) { - size_t index = metadata.ComputeIndex(level, 0, 0); + const size_t index = metadata.ComputeIndex(level, 0, 0); if (index >= nimages) return E_FAIL; @@ -572,7 +572,7 @@ HRESULT DirectX::PrepareUpload( const uint8_t* pSlice = img.pixels + img.slicePitch; for (size_t slice = 1; slice < depth; ++slice) { - size_t tindex = metadata.ComputeIndex(level, 0, slice); + const size_t tindex = metadata.ComputeIndex(level, 0, slice); if (tindex >= nimages) return E_FAIL; @@ -615,7 +615,7 @@ HRESULT DirectX::PrepareUpload( { for (size_t level = 0; level < metadata.mipLevels; ++level) { - size_t index = metadata.ComputeIndex(level, item, 0); + const size_t index = metadata.ComputeIndex(level, item, 0); if (index >= nimages) return E_FAIL; @@ -664,7 +664,7 @@ HRESULT DirectX::CaptureTexture( ComPtr device; pCommandQueue->GetDevice(IID_GRAPHICS_PPV_ARGS(device.GetAddressOf())); - auto desc = pSource->GetDesc(); + auto const desc = pSource->GetDesc(); ComPtr pStaging; std::unique_ptr layoutBuff; @@ -759,9 +759,9 @@ HRESULT DirectX::CaptureTexture( return E_FAIL; } - UINT arraySize = (desc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D) - ? 1u - : desc.DepthOrArraySize; + const UINT arraySize = (desc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D) + ? 1u + : desc.DepthOrArraySize; for (UINT plane = 0; plane < numberOfPlanes; ++plane) { @@ -769,7 +769,7 @@ HRESULT DirectX::CaptureTexture( { for (UINT level = 0; level < desc.MipLevels; ++level) { - UINT dindex = D3D12CalcSubresource(level, item, plane, desc.MipLevels, arraySize); + const UINT dindex = D3D12CalcSubresource(level, item, plane, desc.MipLevels, arraySize); assert(dindex < numberOfResources); const Image* img = result.GetImage(level, item, 0); diff --git a/DirectXTex/DirectXTexDDS.cpp b/DirectXTex/DirectXTexDDS.cpp index 275e1b6..8b76092 100644 --- a/DirectXTex/DirectXTexDDS.cpp +++ b/DirectXTex/DirectXTexDDS.cpp @@ -22,6 +22,8 @@ static_assert(static_cast(TEX_DIMENSION_TEXTURE3D) == static_cast(DDS_ namespace { + constexpr size_t MAX_HEADER_SIZE = sizeof(uint32_t) + sizeof(DDS_HEADER) + sizeof(DDS_HEADER_DXT10); + //------------------------------------------------------------------------------------- // Legacy format mapping table (used for DDS files without 'DX10' extended header) //------------------------------------------------------------------------------------- @@ -172,7 +174,7 @@ namespace ddpfFlags &= ~0xC0000000 /* DDPF_SRGB | DDPF_NORMAL */; } - const size_t MAP_SIZE = sizeof(g_LegacyDDSMap) / sizeof(LegacyDDS); + constexpr size_t MAP_SIZE = sizeof(g_LegacyDDSMap) / sizeof(LegacyDDS); size_t index = 0; for (index = 0; index < MAP_SIZE; ++index) { @@ -294,7 +296,7 @@ namespace } // DDS files always start with the same magic number ("DDS ") - auto dwMagicNumber = *static_cast(pSource); + auto const dwMagicNumber = *static_cast(pSource); if (dwMagicNumber != DDS_MAGIC) { return E_FAIL; @@ -890,7 +892,7 @@ namespace TEXP_LEGACY_A8L8 }; - inline TEXP_LEGACY_FORMAT FindLegacyFormat(uint32_t flags) noexcept + constexpr TEXP_LEGACY_FORMAT FindLegacyFormat(uint32_t flags) noexcept { TEXP_LEGACY_FORMAT lformat = TEXP_LEGACY_UNKNOWN; @@ -971,7 +973,7 @@ namespace for (size_t ocount = 0, icount = 0; ((icount < inSize) && (ocount < (outSize - 3))); ++icount, ocount += 4) { - uint8_t t = *(sPtr++); + const uint8_t t = *(sPtr++); uint32_t t1 = uint32_t((t & 0xe0) | ((t & 0xe0) >> 3) | ((t & 0xc0) >> 6)); uint32_t t2 = uint32_t(((t & 0x1c) << 11) | ((t & 0x1c) << 8) | ((t & 0x18) << 5)); @@ -992,7 +994,7 @@ namespace for (size_t ocount = 0, icount = 0; ((icount < inSize) && (ocount < (outSize - 1))); ++icount, ocount += 2) { - unsigned t = *(sPtr++); + const unsigned t = *(sPtr++); unsigned t1 = ((t & 0xe0u) << 8) | ((t & 0xc0u) << 5); unsigned t2 = ((t & 0x1cu) << 6) | ((t & 0x1cu) << 3); @@ -1020,7 +1022,7 @@ namespace for (size_t ocount = 0, icount = 0; ((icount < (inSize - 1)) && (ocount < (outSize - 3))); icount += 2, ocount += 4) { - uint16_t t = *(sPtr++); + const uint16_t t = *(sPtr++); uint32_t t1 = uint32_t((t & 0x00e0) | ((t & 0x00e0) >> 3) | ((t & 0x00c0) >> 6)); uint32_t t2 = uint32_t(((t & 0x001c) << 11) | ((t & 0x001c) << 8) | ((t & 0x0018) << 5)); @@ -1065,7 +1067,7 @@ namespace for (size_t ocount = 0, icount = 0; ((icount < (inSize - 1)) && (ocount < (outSize - 3))); icount += 2, ocount += 4) { - uint16_t t = *(sPtr++); + const uint16_t t = *(sPtr++); uint32_t t1 = pal8[t & 0xff]; uint32_t ta = (tflags & TEXP_SCANLINE_SETALPHA) ? 0xff000000 : uint32_t((t & 0xff00) << 16); @@ -1088,7 +1090,7 @@ namespace for (size_t ocount = 0, icount = 0; ((icount < inSize) && (ocount < (outSize - 1))); ++icount, ocount += 2) { - unsigned t = *(sPtr++); + const unsigned t = *(sPtr++); unsigned t1 = (t & 0x0fu); unsigned ta = (tflags & TEXP_SCANLINE_SETALPHA) ? 0xf000u : ((t & 0xf0u) << 8); @@ -1108,7 +1110,7 @@ namespace for (size_t ocount = 0, icount = 0; ((icount < inSize) && (ocount < (outSize - 3))); ++icount, ocount += 4) { - uint8_t t = *(sPtr++); + const uint8_t t = *(sPtr++); uint32_t t1 = uint32_t(((t & 0x0f) << 4) | (t & 0x0f)); uint32_t ta = (tflags & TEXP_SCANLINE_SETALPHA) ? 0xff000000 : uint32_t(((t & 0xf0) << 24) | ((t & 0xf0) << 20)); @@ -1135,7 +1137,7 @@ namespace for (size_t ocount = 0, icount = 0; ((icount < (inSize - 1)) && (ocount < (outSize - 3))); icount += 2, ocount += 4) { - uint32_t t = *(sPtr++); + const uint32_t t = *(sPtr++); uint32_t t1 = uint32_t((t & 0x0f00) >> 4) | ((t & 0x0f00) >> 8); uint32_t t2 = uint32_t((t & 0x00f0) << 8) | ((t & 0x00f0) << 4); @@ -1182,7 +1184,7 @@ namespace for (size_t ocount = 0, icount = 0; ((icount < (inSize - 1)) && (ocount < (outSize - 7))); icount += 2, ocount += 8) { - uint16_t t = *(sPtr++); + const uint16_t t = *(sPtr++); uint64_t t1 = t; uint64_t t2 = (t1 << 16); @@ -1206,7 +1208,7 @@ namespace for (size_t ocount = 0, icount = 0; ((icount < (inSize - 1)) && (ocount < (outSize - 3))); icount += 2, ocount += 4) { - uint16_t t = *(sPtr++); + const uint16_t t = *(sPtr++); uint32_t t1 = uint32_t(t & 0xff); uint32_t t2 = uint32_t(t1 << 8); @@ -1317,7 +1319,7 @@ namespace return E_FAIL; size_t dpitch = images[index].rowPitch; - size_t spitch = timages[index].rowPitch; + const size_t spitch = timages[index].rowPitch; const uint8_t *pSrc = timages[index].pixels; if (!pSrc) @@ -1347,11 +1349,11 @@ namespace } else if (IsPlanar(metadata.format)) { - size_t count = ComputeScanlines(metadata.format, images[index].height); + const size_t count = ComputeScanlines(metadata.format, images[index].height); if (!count) return E_UNEXPECTED; - size_t csize = std::min(dpitch, spitch); + const size_t csize = std::min(dpitch, spitch); for (size_t h = 0; h < count; ++h) { memcpy(pDest, pSrc, csize); @@ -1375,7 +1377,7 @@ namespace } else { - TEXP_LEGACY_FORMAT lformat = FindLegacyFormat(convFlags); + const TEXP_LEGACY_FORMAT lformat = FindLegacyFormat(convFlags); if (!LegacyExpandScanline(pDest, dpitch, metadata.format, pSrc, spitch, lformat, pal8, tflags)) @@ -1419,7 +1421,7 @@ namespace return E_FAIL; size_t dpitch = images[index].rowPitch; - size_t spitch = timages[index].rowPitch; + const size_t spitch = timages[index].rowPitch; const uint8_t *pSrc = timages[index].pixels; if (!pSrc) @@ -1468,7 +1470,7 @@ namespace } else { - TEXP_LEGACY_FORMAT lformat = FindLegacyFormat(convFlags); + const TEXP_LEGACY_FORMAT lformat = FindLegacyFormat(convFlags); if (!LegacyExpandScanline(pDest, dpitch, metadata.format, pSrc, spitch, lformat, pal8, tflags)) @@ -1606,7 +1608,7 @@ HRESULT DirectX::GetMetadataFromDDSFile( return HRESULT_E_FILE_TOO_LARGE; } - size_t len = fileInfo.EndOfFile.LowPart; + const size_t len = fileInfo.EndOfFile.LowPart; #else // !WIN32 std::ifstream inFile(std::filesystem::path(szFile), std::ios::in | std::ios::binary | std::ios::ate); if (!inFile) @@ -1623,7 +1625,7 @@ HRESULT DirectX::GetMetadataFromDDSFile( if (!inFile) return E_FAIL; - size_t len = fileLen; + const size_t len = fileLen; #endif // Need at least enough data to fill the standard header and magic number to be a valid DDS @@ -1633,7 +1635,6 @@ HRESULT DirectX::GetMetadataFromDDSFile( } // Read the header in (including extended header if present) - const size_t MAX_HEADER_SIZE = sizeof(uint32_t) + sizeof(DDS_HEADER) + sizeof(DDS_HEADER_DXT10); uint8_t header[MAX_HEADER_SIZE] = {}; #ifdef WIN32 @@ -1643,9 +1644,9 @@ HRESULT DirectX::GetMetadataFromDDSFile( return HRESULT_FROM_WIN32(GetLastError()); } - auto headerLen = static_cast(bytesRead); + auto const headerLen = static_cast(bytesRead); #else - auto headerLen = std::min(len, MAX_HEADER_SIZE); + auto const headerLen = std::min(len, MAX_HEADER_SIZE); inFile.read(reinterpret_cast(header), headerLen); if (!inFile) @@ -1768,7 +1769,7 @@ HRESULT DirectX::LoadFromDDSFile( if (fileInfo.EndOfFile.HighPart > 0) return HRESULT_E_FILE_TOO_LARGE; - size_t len = fileInfo.EndOfFile.LowPart; + const size_t len = fileInfo.EndOfFile.LowPart; #else // !WIN32 std::ifstream inFile(std::filesystem::path(szFile), std::ios::in | std::ios::binary | std::ios::ate); if (!inFile) @@ -1785,7 +1786,7 @@ HRESULT DirectX::LoadFromDDSFile( if (!inFile) return E_FAIL; - size_t len = fileLen; + const size_t len = fileLen; #endif // Need at least enough data to fill the standard header and magic number to be a valid DDS @@ -1795,7 +1796,6 @@ HRESULT DirectX::LoadFromDDSFile( } // Read the header in (including extended header if present) - const size_t MAX_HEADER_SIZE = sizeof(uint32_t) + sizeof(DDS_HEADER) + sizeof(DDS_HEADER_DXT10); uint8_t header[MAX_HEADER_SIZE] = {}; #ifdef WIN32 @@ -1805,9 +1805,9 @@ HRESULT DirectX::LoadFromDDSFile( return HRESULT_FROM_WIN32(GetLastError()); } - auto headerLen = static_cast(bytesRead); + auto const headerLen = static_cast(bytesRead); #else - auto headerLen = std::min(len, MAX_HEADER_SIZE); + auto const headerLen = std::min(len, MAX_HEADER_SIZE); inFile.read(reinterpret_cast(header), headerLen); if (!inFile) @@ -1826,7 +1826,7 @@ HRESULT DirectX::LoadFromDDSFile( { #ifdef WIN32 // Must reset file position since we read more than the standard header above - LARGE_INTEGER filePos = { { sizeof(uint32_t) + sizeof(DDS_HEADER), 0 } }; + const LARGE_INTEGER filePos = { { sizeof(uint32_t) + sizeof(DDS_HEADER), 0 } }; if (!SetFilePointerEx(hFile.get(), filePos, nullptr, FILE_BEGIN)) { return HRESULT_FROM_WIN32(GetLastError()); @@ -1868,7 +1868,7 @@ HRESULT DirectX::LoadFromDDSFile( offset += (256 * sizeof(uint32_t)); } - size_t remaining = len - offset; + const size_t remaining = len - offset; if (remaining == 0) return E_FAIL; @@ -2216,7 +2216,6 @@ HRESULT DirectX::SaveToDDSFile( return E_INVALIDARG; // Create DDS Header - const size_t MAX_HEADER_SIZE = sizeof(uint32_t) + sizeof(DDS_HEADER) + sizeof(DDS_HEADER_DXT10); uint8_t header[MAX_HEADER_SIZE]; size_t required; HRESULT hr = EncodeDDSHeader(metadata, flags, header, MAX_HEADER_SIZE, required); @@ -2304,7 +2303,7 @@ HRESULT DirectX::SaveToDDSFile( } else { - size_t rowPitch = images[index].rowPitch; + const size_t rowPitch = images[index].rowPitch; if (rowPitch < ddsRowPitch) { // DDS uses 1-byte alignment, so if this is happening then the input pitch isn't actually a full line of data @@ -2316,7 +2315,7 @@ HRESULT DirectX::SaveToDDSFile( const uint8_t * __restrict sPtr = images[index].pixels; - size_t lines = ComputeScanlines(metadata.format, images[index].height); + const size_t lines = ComputeScanlines(metadata.format, images[index].height); for (size_t j = 0; j < lines; ++j) { #ifdef WIN32 @@ -2389,7 +2388,7 @@ HRESULT DirectX::SaveToDDSFile( } else { - size_t rowPitch = images[index].rowPitch; + const size_t rowPitch = images[index].rowPitch; if (rowPitch < ddsRowPitch) { // DDS uses 1-byte alignment, so if this is happening then the input pitch isn't actually a full line of data @@ -2401,7 +2400,7 @@ HRESULT DirectX::SaveToDDSFile( const uint8_t * __restrict sPtr = images[index].pixels; - size_t lines = ComputeScanlines(metadata.format, images[index].height); + const size_t lines = ComputeScanlines(metadata.format, images[index].height); for (size_t j = 0; j < lines; ++j) { #ifdef WIN32 diff --git a/DirectXTex/DirectXTexFlipRotate.cpp b/DirectXTex/DirectXTexFlipRotate.cpp index 78978d2..1b26e68 100644 --- a/DirectXTex/DirectXTexFlipRotate.cpp +++ b/DirectXTex/DirectXTexFlipRotate.cpp @@ -211,7 +211,7 @@ HRESULT DirectX::FlipRotate( static_assert(static_cast(TEX_FR_FLIP_VERTICAL) == static_cast(WICBitmapTransformFlipVertical), "TEX_FR_FLIP_VERTICAL no longer matches WIC"); // Only supports 90, 180, 270, or no rotation flags... not a combination of rotation flags - int rotateMode = static_cast(flags & (TEX_FR_ROTATE0 | TEX_FR_ROTATE90 | TEX_FR_ROTATE180 | TEX_FR_ROTATE270)); + const int rotateMode = static_cast(flags & (TEX_FR_ROTATE0 | TEX_FR_ROTATE90 | TEX_FR_ROTATE180 | TEX_FR_ROTATE270)); switch (rotateMode) { @@ -254,7 +254,7 @@ HRESULT DirectX::FlipRotate( else { // Case 2: Source format is not supported by WIC, so we have to convert, flip/rotate, and convert back - uint64_t expandedSize = uint64_t(srcImage.width) * uint64_t(srcImage.height) * sizeof(float) * 4; + const uint64_t expandedSize = uint64_t(srcImage.width) * uint64_t(srcImage.height) * sizeof(float) * 4; if (expandedSize > UINT32_MAX) { // Image is too large for float32, so have to use float16 instead @@ -304,7 +304,7 @@ HRESULT DirectX::FlipRotate( static_assert(static_cast(TEX_FR_FLIP_VERTICAL) == static_cast(WICBitmapTransformFlipVertical), "TEX_FR_FLIP_VERTICAL no longer matches WIC"); // Only supports 90, 180, 270, or no rotation flags... not a combination of rotation flags - int rotateMode = static_cast(flags & (TEX_FR_ROTATE0 | TEX_FR_ROTATE90 | TEX_FR_ROTATE180 | TEX_FR_ROTATE270)); + const int rotateMode = static_cast(flags & (TEX_FR_ROTATE0 | TEX_FR_ROTATE90 | TEX_FR_ROTATE180 | TEX_FR_ROTATE270)); switch (rotateMode) { @@ -346,7 +346,7 @@ HRESULT DirectX::FlipRotate( } WICPixelFormatGUID pfGUID; - bool wicpf = DXGIToWIC(metadata.format, pfGUID); + const bool wicpf = DXGIToWIC(metadata.format, pfGUID); for (size_t index = 0; index < nimages; ++index) { @@ -388,7 +388,7 @@ HRESULT DirectX::FlipRotate( else { // Case 2: Source format is not supported by WIC, so we have to convert, flip/rotate, and convert back - uint64_t expandedSize = uint64_t(src.width) * uint64_t(src.height) * sizeof(float) * 4; + const uint64_t expandedSize = uint64_t(src.width) * uint64_t(src.height) * sizeof(float) * 4; if (expandedSize > UINT32_MAX) { // Image is too large for float32, so have to use float16 instead diff --git a/DirectXTex/DirectXTexHDR.cpp b/DirectXTex/DirectXTexHDR.cpp index 87218c6..b67489c 100644 --- a/DirectXTex/DirectXTexHDR.cpp +++ b/DirectXTex/DirectXTexHDR.cpp @@ -131,8 +131,8 @@ namespace break; } - const size_t formatLen = sizeof(g_Format) - 1; - const size_t exposureLen = sizeof(g_Exposure) - 1; + constexpr size_t formatLen = sizeof(g_Format) - 1; + constexpr size_t exposureLen = sizeof(g_Exposure) - 1; if ((size > formatLen) && memcmp(info, g_Format, formatLen) == 0) { info += formatLen; @@ -148,7 +148,7 @@ namespace static_assert(sizeof(g_sRGBE) == sizeof(g_sXYZE), "Format strings length mismatch"); - const size_t encodingLen = sizeof(g_sRGBE) - 1; + constexpr size_t encodingLen = sizeof(g_sRGBE) - 1; if (size < encodingLen) { @@ -162,7 +162,7 @@ namespace formatFound = true; - size_t len = FindEOL(info, size); + const size_t len = FindEOL(info, size); if (len == size_t(-1)) { return E_FAIL; @@ -184,7 +184,7 @@ namespace ++info; } - size_t len = FindEOL(info, size); + const size_t len = FindEOL(info, size); if (len == size_t(-1) || len < 1) { @@ -206,7 +206,7 @@ namespace } else { - size_t len = FindEOL(info, size); + const size_t len = FindEOL(info, size); if (len == size_t(-1)) { return E_FAIL; @@ -225,7 +225,7 @@ namespace // Get orientation char orientation[256] = {}; - size_t len = FindEOL(info, std::min(sizeof(orientation), size - 1)); + const size_t len = FindEOL(info, std::min(sizeof(orientation), size - 1)); if (len == size_t(-1) || len <= 2) { @@ -314,9 +314,9 @@ namespace for (size_t j = 0; j < width; ++j) { if (pSource + 2 >= ePtr) break; - float r = pSource[0] >= 0.f ? pSource[0] : 0.f; - float g = pSource[1] >= 0.f ? pSource[1] : 0.f; - float b = pSource[2] >= 0.f ? pSource[2] : 0.f; + const float r = pSource[0] >= 0.f ? pSource[0] : 0.f; + const float g = pSource[1] >= 0.f ? pSource[1] : 0.f; + const float b = pSource[2] >= 0.f ? pSource[2] : 0.f; pSource += fpp; const float max_xy = (r > g) ? r : g; @@ -328,9 +328,9 @@ namespace max_xyz = frexpf(max_xyz, &e) * 256.f / max_xyz; e += 128; - uint8_t red = uint8_t(r * max_xyz); - uint8_t green = uint8_t(g * max_xyz); - uint8_t blue = uint8_t(b * max_xyz); + const uint8_t red = uint8_t(r * max_xyz); + const uint8_t green = uint8_t(g * max_xyz); + const uint8_t blue = uint8_t(b * max_xyz); pDestination[0] = red; pDestination[1] = green; @@ -370,9 +370,9 @@ namespace max_xyz = frexpf(max_xyz, &e) * 256.f / max_xyz; e += 128; - uint8_t red = uint8_t(r * max_xyz); - uint8_t green = uint8_t(g * max_xyz); - uint8_t blue = uint8_t(b * max_xyz); + const uint8_t red = uint8_t(r * max_xyz); + const uint8_t green = uint8_t(g * max_xyz); + const uint8_t blue = uint8_t(b * max_xyz); pDestination[0] = red; pDestination[1] = green; @@ -623,7 +623,7 @@ HRESULT DirectX::GetMetadataFromHDRFile(const wchar_t* szFile, TexMetadata& meta return HRESULT_E_FILE_TOO_LARGE; } - size_t len = fileInfo.EndOfFile.LowPart; + const size_t len = fileInfo.EndOfFile.LowPart; #else // !WIN32 std::ifstream inFile(std::filesystem::path(szFile), std::ios::in | std::ios::binary | std::ios::ate); if (!inFile) @@ -640,7 +640,7 @@ HRESULT DirectX::GetMetadataFromHDRFile(const wchar_t* szFile, TexMetadata& meta if (!inFile) return E_FAIL; - size_t len = fileLen; + const size_t len = fileLen; #endif // Need at least enough data to fill the standard header to be a valid HDR @@ -659,9 +659,9 @@ HRESULT DirectX::GetMetadataFromHDRFile(const wchar_t* szFile, TexMetadata& meta return HRESULT_FROM_WIN32(GetLastError()); } - auto headerLen = static_cast(bytesRead); + auto const headerLen = static_cast(bytesRead); #else - auto headerLen = std::min(sizeof(header), len); + auto const headerLen = std::min(sizeof(header), len); inFile.read(reinterpret_cast(header), headerLen); if (!inFile) @@ -695,7 +695,7 @@ HRESULT DirectX::LoadFromHDRMemory(const void* pSource, size_t size, TexMetadata if (offset > size) return E_FAIL; - size_t remaining = size - offset; + const size_t remaining = size - offset; if (remaining == 0) return E_FAIL; @@ -820,7 +820,7 @@ HRESULT DirectX::LoadFromHDRMemory(const void* pSource, size_t size, TexMetadata } // "Standard" Run Length Encoding - size_t spanLen = size_t(inColor[3]) << bitShift; + const size_t spanLen = size_t(inColor[3]) << bitShift; if (spanLen + pixelCount > mdata.width) { image.Release(); @@ -874,7 +874,7 @@ HRESULT DirectX::LoadFromHDRMemory(const void* pSource, size_t size, TexMetadata for (size_t j = 0; j < image.GetPixelsSize(); j += 16) { - auto exponent = static_cast(fdata[3]); + auto const 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)); @@ -927,7 +927,7 @@ HRESULT DirectX::LoadFromHDRFile(const wchar_t* szFile, TexMetadata* metadata, S return HRESULT_E_FILE_TOO_LARGE; } - size_t len = fileInfo.EndOfFile.LowPart; + const size_t len = fileInfo.EndOfFile.LowPart; #else // !WIN32 std::ifstream inFile(std::filesystem::path(szFile), std::ios::in | std::ios::binary | std::ios::ate); if (!inFile) @@ -944,7 +944,7 @@ HRESULT DirectX::LoadFromHDRFile(const wchar_t* szFile, TexMetadata* metadata, S if (!inFile) return E_FAIL; - size_t len = fileLen; + const size_t len = fileLen; #endif // Need at least enough data to fill the header to be a valid HDR @@ -1020,7 +1020,7 @@ HRESULT DirectX::SaveToHDRMemory(const Image& image, Blob& blob) noexcept auto headerLen = static_cast(strlen(header)); size_t rowPitch = image.width * 4; - size_t slicePitch = image.height * rowPitch; + const size_t slicePitch = image.height * rowPitch; HRESULT hr = blob.Initialize(headerLen + slicePitch); if (FAILED(hr)) @@ -1145,8 +1145,8 @@ HRESULT DirectX::SaveToHDRFile(const Image& image, const wchar_t* szFile) noexce return E_FAIL; #endif - uint64_t pitch = uint64_t(image.width) * 4u; - uint64_t slicePitch = uint64_t(image.height) * pitch; + const uint64_t pitch = uint64_t(image.width) * 4u; + const uint64_t slicePitch = uint64_t(image.height) * pitch; if (pitch > UINT32_MAX) return HRESULT_E_ARITHMETIC_OVERFLOW; @@ -1164,7 +1164,7 @@ HRESULT DirectX::SaveToHDRFile(const Image& image, const wchar_t* szFile) noexce // Write blob #ifdef WIN32 - auto bytesToWrite = static_cast(blob.GetBufferSize()); + auto const bytesToWrite = static_cast(blob.GetBufferSize()); DWORD bytesWritten; if (!WriteFile(hFile.get(), blob.GetBufferPointer(), bytesToWrite, &bytesWritten, nullptr)) { @@ -1197,7 +1197,7 @@ HRESULT DirectX::SaveToHDRFile(const Image& image, const wchar_t* szFile) noexce sprintf_s(header, g_Header, image.height, image.width); #ifdef WIN32 - auto headerLen = static_cast(strlen(header)); + auto const headerLen = static_cast(strlen(header)); DWORD bytesWritten; if (!WriteFile(hFile.get(), header, headerLen, &bytesWritten, nullptr)) @@ -1252,7 +1252,7 @@ HRESULT DirectX::SaveToHDRFile(const Image& image, const wchar_t* szFile) noexce } sPtr += image.rowPitch; - size_t encSize = EncodeRLE(enc, rgbe, rowPitch, image.width); + const size_t encSize = EncodeRLE(enc, rgbe, rowPitch, image.width); if (encSize > 0) { if (encSize > UINT32_MAX) diff --git a/DirectXTex/DirectXTexImage.cpp b/DirectXTex/DirectXTexImage.cpp index 8fdc339..c03ebab 100644 --- a/DirectXTex/DirectXTexImage.cpp +++ b/DirectXTex/DirectXTexImage.cpp @@ -521,7 +521,7 @@ HRESULT ScratchImage::InitializeFromImage(const Image& srcImage, bool allow1D, C if (FAILED(hr)) return hr; - size_t rowCount = ComputeScanlines(srcImage.format, srcImage.height); + const size_t rowCount = ComputeScanlines(srcImage.format, srcImage.height); if (!rowCount) return E_UNEXPECTED; @@ -533,10 +533,10 @@ HRESULT ScratchImage::InitializeFromImage(const Image& srcImage, bool allow1D, C if (!dptr) return E_POINTER; - size_t spitch = srcImage.rowPitch; - size_t dpitch = m_image[0].rowPitch; + const size_t spitch = srcImage.rowPitch; + const size_t dpitch = m_image[0].rowPitch; - size_t size = std::min(dpitch, spitch); + const size_t size = std::min(dpitch, spitch); for (size_t y = 0; y < rowCount; ++y) { @@ -554,9 +554,9 @@ HRESULT ScratchImage::InitializeArrayFromImages(const Image* images, size_t nIma if (!images || !nImages) return E_INVALIDARG; - DXGI_FORMAT format = images[0].format; - size_t width = images[0].width; - size_t height = images[0].height; + const DXGI_FORMAT format = images[0].format; + const size_t width = images[0].width; + const size_t height = images[0].height; for (size_t index = 0; index < nImages; ++index) { @@ -577,7 +577,7 @@ HRESULT ScratchImage::InitializeArrayFromImages(const Image* images, size_t nIma if (FAILED(hr)) return hr; - size_t rowCount = ComputeScanlines(format, height); + const size_t rowCount = ComputeScanlines(format, height); if (!rowCount) return E_UNEXPECTED; @@ -592,10 +592,10 @@ HRESULT ScratchImage::InitializeArrayFromImages(const Image* images, size_t nIma if (!dptr) return E_POINTER; - size_t spitch = images[index].rowPitch; - size_t dpitch = m_image[index].rowPitch; + const size_t spitch = images[index].rowPitch; + const size_t dpitch = m_image[index].rowPitch; - size_t size = std::min(dpitch, spitch); + const size_t size = std::min(dpitch, spitch); for (size_t y = 0; y < rowCount; ++y) { @@ -633,9 +633,9 @@ HRESULT ScratchImage::Initialize3DFromImages(const Image* images, size_t depth, if (!images || !depth) return E_INVALIDARG; - DXGI_FORMAT format = images[0].format; - size_t width = images[0].width; - size_t height = images[0].height; + const DXGI_FORMAT format = images[0].format; + const size_t width = images[0].width; + const size_t height = images[0].height; for (size_t slice = 0; slice < depth; ++slice) { @@ -653,7 +653,7 @@ HRESULT ScratchImage::Initialize3DFromImages(const Image* images, size_t depth, if (FAILED(hr)) return hr; - size_t rowCount = ComputeScanlines(format, height); + const size_t rowCount = ComputeScanlines(format, height); if (!rowCount) return E_UNEXPECTED; @@ -668,10 +668,10 @@ HRESULT ScratchImage::Initialize3DFromImages(const Image* images, size_t depth, if (!dptr) return E_POINTER; - size_t spitch = images[slice].rowPitch; - size_t dpitch = m_image[slice].rowPitch; + const size_t spitch = images[slice].rowPitch; + const size_t dpitch = m_image[slice].rowPitch; - size_t size = std::min(dpitch, spitch); + const size_t size = std::min(dpitch, spitch); for (size_t y = 0; y < rowCount; ++y) { @@ -815,7 +815,7 @@ bool ScratchImage::IsAlphaAllOpaque() const noexcept const XMVECTOR* ptr = scanline.get(); for (size_t w = 0; w < img.width; ++w) { - XMVECTOR alpha = XMVectorSplatW(*ptr); + const XMVECTOR alpha = XMVectorSplatW(*ptr); if (XMVector4Less(alpha, threshold)) return false; ++ptr; diff --git a/DirectXTex/DirectXTexMipmaps.cpp b/DirectXTex/DirectXTexMipmaps.cpp index 10e8c55..7fb5549 100644 --- a/DirectXTex/DirectXTexMipmaps.cpp +++ b/DirectXTex/DirectXTexMipmaps.cpp @@ -19,7 +19,7 @@ using Microsoft::WRL::ComPtr; namespace { - inline bool ispow2(_In_ size_t x) noexcept + constexpr bool ispow2(_In_ size_t x) noexcept { return ((x != 0) && !(x & (x - 1))); } @@ -170,8 +170,8 @@ namespace XMVECTOR* ptr = scanline.get(); for (size_t w = 0; w < srcImage.width; ++w) { - XMVECTOR v = *ptr; - XMVECTOR alpha = XMVectorMultiply(XMVectorSplatW(v), vscale); + const XMVECTOR v = *ptr; + const XMVECTOR alpha = XMVectorMultiply(XMVectorSplatW(v), vscale); *(ptr++) = XMVectorSelect(alpha, v, g_XMSelect1110); } @@ -237,7 +237,7 @@ namespace return E_POINTER; } - const size_t N = 8; + constexpr size_t N = 8; XMVECTOR convolution[N * N]; GenerateAlphaCoverageConvolutionVectors(N, convolution); @@ -261,9 +261,9 @@ namespace { // [0]=(x+0, y+0), [1]=(x+0, y+1), [2]=(x+1, y+0), [3]=(x+1, y+1) XMVECTOR v1 = XMVectorSaturate(XMVectorMultiply(XMVectorSplatW(*pRow0), scale)); - XMVECTOR v2 = XMVectorSaturate(XMVectorMultiply(XMVectorSplatW(*pRow1), scale)); + const XMVECTOR v2 = XMVectorSaturate(XMVectorMultiply(XMVectorSplatW(*pRow1), scale)); XMVECTOR v3 = XMVectorSaturate(XMVectorMultiply(XMVectorSplatW(*(pRow0++)), scale)); - XMVECTOR v4 = XMVectorSaturate(XMVectorMultiply(XMVectorSplatW(*(pRow1++)), scale)); + const XMVECTOR v4 = XMVectorSaturate(XMVectorMultiply(XMVectorSplatW(*(pRow1++)), scale)); v1 = XMVectorMergeXY(v1, v2); // [v1.x v2.x --- ---] v3 = XMVectorMergeXY(v3, v4); // [v3.x v4.x --- ---] @@ -309,7 +309,7 @@ namespace // Determine desired scale using a binary search. Hardcoded to 10 steps max. alphaScale = 1.0f; - const size_t N = 10; + constexpr size_t N = 10; for (size_t i = 0; i < N; ++i) { float currentCoverage = 0.0f; @@ -353,7 +353,7 @@ bool DirectX::Internal::CalculateMipLevels( { if (mipLevels > 1) { - size_t maxMips = CountMips(width, height); + const size_t maxMips = CountMips(width, height); if (mipLevels > maxMips) return false; } @@ -377,7 +377,7 @@ bool DirectX::Internal::CalculateMipLevels3D( { if (mipLevels > 1) { - size_t maxMips = CountMips3D(width, height, depth); + const size_t maxMips = CountMips3D(width, height, depth); if (mipLevels > maxMips) return false; } @@ -577,7 +577,7 @@ HRESULT DirectX::Internal::ResizeSeparateColorAndAlpha( for (size_t i = 0; SUCCEEDED(hr) && i < newWidth; i++) { size_t colorWithAlphaIndex = (j * colorWithAlphaStride) + (i * colorWithAlphaBytesPerPixel); - size_t colorIndex = (j * colorStride) + (i * colorBytesPerPixel); + const size_t colorIndex = (j * colorStride) + (i * colorBytesPerPixel); if (((colorWithAlphaIndex + colorBytesInPixel) > colorWithAlphaSizeInBytes) || ((colorIndex + colorBytesPerPixel) > colorSizeInBytes)) @@ -729,7 +729,7 @@ namespace const uint8_t *pSrc = baseImage.pixels; for (size_t h = 0; h < height; ++h) { - size_t msize = std::min(img0->rowPitch, baseImage.rowPitch); + const size_t msize = std::min(img0->rowPitch, baseImage.rowPitch); memcpy_s(pDest, img0->rowPitch, pSrc, msize); pSrc += baseImage.rowPitch; pDest += img0->rowPitch; @@ -876,10 +876,10 @@ namespace } const uint8_t *pSrc = src.pixels; - size_t rowPitch = src.rowPitch; + const size_t rowPitch = src.rowPitch; for (size_t h = 0; h < mdata.height; ++h) { - size_t msize = std::min(dest->rowPitch, rowPitch); + const size_t msize = std::min(dest->rowPitch, rowPitch); memcpy(pDest, pSrc, msize); pSrc += rowPitch; pDest += dest->rowPitch; @@ -928,13 +928,13 @@ namespace const uint8_t* pSrc = src->pixels; uint8_t* pDest = dest->pixels; - size_t rowPitch = src->rowPitch; + const size_t rowPitch = src->rowPitch; - size_t nwidth = (width > 1) ? (width >> 1) : 1; - size_t nheight = (height > 1) ? (height >> 1) : 1; + const size_t nwidth = (width > 1) ? (width >> 1) : 1; + const size_t nheight = (height > 1) ? (height >> 1) : 1; - size_t xinc = (width << 16) / nwidth; - size_t yinc = (height << 16) / nheight; + const size_t xinc = (width << 16) / nwidth; + const size_t yinc = (height << 16) / nheight; size_t lasty = size_t(-1); @@ -1028,10 +1028,10 @@ namespace const uint8_t* pSrc = src->pixels; uint8_t* pDest = dest->pixels; - size_t rowPitch = src->rowPitch; + const size_t rowPitch = src->rowPitch; - size_t nwidth = (width > 1) ? (width >> 1) : 1; - size_t nheight = (height > 1) ? (height >> 1) : 1; + const size_t nwidth = (width > 1) ? (width >> 1) : 1; + const size_t nheight = (height > 1) ? (height >> 1) : 1; for (size_t y = 0; y < nheight; ++y) { @@ -1048,7 +1048,7 @@ namespace for (size_t x = 0; x < nwidth; ++x) { - size_t x2 = x << 1; + const size_t x2 = x << 1; AVERAGE4(target[x], urow0[x2], urow1[x2], urow2[x2], urow3[x2]) } @@ -1114,12 +1114,12 @@ namespace const uint8_t* pSrc = src->pixels; uint8_t* pDest = dest->pixels; - size_t rowPitch = src->rowPitch; + const size_t rowPitch = src->rowPitch; - size_t nwidth = (width > 1) ? (width >> 1) : 1; + const size_t nwidth = (width > 1) ? (width >> 1) : 1; CreateLinearFilter(width, nwidth, (filter & TEX_FILTER_WRAP_U) != 0, lfX); - size_t nheight = (height > 1) ? (height >> 1) : 1; + const size_t nheight = (height > 1) ? (height >> 1) : 1; CreateLinearFilter(height, nheight, (filter & TEX_FILTER_WRAP_V) != 0, lfY); #ifdef _DEBUG @@ -1132,7 +1132,7 @@ namespace for (size_t y = 0; y < nheight; ++y) { - auto& toY = lfY[y]; + auto const& toY = lfY[y]; if (toY.u0 != u0) { @@ -1162,7 +1162,7 @@ namespace for (size_t x = 0; x < nwidth; ++x) { - auto& toX = lfX[x]; + auto const& toX = lfX[x]; BILINEAR_INTERPOLATE(target[x], toX, toY, row0, row1) } @@ -1229,12 +1229,12 @@ namespace const uint8_t* pSrc = src->pixels; uint8_t* pDest = dest->pixels; - size_t rowPitch = src->rowPitch; + const size_t rowPitch = src->rowPitch; - size_t nwidth = (width > 1) ? (width >> 1) : 1; + const size_t nwidth = (width > 1) ? (width >> 1) : 1; CreateCubicFilter(width, nwidth, (filter & TEX_FILTER_WRAP_U) != 0, (filter & TEX_FILTER_MIRROR_U) != 0, cfX); - size_t nheight = (height > 1) ? (height >> 1) : 1; + const size_t nheight = (height > 1) ? (height >> 1) : 1; CreateCubicFilter(height, nheight, (filter & TEX_FILTER_WRAP_V) != 0, (filter & TEX_FILTER_MIRROR_V) != 0, cfY); #ifdef _DEBUG @@ -1251,7 +1251,7 @@ namespace for (size_t y = 0; y < nheight; ++y) { - auto& toY = cfY[y]; + auto const& toY = cfY[y]; // Scanline 1 if (toY.u0 != u0) @@ -1342,7 +1342,7 @@ namespace for (size_t x = 0; x < nwidth; ++x) { - auto& toX = cfX[x]; + auto const& toX = cfX[x]; XMVECTOR C0, C1, C2, C3; @@ -1411,17 +1411,17 @@ namespace return E_POINTER; const uint8_t* pSrc = src->pixels; - size_t rowPitch = src->rowPitch; + const size_t rowPitch = src->rowPitch; const uint8_t* pEndSrc = pSrc + rowPitch * height; uint8_t* pDest = dest->pixels; - size_t nwidth = (width > 1) ? (width >> 1) : 1; + const size_t nwidth = (width > 1) ? (width >> 1) : 1; HRESULT hr = CreateTriangleFilter(width, nwidth, (filter & TEX_FILTER_WRAP_U) != 0, tfX); if (FAILED(hr)) return hr; - size_t nheight = (height > 1) ? (height >> 1) : 1; + const size_t nheight = (height > 1) ? (height >> 1) : 1; hr = CreateTriangleFilter(height, nheight, (filter & TEX_FILTER_WRAP_V) != 0, tfY); if (FAILED(hr)) return hr; @@ -1438,7 +1438,7 @@ namespace { for (size_t j = 0; j < yFrom->count; ++j) { - size_t v = yFrom->to[j].u; + const size_t v = yFrom->to[j].u; assert(v < nheight); TriangleRow* rowAcc = &rowActive[v]; @@ -1459,7 +1459,7 @@ namespace // Create accumulation rows as needed for (size_t j = 0; j < yFrom->count; ++j) { - size_t v = yFrom->to[j].u; + const size_t v = yFrom->to[j].u; assert(v < nheight); TriangleRow* rowAcc = &rowActive[v]; @@ -1500,9 +1500,9 @@ namespace { for (size_t j = 0; j < yFrom->count; ++j) { - size_t v = yFrom->to[j].u; + const size_t v = yFrom->to[j].u; assert(v < nheight); - float yweight = yFrom->to[j].weight; + const float yweight = yFrom->to[j].weight; XMVECTOR* accPtr = rowActive[v].scanline.get(); if (!accPtr) @@ -1513,7 +1513,7 @@ namespace size_t u = xFrom->to[k].u; assert(u < nwidth); - XMVECTOR weight = XMVectorReplicate(yweight * xFrom->to[k].weight); + const XMVECTOR weight = XMVectorReplicate(yweight * xFrom->to[k].weight); assert(x < width); accPtr[u] = XMVectorMultiplyAdd(row[x], weight, accPtr[u]); @@ -1598,8 +1598,8 @@ namespace assert(levels > 1); - size_t width = baseImages[0].width; - size_t height = baseImages[0].height; + const size_t width = baseImages[0].width; + const size_t height = baseImages[0].height; HRESULT hr = mipChain.Initialize3D(baseImages[0].format, width, height, depth, levels); if (FAILED(hr)) @@ -1627,10 +1627,10 @@ namespace } const uint8_t *pSrc = src.pixels; - size_t rowPitch = src.rowPitch; + const size_t rowPitch = src.rowPitch; for (size_t h = 0; h < height; ++h) { - size_t msize = std::min(dest->rowPitch, rowPitch); + const size_t msize = std::min(dest->rowPitch, rowPitch); memcpy(pDest, pSrc, msize); pSrc += rowPitch; pDest += dest->rowPitch; @@ -1673,9 +1673,9 @@ namespace if (depth > 1) { // 3D point filter - size_t ndepth = depth >> 1; + const size_t ndepth = depth >> 1; - size_t zinc = (depth << 16) / ndepth; + const size_t zinc = (depth << 16) / ndepth; size_t sz = 0; for (size_t slice = 0; slice < ndepth; ++slice) @@ -1689,13 +1689,13 @@ namespace const uint8_t* pSrc = src->pixels; uint8_t* pDest = dest->pixels; - size_t rowPitch = src->rowPitch; + const size_t rowPitch = src->rowPitch; - size_t nwidth = (width > 1) ? (width >> 1) : 1; - size_t nheight = (height > 1) ? (height >> 1) : 1; + const size_t nwidth = (width > 1) ? (width >> 1) : 1; + const size_t nheight = (height > 1) ? (height >> 1) : 1; - size_t xinc = (width << 16) / nwidth; - size_t yinc = (height << 16) / nheight; + const size_t xinc = (width << 16) / nwidth; + const size_t yinc = (height << 16) / nheight; size_t lasty = size_t(-1); @@ -1738,13 +1738,13 @@ namespace const uint8_t* pSrc = src->pixels; uint8_t* pDest = dest->pixels; - size_t rowPitch = src->rowPitch; + const size_t rowPitch = src->rowPitch; - size_t nwidth = (width > 1) ? (width >> 1) : 1; - size_t nheight = (height > 1) ? (height >> 1) : 1; + const size_t nwidth = (width > 1) ? (width >> 1) : 1; + const size_t nheight = (height > 1) ? (height >> 1) : 1; - size_t xinc = (width << 16) / nwidth; - size_t yinc = (height << 16) / nheight; + const size_t xinc = (width << 16) / nwidth; + const size_t yinc = (height << 16) / nheight; size_t lasty = size_t(-1); @@ -1842,12 +1842,12 @@ namespace if (depth > 1) { // 3D box filter - size_t ndepth = depth >> 1; + const size_t ndepth = depth >> 1; for (size_t slice = 0; slice < ndepth; ++slice) { - size_t slicea = std::min(slice * 2, depth - 1); - size_t sliceb = std::min(slicea + 1, depth - 1); + const size_t slicea = std::min(slice * 2, depth - 1); + const size_t sliceb = std::min(slicea + 1, depth - 1); const Image* srca = mipChain.GetImage(level - 1, 0, slicea); const Image* srcb = mipChain.GetImage(level - 1, 0, sliceb); @@ -1860,11 +1860,11 @@ namespace const uint8_t* pSrc2 = srcb->pixels; uint8_t* pDest = dest->pixels; - size_t aRowPitch = srca->rowPitch; - size_t bRowPitch = srcb->rowPitch; + const size_t aRowPitch = srca->rowPitch; + const size_t bRowPitch = srcb->rowPitch; - size_t nwidth = (width > 1) ? (width >> 1) : 1; - size_t nheight = (height > 1) ? (height >> 1) : 1; + const size_t nwidth = (width > 1) ? (width >> 1) : 1; + const size_t nheight = (height > 1) ? (height >> 1) : 1; for (size_t y = 0; y < nheight; ++y) { @@ -1892,7 +1892,7 @@ namespace for (size_t x = 0; x < nwidth; ++x) { - size_t x2 = x << 1; + const size_t x2 = x << 1; AVERAGE8(target[x], urow0[x2], urow1[x2], urow2[x2], urow3[x2], vrow0[x2], vrow1[x2], vrow2[x2], vrow3[x2]) @@ -1916,10 +1916,10 @@ namespace const uint8_t* pSrc = src->pixels; uint8_t* pDest = dest->pixels; - size_t rowPitch = src->rowPitch; + const size_t rowPitch = src->rowPitch; - size_t nwidth = (width > 1) ? (width >> 1) : 1; - size_t nheight = (height > 1) ? (height >> 1) : 1; + const size_t nwidth = (width > 1) ? (width >> 1) : 1; + const size_t nheight = (height > 1) ? (height >> 1) : 1; for (size_t y = 0; y < nheight; ++y) { @@ -1936,7 +1936,7 @@ namespace for (size_t x = 0; x < nwidth; ++x) { - size_t x2 = x << 1; + const size_t x2 = x << 1; AVERAGE4(target[x], urow0[x2], urow1[x2], urow2[x2], urow3[x2]) } @@ -1999,10 +1999,10 @@ namespace // Resize base image to each target mip level for (size_t level = 1; level < levels; ++level) { - size_t nwidth = (width > 1) ? (width >> 1) : 1; + const size_t nwidth = (width > 1) ? (width >> 1) : 1; CreateLinearFilter(width, nwidth, (filter & TEX_FILTER_WRAP_U) != 0, lfX); - size_t nheight = (height > 1) ? (height >> 1) : 1; + const size_t nheight = (height > 1) ? (height >> 1) : 1; CreateLinearFilter(height, nheight, (filter & TEX_FILTER_WRAP_V) != 0, lfY); #ifdef _DEBUG @@ -2015,12 +2015,12 @@ namespace if (depth > 1) { // 3D linear filter - size_t ndepth = depth >> 1; + const size_t ndepth = depth >> 1; CreateLinearFilter(depth, ndepth, (filter & TEX_FILTER_WRAP_W) != 0, lfZ); for (size_t slice = 0; slice < ndepth; ++slice) { - auto& toZ = lfZ[slice]; + auto const& toZ = lfZ[slice]; const Image* srca = mipChain.GetImage(level - 1, 0, toZ.u0); const Image* srcb = mipChain.GetImage(level - 1, 0, toZ.u1); @@ -2038,7 +2038,7 @@ namespace for (size_t y = 0; y < nheight; ++y) { - auto& toY = lfY[y]; + auto const& toY = lfY[y]; if (toY.u0 != u0) { @@ -2071,7 +2071,7 @@ namespace for (size_t x = 0; x < nwidth; ++x) { - auto& toX = lfX[x]; + auto const& toX = lfX[x]; TRILINEAR_INTERPOLATE(target[x], toX, toY, toZ, urow0, urow1, vrow0, vrow1) } @@ -2094,14 +2094,14 @@ namespace const uint8_t* pSrc = src->pixels; uint8_t* pDest = dest->pixels; - size_t rowPitch = src->rowPitch; + const size_t rowPitch = src->rowPitch; size_t u0 = size_t(-1); size_t u1 = size_t(-1); for (size_t y = 0; y < nheight; ++y) { - auto& toY = lfY[y]; + auto const& toY = lfY[y]; if (toY.u0 != u0) { @@ -2131,7 +2131,7 @@ namespace for (size_t x = 0; x < nwidth; ++x) { - auto& toX = lfX[x]; + auto const& toX = lfX[x]; BILINEAR_INTERPOLATE(target[x], toX, toY, urow0, urow1) } @@ -2203,10 +2203,10 @@ namespace // Resize base image to each target mip level for (size_t level = 1; level < levels; ++level) { - size_t nwidth = (width > 1) ? (width >> 1) : 1; + const size_t nwidth = (width > 1) ? (width >> 1) : 1; CreateCubicFilter(width, nwidth, (filter & TEX_FILTER_WRAP_U) != 0, (filter & TEX_FILTER_MIRROR_U) != 0, cfX); - size_t nheight = (height > 1) ? (height >> 1) : 1; + const size_t nheight = (height > 1) ? (height >> 1) : 1; CreateCubicFilter(height, nheight, (filter & TEX_FILTER_WRAP_V) != 0, (filter & TEX_FILTER_MIRROR_V) != 0, cfY); #ifdef _DEBUG @@ -2222,12 +2222,12 @@ namespace if (depth > 1) { // 3D cubic filter - size_t ndepth = depth >> 1; + const size_t ndepth = depth >> 1; CreateCubicFilter(depth, ndepth, (filter & TEX_FILTER_WRAP_W) != 0, (filter & TEX_FILTER_MIRROR_W) != 0, cfZ); for (size_t slice = 0; slice < ndepth; ++slice) { - auto& toZ = cfZ[slice]; + auto const& toZ = cfZ[slice]; const Image* srca = mipChain.GetImage(level - 1, 0, toZ.u0); const Image* srcb = mipChain.GetImage(level - 1, 0, toZ.u1); @@ -2249,7 +2249,7 @@ namespace for (size_t y = 0; y < nheight; ++y) { - auto& toY = cfY[y]; + auto const& toY = cfY[y]; // Scanline 1 if (toY.u0 != u0) @@ -2370,7 +2370,7 @@ namespace for (size_t x = 0; x < nwidth; ++x) { - auto& toX = cfX[x]; + auto const& toX = cfX[x]; XMVECTOR D[4]; @@ -2406,7 +2406,7 @@ namespace const uint8_t* pSrc = src->pixels; uint8_t* pDest = dest->pixels; - size_t rowPitch = src->rowPitch; + const size_t rowPitch = src->rowPitch; size_t u0 = size_t(-1); size_t u1 = size_t(-1); @@ -2415,7 +2415,7 @@ namespace for (size_t y = 0; y < nheight; ++y) { - auto& toY = cfY[y]; + auto const& toY = cfY[y]; // Scanline 1 if (toY.u0 != u0) @@ -2506,7 +2506,7 @@ namespace for (size_t x = 0; x < nwidth; ++x) { - auto& toX = cfX[x]; + auto const& toX = cfX[x]; XMVECTOR C0, C1, C2, C3; CUBIC_INTERPOLATE(C0, toX.x, urow[0][toX.u0], urow[0][toX.u1], urow[0][toX.u2], urow[0][toX.u3]) @@ -2570,17 +2570,17 @@ namespace // Resize base image to each target mip level for (size_t level = 1; level < levels; ++level) { - size_t nwidth = (width > 1) ? (width >> 1) : 1; + const size_t nwidth = (width > 1) ? (width >> 1) : 1; HRESULT hr = CreateTriangleFilter(width, nwidth, (filter & TEX_FILTER_WRAP_U) != 0, tfX); if (FAILED(hr)) return hr; - size_t nheight = (height > 1) ? (height >> 1) : 1; + const size_t nheight = (height > 1) ? (height >> 1) : 1; hr = CreateTriangleFilter(height, nheight, (filter & TEX_FILTER_WRAP_V) != 0, tfY); if (FAILED(hr)) return hr; - size_t ndepth = (depth > 1) ? (depth >> 1) : 1; + const size_t ndepth = (depth > 1) ? (depth >> 1) : 1; hr = CreateTriangleFilter(depth, ndepth, (filter & TEX_FILTER_WRAP_W) != 0, tfZ); if (FAILED(hr)) return hr; @@ -2598,7 +2598,7 @@ namespace { for (size_t j = 0; j < zFrom->count; ++j) { - size_t w = zFrom->to[j].u; + const size_t w = zFrom->to[j].u; assert(w < ndepth); TriangleRow* sliceAcc = &sliceActive[w]; @@ -2620,7 +2620,7 @@ namespace // Create accumulation slices as needed for (size_t j = 0; j < zFrom->count; ++j) { - size_t w = zFrom->to[j].u; + const size_t w = zFrom->to[j].u; assert(w < ndepth); TriangleRow* sliceAcc = &sliceActive[w]; @@ -2652,7 +2652,7 @@ namespace return E_POINTER; const uint8_t* pSrc = src->pixels; - size_t rowPitch = src->rowPitch; + const size_t rowPitch = src->rowPitch; const uint8_t* pEndSrc = pSrc + rowPitch * height; for (FilterFrom* yFrom = tfY->from; yFrom < yFromEnd; ) @@ -2672,9 +2672,9 @@ namespace { for (size_t j = 0; j < zFrom->count; ++j) { - size_t w = zFrom->to[j].u; + const size_t w = zFrom->to[j].u; assert(w < ndepth); - float zweight = zFrom->to[j].weight; + const float zweight = zFrom->to[j].weight; XMVECTOR* accSlice = sliceActive[w].scanline.get(); if (!accSlice) @@ -2684,7 +2684,7 @@ namespace { size_t v = yFrom->to[k].u; assert(v < nheight); - float yweight = yFrom->to[k].weight; + const float yweight = yFrom->to[k].weight; XMVECTOR * accPtr = accSlice + v * nwidth; @@ -2693,7 +2693,7 @@ namespace size_t u = xFrom->to[l].u; assert(u < nwidth); - XMVECTOR weight = XMVectorReplicate(zweight * yweight * xFrom->to[l].weight); + const XMVECTOR weight = XMVectorReplicate(zweight * yweight * xFrom->to[l].weight); assert(x < width); accPtr[u] = XMVectorMultiplyAdd(row[x], weight, accPtr[u]); @@ -2710,7 +2710,7 @@ namespace // Write completed accumulation slices for (size_t j = 0; j < zFrom->count; ++j) { - size_t w = zFrom->to[j].u; + const size_t w = zFrom->to[j].u; assert(w < ndepth); TriangleRow* sliceAcc = &sliceActive[w]; @@ -2821,13 +2821,13 @@ HRESULT DirectX::GenerateMipMaps( bool usewic = UseWICFiltering(baseImage.format, filter); WICPixelFormatGUID pfGUID = {}; - bool wicpf = (usewic) ? DXGIToWIC(baseImage.format, pfGUID, true) : false; + const bool wicpf = (usewic) ? DXGIToWIC(baseImage.format, pfGUID, true) : false; if (usewic && !wicpf) { // Check to see if the source and/or result size is too big for WIC - uint64_t expandedSize = uint64_t(std::max(1, baseImage.width >> 1)) * uint64_t(std::max(1, baseImage.height >> 1)) * sizeof(float) * 4; - uint64_t expandedSize2 = uint64_t(baseImage.width) * uint64_t(baseImage.height) * sizeof(float) * 4; + const uint64_t expandedSize = uint64_t(std::max(1, baseImage.width >> 1)) * uint64_t(std::max(1, baseImage.height >> 1)) * sizeof(float) * 4; + const uint64_t expandedSize2 = uint64_t(baseImage.width) * uint64_t(baseImage.height) * sizeof(float) * 4; if (expandedSize > UINT32_MAX || expandedSize2 > UINT32_MAX) { if (filter & TEX_FILTER_FORCE_WIC) @@ -3006,7 +3006,7 @@ HRESULT DirectX::GenerateMipMaps( baseImages.reserve(metadata.arraySize); for (size_t item = 0; item < metadata.arraySize; ++item) { - size_t index = metadata.ComputeIndex(0, item, 0); + const size_t index = metadata.ComputeIndex(0, item, 0); if (index >= nimages) return E_FAIL; @@ -3036,13 +3036,13 @@ HRESULT DirectX::GenerateMipMaps( bool usewic = !metadata.IsPMAlpha() && UseWICFiltering(metadata.format, filter); WICPixelFormatGUID pfGUID = {}; - bool wicpf = (usewic) ? DXGIToWIC(metadata.format, pfGUID, true) : false; + const bool wicpf = (usewic) ? DXGIToWIC(metadata.format, pfGUID, true) : false; if (usewic && !wicpf) { // Check to see if the source and/or result size is too big for WIC - uint64_t expandedSize = uint64_t(std::max(1, metadata.width >> 1)) * uint64_t(std::max(1, metadata.height >> 1)) * sizeof(float) * 4; - uint64_t expandedSize2 = uint64_t(metadata.width) * uint64_t(metadata.height) * sizeof(float) * 4; + const uint64_t expandedSize = uint64_t(std::max(1, metadata.width >> 1)) * uint64_t(std::max(1, metadata.height >> 1)) * sizeof(float) * 4; + const uint64_t expandedSize2 = uint64_t(metadata.width) * uint64_t(metadata.height) * sizeof(float) * 4; if (expandedSize > UINT32_MAX || expandedSize2 > UINT32_MAX) { if (filter & TEX_FILTER_FORCE_WIC) @@ -3228,9 +3228,9 @@ HRESULT DirectX::GenerateMipMaps3D( if (filter & TEX_FILTER_FORCE_WIC) return HRESULT_E_NOT_SUPPORTED; - DXGI_FORMAT format = baseImages[0].format; - size_t width = baseImages[0].width; - size_t height = baseImages[0].height; + const DXGI_FORMAT format = baseImages[0].format; + const size_t width = baseImages[0].width; + const size_t height = baseImages[0].height; if (!CalculateMipLevels3D(width, height, depth, levels)) return E_INVALIDARG; @@ -3350,7 +3350,7 @@ HRESULT DirectX::GenerateMipMaps3D( baseImages.reserve(metadata.depth); for (size_t slice = 0; slice < metadata.depth; ++slice) { - size_t index = metadata.ComputeIndex(0, 0, slice); + const size_t index = metadata.ComputeIndex(0, 0, slice); if (index >= nimages) return E_FAIL; @@ -3477,10 +3477,10 @@ HRESULT DirectX::ScaleMipMapsAlphaForCoverage( return E_POINTER; const uint8_t *pSrc = src.pixels; - size_t rowPitch = src.rowPitch; + const size_t rowPitch = src.rowPitch; for (size_t h = 0; h < metadata.height; ++h) { - size_t msize = std::min(dest->rowPitch, rowPitch); + const size_t msize = std::min(dest->rowPitch, rowPitch); memcpy(pDest, pSrc, msize); pSrc += rowPitch; pDest += dest->rowPitch; diff --git a/DirectXTex/DirectXTexMisc.cpp b/DirectXTex/DirectXTexMisc.cpp index ec48601..053ad96 100644 --- a/DirectXTex/DirectXTexMisc.cpp +++ b/DirectXTex/DirectXTexMisc.cpp @@ -158,8 +158,8 @@ namespace } // MSE = sum[ (I1 - I2)^2 ] / w*h - XMVECTOR d = XMVectorReplicate(float(image1.width * image1.height)); - XMVECTOR v = XMVectorDivide(acc, d); + const XMVECTOR d = XMVectorReplicate(float(image1.width * image1.height)); + const XMVECTOR v = XMVectorDivide(acc, d); if (mseV) { XMStoreFloat4(reinterpret_cast(mseV), v); @@ -178,7 +178,7 @@ namespace //------------------------------------------------------------------------------------- HRESULT EvaluateImage_( const Image& image, - std::function& pixelFunc) + const std::function& pixelFunc) { if (!pixelFunc) return E_INVALIDARG; @@ -214,7 +214,7 @@ namespace //------------------------------------------------------------------------------------- HRESULT TransformImage_( const Image& srcImage, - std::function& pixelFunc, + const std::function& pixelFunc, const Image& destImage) { if (!pixelFunc) diff --git a/DirectXTex/DirectXTexNormalMaps.cpp b/DirectXTex/DirectXTexNormalMaps.cpp index 11603d3..48bf826 100644 --- a/DirectXTex/DirectXTexNormalMaps.cpp +++ b/DirectXTex/DirectXTexNormalMaps.cpp @@ -35,7 +35,7 @@ namespace case CNMAP_CHANNEL_LUMINANCE: { - XMVECTOR v = XMVectorMultiply(val, lScale); + const XMVECTOR v = XMVectorMultiply(val, lScale); XMStoreFloat4A(&f, v); return f.x + f.y + f.z; } @@ -173,15 +173,15 @@ namespace { // Compute normal via central differencing float totDelta = (val0[x] - val0[x + 2]) + (val1[x] - val1[x + 2]) + (val2[x] - val2[x + 2]); - float deltaZX = totDelta * amplitude / 6.f; + const float deltaZX = totDelta * amplitude / 6.f; totDelta = (val0[x] - val2[x]) + (val0[x + 1] - val2[x + 1]) + (val0[x + 2] - val2[x + 2]); - float deltaZY = totDelta * amplitude / 6.f; + const float deltaZY = totDelta * amplitude / 6.f; - XMVECTOR vx = XMVectorSetZ(g_XMNegIdentityR0, deltaZX); // (-1.0f, 0.0f, deltaZX) - XMVECTOR vy = XMVectorSetZ(g_XMNegIdentityR1, deltaZY); // (0.0f, -1.0f, deltaZY) + const XMVECTOR vx = XMVectorSetZ(g_XMNegIdentityR0, deltaZX); // (-1.0f, 0.0f, deltaZX) + const XMVECTOR vy = XMVectorSetZ(g_XMNegIdentityR1, deltaZY); // (0.0f, -1.0f, deltaZY) - XMVECTOR normal = XMVector3Normalize(XMVector3Cross(vx, vy)); + const XMVECTOR normal = XMVector3Normalize(XMVector3Cross(vx, vy)); // Compute alpha (1.0 or an occlusion term) float alpha = 1.f; @@ -189,7 +189,7 @@ namespace if (flags & CNMAP_COMPUTE_OCCLUSION) { float delta = 0.f; - float c = val1[x + 1]; + const float c = val1[x + 1]; float t = val0[x] - c; if (t > 0.f) delta += t; t = val0[x + 1] - c; if (t > 0.f) delta += t; @@ -206,7 +206,7 @@ namespace if (delta > 0.f) { // If < 0, then no occlusion - float r = sqrtf(1.f + delta*delta); + const float r = sqrtf(1.f + delta*delta); alpha = (r - delta) / r; } } @@ -215,7 +215,7 @@ namespace if (convFlags & CONVF_UNORM) { // 0.5f*normal + 0.5f -or- invert sign case: -0.5f*normal + 0.5f - XMVECTOR n1 = XMVectorMultiplyAdd((flags & CNMAP_INVERT_SIGN) ? g_XMNegativeOneHalf : g_XMOneHalf, normal, g_XMOneHalf); + const XMVECTOR n1 = XMVectorMultiplyAdd((flags & CNMAP_INVERT_SIGN) ? g_XMNegativeOneHalf : g_XMOneHalf, normal, g_XMOneHalf); *dptr++ = XMVectorSetW(n1, alpha); } else if (flags & CNMAP_INVERT_SIGN) diff --git a/DirectXTex/DirectXTexPMAlpha.cpp b/DirectXTex/DirectXTexPMAlpha.cpp index 4f02142..059af95 100644 --- a/DirectXTex/DirectXTexPMAlpha.cpp +++ b/DirectXTex/DirectXTexPMAlpha.cpp @@ -16,7 +16,7 @@ using namespace DirectX::Internal; namespace { - inline TEX_FILTER_FLAGS GetSRGBFlags(_In_ TEX_PMALPHA_FLAGS compress) noexcept + constexpr TEX_FILTER_FLAGS GetSRGBFlags(_In_ TEX_PMALPHA_FLAGS compress) noexcept { static_assert(TEX_FILTER_SRGB_IN == 0x1000000, "TEX_FILTER_SRGB flag values don't match TEX_FILTER_SRGB_MASK"); static_assert(static_cast(TEX_PMALPHA_SRGB_IN) == static_cast(TEX_FILTER_SRGB_IN), "TEX_PMALPHA_SRGB* should match TEX_FILTER_SRGB*"); @@ -49,7 +49,7 @@ namespace XMVECTOR* ptr = scanline.get(); for (size_t w = 0; w < srcImage.width; ++w) { - XMVECTOR v = *ptr; + const XMVECTOR v = *ptr; XMVECTOR alpha = XMVectorSplatW(*ptr); alpha = XMVectorMultiply(v, alpha); *(ptr++) = XMVectorSelect(v, alpha, g_XMSelect1110); @@ -84,7 +84,7 @@ namespace if (!pSrc || !pDest) return E_POINTER; - TEX_FILTER_FLAGS filter = GetSRGBFlags(flags); + const TEX_FILTER_FLAGS filter = GetSRGBFlags(flags); for (size_t h = 0; h < srcImage.height; ++h) { @@ -94,7 +94,7 @@ namespace XMVECTOR* ptr = scanline.get(); for (size_t w = 0; w < srcImage.width; ++w) { - XMVECTOR v = *ptr; + const XMVECTOR v = *ptr; XMVECTOR alpha = XMVectorSplatW(*ptr); alpha = XMVectorMultiply(v, alpha); *(ptr++) = XMVectorSelect(v, alpha, g_XMSelect1110); @@ -134,7 +134,7 @@ namespace XMVECTOR* ptr = scanline.get(); for (size_t w = 0; w < srcImage.width; ++w) { - XMVECTOR v = *ptr; + const XMVECTOR v = *ptr; XMVECTOR alpha = XMVectorSplatW(*ptr); if (XMVectorGetX(alpha) > 0) { @@ -172,7 +172,7 @@ namespace if (!pSrc || !pDest) return E_POINTER; - TEX_FILTER_FLAGS filter = GetSRGBFlags(flags); + const TEX_FILTER_FLAGS filter = GetSRGBFlags(flags); for (size_t h = 0; h < srcImage.height; ++h) { @@ -182,7 +182,7 @@ namespace XMVECTOR* ptr = scanline.get(); for (size_t w = 0; w < srcImage.width; ++w) { - XMVECTOR v = *ptr; + const XMVECTOR v = *ptr; XMVECTOR alpha = XMVectorSplatW(*ptr); if (XMVectorGetX(alpha) > 0) { diff --git a/DirectXTex/DirectXTexResize.cpp b/DirectXTex/DirectXTexResize.cpp index 6dde72b..23b21f4 100644 --- a/DirectXTex/DirectXTexResize.cpp +++ b/DirectXTex/DirectXTexResize.cpp @@ -265,10 +265,10 @@ namespace const uint8_t* pSrc = srcImage.pixels; uint8_t* pDest = destImage.pixels; - size_t rowPitch = srcImage.rowPitch; + const size_t rowPitch = srcImage.rowPitch; - size_t xinc = (srcImage.width << 16) / destImage.width; - size_t yinc = (srcImage.height << 16) / destImage.height; + const size_t xinc = (srcImage.width << 16) / destImage.width; + const size_t yinc = (srcImage.height << 16) / destImage.height; size_t lasty = size_t(-1); @@ -332,7 +332,7 @@ namespace const uint8_t* pSrc = srcImage.pixels; uint8_t* pDest = destImage.pixels; - size_t rowPitch = srcImage.rowPitch; + const size_t rowPitch = srcImage.rowPitch; for (size_t y = 0; y < destImage.height; ++y) { @@ -349,7 +349,7 @@ namespace for (size_t x = 0; x < destImage.width; ++x) { - size_t x2 = x << 1; + const size_t x2 = x << 1; AVERAGE4(target[x], urow0[x2], urow1[x2], urow2[x2], urow3[x2]) } @@ -399,14 +399,14 @@ namespace const uint8_t* pSrc = srcImage.pixels; uint8_t* pDest = destImage.pixels; - size_t rowPitch = srcImage.rowPitch; + const size_t rowPitch = srcImage.rowPitch; size_t u0 = size_t(-1); size_t u1 = size_t(-1); for (size_t y = 0; y < destImage.height; ++y) { - auto& toY = lfY[y]; + auto const& toY = lfY[y]; if (toY.u0 != u0) { @@ -436,7 +436,7 @@ namespace for (size_t x = 0; x < destImage.width; ++x) { - auto& toX = lfX[x]; + auto const& toX = lfX[x]; BILINEAR_INTERPOLATE(target[x], toX, toY, row0, row1) } @@ -490,7 +490,7 @@ namespace const uint8_t* pSrc = srcImage.pixels; uint8_t* pDest = destImage.pixels; - size_t rowPitch = srcImage.rowPitch; + const size_t rowPitch = srcImage.rowPitch; size_t u0 = size_t(-1); size_t u1 = size_t(-1); @@ -499,7 +499,7 @@ namespace for (size_t y = 0; y < destImage.height; ++y) { - auto& toY = cfY[y]; + auto const& toY = cfY[y]; // Scanline 1 if (toY.u0 != u0) @@ -590,7 +590,7 @@ namespace for (size_t x = 0; x < destImage.width; ++x) { - auto& toX = cfX[x]; + auto const& toX = cfX[x]; XMVECTOR C0, C1, C2, C3; @@ -654,7 +654,7 @@ namespace { for (size_t j = 0; j < yFrom->count; ++j) { - size_t v = yFrom->to[j].u; + const size_t v = yFrom->to[j].u; assert(v < destImage.height); ++rowActive[v].remaining; } @@ -664,7 +664,7 @@ namespace // Filter image const uint8_t* pSrc = srcImage.pixels; - size_t rowPitch = srcImage.rowPitch; + const size_t rowPitch = srcImage.rowPitch; const uint8_t* pEndSrc = pSrc + rowPitch * srcImage.height; uint8_t* pDest = destImage.pixels; @@ -674,7 +674,7 @@ namespace // Create accumulation rows as needed for (size_t j = 0; j < yFrom->count; ++j) { - size_t v = yFrom->to[j].u; + const size_t v = yFrom->to[j].u; assert(v < destImage.height); TriangleRow* rowAcc = &rowActive[v]; @@ -714,9 +714,9 @@ namespace { for (size_t j = 0; j < yFrom->count; ++j) { - size_t v = yFrom->to[j].u; + const size_t v = yFrom->to[j].u; assert(v < destImage.height); - float yweight = yFrom->to[j].weight; + const float yweight = yFrom->to[j].weight; XMVECTOR* accPtr = rowActive[v].scanline.get(); if (!accPtr) @@ -727,7 +727,7 @@ namespace size_t u = xFrom->to[k].u; assert(u < destImage.width); - XMVECTOR weight = XMVectorReplicate(yweight * xFrom->to[k].weight); + const XMVECTOR weight = XMVectorReplicate(yweight * xFrom->to[k].weight); assert(x < srcImage.width); accPtr[u] = XMVectorMultiplyAdd(row[x], weight, accPtr[u]); @@ -868,13 +868,13 @@ HRESULT DirectX::Resize( bool usewic = UseWICFiltering(srcImage.format, filter); WICPixelFormatGUID pfGUID = {}; - bool wicpf = (usewic) ? DXGIToWIC(srcImage.format, pfGUID, true) : false; + const bool wicpf = (usewic) ? DXGIToWIC(srcImage.format, pfGUID, true) : false; if (usewic && !wicpf) { // Check to see if the source and/or result size is too big for WIC - uint64_t expandedSize = uint64_t(width) * uint64_t(height) * sizeof(float) * 4; - uint64_t expandedSize2 = uint64_t(srcImage.width) * uint64_t(srcImage.height) * sizeof(float) * 4; + const uint64_t expandedSize = uint64_t(width) * uint64_t(height) * sizeof(float) * 4; + const uint64_t expandedSize2 = uint64_t(srcImage.width) * uint64_t(srcImage.height) * sizeof(float) * 4; if (expandedSize > UINT32_MAX || expandedSize2 > UINT32_MAX) { if (filter & TEX_FILTER_FORCE_WIC) @@ -955,13 +955,13 @@ HRESULT DirectX::Resize( bool usewic = !metadata.IsPMAlpha() && UseWICFiltering(metadata.format, filter); WICPixelFormatGUID pfGUID = {}; - bool wicpf = (usewic) ? DXGIToWIC(metadata.format, pfGUID, true) : false; + const bool wicpf = (usewic) ? DXGIToWIC(metadata.format, pfGUID, true) : false; if (usewic && !wicpf) { // Check to see if the source and/or result size is too big for WIC - uint64_t expandedSize = uint64_t(width) * uint64_t(height) * sizeof(float) * 4; - uint64_t expandedSize2 = uint64_t(metadata.width) * uint64_t(metadata.height) * sizeof(float) * 4; + const uint64_t expandedSize = uint64_t(width) * uint64_t(height) * sizeof(float) * 4; + const uint64_t expandedSize2 = uint64_t(metadata.width) * uint64_t(metadata.height) * sizeof(float) * 4; if (expandedSize > UINT32_MAX || expandedSize2 > UINT32_MAX) { if (filter & TEX_FILTER_FORCE_WIC) @@ -980,7 +980,7 @@ HRESULT DirectX::Resize( for (size_t item = 0; item < metadata.arraySize; ++item) { - size_t srcIndex = metadata.ComputeIndex(0, item, 0); + const size_t srcIndex = metadata.ComputeIndex(0, item, 0); if (srcIndex >= nimages) { result.Release(); @@ -1041,7 +1041,7 @@ HRESULT DirectX::Resize( for (size_t slice = 0; slice < metadata.depth; ++slice) { - size_t srcIndex = metadata.ComputeIndex(0, 0, slice); + const size_t srcIndex = metadata.ComputeIndex(0, 0, slice); if (srcIndex >= nimages) { result.Release(); diff --git a/DirectXTex/DirectXTexTGA.cpp b/DirectXTex/DirectXTexTGA.cpp index 4ea5b32..07b20b9 100644 --- a/DirectXTex/DirectXTexTGA.cpp +++ b/DirectXTex/DirectXTexTGA.cpp @@ -403,7 +403,7 @@ namespace auto t = static_cast(uint32_t(*sPtr) | uint32_t(*(sPtr + 1u) << 8)); - uint32_t alpha = (t & 0x8000) ? 255 : 0; + const uint32_t alpha = (t & 0x8000) ? 255 : 0; minalpha = std::min(minalpha, alpha); maxalpha = std::max(maxalpha, alpha); @@ -438,7 +438,7 @@ namespace auto t = static_cast(uint32_t(*sPtr) | uint32_t(*(sPtr + 1u) << 8)); - uint32_t alpha = (t & 0x8000) ? 255 : 0; + const uint32_t alpha = (t & 0x8000) ? 255 : 0; minalpha = std::min(minalpha, alpha); maxalpha = std::max(maxalpha, alpha); @@ -516,7 +516,7 @@ namespace return E_FAIL; // BGRA -> RGBA - uint32_t alpha = *(sPtr + 3); + const uint32_t alpha = *(sPtr + 3); t = uint32_t(*sPtr << 16) | uint32_t(*(sPtr + 1) << 8) | uint32_t(*(sPtr + 2)) | uint32_t(alpha << 24); minalpha = std::min(minalpha, alpha); @@ -646,7 +646,7 @@ namespace if (sPtr + 3 >= endPtr) return E_FAIL; - uint32_t alpha = *(sPtr + 3); + const uint32_t alpha = *(sPtr + 3); auto t = *reinterpret_cast(sPtr); @@ -687,7 +687,7 @@ namespace if (sPtr + 3 >= endPtr) return E_FAIL; - uint32_t alpha = *(sPtr + 3); + const uint32_t alpha = *(sPtr + 3); *dPtr = *reinterpret_cast(sPtr); minalpha = std::min(minalpha, alpha); @@ -885,7 +885,7 @@ namespace sPtr += 2; *dPtr = t; - uint32_t alpha = (t & 0x8000) ? 255 : 0; + const uint32_t alpha = (t & 0x8000) ? 255 : 0; minalpha = std::min(minalpha, alpha); maxalpha = std::max(maxalpha, alpha); @@ -1002,7 +1002,7 @@ namespace if (sPtr + 3 >= endPtr) return E_FAIL; - uint32_t alpha = *(sPtr + 3); + const uint32_t alpha = *(sPtr + 3); *dPtr = *reinterpret_cast(sPtr); minalpha = std::min(minalpha, alpha); @@ -1184,7 +1184,7 @@ namespace ext->wVersionNumber = DIRECTX_TEX_VERSION; ext->bVersionLetter = ' '; - bool sRGB = ((flags & TGA_FLAGS_FORCE_LINEAR) == 0) && ((flags & TGA_FLAGS_FORCE_SRGB) != 0 || IsSRGB(metadata.format)); + const bool sRGB = ((flags & TGA_FLAGS_FORCE_LINEAR) == 0) && ((flags & TGA_FLAGS_FORCE_SRGB) != 0 || IsSRGB(metadata.format)); if (sRGB) { ext->wGammaNumerator = 22; @@ -1265,7 +1265,7 @@ namespace if (ext && ext->wSize == sizeof(TGA_EXTENSION) && ext->wGammaDenominator != 0) { - float gamma = static_cast(ext->wGammaNumerator) / static_cast(ext->wGammaDenominator); + auto const gamma = static_cast(ext->wGammaNumerator) / static_cast(ext->wGammaDenominator); if (fabsf(gamma - 2.2f) < GAMMA_EPSILON || fabsf(gamma - 2.4f) < GAMMA_EPSILON) { sRGB = true; @@ -1368,7 +1368,7 @@ HRESULT DirectX::GetMetadataFromTGAFile(const wchar_t* szFile, TGA_FLAGS flags, return HRESULT_E_FILE_TOO_LARGE; } - size_t len = fileInfo.EndOfFile.LowPart; + const size_t len = fileInfo.EndOfFile.LowPart; #else // !WIN32 std::ifstream inFile(std::filesystem::path(szFile), std::ios::in | std::ios::binary | std::ios::ate); if (!inFile) @@ -1404,7 +1404,7 @@ HRESULT DirectX::GetMetadataFromTGAFile(const wchar_t* szFile, TGA_FLAGS flags, return HRESULT_FROM_WIN32(GetLastError()); } - auto headerLen = static_cast(bytesRead); + auto const headerLen = static_cast(bytesRead); #else inFile.read(reinterpret_cast(header), sizeof(TGA_HEADER)); if (!inFile) @@ -1453,7 +1453,7 @@ HRESULT DirectX::GetMetadataFromTGAFile(const wchar_t* szFile, TGA_FLAGS flags, && ((footer.dwExtensionOffset + sizeof(TGA_EXTENSION)) <= len)) { #ifdef WIN32 - LARGE_INTEGER filePos = { { static_cast(footer.dwExtensionOffset), 0 } }; + const LARGE_INTEGER filePos = { { static_cast(footer.dwExtensionOffset), 0 } }; if (SetFilePointerEx(hFile.get(), filePos, nullptr, FILE_BEGIN)) { if (ReadFile(hFile.get(), &extData, sizeof(TGA_EXTENSION), &bytesRead, nullptr) @@ -1516,7 +1516,7 @@ HRESULT DirectX::LoadFromTGAMemory( const void* pPixels = static_cast(pSource) + offset; - size_t remaining = size - offset; + const size_t remaining = size - offset; if (remaining == 0) return E_FAIL; @@ -1617,7 +1617,7 @@ HRESULT DirectX::LoadFromTGAFile( return HRESULT_E_FILE_TOO_LARGE; } - size_t len = fileInfo.EndOfFile.LowPart; + const size_t len = fileInfo.EndOfFile.LowPart; #else // !WIN32 std::ifstream inFile(std::filesystem::path(szFile), std::ios::in | std::ios::binary | std::ios::ate); if (!inFile) @@ -1653,7 +1653,7 @@ HRESULT DirectX::LoadFromTGAFile( return HRESULT_FROM_WIN32(GetLastError()); } - auto headerLen = static_cast(bytesRead); + auto const headerLen = static_cast(bytesRead); #else inFile.read(reinterpret_cast(header), sizeof(TGA_HEADER)); if (!inFile) @@ -1670,7 +1670,7 @@ HRESULT DirectX::LoadFromTGAFile( return hr; // Read the pixels - auto remaining = len - offset; + auto const remaining = len - offset; if (remaining == 0) return E_FAIL; @@ -1678,7 +1678,7 @@ HRESULT DirectX::LoadFromTGAFile( { #ifdef WIN32 // Skip past the id string - LARGE_INTEGER filePos = { { static_cast(offset), 0 } }; + const LARGE_INTEGER filePos = { { static_cast(offset), 0 } }; if (!SetFilePointerEx(hFile.get(), filePos, nullptr, FILE_BEGIN)) { return HRESULT_FROM_WIN32(GetLastError()); @@ -1766,7 +1766,7 @@ HRESULT DirectX::LoadFromTGAFile( for (size_t x = 0; x < img->width; ++x) { - uint32_t alpha = ((*sPtr & 0xFF000000) >> 24); + const uint32_t alpha = ((*sPtr & 0xFF000000) >> 24); minalpha = std::min(minalpha, alpha); maxalpha = std::max(maxalpha, alpha); @@ -1820,7 +1820,7 @@ HRESULT DirectX::LoadFromTGAFile( return E_POINTER; } - size_t rowPitch = img->rowPitch; + const size_t rowPitch = img->rowPitch; for (size_t h = 0; h < img->height; ++h) { @@ -1828,7 +1828,7 @@ HRESULT DirectX::LoadFromTGAFile( for (size_t x = 0; x < img->width; ++x) { - uint32_t alpha = ((*sPtr & 0xFF000000) >> 24); + const uint32_t alpha = ((*sPtr & 0xFF000000) >> 24); minalpha = std::min(minalpha, alpha); maxalpha = std::max(maxalpha, alpha); @@ -1878,7 +1878,7 @@ HRESULT DirectX::LoadFromTGAFile( return E_POINTER; } - size_t rowPitch = img->rowPitch; + const size_t rowPitch = img->rowPitch; for (size_t h = 0; h < img->height; ++h) { @@ -1886,7 +1886,7 @@ HRESULT DirectX::LoadFromTGAFile( for (size_t x = 0; x < img->width; ++x) { - uint32_t alpha = (*sPtr & 0x8000) ? 255 : 0; + const uint32_t alpha = (*sPtr & 0x8000) ? 255 : 0; minalpha = std::min(minalpha, alpha); maxalpha = std::max(maxalpha, alpha); @@ -2012,7 +2012,7 @@ HRESULT DirectX::LoadFromTGAFile( && ((footer.dwExtensionOffset + sizeof(TGA_EXTENSION)) <= len)) { #ifdef WIN32 - LARGE_INTEGER filePos = { { static_cast(footer.dwExtensionOffset), 0 } }; + const LARGE_INTEGER filePos = { { static_cast(footer.dwExtensionOffset), 0 } }; if (SetFilePointerEx(hFile.get(), filePos, nullptr, FILE_BEGIN)) { if (ReadFile(hFile.get(), &extData, sizeof(TGA_EXTENSION), &bytesRead, nullptr) diff --git a/DirectXTex/DirectXTexUtil.cpp b/DirectXTex/DirectXTexUtil.cpp index d5dda83..2d033f7 100644 --- a/DirectXTex/DirectXTexUtil.cpp +++ b/DirectXTex/DirectXTexUtil.cpp @@ -901,15 +901,15 @@ HRESULT DirectX::ComputePitch(DXGI_FORMAT fmt, size_t width, size_t height, { if (flags & CP_FLAGS_BAD_DXTN_TAILS) { - size_t nbw = width >> 2; - size_t nbh = height >> 2; + const size_t nbw = width >> 2; + const size_t nbh = height >> 2; pitch = std::max(1u, uint64_t(nbw) * 8u); slice = std::max(1u, pitch * uint64_t(nbh)); } else { - uint64_t nbw = std::max(1u, (uint64_t(width) + 3u) / 4u); - uint64_t nbh = std::max(1u, (uint64_t(height) + 3u) / 4u); + const uint64_t nbw = std::max(1u, (uint64_t(width) + 3u) / 4u); + const uint64_t nbh = std::max(1u, (uint64_t(height) + 3u) / 4u); pitch = nbw * 8u; slice = pitch * nbh; } @@ -935,15 +935,15 @@ HRESULT DirectX::ComputePitch(DXGI_FORMAT fmt, size_t width, size_t height, { if (flags & CP_FLAGS_BAD_DXTN_TAILS) { - size_t nbw = width >> 2; - size_t nbh = height >> 2; + const size_t nbw = width >> 2; + const size_t nbh = height >> 2; pitch = std::max(1u, uint64_t(nbw) * 16u); slice = std::max(1u, pitch * uint64_t(nbh)); } else { - uint64_t nbw = std::max(1u, (uint64_t(width) + 3u) / 4u); - uint64_t nbh = std::max(1u, (uint64_t(height) + 3u) / 4u); + const uint64_t nbw = std::max(1u, (uint64_t(width) + 3u) / 4u); + const uint64_t nbh = std::max(1u, (uint64_t(height) + 3u) / 4u); pitch = nbw * 16u; slice = pitch * nbh; } diff --git a/DirectXTex/DirectXTexWIC.cpp b/DirectXTex/DirectXTexWIC.cpp index a1d9c54..1ea1fb7 100644 --- a/DirectXTex/DirectXTexWIC.cpp +++ b/DirectXTex/DirectXTexWIC.cpp @@ -237,7 +237,7 @@ namespace ULONG STDMETHODCALLTYPE Release() override { - ULONG res = InterlockedDecrement(&mRefCount); + const ULONG res = InterlockedDecrement(&mRefCount); if (res == 0) { delete this; @@ -252,7 +252,7 @@ namespace auto ptr = static_cast(mBlob.GetBufferPointer()); if (cb > maxRead) { - uint64_t pos = uint64_t(m_streamPosition) + uint64_t(maxRead); + const uint64_t pos = uint64_t(m_streamPosition) + uint64_t(maxRead); if (pos > UINT32_MAX) return HRESULT_E_ARITHMETIC_OVERFLOW; @@ -268,7 +268,7 @@ namespace } else { - uint64_t pos = uint64_t(m_streamPosition) + uint64_t(cb); + const uint64_t pos = uint64_t(m_streamPosition) + uint64_t(cb); if (pos > UINT32_MAX) return HRESULT_E_ARITHMETIC_OVERFLOW; @@ -286,8 +286,8 @@ namespace HRESULT STDMETHODCALLTYPE Write(void const* pv, ULONG cb, ULONG* pcbWritten) override { - size_t blobSize = mBlob.GetBufferSize(); - size_t spaceAvailable = blobSize - m_streamPosition; + const size_t blobSize = mBlob.GetBufferSize(); + const size_t spaceAvailable = blobSize - m_streamPosition; size_t growAmount = cb; if (spaceAvailable > 0) @@ -305,7 +305,7 @@ namespace if (growAmount > 0) { uint64_t newSize = uint64_t(blobSize); - uint64_t targetSize = uint64_t(blobSize) + growAmount; + const uint64_t targetSize = uint64_t(blobSize) + growAmount; HRESULT hr = ComputeGrowSize(newSize, targetSize); if (FAILED(hr)) return hr; @@ -315,7 +315,7 @@ namespace return hr; } - uint64_t pos = uint64_t(m_streamPosition) + uint64_t(cb); + const uint64_t pos = uint64_t(m_streamPosition) + uint64_t(cb); if (pos > UINT32_MAX) return HRESULT_E_ARITHMETIC_OVERFLOW; @@ -338,7 +338,7 @@ namespace if (size.HighPart > 0) return E_OUTOFMEMORY; - size_t blobSize = mBlob.GetBufferSize(); + const size_t blobSize = mBlob.GetBufferSize(); if (blobSize >= size.LowPart) { @@ -353,7 +353,7 @@ namespace else { uint64_t newSize = uint64_t(blobSize); - uint64_t targetSize = uint64_t(size.QuadPart); + const uint64_t targetSize = uint64_t(size.QuadPart); HRESULT hr = ComputeGrowSize(newSize, targetSize); if (FAILED(hr)) return hr; @@ -494,7 +494,7 @@ namespace size_t m_streamEOF; ULONG mRefCount; - static HRESULT ComputeGrowSize(uint64_t& newSize, uint64_t& targetSize) noexcept + static HRESULT ComputeGrowSize(uint64_t& newSize, const uint64_t targetSize) noexcept { // We grow by doubling until we hit 256MB, then we add 16MB at a time. while (newSize < targetSize) @@ -885,7 +885,7 @@ namespace PROPVARIANT value; PropVariantInit(&value); - bool sRGB = ((flags & WIC_FLAGS_FORCE_LINEAR) == 0) && ((flags & WIC_FLAGS_FORCE_SRGB) != 0 || IsSRGB(format)); + const bool sRGB = ((flags & WIC_FLAGS_FORCE_LINEAR) == 0) && ((flags & WIC_FLAGS_FORCE_SRGB) != 0 || IsSRGB(format)); value.vt = VT_LPSTR; value.pszVal = const_cast("DirectXTex"); diff --git a/DirectXTex/d3dx12.h b/DirectXTex/d3dx12.h index 623d0ef..e61d6f5 100644 --- a/DirectXTex/d3dx12.h +++ b/DirectXTex/d3dx12.h @@ -2101,8 +2101,8 @@ inline UINT64 UpdateSubresources( { for (UINT i = 0; i < NumSubresources; ++i) { - CD3DX12_TEXTURE_COPY_LOCATION Dst(pDestinationResource, i + FirstSubresource); - CD3DX12_TEXTURE_COPY_LOCATION Src(pIntermediate, pLayouts[i]); + const CD3DX12_TEXTURE_COPY_LOCATION Dst(pDestinationResource, i + FirstSubresource); + const CD3DX12_TEXTURE_COPY_LOCATION Src(pIntermediate, pLayouts[i]); pCmdList->CopyTextureRegion(&Dst, 0, 0, 0, &Src, nullptr); } } @@ -2160,8 +2160,8 @@ inline UINT64 UpdateSubresources( { for (UINT i = 0; i < NumSubresources; ++i) { - CD3DX12_TEXTURE_COPY_LOCATION Dst(pDestinationResource, i + FirstSubresource); - CD3DX12_TEXTURE_COPY_LOCATION Src(pIntermediate, pLayouts[i]); + const CD3DX12_TEXTURE_COPY_LOCATION Dst(pDestinationResource, i + FirstSubresource); + const CD3DX12_TEXTURE_COPY_LOCATION Src(pIntermediate, pLayouts[i]); pCmdList->CopyTextureRegion(&Dst, 0, 0, 0, &Src, nullptr); } } @@ -2404,7 +2404,7 @@ inline HRESULT D3DX12SerializeVersionedRootSignature( if (SUCCEEDED(hr)) { - CD3DX12_ROOT_SIGNATURE_DESC desc_1_0(desc_1_1.NumParameters, pParameters_1_0, desc_1_1.NumStaticSamplers, desc_1_1.pStaticSamplers, desc_1_1.Flags); + const CD3DX12_ROOT_SIGNATURE_DESC desc_1_0(desc_1_1.NumParameters, pParameters_1_0, desc_1_1.NumStaticSamplers, desc_1_1.pStaticSamplers, desc_1_1.Flags); hr = D3D12SerializeRootSignature(&desc_1_0, D3D_ROOT_SIGNATURE_VERSION_1, ppBlob, ppErrorBlob); } diff --git a/DirectXTex/filters.h b/DirectXTex/filters.h index 9732cfd..71b3b64 100644 --- a/DirectXTex/filters.h +++ b/DirectXTex/filters.h @@ -67,18 +67,18 @@ namespace DirectX assert(dest > 0); assert(lf != nullptr); - float scale = float(source) / float(dest); + const float scale = float(source) / float(dest); // Mirror is the same case as clamp for linear for (size_t u = 0; u < dest; ++u) { - float srcB = (float(u) + 0.5f) * scale + 0.5f; + const float srcB = (float(u) + 0.5f) * scale + 0.5f; ptrdiff_t isrcB = ptrdiff_t(srcB); ptrdiff_t isrcA = isrcB - 1; - float weight = 1.0f + float(isrcB) - srcB; + const float weight = 1.0f + float(isrcB) - srcB; if (isrcA < 0) { @@ -105,10 +105,10 @@ namespace DirectX #define TRILINEAR_INTERPOLATE( res, x, y, z, r0, r1, r2, r3 ) \ {\ - XMVECTOR a0 = XMVectorScale(XMVectorAdd(XMVectorScale((r0)[ x.u0 ], x.weight0 ), XMVectorScale((r0)[ x.u1 ], x.weight1)), y.weight0); \ - XMVECTOR a1 = XMVectorScale(XMVectorAdd(XMVectorScale((r1)[ x.u0 ], x.weight0 ), XMVectorScale((r1)[ x.u1 ], x.weight1)), y.weight1); \ - XMVECTOR a2 = XMVectorScale(XMVectorAdd(XMVectorScale((r2)[ x.u0 ], x.weight0 ), XMVectorScale((r2)[ x.u1 ], x.weight1)), y.weight0); \ - XMVECTOR a3 = XMVectorScale(XMVectorAdd(XMVectorScale((r3)[ x.u0 ], x.weight0 ), XMVectorScale((r3)[ x.u1 ], x.weight1)), y.weight1); \ + const XMVECTOR a0 = XMVectorScale(XMVectorAdd(XMVectorScale((r0)[ x.u0 ], x.weight0 ), XMVectorScale((r0)[ x.u1 ], x.weight1)), y.weight0); \ + const XMVECTOR a1 = XMVectorScale(XMVectorAdd(XMVectorScale((r1)[ x.u0 ], x.weight0 ), XMVectorScale((r1)[ x.u1 ], x.weight1)), y.weight1); \ + const XMVECTOR a2 = XMVectorScale(XMVectorAdd(XMVectorScale((r2)[ x.u0 ], x.weight0 ), XMVectorScale((r2)[ x.u1 ], x.weight1)), y.weight0); \ + const XMVECTOR a3 = XMVectorScale(XMVectorAdd(XMVectorScale((r3)[ x.u0 ], x.weight0 ), XMVectorScale((r3)[ x.u1 ], x.weight1)), y.weight1); \ res = XMVectorAdd(XMVectorScale(XMVectorAdd(a0, a1), z.weight0), XMVectorScale(XMVectorAdd(a2, a3), z.weight1)); \ } @@ -120,7 +120,7 @@ namespace DirectX XMGLOBALCONST XMVECTORF32 g_cubicSixth = { { { 1.f / 6.f, 1.f / 6.f, 1.f / 6.f, 1.f / 6.f } } }; XMGLOBALCONST XMVECTORF32 g_cubicHalf = { { { 1.f / 2.f, 1.f / 2.f, 1.f / 2.f, 1.f / 2.f } } }; - inline ptrdiff_t bounduvw(ptrdiff_t u, ptrdiff_t maxu, bool wrap, bool mirror) noexcept + constexpr ptrdiff_t bounduvw(ptrdiff_t u, ptrdiff_t maxu, bool wrap, bool mirror) noexcept { if (wrap) { @@ -167,16 +167,16 @@ namespace DirectX assert(dest > 0); assert(cf != nullptr); - float scale = float(source) / float(dest); + const float scale = float(source) / float(dest); for (size_t u = 0; u < dest; ++u) { - float srcB = (float(u) + 0.5f) * scale - 0.5f; + const float srcB = (float(u) + 0.5f) * scale - 0.5f; - ptrdiff_t isrcB = bounduvw(ptrdiff_t(srcB), ptrdiff_t(source) - 1, wrap, mirror); - ptrdiff_t isrcA = bounduvw(isrcB - 1, ptrdiff_t(source) - 1, wrap, mirror); - ptrdiff_t isrcC = bounduvw(isrcB + 1, ptrdiff_t(source) - 1, wrap, mirror); - ptrdiff_t isrcD = bounduvw(isrcB + 2, ptrdiff_t(source) - 1, wrap, mirror); + const ptrdiff_t isrcB = bounduvw(ptrdiff_t(srcB), ptrdiff_t(source) - 1, wrap, mirror); + const ptrdiff_t isrcA = bounduvw(isrcB - 1, ptrdiff_t(source) - 1, wrap, mirror); + const ptrdiff_t isrcC = bounduvw(isrcB + 1, ptrdiff_t(source) - 1, wrap, mirror); + const ptrdiff_t isrcD = bounduvw(isrcB + 2, ptrdiff_t(source) - 1, wrap, mirror); auto& entry = cf[u]; entry.u0 = size_t(isrcA); @@ -184,25 +184,25 @@ namespace DirectX entry.u2 = size_t(isrcC); entry.u3 = size_t(isrcD); - float x = srcB - float(isrcB); + const float x = srcB - float(isrcB); entry.x = x; } } #define CUBIC_INTERPOLATE( res, dx, p0, p1, p2, p3 ) \ { \ - XMVECTOR a0 = (p1); \ - XMVECTOR d0 = XMVectorSubtract(p0, a0); \ - XMVECTOR d2 = XMVectorSubtract(p2, a0); \ - XMVECTOR d3 = XMVectorSubtract(p3, a0); \ + const XMVECTOR a0 = (p1); \ + const XMVECTOR d0 = XMVectorSubtract(p0, a0); \ + const XMVECTOR d2 = XMVectorSubtract(p2, a0); \ + const XMVECTOR d3 = XMVectorSubtract(p3, a0); \ XMVECTOR a1 = XMVectorSubtract(d2, XMVectorMultiply(g_cubicThird, d0)); \ a1 = XMVectorSubtract(a1, XMVectorMultiply(g_cubicSixth, d3)); \ - XMVECTOR a2 = XMVectorAdd(XMVectorMultiply(g_cubicHalf, d0), XMVectorMultiply(g_cubicHalf, d2)); \ + const XMVECTOR a2 = XMVectorAdd(XMVectorMultiply(g_cubicHalf, d0), XMVectorMultiply(g_cubicHalf, d2)); \ XMVECTOR a3 = XMVectorSubtract(XMVectorMultiply(g_cubicSixth, d3), XMVectorMultiply(g_cubicSixth, d0)); \ a3 = XMVectorSubtract(a3, XMVectorMultiply(g_cubicHalf, d2)); \ - XMVECTOR vdx = XMVectorReplicate(dx); \ - XMVECTOR vdx2 = XMVectorMultiply(vdx, vdx); \ - XMVECTOR vdx3 = XMVectorMultiply(vdx2, vdx); \ + const XMVECTOR vdx = XMVectorReplicate(dx); \ + const XMVECTOR vdx2 = XMVectorMultiply(vdx, vdx); \ + const XMVECTOR vdx3 = XMVectorMultiply(vdx2, vdx); \ res = XMVectorAdd(XMVectorAdd(XMVectorAdd(a0, XMVectorMultiply(a1, vdx)), XMVectorMultiply(a2, vdx2)), XMVectorMultiply(a3, vdx3)); \ } @@ -251,19 +251,19 @@ namespace DirectX assert(source > 0); assert(dest > 0); - float scale = float(dest) / float(source); - float scaleInv = 0.5f / scale; + const float scale = float(dest) / float(source); + const float scaleInv = 0.5f / scale; // Determine storage required for filter and allocate memory if needed size_t totalSize = TF_FILTER_SIZE + TF_FROM_SIZE + TF_TO_SIZE; - float repeat = (wrap) ? 1.f : 0.f; + const float repeat = (wrap) ? 1.f : 0.f; for (size_t u = 0; u < source; ++u) { - float src = float(u) - 0.5f; - float destMin = src * scale; - float destMax = destMin + scale; - float t = destMax - destMin + repeat + 1.f; + const float src = float(u) - 0.5f; + const float destMin = src * scale; + const float destMax = destMin + scale; + const float t = destMax - destMin + repeat + 1.f; totalSize += TF_FROM_SIZE + TF_TO_SIZE + size_t(t) * TF_TO_SIZE * 2; } @@ -305,7 +305,7 @@ namespace DirectX for (size_t u = 0; u < source; ++u) { // Setup from entry - size_t sizeFrom = sizeInBytes; + const size_t sizeFrom = sizeInBytes; auto pFrom = reinterpret_cast(pFilter + sizeInBytes); sizeInBytes += TF_FROM_SIZE; @@ -317,7 +317,7 @@ namespace DirectX // Perform two passes to capture the influences from both sides for (size_t j = 0; j < 2; ++j) { - float src = float(u + j) - 0.5f; + const float src = float(u + j) - 0.5f; float destMin = src * scale; float destMax = destMin + scale; diff --git a/DirectXTex/scoped.h b/DirectXTex/scoped.h index d8f768c..f49a6bf 100644 --- a/DirectXTex/scoped.h +++ b/DirectXTex/scoped.h @@ -54,7 +54,7 @@ using ScopedAlignedArrayFloat = std::unique_ptr; inline ScopedAlignedArrayFloat make_AlignedArrayFloat(uint64_t count) { - uint64_t size = sizeof(float) * count; + const uint64_t size = sizeof(float) * count; if (size > static_cast(UINT32_MAX)) return nullptr; auto ptr = _aligned_malloc(static_cast(size), 16); @@ -65,7 +65,7 @@ using ScopedAlignedArrayXMVECTOR = std::unique_ptr static_cast(UINT32_MAX)) return nullptr; auto ptr = _aligned_malloc(static_cast(size), 16);