# Comparison between rgba mode and color index mode

Source: Internet
Author: User

From http://yuxiangjismtp.blog.sohu.com/96152801.html

In color index or rgba mode, each pixel is stored with a certain amount of color data. This quantity is determined by the bit plane in the frame cache. A bit is a single bit of data in a pixel. If it is the color of an 8-bit plane, each pixel has eight color bits, so it has two eight orientations, that is, 256 different color values or 256 colors can be set for each pixel.

The bit plane is usually divided into three parts: R, G, and B (that is, a 24-bit plane system allocates 8 bits to red, green, and blue respectively), but this is not always the case. You can use the glgetintegerv () function and parameters gl_red_bits, gl_green_bits, gl_blue_bits, gl_alpha_bits, and gl_index_bits.

Rgba Display Mode

In rgba mode, the hardware allocates a certain number of BITs to the R, G, B, And a components (the number of each component is not necessarily the same) as shown in 4-2. The values of R, G, and B are usually stored in integer type, rather than floating point numbers, and they are extended into the digits that can be conveniently stored and retrieved. For example, in an 8-bit R system, the components from 0 to 255 can be stored. In this way, 0, 1, 2 ,......, 255 corresponds to the R value 0/255 = 0.0, 1/255, 2/255,..., 255/255 = 1.0. Regardless of the number of planes, 0.0 is always the smallest brightness value, and 1.0 is always the maximum brightness value.

Figure 4-2: RGB values in the bit plane

Note: The Alpha value does not have a direct effect on the screen. It can be used to do many things, including color mixing and transparency, and it can give R, G, and B an effect. (See "hybrid" in Chapter 6th for more information about Alpha values)

The different colors that each pixel can display depend on the number of planes and the ability of hardware to interpret these planes. The number of different colors cannot exceed the N power of 2. Here, n is the number of bit faces. In this way, a 24-bit machine can display up to 16.77 million different colors.

Jitter

Some graphics hardware uses Jitter to increase the number of colors displayed. Jitter is a technique that uses a mixture of multiple colors to create another color effect. To illustrate how jitter works, imagine that your system has only one digit to represent R, G, and B, so that only eight colors can be displayed: black, white, red, blue, green, yellow, blue, and foreign red. To display the pink area, the hardware can use a board layout to alternately fill the area with red and white pixels. If your eyes are far away from the screen, they won't be able to tell each pixel, so that the area shows pink-red and white evenly. If you use a large amount of red, you will get a more red pink. If you use more white pixels, you will get a more white pink.

Using this technology, there is no pink pixel here. The only way to get the pink effect is to fill the area with multiple pixels-you cannot shake one pixel. If you specify a color that does not exist to fill the polygon, the hardware will fill the polygon with a mixture of similar colors to make it look like you want. (Remember, even so, if you read a pixel in the frame cache, you get the real red and white pixel values because there is no pink color. See Chapter 1 for information on Pixel reading)

Figure 4-3 illustrates some simple black-and-white pixel Jitter to obtain a gray gradient. From left to right, the above 4x4 pattern represents the jitter mode of 50%, 19%, and 69% respectively. In each mode, you can see that this mode is simple to repeat, but the black and white blocks are still too large relative to pixels. If you look at the other end of the room, you can see their mixed effect, it looks like three gradients of gray.

Figure 4-3: black and white jitters to gray

If RGB uses eight digits each, you can obtain high-quality images without jitter. However, it is not because your machine has 24 color planes that do not need to shake. For example, if you are running in dual-frame mode, the bit plane is divided into two 12 sets, so that RGB has only four digits. No jitter. The four-digit color of each component can only provide satisfactory results in many environments.

You can enable or disable the jitter function by passing gl_dither to glable or gldisable. Note that, unlike many other features, jitter is enabled by default.

Color index Display Mode
In color index mode, OpenGL uses a color table (or a search table), just like a palette to call out the various colors required by the scenario. The painter's color palette provides many small grids for color. Similarly, the computer's color table provides many indexes for mixing RGB values, as shown in 4-4.

Figure 4-4: Color Table

The painter selects a color from the palette and fills it in the grid of the corresponding area. The computer saves the color index value to the bit plane for each pixel. Then these bits correspond to the color table, and the screen will use the color table to find the corresponding RGB value for painting, 4-5.

Figure 4-5: Use a color table to draw an image

In the color index mode, the colors that exist at the same time are limited by the size of the color table and the number of planes. The size of the color table is determined by the space allocated by the hardware. The size of a color table is usually 2 to the power, usually from 256 (8 to the power of 2) to 4096 (12 to the power of 2). The index indicates the number of bit planes used. If the color table has 2 index values to the nth power and m available bits, the number of available bits is the nth power of 2 and the small one in the M power of 2.

In rgba mode, the color of each pixel is independent of its pixel. However, in the color index mode, pixels with the same index value share the same color table position. If the content in the color table changes, the pixels with the same index value change the color.

Select the rgba mode or the color index mode.
You need to decide which color mode to use based on the needs of available hardware and applications. For most systems, the rgba mode can represent more colors at the same time than the color index mode. Similarly, for most effects, such as shadow, illumination, texture ing, and atomization, The rgba mode provides richer functions than the color index mode.

In the following cases, you would rather use the color index mode:

• If you are importing an existing program, it mainly uses the color index mode. It may be easier not to change to the rgba mode.
• If you only have a few Bit Planes available, the rgba mode will make the shadow transition very rough. For example, you only have eight faces. In rgba mode, you can only divide the red area into three faces, the green area into three faces, and the blue area into two faces. You can only get 8 levels of red and green, or even 4 levels of blue. The changes between colors are very obvious.
• In this case, if you have a limited gradient requirement, you can use the color search table to load more gradient colors. For example, if you need a blue gradient, you can use the color index mode to store 256-Level Blue in the color search table, which is much better than the four-level blue value in rgba mode. Of course, in this example, your color table is used up, so there is no red or green gradient color or other mixed colors.

There are a lot of tricks for color-based patterns, such as graphic table animation and hierarchical painting. (See Chapter 1 for more information)

In short, Once possible, use the rgba mode. It works better in texture ing, illumination, gradient, atomization, anti-sample and mixing.

Switch between display modes
In the best case, you may not need to choose between the rgba mode and the color index mode. For example, you may want to use the color mode for color table animation, and then immediately switch to the rgba mode for texture ing as needed.

Alternatively, you may want to switch between a single frame and two frames. For example, you may have few Bit Planes, for example, eight bit planes. In single frame mode, you will have 256 colors, but when you use the double frame mode to eliminate the flickering animation, you will only have 16 colors. Maybe you want to draw a moving object without blinking, you have to sacrifice the number of colors in exchange for the Two-frame mode (maybe because the object is moving too fast, the observer does not notice this difference ). But when the object is still, you can draw it in single frame mode to get more colors.

Unfortunately, most window systems do not allow such easy switching. For example, in the X Window System, the color display mode is an attribute of X visual, and X visual is specified before the window is created. Once it is specified, it cannot be changed in the window lifecycle. When you create a two-frame window in rgba mode, you cannot change it any more.

One way to solve this problem is to create multiple windows with different display modes. Then you control the display and non-display of the window (for example, mapping and unmaping an X Window, or managing and unmanaging a motif or Athena control), and then draw an object in the appropriate position, the last window is displayed.

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.