Matteo Bruni (@Mystral) commented about dlls/d3dx9_36/surface.c:
+ + 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; + channel_conv = (channel_conv + 1.0f) / 2.0f; + } + else + { + unique_values = (1u << channel_bits) - 1; + channel_conv = ((uint8_t)(channel_conv * unique_values + 0.5f)) / unique_values; + } + + channel_conv = channel_conv * 255.0f + 0.5f; + slop = ((255.0f - unique_values) / unique_values) / 2.0f; + color_key_out->color_key_min[i] = d3dx_clamp(channel_conv - slop, 0.0f, 255.0f); + color_key_out->color_key_max[i] = d3dx_clamp(channel_conv + slop, 0.0f, 255.0f); Similarly here:
channel_conv = channel_conv * 255.0f;
slop = (255.0f - unique_values) / unique_values / 2.0f;
color_key_out->color_key_min[i] = rintf(d3dx_clamp(channel_conv - slop, 0.0f, 255.0f));
color_key_out->color_key_max[i] = rintf(d3dx_clamp(channel_conv + slop, 0.0f, 255.0f));
The whole conversion math is quite questionable, but the results seem to match native pretty closely so I guess it is what it is :sweat_smile: -- https://gitlab.winehq.org/wine/wine/-/merge_requests/7711#note_102880