Difference between revisions of "Save paletted image files"

From TTWiki
Jump to navigationJump to search
m (Fix: there shouldn't be a pipe in url links)
m (missed one)
Line 1: Line 1:
 
This pagecovers how to apply a palette to a graphics file in several graphics editor. If your editor is not listed here and you know how to work with palettes using it, please add it here.
 
This pagecovers how to apply a palette to a graphics file in several graphics editor. If your editor is not listed here and you know how to work with palettes using it, please add it here.
   
You find a range of palettes with and without action colours (which might be useful for conversions) for various graphics programmes on the [http://dev.openttdcoop.org/documents/1| DevZone]
+
You find a range of palettes with and without action colours (which might be useful for conversions) for various graphics programmes on the [http://dev.openttdcoop.org/documents/1 DevZone]
   
   

Revision as of 18:14, 16 April 2012

This pagecovers how to apply a palette to a graphics file in several graphics editor. If your editor is not listed here and you know how to work with palettes using it, please add it here.

You find a range of palettes with and without action colours (which might be useful for conversions) for various graphics programmes on the DevZone


Adobe Photoshop

Fig. 1: Photoshop palette window showing in this case the Windows palette
Fig. 2: Photoshop indexed color window

In this subsection it is explained how to create a palette file and how to apply it using Adobe Photoshop (CS5 is used here, but identical or similar procedures apply in other versions of Photoshop). It is assumed that you have a clue about working with Photoshop.

Retreiving a palette file

You can use an existing graphics file that has the correct palette applied to retrieve the palette and save it to a separate file. This palette can then be applied to graphics files that don't have a palette. You can skip this part if you have downloaded a premade palette file.

  1. Open a graphics file of which you know it has the correct palette in Photoshop. Decoded NewGRFs (using GRFCodec) surely will have the correct palette applied.
  2. Go to Image > Mode > Color Table... The window from Fig. 1 will appear.
  3. Click Save... and store the palette file (*.act) somewhere on your computer.

Applying a palette from file

The Windows or DOS TTD palette must be applied to your graphics file for them to work in GRFCodec and NML. For the next steps we assume that you have a palette file (*.act) with the palette of your choice stored somewhere on your computer.

  1. Open a graphics file in Photoshop.
  2. Go to Image > Mode and check if RGB Color is checked. Select it if that is not the case, which will convert your graphics file to full-colour, maintaining the colours as they appear.
  3. Go to Image > Mode > Indexed Color... The window from Fig. 2 will appear.
  4. From the Palette drop-down, select Custom... The palette window (see Fig. 1) appears.
  5. Click Load... and browse the palette file. Click OK to close the palette window.
  6. In the indexed color window, you may select your choise of Dither. The dither will convert all colours that are in the graphics file but not in the palette to the palette colours. Either use the Diffusion dither (with preserving exact colors) or the Noise dither. Play around with the settings using the Preview to see the result and pick whatever looks best. If the sprites in the image file were drawn properly (using only palette colours), you should see no difference.
  7. Click OK to apply the palette file (and dither) to this image file. Note that this will flatten all layers (if any) in your graphics file.
  8. Save the file as (preferrably) a PNG image.

Important note on PCX files in Photoshop

Photoshop has a quirk in which palettes from PCX files are read and written backwards. This is no problem is you stay with pcx, but it is if you convert from pcx to png (and the other way round). Any such conversion will have the palette stored backwards in the target file, making it unusable by GRFCodec or NML. Note:

  • You cannot use the palette file saved from a PCX file for a PNG file;
  • You cannot use the palette file saved from a PNG file for a PCX file;
  • When converting PCX <-> PNG, you must convert to RGB Color first and then back to Indexed Color, applying the palette file of your target file format (e.g. when converting to PNG, apply the palette retrieved from a PNG file).

GIMP

Fig. 3: GIMP palette window
Fig. 4: GIMP import pallete window showing the TTD Windows palette
Fig. 5: GIMP indexed color conversion window

In this subsection it is explained how to create a palette file and how to apply it using the GNU Image Manipulation Program (2.6 is used here, but identical or similar procedures should apply in other versions). It is assumed that you have a clue about working with GIMP.

Download a palette file

In case of doubt you simply want to get the DOS palette. See the above link to the DevZone for more options.

Import a palette file

Before you can use a palette in GIMP you must import it. You can import a palette form a file that has the correct palette applied or import a downloaded palette (*.gpl) file.

  1. Open a graphics file of which you know it has the correct palette in GIMP if you want to get the palette from that file (otherwise go to the next step). Decoded NewGRFs (using GRFCodec) surely will have the correct palette applied.
  2. Go to Windows > Dockable Dialogs > Palettes... The window from Fig. 3 with a list of builtin palettes will appear.
  3. Rightclick anywhere in the list with palettes and click Import Palette... from the context menu. The window from Fig 4. will appear.
  4. Now choose if you want to retrieve the palette from the opened image or if you want to import a palette from a palette file.
    1. Select Image below Select Source to get the palette from the current image file.
    2. Select Palette file below Select Source and browse to a *.gpl palette file to get the palette from that file.
  5. The palette will be shown. Give the palette a name and click Import. The TTD palette will now be added to the list of palettes.

Applying a palette

Make sure the palette you want to use is imported in GIMP (see above).

  1. Open a graphics file in GIMP.
  2. Go to Image > Mode and check if RGB is selected. Select it if that is not the case, which will convert your graphics file to full-colour, maintaining the colours as they appear.
  3. Go to Image > Mode > Indexed... The window from Fig. 5 will appear.
  4. Select Use custom palette and then select the TTD palette from the palette list (click on the button showing a palette).
  5. Make sure to uncheck Remove unused colors from colormap.
  6. In the same window, you may select your choise of Dithering. The dither will convert all colours that are in the graphics file but not in the palette to the palette colours. Play around with the settings to find the best result. If the sprites in the image file were drawn properly (using only palette colours), you should see no difference.
  7. Click Convert to apply the palette (and dither) to this image file.
  8. Save the file as (preferrably) a PNG image.

Saving a palette to file

If you want to share your imported palette, you must have a palette file.

  1. Exit GIMP to automatically save your palette(s).
  2. Reopen GIMP (and the palette window via Windows > Dockable Dialogs > Palettes if this is closed).
  3. Rightclick your palette in the palette window and choose Copy Palette Location. This copies the path to the palette file to the clipboard
  4. With GIMP open, get the clipboard contents and browse to the specified folder (usualy ~/.gimp-2.6/palettes).
  5. Copy or upload the *.gpl file with the palette from there.

Surely there must be an easier way to do this, but I haven't found that so far.