Matteo Bruni (@Mystral) commented about dlls/d3dx9_36/surface.c:
*/
if (src_ctype == CTYPE_FLOAT || (src_ctype == CTYPE_SNORM && channel_bits > 8)
|| (src_ctype != CTYPE_SNORM && channel_bits >= 8))
{
color_key_out->color_key_min[i] = color_key_out->color_key_max[i] = ck_channel;
continue;
}
channel_conv = ((float)ck_channel) / 255.0f;
if (src_ctype == CTYPE_SNORM)
{
const uint32_t max_value = (1u << (channel_bits - 1)) - 1;
unique_values = (1u << channel_bits) - 2;
channel_conv = (channel_conv * 2.0f) - 1.0f;
channel_conv = ((int8_t)(channel_conv * max_value + 0.5f)) / (float)max_value;
A possible alternative, maybe nicer but not really any different in the generated code: ``` channel_conv = rintf(channel_conv * max_value) / max_value; ```