mirror of
https://github.com/microsoft/DirectXTex.git
synced 2025-07-14 22:20:12 +02:00
Minor code review feedback
This commit is contained in:
parent
2f3955277b
commit
685a69ad1b
@ -184,16 +184,8 @@ template <bool bRange> void OptimizeAlpha(float *pX, float *pY, const float *pPo
|
|||||||
const float *pC = (6 == cSteps) ? pC6 : pC8;
|
const float *pC = (6 == cSteps) ? pC6 : pC8;
|
||||||
const float *pD = (6 == cSteps) ? pD6 : pD8;
|
const float *pD = (6 == cSteps) ? pD6 : pD8;
|
||||||
|
|
||||||
float MAX_VALUE = 1.0f;
|
const float MAX_VALUE = 1.0f;
|
||||||
float MIN_VALUE;
|
const float MIN_VALUE = (bRange) ? -1.0f : 0.0f;
|
||||||
if (bRange)
|
|
||||||
{
|
|
||||||
MIN_VALUE = -1.0f;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
MIN_VALUE = 0.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find Min and Max points, as starting point
|
// Find Min and Max points, as starting point
|
||||||
float fX = MAX_VALUE;
|
float fX = MAX_VALUE;
|
||||||
|
@ -190,17 +190,13 @@ namespace
|
|||||||
_Out_ uint8_t &endpointU_1)
|
_Out_ uint8_t &endpointU_1)
|
||||||
{
|
{
|
||||||
// The boundary of codec for signed/unsigned format
|
// The boundary of codec for signed/unsigned format
|
||||||
float MIN_NORM;
|
const float MIN_NORM = 0.f;
|
||||||
float MAX_NORM = 1.0f;
|
const float MAX_NORM = 1.f;
|
||||||
int8_t iStart, iEnd;
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
MIN_NORM = 0.0f;
|
|
||||||
|
|
||||||
// Find max/min of input texels
|
// Find max/min of input texels
|
||||||
float fBlockMax = theTexelsU[0];
|
float fBlockMax = theTexelsU[0];
|
||||||
float fBlockMin = theTexelsU[0];
|
float fBlockMin = theTexelsU[0];
|
||||||
for (i = 0; i < BLOCK_SIZE; ++i)
|
for (size_t i = 0; i < BLOCK_SIZE; ++i)
|
||||||
{
|
{
|
||||||
if (theTexelsU[i] < fBlockMin)
|
if (theTexelsU[i] < fBlockMin)
|
||||||
{
|
{
|
||||||
@ -212,7 +208,7 @@ namespace
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there are boundary values in input texels, Should use 4 block-codec to guarantee
|
// If there are boundary values in input texels, should use 4 interpolated color values to guarantee
|
||||||
// the exact code of the boundary values.
|
// the exact code of the boundary values.
|
||||||
bool bUsing4BlockCodec = (MIN_NORM == fBlockMin || MAX_NORM == fBlockMax);
|
bool bUsing4BlockCodec = (MIN_NORM == fBlockMin || MAX_NORM == fBlockMax);
|
||||||
|
|
||||||
@ -221,20 +217,22 @@ namespace
|
|||||||
|
|
||||||
if (!bUsing4BlockCodec)
|
if (!bUsing4BlockCodec)
|
||||||
{
|
{
|
||||||
|
// 6 interpolated color values
|
||||||
OptimizeAlpha<false>(&fStart, &fEnd, theTexelsU, 8);
|
OptimizeAlpha<false>(&fStart, &fEnd, theTexelsU, 8);
|
||||||
|
|
||||||
iStart = (uint8_t)(fStart * 255.0f);
|
uint8_t iStart = static_cast<uint8_t>(fStart * 255.0f);
|
||||||
iEnd = (uint8_t)(fEnd * 255.0f);
|
uint8_t iEnd = static_cast<uint8_t>(fEnd * 255.0f);
|
||||||
|
|
||||||
endpointU_0 = iEnd;
|
endpointU_0 = iEnd;
|
||||||
endpointU_1 = iStart;
|
endpointU_1 = iStart;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// 4 interpolated color values
|
||||||
OptimizeAlpha<false>(&fStart, &fEnd, theTexelsU, 6);
|
OptimizeAlpha<false>(&fStart, &fEnd, theTexelsU, 6);
|
||||||
|
|
||||||
iStart = (uint8_t)(fStart * 255.0f);
|
uint8_t iStart = static_cast<uint8_t>(fStart * 255.0f);
|
||||||
iEnd = (uint8_t)(fEnd * 255.0f);
|
uint8_t iEnd = static_cast<uint8_t>(fEnd * 255.0f);
|
||||||
|
|
||||||
endpointU_1 = iEnd;
|
endpointU_1 = iEnd;
|
||||||
endpointU_0 = iStart;
|
endpointU_0 = iStart;
|
||||||
@ -247,17 +245,13 @@ namespace
|
|||||||
_Out_ int8_t &endpointU_1)
|
_Out_ int8_t &endpointU_1)
|
||||||
{
|
{
|
||||||
// The boundary of codec for signed/unsigned format
|
// The boundary of codec for signed/unsigned format
|
||||||
float MIN_NORM;
|
const float MIN_NORM = -1.f;
|
||||||
float MAX_NORM = 1.0f;
|
const float MAX_NORM = 1.f;
|
||||||
int8_t iStart, iEnd;
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
MIN_NORM = -1.0f;
|
|
||||||
|
|
||||||
// Find max/min of input texels
|
// Find max/min of input texels
|
||||||
float fBlockMax = theTexelsU[0];
|
float fBlockMax = theTexelsU[0];
|
||||||
float fBlockMin = theTexelsU[0];
|
float fBlockMin = theTexelsU[0];
|
||||||
for (i = 0; i < BLOCK_SIZE; ++i)
|
for (size_t i = 0; i < BLOCK_SIZE; ++i)
|
||||||
{
|
{
|
||||||
if (theTexelsU[i] < fBlockMin)
|
if (theTexelsU[i] < fBlockMin)
|
||||||
{
|
{
|
||||||
@ -269,7 +263,7 @@ namespace
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there are boundary values in input texels, Should use 4 block-codec to guarantee
|
// If there are boundary values in input texels, should use 4 interpolated color values to guarantee
|
||||||
// the exact code of the boundary values.
|
// the exact code of the boundary values.
|
||||||
bool bUsing4BlockCodec = (MIN_NORM == fBlockMin || MAX_NORM == fBlockMax);
|
bool bUsing4BlockCodec = (MIN_NORM == fBlockMin || MAX_NORM == fBlockMax);
|
||||||
|
|
||||||
@ -278,8 +272,10 @@ namespace
|
|||||||
|
|
||||||
if (!bUsing4BlockCodec)
|
if (!bUsing4BlockCodec)
|
||||||
{
|
{
|
||||||
|
// 6 interpolated color values
|
||||||
OptimizeAlpha<true>(&fStart, &fEnd, theTexelsU, 8);
|
OptimizeAlpha<true>(&fStart, &fEnd, theTexelsU, 8);
|
||||||
|
|
||||||
|
int8_t iStart, iEnd;
|
||||||
FloatToSNorm(fStart, &iStart);
|
FloatToSNorm(fStart, &iStart);
|
||||||
FloatToSNorm(fEnd, &iEnd);
|
FloatToSNorm(fEnd, &iEnd);
|
||||||
|
|
||||||
@ -288,8 +284,10 @@ namespace
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// 4 interpolated color values
|
||||||
OptimizeAlpha<true>(&fStart, &fEnd, theTexelsU, 6);
|
OptimizeAlpha<true>(&fStart, &fEnd, theTexelsU, 6);
|
||||||
|
|
||||||
|
int8_t iStart, iEnd;
|
||||||
FloatToSNorm(fStart, &iStart);
|
FloatToSNorm(fStart, &iStart);
|
||||||
FloatToSNorm(fEnd, &iEnd);
|
FloatToSNorm(fEnd, &iEnd);
|
||||||
|
|
||||||
@ -333,12 +331,12 @@ namespace
|
|||||||
_In_reads_(NUM_PIXELS_PER_BLOCK) const float theTexelsU[])
|
_In_reads_(NUM_PIXELS_PER_BLOCK) const float theTexelsU[])
|
||||||
{
|
{
|
||||||
float rGradient[8];
|
float rGradient[8];
|
||||||
int i;
|
for (size_t i = 0; i < 8; ++i)
|
||||||
for (i = 0; i < 8; ++i)
|
|
||||||
{
|
{
|
||||||
rGradient[i] = pBC->DecodeFromIndex(i);
|
rGradient[i] = pBC->DecodeFromIndex(i);
|
||||||
}
|
}
|
||||||
for (i = 0; i < NUM_PIXELS_PER_BLOCK; ++i)
|
|
||||||
|
for (size_t i = 0; i < NUM_PIXELS_PER_BLOCK; ++i)
|
||||||
{
|
{
|
||||||
size_t uBestIndex = 0;
|
size_t uBestIndex = 0;
|
||||||
float fBestDelta = 100000;
|
float fBestDelta = 100000;
|
||||||
@ -360,12 +358,12 @@ namespace
|
|||||||
_In_reads_(NUM_PIXELS_PER_BLOCK) const float theTexelsU[])
|
_In_reads_(NUM_PIXELS_PER_BLOCK) const float theTexelsU[])
|
||||||
{
|
{
|
||||||
float rGradient[8];
|
float rGradient[8];
|
||||||
int i;
|
for (size_t i = 0; i < 8; ++i)
|
||||||
for (i = 0; i < 8; ++i)
|
|
||||||
{
|
{
|
||||||
rGradient[i] = pBC->DecodeFromIndex(i);
|
rGradient[i] = pBC->DecodeFromIndex(i);
|
||||||
}
|
}
|
||||||
for (i = 0; i < NUM_PIXELS_PER_BLOCK; ++i)
|
|
||||||
|
for (size_t i = 0; i < NUM_PIXELS_PER_BLOCK; ++i)
|
||||||
{
|
{
|
||||||
size_t uBestIndex = 0;
|
size_t uBestIndex = 0;
|
||||||
float fBestDelta = 100000;
|
float fBestDelta = 100000;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user