25using namespace DirectX::PackedVector;
34 const HDRColorA g_Luminance(0.2125f / 0.7154f, 1.0f, 0.0721f / 0.7154f, 1.0f);
35 const HDRColorA g_LuminanceInv(0.7154f / 0.2125f, 1.0f, 0.7154f / 0.0721f, 1.0f);
40 inline void Decode565(_Out_
HDRColorA* pColor, _In_
const uint16_t w565)
noexcept
42 pColor->r =
static_cast<float>((w565 >> 11) & 31) * (1.0f / 31.0f);
43 pColor->g =
static_cast<float>((w565 >> 5) & 63) * (1.0f / 63.0f);
44 pColor->b =
static_cast<float>((w565 >> 0) & 31) * (1.0f / 31.0f);
48 inline uint16_t Encode565(_In_
const HDRColorA* pColor)
noexcept
52 Color.r = (pColor->r < 0.0f) ? 0.0f : (pColor->r > 1.0f) ? 1.0f : pColor->r;
53 Color.g = (pColor->g < 0.0f) ? 0.0f : (pColor->g > 1.0f) ? 1.0f : pColor->g;
54 Color.b = (pColor->b < 0.0f) ? 0.0f : (pColor->b > 1.0f) ? 1.0f : pColor->b;
59 w =
static_cast<uint16_t
>((
static_cast<int32_t
>(
Color.r * 31.0f + 0.5f) << 11) | (
static_cast<int32_t
>(
Color.g * 63.0f + 0.5f) << 5)
60 | (
static_cast<int32_t
>(
Color.b * 31.0f + 0.5f) << 0));
70 uint32_t flags)
noexcept
72 constexpr float fEpsilon = (0.25f / 64.0f) * (0.25f / 64.0f);
73 static const float pC3[] = { 2.0f / 2.0f, 1.0f / 2.0f, 0.0f / 2.0f };
74 static const float pD3[] = { 0.0f / 2.0f, 1.0f / 2.0f, 2.0f / 2.0f };
75 static const float pC4[] = { 3.0f / 3.0f, 2.0f / 3.0f, 1.0f / 3.0f, 0.0f / 3.0f };
76 static const float pD4[] = { 0.0f / 3.0f, 1.0f / 3.0f, 2.0f / 3.0f, 3.0f / 3.0f };
78 const float* pC = (3 == cSteps) ? pC3 : pC4;
79 const float* pD = (3 == cSteps) ? pD3 : pD4;
88 if (pPoints[iPoint].a > 0.0f)
91 if (pPoints[iPoint].r < X.
r)
92 X.
r = pPoints[iPoint].r;
94 if (pPoints[iPoint].g < X.
g)
95 X.
g = pPoints[iPoint].g;
97 if (pPoints[iPoint].b < X.
b)
98 X.
b = pPoints[iPoint].b;
100 if (pPoints[iPoint].r > Y.
r)
101 Y.
r = pPoints[iPoint].r;
103 if (pPoints[iPoint].g > Y.
g)
104 Y.
g = pPoints[iPoint].g;
106 if (pPoints[iPoint].b > Y.
b)
107 Y.
b = pPoints[iPoint].b;
114 const float fAB = AB.r * AB.r + AB.g * AB.g + AB.b * AB.b;
131 const float fABInv = 1.0f / fAB;
133 HDRColorA Dir(AB.r * fABInv, AB.g * fABInv, AB.b * fABInv, 0.0f);
135 const HDRColorA Mid((X.
r + Y.
r) * 0.5f, (X.
g + Y.
g) * 0.5f, (X.
b + Y.
b) * 0.5f, 0.0f);
142 Pt.
r = (pPoints[iPoint].r - Mid.r) * Dir.r;
143 Pt.g = (pPoints[iPoint].g - Mid.g) * Dir.g;
144 Pt.b = (pPoints[iPoint].b - Mid.b) * Dir.b;
150 f = Pt.r + Pt.g + Pt.b;
151 fDir[0] += pPoints[iPoint].a * f * f;
153 f = Pt.r + Pt.g - Pt.b;
154 fDir[1] += pPoints[iPoint].a * f * f;
156 f = Pt.r - Pt.g + Pt.b;
157 fDir[2] += pPoints[iPoint].a * f * f;
159 f = Pt.r - Pt.g - Pt.b;
160 fDir[3] += pPoints[iPoint].a * f * f;
162 f = Pt.r + Pt.g + Pt.b;
165 f = Pt.r + Pt.g - Pt.b;
168 f = Pt.r - Pt.g + Pt.b;
171 f = Pt.r - Pt.g - Pt.b;
176 float fDirMax = fDir[0];
179 for (
size_t iDir = 1; iDir < 4; iDir++)
181 if (fDir[iDir] > fDirMax)
183 fDirMax = fDir[iDir];
203 if (fAB < 1.0f / 4096.0f)
217 const auto fSteps =
static_cast<float>(cSteps - 1);
219 for (
size_t iIteration = 0; iIteration < 8; iIteration++)
224 for (
size_t iStep = 0; iStep < cSteps; iStep++)
226 pSteps[iStep].
r = X.
r * pC[iStep] + Y.
r * pD[iStep];
227 pSteps[iStep].
g = X.
g * pC[iStep] + Y.
g * pD[iStep];
228 pSteps[iStep].
b = X.
b * pC[iStep] + Y.
b * pD[iStep];
229 pSteps[iStep].
a = 1.0f;
237 const float fLen = (Dir.r * Dir.r + Dir.g * Dir.g + Dir.b * Dir.b);
239 if (fLen < (1.0f / 4096.0f))
242 const float fScale = fSteps / fLen;
257 = (pPoints[iPoint].r - X.
r) * Dir.r + (pPoints[iPoint].g - X.
g) * Dir.g + (pPoints[iPoint].b - X.
b) * Dir.b;
262 else if (fDot >= fSteps)
265 iStep = uint32_t(fDot + 0.5f);
268 Diff.
r = pSteps[iStep].
r - pPoints[iPoint].r;
269 Diff.
g = pSteps[iStep].
g - pPoints[iPoint].g;
270 Diff.
b = pSteps[iStep].
b - pPoints[iPoint].b;
274 const float fC = pC[iStep] * pPoints[iPoint].a * (1.0f / 8.0f);
275 const float fD = pD[iStep] * pPoints[iPoint].a * (1.0f / 8.0f);
277 const float fC = pC[iStep] * (1.0f / 8.0f);
278 const float fD = pD[iStep] * (1.0f / 8.0f);
281 d2X += fC * pC[iStep];
286 d2Y += fD * pD[iStep];
295 const float f = -1.0f / d2X;
304 const float f = -1.0f / d2Y;
311 if ((dX.
r * dX.
r < fEpsilon) && (dX.
g * dX.
g < fEpsilon) && (dX.
b * dX.
b < fEpsilon) && (dY.
r * dY.
r < fEpsilon)
312 && (dY.
g * dY.
g < fEpsilon) && (dY.
b * dY.
b < fEpsilon))
331 assert(pColor && pBC);
332 static_assert(
sizeof(
D3DX_BC1) == 8,
"D3DX_BC1 should be 8 bytes");
334 static XMVECTORF32 s_Scale = { { { 1.f / 31.f, 1.f / 63.f, 1.f / 31.f, 1.f } } };
336 XMVECTOR clr0 = XMLoadU565(
reinterpret_cast<const XMU565*
>(&pBC->rgb[0]));
337 XMVECTOR clr1 = XMLoadU565(
reinterpret_cast<const XMU565*
>(&pBC->rgb[1]));
339 clr0 = XMVectorMultiply(clr0, s_Scale);
340 clr1 = XMVectorMultiply(clr1, s_Scale);
342 clr0 = XMVectorSwizzle<2, 1, 0, 3>(clr0);
343 clr1 = XMVectorSwizzle<2, 1, 0, 3>(clr1);
345 clr0 = XMVectorSelect(g_XMIdentityR3, clr0, g_XMSelect1110);
346 clr1 = XMVectorSelect(g_XMIdentityR3, clr1, g_XMSelect1110);
349 if (isbc1 && (pBC->rgb[0] <= pBC->rgb[1]))
351 clr2 = XMVectorLerp(clr0, clr1, 0.5f);
352 clr3 = XMVectorZero();
356 clr2 = XMVectorLerp(clr0, clr1, 1.f / 3.f);
357 clr3 = XMVectorLerp(clr0, clr1, 2.f / 3.f);
360 uint32_t dw = pBC->bitmap;
362 for (
size_t i = 0; i < NUM_PIXELS_PER_BLOCK; ++i, dw >>= 2)
366 case 0: pColor[i] = clr0;
break;
367 case 1: pColor[i] = clr1;
break;
368 case 2: pColor[i] = clr2;
break;
371 default: pColor[i] = clr3;
break;
381 uint32_t flags)
noexcept
383 assert(pBC && pColor);
384 static_assert(
sizeof(
D3DX_BC1) == 8,
"D3DX_BC1 should be 8 bytes");
391 size_t uColorKey = 0;
395 if (pColor[i].a < threshold)
401 pBC->rgb[0] = 0x0000;
402 pBC->rgb[1] = 0xffff;
403 pBC->bitmap = 0xffffffff;
407 uSteps = (uColorKey > 0) ? 3u : 4u;
439 Color[i].r =
static_cast<float>(
static_cast<int32_t
>(Clr.
r * 31.0f + 0.5f)) * (1.0f / 31.0f);
440 Color[i].g =
static_cast<float>(
static_cast<int32_t
>(Clr.
g * 63.0f + 0.5f)) * (1.0f / 63.0f);
441 Color[i].b =
static_cast<float>(
static_cast<int32_t
>(Clr.
b * 31.0f + 0.5f)) * (1.0f / 31.0f);
444 Color[i].a = pColor[i].a;
460 _Analysis_assume_(i < 15);
461 Error[i + 1].r += Diff.
r * (7.0f / 16.0f);
462 Error[i + 1].g += Diff.
g * (7.0f / 16.0f);
463 Error[i + 1].b += Diff.
b * (7.0f / 16.0f);
470 Error[i + 3].r += Diff.
r * (3.0f / 16.0f);
471 Error[i + 3].g += Diff.
g * (3.0f / 16.0f);
472 Error[i + 3].b += Diff.
b * (3.0f / 16.0f);
475 Error[i + 4].r += Diff.
r * (5.0f / 16.0f);
476 Error[i + 4].g += Diff.
g * (5.0f / 16.0f);
477 Error[i + 4].b += Diff.
b * (5.0f / 16.0f);
482 _Analysis_assume_(i < 11);
483 Error[i + 5].r += Diff.
r * (1.0f / 16.0f);
484 Error[i + 5].g += Diff.
g * (1.0f / 16.0f);
485 Error[i + 5].b += Diff.
b * (1.0f / 16.0f);
492 Color[i].r *= g_Luminance.r;
493 Color[i].g *= g_Luminance.g;
494 Color[i].b *= g_Luminance.b;
500 HDRColorA ColorA, ColorB, ColorC, ColorD;
502 OptimizeRGB(&ColorA, &ColorB, Color, uSteps, flags);
511 ColorC.
r = ColorA.
r * g_LuminanceInv.r;
512 ColorC.
g = ColorA.
g * g_LuminanceInv.g;
513 ColorC.
b = ColorA.
b * g_LuminanceInv.b;
516 ColorD.
r = ColorB.
r * g_LuminanceInv.r;
517 ColorD.
g = ColorB.
g * g_LuminanceInv.g;
518 ColorD.
b = ColorB.
b * g_LuminanceInv.b;
522 const uint16_t wColorA = Encode565(&ColorC);
523 const uint16_t wColorB = Encode565(&ColorD);
525 if ((uSteps == 4) && (wColorA == wColorB))
527 pBC->rgb[0] = wColorA;
528 pBC->rgb[1] = wColorB;
529 pBC->bitmap = 0x00000000;
533 Decode565(&ColorC, wColorA);
534 Decode565(&ColorD, wColorB);
543 ColorA.
r = ColorC.
r * g_Luminance.r;
544 ColorA.
g = ColorC.
g * g_Luminance.g;
545 ColorA.
b = ColorC.
b * g_Luminance.b;
547 ColorB.
r = ColorD.
r * g_Luminance.r;
548 ColorB.
g = ColorD.
g * g_Luminance.g;
549 ColorB.
b = ColorD.
b * g_Luminance.b;
555 if ((3 == uSteps) == (wColorA <= wColorB))
557 pBC->rgb[0] = wColorA;
558 pBC->rgb[1] = wColorB;
565 pBC->rgb[0] = wColorB;
566 pBC->rgb[1] = wColorA;
572 static const size_t pSteps3[] = { 0, 2, 1 };
573 static const size_t pSteps4[] = { 0, 2, 3, 1 };
574 const size_t* pSteps;
592 Dir.
r = Step[1].
r - Step[0].
r;
593 Dir.
g = Step[1].
g - Step[0].
g;
594 Dir.
b = Step[1].
b - Step[0].
b;
597 const auto fSteps =
static_cast<float>(uSteps - 1);
598 const float fScale = (wColorA != wColorB) ? (fSteps / (Dir.
r * Dir.
r + Dir.
g * Dir.
g + Dir.
b * Dir.
b)) : 0.0f;
611 if ((3 == uSteps) && (pColor[i].a < threshold))
613 dw = (3u << 30) | (dw >> 2);
626 Clr.
r = pColor[i].r * g_Luminance.r;
627 Clr.
g = pColor[i].g * g_Luminance.g;
628 Clr.
b = pColor[i].b * g_Luminance.b;
639 const float fDot = (Clr.
r - Step[0].
r) * Dir.
r + (Clr.
g - Step[0].g) * Dir.
g + (Clr.
b - Step[0].
b) * Dir.
b;
644 else if (fDot >= fSteps)
647 iStep = uint32_t(pSteps[uint32_t(fDot + 0.5f)]);
649 dw = (iStep << 30) | (dw >> 2);
654 Diff.
r =
Color[i].a * (Clr.
r - Step[iStep].
r);
655 Diff.
g =
Color[i].a * (Clr.
g - Step[iStep].
g);
656 Diff.
b =
Color[i].a * (Clr.
b - Step[iStep].
b);
661 Error[i + 1].r += Diff.
r * (7.0f / 16.0f);
662 Error[i + 1].g += Diff.
g * (7.0f / 16.0f);
663 Error[i + 1].b += Diff.
b * (7.0f / 16.0f);
670 Error[i + 3].r += Diff.
r * (3.0f / 16.0f);
671 Error[i + 3].g += Diff.
g * (3.0f / 16.0f);
672 Error[i + 3].b += Diff.
b * (3.0f / 16.0f);
675 Error[i + 4].r += Diff.
r * (5.0f / 16.0f);
676 Error[i + 4].g += Diff.
g * (5.0f / 16.0f);
677 Error[i + 4].b += Diff.
b * (5.0f / 16.0f);
681 Error[i + 5].r += Diff.
r * (1.0f / 16.0f);
682 Error[i + 5].g += Diff.
g * (1.0f / 16.0f);
683 Error[i + 5].b += Diff.
b * (1.0f / 16.0f);
697#ifdef COLOR_AVG_0WEIGHTS
700 Color.r = pColor[0].r;
701 Color.g = pColor[0].g;
702 Color.b = pColor[0].b;
706 Color.r += pColor[i].r;
707 Color.g += pColor[i].g;
708 Color.b += pColor[i].b;
711 Color.r *= 1.0f / 16.0f;
712 Color.g *= 1.0f / 16.0f;
713 Color.b *= 1.0f / 16.0f;
715 const uint16_t wColor = Encode565(&Color);
717 const uint16_t wColor = 0x0000;
721 pBC->rgb[0] = wColor;
722 pBC->rgb[1] = wColor;
723 pBC->bitmap = 0x00000000;
737 auto pBC1 =
reinterpret_cast<const D3DX_BC1*
>(pBC);
738 DecodeBC1(pColor, pBC1,
true);
741_Use_decl_annotations_
void DirectX::D3DXEncodeBC1(uint8_t* pBC,
const XMVECTOR* pColor,
float threshold, uint32_t flags)
noexcept
743 assert(pBC && pColor);
754 XMStoreFloat4(
reinterpret_cast<XMFLOAT4*
>(&clr), pColor[i]);
756 const float fAlph = clr.
a + fError[i];
761 Color[i].a =
static_cast<float>(
static_cast<int32_t
>(clr.
a + fError[i] + 0.5f));
763 const float fDiff = fAlph -
Color[i].a;
768 _Analysis_assume_(i < 15);
769 fError[i + 1] += fDiff * (7.0f / 16.0f);
775 fError[i + 3] += fDiff * (3.0f / 16.0f);
777 fError[i + 4] += fDiff * (5.0f / 16.0f);
782 _Analysis_assume_(i < 11);
783 fError[i + 5] += fDiff * (1.0f / 16.0f);
792 XMStoreFloat4(
reinterpret_cast<XMFLOAT4*
>(&Color[i]), pColor[i]);
796 auto pBC1 =
reinterpret_cast<D3DX_BC1*
>(pBC);
797 EncodeBC1(pBC1, Color,
true, threshold, flags);
805 assert(pColor && pBC);
806 static_assert(
sizeof(
D3DX_BC2) == 16,
"D3DX_BC2 should be 16 bytes");
808 auto pBC2 =
reinterpret_cast<const D3DX_BC2*
>(pBC);
811 DecodeBC1(pColor, &pBC2->bc1,
false);
814 uint32_t dw = pBC2->bitmap[0];
816 for (
size_t i = 0; i < 8; ++i, dw >>= 4)
818#pragma prefast(suppress : 22103, "writing blocks in two halves confuses tool")
819 pColor[i] = XMVectorSetW(pColor[i],
static_cast<float>(dw & 0xf) * (1.0f / 15.0f));
822 dw = pBC2->bitmap[1];
824 for (
size_t i = 8; i < NUM_PIXELS_PER_BLOCK; ++i, dw >>= 4)
825 pColor[i] = XMVectorSetW(pColor[i],
static_cast<float>(dw & 0xf) * (1.0f / 15.0f));
828_Use_decl_annotations_
void DirectX::D3DXEncodeBC2(uint8_t* pBC,
const XMVECTOR* pColor, uint32_t flags)
noexcept
830 assert(pBC && pColor);
831 static_assert(
sizeof(
D3DX_BC2) == 16,
"D3DX_BC2 should be 16 bytes");
836 XMStoreFloat4(
reinterpret_cast<XMFLOAT4*
>(&Color[i]), pColor[i]);
839 auto pBC2 =
reinterpret_cast<D3DX_BC2*
>(pBC);
848 float fAlph =
Color[i].a;
852 const auto u =
static_cast<uint32_t
>(fAlph * 15.0f + 0.5f);
854 pBC2->bitmap[i >> 3] >>= 4;
855 pBC2->bitmap[i >> 3] |= (u << 28);
859 const float fDiff = fAlph - float(u) * (1.0f / 15.0f);
864 _Analysis_assume_(i < 15);
865 fError[i + 1] += fDiff * (7.0f / 16.0f);
871 fError[i + 3] += fDiff * (3.0f / 16.0f);
873 fError[i + 4] += fDiff * (5.0f / 16.0f);
878 _Analysis_assume_(i < 11);
879 fError[i + 5] += fDiff * (1.0f / 16.0f);
887 if (!pBC2->bitmap[0] && !pBC2->bitmap[1])
889 EncodeSolidBC1(pBC2->dxt1, Color);
894 EncodeBC1(&pBC2->bc1, Color,
false, 0.f, flags);
902 assert(pColor && pBC);
903 static_assert(
sizeof(
D3DX_BC3) == 16,
"D3DX_BC3 should be 16 bytes");
905 auto pBC3 =
reinterpret_cast<const D3DX_BC3*
>(pBC);
908 DecodeBC1(pColor, &pBC3->bc1,
false);
913 fAlpha[0] =
static_cast<float>(pBC3->alpha[0]) * (1.0f / 255.0f);
914 fAlpha[1] =
static_cast<float>(pBC3->alpha[1]) * (1.0f / 255.0f);
916 if (pBC3->alpha[0] > pBC3->alpha[1])
918 for (
size_t i = 1; i < 7; ++i)
919 fAlpha[i + 1] = (fAlpha[0] *
float(7u - i) + fAlpha[1] *
float(i)) * (1.0f / 7.0f);
923 for (
size_t i = 1; i < 5; ++i)
924 fAlpha[i + 1] = (fAlpha[0] *
float(5u - i) + fAlpha[1] *
float(i)) * (1.0f / 5.0f);
930 uint32_t dw = uint32_t(pBC3->bitmap[0]) | uint32_t(pBC3->bitmap[1] << 8) | uint32_t(pBC3->bitmap[2] << 16);
932 for (
size_t i = 0; i < 8; ++i, dw >>= 3)
933 pColor[i] = XMVectorSetW(pColor[i], fAlpha[dw & 0x7]);
935 dw = uint32_t(pBC3->bitmap[3]) | uint32_t(pBC3->bitmap[4] << 8) | uint32_t(pBC3->bitmap[5] << 16);
937 for (
size_t i = 8; i < NUM_PIXELS_PER_BLOCK; ++i, dw >>= 3)
938 pColor[i] = XMVectorSetW(pColor[i], fAlpha[dw & 0x7]);
941_Use_decl_annotations_
void DirectX::D3DXEncodeBC3(uint8_t* pBC,
const XMVECTOR* pColor, uint32_t flags)
noexcept
943 assert(pBC && pColor);
944 static_assert(
sizeof(
D3DX_BC3) == 16,
"D3DX_BC3 should be 16 bytes");
949 XMStoreFloat4(
reinterpret_cast<XMFLOAT4*
>(&Color[i]), pColor[i]);
952 auto pBC3 =
reinterpret_cast<D3DX_BC3*
>(pBC);
960 float fMinAlpha =
Color[0].a;
961 float fMaxAlpha =
Color[0].a;
965 float fAlph =
Color[i].a;
969 fAlpha[i] =
static_cast<float>(
static_cast<int32_t
>(fAlph * 255.0f + 0.5f)) * (1.0f / 255.0f);
971 if (fAlpha[i] < fMinAlpha)
972 fMinAlpha = fAlpha[i];
973 else if (fAlpha[i] > fMaxAlpha)
974 fMaxAlpha = fAlpha[i];
978 const float fDiff = fAlph - fAlpha[i];
983 _Analysis_assume_(i < 15);
984 fError[i + 1] += fDiff * (7.0f / 16.0f);
990 fError[i + 3] += fDiff * (3.0f / 16.0f);
992 fError[i + 4] += fDiff * (5.0f / 16.0f);
997 _Analysis_assume_(i < 11);
998 fError[i + 5] += fDiff * (1.0f / 16.0f);
1005 if (0.0f == fMaxAlpha)
1007 EncodeSolidBC1(&pBC3->dxt1, Color);
1008 pBC3->alpha[0] = 0x00;
1009 pBC3->alpha[1] = 0x00;
1010 memset(pBC3->bitmap, 0x00, 6);
1015 EncodeBC1(&pBC3->bc1, Color,
false, 0.f, flags);
1018 if (1.0f == fMinAlpha)
1020 pBC3->alpha[0] = 0xff;
1021 pBC3->alpha[1] = 0xff;
1022 memset(pBC3->bitmap, 0x00, 6);
1027 const uint32_t uSteps = ((0.0f == fMinAlpha) || (1.0f == fMaxAlpha)) ? 6u : 8u;
1029 float fAlphaA, fAlphaB;
1032 const auto bAlphaA =
static_cast<uint8_t
>(
static_cast<int32_t
>(fAlphaA * 255.0f + 0.5f));
1033 const auto bAlphaB =
static_cast<uint8_t
>(
static_cast<int32_t
>(fAlphaB * 255.0f + 0.5f));
1035 fAlphaA =
static_cast<float>(bAlphaA) * (1.0f / 255.0f);
1036 fAlphaB =
static_cast<float>(bAlphaB) * (1.0f / 255.0f);
1039 if ((8 == uSteps) && (bAlphaA == bAlphaB))
1041 pBC3->alpha[0] = bAlphaA;
1042 pBC3->alpha[1] = bAlphaB;
1043 memset(pBC3->bitmap, 0x00, 6);
1047 static const size_t pSteps6[] = { 0, 2, 3, 4, 5, 1 };
1048 static const size_t pSteps8[] = { 0, 2, 3, 4, 5, 6, 7, 1 };
1050 const size_t* pSteps;
1051 float fStep[8] = {};
1055 pBC3->alpha[0] = bAlphaA;
1056 pBC3->alpha[1] = bAlphaB;
1061 for (
size_t i = 1; i < 5; ++i)
1062 fStep[i + 1] = (fStep[0] *
float(5u - i) + fStep[1] *
float(i)) * (1.0f / 5.0f);
1071 pBC3->alpha[0] = bAlphaB;
1072 pBC3->alpha[1] = bAlphaA;
1077 for (
size_t i = 1; i < 7; ++i)
1078 fStep[i + 1] = (fStep[0] *
float(7u - i) + fStep[1] *
float(i)) * (1.0f / 7.0f);
1084 const auto fSteps =
static_cast<float>(uSteps - 1);
1085 const float fScale = (fStep[0] != fStep[1]) ? (fSteps / (fStep[1] - fStep[0])) : 0.0f;
1090 for (
size_t iSet = 0; iSet < 2; iSet++)
1094 const size_t iMin = iSet * 8;
1095 const size_t iLim = iMin + 8;
1097 for (
size_t i = iMin; i < iLim; ++i)
1099 float fAlph =
Color[i].a;
1102 const float fDot = (fAlph - fStep[0]) * fScale;
1106 iStep = ((6 == uSteps) && (fAlph <= fStep[0] * 0.5f)) ? 6u : 0u;
1107 else if (fDot >= fSteps)
1108 iStep = ((6 == uSteps) && (fAlph >= (fStep[1] + 1.0f) * 0.5f)) ? 7u : 1u;
1110 iStep = uint32_t(pSteps[uint32_t(fDot + 0.5f)]);
1112 dw = (iStep << 21) | (dw >> 3);
1116 const float fDiff = (fAlph - fStep[iStep]);
1119 fError[i + 1] += fDiff * (7.0f / 16.0f);
1124 fError[i + 3] += fDiff * (3.0f / 16.0f);
1126 fError[i + 4] += fDiff * (5.0f / 16.0f);
1129 fError[i + 5] += fDiff * (1.0f / 16.0f);
1134 pBC3->bitmap[0 + iSet * 3] =
reinterpret_cast<uint8_t*
>(&dw)[0];
1135 pBC3->bitmap[1 + iSet * 3] =
reinterpret_cast<uint8_t*
>(&dw)[1];
1136 pBC3->bitmap[2 + iSet * 3] =
reinterpret_cast<uint8_t*
>(&dw)[2];
#define NUM_PIXELS_PER_BLOCK
void D3DXEncodeBC2(_Out_writes_(16) uint8_t *pBC, _In_reads_(NUM_PIXELS_PER_BLOCK) const XMVECTOR *pColor, _In_ uint32_t flags) noexcept
void D3DXDecodeBC2(_Out_writes_(NUM_PIXELS_PER_BLOCK) XMVECTOR *pColor, _In_reads_(16) const uint8_t *pBC) noexcept
void D3DXDecodeBC1(_Out_writes_(NUM_PIXELS_PER_BLOCK) XMVECTOR *pColor, _In_reads_(8) const uint8_t *pBC) noexcept
void D3DXDecodeBC3(_Out_writes_(NUM_PIXELS_PER_BLOCK) XMVECTOR *pColor, _In_reads_(16) const uint8_t *pBC) noexcept
void D3DXEncodeBC3(_Out_writes_(16) uint8_t *pBC, _In_reads_(NUM_PIXELS_PER_BLOCK) const XMVECTOR *pColor, _In_ uint32_t flags) noexcept
void OptimizeAlpha(float *pX, float *pY, const float *pPoints, uint32_t cSteps) noexcept
HDRColorA * HDRColorALerp(_Out_ HDRColorA *pOut, _In_ const HDRColorA *pC1, _In_ const HDRColorA *pC2, _In_ float s) noexcept
void D3DXEncodeBC1(_Out_writes_(8) uint8_t *pBC, _In_reads_(NUM_PIXELS_PER_BLOCK) const XMVECTOR *pColor, _In_ float threshold, _In_ uint32_t flags) noexcept
uint32_t Color(Echo echo)