home *** CD-ROM | disk | FTP | other *** search
- OPTIMUM PALETTES
- ================
-
-
-
- This is a commandline utility which reads in 32bpp sprites, finds a more or less
- optimal palette (1/2/4/8 bpp) and writes a dithered sprite with that palette as
- output file. To find the (near) optimal palette an iterative error-gradient method
- is employed -- there are probably better ways but the output thus created is very
- good so there's little motivation to change this, even though it's rather slow.
-
- Usage:
- ------
-
- op [-b# -i# -m# -v# -p<file> -f -g -G -c -C] <infile> <outfile>
-
- where # are numbers (there may or may not be spaces between the switches and their
- numbers). The switches and their meaning are:
-
- -b# BPP of the output sprite. Legal values are 1,2,4 and 8.
- -i# Maximum number of iterations, default 32.
- -m# Match palettes with recursion depth # (see below)
- -v# Verbose mode (0-3), determines how much output text should be written.
- 0: none; 1: only main stages; 2: each iteration (default);
- 3: palette matching stages.
- -p<f> Write palette to file <f>. This output file will be a standard palette
- file that should be usable on any machine. 256 colour palette file are only
- usable on RiscPCs. For older machines use the program "setpal" also included
- in this distribution.
- -f Use hardware floating point instructions. This is recommended if your
- machine has hardware FP. Otherwise you're better off not using this
- switch which will make op use its own floating point code.
- -g Make the output a greyscale image.
- -G Make lightest and darkest greyscales (black/white) fixpoints, i.e. these
- colours will remain unchanged during the iteration.
- -c Like -G but additionally make the purest spectral colours fixpoints. For
- instance for red this is the colour where red/(green+blue) is maximal. Sadly
- this usually results in very dark colours which is pretty useless...
- -C Like -G but additionally make brightest spectral colours fixpoints. This
- means the largest quantity of each of the three spectral colours used in the
- source sprite. This is usually a lot better than -c.
-
-
- First up op will sort the source sprite to get the number of individual colours.
- This is usually pretty quick (a couple of seconds) but may in extreme cases take
- up several minutes :-(.
-
- op will iterate until the palette doesn't change anymore or the maximum number of
- iterations has been reached. The number output each iteration is the sum of the
- weighted, squared errors which is usally very large (around 1e10); it won't go
- anywhere near zero unless you have fewer individual colours than palette entries
- in which case there will be no iteration in the first place. Typically the error
- will go down to 1/100th to 1/1000th its original value. The currently best
- palette has a `*' in front of the error.
- Don't be discouraged when the computation starts diverging after a couple of
- iterations, that's perfectly normal. Convergence is pretty rare with sprites
- with >= 4bpp. This is also the reason why I'm talking of "more or less" optimal
- palettes since a gradient method can only find local minima - all you can do is
- hope it's a global one as well... (and usually it's pretty damn close).
- The time taken for each iteration is mostly dependent upon the number of individual
- colours, not the sprite's size as such. This may take quite long - after all in
- the worst case each colour has to be verified with each palette entry to determine
- the best match. op uses a pretty smart system to be able to terminate the lookup as
- soon as possible but especially towards the beginning this will not always be
- possible.
- So in conclusion: it takes a lot of time, but the output is really good.
-
-
- Dithering:
- ----------
-
- Hmm... not much to say here. I use a dithering method that propagates two error
- values. The reason the dithering takes longer than ChangeFSI's is that you're
- comparing ChangeFSI dithering to the default palette which it knows quite a bit
- about to op dithering to an utterly arbitrary palette which will naturally take
- up more time. To verify this set the current palette using the -p file and tell
- ChangeFSI to output to current mode - you'll be amazed how much longer it'll take...
-
-
- Fixpoints:
- ----------
-
- There's one problem here: the most extreme colours (be it brightness or colour
- saturation) will be "drawn" towards the middle by the iteration, i.e. the image
- will be mellowed-out a little (this effect is hardly noticable with 8bpp but
- the stronger the fewer bpp). A typical effect is white becoming somewhat yellow.
- To remedy that you can declare some colours fixpoints. The -G switch will make
- the lightest and darkest greyscale fixpoints (usually white and black), -c and
- -C try the same for the three spectral colours. If you're using one of the later
- I'd go for -C since -c usually results in very dark colours.
- The effect of declaring fixpoints is preserving small areas of extreme colours
- - say a small spot of bright red - at the cost of a higher error. Neither switch
- has much effect in 256 colour modes. With 16 colours all of them can make a
- difference but using -c/-C fixes 5 colours out of 16 which will make the
- approximation pretty bad so I'd only use -G in that case. In 1 or 2 bpp modes
- only -G is possible in the first place and even that is not a good idea, if you
- ask me...
-
-
- Palette Matching:
- -----------------
-
- If you only want to find the (more or less) best palette you needn't worry about
- this. Palette Matching is a purely cosmetic aspect re. viewing the output sprites
- with the current palette forced to their palettes. This attempts to permute the
- palette found in such a way that it best fits the default palette for that mode.
- And since permutation means exponential complexity we're in trouble.
- The palette matching used by op is a recursive procedure with a maximum recursion
- depth of (n - 1) where n = number of colours in palette. Explaining how it works is
- pretty complicated, all you need to know is that the smaller the value you pass
- to -m the faster the matching will be done and the worse the match will be. If
- you intend to view the sprites in the desktop with the current palette forced to
- theirs I recommend at least -m1 although this will take some time in 256 colour
- modes. In 16 or less colour modes you can usually go for the full depth without
- ludicrous delays but -m1 is definitely the maximum I'd use for 256 colour sprites.
- The lowest value possible at all is -m0 which actually does more harm than good in
- 256 colour modes.
-
- The output you get in this stage if you specified -v3 is closely linked to the
- way the algorithm works. Basically each line means one colour matched. It's all
- a bit complicated...
-
-
-
- The setpal utility:
- -------------------
-
- This sets the current palette to the one output into a file by op. Use:
-
- setpal <palname>
-
- where <palname> is the name of the palette file. Since setpal registers as a WIMP
- task to be able to force a redraw you can't start it from a task window. You can't
- run it from single tasking either since the WIMP isn't active then. So you either
- have to write the command in an obey file or call it via the TaskManager (-> NewTask).
-
- Make sure that the current mode has the same number of colours as specified in the
- palette file. For 256 colour palettes: use this only if your hardware allows free
- programming of all 256 palette entries (RiscPC, older machines with graphic cards).
-
- The easiest way to view the output sprites with their palette is to get the latest
- version of !Deep4All (0.12) which can do this without any hassle and doesn't even
- need the palette file.
-
-
-
- What, no WIMP frontend?
- -----------------------
-
- No.
-
- Anyone can write one if (s)he so pleases. I didn't make it a WIMP program for a couple
- of reasons:
-
- 1) I have more important things to do
- 2) I like running stuff in task windows that don't lock up the computer
- 3) As an owner of an old A5000 it's imperative to me that something like this runs
- with !Virtual.
-
-
-
-
-
- LEGAL ISSUES and CONTACT:
- =========================
-
- This program is Videoware. For what this means and how to contact me read the file
- VIDEOWARE.
-
-
- Hopefully this proves useful to some people,
-
-
-
-
- Andreas Dehmel, March 97
-