home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Der Mediaplex Sampler - Die 6 von Plex
/
6_v_plex.zip
/
6_v_plex
/
DISK2
/
MULTI_04
/
CONVRT.ZIP
/
CONVERT.DOC
< prev
next >
Wrap
Text File
|
1993-05-12
|
12KB
|
244 lines
Convert version 1.2
May 12, 1993
Copyright 1993 Stephen B. Coy
All Rights Reserved
Unmodified copies of Convert may be freely distributed via
BBSs, Internet and services such as CompuServe and BIX. You may
not include Convert as part of any commercial product, that
includes shareware, without explicit permission. I can be
contacted at the address below for more info and bug reports.
Stephen Coy
Vivid Software
15205 NE 13th Pl., #2904
Bellevue, WA 98007
(206)641-8615
CompuServe : 70413,136
Internet : coy@plato.ds.boeing.com
Convert is based on Convert.exe which is included with
the shareware ray tracer Vivid. (plug, plug!) I've decided to
move away from Vivid's own .img format and join the rest of the
world using Truevision's Targa format. Convert reads truecolor
Targa files (16, 24 and 32 bit) and Vivid's .img files and
converts them to 8-bit GIFs. When 32-bit Targa files are
converted the alpha data is ignored. Convert will read both
run-length encoded and unencoded Targas.
Convert.exe is a real-mode version which should run on
just about any system. Conv_386.exe is a 386 compiled version
which runs about twice as fast and uses a DOS extender so it
shouldn't run out of memory.
When running convert you have two main decisions to make: a)
how should the program pick the palette and b) should the program
do any dithering of the output. Picking the palette is not
always an easy problem. Standard VGA allows us to view only 256
of the available 262,144 colors. An "average" lores image will
have about 7000 colors which we need to represent with our
palette of 256. A higher resolution image my have tens of
thousands of colors to represent. The following algorithms are
currently implemented in convert.
Palette File -- A palette may be input via a .map file.
This uses the same format as .map files created/read by Fractint.
This option is useful for creating multiple gifs with the same
palette for animation.
Popularity -- The popularity algorithm chooses the palette
by picking the 256 colors which represent then greatest number of
pixels in the image. The remaining colors in the image are
mapped onto the palette using a minimum distance formula. The
popularity algorithm tends to work best on images with a lower
number of colors. One typical problem of the algorithm is that
small highlights may not be colored correctly. Highlights
generally only cover a few pixels so their color usually doesn't
have enough representation in the image to be chosen by the
popularity algorithm. To help alleviate this problem, Convert
forces the corners of the color cube (white, red, green, blue,
cyan, magenta, yellow, and black) to be selected as the first
eight palette entries. Since most highlights are white this
greatly helps reduce unwanted artifacts in the resulting image.
This is the default option for choosing the palette.
Median Cut -- The median cut algorithm tries to choose a
more well balanced set of colors to represent the image. The
general idea of the median cut is to choose a palette in which
each entry represents about the same number of pixels in the
image. This helps to correctly color highlights that a pure
popularity algorithm might miss. Convert also allows you to
limit the number of pixels represented by any one color. This,
in effect, increases the importance of the colors in highlights
and other small regions of the image. With this limit set to
one, every color in the image is given the same weight without
regard for the number of pixels it covers. This is the option
you will want to use 90% of the time.
Fixed Palette -- The fixed palette option uses a
predetermined palette instead of choosing one based on the
content of the image. This has the advantage of being much
faster. When choosing by popularity or median cut Convert must
first build a tree structure in memory containing every color in
the image and a count of the number of pixels represented by that
color. After choosing the palette the colors in the tree must
then be mapped onto the colors in the palette. This can slow
Convert down quite a bit. When using a fixed palette the image
colors are mapped directly onto the palette colors via simple
equations eliminating the need for the tree structure and the
costly remapping of the images colors to an arbitrary palette.
Also, the current version of Convert can only support a tree
containing about 57,000 colors. After this my clone runs out of
RAM. The fixed palettes supported by Convert are:
0 : A grey scale image using 256 grey scale tones. Due to
VGA limitations this will display as 64 shades on most PC
systems. Of the three fixed palettes supported by Convert this
is the only one I ever use.
1 : Divides the color cube into 8 shades of red, 8 shades of
green, and 4 shades of blue. Generally produces fairly bad
images but kept in for nostalgia. Blue was chosen to get the
lower resolution because in general the human eye is much less
sensitive in the blue range and has a harder time focusing on
edges therefore the loss of color resolution is not missed as
much.
2 : Divides the color cube into 6 shades of red, 7 shades of
green, and 6 shades of blue. This option gives the best balance
of speed vs good color representation. I've found that it works
best with images that have a large number of colors. The
addition of dithering is usually helpful.
Dithering is the process of displaying pixels of differing
colors next to each other in such a way as to produce the
illusion of more colors. An every day example of this is your
television. Stick your nose up to the picture tube and notice
that the screen is made up of tiny red, green, and blue dots
which vary in intensity. These are the only colors your TV
actually produces but your eye combines them to produce the rest
of the spectrum. Well, at least the spectrum according to NTSC.
Floyd Steinberg dithering is the original error diffusion
dithering algorithm. Error diffusion dithering attempts to
compensate for a limited palette by insuring that the sum of the
errors in any region of the image is zero even though the colors
at each individual pixel may contain some error. At each pixel
as Convert scans through the image the nearest color for that
pixel is chosen. Generally this color will not be exact. The
difference between the chosen palette color and the true color is
then added to the neighboring pixels which have not been scanned
yet. Floyd Steinberg dithering has the advantage of having a
"random" look to it. Generally, it does not produce noticeable
patterns in the output image.
Ordered dithering works by adding a fixed amount to each
pixel based on its location. The sum of these additions over a
region of the image is equal to zero. Since ordered dither does
not take into account the values of neighboring pixels it
produces fixed patterns in the images which may be distracting in
some cases. Ordered dithering combined with a fixed palette has
an advantage if you are producing single fames for an animation.
During an animation the background (non-moving) regions of the
image will stay constant whereas if you use Floyd Steinberg
dithering the patterns constantly shift around and below any
moving objects on the screen.
The random noise option allows you to add white noise to an
image. In some cases this may help as much as dithering. It can
also be used in conjunction with either of the dithering options.
Interesting effects may be obtained by increasing the range of
the noise. Images converted with a large amount of noise tend to
take on a distinctly grainy look. Interesting, but not overly
useful. The default range for the noise is +-4 on a 0..255
range. This value was chosen strictly because it seemed to look
good in most cases. Random noise has the advantage of being
constant from image to image. This means that smooth areas in a
series of images will not shimmer during animation.
Ok, fine, now how do I run Convert? Well, it goes like this:
C> convert [-m #] [-f #] [-p palfile] [-d] [-o] [-r [#]] file
If the file name has no extension then Convert will first try
and open file.tga and then file.img. If the filename already
has an extension then it is used "as-is."
[-m #] chooses median cut and limits each color to represent
at most # pixels. # defaults to 64K and is optional.
[-f #] chooses fixed palette #. # defaults to 0, grey
scale.
[-p palfile] reads the palette out of the file palfile.map.
If this file does not exist the palette will be chosen by
median cut, popularity, or fixed depending on what other
flags are set. After the palette is chosen it will then be
written to the file palfile.map.
[-d] chooses Floyd Steinberg dithering.
[-o] chooses ordered dithering.
[-r #] chooses random noise +- #. # defaults to 4.
For example:
C> convert -f 2 -d test
will convert test.img to test.gif using fixed palette 2 and
Floyd Steinberg dithering.
Assuming that test.map does not exist
C> convert -m -p test test1
C> convert -m -p test test2
C> convert -m -p test test3
C> convert -m -p test test4
will convert test1 using median cut to choose the palette. The
palette will then be saved to test.map. Test2, test3, and test4
will then be converted using the palette in test.map.
In general the best results will be obtained by using the -m
-d flags as in Convert -m -d test. For images that tend to be
fairly monochromatic I've found that -m -d -r works well.
Adding the small amount of random noise helps break up some of
the banding. On the down side it also adds to the .gif file size
since it is tough to compress random noise well. To get nice
looking grey scale images try -f 0 -r.
Questions, problems and suggestions can be addressed to
me at the address at the top of this file. I can also be
found on PCGnet, Internet and CompuServe.
Have fun,
Stephen
Trademarks:
BIX .......... Byte
GIF .......... CompuServe
Targa ........ Truevision
Vivid ........ Vivid Software
version 1.0
Original version
version 1.1
Fixed bug with RLE encoded Targa files having the red and blue
planes swapped.
version 1.2
Added support for reading 16-bit Targa files.
Added 5-bit prequantizing using te -5 flag on the command
line. This is most effective in images with large numbers
of colors.