From: peterk@cbmger.de.so.commodore.com (Dr Peter Kittel Germany)
Newsgroups: comp.sys.amiga.advocacy,comp.sys.amiga.misc
Subject: Re: How does this HAM kludge work?
Date: 14 Dec 92 19:01:00 GMT
Reply-To: peterk@cbmger.de.so.commodore.com (Dr Peter Kittel Germany)
Followup-To: comp.sys.amiga.advocacy
Organization: Commodore Germany

In article <1992Dec12.172420.8553@usl.edu> das9674@usl.edu (Stephenson Daniel A) writes:
>Would someone please explain to me the trick behind this 'HAM' technique?

Ok. For every pixel, you store a certain amount of bits in your video RAM.
In HAM mode, two of these bits for every pixel are control bits. With these
two pixels, you can cover 4 cases: the first just indicates that this pixel
is a "normal" one, with the other bits of the pixel data giving the number
of one palette color. The other 3 cases indicate HAM pixels: here the value
of the rest of the bits does *not* give you a palette color number, but the
new value for one of the three color components Red, Green, or Blue.

When you now want to have a certain color in your picture, first you look
whether this color is already present in your current palette. Then it'sa
easy, set the control bits of that pixel to zero (indicating a palette
pixel) and the other bits to the color number. If the color differs, then
you have again two possibilities: Still use one of the base colors, because
it's suffuciently near to the wanted color; or recognize that the preceding
pixel already is very similar to the wanted color, you can modify one of
its 3 color components to make it fit even better or even exactly. Then
you set the control bits to the number indicating Red, Green, or Blue
modification and the rest of the bits to the value of this component.

This way, you can easily display images where you have rather smooth
color transitions, like in human faces. You can stay with practically
the same base color for great parts and only slightly modify some compo-
nents from pixel to pixel.

>Nothing grossly technical, please.  

I hope it wasn't too much :-).

>Also, how might this lead to the famous 'fringing'?

Well, if your wanted color is not found in the palette, and also the
preceding pixel has a very differing color, then you're lost. You *have*
to choose some color that's rather far away from the wanted one, but
you can fix this with every next pixel. In worst case, you need four
steps: One base color pixel plus three HAM pixels to adjust all the 
components. So you get 3 pixels in a row that don't quite match, and
this is visible as fringing. BUUUUUUT: If you are clever, you can
avoid this situation in the far majority of cases. It's a question of
evaluating a picture (I always talk about converting a 24-bit true-
color image into HAM) and optimizing your base palette. If done right,
e.g. considering colors occuring at edges within the picture etc.,
you can minimize those fringing cases drastically.

If you have the opportunity, get Fish disk 196. There are probably the
best HAM6 pictures that exist. Now with AA and HAM8, you will see even
more brilliant things: Here HAM can be considered as a very effective
way to compress 24-bit (ok, or 18-bit) pictures down to 8-bit pics,
with nearly no loss in visible quality, that's 67 % (or 55 %)!

-- 
Best regards, Dr. Peter Kittel  // E-Mail to \\  Only my personal opinions...
Commodore Frankfurt, Germany  \X/ {uunet|pyramid|rutgers}!cbmvax!cbmger!peterk
Wer's nicht kann, soll's bleiben klopfen oder Steine lassen!