What is the inversion of colors algorithm ? How can we implement this?
For example
Black->White
Blue-&g开发者_如何学Got;Yellow
You do this:
RInv = 255 - R
GInv = 255 - G
BInv = 255 - B
which can be done with XOR as follows:
RInv = R xor 255
GInv = G xor 255
BInv = B xor 255
The xor
works because we want the sum of R and RInv to be equal to 255:
RInv = 255 - R
=> RInv + R = 255
and, since a xor
on binary numbers is an addition over the Galois field mod 2, we get:
C = A xor B
=> C xor B = A xor B xor B = A
RInv = 255 xor R
RInv xor R = 255
精彩评论