A warning: palette reduction is by far the slowest step in Qwalk model conversion when you are converting something to MDL or MD2. Because of the "palettize_colour" function itself. I decided I wanted to do it exactly, and I'm not really sure how to optimize it, other than to, for each pixel, compare with all 256 colours. (Now that was a badly split infinitive...)
The other option would be something like to reduce 24-bit to 16-bit first, then you can use a offline generated lookup table (in fact GLQuake mentions some '15to8' conversion table which is probably this exactly, though I don't know what it was used for). It would be infinitely faster, but possibly lead to some minor posterization. I would probably recommend it if you were doing this in the game on load.
If you used a 16to8 or 15to8 table, and didn't support fullbrights (which aren't used in 24-bit colour images anyway), you could inline the lookup and unroll the loop a bit and it would be basically instantaneous.