Search code examples
colorsluargbole

How can I convert colour codes from OLE to RGB using Lua?


In the environment I'm working in, the implemented Lua functions will supply me with OLE colour codes whenever I ask it what colour is any given word, but, on the other hand, expect me to supply it with RGB colour codes whenever I want to colour any given word.

So far I've been googling the OLE colour codes in order to find their respective pages (along with their RGB colour codes) in htmlcsscolor.com because even though this site has the information it won't allow me to search a colour by its OLE colour code.

Is there a quicker way (maybe a function or at least instructions on how to convert) of retrieving a colour's RGB code from its OLE code (using Lua if possible)?


Solution

  • The OLE Color code can be converted to an "RGB color code" (which is an ambiguous term here, because Lua has no inherent concept of colors) as follows:

    • The red component is ole_color % 256.
    • The green component is (ole_color / 256) % 256.
    • The blue component is (ole_color / 65536) % 256.

    Each component ranges from 0 to 255.

    (Note that shifts and the bitwise AND would be better here, but Lua doesn't support bitwise operations without aid from a helper library; depending on what program uses Lua, the program may provide built-in functions for bitwise operations.)