Path: utzoo!attcan!utgpu!watmath!iuvax!mailrus!wuarchive!udel!mmdf
From: webb@udel.edu (David Webb)
Newsgroups: comp.sys.amiga
Subject: (none)
Message-ID: <495@nigel.udel.EDU>
Date: 2 Oct 89 13:27:08 GMT
Lines: 69


------- Forwarded Message

Received: from louie.udel.edu by dewey.udel.edu id aa00302; 28 Sep 89 23:03 EDT
Received: from louie.udel.edu by louie.udel.edu id aa22695; 29 Sep 89 2:59 GMT
Received: by cbmvax.UUCP (5.57/UUCP-Project/Commodore 12/21/87))
	id AA09544; Thu, 28 Sep 89 17:53:21 EDT
Date: Thu, 28 Sep 89 17:53:21 EDT
From: Fred Mitchell - QA 
Message-Id: <8909282153.AA09544@cbmvax.UUCP>
To: mmdf@udel.edu
Subject: Re: RGB to HAM IFF
Newsgroups: comp.sys.amiga
In-Reply-To: <253@snow-white.udel.EDU>
Organization: Commodore Technology, West Chester, PA
Cc:   

In article <253@snow-white.udel.EDU> you write:
>
>   Has anyone worked out a method of converting RGBs to HAM. I have
>   three B/W images (8 bits/pixel), and I would like to covert them
>   to a HAM image. If somebody could show me the way I would not writing
>   the C-code and making it public...
>
>   Soofi

I will attempt to describe an algorithm that I developed for converting
RGB to ham. This method does not use any dithering, but should produce
excellant results.

0) Reduction of BitPlanes
	Drop the 4 least significant bit planes from each R, G, and B.
	So now you'll have 16 'grey' levels instead of 256 for each
	gun (by gun, I mean the color gun metaphor of the R, G, and B picts.)
 
1) Pallette selection of colors
	Take a random sample of the RGB picture. 1000 should be a nice number.
	Then pick the 16 most optimal colors. These are not nessacarily the
	'most used', for you should have an even spread across the spectrum
	of the picture. Construct an 3-D array 16x16x16 (color cube) and let
	each edge represent one of your 'gun' colors. Init it to zero, and
	for each RGB value in your sample, increment its place in that
	array. Then scan the array for the most used entries that
	are well distributed.

2) Ham conversion
	Now, for each line of HAM, do:
		a) Initialize the line to the best matched pallette color.
		b) remember the RGB value of current pixel
		c) increment to next pixel
		d) look at RGB from source picture, and decide nearest match:
			1) From pallete (1 of the 16 colors) ?
			2) By modifying Red from last pixel ?
			3) By modifying Green ?
			4) By modifying Blue ?
		e) color pixel accordinly
		f) go back to (b) until end-of-line is reached

3) Write out HAM to IFF file and you're done.

Let me know how it turns out!

	-Fred Mitchell
	-Mitchell	(mitchell@cbmvax.UUCP)		    /// 
							   ///  We're all just  
	 All comments and opinions are my own. Period. \\\///  isolated pockets 
	        STRONG.DREAMS.REIGN.HERE		\XX/  of Ignorance......

------- End of Forwarded Message