Fallout 2 utility How to recolor sprites automatically: a Python script to replace colors in FRM files.

Dr Felix

First time out of the vault
Have you ever wanted a bright pink super mutant? Maybe you want to give Myron a red shirt, make combat armour blue, make a critter's blood green, or change the skin or hair colour of some NPC.

I made a Python script to recolor FRM files en masse (it also works for .FR0 to .FR5) while editing sprites for a mod I'm making and I thought someone else might find it useful. I put comments with instructions into the script so you can still use it if you don't know anything about Python.

To use it, you first need to use the Fallout default colour palette as a reference. You can read details about FRM and PAL files in Fallout here:
But the basic idea is that the palette is a 16x16 grid of 256 colours used in the game, and an FRM file references these colours with an index from 0-255 for each pixel of each frame, rather than a full RGB description. The indices on the palette start at 0 at the top left and increase left to right, then top to bottom. What my script does is find each index you want to replace in the FRM file and replaces it with an index that you specify. So you need to look at the colour palette to figure out what indices to put into the script. I suggest using Palette suite:
It will open the Default.act colour table which you can use as a reference, and it conveniently shows the index of each colour in the bottom left. You can use Palette Suite to edit the .act for testing on a single frame first (ie copy and paste one colour into a different square) and display it in FRM Workshop:
You could also use Jochua's Frame Animator but I found FRM Workshop worked better for me loading a custom .act palette, plus it allows you to zoom in on the sprite.

As an example, my goal was to recolor green into orange to change the Fallout 1 Katja/Nicole sprite to have red hair instead of green. Here's the default palette on the left and on the right is what I changed it to; I just copied the orange-brown colours from 144 to 155 onto the green squares roughly accounting for shade. The 0th index looks white but actually means a transparent pixel in game, and the white pixels on the last couple of rows are special animated pixels in various colours for forcefields, computers, fires, and radioactive goo.

palsuite.png
palsuite2.png


Once you've found a recolouring that looks good in FRM workshop, you need to manually put the indices of each replacement you did into these lines of the code starting with "frameimage = ":

script.png


Each of these lines replaces all of one index (eg 219 in the first one) with another (eg 151 in the first one). Once you've put your index replacements into the script, delete any extra lines you aren't using, or copy and paste them to make more if you need. Just make sure you preserve the indentation if you do, otherwise it breaks the code. You could do other creative things here like only replacing colours in the top 1/4 of the frame to recolour hair/hats but not pants, for example. If you want to do something like that but have trouble let me know and I'll try to help.
Once done, change the lines at the start of the script to specify your input and output folders/file name and run the script. You don't actually input the .act file from PalSuite into the script at all, it's just so you can test out what colours to replace in a visually easy way. By the way, use .act instead of .pal. Palsuite doesn't seem to be compatible with Fallout's .pal format.

Anyway, here's my resulting ginger sprite in game.

recolour.png


I've uploaded two versions of the script. One recolours just one file that you specify the file name of at the top of the script. Use this one for testing. It also has a boolean flag for whether the file is FRM or FR0-5, so make sure you have that correct.
The other version recolours all files (FRM and FR0-5) in the input folder you indicate and saves them in the output folder. It takes a few minutes to get through them all but it's much faster than painting them manually.
 

Attachments

Back
Top