Path: utzoo!attcan!uunet!portal!cup.portal.com!doug-merritt From: doug-merritt@cup.portal.com Newsgroups: comp.sys.amiga Subject: Re: RGB to HSV, and RGB to CMY Message-ID: <6447@cup.portal.com> Date: 12 Jun 88 16:31:35 GMT References: <4402@gryphon.CTS.COM> Organization: The Portal System (TM) Lines: 46 XPortal-User-Id: 1.1001.4407 dsears says: >any hints on converting RGB to CMY or CMYB [...] as applied to low-cost >color printers? C = 1 - R, etc. is too simple. The Neugebauer >equations ... [ are ] real hard to solve (system of three NONlinear equations) >Has anybody come up with a practical approach? One thing to keep in mind with all these color space transformations is that, for many purposes, you're never going to need more than 4096 colors on the Amiga. And usually *less* than that in the target color space (unless the transformation is one-to-one, which is unusual). For such applications, you can precompute the transformation for each of the 4096 input RGB values, so it doesn't matter if it's really slow. As for handling apparently-insoluble nonlinear equations, the most common trick for *applied* math is to emulate them by a patchwork of more tractable equations. Graph the nonlinear equation, then use a ruler to draw straight line segment approximations to it's graph. Use as many straight lines as necessary to get a good approximation. Now you can use the equation of each of these resulting linear approximations instead of the original, and they *can* be solved because they're so simple. This method is *easily* good enough to build the 4096 value lookup table, if you use it carefully. If you're working in a 24 bit color space, then the lookup table would be too big (2^24 = 16 million), but you can still use the "piecewise linear approximation" to do the transformations. In this case it may be necessary to have more of the linear equations than in the 4096 case, if you're very concerned with accuracy. If you actually use graph paper to find the approximations, it's very easy to see (and to minimize) the maximum error, since it's just the maximum distance between a point on the original nonlinear curve, and the corresponding approximation on the straight line. If that sounds confusing, grab some graph paper and try it on something simple like a parabola. It's obvious when you're looking at it. If you end up with a *lot* of linear equations, each with widely varying intervals over which they are valid (unusual except for precision applications), then you may want to use a hash table or a tree for looking up the appropriate equation. Doug -- Doug Merritt ucbvax!sun.com!cup.portal.com!doug-merritt or ucbvax!eris!doug (doug@eris.berkeley.edu) or ucbvax!unisoft!certes!doug