If I were to do this "from the ground up," I might make each country shape its own layer black only, with the layers named uniquely, and apply a layer effect "color overlay." To achieve the desired color, and a stroke to define the outline. If there is more detail to the map, and you only want to alter the background color, you can overlay other items with a different layer.
Flood fill can be tricky depending on non-contiguous areas and anti-aliasing of the item, so the layer effect would probably give you an easier time.
To view all countries, you toggle all layers visible. To programmatically change a color, you can now reference the layer by its unique ID, and then alter the color overlay property.
The specifics of how to do this will depend on your need and the program you use. I know that both GIMP and PS are scriptable (and AFAIK, support color overlay and stroke).
With Photoshop, you can use vbscript and then have access to the OS file system (I don't think javascript allows this?). The benefit of this is that you could create a data file with the country's layer name and color info (etc) and possibly calculate different things on the fly. It also supports variables and data files IIRC (the limits of which I am not familiar).
Knowing open source, GIMP probably gives you deeper access to the backend for scripting.