TIP: Click on subject to list as thread! ANSI
echo: delphi
to: ALL
from: BRYAN SMITH
date: 1996-07-01 11:45:00
subject: XOR on Canvas.Pixels[]

I tried to get a moving dot on a "Canvas" by XOR-ing the pixel with
$00FFFFFF twice, once to create the dot, the second time to restore the
original color.  In doing so, I came across an unexpected (to me) effect of
the XOR function.  Can anybody explain what is going on ?
The code looks like this ...
Canvas.Pixels[x,y] := Canvas.Pixels[x,y] xor $00FFFFFF ;
My understanding is that XOR flips a bit in Canvas.Pixels if that bit is set
in the mask $00FFFFFF, or leaves it alone if that bit is not set.  However,
the results were as follows ...
Initial Colour          clNavy          clTeal          clBlue
Initial Pixel value     $00800000       $00808000       $00FF0000
After one XOR           $00C0DCC0       $00A4A0A0       $0000FFFF
After second XOR        $00000000       $00808080       $00FF0000
Final Colour is         clBlack         Grey            clBlue
Expected result ?       No              No              Yes
Typecasting to Longint before the XOR and back to TColor after the XOR does
not seem to help.
I suspect that I am getting caught up in some "closest color" rule.  Any
ideas ?  My general impression is that this works if the intial colour is of
high intensity (uses FF or 00) but not if it is a subdued colour.
--- PPoint 2.00
---------------
* Origin: Kingston, Canada (1:249/109.11)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.