Fix compiler errors (Clang 6) (#37)

This commit is contained in:
Chuck Walbourn 2018-06-12 18:07:34 -07:00 committed by GitHub
parent 094988727e
commit 0d94e9469b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 266 additions and 264 deletions

View File

@ -9,7 +9,7 @@
// http://go.microsoft.com/fwlink/?LinkId=248926 // http://go.microsoft.com/fwlink/?LinkId=248926
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
#include "directxtexp.h" #include "DirectXTexp.h"
// Experiemental encoding variants, not enabled by default // Experiemental encoding variants, not enabled by default
//#define COLOR_WEIGHTS //#define COLOR_WEIGHTS
@ -35,9 +35,9 @@ namespace
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
inline void Decode565(_Out_ HDRColorA *pColor, _In_ const uint16_t w565) inline void Decode565(_Out_ HDRColorA *pColor, _In_ const uint16_t w565)
{ {
pColor->r = (float)((w565 >> 11) & 31) * (1.0f / 31.0f); pColor->r = static_cast<float>((w565 >> 11) & 31) * (1.0f / 31.0f);
pColor->g = (float)((w565 >> 5) & 63) * (1.0f / 63.0f); pColor->g = static_cast<float>((w565 >> 5) & 63) * (1.0f / 63.0f);
pColor->b = (float)((w565 >> 0) & 31) * (1.0f / 31.0f); pColor->b = static_cast<float>((w565 >> 0) & 31) * (1.0f / 31.0f);
pColor->a = 1.0f; pColor->a = 1.0f;
} }
@ -51,9 +51,10 @@ namespace
uint16_t w; uint16_t w;
w = (uint16_t)((static_cast<int32_t>(Color.r * 31.0f + 0.5f) << 11) | w = static_cast<uint16_t>(
(static_cast<int32_t>(Color.g * 63.0f + 0.5f) << 5) | (static_cast<int32_t>(Color.r * 31.0f + 0.5f) << 11)
(static_cast<int32_t>(Color.b * 31.0f + 0.5f) << 0)); | (static_cast<int32_t>(Color.g * 63.0f + 0.5f) << 5)
| (static_cast<int32_t>(Color.b * 31.0f + 0.5f) << 0));
return w; return w;
} }
@ -208,7 +209,7 @@ namespace
} }
// Use Newton's Method to find local minima of sum-of-squares error. // Use Newton's Method to find local minima of sum-of-squares error.
float fSteps = (float)(cSteps - 1); auto fSteps = static_cast<float>(cSteps - 1);
for (size_t iIteration = 0; iIteration < 8; iIteration++) for (size_t iIteration = 0; iIteration < 8; iIteration++)
{ {
@ -431,9 +432,9 @@ namespace
Clr.b += Error[i].b; Clr.b += Error[i].b;
} }
Color[i].r = (float) static_cast<int32_t>(Clr.r * 31.0f + 0.5f) * (1.0f / 31.0f); Color[i].r = static_cast<float>(static_cast<int32_t>(Clr.r * 31.0f + 0.5f) * (1.0f / 31.0f));
Color[i].g = (float) static_cast<int32_t>(Clr.g * 63.0f + 0.5f) * (1.0f / 63.0f); Color[i].g = static_cast<float>(static_cast<int32_t>(Clr.g * 63.0f + 0.5f) * (1.0f / 63.0f));
Color[i].b = (float) static_cast<int32_t>(Clr.b * 31.0f + 0.5f) * (1.0f / 31.0f); Color[i].b = static_cast<float>(static_cast<int32_t>(Clr.b * 31.0f + 0.5f) * (1.0f / 31.0f));
#ifdef COLOR_WEIGHTS #ifdef COLOR_WEIGHTS
Color[i].a = pColor[i].a; Color[i].a = pColor[i].a;
@ -586,7 +587,7 @@ namespace
Dir.g = Step[1].g - Step[0].g; Dir.g = Step[1].g - Step[0].g;
Dir.b = Step[1].b - Step[0].b; Dir.b = Step[1].b - Step[0].b;
float fSteps = (float)(uSteps - 1); auto fSteps = static_cast<float>(uSteps - 1);
float fScale = (wColorA != wColorB) ? (fSteps / (Dir.r * Dir.r + Dir.g * Dir.g + Dir.b * Dir.b)) : 0.0f; float fScale = (wColorA != wColorB) ? (fSteps / (Dir.r * Dir.r + Dir.g * Dir.g + Dir.b * Dir.b)) : 0.0f;
Dir.r *= fScale; Dir.r *= fScale;
@ -602,7 +603,7 @@ namespace
{ {
if ((3 == uSteps) && (pColor[i].a < threshold)) if ((3 == uSteps) && (pColor[i].a < threshold))
{ {
dw = (3 << 30) | (dw >> 2); dw = (3u << 30) | (dw >> 2);
} }
else else
{ {
@ -751,7 +752,7 @@ void DirectX::D3DXEncodeBC1(uint8_t *pBC, const XMVECTOR *pColor, float threshol
Color[i].r = clr.r; Color[i].r = clr.r;
Color[i].g = clr.g; Color[i].g = clr.g;
Color[i].b = clr.b; Color[i].b = clr.b;
Color[i].a = (float) static_cast<int32_t>(clr.a + fError[i] + 0.5f); Color[i].a = static_cast<float>(static_cast<int32_t>(clr.a + fError[i] + 0.5f));
float fDiff = fAlph - Color[i].a; float fDiff = fAlph - Color[i].a;
@ -811,13 +812,13 @@ void DirectX::D3DXDecodeBC2(XMVECTOR *pColor, const uint8_t *pBC)
for (size_t i = 0; i < 8; ++i, dw >>= 4) for (size_t i = 0; i < 8; ++i, dw >>= 4)
{ {
#pragma prefast(suppress:22103, "writing blocks in two halves confuses tool") #pragma prefast(suppress:22103, "writing blocks in two halves confuses tool")
pColor[i] = XMVectorSetW(pColor[i], (float)(dw & 0xf) * (1.0f / 15.0f)); pColor[i] = XMVectorSetW(pColor[i], static_cast<float>(dw & 0xf) * (1.0f / 15.0f));
} }
dw = pBC2->bitmap[1]; dw = pBC2->bitmap[1];
for (size_t i = 8; i < NUM_PIXELS_PER_BLOCK; ++i, dw >>= 4) for (size_t i = 8; i < NUM_PIXELS_PER_BLOCK; ++i, dw >>= 4)
pColor[i] = XMVectorSetW(pColor[i], (float)(dw & 0xf) * (1.0f / 15.0f)); pColor[i] = XMVectorSetW(pColor[i], static_cast<float>(dw & 0xf) * (1.0f / 15.0f));
} }
_Use_decl_annotations_ _Use_decl_annotations_
@ -845,14 +846,14 @@ void DirectX::D3DXEncodeBC2(uint8_t *pBC, const XMVECTOR *pColor, DWORD flags)
if (flags & BC_FLAGS_DITHER_A) if (flags & BC_FLAGS_DITHER_A)
fAlph += fError[i]; fAlph += fError[i];
uint32_t u = (uint32_t) static_cast<int32_t>(fAlph * 15.0f + 0.5f); auto u = static_cast<uint32_t>(fAlph * 15.0f + 0.5f);
pBC2->bitmap[i >> 3] >>= 4; pBC2->bitmap[i >> 3] >>= 4;
pBC2->bitmap[i >> 3] |= (u << 28); pBC2->bitmap[i >> 3] |= (u << 28);
if (flags & BC_FLAGS_DITHER_A) if (flags & BC_FLAGS_DITHER_A)
{ {
float fDiff = fAlph - (float)u * (1.0f / 15.0f); float fDiff = fAlph - float(u) * (1.0f / 15.0f);
if (3 != (i & 3)) if (3 != (i & 3))
{ {
@ -908,8 +909,8 @@ void DirectX::D3DXDecodeBC3(XMVECTOR *pColor, const uint8_t *pBC)
// Adaptive 3-bit alpha part // Adaptive 3-bit alpha part
float fAlpha[8]; float fAlpha[8];
fAlpha[0] = ((float)pBC3->alpha[0]) * (1.0f / 255.0f); fAlpha[0] = static_cast<float>(pBC3->alpha[0]) * (1.0f / 255.0f);
fAlpha[1] = ((float)pBC3->alpha[1]) * (1.0f / 255.0f); fAlpha[1] = static_cast<float>(pBC3->alpha[1]) * (1.0f / 255.0f);
if (pBC3->alpha[0] > pBC3->alpha[1]) if (pBC3->alpha[0] > pBC3->alpha[1])
{ {
@ -1028,11 +1029,11 @@ void DirectX::D3DXEncodeBC3(uint8_t *pBC, const XMVECTOR *pColor, DWORD flags)
float fAlphaA, fAlphaB; float fAlphaA, fAlphaB;
OptimizeAlpha<false>(&fAlphaA, &fAlphaB, fAlpha, uSteps); OptimizeAlpha<false>(&fAlphaA, &fAlphaB, fAlpha, uSteps);
uint8_t bAlphaA = (uint8_t) static_cast<int32_t>(fAlphaA * 255.0f + 0.5f); auto bAlphaA = static_cast<uint8_t>(static_cast<int32_t>(fAlphaA * 255.0f + 0.5f));
uint8_t bAlphaB = (uint8_t) static_cast<int32_t>(fAlphaB * 255.0f + 0.5f); auto bAlphaB = static_cast<uint8_t>(static_cast<int32_t>(fAlphaB * 255.0f + 0.5f));
fAlphaA = (float)bAlphaA * (1.0f / 255.0f); fAlphaA = static_cast<float>(bAlphaA) * (1.0f / 255.0f);
fAlphaB = (float)bAlphaB * (1.0f / 255.0f); fAlphaB = static_cast<float>(bAlphaB) * (1.0f / 255.0f);
// Setup block // Setup block
if ((8 == uSteps) && (bAlphaA == bAlphaB)) if ((8 == uSteps) && (bAlphaA == bAlphaB))
@ -1080,7 +1081,7 @@ void DirectX::D3DXEncodeBC3(uint8_t *pBC, const XMVECTOR *pColor, DWORD flags)
} }
// Encode alpha bitmap // Encode alpha bitmap
float fSteps = (float)(uSteps - 1); auto fSteps = static_cast<float>(uSteps - 1);
float fScale = (fStep[0] != fStep[1]) ? (fSteps / (fStep[1] - fStep[0])) : 0.0f; float fScale = (fStep[0] != fStep[1]) ? (fSteps / (fStep[1] - fStep[0])) : 0.0f;
if (flags & BC_FLAGS_DITHER_A) if (flags & BC_FLAGS_DITHER_A)
@ -1130,8 +1131,8 @@ void DirectX::D3DXEncodeBC3(uint8_t *pBC, const XMVECTOR *pColor, DWORD flags)
} }
} }
pBC3->bitmap[0 + iSet * 3] = ((uint8_t *)&dw)[0]; pBC3->bitmap[0 + iSet * 3] = reinterpret_cast<uint8_t *>(&dw)[0];
pBC3->bitmap[1 + iSet * 3] = ((uint8_t *)&dw)[1]; pBC3->bitmap[1 + iSet * 3] = reinterpret_cast<uint8_t *>(&dw)[1];
pBC3->bitmap[2 + iSet * 3] = ((uint8_t *)&dw)[2]; pBC3->bitmap[2 + iSet * 3] = reinterpret_cast<uint8_t *>(&dw)[2];
} }
} }

View File

@ -216,7 +216,7 @@ template <bool bRange> void OptimizeAlpha(float *pX, float *pY, const float *pPo
} }
// Use Newton's Method to find local minima of sum-of-squares error. // Use Newton's Method to find local minima of sum-of-squares error.
float fSteps = (float)(cSteps - 1); auto fSteps = static_cast<float>(cSteps - 1);
for (size_t iIteration = 0; iIteration < 8; iIteration++) for (size_t iIteration = 0; iIteration < 8; iIteration++)
{ {

View File

@ -9,7 +9,7 @@
// http://go.microsoft.com/fwlink/?LinkId=248926 // http://go.microsoft.com/fwlink/?LinkId=248926
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
#include "directxtexp.h" #include "DirectXTexp.h"
#include "BC.h" #include "BC.h"
@ -70,13 +70,13 @@ namespace
size_t GetIndex(size_t uOffset) const size_t GetIndex(size_t uOffset) const
{ {
return (size_t)((data >> (3 * uOffset + 16)) & 0x07); return static_cast<size_t>((data >> (3 * uOffset + 16)) & 0x07);
} }
void SetIndex(size_t uOffset, size_t uIndex) void SetIndex(size_t uOffset, size_t uIndex)
{ {
data &= ~((uint64_t)0x07 << (3 * uOffset + 16)); data &= ~(uint64_t(0x07) << (3 * uOffset + 16));
data |= ((uint64_t)uIndex << (3 * uOffset + 16)); data |= (uint64_t(uIndex) << (3 * uOffset + 16));
} }
union union
@ -129,13 +129,13 @@ namespace
size_t GetIndex(size_t uOffset) const size_t GetIndex(size_t uOffset) const
{ {
return (size_t)((data >> (3 * uOffset + 16)) & 0x07); return static_cast<size_t>((data >> (3 * uOffset + 16)) & 0x07);
} }
void SetIndex(size_t uOffset, size_t uIndex) void SetIndex(size_t uOffset, size_t uIndex)
{ {
data &= ~((uint64_t)0x07 << (3 * uOffset + 16)); data &= ~(uint64_t(0x07) << (3 * uOffset + 16));
data |= ((uint64_t)uIndex << (3 * uOffset + 16)); data |= (uint64_t(uIndex) << (3 * uOffset + 16));
} }
union union
@ -168,14 +168,14 @@ namespace
if (fVal < -1) if (fVal < -1)
fVal = -1; // Clamp to -1 fVal = -1; // Clamp to -1
fVal = fVal * (int8_t)(dwMostNeg - 1); fVal = fVal * static_cast<int8_t>(dwMostNeg - 1);
if (fVal >= 0) if (fVal >= 0)
fVal += .5f; fVal += .5f;
else else
fVal -= .5f; fVal -= .5f;
*piSNorm = (int8_t)(fVal); *piSNorm = static_cast<int8_t>(fVal);
} }
@ -216,8 +216,8 @@ namespace
// 6 interpolated color values // 6 interpolated color values
OptimizeAlpha<false>(&fStart, &fEnd, theTexelsU, 8); OptimizeAlpha<false>(&fStart, &fEnd, theTexelsU, 8);
uint8_t iStart = static_cast<uint8_t>(fStart * 255.0f); auto iStart = static_cast<uint8_t>(fStart * 255.0f);
uint8_t iEnd = static_cast<uint8_t>(fEnd * 255.0f); auto iEnd = static_cast<uint8_t>(fEnd * 255.0f);
endpointU_0 = iEnd; endpointU_0 = iEnd;
endpointU_1 = iStart; endpointU_1 = iStart;
@ -227,8 +227,8 @@ namespace
// 4 interpolated color values // 4 interpolated color values
OptimizeAlpha<false>(&fStart, &fEnd, theTexelsU, 6); OptimizeAlpha<false>(&fStart, &fEnd, theTexelsU, 6);
uint8_t iStart = static_cast<uint8_t>(fStart * 255.0f); auto iStart = static_cast<uint8_t>(fStart * 255.0f);
uint8_t iEnd = static_cast<uint8_t>(fEnd * 255.0f); auto iEnd = static_cast<uint8_t>(fEnd * 255.0f);
endpointU_1 = iEnd; endpointU_1 = iEnd;
endpointU_0 = iStart; endpointU_0 = iStart;
@ -559,4 +559,4 @@ void DirectX::D3DXEncodeBC5S(uint8_t *pBC, const XMVECTOR *pColor, DWORD flags)
FindClosestSNORM(pBCR, theTexelsU); FindClosestSNORM(pBCR, theTexelsU);
FindClosestSNORM(pBCG, theTexelsV); FindClosestSNORM(pBCG, theTexelsV);
} }

View File

@ -9,7 +9,7 @@
// http://go.microsoft.com/fwlink/?LinkId=248926 // http://go.microsoft.com/fwlink/?LinkId=248926
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
#include "directxtexp.h" #include "DirectXTexp.h"
#include "BC.h" #include "BC.h"
@ -428,16 +428,16 @@ namespace DirectX
inline HDRColorA& HDRColorA::operator = (const LDRColorA& c) inline HDRColorA& HDRColorA::operator = (const LDRColorA& c)
{ {
r = (float)c.r; r = static_cast<float>(c.r);
g = (float)c.g; g = static_cast<float>(c.g);
b = (float)c.b; b = static_cast<float>(c.b);
a = (float)c.a; a = static_cast<float>(c.a);
return *this; return *this;
} }
inline LDRColorA HDRColorA::ToLDRColorA() const inline LDRColorA HDRColorA::ToLDRColorA() const
{ {
return LDRColorA((uint8_t)(r + 0.01f), (uint8_t)(g + 0.01f), (uint8_t)(b + 0.01f), (uint8_t)(a + 0.01f)); return LDRColorA(static_cast<uint8_t>(r + 0.01f), static_cast<uint8_t>(g + 0.01f), static_cast<uint8_t>(b + 0.01f), static_cast<uint8_t>(a + 0.01f));
} }
} }
@ -454,11 +454,6 @@ namespace
INTColor(int nr, int ng, int nb) : pad(0) { r = nr; g = ng; b = nb; } INTColor(int nr, int ng, int nb) : pad(0) { r = nr; g = ng; b = nb; }
INTColor(const INTColor& c) : pad(0) { r = c.r; g = c.g; b = c.b; } INTColor(const INTColor& c) : pad(0) { r = c.r; g = c.g; b = c.b; }
INTColor operator - (_In_ const INTColor& c) const
{
return INTColor(r - c.r, g - c.g, b - c.b);
}
INTColor& operator += (_In_ const INTColor& c) INTColor& operator += (_In_ const INTColor& c)
{ {
r += c.r; r += c.r;
@ -487,14 +482,14 @@ namespace
{ {
assert(i < sizeof(INTColor) / sizeof(int)); assert(i < sizeof(INTColor) / sizeof(int));
_Analysis_assume_(i < sizeof(INTColor) / sizeof(int)); _Analysis_assume_(i < sizeof(INTColor) / sizeof(int));
return ((int*) this)[i]; return reinterpret_cast<int*>(this)[i];
} }
void Set(_In_ const HDRColorA& c, _In_ bool bSigned) void Set(_In_ const HDRColorA& c, _In_ bool bSigned)
{ {
PackedVector::XMHALF4 aF16; PackedVector::XMHALF4 aF16;
XMVECTOR v = XMLoadFloat4((const XMFLOAT4*)& c); XMVECTOR v = XMLoadFloat4(reinterpret_cast<const XMFLOAT4*>(&c));
XMStoreHalf4(&aF16, v); XMStoreHalf4(&aF16, v);
r = F16ToINT(aF16.x, bSigned); r = F16ToINT(aF16.x, bSigned);
@ -528,7 +523,7 @@ namespace
private: private:
static int F16ToINT(_In_ const PackedVector::HALF& f, _In_ bool bSigned) static int F16ToINT(_In_ const PackedVector::HALF& f, _In_ bool bSigned)
{ {
uint16_t input = *((const uint16_t*)&f); uint16_t input = *reinterpret_cast<const uint16_t*>(&f);
int out, s; int out, s;
if (bSigned) if (bSigned)
{ {
@ -563,10 +558,10 @@ namespace
else else
{ {
assert(input >= 0 && input <= F16MAX); assert(input >= 0 && input <= F16MAX);
out = (uint16_t)input; out = static_cast<uint16_t>(input);
} }
*((uint16_t*)&h) = out; *reinterpret_cast<uint16_t*>(&h) = out;
return h; return h;
} }
}; };
@ -605,7 +600,7 @@ namespace
{ {
size_t uFirstIndexBits = 8 - uBase; size_t uFirstIndexBits = 8 - uBase;
size_t uNextIndexBits = uNumBits - uFirstIndexBits; size_t uNextIndexBits = uNumBits - uFirstIndexBits;
ret = (m_uBits[uIndex] >> uBase) | ((m_uBits[uIndex + 1] & ((1 << uNextIndexBits) - 1)) << uFirstIndexBits); ret = static_cast<uint8_t>((unsigned(m_uBits[uIndex]) >> uBase) | ((unsigned(m_uBits[uIndex + 1]) & ((1u << uNextIndexBits) - 1)) << uFirstIndexBits));
} }
else else
{ {
@ -798,7 +793,7 @@ namespace
static uint8_t Quantize(_In_ uint8_t comp, _In_ uint8_t uPrec) static uint8_t Quantize(_In_ uint8_t comp, _In_ uint8_t uPrec)
{ {
assert(0 < uPrec && uPrec <= 8); assert(0 < uPrec && uPrec <= 8);
uint8_t rnd = (uint8_t)std::min<uint16_t>(255, uint16_t(comp) + (1 << (7 - uPrec))); uint8_t rnd = std::min<uint8_t>(255u, static_cast<uint8_t>(unsigned(comp) + (1u << (7 - uPrec))));
return rnd >> (8 - uPrec); return rnd >> (8 - uPrec);
} }
@ -818,7 +813,7 @@ namespace
static uint8_t Unquantize(_In_ uint8_t comp, _In_ size_t uPrec) static uint8_t Unquantize(_In_ uint8_t comp, _In_ size_t uPrec)
{ {
assert(0 < uPrec && uPrec <= 8); assert(0 < uPrec && uPrec <= 8);
comp = comp << (8 - uPrec); comp = static_cast<uint8_t>(unsigned(comp) << (8 - uPrec));
return comp | (comp >> uPrec); return comp | (comp >> uPrec);
} }
@ -1280,7 +1275,7 @@ namespace
} }
// Use Newton's Method to find local minima of sum-of-squares error. // Use Newton's Method to find local minima of sum-of-squares error.
float fSteps = (float)(cSteps - 1); auto fSteps = static_cast<float>(cSteps - 1);
for (size_t iIteration = 0; iIteration < 8; iIteration++) for (size_t iIteration = 0; iIteration < 8; iIteration++)
{ {
@ -1472,7 +1467,7 @@ namespace
} }
// Use Newton's Method to find local minima of sum-of-squares error. // Use Newton's Method to find local minima of sum-of-squares error.
float fSteps = (float)(cSteps - 1); auto fSteps = static_cast<float>(cSteps - 1);
for (size_t iIteration = 0; iIteration < 8 && fError > 0.0f; iIteration++) for (size_t iIteration = 0; iIteration < 8 && fError > 0.0f; iIteration++)
{ {
@ -1656,7 +1651,7 @@ void D3DX_BC6H::Decode(bool bSigned, HDRColorA* pOut) const
uint8_t uMode = GetBits(uStartBit, 2); uint8_t uMode = GetBits(uStartBit, 2);
if (uMode != 0x00 && uMode != 0x01) if (uMode != 0x00 && uMode != 0x01)
{ {
uMode = (GetBits(uStartBit, 3) << 2) | uMode; uMode = static_cast<uint8_t>((unsigned(GetBits(uStartBit, 3)) << 2) | uMode);
} }
assert(uMode < 32); assert(uMode < 32);
@ -2035,7 +2030,7 @@ float D3DX_BC6H::MapColorsQuantized(const EncodeParams* pEP, const INTColor aCol
assert(pEP); assert(pEP);
const uint8_t uIndexPrec = ms_aInfo[pEP->uMode].uIndexPrec; const uint8_t uIndexPrec = ms_aInfo[pEP->uMode].uIndexPrec;
const uint8_t uNumIndices = 1 << uIndexPrec; auto uNumIndices = static_cast<const uint8_t>(1u << uIndexPrec);
INTColor aPalette[BC6H_MAX_INDICES]; INTColor aPalette[BC6H_MAX_INDICES];
GeneratePaletteQuantized(pEP, endPts, aPalette); GeneratePaletteQuantized(pEP, endPts, aPalette);
@ -2239,7 +2234,7 @@ void D3DX_BC6H::AssignIndices(const EncodeParams* pEP, const INTEndPntPair aEndP
{ {
assert(pEP); assert(pEP);
const uint8_t uPartitions = ms_aInfo[pEP->uMode].uPartitions; const uint8_t uPartitions = ms_aInfo[pEP->uMode].uPartitions;
const uint8_t uNumIndices = 1 << ms_aInfo[pEP->uMode].uIndexPrec; auto uNumIndices = static_cast<const uint8_t>(1u << ms_aInfo[pEP->uMode].uIndexPrec);
assert(uPartitions < BC6H_MAX_REGIONS && pEP->uShape < BC6H_MAX_SHAPES); assert(uPartitions < BC6H_MAX_REGIONS && pEP->uShape < BC6H_MAX_SHAPES);
_Analysis_assume_(uPartitions < BC6H_MAX_REGIONS && pEP->uShape < BC6H_MAX_SHAPES); _Analysis_assume_(uPartitions < BC6H_MAX_REGIONS && pEP->uShape < BC6H_MAX_SHAPES);
@ -2400,7 +2395,7 @@ void D3DX_BC6H::GeneratePaletteUnquantized(const EncodeParams* pEP, size_t uRegi
_Analysis_assume_(uRegion < BC6H_MAX_REGIONS && pEP->uShape < BC6H_MAX_SHAPES); _Analysis_assume_(uRegion < BC6H_MAX_REGIONS && pEP->uShape < BC6H_MAX_SHAPES);
const INTEndPntPair& endPts = pEP->aUnqEndPts[pEP->uShape][uRegion]; const INTEndPntPair& endPts = pEP->aUnqEndPts[pEP->uShape][uRegion];
const uint8_t uIndexPrec = ms_aInfo[pEP->uMode].uIndexPrec; const uint8_t uIndexPrec = ms_aInfo[pEP->uMode].uIndexPrec;
const uint8_t uNumIndices = 1 << uIndexPrec; auto uNumIndices = static_cast<const uint8_t>(1u << uIndexPrec);
assert(uNumIndices > 0); assert(uNumIndices > 0);
_Analysis_assume_(uNumIndices > 0); _Analysis_assume_(uNumIndices > 0);
@ -2433,7 +2428,7 @@ float D3DX_BC6H::MapColors(const EncodeParams* pEP, size_t uRegion, size_t np, c
{ {
assert(pEP); assert(pEP);
const uint8_t uIndexPrec = ms_aInfo[pEP->uMode].uIndexPrec; const uint8_t uIndexPrec = ms_aInfo[pEP->uMode].uIndexPrec;
const uint8_t uNumIndices = 1 << uIndexPrec; auto uNumIndices = static_cast<const uint8_t>(1u << uIndexPrec);
INTColor aPalette[BC6H_MAX_INDICES]; INTColor aPalette[BC6H_MAX_INDICES];
GeneratePaletteUnquantized(pEP, uRegion, aPalette); GeneratePaletteUnquantized(pEP, uRegion, aPalette);
@ -2535,7 +2530,7 @@ void D3DX_BC7::Decode(HDRColorA* pOut) const
assert(uPartitions < BC7_MAX_REGIONS); assert(uPartitions < BC7_MAX_REGIONS);
_Analysis_assume_(uPartitions < BC7_MAX_REGIONS); _Analysis_assume_(uPartitions < BC7_MAX_REGIONS);
const uint8_t uNumEndPts = (uPartitions + 1) << 1; auto uNumEndPts = static_cast<const uint8_t>((unsigned(uPartitions) + 1u) << 1);
const uint8_t uIndexPrec = ms_aInfo[uMode].uIndexPrec; const uint8_t uIndexPrec = ms_aInfo[uMode].uIndexPrec;
const uint8_t uIndexPrec2 = ms_aInfo[uMode].uIndexPrec2; const uint8_t uIndexPrec2 = ms_aInfo[uMode].uIndexPrec2;
size_t i; size_t i;
@ -2643,7 +2638,7 @@ void D3DX_BC7::Decode(HDRColorA* pOut) const
{ {
if (RGBAPrec[ch] != RGBAPrecWithP[ch]) if (RGBAPrec[ch] != RGBAPrecWithP[ch])
{ {
c[i][ch] = (c[i][ch] << 1) | P[pi]; c[i][ch] = static_cast<uint8_t>((unsigned(c[i][ch]) << 1) | P[pi]);
} }
} }
} }
@ -2879,7 +2874,7 @@ float D3DX_BC7::PerturbOne(const EncodeParams* pEP, const LDRColorA aColors[], s
if (tmp < 0 || tmp >= (1 << prec)) if (tmp < 0 || tmp >= (1 << prec))
continue; continue;
else else
*ptmp_c = (uint8_t)tmp; *ptmp_c = static_cast<uint8_t>(tmp);
float fTotalErr = MapColors(pEP, aColors, np, uIndexMode, tmp_endPts, fMinErr); float fTotalErr = MapColors(pEP, aColors, np, uIndexMode, tmp_endPts, fMinErr);
if (fTotalErr < fMinErr) if (fTotalErr < fMinErr)
@ -2928,8 +2923,8 @@ void D3DX_BC7::Exhaustive(const EncodeParams* pEP, const LDRColorA aColors[], si
{ {
for (int b = std::max<int>(a, blow); b < bhigh; ++b) for (int b = std::max<int>(a, blow); b < bhigh; ++b)
{ {
tmpEndPt.A[ch] = (uint8_t)a; tmpEndPt.A[ch] = static_cast<uint8_t>(a);
tmpEndPt.B[ch] = (uint8_t)b; tmpEndPt.B[ch] = static_cast<uint8_t>(b);
float fErr = MapColors(pEP, aColors, np, uIndexMode, tmpEndPt, fBestErr); float fErr = MapColors(pEP, aColors, np, uIndexMode, tmpEndPt, fBestErr);
if (fErr < fBestErr) if (fErr < fBestErr)
@ -2948,8 +2943,8 @@ void D3DX_BC7::Exhaustive(const EncodeParams* pEP, const LDRColorA aColors[], si
{ {
for (int a = std::max<int>(b, alow); a <= ahigh; ++a) for (int a = std::max<int>(b, alow); a <= ahigh; ++a)
{ {
tmpEndPt.A[ch] = (uint8_t)a; tmpEndPt.A[ch] = static_cast<uint8_t>(a);
tmpEndPt.B[ch] = (uint8_t)b; tmpEndPt.B[ch] = static_cast<uint8_t>(b);
float fErr = MapColors(pEP, aColors, np, uIndexMode, tmpEndPt, fBestErr); float fErr = MapColors(pEP, aColors, np, uIndexMode, tmpEndPt, fBestErr);
if (fErr < fBestErr) if (fErr < fBestErr)
@ -2964,8 +2959,8 @@ void D3DX_BC7::Exhaustive(const EncodeParams* pEP, const LDRColorA aColors[], si
if (fBestErr < fOrgErr) if (fBestErr < fOrgErr)
{ {
optEndPt.A[ch] = (uint8_t)amin; optEndPt.A[ch] = static_cast<uint8_t>(amin);
optEndPt.B[ch] = (uint8_t)bmin; optEndPt.B[ch] = static_cast<uint8_t>(bmin);
fOrgErr = fBestErr; fOrgErr = fBestErr;
} }
} }
@ -3073,8 +3068,8 @@ void D3DX_BC7::AssignIndices(const EncodeParams* pEP, size_t uShape, size_t uInd
const uint8_t uIndexPrec = uIndexMode ? ms_aInfo[pEP->uMode].uIndexPrec2 : ms_aInfo[pEP->uMode].uIndexPrec; const uint8_t uIndexPrec = uIndexMode ? ms_aInfo[pEP->uMode].uIndexPrec2 : ms_aInfo[pEP->uMode].uIndexPrec;
const uint8_t uIndexPrec2 = uIndexMode ? ms_aInfo[pEP->uMode].uIndexPrec : ms_aInfo[pEP->uMode].uIndexPrec2; const uint8_t uIndexPrec2 = uIndexMode ? ms_aInfo[pEP->uMode].uIndexPrec : ms_aInfo[pEP->uMode].uIndexPrec2;
const uint8_t uNumIndices = 1 << uIndexPrec; auto uNumIndices = static_cast<const uint8_t>(1u << uIndexPrec);
const uint8_t uNumIndices2 = 1 << uIndexPrec2; auto uNumIndices2 = static_cast<const uint8_t>(1u << uIndexPrec2);
assert((uNumIndices <= BC7_MAX_INDICES) && (uNumIndices2 <= BC7_MAX_INDICES)); assert((uNumIndices <= BC7_MAX_INDICES) && (uNumIndices2 <= BC7_MAX_INDICES));
_Analysis_assume_((uNumIndices <= BC7_MAX_INDICES) && (uNumIndices2 <= BC7_MAX_INDICES)); _Analysis_assume_((uNumIndices <= BC7_MAX_INDICES) && (uNumIndices2 <= BC7_MAX_INDICES));
@ -3312,8 +3307,8 @@ float D3DX_BC7::RoughMSE(EncodeParams* pEP, size_t uShape, size_t uIndexMode)
const uint8_t uIndexPrec = uIndexMode ? ms_aInfo[pEP->uMode].uIndexPrec2 : ms_aInfo[pEP->uMode].uIndexPrec; const uint8_t uIndexPrec = uIndexMode ? ms_aInfo[pEP->uMode].uIndexPrec2 : ms_aInfo[pEP->uMode].uIndexPrec;
const uint8_t uIndexPrec2 = uIndexMode ? ms_aInfo[pEP->uMode].uIndexPrec : ms_aInfo[pEP->uMode].uIndexPrec2; const uint8_t uIndexPrec2 = uIndexMode ? ms_aInfo[pEP->uMode].uIndexPrec : ms_aInfo[pEP->uMode].uIndexPrec2;
const uint8_t uNumIndices = 1 << uIndexPrec; auto uNumIndices = static_cast<const uint8_t>(1u << uIndexPrec);
const uint8_t uNumIndices2 = 1 << uIndexPrec2; auto uNumIndices2 = static_cast<const uint8_t>(1u << uIndexPrec2);
size_t auPixIdx[NUM_PIXELS_PER_BLOCK]; size_t auPixIdx[NUM_PIXELS_PER_BLOCK];
LDRColorA aPalette[BC7_MAX_REGIONS][BC7_MAX_INDICES]; LDRColorA aPalette[BC7_MAX_REGIONS][BC7_MAX_INDICES];

View File

@ -7,7 +7,7 @@
// Licensed under the MIT License. // Licensed under the MIT License.
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
#include "directxtexp.h" #include "DirectXTexp.h"
#include "BCDirectCompute.h" #include "BCDirectCompute.h"
@ -427,7 +427,7 @@ HRESULT GPUCompressBC::Compress(const Image& srcImage, const Image& destImage)
size_t xblocks = std::max<size_t>(1, (m_width + 3) >> 2); size_t xblocks = std::max<size_t>(1, (m_width + 3) >> 2);
size_t yblocks = std::max<size_t>(1, (m_height + 3) >> 2); size_t yblocks = std::max<size_t>(1, (m_height + 3) >> 2);
UINT num_total_blocks = static_cast<UINT>(xblocks * yblocks); auto num_total_blocks = static_cast<UINT>(xblocks * yblocks);
UINT num_blocks = num_total_blocks; UINT num_blocks = num_total_blocks;
int start_block_id = 0; int start_block_id = 0;
while (num_blocks > 0) while (num_blocks > 0)
@ -608,4 +608,4 @@ HRESULT GPUCompressBC::Compress(const Image& srcImage, const Image& destImage)
} }
return hr; return hr;
} }

View File

@ -50,9 +50,11 @@ struct DDS_PIXELFORMAT
#define DDS_BUMPDUDV 0x00080000 // DDPF_BUMPDUDV #define DDS_BUMPDUDV 0x00080000 // DDPF_BUMPDUDV
#ifndef MAKEFOURCC #ifndef MAKEFOURCC
#define MAKEFOURCC(ch0, ch1, ch2, ch3) \ #define MAKEFOURCC(ch0, ch1, ch2, ch3) \
((uint32_t)(uint8_t)(ch0) | ((uint32_t)(uint8_t)(ch1) << 8) | \ (static_cast<uint32_t>(static_cast<uint8_t>(ch0)) \
((uint32_t)(uint8_t)(ch2) << 16) | ((uint32_t)(uint8_t)(ch3) << 24 )) | (static_cast<uint32_t>(static_cast<uint8_t>(ch1)) << 8) \
| (static_cast<uint32_t>(static_cast<uint8_t>(ch2)) << 16) \
| (static_cast<uint32_t>(static_cast<uint8_t>(ch3)) << 24))
#endif /* defined(MAKEFOURCC) */ #endif /* defined(MAKEFOURCC) */
extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_DXT1 = extern __declspec(selectany) const DDS_PIXELFORMAT DDSPF_DXT1 =

View File

@ -9,7 +9,7 @@
// http://go.microsoft.com/fwlink/?LinkId=248926 // http://go.microsoft.com/fwlink/?LinkId=248926
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
#include "directxtexp.h" #include "DirectXTexp.h"
#ifdef _OPENMP #ifdef _OPENMP
#include <omp.h> #include <omp.h>

View File

@ -9,7 +9,7 @@
// http://go.microsoft.com/fwlink/?LinkId=248926 // http://go.microsoft.com/fwlink/?LinkId=248926
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
#include "directxtexp.h" #include "DirectXTexp.h"
#include "bcdirectcompute.h" #include "bcdirectcompute.h"

View File

@ -9,7 +9,7 @@
// http://go.microsoft.com/fwlink/?LinkId=248926 // http://go.microsoft.com/fwlink/?LinkId=248926
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
#include "directxtexp.h" #include "DirectXTexp.h"
using namespace DirectX; using namespace DirectX;
using namespace DirectX::PackedVector; using namespace DirectX::PackedVector;
@ -52,12 +52,12 @@ namespace
inline float FloatFrom7e3(uint32_t Value) inline float FloatFrom7e3(uint32_t Value)
{ {
uint32_t Mantissa = (uint32_t)(Value & 0x7F); auto Mantissa = static_cast<uint32_t>(Value & 0x7F);
uint32_t Exponent = (Value & 0x380); uint32_t Exponent = (Value & 0x380);
if (Exponent != 0) // The value is normalized if (Exponent != 0) // The value is normalized
{ {
Exponent = (uint32_t)((Value >> 7) & 0x7); Exponent = static_cast<uint32_t>((Value >> 7) & 0x7);
} }
else if (Mantissa != 0) // The value is denormalized else if (Mantissa != 0) // The value is denormalized
{ {
@ -74,7 +74,7 @@ namespace
} }
else // The value is zero else // The value is zero
{ {
Exponent = (uint32_t)-124; Exponent = uint32_t(-124);
} }
uint32_t Result = ((Exponent + 124) << 23) | // Exponent uint32_t Result = ((Exponent + 124) << 23) | // Exponent
@ -118,12 +118,12 @@ namespace
inline float FloatFrom6e4(uint32_t Value) inline float FloatFrom6e4(uint32_t Value)
{ {
uint32_t Mantissa = (uint32_t)(Value & 0x3F); uint32_t Mantissa = static_cast<uint32_t>(Value & 0x3F);
uint32_t Exponent = (Value & 0x3C0); uint32_t Exponent = (Value & 0x3C0);
if (Exponent != 0) // The value is normalized if (Exponent != 0) // The value is normalized
{ {
Exponent = (uint32_t)((Value >> 6) & 0xF); Exponent = static_cast<uint32_t>((Value >> 6) & 0xF);
} }
else if (Mantissa != 0) // The value is denormalized else if (Mantissa != 0) // The value is denormalized
{ {
@ -140,7 +140,7 @@ namespace
} }
else // The value is zero else // The value is zero
{ {
Exponent = (uint32_t)-120; Exponent = uint32_t(-120);
} }
uint32_t Result = ((Exponent + 120) << 23) | // Exponent uint32_t Result = ((Exponent + 120) << 23) | // Exponent
@ -762,7 +762,7 @@ _Use_decl_annotations_ bool DirectX::_LoadScanline(
size_t size, size_t size,
DXGI_FORMAT format) DXGI_FORMAT format)
{ {
assert(pDestination && count > 0 && (((uintptr_t)pDestination & 0xF) == 0)); assert(pDestination && count > 0 && ((reinterpret_cast<uintptr_t>(pDestination) & 0xF) == 0));
assert(pSource && size > 0); assert(pSource && size > 0);
assert(IsValid(format) && !IsTypeless(format, false) && !IsCompressed(format) && !IsPlanar(format) && !IsPalettized(format)); assert(IsValid(format) && !IsTypeless(format, false) && !IsCompressed(format) && !IsPlanar(format) && !IsPalettized(format));
@ -828,7 +828,7 @@ _Use_decl_annotations_ bool DirectX::_LoadScanline(
auto sPtr = static_cast<const float*>(pSource); auto sPtr = static_cast<const float*>(pSource);
for (size_t icount = 0; icount < (size - psize + 1); icount += psize) for (size_t icount = 0; icount < (size - psize + 1); icount += psize)
{ {
const uint8_t* ps8 = reinterpret_cast<const uint8_t*>(&sPtr[1]); auto ps8 = reinterpret_cast<const uint8_t*>(&sPtr[1]);
if (dPtr >= ePtr) break; if (dPtr >= ePtr) break;
*(dPtr++) = XMVectorSet(sPtr[0], static_cast<float>(*ps8), 0.f, 1.f); *(dPtr++) = XMVectorSet(sPtr[0], static_cast<float>(*ps8), 0.f, 1.f);
sPtr += 2; sPtr += 2;
@ -863,7 +863,7 @@ _Use_decl_annotations_ bool DirectX::_LoadScanline(
auto sPtr = static_cast<const float*>(pSource); auto sPtr = static_cast<const float*>(pSource);
for (size_t icount = 0; icount < (size - psize + 1); icount += psize) for (size_t icount = 0; icount < (size - psize + 1); icount += psize)
{ {
const uint8_t* pg8 = reinterpret_cast<const uint8_t*>(&sPtr[1]); auto pg8 = reinterpret_cast<const uint8_t*>(&sPtr[1]);
if (dPtr >= ePtr) break; if (dPtr >= ePtr) break;
*(dPtr++) = XMVectorSet(0.f /* typeless component assumed zero */, static_cast<float>(*pg8), 0.f, 1.f); *(dPtr++) = XMVectorSet(0.f /* typeless component assumed zero */, static_cast<float>(*pg8), 0.f, 1.f);
sPtr += 2; sPtr += 2;
@ -964,8 +964,8 @@ _Use_decl_annotations_ bool DirectX::_LoadScanline(
auto sPtr = static_cast<const uint32_t*>(pSource); auto sPtr = static_cast<const uint32_t*>(pSource);
for (size_t icount = 0; icount < (size - sizeof(uint32_t) + 1); icount += sizeof(uint32_t)) for (size_t icount = 0; icount < (size - sizeof(uint32_t) + 1); icount += sizeof(uint32_t))
{ {
float d = static_cast<float>(*sPtr & 0xFFFFFF) / 16777215.f; auto d = static_cast<float>(*sPtr & 0xFFFFFF) / 16777215.f;
float s = static_cast<float>((*sPtr & 0xFF000000) >> 24); auto s = static_cast<float>((*sPtr & 0xFF000000) >> 24);
++sPtr; ++sPtr;
if (dPtr >= ePtr) break; if (dPtr >= ePtr) break;
*(dPtr++) = XMVectorSet(d, s, 0.f, 1.f); *(dPtr++) = XMVectorSet(d, s, 0.f, 1.f);
@ -980,7 +980,7 @@ _Use_decl_annotations_ bool DirectX::_LoadScanline(
auto sPtr = static_cast<const uint32_t*>(pSource); auto sPtr = static_cast<const uint32_t*>(pSource);
for (size_t icount = 0; icount < (size - sizeof(uint32_t) + 1); icount += sizeof(uint32_t)) for (size_t icount = 0; icount < (size - sizeof(uint32_t) + 1); icount += sizeof(uint32_t))
{ {
float r = static_cast<float>(*sPtr & 0xFFFFFF) / 16777215.f; auto r = static_cast<float>(*sPtr & 0xFFFFFF) / 16777215.f;
++sPtr; ++sPtr;
if (dPtr >= ePtr) break; if (dPtr >= ePtr) break;
*(dPtr++) = XMVectorSet(r, 0.f /* typeless component assumed zero */, 0.f, 1.f); *(dPtr++) = XMVectorSet(r, 0.f /* typeless component assumed zero */, 0.f, 1.f);
@ -995,7 +995,7 @@ _Use_decl_annotations_ bool DirectX::_LoadScanline(
auto sPtr = static_cast<const uint32_t*>(pSource); auto sPtr = static_cast<const uint32_t*>(pSource);
for (size_t icount = 0; icount < (size - sizeof(uint32_t) + 1); icount += sizeof(uint32_t)) for (size_t icount = 0; icount < (size - sizeof(uint32_t) + 1); icount += sizeof(uint32_t))
{ {
float g = static_cast<float>((*sPtr & 0xFF000000) >> 24); auto g = static_cast<float>((*sPtr & 0xFF000000) >> 24);
++sPtr; ++sPtr;
if (dPtr >= ePtr) break; if (dPtr >= ePtr) break;
*(dPtr++) = XMVectorSet(0.f /* typeless component assumed zero */, g, 0.f, 1.f); *(dPtr++) = XMVectorSet(0.f /* typeless component assumed zero */, g, 0.f, 1.f);
@ -1325,9 +1325,9 @@ _Use_decl_annotations_ bool DirectX::_LoadScanline(
// G = 1.1678Y' - 0.3929Cb' - 0.8152Cr' // G = 1.1678Y' - 0.3929Cb' - 0.8152Cr'
// B = 1.1678Y' + 2.0232Cb' // B = 1.1678Y' + 2.0232Cb'
int r = static_cast<int>((76533 * y + 104905 * v + 32768) >> 16); auto r = static_cast<int>((76533 * y + 104905 * v + 32768) >> 16);
int g = static_cast<int>((76533 * y - 25747 * u - 53425 * v + 32768) >> 16); auto g = static_cast<int>((76533 * y - 25747 * u - 53425 * v + 32768) >> 16);
int b = static_cast<int>((76533 * y + 132590 * u + 32768) >> 16); auto b = static_cast<int>((76533 * y + 132590 * u + 32768) >> 16);
if (dPtr >= ePtr) break; if (dPtr >= ePtr) break;
*(dPtr++) = XMVectorSet(float(std::min<int>(std::max<int>(r, 0), 1023)) / 1023.f, *(dPtr++) = XMVectorSet(float(std::min<int>(std::max<int>(r, 0), 1023)) / 1023.f,
@ -1426,9 +1426,9 @@ _Use_decl_annotations_ bool DirectX::_LoadScanline(
++sPtr; ++sPtr;
// See Y410 // See Y410
int r = static_cast<int>((76533 * y0 + 104905 * v + 32768) >> 16); auto r = static_cast<int>((76533 * y0 + 104905 * v + 32768) >> 16);
int g = static_cast<int>((76533 * y0 - 25747 * u - 53425 * v + 32768) >> 16); auto g = static_cast<int>((76533 * y0 - 25747 * u - 53425 * v + 32768) >> 16);
int b = static_cast<int>((76533 * y0 + 132590 * u + 32768) >> 16); auto b = static_cast<int>((76533 * y0 + 132590 * u + 32768) >> 16);
if (dPtr >= ePtr) break; if (dPtr >= ePtr) break;
*(dPtr++) = XMVectorSet(float(std::min<int>(std::max<int>(r, 0), 1023)) / 1023.f, *(dPtr++) = XMVectorSet(float(std::min<int>(std::max<int>(r, 0), 1023)) / 1023.f,
@ -1463,9 +1463,9 @@ _Use_decl_annotations_ bool DirectX::_LoadScanline(
++sPtr; ++sPtr;
// See Y416 // See Y416
int r = static_cast<int>((76607 * y0 + 105006 * v + 32768) >> 16); auto r = static_cast<int>((76607 * y0 + 105006 * v + 32768) >> 16);
int g = static_cast<int>((76607 * y0 - 25772 * u - 53477 * v + 32768) >> 16); auto g = static_cast<int>((76607 * y0 - 25772 * u - 53477 * v + 32768) >> 16);
int b = static_cast<int>((76607 * y0 + 132718 * u + 32768) >> 16); auto b = static_cast<int>((76607 * y0 + 132718 * u + 32768) >> 16);
if (dPtr >= ePtr) break; if (dPtr >= ePtr) break;
*(dPtr++) = XMVectorSet(float(std::min<int>(std::max<int>(r, 0), 65535)) / 65535.f, *(dPtr++) = XMVectorSet(float(std::min<int>(std::max<int>(r, 0), 65535)) / 65535.f,
@ -1516,7 +1516,7 @@ _Use_decl_annotations_ bool DirectX::_LoadScanline(
FloatFrom7e3(sPtr->x), FloatFrom7e3(sPtr->x),
FloatFrom7e3(sPtr->y), FloatFrom7e3(sPtr->y),
FloatFrom7e3(sPtr->z), FloatFrom7e3(sPtr->z),
(float)(sPtr->v >> 30) / 3.0f static_cast<float>(sPtr->v >> 30) / 3.0f
} } }; } } };
++sPtr; ++sPtr;
@ -1540,7 +1540,7 @@ _Use_decl_annotations_ bool DirectX::_LoadScanline(
FloatFrom6e4(sPtr->x), FloatFrom6e4(sPtr->x),
FloatFrom6e4(sPtr->y), FloatFrom6e4(sPtr->y),
FloatFrom6e4(sPtr->z), FloatFrom6e4(sPtr->z),
(float)(sPtr->v >> 30) / 3.0f static_cast<float>(sPtr->v >> 30) / 3.0f
} } }; } } };
++sPtr; ++sPtr;
@ -1612,7 +1612,7 @@ bool DirectX::_StoreScanline(
float threshold) float threshold)
{ {
assert(pDestination && size > 0); assert(pDestination && size > 0);
assert(pSource && count > 0 && (((uintptr_t)pSource & 0xF) == 0)); assert(pSource && count > 0 && ((reinterpret_cast<uintptr_t>(pSource) & 0xF) == 0));
assert(IsValid(format) && !IsTypeless(format) && !IsCompressed(format) && !IsPlanar(format) && !IsPalettized(format)); assert(IsValid(format) && !IsTypeless(format) && !IsCompressed(format) && !IsPlanar(format) && !IsPalettized(format));
const XMVECTOR* __restrict sPtr = pSource; const XMVECTOR* __restrict sPtr = pSource;
@ -1689,7 +1689,7 @@ bool DirectX::_StoreScanline(
XMFLOAT4 f; XMFLOAT4 f;
XMStoreFloat4(&f, *sPtr++); XMStoreFloat4(&f, *sPtr++);
dPtr[0] = f.x; dPtr[0] = f.x;
uint8_t* ps8 = reinterpret_cast<uint8_t*>(&dPtr[1]); auto ps8 = reinterpret_cast<uint8_t*>(&dPtr[1]);
ps8[0] = static_cast<uint8_t>(std::min<float>(255.f, std::max<float>(0.f, f.y))); ps8[0] = static_cast<uint8_t>(std::min<float>(255.f, std::max<float>(0.f, f.y)));
ps8[1] = ps8[2] = ps8[3] = 0; ps8[1] = ps8[2] = ps8[3] = 0;
dPtr += 2; dPtr += 2;
@ -2417,7 +2417,7 @@ bool DirectX::_StoreScanline(
dPtr->x = FloatTo6e4(tmp.x); dPtr->x = FloatTo6e4(tmp.x);
dPtr->y = FloatTo6e4(tmp.y); dPtr->y = FloatTo6e4(tmp.y);
dPtr->z = FloatTo6e4(tmp.z); dPtr->z = FloatTo6e4(tmp.z);
dPtr->w = (uint32_t)tmp.w; dPtr->w = static_cast<uint32_t>(tmp.w);
++dPtr; ++dPtr;
} }
return true; return true;
@ -2645,7 +2645,7 @@ bool DirectX::_StoreScanlineLinear(
float threshold) float threshold)
{ {
assert(pDestination && size > 0); assert(pDestination && size > 0);
assert(pSource && count > 0 && (((uintptr_t)pSource & 0xF) == 0)); assert(pSource && count > 0 && ((reinterpret_cast<uintptr_t>(pSource) & 0xF) == 0));
assert(IsValid(format) && !IsTypeless(format) && !IsCompressed(format) && !IsPlanar(format) && !IsPalettized(format)); assert(IsValid(format) && !IsTypeless(format) && !IsCompressed(format) && !IsPlanar(format) && !IsPalettized(format));
switch (format) switch (format)
@ -2719,7 +2719,7 @@ bool DirectX::_LoadScanlineLinear(
DXGI_FORMAT format, DXGI_FORMAT format,
DWORD flags) DWORD flags)
{ {
assert(pDestination && count > 0 && (((uintptr_t)pDestination & 0xF) == 0)); assert(pDestination && count > 0 && ((reinterpret_cast<uintptr_t>(pDestination) & 0xF) == 0));
assert(pSource && size > 0); assert(pSource && size > 0);
assert(IsValid(format) && !IsTypeless(format, false) && !IsCompressed(format) && !IsPlanar(format) && !IsPalettized(format)); assert(IsValid(format) && !IsTypeless(format, false) && !IsCompressed(format) && !IsPlanar(format) && !IsPalettized(format));
@ -2906,9 +2906,9 @@ DWORD DirectX::_GetConvertFlags(DXGI_FORMAT format)
} }
#endif #endif
ConvertData key = { format, 0 }; ConvertData key = { format, 0, 0 };
const ConvertData* in = (const ConvertData*)bsearch_s(&key, g_ConvertTable, _countof(g_ConvertTable), sizeof(ConvertData), auto in = reinterpret_cast<const ConvertData*>(bsearch_s(&key, g_ConvertTable, _countof(g_ConvertTable), sizeof(ConvertData),
ConvertCompare, nullptr); ConvertCompare, nullptr));
return (in) ? in->flags : 0; return (in) ? in->flags : 0;
} }
@ -2920,7 +2920,7 @@ void DirectX::_ConvertScanline(
DXGI_FORMAT inFormat, DXGI_FORMAT inFormat,
DWORD flags) DWORD flags)
{ {
assert(pBuffer && count > 0 && (((uintptr_t)pBuffer & 0xF) == 0)); assert(pBuffer && count > 0 && ((reinterpret_cast<uintptr_t>(pBuffer) & 0xF) == 0));
assert(IsValid(outFormat) && !IsTypeless(outFormat) && !IsPlanar(outFormat) && !IsPalettized(outFormat)); assert(IsValid(outFormat) && !IsTypeless(outFormat) && !IsPlanar(outFormat) && !IsPalettized(outFormat));
assert(IsValid(inFormat) && !IsTypeless(inFormat) && !IsPlanar(inFormat) && !IsPalettized(inFormat)); assert(IsValid(inFormat) && !IsTypeless(inFormat) && !IsPlanar(inFormat) && !IsPalettized(inFormat));
@ -2939,12 +2939,12 @@ void DirectX::_ConvertScanline(
#endif #endif
// Determine conversion details about source and dest formats // Determine conversion details about source and dest formats
ConvertData key = { inFormat, 0 }; ConvertData key = { inFormat, 0, 0 };
const ConvertData* in = (const ConvertData*)bsearch_s(&key, g_ConvertTable, _countof(g_ConvertTable), sizeof(ConvertData), auto in = reinterpret_cast<const ConvertData*>(
ConvertCompare, nullptr); bsearch_s(&key, g_ConvertTable, _countof(g_ConvertTable), sizeof(ConvertData), ConvertCompare, nullptr));
key.format = outFormat; key.format = outFormat;
const ConvertData* out = (const ConvertData*)bsearch_s(&key, g_ConvertTable, _countof(g_ConvertTable), sizeof(ConvertData), auto out = reinterpret_cast<const ConvertData*>(
ConvertCompare, nullptr); bsearch_s(&key, g_ConvertTable, _countof(g_ConvertTable), sizeof(ConvertData), ConvertCompare, nullptr));
if (!in || !out) if (!in || !out)
{ {
assert(false); assert(false);
@ -3637,7 +3637,7 @@ namespace
type * __restrict dest = reinterpret_cast<type*>(pDestination); \ type * __restrict dest = reinterpret_cast<type*>(pDestination); \
for(size_t i = 0; i < count; ++i) \ for(size_t i = 0; i < count; ++i) \
{ \ { \
ptrdiff_t index = static_cast<ptrdiff_t>((row & 1) ? (count - i - 1) : i ); \ auto index = static_cast<ptrdiff_t>((row & 1) ? (count - i - 1) : i ); \
ptrdiff_t delta = (row & 1) ? -2 : 0; \ ptrdiff_t delta = (row & 1) ? -2 : 0; \
\ \
XMVECTOR v = sPtr[ index ]; \ XMVECTOR v = sPtr[ index ]; \
@ -3693,7 +3693,7 @@ namespace
type * __restrict dest = reinterpret_cast<type*>(pDestination); \ type * __restrict dest = reinterpret_cast<type*>(pDestination); \
for(size_t i = 0; i < count; ++i) \ for(size_t i = 0; i < count; ++i) \
{ \ { \
ptrdiff_t index = static_cast<ptrdiff_t>((row & 1) ? (count - i - 1) : i ); \ auto index = static_cast<ptrdiff_t>((row & 1) ? (count - i - 1) : i ); \
ptrdiff_t delta = (row & 1) ? -2 : 0; \ ptrdiff_t delta = (row & 1) ? -2 : 0; \
\ \
XMVECTOR v = sPtr[ index ]; \ XMVECTOR v = sPtr[ index ]; \
@ -3746,7 +3746,7 @@ namespace
type * __restrict dest = reinterpret_cast<type*>(pDestination); \ type * __restrict dest = reinterpret_cast<type*>(pDestination); \
for(size_t i = 0; i < count; ++i) \ for(size_t i = 0; i < count; ++i) \
{ \ { \
ptrdiff_t index = static_cast<ptrdiff_t>((row & 1) ? (count - i - 1) : i ); \ auto index = static_cast<ptrdiff_t>((row & 1) ? (count - i - 1) : i ); \
ptrdiff_t delta = (row & 1) ? -2 : 0; \ ptrdiff_t delta = (row & 1) ? -2 : 0; \
\ \
XMVECTOR v = sPtr[ index ]; \ XMVECTOR v = sPtr[ index ]; \
@ -3805,7 +3805,7 @@ bool DirectX::_StoreScanlineDither(
XMVECTOR* pDiffusionErrors) XMVECTOR* pDiffusionErrors)
{ {
assert(pDestination && size > 0); assert(pDestination && size > 0);
assert(pSource && count > 0 && (((uintptr_t)pSource & 0xF) == 0)); assert(pSource && count > 0 && ((reinterpret_cast<uintptr_t>(pSource) & 0xF) == 0));
assert(IsValid(format) && !IsTypeless(format) && !IsCompressed(format) && !IsPlanar(format) && !IsPalettized(format)); assert(IsValid(format) && !IsTypeless(format) && !IsCompressed(format) && !IsPlanar(format) && !IsPalettized(format));
XMVECTOR ordered[4]; XMVECTOR ordered[4];
@ -3879,7 +3879,7 @@ bool DirectX::_StoreScanlineDither(
XMUDEC4 * __restrict dest = static_cast<XMUDEC4*>(pDestination); XMUDEC4 * __restrict dest = static_cast<XMUDEC4*>(pDestination);
for (size_t i = 0; i < count; ++i) for (size_t i = 0; i < count; ++i)
{ {
ptrdiff_t index = static_cast<ptrdiff_t>((y & 1) ? (count - i - 1) : i); auto index = static_cast<ptrdiff_t>((y & 1) ? (count - i - 1) : i);
ptrdiff_t delta = (y & 1) ? -2 : 0; ptrdiff_t delta = (y & 1) ? -2 : 0;
XMVECTOR v = XMVectorClamp(sPtr[index], MinXR, MaxXR); XMVECTOR v = XMVectorClamp(sPtr[index], MinXR, MaxXR);
@ -3957,7 +3957,7 @@ bool DirectX::_StoreScanlineDither(
uint32_t * __restrict dest = static_cast<uint32_t*>(pDestination); uint32_t * __restrict dest = static_cast<uint32_t*>(pDestination);
for (size_t i = 0; i < count; ++i) for (size_t i = 0; i < count; ++i)
{ {
ptrdiff_t index = static_cast<ptrdiff_t>((y & 1) ? (count - i - 1) : i); auto index = static_cast<ptrdiff_t>((y & 1) ? (count - i - 1) : i);
ptrdiff_t delta = (y & 1) ? -2 : 0; ptrdiff_t delta = (y & 1) ? -2 : 0;
XMVECTOR v = XMVectorClamp(sPtr[index], g_XMZero, Clamp); XMVECTOR v = XMVectorClamp(sPtr[index], g_XMZero, Clamp);
@ -4044,7 +4044,7 @@ bool DirectX::_StoreScanlineDither(
XMU565 * __restrict dest = static_cast<XMU565*>(pDestination); XMU565 * __restrict dest = static_cast<XMU565*>(pDestination);
for (size_t i = 0; i < count; ++i) for (size_t i = 0; i < count; ++i)
{ {
ptrdiff_t index = static_cast<ptrdiff_t>((y & 1) ? (count - i - 1) : i); auto index = static_cast<ptrdiff_t>((y & 1) ? (count - i - 1) : i);
ptrdiff_t delta = (y & 1) ? -2 : 0; ptrdiff_t delta = (y & 1) ? -2 : 0;
XMVECTOR v = XMVectorSwizzle<2, 1, 0, 3>(sPtr[index]); XMVECTOR v = XMVectorSwizzle<2, 1, 0, 3>(sPtr[index]);
@ -4093,7 +4093,7 @@ bool DirectX::_StoreScanlineDither(
XMU555 * __restrict dest = static_cast<XMU555*>(pDestination); XMU555 * __restrict dest = static_cast<XMU555*>(pDestination);
for (size_t i = 0; i < count; ++i) for (size_t i = 0; i < count; ++i)
{ {
ptrdiff_t index = static_cast<ptrdiff_t>((y & 1) ? (count - i - 1) : i); auto index = static_cast<ptrdiff_t>((y & 1) ? (count - i - 1) : i);
ptrdiff_t delta = (y & 1) ? -2 : 0; ptrdiff_t delta = (y & 1) ? -2 : 0;
XMVECTOR v = XMVectorSwizzle<2, 1, 0, 3>(sPtr[index]); XMVECTOR v = XMVectorSwizzle<2, 1, 0, 3>(sPtr[index]);
@ -4148,7 +4148,7 @@ bool DirectX::_StoreScanlineDither(
XMUBYTEN4 * __restrict dest = static_cast<XMUBYTEN4*>(pDestination); XMUBYTEN4 * __restrict dest = static_cast<XMUBYTEN4*>(pDestination);
for (size_t i = 0; i < count; ++i) for (size_t i = 0; i < count; ++i)
{ {
ptrdiff_t index = static_cast<ptrdiff_t>((y & 1) ? (count - i - 1) : i); auto index = static_cast<ptrdiff_t>((y & 1) ? (count - i - 1) : i);
ptrdiff_t delta = (y & 1) ? -2 : 0; ptrdiff_t delta = (y & 1) ? -2 : 0;
XMVECTOR v = XMVectorSwizzle<2, 1, 0, 3>(sPtr[index]); XMVECTOR v = XMVectorSwizzle<2, 1, 0, 3>(sPtr[index]);
@ -4204,7 +4204,7 @@ bool DirectX::_StoreScanlineDither(
uint8_t * __restrict dest = static_cast<uint8_t*>(pDestination); uint8_t * __restrict dest = static_cast<uint8_t*>(pDestination);
for (size_t i = 0; i < count; ++i) for (size_t i = 0; i < count; ++i)
{ {
ptrdiff_t index = static_cast<ptrdiff_t>((y & 1) ? (count - i - 1) : i); auto index = static_cast<ptrdiff_t>((y & 1) ? (count - i - 1) : i);
ptrdiff_t delta = (y & 1) ? -2 : 0; ptrdiff_t delta = (y & 1) ? -2 : 0;
XMVECTOR v = XMVectorSaturate(sPtr[index]); XMVECTOR v = XMVectorSaturate(sPtr[index]);
@ -4238,8 +4238,7 @@ bool DirectX::_StoreScanlineDither(
auto dPtr = &dest[index]; auto dPtr = &dest[index];
if (dPtr >= ePtr) break; if (dPtr >= ePtr) break;
*dPtr = (static_cast<uint8_t>(tmp.x) & 0xF) *dPtr = static_cast<uint8_t>((unsigned(tmp.x) & 0xF) | ((unsigned(tmp.y) & 0xF) << 4));
| ((static_cast<uint8_t>(tmp.y) & 0xF) << 4);
} }
return true; return true;
} }

View File

@ -9,7 +9,7 @@
// http://go.microsoft.com/fwlink/?LinkId=248926 // http://go.microsoft.com/fwlink/?LinkId=248926
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
#include "directxtexp.h" #include "DirectXTexp.h"
#if !defined(_XBOX_ONE) || !defined(_TITLE) #if !defined(_XBOX_ONE) || !defined(_TITLE)
#include <d3d10.h> #include <d3d10.h>
@ -763,7 +763,7 @@ HRESULT DirectX::CaptureTexture(
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ; desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
desc.Usage = D3D11_USAGE_STAGING; desc.Usage = D3D11_USAGE_STAGING;
hr = pDevice->CreateTexture1D(&desc, 0, pStaging.GetAddressOf()); hr = pDevice->CreateTexture1D(&desc, nullptr, pStaging.GetAddressOf());
if (FAILED(hr)) if (FAILED(hr))
break; break;
@ -809,7 +809,7 @@ HRESULT DirectX::CaptureTexture(
desc.SampleDesc.Quality = 0; desc.SampleDesc.Quality = 0;
ComPtr<ID3D11Texture2D> pTemp; ComPtr<ID3D11Texture2D> pTemp;
hr = pDevice->CreateTexture2D(&desc, 0, pTemp.GetAddressOf()); hr = pDevice->CreateTexture2D(&desc, nullptr, pTemp.GetAddressOf());
if (FAILED(hr)) if (FAILED(hr))
break; break;
@ -848,7 +848,7 @@ HRESULT DirectX::CaptureTexture(
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ; desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
desc.Usage = D3D11_USAGE_STAGING; desc.Usage = D3D11_USAGE_STAGING;
hr = pDevice->CreateTexture2D(&desc, 0, pStaging.GetAddressOf()); hr = pDevice->CreateTexture2D(&desc, nullptr, pStaging.GetAddressOf());
if (FAILED(hr)) if (FAILED(hr))
break; break;
@ -868,7 +868,7 @@ HRESULT DirectX::CaptureTexture(
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ; desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
desc.Usage = D3D11_USAGE_STAGING; desc.Usage = D3D11_USAGE_STAGING;
hr = pDevice->CreateTexture2D(&desc, 0, &pStaging); hr = pDevice->CreateTexture2D(&desc, nullptr, &pStaging);
if (FAILED(hr)) if (FAILED(hr))
break; break;
@ -921,7 +921,7 @@ HRESULT DirectX::CaptureTexture(
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ; desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
desc.Usage = D3D11_USAGE_STAGING; desc.Usage = D3D11_USAGE_STAGING;
hr = pDevice->CreateTexture3D(&desc, 0, pStaging.GetAddressOf()); hr = pDevice->CreateTexture3D(&desc, nullptr, pStaging.GetAddressOf());
if (FAILED(hr)) if (FAILED(hr))
break; break;

View File

@ -9,7 +9,7 @@
// http://go.microsoft.com/fwlink/?LinkId=248926 // http://go.microsoft.com/fwlink/?LinkId=248926
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
#include "directxtexp.h" #include "DirectXTexp.h"
#if defined(_XBOX_ONE) && defined(_TITLE) #if defined(_XBOX_ONE) && defined(_TITLE)
#include "d3dx12_x.h" #include "d3dx12_x.h"
@ -52,7 +52,7 @@ namespace
else else
{ {
// Plane 1 // Plane 1
res.pData = (uint8_t*)(res.pData) + res.RowPitch * height; res.pData = const_cast<uint8_t*>(reinterpret_cast<const uint8_t*>(res.pData) + res.RowPitch * height);
res.SlicePitch = res.RowPitch * ((height + 1) >> 1); res.SlicePitch = res.RowPitch * ((height + 1) >> 1);
} }
break; break;
@ -66,7 +66,7 @@ namespace
else else
{ {
// Plane 1 // Plane 1
res.pData = (uint8_t*)(res.pData) + res.RowPitch * height; res.pData = const_cast<uint8_t*>(reinterpret_cast<const uint8_t*>(res.pData) + res.RowPitch * height);
res.RowPitch = (res.RowPitch >> 1); res.RowPitch = (res.RowPitch >> 1);
res.SlicePitch = res.RowPitch * height; res.SlicePitch = res.RowPitch * height;
} }
@ -82,8 +82,8 @@ namespace
_In_ D3D12_RESOURCE_STATES stateBefore, _In_ D3D12_RESOURCE_STATES stateBefore,
_In_ D3D12_RESOURCE_STATES stateAfter) _In_ D3D12_RESOURCE_STATES stateAfter)
{ {
assert(commandList != 0); assert(commandList != nullptr);
assert(resource != 0); assert(resource != nullptr);
if (stateBefore == stateAfter) if (stateBefore == stateAfter)
return; return;
@ -223,7 +223,7 @@ namespace
fmt = MakeTypelessFLOAT(fmt); fmt = MakeTypelessFLOAT(fmt);
} }
D3D12_FEATURE_DATA_FORMAT_SUPPORT formatInfo = { fmt }; D3D12_FEATURE_DATA_FORMAT_SUPPORT formatInfo = { fmt, D3D12_FORMAT_SUPPORT1_NONE, D3D12_FORMAT_SUPPORT2_NONE };
hr = device->CheckFeatureSupport(D3D12_FEATURE_FORMAT_SUPPORT, &formatInfo, sizeof(formatInfo)); hr = device->CheckFeatureSupport(D3D12_FEATURE_FORMAT_SUPPORT, &formatInfo, sizeof(formatInfo));
if (FAILED(hr)) if (FAILED(hr))
return hr; return hr;
@ -278,7 +278,7 @@ namespace
return hr; return hr;
// Execute the command list // Execute the command list
pCommandQ->ExecuteCommandLists(1, (ID3D12CommandList**)commandList.GetAddressOf()); pCommandQ->ExecuteCommandLists(1, CommandListCast(commandList.GetAddressOf()));
// Signal the fence // Signal the fence
hr = pCommandQ->Signal(fence.Get(), 1); hr = pCommandQ->Signal(fence.Get(), 1);
@ -326,7 +326,7 @@ bool DirectX::IsSupportedTexture(
size_t iDepth = metadata.depth; 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 // Most cases are known apriori based on feature level, but we use this for robustness to handle the few optional cases
D3D12_FEATURE_DATA_FORMAT_SUPPORT formatSupport = { fmt }; D3D12_FEATURE_DATA_FORMAT_SUPPORT formatSupport = { fmt, D3D12_FORMAT_SUPPORT1_NONE, D3D12_FORMAT_SUPPORT2_NONE };
HRESULT hr = pDevice->CheckFeatureSupport(D3D12_FEATURE_FORMAT_SUPPORT, &formatSupport, sizeof(formatSupport)); HRESULT hr = pDevice->CheckFeatureSupport(D3D12_FEATURE_FORMAT_SUPPORT, &formatSupport, sizeof(formatSupport));
if (FAILED(hr)) if (FAILED(hr))
{ {
@ -349,7 +349,7 @@ bool DirectX::IsSupportedTexture(
return false; return false;
{ {
UINT numberOfResources = static_cast<UINT>(arraySize * metadata.mipLevels); auto numberOfResources = static_cast<UINT>(arraySize * metadata.mipLevels);
if (numberOfResources > D3D12_REQ_SUBRESOURCES) if (numberOfResources > D3D12_REQ_SUBRESOURCES)
return false; return false;
} }
@ -378,7 +378,7 @@ bool DirectX::IsSupportedTexture(
} }
{ {
UINT numberOfResources = static_cast<UINT>(arraySize * metadata.mipLevels); auto numberOfResources = static_cast<UINT>(arraySize * metadata.mipLevels);
if (numberOfResources > D3D12_REQ_SUBRESOURCES) if (numberOfResources > D3D12_REQ_SUBRESOURCES)
return false; return false;
} }
@ -395,7 +395,7 @@ bool DirectX::IsSupportedTexture(
return false; return false;
{ {
UINT numberOfResources = static_cast<UINT>(metadata.mipLevels); auto numberOfResources = static_cast<UINT>(metadata.mipLevels);
if (numberOfResources > D3D12_REQ_SUBRESOURCES) if (numberOfResources > D3D12_REQ_SUBRESOURCES)
return false; return false;
} }
@ -785,7 +785,7 @@ HRESULT DirectX::CaptureTexture(
static_cast<LONG_PTR>(pLayout[dindex].Footprint.RowPitch * pNumRows[dindex]) static_cast<LONG_PTR>(pLayout[dindex].Footprint.RowPitch * pNumRows[dindex])
}; };
if (pRowSizesInBytes[dindex] > (SIZE_T)-1) if (pRowSizesInBytes[dindex] > SIZE_T(-1))
{ {
pStaging->Unmap(0, nullptr); pStaging->Unmap(0, nullptr);
result.Release(); result.Release();
@ -793,7 +793,7 @@ HRESULT DirectX::CaptureTexture(
} }
MemcpySubresource(&destData, &srcData, MemcpySubresource(&destData, &srcData,
(SIZE_T)pRowSizesInBytes[dindex], static_cast<SIZE_T>(pRowSizesInBytes[dindex]),
pNumRows[dindex], pNumRows[dindex],
pLayout[dindex].Footprint.Depth); pLayout[dindex].Footprint.Depth);
} }

View File

@ -9,7 +9,7 @@
// http://go.microsoft.com/fwlink/?LinkId=248926 // http://go.microsoft.com/fwlink/?LinkId=248926
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
#include "directxtexp.h" #include "DirectXTexp.h"
#include "dds.h" #include "dds.h"
@ -287,7 +287,7 @@ namespace
return E_FAIL; return E_FAIL;
} }
auto pHeader = reinterpret_cast<const DDS_HEADER*>((const uint8_t*)pSource + sizeof(uint32_t)); auto pHeader = reinterpret_cast<const DDS_HEADER*>(static_cast<const uint8_t*>(pSource) + sizeof(uint32_t));
// Verify header to validate DDS file // Verify header to validate DDS file
if (pHeader->size != sizeof(DDS_HEADER) if (pHeader->size != sizeof(DDS_HEADER)
@ -310,7 +310,7 @@ namespace
return E_FAIL; return E_FAIL;
} }
auto d3d10ext = reinterpret_cast<const DDS_HEADER_DXT10*>((const uint8_t*)pSource + sizeof(uint32_t) + sizeof(DDS_HEADER)); auto d3d10ext = reinterpret_cast<const DDS_HEADER_DXT10*>(static_cast<const uint8_t*>(pSource) + sizeof(uint32_t) + sizeof(DDS_HEADER));
convFlags |= CONV_FLAGS_DX10; convFlags |= CONV_FLAGS_DX10;
metadata.arraySize = d3d10ext->arraySize; metadata.arraySize = d3d10ext->arraySize;
@ -504,6 +504,7 @@ namespace
convFlags |= CONV_FLAGS_EXPAND; convFlags |= CONV_FLAGS_EXPAND;
if (metadata.format == DXGI_FORMAT_B5G6R5_UNORM) if (metadata.format == DXGI_FORMAT_B5G6R5_UNORM)
convFlags |= CONV_FLAGS_NOALPHA; convFlags |= CONV_FLAGS_NOALPHA;
break;
default: default:
break; break;
@ -877,13 +878,13 @@ namespace
for (size_t ocount = 0, icount = 0; ((icount < inSize) && (ocount < (outSize - 1))); ++icount, ocount += 2) for (size_t ocount = 0, icount = 0; ((icount < inSize) && (ocount < (outSize - 1))); ++icount, ocount += 2)
{ {
uint8_t t = *(sPtr++); unsigned t = *(sPtr++);
uint16_t t1 = ((t & 0xe0) << 8) | ((t & 0xc0) << 5); unsigned t1 = ((t & 0xe0u) << 8) | ((t & 0xc0u) << 5);
uint16_t t2 = ((t & 0x1c) << 6) | ((t & 0x1c) << 3); unsigned t2 = ((t & 0x1cu) << 6) | ((t & 0x1cu) << 3);
uint16_t t3 = ((t & 0x03) << 3) | ((t & 0x03) << 1) | ((t & 0x02) >> 1); unsigned t3 = ((t & 0x03u) << 3) | ((t & 0x03u) << 1) | ((t & 0x02) >> 1);
*(dPtr++) = t1 | t2 | t3; *(dPtr++) = static_cast<uint16_t>(t1 | t2 | t3);
} }
return true; return true;
} }
@ -892,7 +893,6 @@ namespace
default: default:
return false; return false;
} }
break;
case TEXP_LEGACY_A8R3G3B2: case TEXP_LEGACY_A8R3G3B2:
if (outFormat != DXGI_FORMAT_R8G8B8A8_UNORM) if (outFormat != DXGI_FORMAT_R8G8B8A8_UNORM)
@ -974,12 +974,12 @@ namespace
for (size_t ocount = 0, icount = 0; ((icount < inSize) && (ocount < (outSize - 1))); ++icount, ocount += 2) for (size_t ocount = 0, icount = 0; ((icount < inSize) && (ocount < (outSize - 1))); ++icount, ocount += 2)
{ {
uint8_t t = *(sPtr++); unsigned t = *(sPtr++);
uint16_t t1 = (t & 0x0f); unsigned t1 = (t & 0x0fu);
uint16_t ta = (flags & TEXP_SCANLINE_SETALPHA) ? 0xf000 : ((t & 0xf0) << 8); unsigned ta = (flags & TEXP_SCANLINE_SETALPHA) ? 0xf000u : ((t & 0xf0u) << 8);
*(dPtr++) = t1 | (t1 << 4) | (t1 << 8) | ta; *(dPtr++) = static_cast<uint16_t>(t1 | (t1 << 4) | (t1 << 8) | ta);
} }
return true; return true;
} }
@ -1008,7 +1008,6 @@ namespace
default: default:
return false; return false;
} }
break;
case TEXP_LEGACY_B4G4R4A4: case TEXP_LEGACY_B4G4R4A4:
if (outFormat != DXGI_FORMAT_R8G8B8A8_UNORM) if (outFormat != DXGI_FORMAT_R8G8B8A8_UNORM)
@ -1158,7 +1157,13 @@ namespace
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
} }
if (!_SetupImageArray((uint8_t*)pPixels, pixelSize, metadata, cpFlags, timages.get(), nimages)) if (!_SetupImageArray(
const_cast<uint8_t*>(reinterpret_cast<const uint8_t*>(pPixels)),
pixelSize,
metadata,
cpFlags,
timages.get(),
nimages))
{ {
return E_FAIL; return E_FAIL;
} }
@ -1646,7 +1651,7 @@ HRESULT DirectX::LoadFromDDSFile(
{ {
// Must reset file position since we read more than the standard header above // Must reset file position since we read more than the standard header above
LARGE_INTEGER filePos = { { sizeof(uint32_t) + sizeof(DDS_HEADER), 0 } }; LARGE_INTEGER filePos = { { sizeof(uint32_t) + sizeof(DDS_HEADER), 0 } };
if (!SetFilePointerEx(hFile.get(), filePos, 0, FILE_BEGIN)) if (!SetFilePointerEx(hFile.get(), filePos, nullptr, FILE_BEGIN))
{ {
return HRESULT_FROM_WIN32(GetLastError()); return HRESULT_FROM_WIN32(GetLastError());
} }
@ -1777,7 +1782,7 @@ HRESULT DirectX::SaveToDDSMemory(
// Determine memory required // Determine memory required
size_t required = 0; size_t required = 0;
HRESULT hr = _EncodeDDSHeader(metadata, flags, 0, 0, required); HRESULT hr = _EncodeDDSHeader(metadata, flags, nullptr, 0, required);
if (FAILED(hr)) if (FAILED(hr))
return hr; return hr;
@ -1832,7 +1837,7 @@ HRESULT DirectX::SaveToDDSMemory(
return E_FAIL; return E_FAIL;
} }
switch (metadata.dimension) switch (static_cast<DDS_RESOURCE_DIMENSION>(metadata.dimension))
{ {
case DDS_DIMENSION_TEXTURE1D: case DDS_DIMENSION_TEXTURE1D:
case DDS_DIMENSION_TEXTURE2D: case DDS_DIMENSION_TEXTURE2D:
@ -2024,7 +2029,7 @@ HRESULT DirectX::SaveToDDSFile(
} }
// Write images // Write images
switch (metadata.dimension) switch (static_cast<DDS_RESOURCE_DIMENSION>(metadata.dimension))
{ {
case DDS_DIMENSION_TEXTURE1D: case DDS_DIMENSION_TEXTURE1D:
case DDS_DIMENSION_TEXTURE2D: case DDS_DIMENSION_TEXTURE2D:

View File

@ -9,7 +9,7 @@
// http://go.microsoft.com/fwlink/?LinkId=248926 // http://go.microsoft.com/fwlink/?LinkId=248926
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
#include "directxtexp.h" #include "DirectXTexp.h"
using namespace DirectX; using namespace DirectX;
using Microsoft::WRL::ComPtr; using Microsoft::WRL::ComPtr;

View File

@ -9,7 +9,7 @@
// http://go.microsoft.com/fwlink/?LinkId=248926 // http://go.microsoft.com/fwlink/?LinkId=248926
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
#include "directxtexp.h" #include "DirectXTexp.h"
// //
// In theory HDR (RGBE) Radiance files can have any of the following data orientations // In theory HDR (RGBE) Radiance files can have any of the following data orientations
@ -175,7 +175,7 @@ namespace
char buff[32] = {}; char buff[32] = {};
strncpy_s(buff, info, std::min<size_t>(31, len)); strncpy_s(buff, info, std::min<size_t>(31, len));
float newExposure = static_cast<float>(atof(buff)); auto newExposure = static_cast<float>(atof(buff));
if ((newExposure >= 1e-12) && (newExposure <= 1e12)) if ((newExposure >= 1e-12) && (newExposure <= 1e12))
{ {
// Note that we ignore strange exposure values (like EXPOSURE=0) // Note that we ignore strange exposure values (like EXPOSURE=0)
@ -347,7 +347,7 @@ namespace
for (size_t pixelCount = 0; pixelCount < width;) for (size_t pixelCount = 0; pixelCount < width;)
{ {
size_t spanLen = 1; size_t spanLen = 1;
const uint32_t* spanPtr = reinterpret_cast<const uint32_t*>(scanPtr); auto spanPtr = reinterpret_cast<const uint32_t*>(scanPtr);
while (pixelCount + spanLen < width && spanLen < 32767) while (pixelCount + spanLen < width && spanLen < 32767)
{ {
if (spanPtr[spanLen] == *spanPtr) if (spanPtr[spanLen] == *spanPtr)
@ -368,7 +368,7 @@ namespace
if (encSize + 8 > rowPitch) if (encSize + 8 > rowPitch)
return 0; return 0;
uint8_t rleLen = static_cast<uint8_t>(std::min<size_t>(spanLen - 1, 255)); auto rleLen = static_cast<uint8_t>(std::min<size_t>(spanLen - 1, 255));
enc[0] = scanPtr[0]; enc[0] = scanPtr[0];
enc[1] = scanPtr[1]; enc[1] = scanPtr[1];
@ -676,7 +676,7 @@ HRESULT DirectX::LoadFromHDRMemory(const void* pSource, size_t size, TexMetadata
return E_FAIL; return E_FAIL;
} }
float val = static_cast<float>(sourcePtr[1]); auto val = static_cast<float>(sourcePtr[1]);
for (uint8_t j = 0; j < runLen; ++j) for (uint8_t j = 0; j < runLen; ++j)
{ {
*pixelLoc = val; *pixelLoc = val;
@ -696,7 +696,7 @@ HRESULT DirectX::LoadFromHDRMemory(const void* pSource, size_t size, TexMetadata
++sourcePtr; ++sourcePtr;
for (uint8_t j = 0; j < runLen; ++j) for (uint8_t j = 0; j < runLen; ++j)
{ {
float val = static_cast<float>(*sourcePtr++); auto val = static_cast<float>(*sourcePtr++);
*pixelLoc = val; *pixelLoc = val;
pixelLoc += 4; pixelLoc += 4;
} }
@ -782,7 +782,7 @@ HRESULT DirectX::LoadFromHDRMemory(const void* pSource, size_t size, TexMetadata
for (size_t j = 0; j < image.GetPixelsSize(); j += 16) for (size_t j = 0; j < image.GetPixelsSize(); j += 16)
{ {
int exponent = static_cast<int>(fdata[3]); auto exponent = static_cast<int>(fdata[3]);
fdata[0] = 1.0f / exposure*ldexpf((fdata[0] + 0.5f), exponent - (128 + 8)); 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[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)); fdata[2] = 1.0f / exposure*ldexpf((fdata[2] + 0.5f), exponent - (128 + 8));
@ -909,7 +909,7 @@ HRESULT DirectX::SaveToHDRMemory(const Image& image, Blob& blob)
// Copy header // Copy header
auto dPtr = static_cast<uint8_t*>(blob.GetBufferPointer()); auto dPtr = static_cast<uint8_t*>(blob.GetBufferPointer());
assert(dPtr != 0); assert(dPtr != nullptr);
memcpy_s(dPtr, blob.GetBufferSize(), header, headerLen); memcpy_s(dPtr, blob.GetBufferSize(), header, headerLen);
dPtr += headerLen; dPtr += headerLen;
@ -1024,7 +1024,7 @@ HRESULT DirectX::SaveToHDRFile(const Image& image, const wchar_t* szFile)
return hr; return hr;
// Write blob // Write blob
const DWORD bytesToWrite = static_cast<DWORD>(blob.GetBufferSize()); auto bytesToWrite = static_cast<const DWORD>(blob.GetBufferSize());
DWORD bytesWritten; DWORD bytesWritten;
if (!WriteFile(hFile.get(), blob.GetBufferPointer(), bytesToWrite, &bytesWritten, nullptr)) if (!WriteFile(hFile.get(), blob.GetBufferPointer(), bytesToWrite, &bytesWritten, nullptr))
{ {

View File

@ -9,7 +9,7 @@
// http://go.microsoft.com/fwlink/?LinkId=248926 // http://go.microsoft.com/fwlink/?LinkId=248926
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
#include "directxtexp.h" #include "DirectXTexp.h"
namespace DirectX namespace DirectX
{ {

View File

@ -9,7 +9,7 @@
// http://go.microsoft.com/fwlink/?LinkId=248926 // http://go.microsoft.com/fwlink/?LinkId=248926
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
#include "directxtexp.h" #include "DirectXTexp.h"
#include "filters.h" #include "filters.h"
@ -1214,7 +1214,7 @@ namespace
{ {
// Steal and reuse scanline from 'free row' list // Steal and reuse scanline from 'free row' list
// (it will always be at least as wide as nwidth due to loop decending order) // (it will always be at least as wide as nwidth due to loop decending order)
assert(rowFree->scanline != 0); assert(rowFree->scanline != nullptr);
rowAcc->scanline.reset(rowFree->scanline.release()); rowAcc->scanline.reset(rowFree->scanline.release());
rowFree = rowFree->next; rowFree = rowFree->next;
} }
@ -2368,7 +2368,7 @@ namespace
{ {
// Steal and reuse scanline from 'free slice' list // Steal and reuse scanline from 'free slice' list
// (it will always be at least as large as nwidth*nheight due to loop decending order) // (it will always be at least as large as nwidth*nheight due to loop decending order)
assert(sliceFree->scanline != 0); assert(sliceFree->scanline != nullptr);
sliceAcc->scanline.reset(sliceFree->scanline.release()); sliceAcc->scanline.reset(sliceFree->scanline.release());
sliceFree = sliceFree->next; sliceFree = sliceFree->next;
} }
@ -2609,7 +2609,6 @@ HRESULT DirectX::GenerateMipMaps(
return _ConvertFromR32G32B32A32(tMipChain.GetImages(), tMipChain.GetImageCount(), tMipChain.GetMetadata(), baseImage.format, mipChain); return _ConvertFromR32G32B32A32(tMipChain.GetImages(), tMipChain.GetImageCount(), tMipChain.GetMetadata(), baseImage.format, mipChain);
} }
} }
break;
default: default:
return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED); return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED);
@ -2815,7 +2814,6 @@ HRESULT DirectX::GenerateMipMaps(
return _ConvertFromR32G32B32A32(tMipChain.GetImages(), tMipChain.GetImageCount(), tMipChain.GetMetadata(), metadata.format, mipChain); return _ConvertFromR32G32B32A32(tMipChain.GetImages(), tMipChain.GetImageCount(), tMipChain.GetMetadata(), metadata.format, mipChain);
} }
} }
break;
default: default:
return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED); return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED);

View File

@ -9,7 +9,7 @@
// http://go.microsoft.com/fwlink/?LinkId=248926 // http://go.microsoft.com/fwlink/?LinkId=248926
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
#include "directxtexp.h" #include "DirectXTexp.h"
using namespace DirectX; using namespace DirectX;

View File

@ -9,7 +9,7 @@
// http://go.microsoft.com/fwlink/?LinkId=248926 // http://go.microsoft.com/fwlink/?LinkId=248926
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
#include "directxtexp.h" #include "DirectXTexp.h"
using namespace DirectX; using namespace DirectX;
@ -38,7 +38,6 @@ namespace
XMStoreFloat4A(&f, v); XMStoreFloat4A(&f, v);
return f.x + f.y + f.z; return f.x + f.y + f.z;
} }
break;
default: default:
assert(false); assert(false);

View File

@ -75,6 +75,8 @@
#include <d3d11_1.h> #include <d3d11_1.h>
#endif #endif
#define _XM_NO_XMVECTOR_OVERLOADS_
#include <directxmath.h> #include <directxmath.h>
#include <directxpackedvector.h> #include <directxpackedvector.h>
#include <assert.h> #include <assert.h>

View File

@ -9,7 +9,7 @@
// http://go.microsoft.com/fwlink/?LinkId=248926 // http://go.microsoft.com/fwlink/?LinkId=248926
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
#include "directxtexp.h" #include "DirectXTexp.h"
using namespace DirectX; using namespace DirectX;

View File

@ -9,7 +9,7 @@
// http://go.microsoft.com/fwlink/?LinkId=248926 // http://go.microsoft.com/fwlink/?LinkId=248926
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
#include "directxtexp.h" #include "DirectXTexp.h"
#include "filters.h" #include "filters.h"
@ -678,7 +678,7 @@ namespace
if (rowFree) if (rowFree)
{ {
// Steal and reuse scanline from 'free row' list // Steal and reuse scanline from 'free row' list
assert(rowFree->scanline != 0); assert(rowFree->scanline != nullptr);
rowAcc->scanline.reset(rowFree->scanline.release()); rowAcc->scanline.reset(rowFree->scanline.release());
rowFree = rowFree->next; rowFree = rowFree->next;
} }

View File

@ -9,7 +9,7 @@
// http://go.microsoft.com/fwlink/?LinkId=248926 // http://go.microsoft.com/fwlink/?LinkId=248926
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
#include "directxtexp.h" #include "DirectXTexp.h"
// //
// The implementation here has the following limitations: // The implementation here has the following limitations:
@ -42,8 +42,6 @@ namespace
TGA_FLAGS_INTERLEAVED_4WAY = 0x80, // Deprecated TGA_FLAGS_INTERLEAVED_4WAY = 0x80, // Deprecated
}; };
const char* g_TGA20_Signature = "TRUEVISION-XFILE.";
#pragma pack(push,1) #pragma pack(push,1)
struct TGA_HEADER struct TGA_HEADER
{ {
@ -373,7 +371,7 @@ namespace
if (sPtr + 1 >= endPtr) if (sPtr + 1 >= endPtr)
return E_FAIL; return E_FAIL;
uint16_t t = *sPtr | (*(sPtr + 1) << 8); auto t = static_cast<uint16_t>(unsigned(*sPtr) | (*(sPtr + 1u) << 8));
if (t & 0x8000) if (t & 0x8000)
nonzeroa = true; nonzeroa = true;
sPtr += 2; sPtr += 2;
@ -405,7 +403,7 @@ namespace
if (x >= image->width) if (x >= image->width)
return E_FAIL; return E_FAIL;
uint16_t t = *sPtr | (*(sPtr + 1) << 8); auto t = static_cast<uint16_t>(unsigned(*sPtr) | (*(sPtr + 1u) << 8));
if (t & 0x8000) if (t & 0x8000)
nonzeroa = true; nonzeroa = true;
sPtr += 2; sPtr += 2;
@ -650,7 +648,7 @@ namespace
if (sPtr + 1 >= endPtr) if (sPtr + 1 >= endPtr)
return E_FAIL; return E_FAIL;
uint16_t t = *sPtr | (*(sPtr + 1) << 8); auto t = static_cast<uint16_t>(unsigned(*sPtr) | (*(sPtr + 1u) << 8));
sPtr += 2; sPtr += 2;
*dPtr = t; *dPtr = t;
@ -860,7 +858,7 @@ HRESULT DirectX::GetMetadataFromTGAMemory(
return E_INVALIDARG; return E_INVALIDARG;
size_t offset; size_t offset;
return DecodeTGAHeader(pSource, size, metadata, offset, 0); return DecodeTGAHeader(pSource, size, metadata, offset, nullptr);
} }
_Use_decl_annotations_ _Use_decl_annotations_
@ -908,7 +906,7 @@ HRESULT DirectX::GetMetadataFromTGAFile(const wchar_t* szFile, TexMetadata& meta
} }
size_t offset; size_t offset;
return DecodeTGAHeader(header, bytesRead, metadata, offset, 0); return DecodeTGAHeader(header, bytesRead, metadata, offset, nullptr);
} }
@ -1029,7 +1027,7 @@ HRESULT DirectX::LoadFromTGAFile(
return hr; return hr;
// Read the pixels // Read the pixels
DWORD remaining = static_cast<DWORD>(fileInfo.EndOfFile.LowPart - offset); auto remaining = static_cast<DWORD>(fileInfo.EndOfFile.LowPart - offset);
if (remaining == 0) if (remaining == 0)
return E_FAIL; return E_FAIL;
@ -1037,7 +1035,7 @@ HRESULT DirectX::LoadFromTGAFile(
{ {
// Skip past the id string // Skip past the id string
LARGE_INTEGER filePos = { { static_cast<DWORD>(offset), 0 } }; LARGE_INTEGER filePos = { { static_cast<DWORD>(offset), 0 } };
if (!SetFilePointerEx(hFile.get(), filePos, 0, FILE_BEGIN)) if (!SetFilePointerEx(hFile.get(), filePos, nullptr, FILE_BEGIN))
{ {
return HRESULT_FROM_WIN32(GetLastError()); return HRESULT_FROM_WIN32(GetLastError());
} }
@ -1091,7 +1089,7 @@ HRESULT DirectX::LoadFromTGAFile(
for (size_t h = 0; h < img->height; ++h) for (size_t h = 0; h < img->height; ++h)
{ {
const uint32_t* sPtr = reinterpret_cast<const uint32_t*>(pPixels); auto sPtr = reinterpret_cast<const uint32_t*>(pPixels);
for (size_t x = 0; x < img->width; ++x) for (size_t x = 0; x < img->width; ++x)
{ {
@ -1149,7 +1147,7 @@ HRESULT DirectX::LoadFromTGAFile(
for (size_t h = 0; h < img->height; ++h) for (size_t h = 0; h < img->height; ++h)
{ {
const uint16_t* sPtr = reinterpret_cast<const uint16_t*>(pPixels); auto sPtr = reinterpret_cast<const uint16_t*>(pPixels);
for (size_t x = 0; x < img->width; ++x) for (size_t x = 0; x < img->width; ++x)
{ {
@ -1264,7 +1262,7 @@ HRESULT DirectX::SaveToTGAMemory(const Image& image, Blob& blob)
// Copy header // Copy header
auto dPtr = static_cast<uint8_t*>(blob.GetBufferPointer()); auto dPtr = static_cast<uint8_t*>(blob.GetBufferPointer());
assert(dPtr != 0); assert(dPtr != nullptr);
memcpy_s(dPtr, blob.GetBufferSize(), &tga_header, sizeof(TGA_HEADER)); memcpy_s(dPtr, blob.GetBufferSize(), &tga_header, sizeof(TGA_HEADER));
dPtr += sizeof(TGA_HEADER); dPtr += sizeof(TGA_HEADER);

View File

@ -9,7 +9,7 @@
// http://go.microsoft.com/fwlink/?LinkId=248926 // http://go.microsoft.com/fwlink/?LinkId=248926
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
#include "directxtexp.h" #include "DirectXTexp.h"
#if defined(_XBOX_ONE) && defined(_TITLE) #if defined(_XBOX_ONE) && defined(_TITLE)
static_assert(XBOX_DXGI_FORMAT_R10G10B10_7E3_A2_FLOAT == DXGI_FORMAT_R10G10B10_7E3_A2_FLOAT, "Xbox One XDK mismatch detected"); static_assert(XBOX_DXGI_FORMAT_R10G10B10_7E3_A2_FLOAT == DXGI_FORMAT_R10G10B10_7E3_A2_FLOAT, "Xbox One XDK mismatch detected");
@ -71,6 +71,48 @@ namespace
bool g_WIC2 = false; bool g_WIC2 = false;
IWICImagingFactory* g_Factory = nullptr; IWICImagingFactory* g_Factory = nullptr;
BOOL WINAPI InitializeWICFactory(PINIT_ONCE, PVOID, PVOID *ifactory) noexcept
{
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE)
HRESULT hr = CoCreateInstance(
CLSID_WICImagingFactory2,
nullptr,
CLSCTX_INPROC_SERVER,
__uuidof(IWICImagingFactory2),
ifactory
);
if (SUCCEEDED(hr))
{
// WIC2 is available on Windows 10, Windows 8.x, and Windows 7 SP1 with KB 2670838 installed
g_WIC2 = true;
return TRUE;
}
else
{
g_WIC2 = false;
hr = CoCreateInstance(
CLSID_WICImagingFactory1,
nullptr,
CLSCTX_INPROC_SERVER,
__uuidof(IWICImagingFactory),
ifactory
);
return SUCCEEDED(hr) ? TRUE : FALSE;
}
#else
g_WIC2 = false;
return SUCCEEDED(CoCreateInstance(
CLSID_WICImagingFactory,
nullptr,
CLSCTX_INPROC_SERVER,
__uuidof(IWICImagingFactory),
ifactory)) ? TRUE : FALSE;
#endif
}
} }
@ -236,47 +278,9 @@ IWICImagingFactory* DirectX::GetWICFactory(bool& iswic2)
static INIT_ONCE s_initOnce = INIT_ONCE_STATIC_INIT; static INIT_ONCE s_initOnce = INIT_ONCE_STATIC_INIT;
InitOnceExecuteOnce(&s_initOnce, InitOnceExecuteOnce(&s_initOnce,
[](PINIT_ONCE, PVOID, LPVOID *factory) noexcept -> BOOL InitializeWICFactory,
{ nullptr,
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE) reinterpret_cast<LPVOID*>(&g_Factory));
HRESULT hr = CoCreateInstance(
CLSID_WICImagingFactory2,
nullptr,
CLSCTX_INPROC_SERVER,
__uuidof(IWICImagingFactory2),
factory
);
if (SUCCEEDED(hr))
{
// WIC2 is available on Windows 10, Windows 8.x, and Windows 7 SP1 with KB 2670838 installed
g_WIC2 = true;
return TRUE;
}
else
{
g_WIC2 = false;
hr = CoCreateInstance(
CLSID_WICImagingFactory1,
nullptr,
CLSCTX_INPROC_SERVER,
__uuidof(IWICImagingFactory),
factory
);
return SUCCEEDED(hr) ? TRUE : FALSE;
}
#else
g_WIC2 = false;
return SUCCEEDED(CoCreateInstance(
CLSID_WICImagingFactory,
nullptr,
CLSCTX_INPROC_SERVER,
__uuidof(IWICImagingFactory),
factory)) ? TRUE : FALSE;
#endif
}, nullptr, reinterpret_cast<LPVOID*>(&g_Factory));
iswic2 = g_WIC2; iswic2 = g_WIC2;
return g_Factory; return g_Factory;
@ -1401,7 +1405,6 @@ size_t TexMetadata::ComputeIndex(size_t mip, size_t item, size_t slice) const
return index; return index;
} }
break;
default: default:
return size_t(-1); return size_t(-1);

View File

@ -9,7 +9,7 @@
// http://go.microsoft.com/fwlink/?LinkId=248926 // http://go.microsoft.com/fwlink/?LinkId=248926
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
#include "directxtexp.h" #include "DirectXTexp.h"
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
// IStream support for WIC Memory routines // IStream support for WIC Memory routines
@ -62,7 +62,7 @@
#pragma prefast(suppress:6387 28196, "a simple wrapper around an existing annotated function" ); #pragma prefast(suppress:6387 28196, "a simple wrapper around an existing annotated function" );
static inline HRESULT CreateMemoryStream(_Outptr_ IStream** stream) static inline HRESULT CreateMemoryStream(_Outptr_ IStream** stream)
{ {
return CreateStreamOnHGlobal(0, TRUE, stream); return CreateStreamOnHGlobal(nullptr, TRUE, stream);
} }
#endif #endif
@ -1167,7 +1167,7 @@ HRESULT DirectX::SaveToWICMemory(
return hr; return hr;
LARGE_INTEGER li = {}; LARGE_INTEGER li = {};
hr = stream->Seek(li, STREAM_SEEK_SET, 0); hr = stream->Seek(li, STREAM_SEEK_SET, nullptr);
if (FAILED(hr)) if (FAILED(hr))
return hr; return hr;
@ -1224,7 +1224,7 @@ HRESULT DirectX::SaveToWICMemory(
return hr; return hr;
LARGE_INTEGER li = {}; LARGE_INTEGER li = {};
hr = stream->Seek(li, STREAM_SEEK_SET, 0); hr = stream->Seek(li, STREAM_SEEK_SET, nullptr);
if (FAILED(hr)) if (FAILED(hr))
return hr; return hr;

View File

@ -63,7 +63,7 @@ inline void _CreateLinearFilter(_In_ size_t source, _In_ size_t dest, _In_ bool
{ {
assert(source > 0); assert(source > 0);
assert(dest > 0); assert(dest > 0);
assert(lf != 0); assert(lf != nullptr);
float scale = float(source) / float(dest); float scale = float(source) / float(dest);
@ -163,7 +163,7 @@ inline void _CreateCubicFilter(_In_ size_t source, _In_ size_t dest, _In_ bool w
{ {
assert(source > 0); assert(source > 0);
assert(dest > 0); assert(dest > 0);
assert(cf != 0); assert(cf != nullptr);
float scale = float(source) / float(dest); float scale = float(source) / float(dest);
@ -294,7 +294,7 @@ namespace TriangleFilter
tf->totalSize = totalSize; tf->totalSize = totalSize;
} }
assert(pFilter != 0); assert(pFilter != nullptr);
_Analysis_assume_(pFilter != 0); _Analysis_assume_(pFilter != 0);
// Filter setup // Filter setup