开发者

xor and color inversion?

开发者 https://www.devze.com 2023-02-22 18:26 出处:网络
What is the inversion of colors algorithm ? How can we implement this? For example Black->White Blue-&g开发者_如何学Got;Yellow

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
0

精彩评论

暂无评论...
验证码 换一张
取 消