DirectXTex: some code cleanup

This commit is contained in:
walbourn_cp 2013-06-10 15:16:08 -07:00
parent ae8a8cfa9a
commit 8a267b10b2

View File

@ -1110,8 +1110,9 @@ bool _LoadScanline( XMVECTOR* pDestination, size_t count,
if ( sPtr >= ePtr ) break;\ if ( sPtr >= ePtr ) break;\
func( dPtr++, *sPtr++ );\ func( dPtr++, *sPtr++ );\
}\ }\
return true; \
}\ }\
return true; return false;
_Use_decl_annotations_ _Use_decl_annotations_
bool _StoreScanline( LPVOID pDestination, size_t size, DXGI_FORMAT format, bool _StoreScanline( LPVOID pDestination, size_t size, DXGI_FORMAT format,
@ -1186,8 +1187,9 @@ bool _StoreScanline( LPVOID pDestination, size_t size, DXGI_FORMAT format,
ps8[1] = ps8[2] = ps8[3] = 0; ps8[1] = ps8[2] = ps8[3] = 0;
dPtr += 2; dPtr += 2;
} }
}
return true; return true;
}
return false;
case DXGI_FORMAT_R10G10B10A2_UNORM: case DXGI_FORMAT_R10G10B10A2_UNORM:
STORE_SCANLINE( XMUDECN4, XMStoreUDecN4 ); STORE_SCANLINE( XMUDECN4, XMStoreUDecN4 );
@ -1204,8 +1206,7 @@ bool _StoreScanline( LPVOID pDestination, size_t size, DXGI_FORMAT format,
{ {
if ( sPtr >= ePtr ) break; if ( sPtr >= ePtr ) break;
XMVECTOR N = XMVectorMultiply(*sPtr++, Scale); XMVECTOR N = XMVectorMultiplyAdd( *sPtr++, Scale, Bias );
N = XMVectorAdd( N, Bias );
N = XMVectorClamp( N, g_XMZero, C ); N = XMVectorClamp( N, g_XMZero, C );
XMFLOAT4A tmp; XMFLOAT4A tmp;
@ -1217,8 +1218,9 @@ bool _StoreScanline( LPVOID pDestination, size_t size, DXGI_FORMAT format,
| (((uint32_t)tmp.x & 0x3FF)); | (((uint32_t)tmp.x & 0x3FF));
++dPtr; ++dPtr;
} }
}
return true; return true;
}
return false;
case DXGI_FORMAT_R10G10B10A2_UINT: case DXGI_FORMAT_R10G10B10A2_UINT:
STORE_SCANLINE( XMUDEC4, XMStoreUDec4 ); STORE_SCANLINE( XMUDEC4, XMStoreUDec4 );
@ -1264,8 +1266,9 @@ bool _StoreScanline( LPVOID pDestination, size_t size, DXGI_FORMAT format,
if ( sPtr >= ePtr ) break; if ( sPtr >= ePtr ) break;
XMStoreFloat( dPtr++, *(sPtr++) ); XMStoreFloat( dPtr++, *(sPtr++) );
} }
}
return true; return true;
}
return false;
case DXGI_FORMAT_R32_UINT: case DXGI_FORMAT_R32_UINT:
if ( size >= sizeof(uint32_t) ) if ( size >= sizeof(uint32_t) )
@ -1277,8 +1280,9 @@ bool _StoreScanline( LPVOID pDestination, size_t size, DXGI_FORMAT format,
XMVECTOR v = XMConvertVectorFloatToUInt( *(sPtr++), 0 ); XMVECTOR v = XMConvertVectorFloatToUInt( *(sPtr++), 0 );
XMStoreInt( dPtr++, v ); XMStoreInt( dPtr++, v );
} }
}
return true; return true;
}
return false;
case DXGI_FORMAT_R32_SINT: case DXGI_FORMAT_R32_SINT:
if ( size >= sizeof(uint32_t) ) if ( size >= sizeof(uint32_t) )
@ -1290,8 +1294,9 @@ bool _StoreScanline( LPVOID pDestination, size_t size, DXGI_FORMAT format,
XMVECTOR v = XMConvertVectorFloatToInt( *(sPtr++), 0 ); XMVECTOR v = XMConvertVectorFloatToInt( *(sPtr++), 0 );
XMStoreInt( dPtr++, v ); XMStoreInt( dPtr++, v );
} }
}
return true; return true;
}
return false;
case DXGI_FORMAT_D24_UNORM_S8_UINT: case DXGI_FORMAT_D24_UNORM_S8_UINT:
if ( size >= sizeof(uint32_t) ) if ( size >= sizeof(uint32_t) )
@ -1307,8 +1312,9 @@ bool _StoreScanline( LPVOID pDestination, size_t size, DXGI_FORMAT format,
*dPtr++ = (static_cast<uint32_t>( f.x * 16777215.f ) & 0xFFFFFF) *dPtr++ = (static_cast<uint32_t>( f.x * 16777215.f ) & 0xFFFFFF)
| ((static_cast<uint32_t>( f.y ) & 0xFF) << 24); | ((static_cast<uint32_t>( f.y ) & 0xFF) << 24);
} }
}
return true; return true;
}
return false;
case DXGI_FORMAT_R8G8_UNORM: case DXGI_FORMAT_R8G8_UNORM:
STORE_SCANLINE( XMUBYTEN2, XMStoreUByteN2 ) STORE_SCANLINE( XMUBYTEN2, XMStoreUByteN2 )
@ -1332,8 +1338,9 @@ bool _StoreScanline( LPVOID pDestination, size_t size, DXGI_FORMAT format,
float v = XMVectorGetX( *sPtr++ ); float v = XMVectorGetX( *sPtr++ );
*(dPtr++) = XMConvertFloatToHalf(v); *(dPtr++) = XMConvertFloatToHalf(v);
} }
}
return true; return true;
}
return false;
case DXGI_FORMAT_D16_UNORM: case DXGI_FORMAT_D16_UNORM:
case DXGI_FORMAT_R16_UNORM: case DXGI_FORMAT_R16_UNORM:
@ -1347,8 +1354,9 @@ bool _StoreScanline( LPVOID pDestination, size_t size, DXGI_FORMAT format,
v = std::max<float>( std::min<float>( v, 1.f ), 0.f ); v = std::max<float>( std::min<float>( v, 1.f ), 0.f );
*(dPtr++) = static_cast<uint16_t>( v*65535.f + 0.5f ); *(dPtr++) = static_cast<uint16_t>( v*65535.f + 0.5f );
} }
}
return true; return true;
}
return false;
case DXGI_FORMAT_R16_UINT: case DXGI_FORMAT_R16_UINT:
if ( size >= sizeof(uint16_t) ) if ( size >= sizeof(uint16_t) )
@ -1361,8 +1369,9 @@ bool _StoreScanline( LPVOID pDestination, size_t size, DXGI_FORMAT format,
v = std::max<float>( std::min<float>( v, 65535.f ), 0.f ); v = std::max<float>( std::min<float>( v, 65535.f ), 0.f );
*(dPtr++) = static_cast<uint16_t>(v); *(dPtr++) = static_cast<uint16_t>(v);
} }
}
return true; return true;
}
return false;
case DXGI_FORMAT_R16_SNORM: case DXGI_FORMAT_R16_SNORM:
if ( size >= sizeof(int16_t) ) if ( size >= sizeof(int16_t) )
@ -1375,8 +1384,9 @@ bool _StoreScanline( LPVOID pDestination, size_t size, DXGI_FORMAT format,
v = std::max<float>( std::min<float>( v, 1.f ), -1.f ); v = std::max<float>( std::min<float>( v, 1.f ), -1.f );
*(dPtr++) = static_cast<uint16_t>( v * 32767.f ); *(dPtr++) = static_cast<uint16_t>( v * 32767.f );
} }
}
return true; return true;
}
return false;
case DXGI_FORMAT_R16_SINT: case DXGI_FORMAT_R16_SINT:
if ( size >= sizeof(int16_t) ) if ( size >= sizeof(int16_t) )
@ -1389,8 +1399,9 @@ bool _StoreScanline( LPVOID pDestination, size_t size, DXGI_FORMAT format,
v = std::max<float>( std::min<float>( v, 32767.f ), -32767.f ); v = std::max<float>( std::min<float>( v, 32767.f ), -32767.f );
*(dPtr++) = static_cast<int16_t>(v); *(dPtr++) = static_cast<int16_t>(v);
} }
}
return true; return true;
}
return false;
case DXGI_FORMAT_R8_UNORM: case DXGI_FORMAT_R8_UNORM:
if ( size >= sizeof(uint8_t) ) if ( size >= sizeof(uint8_t) )
@ -1403,8 +1414,9 @@ bool _StoreScanline( LPVOID pDestination, size_t size, DXGI_FORMAT format,
v = std::max<float>( std::min<float>( v, 1.f ), 0.f ); v = std::max<float>( std::min<float>( v, 1.f ), 0.f );
*(dPtr++) = static_cast<uint8_t>( v * 255.f); *(dPtr++) = static_cast<uint8_t>( v * 255.f);
} }
}
return true; return true;
}
return false;
case DXGI_FORMAT_R8_UINT: case DXGI_FORMAT_R8_UINT:
if ( size >= sizeof(uint8_t) ) if ( size >= sizeof(uint8_t) )
@ -1417,8 +1429,9 @@ bool _StoreScanline( LPVOID pDestination, size_t size, DXGI_FORMAT format,
v = std::max<float>( std::min<float>( v, 255.f ), 0.f ); v = std::max<float>( std::min<float>( v, 255.f ), 0.f );
*(dPtr++) = static_cast<uint8_t>(v); *(dPtr++) = static_cast<uint8_t>(v);
} }
}
return true; return true;
}
return false;
case DXGI_FORMAT_R8_SNORM: case DXGI_FORMAT_R8_SNORM:
if ( size >= sizeof(int8_t) ) if ( size >= sizeof(int8_t) )
@ -1431,8 +1444,9 @@ bool _StoreScanline( LPVOID pDestination, size_t size, DXGI_FORMAT format,
v = std::max<float>( std::min<float>( v, 1.f ), -1.f ); v = std::max<float>( std::min<float>( v, 1.f ), -1.f );
*(dPtr++) = static_cast<int8_t>( v * 127.f ); *(dPtr++) = static_cast<int8_t>( v * 127.f );
} }
}
return true; return true;
}
return false;
case DXGI_FORMAT_R8_SINT: case DXGI_FORMAT_R8_SINT:
if ( size >= sizeof(int8_t) ) if ( size >= sizeof(int8_t) )
@ -1445,8 +1459,9 @@ bool _StoreScanline( LPVOID pDestination, size_t size, DXGI_FORMAT format,
v = std::max<float>( std::min<float>( v, 127.f ), -127.f ); v = std::max<float>( std::min<float>( v, 127.f ), -127.f );
*(dPtr++) = static_cast<int8_t>( v ); *(dPtr++) = static_cast<int8_t>( v );
} }
}
return true; return true;
}
return false;
case DXGI_FORMAT_A8_UNORM: case DXGI_FORMAT_A8_UNORM:
if ( size >= sizeof(uint8_t) ) if ( size >= sizeof(uint8_t) )
@ -1459,8 +1474,9 @@ bool _StoreScanline( LPVOID pDestination, size_t size, DXGI_FORMAT format,
v = std::max<float>( std::min<float>( v, 1.f ), 0.f ); v = std::max<float>( std::min<float>( v, 1.f ), 0.f );
*(dPtr++) = static_cast<uint8_t>( v * 255.f); *(dPtr++) = static_cast<uint8_t>( v * 255.f);
} }
}
return true; return true;
}
return false;
case DXGI_FORMAT_R1_UNORM: case DXGI_FORMAT_R1_UNORM:
if ( size >= sizeof(uint8_t) ) if ( size >= sizeof(uint8_t) )
@ -1482,8 +1498,9 @@ bool _StoreScanline( LPVOID pDestination, size_t size, DXGI_FORMAT format,
} }
*(dPtr++) = pixels; *(dPtr++) = pixels;
} }
}
return true; return true;
}
return false;
case DXGI_FORMAT_R9G9B9E5_SHAREDEXP: case DXGI_FORMAT_R9G9B9E5_SHAREDEXP:
if ( size >= sizeof(XMFLOAT3SE) ) if ( size >= sizeof(XMFLOAT3SE) )
@ -1522,8 +1539,9 @@ bool _StoreScanline( LPVOID pDestination, size_t size, DXGI_FORMAT format,
dPtr->zm = static_cast<uint32_t>( round_to_nearest(b * ScaleR) ); dPtr->zm = static_cast<uint32_t>( round_to_nearest(b * ScaleR) );
++dPtr; ++dPtr;
} }
}
return true; return true;
}
return false;
case DXGI_FORMAT_R8G8_B8G8_UNORM: case DXGI_FORMAT_R8G8_B8G8_UNORM:
if ( size >= sizeof(XMUBYTEN4) ) if ( size >= sizeof(XMUBYTEN4) )
@ -1537,8 +1555,9 @@ bool _StoreScanline( LPVOID pDestination, size_t size, DXGI_FORMAT format,
XMVECTOR v = XMVectorSelect( v1, v0, g_XMSelect1110 ); XMVECTOR v = XMVectorSelect( v1, v0, g_XMSelect1110 );
XMStoreUByteN4( dPtr++, v ); XMStoreUByteN4( dPtr++, v );
} }
}
return true; return true;
}
return false;
case DXGI_FORMAT_G8R8_G8B8_UNORM: case DXGI_FORMAT_G8R8_G8B8_UNORM:
if ( size >= sizeof(XMUBYTEN4) ) if ( size >= sizeof(XMUBYTEN4) )
@ -1554,8 +1573,9 @@ bool _StoreScanline( LPVOID pDestination, size_t size, DXGI_FORMAT format,
XMVECTOR v = XMVectorSelect( v1, v0, select1101 ); XMVECTOR v = XMVectorSelect( v1, v0, select1101 );
XMStoreUByteN4( dPtr++, v ); XMStoreUByteN4( dPtr++, v );
} }
}
return true; return true;
}
return false;
case DXGI_FORMAT_B5G6R5_UNORM: case DXGI_FORMAT_B5G6R5_UNORM:
if ( size >= sizeof(XMU565) ) if ( size >= sizeof(XMU565) )
@ -1569,8 +1589,9 @@ bool _StoreScanline( LPVOID pDestination, size_t size, DXGI_FORMAT format,
v = XMVectorMultiply( v, s_Scale ); v = XMVectorMultiply( v, s_Scale );
XMStoreU565( dPtr++, v ); XMStoreU565( dPtr++, v );
} }
}
return true; return true;
}
return false;
case DXGI_FORMAT_B5G5R5A1_UNORM: case DXGI_FORMAT_B5G5R5A1_UNORM:
if ( size >= sizeof(XMU555) ) if ( size >= sizeof(XMU555) )
@ -1586,8 +1607,9 @@ bool _StoreScanline( LPVOID pDestination, size_t size, DXGI_FORMAT format,
dPtr->w = ( XMVectorGetW( v ) > threshold ) ? 1 : 0; dPtr->w = ( XMVectorGetW( v ) > threshold ) ? 1 : 0;
++dPtr; ++dPtr;
} }
}
return true; return true;
}
return false;
case DXGI_FORMAT_B8G8R8A8_UNORM: case DXGI_FORMAT_B8G8R8A8_UNORM:
case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB: case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB:
@ -1600,8 +1622,9 @@ bool _StoreScanline( LPVOID pDestination, size_t size, DXGI_FORMAT format,
XMVECTOR v = XMVectorSwizzle<2, 1, 0, 3>( *sPtr++ ); XMVECTOR v = XMVectorSwizzle<2, 1, 0, 3>( *sPtr++ );
XMStoreUByteN4( dPtr++, v ); XMStoreUByteN4( dPtr++, v );
} }
}
return true; return true;
}
return false;
case DXGI_FORMAT_B8G8R8X8_UNORM: case DXGI_FORMAT_B8G8R8X8_UNORM:
case DXGI_FORMAT_B8G8R8X8_UNORM_SRGB: case DXGI_FORMAT_B8G8R8X8_UNORM_SRGB:
@ -1614,8 +1637,9 @@ bool _StoreScanline( LPVOID pDestination, size_t size, DXGI_FORMAT format,
XMVECTOR v = XMVectorPermute<2, 1, 0, 7>( *sPtr++, g_XMIdentityR3 ); XMVECTOR v = XMVectorPermute<2, 1, 0, 7>( *sPtr++, g_XMIdentityR3 );
XMStoreUByteN4( dPtr++, v ); XMStoreUByteN4( dPtr++, v );
} }
}
return true; return true;
}
return false;
#ifdef DXGI_1_2_FORMATS #ifdef DXGI_1_2_FORMATS
case DXGI_FORMAT_B4G4R4A4_UNORM: case DXGI_FORMAT_B4G4R4A4_UNORM:
@ -1630,8 +1654,9 @@ bool _StoreScanline( LPVOID pDestination, size_t size, DXGI_FORMAT format,
v = XMVectorMultiply( v, s_Scale ); v = XMVectorMultiply( v, s_Scale );
XMStoreUNibble4( dPtr++, v ); XMStoreUNibble4( dPtr++, v );
} }
}
return true; return true;
}
return false;
// We don't support the video formats ( see IsVideo function ) // We don't support the video formats ( see IsVideo function )
#endif // DXGI_1_2_FORMATS #endif // DXGI_1_2_FORMATS