First of all thank you. It's far from being finished, but as I have said it's a pretty good start for editor or perhaps MOO2 remake.
From looking at some other MOO2 code, it looks like there are a lot of custom palettes so one load palette function may not work for all the LBX files.
Yes you're right, but it's not only that different palettes are used for different LBX files. There are internal palettes in some images. There are few palettes mixed with mouse cursors in FONTS.LBX and IFONTS.LBX. But! Take for example COUNCIL.LBX. The first file which in fact is mouse cursor has internal palette. The rest of the graphics in this file doesn't have internal palettes, but neither looks good with so called external palettes (FONTS.LBX and IFONTS.LBX). But if you take the internal palette from the first image in COUNCIL.LBX, other images look good!
It's not the only rather ugly thing that is seen in the graphics. IMO I think that some coders were smoking too much dope. I know that it was the time were size mattered, but this really could be done cleaner. For example. Take SHIPS.LBX. None of the ship images looks good with external palettes. But this is more complicated issue, because there are many small files, one by one pixel size, that doesn't do anything that are really palette holders. BUT! Those are not full palettes, but rather chunks merged with other palettes. The SHIPS.LBX is structured like this: SHIP_GRAPHIC1, SHIP_GRAPHIC2, ... , SHIP_GRAPHICn, PALETTEHOLDER, SHIPGRAPHICx1, SHIPGRAPHICx2, ... , SHIPGRAPHICxn, and so on. Those ships are categorised by colour. (I've only recently spotted that ship design DOESN'T belong to RACE, but to COLOR you choose in the game!) You can think about those ship groups as colour groups. Also if you take a look at some external palettes you can see there are few of them that obviously have the same colour representation for few places in the palette. These are probably the places where those palette chunks from internal palettes go (are merged). This is not a stupid idea, but to check which palettes are used for ships for example you'll have to get numerical representations of the colours in the ship graphics and then compare with those placeholder places in external palettes.
That's why a full blown converter and editor would need external representation of palette relations between most of the graphic files, external palettes and internal (merged) palettes in some kind of XML file. I want to do it, but currently my business projects are priority, so I won't have time for it. If anybody would like to decipher which palettes are used for what and where it would be really nice and could really speedup the development of the converter and the viewer.