Fixed -Wimplicit-int-float-conversion

This commit is contained in:
Chuck Walbourn 2020-04-30 01:18:41 -07:00
parent 6ca1e02f6a
commit 50abcdf121
4 changed files with 16 additions and 18 deletions

View File

@ -430,9 +430,9 @@ namespace
Clr.b += Error[i].b; Clr.b += Error[i].b;
} }
Color[i].r = static_cast<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 = static_cast<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 = static_cast<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;
@ -918,12 +918,12 @@ void DirectX::D3DXDecodeBC3(XMVECTOR *pColor, const uint8_t *pBC) noexcept
if (pBC3->alpha[0] > pBC3->alpha[1]) if (pBC3->alpha[0] > pBC3->alpha[1])
{ {
for (size_t i = 1; i < 7; ++i) for (size_t i = 1; i < 7; ++i)
fAlpha[i + 1] = (fAlpha[0] * (7 - i) + fAlpha[1] * i) * (1.0f / 7.0f); fAlpha[i + 1] = (fAlpha[0] * float(7u - i) + fAlpha[1] * float(i)) * (1.0f / 7.0f);
} }
else else
{ {
for (size_t i = 1; i < 5; ++i) for (size_t i = 1; i < 5; ++i)
fAlpha[i + 1] = (fAlpha[0] * (5 - i) + fAlpha[1] * i) * (1.0f / 5.0f); fAlpha[i + 1] = (fAlpha[0] * float(5u - i) + fAlpha[1] * float(i)) * (1.0f / 5.0f);
fAlpha[6] = 0.0f; fAlpha[6] = 0.0f;
fAlpha[7] = 1.0f; fAlpha[7] = 1.0f;
@ -969,7 +969,7 @@ void DirectX::D3DXEncodeBC3(uint8_t *pBC, const XMVECTOR *pColor, DWORD flags) n
if (flags & BC_FLAGS_DITHER_A) if (flags & BC_FLAGS_DITHER_A)
fAlph += fError[i]; fAlph += fError[i];
fAlpha[i] = static_cast<int32_t>(fAlph * 255.0f + 0.5f) * (1.0f / 255.0f); fAlpha[i] = static_cast<float>(static_cast<int32_t>(fAlph * 255.0f + 0.5f)) * (1.0f / 255.0f);
if (fAlpha[i] < fMinAlpha) if (fAlpha[i] < fMinAlpha)
fMinAlpha = fAlpha[i]; fMinAlpha = fAlpha[i];
@ -1062,7 +1062,7 @@ void DirectX::D3DXEncodeBC3(uint8_t *pBC, const XMVECTOR *pColor, DWORD flags) n
fStep[1] = fAlphaB; fStep[1] = fAlphaB;
for (size_t i = 1; i < 5; ++i) for (size_t i = 1; i < 5; ++i)
fStep[i + 1] = (fStep[0] * (5 - i) + fStep[1] * i) * (1.0f / 5.0f); fStep[i + 1] = (fStep[0] * float(5u - i) + fStep[1] * float(i)) * (1.0f / 5.0f);
fStep[6] = 0.0f; fStep[6] = 0.0f;
fStep[7] = 1.0f; fStep[7] = 1.0f;
@ -1078,7 +1078,7 @@ void DirectX::D3DXEncodeBC3(uint8_t *pBC, const XMVECTOR *pColor, DWORD flags) n
fStep[1] = fAlphaA; fStep[1] = fAlphaA;
for (size_t i = 1; i < 7; ++i) for (size_t i = 1; i < 7; ++i)
fStep[i + 1] = (fStep[0] * (7 - i) + fStep[1] * i) * (1.0f / 7.0f); fStep[i + 1] = (fStep[0] * float(7u - i) + fStep[1] * float(i)) * (1.0f / 7.0f);
pSteps = pSteps8; pSteps = pSteps8;
} }

View File

@ -55,7 +55,7 @@ namespace
if (red_0 > red_1) if (red_0 > red_1)
{ {
uIndex -= 1; uIndex -= 1;
return (fred_0 * (7 - uIndex) + fred_1 * uIndex) / 7.0f; return (fred_0 * float(7u - uIndex) + fred_1 * float(uIndex)) / 7.0f;
} }
else else
{ {
@ -64,7 +64,7 @@ namespace
if (uIndex == 7) if (uIndex == 7)
return 1.0f; return 1.0f;
uIndex -= 1; uIndex -= 1;
return (fred_0 * (5 - uIndex) + fred_1 * uIndex) / 5.0f; return (fred_0 * float(5u - uIndex) + fred_1 * float(uIndex)) / 5.0f;
} }
} }
@ -114,7 +114,7 @@ namespace
if (red_0 > red_1) if (red_0 > red_1)
{ {
uIndex -= 1; uIndex -= 1;
return (fred_0 * (7 - uIndex) + fred_1 * uIndex) / 7.0f; return (fred_0 * float(7u - uIndex) + fred_1 * float(uIndex)) / 7.0f;
} }
else else
{ {
@ -123,7 +123,7 @@ namespace
if (uIndex == 7) if (uIndex == 7)
return 1.0f; return 1.0f;
uIndex -= 1; uIndex -= 1;
return (fred_0 * (5 - uIndex) + fred_1 * uIndex) / 5.0f; return (fred_0 * float(5u - uIndex) + fred_1 * float(uIndex)) / 5.0f;
} }
} }

View File

@ -1297,7 +1297,7 @@ _Use_decl_annotations_ bool DirectX::_LoadScanline(
*(dPtr++) = XMVectorSet(float(std::min<int>(std::max<int>(r, 0), 255)) / 255.f, *(dPtr++) = XMVectorSet(float(std::min<int>(std::max<int>(r, 0), 255)) / 255.f,
float(std::min<int>(std::max<int>(g, 0), 255)) / 255.f, float(std::min<int>(std::max<int>(g, 0), 255)) / 255.f,
float(std::min<int>(std::max<int>(b, 0), 255)) / 255.f, float(std::min<int>(std::max<int>(b, 0), 255)) / 255.f,
float(a / 255.f)); float(a) / 255.f);
} }
return true; return true;
} }
@ -1333,7 +1333,7 @@ _Use_decl_annotations_ bool DirectX::_LoadScanline(
*(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,
float(std::min<int>(std::max<int>(g, 0), 1023)) / 1023.f, float(std::min<int>(std::max<int>(g, 0), 1023)) / 1023.f,
float(std::min<int>(std::max<int>(b, 0), 1023)) / 1023.f, float(std::min<int>(std::max<int>(b, 0), 1023)) / 1023.f,
float(a / 3.f)); float(a) / 3.f);
} }
return true; return true;
} }

View File

@ -191,12 +191,12 @@ namespace
{ {
for (size_t sy = 0; sy < N; ++sy) for (size_t sy = 0; sy < N; ++sy)
{ {
const float fy = (sy + 0.5f) / N; const float fy = (float(sy) + 0.5f) / float(N);
const float ify = 1.0f - fy; const float ify = 1.0f - fy;
for (size_t sx = 0; sx < N; ++sx) for (size_t sx = 0; sx < N; ++sx)
{ {
const float fx = (sx + 0.5f) / N; const float fx = (float(sx) + 0.5f) / float(N);
const float ifx = 1.0f - fx; const float ifx = 1.0f - fx;
// [0]=(x+0, y+0), [1]=(x+0, y+1), [2]=(x+1, y+0), [3]=(x+1, y+1) // [0]=(x+0, y+0), [1]=(x+0, y+1), [2]=(x+1, y+0), [3]=(x+1, y+1)
@ -303,7 +303,6 @@ namespace
{ {
float minAlphaScale = 0.0f; float minAlphaScale = 0.0f;
float maxAlphaScale = 4.0f; float maxAlphaScale = 4.0f;
float bestAlphaScale = 1.0f;
float bestError = FLT_MAX; float bestError = FLT_MAX;
// Determine desired scale using a binary search. Hardcoded to 10 steps max. // Determine desired scale using a binary search. Hardcoded to 10 steps max.
@ -322,7 +321,6 @@ namespace
if (error < bestError) if (error < bestError)
{ {
bestError = error; bestError = error;
bestAlphaScale = alphaScale;
} }
if (currentCoverage < targetCoverage) if (currentCoverage < targetCoverage)