This is part of a pixel blending operation to enhance precision.
typedef unsigned uint;
uint h(uint x) {
x &= 0xff;
return x << 8 | x;
}
uint g(uint x, uint y) {
return h(x) * h(y) >> 24;
}
I looked at the compiler output, and found a very interesting line.
g:
movzx edi, dil
movzx esi, sil
imul esi, edi
imul eax, esi, 66049 # <---
shr eax, 24
ret
This can be decompiled as,
uint g_(uint x, uint y) {
return (x & 0xff) * (y & 0xff) * 66049 >> 24;
}
I couldn't understand how multiplying by 66049 can produce the desired result. What is the math behind it?