I confirm if you want to use the code in the IconEditor you can.
Even it looks complicated to you. It tries to reproduce the ColorPalette of Windows.
I am waiting for the new Module feature in the next version of B4PPC, so this kind of code can be put into a module and reused by anyone with almost no need of adaptation.