edgincd2@mentor.cc.purdue.edu (Chris Edgington *Computer Science Major*) (11/16/90)
I have recently been trying to write some VGA groutines in Turbo Assembler to operate in mode 13h. Does anyone have any text or docs that explain the pallete information. I already know that the format of the pallete is one byte for each R G B for each of the 256 colors, so there should be 256 * 3 bytes of info, but I really don't know how to combine R G B to get a specific color. What my ultimate goal is to create a pallete which is a rainbow of 256 different colors. Thanks, Chris Edgington
bcw@rti.rti.org (Bruce Wright) (12/02/90)
In article <16716@mentor.cc.purdue.edu>, edgincd2@mentor.cc.purdue.edu (Chris Edgington *Computer Science Major*) writes: > I have recently been trying to write some VGA groutines in Turbo > Assembler to operate in mode 13h. Does anyone have any text or > docs that explain the pallete information. I already know that > the format of the pallete is one byte for each R G B for each of > the 256 colors, so there should be 256 * 3 bytes of info, but I > really don't know how to combine R G B to get a specific color. The RGB color model's only real advantage is that it represents what the computer hardware is actually generating. As you note, it isn't very intuitive for generating specific colors. You can get an approximation by considering that: Red + Blue = Magenta Blue + Green = Cyan Red + Green = Yellow and that other colors can be generated "between" these colors by using differing values for the components. But this is still difficult to think about because human color perception doesn't work that way. You might try to get hold of Charles Petzold's COLORSCR program that runs under Windows (he describes it in his book "Programming Windows"). It allows you to experiment with different RGB values to produce different colors; this might help somewhat. Many computer graphics systems use some other color model that is more intuitive for the user, but convert the info to RGB for the actual display. You might try looking up a book on computer graphics for more detail. Don't restrict yourself to books about PC graphics, since unfortunately an awful lot of PC books don't discuss the technical and mathematical foundations of graphics but just describe how to make things appear on the screen and don't bother to go into more complex issues. You may have to look in a good technical bookstore - shopping mall bookstores don't tend to carry the more technical books (though there are exceptions). One example of this sort of color model is the HSV model, which has an axis V from black (0) to white (1), a hue H which is an angle around the axis (red = 0), and a saturation S from 0 to 1 which is the distance from the axis. "Fundamentals of Computer Graphics" by Foley and Van Dam gives an algorithm for converting from HSV to RGB and back (as well as other color models and the analogous conversions). The HSV to RGB routine is given in pseudo-Pascal: procedure HSV_TO_RGB (var r, g, b : real; h, s, v : real); { Given: h in [0, 360] or undefined, s and v in [0,1] } { Desired: r, g, b, each in [0,1] } { (to be scaled as appropriate for the } { hardware -- bcw) } begin if s = 0 then { achromatic color: there is no hue } if h = undefined then begin { This is the achromatic case } r := v; g := v; b := v end else ERROR { error if s = 0 and h has a value } else { chromatic color: there is a hue } begin if h = 360 then h := 0; h := h / 60; { h is now in [0,6] } i := FLOOR (h); { largest integer <= h } f := h - i; { fractional part of h } p := v * (1 - s); q := v * (1 - (s * f)); t := v * (1 - (s * (1 - f))); case i of 0: (r, g, b) := (v, t, p); { triplet assignment } 1: (r, g, b) := (q, v, p); 2: (r, g, b) := (p, v, t); 3: (r, g, b) := (p, q, v); 4: (r, g, b) := (t, p, v); 5: (r, g, b) := (v, p, q); end { case } end { hue } end { HSV_TO_RGB } If you want more detail see a book like Foley and Van Dam's. It isn't much of a "how-to" book, but they do give a lot more of the basis of computer graphics than most of the "how-to" books, and makes a nice complement for getting the theory as opposed to the "how-to" books practice. Good luck. Bruce C. Wright