Internet Windows Android

Raster encoding. Binary coding of graphic information Paletted coding

Question 7. Color depth

color depth - is the number of bits used to encode one pixel.

If to encode one pixel we take 1 bit– then with its help we can get only 2 colors: black (0) and white (1), that is, a black and white image.

2 bits– 4 colors (00, 01, 10, 11)

8 bit– 2 8 colors = 256 flowers, etc.

Thus, the number of colors can be determined by the formula:

where, N- number of flowers

I - bit depth of color.

Conclusion: the more bits used to encode 1 pixel, the more colors and more realistic the image, but the file size also increases.

In this way, bitmap file size is the product of the width and height of the image in pixels and the color depth.

It does not matter at all what is shown in the photograph. If the three parameters are the same, then the uncompressed file size will be the same for any image.

Calculation example. Determine the size of a 24-bit graphic file with a resolution of 800 x 600.

Solution. From the condition the file has parameters

A = 800 pixels

H = 600 pixels

Color depth I= 24 bits(3 bytes)

then the file size formula is V = A + B + I

V = 800 x 600 x 24 = 11520000 bits = 1440000 bytes = 1406, 25 KB = 1.37 MB

Example 2 In the process of optimization, the number of colors was reduced from 65536 to 256. By how many times the file size has decreased.

From the formula N = 2 I it follows that the color depth I 1 = log 2 65536 = 16 bits, and after optimization I 2 = log 2 256 = 8 bits

At the same time, the size of the image in pixels has not changed. using the formula to calculate the file size we have: V 1 = a x b x 16 = 16 ab and

V 2 \u003d a x b x 8 \u003d 8 ab

We make up the proportion V 1: V 2 \u003d 16 ab: 8 ab

So: the size of the graphic file depends on the size of the image and the number of colors.

At the same time, a high-quality image with 24 or 32 bit encoding turns out to be quite large (megabytes).

This is very inconvenient for storing and transferring images (especially on the Internet). Therefore, graphic files are subject to optimization.

Color depth– the number of bits per pixel (bpp). The most popular resolution is 8 bpp (256 colors), 16 bpp (65536 colors)

Since the 80s technology for processing graphic information on a PC is developing. The form of representation on the display screen of a graphic image, consisting of individual dots (pixels), is called a raster.

The minimum object in a raster graphics editor is a point. Raster graphics editor is designed to create drawings, diagrams.

Monitor resolution (number of horizontal and vertical dots), as well as the number of possible colors for each dot, are determined by the type of monitor.

The common resolution is 800 x 600 = 480,000 dots.

1 pixel of a black and white screen is encoded by 1 bit of information (black dot or white dot). The number of different colors K and the number of bits for their encoding are related by the formula: K = 2b.

Modern monitors have the following color palettes: 16 colors, 256 colors; 65,536 colors (high color), 16,777,216 colors (true color).

In table. 1 shows the dependence of the information capacity of one pixel on the color palette of the monitor.

Table 1

Number of colors

monitor

Number of bits encoding one point

16 (2 16 = 65 536)

24 (2 24 =16 777 216)

Memory required to store a graphic image that occupies the entire screen (video memory), is equal to the product of the resolution and the number of bits encoding one point. A bitmap (binary image code) is stored in the video memory of a PC, it is read by the processor at least 50 times per second and displayed on the screen.

In table. 2 shows the amount of video memory for monitors with different resolutions and color palettes.

table 2

256 colors

65536 colors

167777216 colors

Entering and storing technical drawings and similar graphic images in a computer is carried out differently. Any drawing consists of segments, arcs, circles. The position of each segment in the drawing is given by the coordinates of two points that define its beginning and end. The circle is given by the coordinates of the center and the length of the radius. Arc - coordinates of the beginning and end, center and radius. For each line, its type is indicated: thin, dash-dotted, etc. This form of presentation of graphic information is called vector. The minimum unit processed by the vector graphics editor is an object (rectangle, circle, arc). Information about the drawings is processed by special programs. Storing information in vector form reduces the required amount of memory by several orders of magnitude compared to the raster form of information representation.

video memory is binary information about the image displayed on the screen. Almost all images created, processed or viewed using a computer can be divided into two large parts - raster and vector graphics.

Bitmaps are a single-layer grid of dots called pixels (pixel, from the English picture element). Pixel code contains information about its color.

For a black and white image (without halftones), a pixel can take only two values: white and black (shines - does not glow), and one bit of memory is enough to encode it: 1 - white, 0 - black.

A pixel on a color display can have different colors, so one bit per pixel is not enough. Two bits per pixel are required to encode a 4-color image because two bits can take on 4 different states. For example, this color coding option can be used: 00 - black, 10 - green, 01 - red, 11 - brown.

On RGB monitors, all the variety of colors is obtained by combining the basic colors - red (Red), green (Green), blue (Blue), from which 8 basic combinations can be obtained:

color

Brown

Of course, if you have the ability to control the intensity (brightness) of the glow of the basic colors, then the number of different options for their combinations, generating various shades, increases. The number of different colors - K and the number of bits for their encoding - N are interconnected by a simple formula: 2 N = K.

As opposed to raster graphics vector image layered. Each element of a vector image - a line, a rectangle, a circle or a fragment of text - is located in its own layer, the pixels of which are set independently of other layers. Each element of a vector image is an object that is described using a special language (mathematical equations of lines, arcs, circles, etc.). Complex objects (broken lines, various geometric shapes) are represented as a set of elementary graphic objects.

Tasks

Control questions

1. How many bits are needed to encode 1 character?

2. The average student reading speed is 160 characters per minute. How much information will he process in 7 hours of continuous reading of the text?

3. What is the essence of the raster form of representation of graphic information?

4. How many bits of information are needed to encode 1 dot of a black and white monitor screen?

5. What is the formula for determining the amount of display video memory?

6. What is the essence of the vector form of presentation of graphic information?

Task 1. Determine the size of a 24-bit graphic file with a resolution of 1024 x 600.

Task 2. In the process of optimization, the number of colors was reduced from 65536 to 2. By how many times the file size has decreased.

Task 3. The binary code of the picture is given. It is known that the drawing is monochrome and the matrix has a size of 8X8. Restore the drawing by code:

a) 00111100 01000010 00000010 01111110 10000010 10000010 10000110 01111011

b) 10111110 11000001 10000001 00111110 00000001 00000001 10000001 01111110

c) 00111111 01000010 01000010 01000010 00111110 00100010 01000010 11000111

Task4 . The image on the display screen is built from individual dots (pixels). Let the screen resolution be set to 1200x1024. How many bytes will the screen image take in computer memory if it is saved (dot by point, in the format bit map - * bmp) as:

a) monochrome image;

b) 256-color drawing;

c) 24-bit drawing.

Task 5. To encode the color hue of one point (pixel) of a color image in accordance with the RGB color formation model, 1 byte (8 bits) is used: 3 bits for encoding the brightness level of red (Red) color, 2 bits for encoding the brightness level of green (Green) color and 3 bit on blue (Blue) color. Define:

a) how many brightness levels of each color can be encoded in this way;

b) how many color shades of the image can be transferred.

Solve the same problem, but using the True Color mode, when 3 bytes are used to transmit the color of one pixel - one for each color.

Test

1. The curriculum occupies 19 KB of PC memory. The program instruction occupies 1 display frame (25 lines of 80 characters). What part of the program is the instruction?

a) 2000 bytes;

c) 1/10 part;

2. The computer screen can operate in various modes, which differ in resolution and the number of possible colors for each dot.

Fill the table:

3. What is the minimum object used in a raster graphics editor?

a) Screen point (pixel);

b) object (rectangle, circle, etc.);

c) color palette;

d) familiarity (symbol).

4. What is a vector graphics editor for?

a) To create drawings;

b) for plotting graphs:

c) to build diagrams;

d) to create and edit drawings.

6. How much information does the binary encoding of 1 dot on a black and white screen (without gradation of brightness) require?

d) 16 bytes.

7. A raster graphic file contains a black-and-white image with 16 shades of gray, 10x10 pixels in size. What is the information volume of this file?

b) 400 bytes;

d) 100 bytes.

Correct answers for test 2.2: 1-d, 3-a, 4-a, 5-b, 6-a, 7-c.

A code is a set of conventions (or signals) for recording (or transmitting) some predefined concepts.

Encoding information is the process of forming a certain representation of information. In a narrower sense, the term "coding" is often understood as the transition from one form of information presentation to another, more convenient for storage, transmission or processing.

Usually each image when encoding (sometimes they say - encryption) is represented by a separate sign.

A sign is an element of a finite set of distinct elements.

In a narrower sense, the term "coding" is often understood as the transition from one form of information presentation to another, more convenient for storage, transmission or processing.

A computer can only process information presented in numerical form. All other information (such as sounds, images, instrument readings, etc.) must be converted into numerical form for processing on a computer. For example, to quantify musical sound, one can measure the intensity of sound at certain frequencies at short intervals, presenting the results of each measurement in numerical form. With the help of computer programs, you can perform transformations of the received information, for example, "overlay" sounds from different sources on top of each other.

Similarly, text information can be processed on a computer. When entered into a computer, each letter is encoded with a certain number, and when output to external devices (screen or print), for human perception, images of letters are built using these numbers. The correspondence between a set of letters and numbers is called a character encoding.

As a rule, all numbers in the computer are represented using zeros and ones (and not ten digits, as is customary for people). In other words, computers usually work in the binary system, since the devices for processing them are much simpler. Entering numbers into a computer and outputting them for human reading can be done in the usual decimal form, and all the necessary conversions are performed by programs running on a computer.

Ways to encode information.

The same information can be presented (encoded) in several forms. With the advent of computers, it became necessary to encode all types of information that both an individual and humanity as a whole deal with. But mankind began to solve the problem of encoding information long before the advent of computers. The grandiose achievements of mankind - writing and arithmetic - are nothing more than a system for coding speech and numerical information. Information never appears in its pure form, it is always presented in some way, encoded in some way.

Binary coding is one of the most common ways to represent information. In computers, robots and machine tools with numerical control, as a rule, all the information that the device deals with is encoded in the form of words of the binary alphabet.

Coding of character (text) information.

The main operation performed on individual characters of the text is character comparison.

When comparing characters, the most important aspects are the uniqueness of the code for each character and the length of this code, and the choice of encoding principle itself is practically irrelevant.

Various conversion tables are used to encode texts. It is important that the same table is used when encoding and decoding the same text.

Conversion table - a table containing a list of encoded characters ordered in some way, according to which the character is converted to its binary code and vice versa.

The most popular conversion tables: DKOI-8, ASCII, CP1251, Unicode.

Historically, 8 bits or 1 byte has been chosen as the code length for character encoding. Therefore, most often one character of text stored in a computer corresponds to one byte of memory.

There can be 28 = 256 different combinations of 0 and 1 with a code length of 8 bits, therefore, using one recoding table, no more than 256 characters can be encoded. With a code length of 2 bytes (16 bits), 65536 characters can be encoded.

Encoding of numerical information.

The similarity in encoding numerical and textual information is as follows: in order to be able to compare data of this type, different numbers (as well as different characters) must have a different code. The main difference between numerical data and symbolic data is that, in addition to the comparison operation, various mathematical operations are performed on numbers: addition, multiplication, root extraction, calculation of the logarithm, etc. The rules for performing these operations in mathematics are developed in detail for numbers represented in the positional number system.

The basic number system for representing numbers in a computer is the binary positional number system.

Encoding of text information

Currently, most users, using a computer, process textual information, which consists of characters: letters, numbers, punctuation marks, etc. Let's calculate how many characters and how many bits we need.

10 digits, 12 punctuation marks, 15 arithmetic symbols, letters of the Russian and Latin alphabet, TOTAL: 155 characters, which corresponds to 8 bits of information.

Units of measurement of information.

1 byte = 8 bits

1 KB = 1024 bytes

1 MB = 1024 KB

1 GB = 1024 MB

1 TB = 1024 GB

The essence of encoding is that each character is assigned a binary code from 00000000 to 11111111 or the corresponding decimal code from 0 to 255.

It must be remembered that at present five different code tables are used to encode Russian letters (KOI - 8, СР1251, СР866, Mac, ISO), and texts encoded using one table will not be displayed correctly in another

The main character encoding display is the ASCII code - American Standard Code for Information Interchange - the American standard code for information exchange, which is a 16 by 16 table, where characters are encoded in hexadecimal.

Coding of graphic information.

An important step in encoding a graphic image is its division into discrete elements (sampling).

The main ways of representing graphics for its storage and processing using a computer are raster and vector images.

A vector image is a graphical object consisting of elementary geometric shapes (most often segments and arcs). The position of these elementary segments is determined by the coordinates of the points and the radius value. For each line, binary codes for the line type (solid, dotted, dash-dotted), thickness, and color are indicated.

A raster image is a collection of dots (pixels) obtained as a result of image discretization in accordance with the matrix principle.

The matrix principle of encoding graphic images is that the image is divided into a given number of rows and columns. Then each element of the resulting grid is encoded according to the selected rule.

Pixel (picture element - picture element) - the minimum unit of the image, the color and brightness of which can be set independently of the rest of the image.

In accordance with the matrix principle, images are built that are output to the printer, displayed on the display screen, obtained using a scanner.

The image quality will be higher, the "dense" the pixels are, that is, the greater the resolution of the device, and the more accurately the color of each of them is encoded.

For a black and white image, the color code of each pixel is given by one bit.

If the picture is colored, then for each point the binary code of its color is set.

Since colors are also encoded in binary code, if, for example, you want to use a 16-color drawing, then you will need 4 bits (16=24) to encode each pixel, and if it is possible to use 16 bits (2 bytes) to encode a color one pixel, then you can then transmit 216 = 65536 different colors. Using three bytes (24 bits) to encode the color of one point allows you to reflect 16777216 (or about 17 million) different shades of color - the so-called "true color" mode (True Color). Note that these are currently used, but far from the limiting capabilities of modern computers.

Audio encoding.

From the course of physics, you know that sound is air vibrations. By its nature, sound is a continuous signal. If we convert sound into an electrical signal (for example, using a microphone), we will see a voltage that changes smoothly over time.

For computer processing, an analog signal must somehow be converted into a sequence of binary numbers, and for this it must be sampled and digitized.

You can do the following: measure the signal amplitude at regular intervals and write the obtained numerical values ​​into the computer's memory.

Graphic information can be understood as a drawing, a drawing, a photograph, a picture in a book, images on a TV screen or in a cinema, etc. Let's consider the principles of encoding graphic information on the example of an image on a TV screen. This image consists of horizontal lines - lines, each of which, in turn, consists of the smallest elementary units of the image - points, which are commonly called pixels (picsel - PICture "S ELement - element of the picture). The entire array of elementary units of the image is called raster .

The degree of clarity of the image depends on the number of lines on the entire screen and the number of dots per line, which represent resolution screen, or just permission . The more lines and dots, the sharper and better the image.

If we look at the resolution figures of today's plasma and LCD TVs, we find that the most common resolutions are 640x480 (LCD TVs with a 4:3 aspect ratio); 852×480 (plasma panels with aspect ratio 16:9), 1024×768 (LCD and plasma both 4:3 and 16:9); 1366×768 (HD Ready); 1920×1080 (Full HD) pixels. There are, but rarely, some other resolution values, such as 800x600 or 1024x1024 pixels.

A resolution designation such as 640x480 means that 480 horizontal lines of 640 pixels each are used. Thus, the image on the screen is a sequence of 640·480=307200 pixels.

Images can be monochrome or color.

monochrome image consists of any two contrasting colors - black and white, green and white, brown and white, etc. For simplicity of discussion, we will assume that one of the colors is black and the second is white. Then each pixel of the image can be either black or white. By assigning the binary code “0” to black and the code “1” to white (or vice versa), we can encode the state of 1 pixel of a monochrome image in 1 bit. However, the resulting image will be overly contrasty.

It is generally accepted today, which gives fairly realistic monochrome images, to encode the state of 1 pixel using 1 byte, which allows you to transfer 256 different shades of gray from completely white to completely black. In this case, to transfer the entire raster of 640x480 pixels, 307200 bytes are required.

color image can be formed on the basis of various models. The most common color models:

· RGB is most often used in computer science;


· CMYK - the main color model in polygraphy;

· in television, the YUV color model is used for the PAL standard, the YDbDr model for SÉCAM, and the YIQ model for NTSC;

· The XYZ reference model is based on measurements of the characteristics of the human eye.

RGB model(from the words Red, Green, Blue - red, green, blue) most accurately fits the principles of displaying an image on a monitor screen - three numbers set the brightness of the glow of red, green and blue phosphor grains at a given point on the screen. Therefore, this model is most widely used in the field of computer graphics, focused on viewing images on a monitor screen.

The RGB model relies on the fact that the human eye perceives all colors as the sum of three primary colors - red , green and blue (fig.4.1). Since a color is formed by adding three colors together, this pattern is often referred to as additive(summing up).

For example, to set a white color, you must specify the maximum brightness values ​​for all three components, and to set a black one, completely extinguish all sources (for example, phosphor points) that set the color at the desired point in the image, specify zero brightness for them.

If each of the colors is encoded using 1 byte (the brightness of each component is given by numbers from 0 to 255), as is customary for a realistic monochrome image, it will be possible to transmit 256 shades of each of the primary colors. And in total, in this case, 256 256 256 = 16 777 216 different colors are transmitted, which is close enough to the real sensitivity of the human eye. Thus, with this color coding scheme, 1 pixel image requires 3 bytes or 24 bits of memory. This way of representing color graphics is called the mode true color (true color - true color) or full color mode .

There are professional devices (for example, scanners) that allow you to obtain images in which each pixel is described not by three, but by six (16 bits for each color component) or even eight bytes. Such modes are used for the best reproduction of shades and, most importantly, the brightness of image pixels. This allows the most reliable reproduction of images of such technically complex scenes as, for example, evening or dawn landscapes.

Rice. 4.1. RGB color model represented as a cube

Example 4.7. In Win32, the standard type for representing colors is COLORREF. To define a color in RGB, 4 bytes are used in the form:

BB, GG, RR - the value of the intensity of the blue, green and red components of the color, respectively. Their maximum value is 0xFF.

Then you can define a variable of type COLORREF as follows:

COLORREF C=(b,g,r);

b, g and r- intensity (in the range from 0 to 255) respectively of the blue, green and red components of the determined color C. That is, the bright red color can be defined as (255.0.0), bright purple - (255.0.255), black - (0,0,0) and white - (255,255,255).

Full color mode requires a lot of memory. Therefore, various modes and graphic formats are being developed for memory, which convey color slightly worse, but require much less memory. In particular, we can mention the High Color mode (high color - rich color), in which 16 bits are used to transmit the color of 1 pixel, and therefore 65,535 color shades can be transmitted, as well as the index mode, which is based on a pre-created for a given picture table of the color shades used in it. Then the desired pixel color is selected from this table using the index number, which takes only 1 byte of memory. When writing an image to computer memory, in addition to the color of individual dots, it is necessary to record a lot of additional information - the size of the picture, resolution, brightness of dots, etc. A specific method of encoding all the information required when writing an image to computer memory forms a graphic format. Graphic information encoding formats based on the transfer of the color of each individual pixel that makes up the image are classified as raster, or BMP (Bit Map - bitmap), formats.

CMYK model(Cyan, Magenta, Yellow, blacK) A subtractive color scheme used primarily in the printing industry for standard process printing. The CMYK scheme (Fig. 4.2) usually has a relatively small color gamut.

Rice. 4.2. Subtractive synthesis scheme in CMYK

In Russian, these colors are often called like this: cyan, magenta, yellow . The color in such a scheme depends not only on the spectral characteristics of dyes and on the method of their application, but also on their quantity, paper characteristics and other factors. For example, there are American, European and Japanese standards for coated and uncoated papers.

Although in theory black can be obtained by mixing magenta, cyan and yellow in equal proportions, in practice mixing actual magenta, cyan and yellow results in a more dirty brown or dirty gray color. Since the purity and saturation of black is extremely important in the printing process, another color was introduced into the model - black .

The explanation of the first three letters in the CMYK abbreviation is given above, and about the fourth one of the versions claims that K- short for English. black K (if we took B, then there would be confusion with the RGB model, where B is blue). According to this version, when printing films were printed, the color to which they belong was indicated with one letter. According to another version, the letter K appeared from the abbreviation of English. the words key : in English-speaking countries by the term key plate indicates the printing plate for black ink.

CMYK is called the subtractive model because this model is used mainly in printing for color printing, and paper and other printed materials serve as surfaces that reflect light: it is more convenient to calculate how much light (and color) is reflected from a particular surface, rather than how much absorbed. Thus, if we subtract three primary colors, RGB, from white, we get a triple of CMY complementary colors. "Subtractive" means "subtracted" - we subtract primary colors from white.

Each number that defines a color in CMYK represents the percentage of that color's ink that makes up the color combination. For example, to get dark orange, mix 30% cyan, 45 magenta, 80 yellow, and 5% black. This can be denoted as follows: (30,45,80,5). Sometimes they use this designation: C30M45Y80K5.

Control questions and tasks

1. What is the data format?

2. How is numerical information encoded in computers?

3. How is the range of representation of an integer related to the format of its storage.

4. Are there any differences in the display of positive numbers in direct, reverse and additional codes?

5. Express the number -78 in forward, reverse and two's complement codes in one-byte format.

6. How are the accuracy and range of representation of a real number related to the capacity of the mantissa?

7. Why is the order in the representation of a real number called shifted?

8. Why is the first digit of the mantissa not stored when representing a normalized real number?

9. Write the number 34.256 in single real number format.

10. How is text information encoded in computers?

11. What are code tables used for? What code tables do you know?

12. What is the difference between a basic ASCII table and an extended one?

13. What are the advantages of presenting textual information in Unicode format?

14. Define terms pixel, raster, resolution .

15. How many bytes of memory is needed to encode an image on a computer monitor screen with a resolution of 800×600 at 256 colors?

16. What color imaging models do you know?

17. What colors are considered primary in RGB and CMYK models?


5. Basic concepts of the algebra of logic

a) b)

Figure 6.3 - Raster drawing

a) raster; b) pattern modeling

A bitmap is a collection of square pixels. The size of the square is determined resolution. Resolution is the number of pixels per unit length of an image. Resolution is measured in pixels per inch. ppi – pixels per inch. For example, a resolution of 254 ppi means that there are 254 pixels per inch (25.4 mm), so each pixel has a size of 0.1 ∙ 0.1 mm. The higher the resolution, the more accurately (clearer) the pattern is modeled.

6.2 Color coding

Each pixel is encoded with a color. For example, for a black and white drawing, white is 1, black is 0. Then figure 6.3 can be encoded with a matrix of 4 9, the first three lines of which, filled in with codes, are shown below:

What if the drawing is in color? For example, a drawing of a flag that uses 4 colors - black, white, red, blue (Figure 6.4, a). Attached is a drawing in color.

blue
Red

Figure 6.4 - Coding of a color bitmap;

a) raster drawing; b) pattern encoding matrix

It takes 2 bits to encode one of the four color options, so the code for each color (and the code for each pixel) will consist of two bits. Let 00 be black, 01 be red, 10 be blue, and 11 be white. Then we get a table of codes (Figure 6.4, b).

6.2.1 Screen color coding

It is believed that any radiated color can be simulated using only three light beams (red, green and blue) of different brightness. Consequently, any color (including "white") is approximately decomposed into three components - red, green and blue. By changing the brightness of these components, you can make any color. This color model was named RGB after the initial letters of English words. red- Red, green- green and blue- blue (Figure 6.5, a). The drawing in color is given in the appendix.



In the RGB model, the brightness of each component is most often encoded as an integer from 0 to 255. In this case, the color code is a triple of numbers (R, G, B), the brightness of individual components. Color (0,0,0) is black and (255,255,255) is white. If all components are of equal brightness, shades of gray are obtained, from black to white. For example, (75,75,75) is dark gray and (175,175,175) is light gray.

To make a light red (pink) color, you need to increase the brightness of green and blue colors equally in red (255,0,0), for example, (255, 155, 155) is pink. This can be checked in the MSWord editor, tool - text color - other colors... - spectrum(Figure 6.5, b).

a) b)


Figure 6.5 - RGB color model;

a) RGB model; b) text color tool in MSWord

Some color codes are shown in Table 6.1 below.

Table 6.1 - Color codes

In total there are 256 brightness options for each of the three colors. This makes it possible to encode 256 3 = 16,777,216 shades (more than 16 million), which is more than enough for a human. Because
256 = 2 8 , each of the three components occupies 8 bits or one byte in memory, and all information about some color is 24 bits (or three bytes). This value is called color depth.



Color depth is the number of bits used to encode the color of a pixel.

Each pixel is allocated from 1 bit to 3 bytes of video memory ( the image is formed in the video memory). For instance:

Monochrome mode, 2 colors (black and white) - 1 bit (Figure 6.3, b).

Color mode, 8 colors - 3 bit. red=0; 1. Green=0; 1. Blue=0; 1. RGB= 2 3 = 8.

Color mode, 16 colors - 4 bits; i = 0; 1 - intensity (bright, dim); i RGB = 2∙2 3 = 2 4 = 16 (table 6.2).

Color mode, 256 colors - 8 bit; i = 00000 ,…, 11111 = = 2 5 = 32 intensity gradations; i RGB = 2 5 * 2 3 = 2 8 = 256.

Or 2 intensity gradations and 2 RGB colors
i 2 R 2 G 2 B 2 \u003d 4 * 4 * 4 * 4 \u003d 2 8 \u003d 256 (table 6.3).

Color mode, 16 million colors - 3 bytes = 24 bits
(Figure 6.5, b).

Table 6.2 - Codes for the formation of 16 colors

Color i RGB
Black (black)
Blue (blue)
Green (green)
Cyan (blue-green)
Red (red)
Magenta (purple)
Brown (brown)
Light Gray (light gray)
Dark Gray (dark gray)
Light Blue (bright blue)
Light Green (bright green)
Light Cyan (turquoise)
Light Red (bright red)
Light Magenta (purple)
Yellow (yellow)
White (white)

Table 6.3 - Codes for the formation of 256 colors

i R G B
∙∙∙ ∙∙∙ ∙∙∙ ∙∙∙

24-bit color coding is often referred to as the mode true color(English) true color- true color). To calculate the size of the picture in bytes with this encoding, you need to determine the total number of pixels (multiply the width and height) and multiply the result by 3, since the color of each pixel is encoded in three bytes. For example, a 20x30 pixel image encoded in truecolor mode would take up 20x30x3 = 1800 bytes.

In addition to the true color mode, 16-bit coding is also used (eng. high color- “high” color), when five bits are assigned to the red and blue components, and six bits to the green, to which the human eye is more sensitive (total 16 bits). In High Color mode, 2 16 = 65536 different colors can be encoded. In mobile phones, 12-bit color coding (4 bits per component, 2 12 = 4096 colors).

The relationship between color depth and the number of colors generated can be shown in Table 6.4.

Table 6.4 - Color depth and number of colors

Generally, the fewer colors used, the more the color image will be distorted. Thus, when encoding color, there is also an inevitable loss of information that is "added" to the loss caused by sampling. Discretization occurs when the pattern is replaced by a set of square pixels. However, as the number of colors used increases, the file size grows at the same time. For example, in the mode true color the file will be twice as large as with
12 bit encoding.

Very often (for example, in diagrams, diagrams and drawings), the number of colors in the image is small (no more than 256). In this case apply palette coding.

Color palette is a table in which each color specified as components in the RGB model is assigned a numerical code.

Palette size is the number of bytes indicating the colors of the palette.

For example, a black and white palette, only 2 colors (Figure 6.3):

ü black: RGB code (0,0,0); binary code 0 2 ;

ü white: RGB code (255,255,255); binary code 1 2 .

Here the palette size is 6 bytes.

Flag image encoding, four colors (Figure 6.4):

ü black: RGB code (0,0,0); binary code 00 2 ;

ü red: RGB code (255,0,0); binary code 01 2 ;

ü blue: RGB code (0,0,255); binary code 10 2 ;

ü white: RGB code (255,255,255); binary code 11 2 .

Here the palette size is 12 bytes.

Below are data on some variants of encoding with a palette (Table 6.5).

Table 6.5 - Coding options with palette

Given the known characteristics of the monitor screen (screen resolution and number of pixel colors), you can calculate the minimum amount of video memory to form a high-quality image (Table 6.6).

Table 6.6 - The amount of video memory

6.2.2 Color coding on paper

RGB encoding best describes the color that is emitted by some device, such as a monitor or laptop screen. When we look at an image printed on paper, the situation is completely different. We see not the direct rays of the source entering the eye, but reflected from the surface. "White light" from some source (the sun, a light bulb), containing waves in the entire visible range, falls on the paper on which the paint is applied. The paint absorbs some of the rays (their energy is spent on heating the paper), and the remaining reflected colors fall into the eye, this is the color that we see.

For example, if the paint absorbs red rays, only blue and green ones are reflected - we see blue. In this sense, red and blue colors complement each other, just like the green-violet and blue-yellow pairs. Indeed, if you “subtract” green from white, you get purple, and if you “subtract” blue, you get yellow.

Note the color synonyms: violet = magenta.

The ratios of incident and reflected colors are shown below (Table 6.7).

Table 6.7 - Ratios of incident and reflected colors

Three additional colors - blue, violet and yellow - are used to build a color model. CMY(English) cyan- blue, Magenta- Violet, Yellow- yellow), which is used for printing (Figure 6.6, b). Thus, the RGB and CMY color models are reversible (Figure 6.7). The drawing in color is shown in the application.

Figure 6.6 - Color models;

a) RGB model (for monitor); b) CMY model (for printer)

Figure 6.7 - Reversible color models

The values ​​C=M=Y=0 indicate that on white paper
no paint is applied, so all the rays are reflected, it is white.

When applying blue, violet and yellow paints, theoretically, black should be obtained (Figure 6.6, b), all rays are absorbed. However, in practice, the colors are not perfect, so instead of black, a dirty brown is obtained. In addition, when printing black areas, you have to “pour” a triple portion of ink into one place. It should also be borne in mind that usually black text is often printed on printers, and color inks are much more expensive than black ones.

To solve this problem, black is added to the paint set, this is the so-called key color (English) Keycolor), so the resulting model is denoted CMYK.

In addition to the RGB and CMY (CMYK) color models, there are others. The most interesting of them is the model HSB(English Hue - tone, shade; Saturation - saturation, Brightness - brightness), which is closest to the natural perception of a person. Hue is, for example, blue, green, yellow. Saturation is the purity of a hue, reducing saturation to zero results in gray. Brightness determines how light or dark a color is. Any color turns black when brightness is reduced to zero.

6.3 Features of bitmap coding

With raster encoding, the picture is divided into pixels (discretized). For each pixel, a color is determined, which is most often encoded using an RGB code.

Raster encoding has dignity:

ü universal method (any image can be encoded);

ü the only method for encoding and processing blurry images that do not have clear boundaries, such as photographs;

and limitations:

ü there is always a loss of information during discretization;

ü when resizing the image, the color and shape of the objects in the picture are distorted, since when increasing the size, it is necessary to somehow restore the missing pixels, and when decreasing, replace several pixels with one;

ü the file size does not depend on the complexity of the image, but is determined only by the resolution and color depth; as a rule, raster drawings have a large volume.

There are many different formats for raster drawings. The most common filename extensions are:

.bmp(eng. bitmap - bitmap) - a standard format in the Windows operating system; supports paletted and truecolor encoding;

.jpg or .jpeg(eng. Joint Photographic Experts Group - a joint group of expert photographers) - a format designed specifically for encoding photographs; only supports true color mode; to reduce the file size, strong compression is used, in which the image is slightly distorted, so it is not recommended to use it for drawings with clear boundaries;

.gif(eng. Graphics Interchange Format - a format for exchanging images) - a format that supports only coding with a palette (from 2 to 256 colors); unlike previous formats, parts of the picture can be transparent; in the modern version, you can store animated images; lossless compression is used, that is, the image is not distorted during compression;

.png(English Portable Network Graphics - portable network images) - a format that supports both true color mode and paletted coding; parts of the image can be transparent and even semi-transparent (32-bit RGBA encoding, where the fourth byte specifies transparency); the image is compressed without distortion; animation is not supported.

6.4 A note about file encoding

Earlier it was said that all kinds of information are stored in the computer memory in the form of binary codes, that is, chains of zeros and ones. Having received such a chain, it is absolutely impossible to say that it is text, picture, sound or video. For example, the code 11001000 2 can represent the number 200, the letter "I", one of the color components of a pixel in true color mode, the color number in the palette for a picture with a palette of 256 colors, the color of 8 pixels of a black and white picture, etc. How computer understands binary data? First of all, you need to focus on the file name extension. For example, most often .txt files contain text, while files with .bmp, .gif, .jpg, .png extensions contain pictures.

However, the file extension can be changed as you like. For example, you can make a text file have a .bmp extension and a JPEG picture have a .txt extension. Therefore, at the beginning of all files of special formats (except for plain text, .txt), a header is written, by which you can "recognize" the type of file and its characteristics. For example, BMP files start with the characters "BM" and GIF files start with the characters "GIF". In addition, the title indicates the size of the picture and its characteristics, such as the number of colors in the palette, compression method, etc. Using this information, the program decodes (decrypts) the main part of the file and displays it on the screen.

6.5 Questions and tasks

1. What are the two principles of coding drawings used in computer technology?

2. Why is it not possible to come up with a single method for coding drawings that is suitable in all situations?

3. What is the idea of ​​raster coding?
What is a raster?

4. What is the idea behind vector coding? What is a graphic primitive?

5. What is a pixel? How did such a word come about?

6. What is pattern discretization? Why is it necessary?

7. What is lost when discretizing a picture?

8. What is the resolution (screen, printer)? In what units is it measured?

9. What is color depth? In what units is it
measured?

10. What is True Color mode?

11. What is High Color mode?

12. What is palette coding? What is its fundamental difference from the true color mode?

13. What are the advantages and disadvantages of raster coding?

14. What are the advantages and disadvantages of vector coding?

15. In what formats is it advisable to save photos?

16. In what formats is it advisable to save drawings, drawings with clear boundaries?

17. How will the code for the next picture be written? A black and white bitmap is encoded line by line, starting at the top left and ending at the bottom right. When encoded, 0 denotes black and 1 denotes white.

Solution. The image code entry will be as follows:

010100 011111 101010 011101 = 010100011111101010011101 2 =

24375235 8 = 51FAD 16 .


List of sources used

1. Andreeva E. V. Mathematical foundations of informatics: textbook. allowance / E. V. Andreeva, L. L. Bosova, I. N. Falina. – M. : BINOM. Knowledge Lab, 2007.

2. Pospelov D. A. Arithmetic bases of computers of discrete action / D. A. Pospelov. - M .: Energy, 1970.

3. Saveliev A. Ya. Arithmetic and logical foundations of digital automata / A. Ya. Saveliev. - M .: Higher school, 1980.

4. Pozdnyakov S. N. Discrete mathematics: textbook
/ S. N. Pozdnyakov, S. V. Rybin. - M. : Academy, 2008.

5. Hartley R. V. L. Information transfer / R. V. L. Hartley
// Information theory and its applications. - M. : Fizmatgiz, 1959.

6. Shannon K. Mathematical Theory of Communication. (Shannon C.E. A Mathematical Theory of Communication. Bell System Technical Journal. - 1948. - pp. 379-423, 623-656).

7. Yushkevich A. P. History of mathematics in the Middle Ages
/ A. P. Yushkevich. - M. : Fizmatgiz, 1961.


24-bit color(which is a subset true color English "true color") in computer graphics - a method of representing and storing an image that allows you to display a large number of colors, halftones and shades. A color is represented using 256 levels for each of the three components of the RGB model: red(R), green(G), and blue(B), resulting in 16,777,216 (224) different colors.

32-bit TrueColor can store an alpha channel, which sets the degree of pixel transparency for displaying translucent images, such as translucent windows, fade-out menus, and shadows. Some video adapters are capable of processing the alpha channel in hardware.

Number of bits when digitizing a signal

You should not confuse the number of bits when digitizing a signal (by a scanner or a digital camera) and the number of bits when storing and displaying it on the screen.

Color with 256 levels per channel is stored in a gamma-corrected form, while a linear signal is digitized from the camera pixels. It is usually stored in raw camera data in Raw format.

Write a review on the article "TrueColor"

Notes

An excerpt characterizing TrueColor

The countess was so tired of the visits that she did not order to receive anyone else, and the porter was only ordered to call everyone who would still come with congratulations to eat without fail. The Countess wanted to talk face to face with her childhood friend, Princess Anna Mikhailovna, whom she had not seen well since her arrival from Petersburg. Anna Mikhailovna, with her tearful and pleasant face, moved closer to the countess's chair.
"I'll be completely frank with you," said Anna Mikhailovna. “There aren’t many of us left, old friends!” That's why I treasure your friendship.
Anna Mikhailovna looked at Vera and stopped. The countess shook hands with her friend.
“Vera,” said the countess, turning to her eldest daughter, who was obviously unloved. How do you have no idea? Don't you feel like you're out of place here? Go to your sisters, or...
Beautiful Vera smiled contemptuously, apparently not feeling the slightest insult.
“If you had told me long ago, mother, I would have left at once,” she said, and went to her room.
But, passing by the sofa, she noticed that two couples were sitting symmetrically in it at two windows. She stopped and smiled contemptuously. Sonya was sitting close beside Nikolai, who was copying for her the poems he had composed for the first time. Boris and Natasha were sitting at the other window and fell silent when Vera entered. Sonya and Natasha looked at Vera with guilty and happy faces.
It was fun and touching to look at these girls in love, but the sight of them, obviously, did not arouse a pleasant feeling in Vera.
“How many times have I asked you,” she said, “not to take my things, you have your own room.
She took the inkwell from Nikolai.
“Now, now,” he said, wetting his pen.
“You know how to do everything at the wrong time,” Vera said. - Then they ran into the living room, so that everyone felt ashamed for you.
In spite of the fact, or precisely because what she said was perfectly true, no one answered her, and all four only looked at each other. She hesitated in the room with an inkwell in her hand.

Rasters, pixels, sampling, resolution

Like all kinds of information, images in a computer are encoded as binary sequences. Two fundamentally different coding methods are used, each of which has its own advantages and disadvantages.

Both a line and an area are made up of an infinite number of points. We need to encode the color of each of these points. If there are infinitely many of them, we immediately conclude that this requires an infinite amount of memory. Therefore, the image cannot be encoded in a “dot-by-point” way. However, this idea can still be used.

Let's start with a black and white drawing. Imagine that a grid is superimposed on the image of a rhombus, which divides it into squares. Such a grid is called a raster. Now for each square we define a color (black or white). For those squares in which a part turned out to be painted in black, and a part in white, we will choose a color depending on which part (black or white) is larger.

Picture 1.

We have a so-called raster drawing, consisting of pixel squares.

Definition 1

Pixel(eng. pixel = picture element, picture element) is the smallest picture element for which you can set your own color. Having divided the “ordinary” drawing into squares, we performed its discretization - we divided a single object into separate elements. Indeed, we had a single and indivisible drawing - the image of a rhombus. As a result, we got a discrete object - a set of pixels.

The binary code for a black and white picture obtained as a result of sampling can be constructed as follows:

  • we replace white pixels with zeros, and black pixels with ones;
  • write out the rows of the resulting table one by one.

Example 1

Let's show this with a simple example:

Figure 2.

The width of this picture is $8$ pixels, so each line of the table consists of $8$ bits. In order not to write a very long chain of zeros and ones, it is convenient to use the hexadecimal number system, encoding $4$ neighboring bits (tetrad) with one hexadecimal digit.

Figure 3

For example, for the first line we get the code $1A_(16)$:

and for the whole drawing: $1A2642FF425A5A7E_(16)$.

Remark 1

It is very important to understand what we have gained and what we have lost as a result of discretization. Most importantly, we were able to encode the drawing in binary. However, the picture was distorted - instead of a rhombus, we got a set of squares. The reason for the distortion is that in some squares, parts of the original image were filled with different colors, and in the encoded image, each pixel necessarily has one color. Thus, some of the original information was lost during encoding. This will manifest itself, for example, when the picture is enlarged - the squares increase, and the picture is even more distorted. To reduce information loss, you need to reduce the pixel size, that is, increase the resolution.

Definition 2

Permission is the number of pixels per inch of image size.

Resolution is usually measured in pixels per inch (the English notation $ppi$ = pixels per inch is used). For example, a resolution of $254$ $ppi$ means that there are $254$ pixels per inch ($25.4$ mm), so each pixel "contains" a $0.1×0.1$ mm square of the original image. The higher the resolution, the more accurately the picture is encoded (less information is lost), but at the same time the file size also grows.

Color coding

What if the drawing is in color? In this case, one bit is no longer enough to encode the color of a pixel. For example, in the image of the Russian flag $4$ shown in the figure, the colors are black, blue, red and white. It takes $2$ bits to encode one of the four options, so the code for each color (and the code for each pixel) will consist of two bits. Let $00$ be black, $01$ be red, $10$ be blue, and $11$ be white. Then we get the following table:

Figure 4

The only problem is that when displaying on the screen, you need to somehow determine which color corresponds to one or another code. That is, color information must be expressed as a number (or a set of numbers).

Man perceives light as a set of electromagnetic waves. A certain wavelength corresponds to a certain color. For example, wavelengths of $500-565$ nm are green. So-called "white" light is actually a mixture of wavelengths that cover the entire visible range.

According to the modern concept of color vision (Jung-Helmholtz theory), the human eye contains three types of sensitive elements. Each of them perceives the entire stream of light, but the first are most sensitive in the red region, the second in the green region, and the third in the blue region. Color is the result of excitation of all three types of receptors. Therefore, it is believed that any color (that is, the sensations of a person who perceives waves of a certain wavelength) can be imitated using only three light beams (red, green and blue) of different brightness. Therefore, any color is approximately decomposed into three components - red, green and blue. By changing the strength of these components, you can make any color. This color model is called RGB after the initial letters of the English words red (red), green (green) and blue (blue).

In the RBG model, the brightness of each component (or, as they say, each channel) is most often encoded by an integer from $0$ to $255$. In this case, the color code is a triple of numbers (R, G, B), the brightness of individual channels. Color ($0,0,0$) is black and ($255,255,255$) is white. If all components are of equal brightness, shades of gray are obtained, from black to white.

Figure 5

To make a light red (pink) color, you need to increase the brightness of the green and blue channels equally in red ($255.0.0$), for example, the color ($255, $150, $150) is pink. Uniform decrease in the brightness of all channels makes a dark color, for example, the color with the code ($100.0.0$) is dark red.

In total, there are $256$ brightness options for each of the three colors. This allows $256^3= 16,777,216$ shades to be encoded, which is more than enough for a human. Since $256 = 2^8$, each of the three components occupies $8$ bits or $1$ bytes in memory, and all information about some color is $24$ bits (or $3$ bytes). This value is called color depth.

Definition 3

Color depth is the number of bits used to encode the color of a pixel.

$24$-bit color coding is often referred to as True Color mode. To calculate the size of the picture in bytes with this encoding, you need to determine the total number of pixels (multiply the width and height) and multiply the result by $3$, since the color of each pixel is encoded in three bytes. For example, a picture of $20x30$ pixels encoded in truecolor mode would take $20x30x3 = 1800$ bytes.

In addition to the true color mode, $16$-bit coding (High Color) is also used, when $5$ bits are assigned to the red and blue components, and $6$ bits to the green component, to which the human eye is more sensitive. In High Color mode, $2^(16) = 65,536$ different colors can be encoded. Mobile phones have $12$-bit color coding ($4$ bits per channel, $4096$ colors).

Palette coding

Generally, the fewer colors used, the more the color image will be distorted. Thus, when encoding color, there is also an inevitable loss of information that is "added" to the loss caused by sampling. Very often (for example, in schemes, diagrams and drawings) the number of colors in the image is small (no more than $256$). In this case, palette coding is used.

Definition 4

Color palette is a table in which each color specified as components in the RGB model is assigned a numerical code.

Palette encoding is done like this:

  • select the number of colors $N$ (usually not more than $256$);
  • choose any $N$ colors from the true color palette ($16 777 216$ colors) and find components in the RGB model for each of them;
  • each color is assigned a number (code) from $0$ to $N–1$;
  • we compose the palette, first writing the RGB components of the color with the $0$ code, then the color components with the $1$ code, and so on.

The color of each pixel is encoded not as RGB values, but as a color number in the palette. For example, when encoding the image of the Russian flag (see above), $4$ colors were chosen:

  • black: RGB code ($0.0.0$); binary code $002$;
  • red: RGB code ($255.0.0$); binary code $012$;
  • blue: RGB code ($0.0.255); binary $102$;
  • white: RGB code ($255,255,255); binary code $112$.

Therefore, the palette, which is usually written to a special service area at the beginning of the file (it is called the file header), is four three-byte blocks:

Figure 6

The code of each pixel takes only two bits.

Palettes with more than $256$ of colors are not used in practice.

Advantages and disadvantages of raster coding

Raster encoding has dignity:

  • universal method (any image can be encoded);
  • the only method for encoding and processing blurry images that do not have clear boundaries, such as photographs.

AND limitations:

  • when discretizing, there is always a loss of information;
  • when resizing the image, the color and shape of the objects in the picture are distorted, since when increasing the size, it is necessary to somehow restore the missing pixels, and when decreasing, replace several pixels with one;
  • the file size does not depend on the complexity of the image, but is determined only by the resolution and color depth.

As a rule, raster drawings have a large volume.