Hi Tim,
I found this thread really interesting and spent some time attempting to understand the arrangement of the 24-bit RGB integer, and how the various values are calculated from it.
Here is my take on it:
The RGB value is a 24-bit integer (i.e. composed of 3-bytes, the first being blue, then green, and the highest being red). To understand it, I created
this diagram (using the RGB value from your first example).
When calculating the values, here was the previous function, as supplied by Tim's post:
(defun TrueColor-split ( c / )
(list (lsh (fix c) -16)
(lsh (lsh (fix c) 16) -24)
(lsh (lsh (fix c) 24) -24)
)
)
Hence to obtain, say, the Green value we use:
(lsh (lsh (fix c) 16) -24)
Here, all the bit-values are shifted 16 bits to the left, and being in a 32-bit environment the Red bits are consequently discarded and the Green bits occupy the 4th byte (located above the previous red byte), with the Blue bits occupying the 3rd byte (previously Red).
All the values are then shifted 24 bits to the right, and hence the green bits now occupy the first byte (previously blue), and the blue values are discarded, leaving just the green value which is returned.
Notice that, when calculating the Red value, the bits are only shifted down by 16 bits (discarding the green/blue bits) - this method hence assumes the 4th byte is empty and so doesn't bother to discard any possible values in the 4th byte.
However, in your override example, the 4th byte has value, and hence the assumption is not valid.
The correction, as supplied in your last post corrects this by first shifting the Red bits left by 8-bits, discarding any values that may be in the 4th byte, before shifting all the bits back down by 24 bits (3 bytes), meaning the Red values are now sitting in the 1st byte.
I hope my reasoning has been somewhat clear, and please don't take this that I'm teaching you to suck eggs, this was more for my own understanding that I thought I'd share. And, of course, if you see something wrong with the above, please do let me know.
Lee