Xref: utzoo comp.graphics:3941 comp.windows.x:6851 Path: utzoo!attcan!uunet!husc6!rutgers!ucsd!orion.cf.uci.edu!paris.ics.uci.edu!venera.isi.edu!raveling From: raveling@vaxb.isi.edu (Paul Raveling) Newsgroups: comp.graphics,comp.windows.x Subject: Re: Luminance from RGB Message-ID: <7086@venera.isi.edu> Date: 19 Dec 88 17:56:07 GMT References: <8241@pasteur.Berkeley.EDU> <518@midgard.Midgard.MN.ORG> <16929@onfcanim.UUCP> Sender: news@venera.isi.edu Reply-To: raveling@vaxb.isi.edu (Paul Raveling) Organization: USC-Information Sciences Institute Lines: 43 In article <16929@onfcanim.UUCP> dave@onfcanim.UUCP (Dave Martindale) writes: >In article <518@midgard.Midgard.MN.ORG> dal@midgard.Midgard.MN.ORG (Dale Schumacher) writes: >> >>The point of my "round-about" method is performance. It's much easier to >>replicate bits and do shifts than to divide by 7. > >But it's faster to *implement* almost any function using table lookup. This is true for relatively complex functions, but not usually for those that break down easily to simple operations such as shifts and adds. I've measured speed improvements up to a factor of 14 over ordinary C code in the most extreme case by moving a critical algorithm to assembly language and using this sort of shifty logic. Both techniques are valuable. For example, real time software such as that used in Central Air Data Computers uses shift/subtract logic wherever possible for functions such as the simplest digital filters [something like filtered_value = (7*old_value+new_value)/8]; it uses table lookup with linear interpolation between entries for other functions. The other functions need not be very complex to make the table lookup useful -- sqrt, for example. Where table lookup REALLY shines is evaluating relatively complex functions. Software such as the B-1B's CADC uses it profusely to keep adequate real time margins. >Once you are using table lookup to do the pixel-by-pixel "computations", >it really doesn't matter how expensive the code that initializes the table >is - you only do it once. So you might as well use multiply and divide, >and do the calculations in a way that someone else can read, and can see >by inspection is correct. Good commenting serves the latter purpose. It's just as easy to supply an actual equation as a comment as it is to use it as code. It's a matter of software engineering discipline to be sure the comments match the code -- we all do that, religiously, don't we? --------------------- Paul Raveling Raveling@vaxb.isi.edu