Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!samsung!zaphod.mps.ohio-state.edu!wuarchive!decwrl!sgi!shinobu!odin!sgi.com!scotth From: scotth@corp.sgi.com (Scott Henry) Newsgroups: comp.sys.amiga Subject: Re: HAM registers (long), was: Re: MacII Graphics to Amiga Message-ID: Date: 18 Feb 90 22:29:24 GMT References: <2934@bingvaxu.cc.binghamton.edu> <26885@cup.portal.com> <17098@boulder.Colorado.EDU> Sender: news@odin.SGI.COM Reply-To: scotth@sgi.com (Scott Henry) Organization: Silicon Graphics Inc, Mountain View, CA Lines: 37 In-reply-to: rademach@boulder.Colorado.EDU's message of 17 Feb 90 21:38:17 GMT A while ago I was trying to convert 24bit RGB images to HAM (I never finished the project, I didn't have a good IFF-writing function). The key to making a good HAM image is that HAM images perform poorly on color changes. Therefore, what you want to do is make the color registers contain pixels with the biggest color shifts. The algorithm I came up with requires two passes on the image. I defined the "distance" between 2 adjacent pixels as: 0 if the second pixel differed in only one of RGB from the previous one, or the sum of the square of the difference of the smaller two different colors. Basically, I was trying to attach a number to the HAM error. First pass: I arbitrarily defined border (for the first pixel on each line) as black (r=0,g=0,b=0). I then computed the distance between all adjacent pixels, and stored them in an array, along with the RGB values of the pixel. I sorted the array to put the highest errors first. If there were more than 15 colors with error > 0 (remember that color 0 is taken as 0,0,0), then I was going to try several optimizations of the colors selected for the registers. The first one (the only one I tried) was to map out any colors that happened to be within +- 1 in any single R, G, or B from another register. Other optimizations required keeping a count of the pixels affected by the error, so as to minimize the number of error pixels. Second pass: scan through the image. If a pixel was equal to a color register, use it, else compute the HAM error -- if it was less than the best register, compute the HAM delta, else use the closest register. Hope this helps people make better HAM conversion programs -- most of the ones I've seen do a lousy job (one reason I started writing my own -- one of these days I'll go back and finish it). -- Scott Henry | These are my | Tardis Express -- when it Information Services, | Opinions only!| absolutely, positively Silicon Graphics, Inc | Whose else? | has to be there -- yesterday.