Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.csd.uwm.edu!cs.utexas.edu!uunet!cbmvax!mitchell From: mitchell@cbmvax.UUCP (Fred Mitchell - QA) Newsgroups: comp.graphics Subject: Re: How to map 24-bit RGB to best EGA/VGA palette? Keywords: RGB EGA VGA color Message-ID: <7743@cbmvax.UUCP> Date: 23 Aug 89 19:38:44 GMT References: <3129@cbnewsm.ATT.COM> Reply-To: mitchell@cbmvax.UUCP (Fred Mitchell - QA) Distribution: na Organization: Commodore Technology, West Chester, PA Lines: 41 In article <3129@cbnewsm.ATT.COM> schapira@cbnewsm.ATT.COM (alexander.d.schapira) writes: >Can anyone shed some *light* on algorithms for mapping 24-bit RGB >pixel data (such as found in some image files) into the "best" >EGA or VGA palette? One way that you can do it is this (since I am not totally familar with how the VGA palette works, you may have to adapt this): NOTE: in all of this, treat all your colors as a R-G-B 'vector'. Determine your target color range in terms of the 24-bit pallette- that is, come up with a color-equivalency table for your target colors (all of them) that matches the 24-bit colors as closely as possible. Next, take a random color sample of your 24-bit image. How large of a sample you'll have to experiment with, but start off with 10 * #target-colors. Next, set up a weighted color-range-substitution table that will basically map the 24-bit colors onto your target palette. Normally, this will simply be the nearest-color match in terms of the RGB representation of your source pixel and target color range. Then determine the relative frequency of the colors for each color range. Take the highest of these and use them for your color palette. Now, just go through each pixel and substitute the 'mapped' color in your table (or the nearest color) and use that as the color for your VGA pixel. Of course, if the size of your source and target images differ, you'll have to deal with that too. This is, I know, a very sketchy description of one possible solution. There may be better and/or faster approaches to this, but what I have described above has been used in a Ray-Tracing package that I am working on. If you need more help, just drop me E-MAIL or call me (voice) at 215-228-7490. -- |*******************************************| -Compliments of /// |* All thoughts and comments are soley *| Fred Mitchell \\\/// |* thoses of The Author and has nothing to *| \XX/ |* do with Commodore-Amiga. *| Software QA - Commodore-Amiga |*******************************************|