Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!bloom-beacon!apple!oliveb!sun!falk From: falk@sun.Eng.Sun.COM (Ed Falk) Newsgroups: comp.graphics Subject: Computer Graphics Academy Awards. Message-ID: <96848@sun.Eng.Sun.COM> Date: 31 Mar 89 03:42:03 GMT References: <28994@sri-unix.SRI.COM> Organization: Sun Microsystems, Inc. - Mtn View, CA Lines: 84 Announcing, the first annual comp.graphics awards for most frequently asked questions. Nomination #1: > Does someone have some good ideas and/or snippets of C code > for doing RGB -> CYMK conversion? TIA. ...doug beck > dbeck@unix.sri.com One of my personal favorites. Most questions reveal intelligence of the answerer in that smart people can answer the question and not-so-smart people can't. This question is unique in that the smart people are the ones who tell you they *can't* answer it. A common solution is to tell you that CMY = [ 1 1 1 ] - [ r g b ] with some correction applied to obtain black. However, the transfer function is nowhere near linear and varies with everything from how you adjusted your monitor when you looked at the original to how the room is lit to the phase of the moon. There are people who make their livings coming up with good values for C,M,Y,K. To do it properly, what you need to do is sit down with a book of sample colors with their CMYK components listed. Look through the book and choose the color you want. With luck, you can come up with a graphics program that can display reasonable approximation to what you want under certain circumstances, but there's no one way to do the transformation. Also, CMY = [ 1 1 1 ] - [ RGB ] doesn't even come close. At the very least you need to do gamma correction. Our next nominee is: > Hello all, > > I am looking for a fast algorithm to find all the points inside an > arbitrary polygon. Does anyone have any code (in any reasonable > language) to do this reliably and quickly? I hope you're not talking about real numbers here. There are an infinite number of points inside a polygon. Are you talking about how to scan-convert a polygon in integer coordinates or are you talking about how to test a point to see if it's inside or outside? If you want to scan-convert a polygon, check out Fundamentals of Interactive Computer Graphics by Foley and VanDam (sp?). They give a nice algorithm there. Also, Foley & VanD. give a couple of nice algorithms for filling an arbitrary boundary given any one point inside the boundary (this is called "seed-fill"). If you want to test to see if a point is inside a polygon, a simple way to to project a half-line out of the point and count how many edges it intersects. If the answer is odd, you're inside the polygon. Be careful with round-off error if you're not working with integers and be careful to look for cases where the halfline intersects a vertex of the polygon. Alternatively, you can sum up the angles from your point to all the vertices and see if it comes to 0 or 360. Details left to the reader because I'm late for an appointment. Next, we have: > Could anyone give me some help on this? Do you take the normalized > vector for a particular color and this is your percentage > in the shade of grey? (r * 0.??? + g * 0.??? + b * 0.???) = grey. > I get the impression that the various percentages for r, g, and b > should be about .300, .450, and .250 respectively. It doesn't matter all that much, you can get by with v=(r+g+b)/3 and your eye won't care. The "official" values (NTSC) are v = .299r + .587g + .144b. I've also seen .3r + .59g + .11b quoted. I was surprised that "How do I convert 24-bit true color to 8-bit colormap?" wasn't asked this month. -- -ed falk, sun microsystems sun!falk, falk@sun.com card-carrying ACLU member.