Image programming in actionscript3 games (serialization 4)

Source: Internet
Author: User
1.1 RGB mode, argb mode and its operations 1.1.1 RGB mode and their operations

RGB is short for the three primary colors (red, green, blue). In physics, all colors in nature can be divided into these three colors. The color varies depending on the color. In turn, any color can be synthesized by three colors: Red, green, and blue. The white color reflects any color light, so its red, green, and blue components are equal to 100%. The black color does not reflect any color light, and the composition of the three primary colors is equal to 0%. Red only reflects the red light, so the red light is equal to 100%, and the other two colors are 0%.

Computer software is used to calling color light a "channel" and extending the concept to other color patterns. At the same time, the computer allocates an 8-bit storage space for each color channel. The value range of each channel is 0 ~ 255 (0 represents 0%, 255 represents 100% ). The three channels, red, green, and blue, are mixed into one color, occupying 24-bit space in the memory, that is, three bytes.

To explain the relationship between the color value and the channel, binary operations are always inevitable. This is a headache for friends who study fine arts but do not have the foundation of computer programming. We need to analyze it in depth, i'm afraid I have to open a chapter to discuss it. Therefore, if you may find it difficult to read the following content, you are advised to find a book introducing basic computer knowledge for simultaneous reading.

In flash CS6, when the FLA document is enabled, click "window"-"color" (Alt + Shift + F9) in the menu item ), the Color panel of 1.1 is displayed.

After the "solid color" option is selected in the drop-down box at the top of the Panel, a color palette is displayed below. You can drag the circle on the left and select the color directly from the slider in the middle, you can also modify the text box on the right or bottom to directly set the color value.

This section focuses on the RGB/argb mode. R, G, B, And a in the lower right represent the four channels: red, green, blue, and opacity. Here we temporarily ignore part.
The lower-left value does not seem to have any relationship with the value on the right for friends who have never touched the color calculation. In fact, this relationship is big. The six characters in the lower-left values correspond to one channel on the right. In Figure 1.1, C4 represents the R (red) value, and 196, 85 represents the G (green) value, 133, ee represents the value of B (blue), 238.
 


Figure 1.1 flash CS6 coloring Tool

We can write a small piece of code to test it:

1 trace(parseInt("C4",16));2 trace(parseInt("85",16));3 trace(parseInt("EE",16));4 trace(Number(196).toString(16));5 trace(Number(133).toString(16));6 trace(Number(238).toString(16));


Test results:
196,133,238, C4, 85, ee

Obviously, the color value on the left side is a hexadecimal number. After the two characters are obtained and converted into a decimal value, the color value is equal to the RGB value on the right. So what is c485ee? Is it a simple concatenated string? Or is it a truly hexadecimal number?

Next let's take a look at 0 ~ Integers between 15, their binary, hexadecimal, and hexadecimal are written as follows:

 

Decimal

0

1

2

3

4

5

6

7

Binary

0

1

10

11

100

101

110

111

Hexadecimal

0

1

2

3

4

5

6

7

Decimal

8

9

10

11

12

13

14

15

Binary

1000

1001

1010

1011

1100

1101

1110

1111

Hexadecimal

8

9

A

B

C

D

E

F


It is not hard to see that the first digit (character) displayed in hexadecimal represents exactly four digits in hexadecimal notation, so the EE representing blue occupies eight digits, green 85 and C4, which represent red, also occupy eight places, of which 85 is shifted to eight places, while C4 is shifted to 16 places, therefore, the hexadecimal number 0xc485ee can be obtained by the R, G, and B values through the binary bitwise operation:

 

1 0xC485EE = 0xC4 << 16 | 0x85 << 8 | 0xEE

 

The color value of as3 is generally expressed in hexadecimal numbers such as 0xc485ee. Therefore, the formula for calculating the color value is as follows:

 

1 color = red << 16 | green << 8 | blue。

 

Otherwise, if you want to obtain the components of each channel from the color value:

 

1 0xEE = 0xC485EE & 0xFF2 0x85 = 0xC485 & 0xFF = (0xC485EE >> 8) & 0xFF3 0xC4 = 0xC485EE >> 16 & 0xFF

 

Therefore

1 blue = color & 0xFF2 green = (color >> 8) & 0xFF3 red = (color >> 16) & 0xFF


If you think that I am not clear enough, you can read the introduction of color in Chapter 3.0: Rendering Technology in the article "Corner 4th animation tutorial, keith Peter explained the RGB color operation in more detail than I did.

In RGB mode, a color is determined by the composition of the three primary colors. The value of each channel represents the ratio of the color light to be reflected. If R = 127 (0x7f), it indicates that the color reflects the red light of 50%. Therefore, 0x7f0000 is a red color with medium brightness.
As for the reflection of a variety of light at the same time, it will get the magic like the color, it is the problem that the physicist has studied. For an optical idiot like me, there are nine tricks on this issue. For example, why does the total reflection of red light and green light (0xffff00) get yellow? I cannot give a reasonable explanation from a scientific point of view.

Artists often don't need to pay attention to this. They just need to open the palette and can extract their favorite colors as they like. (Of course, their things are not as simple as we think, and they have less aesthetic cells, I think it is impossible for you to bring up a satisfactory color when you order it for a long time ).

Programmers like me who do not have an artistic skills and have knowledge of physics and half a bucket of water usually have difficulty in identifying numbers in RGB mode (except for some very characteristic values such as 0x000000/0 xffffff) which of the following colors (such as brown, purple, and orange) in our sensory perception ). Because this model is too academic and not intuitive enough, a more emotional color model such as HSB came into being. I will mention it in section 1.2. However, no matter what mode you use, in as3, you must convert it to RGB mode to apply it to the Display object.

The following describes the argb mode.

Contact Us

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.