Jump to content

[C&C1/RA1/TS/RA2] Editing paletted graphics in Gimp


Nyerguds

Recommended Posts

Nowadays, it seems that the very concept of paletted graphics doesn't get much attention in image editors anymore. In fact, many people don't even grasp the concept of colour palettes anymore. So I've decided to write a tutorial explaining what paletted graphics are in general, how they work in the Command & Conquer games, and how to edit them with Gimp.

Gimp is probably not the ideal image editor to use for paletted graphics, but it does, in fact, support them (unlike programs like MS Paint), and it's free. It has its drawbacks, though. The relevant options are not always easy to find, and its brush tools have ridiculously large default sizes for pixel editing work, which are always reset on restart of the program.

 

Paletted graphics

Right. First of all, what are paletted graphics? I'm not really an expert on the history behind it all, but basically, they are a way to save memory.

In a normal, full-colour image, each pixel is assigned a colour. Such a colour is a triplet of bytes, each byte being one colour component. The three are Red, Green, and Blue. This means that each pixel on an image would take up three bytes. On modern image formats, a fourth is assigned for transparency, but that's irrelevant in C&C graphics, so we won't discuss that here.

Paletted graphics, in contrast, use only one byte per pixel (or less, but we'll stick to C&C's 8-bit-per-pixel images here for now). A paletted image's file header contains a list of 256 colour triplets which define all colours that will be used on the image. Once you got that palette, each actual pixel on the image simply needs to refer to a colour index on that palette; a number from 0 to 255, a value which fits inside a single byte. So at the extra cost of adding the palette in advance, the actual image can be a lot smaller in file size.

There's some historical reasons for this in the way graphics cards handle graphics using palettes, but since I don't really know the specifics of that, let's not go deeper into that.

Instead, let's look at a very peculiar kind of paletted image formats: game sprites.

What's so odd about game sprites, like the C&C SHP format, is that they are paletted images without colours saved inside them. Instead, they will use whatever colours the game (or an external viewing tool, like XCC Mixer) gives it. This explains why C&C1 graphics will work perfectly fine in RA1, but will look all messed up: the file format is the same, but the C&C graphics were made for a different palette, meaning the palette indices on these graphics are all wrong in RA1's colour palette.

So, you may wonder, why did Westwood not simply include the palette? There are two reasons for that.

The first: in C&C1 and RA1, the entire screen, at any given time, contains only a single palette. The game itself can only show graphics of one single 256-colour palette at the same time.

The second: Command & Conquer 1 uses the same unit and structure graphics for all theaters, while Desert theater has a different palette than Temperate/Winter. How is this done? Simple, actually: the palettes have parts that are different, and parts that are the same. The units, structures and general game UI are made so they ONLY use the palette indices on which the colours remain the same between all theaters.

In Tiberian Sun and Red Alert 2, they decided to keep the same 256-colour formats because of the ease of remapping the house colours on 256-colour graphics. The games themselves, though, are high colour, and can handle showing several colour paletted graphics with different palettes at the same time.

I hope this gives some insight into the game's graphics formats.

 

Usage in Gimp

(everything here was tested on Gimp 2.8.0)

From what I've seen, Gimp does not have any feature to import or export colour palettes in specific palette file formats. However, like any image editor that supports colour palettes, it can simply get the palette from the image itself.

First of all, to see the palette in a 256-colour image in Gimp, go to [Windows] -> [Dockable Dialogs] -> [Colormap]. This will give you a dialog on which you can see the current image's palette at all times.

You can click on the colours in this colour map dialog to easily select them for editing. Another handy feature for pixel work is to enable the grid in Gimp. You can find it under [View] -> [show Grid].

So, what we need to do to get the palettes into Gimp is simply convering some SHP file to PNG with XCC Mixer, with the palette we need, and then opening that in Gimp to get the palette out. For completeness' sake, I'll go over the steps including XCC Mixer:

  • In XCC Mixer, press ctrl+p, and select the palette you want to import into Gimp.
  • Right-click on any SHP file you want, and press [Copy As PNG].
  • If the conversion created multiple PNG images, delete all but one of them. It doesn't matter at all what is on the image; only the palette saved in its file header is important.
  • Open the remaining single image in Gimp.
  • In Gimp, go to [Windows] -> [Dockable Dialogs] -> [palettes]. This will give you the list of Gimp's internal colour palettes.
  • In that list, right click and select [import Palette]. It will open the "Import Palette" dialog.
  • On the dialog, change the radio button for the source selection to "Image", and select the image you opened as source to take the palette from.
  • At the bottom of the dialog, give the palette a name (easiest would be to use the same name as the one in XCC Mixer) and press [import]. The palette will now show up in Gimp's palettes list.

So, what can we do with these imported palettes? One of the uses is the palette conversion I covered in my other tutorial. Here's how to do that conversion in Gimp:

  • Open the image in Gimp.
  • Go to [image] -> [Mode]. You'll see the mode is either [RGB] or [indexed]. If it is already Indexed, change it to RGB.
  • Go to [image] -> [Mode] again, and now select [indexed]. A colour conversion dialog will appear.
  • In the dialog, select "use custom palette", select one of the palettes you imported before, UNCHECK "remove unused colours", set Dithering to 'None', and click [Convert].

That's it. Export the image as png or something again, and you're done.

Another possibility is to change an image's palette without adapting the graphics to the new palette. This is handy if you have graphics converted with the standard yellow remap, but you want to change them to the purple palettes as remap for editing.

To do such a palette replacement:

  • Go to [Colors] -> [Map] -> [set Color Map].
  • Click the palette button, select the new palette, and press [Close]
  • Press [OK].

That's it! You should now see the image adapt its colours to the new palette.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...