Color palettes in RGB, CMYK and HSB color rendering systems. Palette (computer graphics) Color palettes in computer graphics

Any color can be selected from a wide color space N colors, and their coordinates (usually: R, G And B) are stored in a special table - palette. Raster graphics data that uses a palette is an array that stores numbers(indices) of colors in the palette.

Palette graphics allow you to combine a wide color gamut of an image with low memory consumption.

Palette video modes

Palette modes are video modes in which each pixel can accept one of a small (from 2 to 256) number of colors. Video memory in such modes is divided into two parts: a color table (palette), which contains the values ​​of red, green and blue for each color, and a frame buffer, which stores the color number in the palette for each pixel.

Typically, the palette can be changed independently of the framebuffer. If somehow a picture in the wrong palette gets onto the screen, a specific video effect occurs.

To display an image with more than 256 colors on a 256-color screen, you need to build a palette that approximates the required colors. High-quality construction of a 256-color palette can take quite a lot of time (up to several seconds on computers of that time). Therefore, where speed is required (web, games, video playback), the palette is strictly specified in the graphic data, and is not built dynamically.

Palette special effects

The fact that the palette can be changed independently of the framebuffer is widely used in video games to achieve very fast special effects. Here's a (non-exhaustive) list of games with similar video effects.

  • Doom: screen flashes when the hero picks up an item or is injured, as well as changing the color of the image when using a spacesuit.
  • Warcraft II: water splash. Interestingly, water splashing is also implemented in the Warcraft II editor - of course, only in 256-color modes.

Also, lightening and darkening colors in palette games is performed very quickly (albeit poorly) using color replacement tables - in one or two machine commands per pixel. In Doom, darkness, night vision and invulnerability are implemented using color substitution; in almost all strategies of that time (and in the same Doom) - repainting identification marks in the player’s color. In truecolor, these same operations have to be done component by component, often with expensive multiplication, which requires much more CPU time.

Comparison with HighColor and TrueColor

Advantages:

  • Low memory consumption.
  • Fast palette special effects.

Flaws:

  • Incomplete set of colors.
  • Constructing the optimal palette for a full-color image can be computationally intensive.

Palette files

Palette, or indexed files are graphic files arranged in a similar way. As in palette video modes, by changing the palette you can recolor objects (for example, in a computer game there are cars of six colors, while the data files store one picture of a car with six palettes). Cm.

The concepts of light and color in computer graphics are fundamental. Light can be viewed in two ways: either as a stream of particles of various energies, or as a stream of electromagnetic waves.

The concept of color is closely related to how a person perceives light. We can say that the sensation of light is formed by the human brain as a result of analyzing the light flux falling on the retina of the eyes.

The source or object is achromatic , if the observed light contains all visible wavelengths in approximately equal quantities. Achromatic colors are white, black, and shades of gray. For example, objects that achromatically reflect more than 80% of the light from a white source appear white, and less than 3% appear black.

If the perceived light contains wavelengths in unequal quantities, then it is called chromatic .

It is believed that in the human eye there are three groups of color receptors (cones), each of which is sensitive to a specific wavelength of light. Each group forms one of three primary colors : red, green, blue.

Rice. 1.6. Eye reaction curves

If the wavelengths of the light flux are concentrated at the upper end of the visible spectrum (about 700 Nm), then the light is perceived as red. If the wavelengths are concentrated at the lower end of the visible spectrum (about 400 nm), then the light is perceived as blue. If the wavelengths are concentrated in the middle of the visible spectrum (about 550 nm), then the light is perceived as green.

Using experiments based on this hypothesis, the eye response curves shown in Fig. 1 were obtained. 16.

The physical characteristics of the luminous flux are determined by the parameters power ,brightness And illumination . The visual parameters of color sensation are characterized by lightness ,saturation And color tone .

Lightness - this is the distinguishability of areas that reflect light more or less strongly. The minimum difference between the brightness of objects distinguishable by lightness is called threshold .

Saturation color indicates how different a given color is from monochromatic (“pure”) radiation of the same light tone. Saturation characterizes the degree of weakening (dilution) of a given color with white and allows you to distinguish pink from red, cyan from blue.

Color tone allows you to distinguish primary colors such as red, green, blue.

      1. Color models

As we can see from the above, the description of color can be based on the composition of any color based on primary colors or on concepts such as lightness, saturation, hue. In relation to computer graphics, the description of color must also take into account the specifics of the equipment for input/output of images. Due to the need to describe the various physical processes of color reproduction, various color models have been developed. Color models make it possible to describe certain color regions of the spectrum using mathematics. Color models describe color shades by mixing several primary colors.

Primary colors are divided into shades according to brightness (from dark to light), and each gradation of brightness is assigned a numerical value (for example, the darkest is 0, the lightest is 255). It is believed that the average person is able to perceive about 256 shades of one color. Thus, any color can be decomposed into shades of primary colors and designated by a set of numbers - color coordinates.

Thus, when choosing a color model, you can define a three-dimensional color coordinate space within which each color is represented by a point. This space is called color model space.

Professional graphics programs usually allow you to work with several color models, most of which are created for special purposes or specific types of paints: CMY, CMYK, CMYK256, RGB, HSB, HLS, L*a*b, YIQ, Grayscale and Registration color. Some of them are rarely used, others have overlapping ranges.

RGB color model. One of the most common color models, called the RGB model, is based on the reproduction of any color by adding three primary colors: red (Red), green (Green) and blue (Blue). Each channel - R, G or B has its own separate parameter, indicating the amount of the corresponding component in the final color. For example: (255, 64, 23) – a color containing a strong red component, a little green and very little blue. Naturally, this mode is most suitable for conveying the richness of the colors of the surrounding nature. But it also requires high costs, since the color depth here is the greatest - 3 channels of 8 bits each, which gives a total of 24 bits.

Since colors are added in the RGB model, it is called additive (additive). It is this model that is used to reproduce color in modern monitors.

The RGB color space of the model is a unit cube.

Rice. 1.7. RGB color space model

CMY andCMYK. The CMY model also uses three primary colors: Cyan (blue), Magenta (magenta or crimson) and Yellow (yellow). These colors describe the light reflected from white paper from the three primary colors of the RGB model. Therefore, we can describe the relationship between RGB and CMY models as follows:


.

The CMY model is subtractive (subtraction based) color model. As already mentioned, the CMY model describes colors on a white medium, i.e., dye applied to white paper subtracts part of the spectrum from the incident white light. For example, blue (Cyan) dye was applied to the surface of the paper. Now the red light falling on the paper is completely absorbed. Thus, the blue medium subtracts red light from the incident white light.

This model most accurately describes the colors when printing an image, i.e. in printing.

Since three dyes are required to reproduce black, and consumables are expensive, using a CMY model is not effective. An additional factor that does not add to the attractiveness of the CMY model is the appearance of undesirable visual effects that arise due to the fact that when drawing a point, the three basic colors may lie with slight deviations. Therefore, black (blacK) is added to the basic three colors of the CMY model and a new CMYK color model is obtained.

To convert from a CMY model to a CMYK model, the following relationship is sometimes used:

K= min( C, M, Y);

C = CK;

M=MK;

Y=YK.

The conversion ratios for RGB to CMY and CMY to CMYK model are correct only if the spectral reflectance curves for the base colors do not intersect. Therefore, in general, we can say that there are colors described in the RGB model, but not described in the CMYK model.

There is also a CMYK256 model, which is used for more accurate color reproduction for high-quality image printing.

HSV and HLS color models. The models considered are focused on working with color-transmitting equipment and are inconvenient for some people. Therefore, the HSV, HLS models rely on the intuitive concepts of saturation and brightness hue.

The color space model HSV (Hue, Saturation, Value), sometimes called HSB (Hue, Saturation, Brightness), uses a cylindrical coordinate system, and the set of valid colors is represented by a hexagonal cone placed on the top.

The base of the cone represents bright colors and matches V= 1. However, the base colors V= 1 do not have the same perceived intensity. Tone ( H) measured by the angle measured around the vertical axis O.V.. In this case, the red color corresponds to an angle of 0, the green color corresponds to an angle of 120, etc. Colors that complement each other to white are opposite one another, that is, their tones differ by 180. Magnitude S varies from 0 on the axis O.V. up to 1 on the faces of the cone.

The cone has unit height ( V= 1) and the base located at the origin. At the base of the cone the size H And S don't make sense. White color corresponds to a pair S= 1,V= 1. Axis O.V.(S= 0) corresponds to achromatic colors (gray tones).

The process of adding white to a given color can be thought of as reducing saturation S, and the process of adding black is like reducing brightness V. The base of the hexagonal cone corresponds to the RGB projection of the cube along its main diagonal.

Rice. 1.8. HSV model color space

Another example of a system built on the intuitive concepts of hue, saturation and brightness is the HLS (Hue, Lightness, Saturation) system. Here the set of all colors is represented by two hexagonal cones placed on top of each other (base to base).

Rice. 1.9. HLS model color space

Full color and indexed images. As we've seen, pixel colors can be defined by explicitly specifying several color parameters. For example, in the RGB model, the final color is determined by three terms for the three primary colors. This approach allows us to form so-called full color Images.

The second approach is that the first part of the file storing the image stores "palette" , in which the colors present in the image are encoded using one of the color models. And the second part, which directly describes the pixels of the image, actually consists of indices in the palette. Images formed in this way are called images with indexed palette .

A special case of an indexed image is a black and white image. In such an image there can only be 2 colors - black and white, coded 0 and 1, respectively. The image depth in this case is 1 bit. This depth is very poorly suited to the presentation of photorealistic images and is only used for specialized images.

The advantage of the palette is the ability to significantly reduce the size of the image file. The disadvantage is the possibility of color loss with a limited palette size. Typically the palette size is up to 256 colors.


Color palettes in color rendering systems R G B , C M Y K And H.S.B.



How do people perceive color?

A person perceives light using color receptors (cones) located on the retina of the eye.

Cones are sensitive to red, green and blue (primary colors).


The sum of red, green and blue colors is perceived by a person as white .

Their absence - how black, and their various combinations are like numerous shades of colors .


Based on the physiology of color perception, a person best perceives color from a monitor screen as the sum of the radiation of three basic colors: red, green, blue.

This color rendering system is called RGB, after the first letters of the English color names (Red, Green, Blue).


The color from the palette can be determined using the formula:

Color = R+G+B

R, G, B – basic colors that take values ​​from 0 to 255

So, with a color depth of 24 bits, 8 bits are allocated for encoding each of the basic colors, then for each color N = 2 8 = 256 intensity levels are possible.


Formation of color in R G B

Color

Color formation

255 + 255 + 255

Purple

In the RGB system, the color palette is formed by adding the basic colors: red, green and blue.



Purple

The CMYK system, unlike RGB, is based on the perception of reflected rather than emitted light.

Thus, blue ink applied to paper absorbs red and reflects green and blue.

The colors of the palette can be determined using the formula:

Color = C+M+Y

C, M and Y – palette colors that take values ​​from 0% to 100%


Formation of color in C M Y K

Color

Color formation

C + M +Y = - G - B – R

Y +C = - R - B

In the CMYK color system, the color palette is created by combining cyan, magenta, yellow and black.


  • Hue(color shade)
  • Saturation(saturation)
  • Brightness(brightness)

Color palettes in color rendering systems R G B , C M Y K And H.S.B.

Lecture 5

Color coding. Palette

Color coding

In order for a computer to be able to work with color images, it is necessary to represent colors in the form of numbers - color encoding. The encoding method depends on the color model and numeric data format in the computer.

For RGB model each of the components can be represented by numbers limited to a certain range, for example, fractional numbers from zero to one or integer numbers from zero to some maximum value. The most common color representation scheme for video devices is the so-called RGB representation, in which any color is represented as the sum of three primary colors - red, green, blue - with given intensities. The entire possible color space is a unit cube, and each color is defined by a triple of numbers (r, g, b) – (red, green, blue). For example, yellow is specified as (1, 1, 0), and magenta is specified as (1, 0, 1), white corresponds to the set (1, 1, 1), and black corresponds to (0, 0, 0).

Typically, a fixed number n bits of memory are allocated for storing each color component. Therefore, it is considered that the acceptable range of values ​​for color components is not , but .

Almost any video adapter is capable of displaying a significantly larger number of colors than that determined by the size of video memory allocated for one pixel. To use this feature, the concept of a palette is introduced.

Palette – an array in which each possible pixel value is associated with a color value ( r, g, b ). The size of the palette and its organization depend on the type of video adapter used.

The simplest way is to organize the palette into
EGA adapter . Each of the 16 possible logical colors (pixel values) is allocated 6 bits, 2 bits for each color component. In this case, the color in the palette is set by a byte of the form 00 rgbRGB, where r, g, b, R, G, B can take the value 0 or 1. Thus, for each of the 16 logical colors, you can set any of the 64 possible physical colors.

16-color standard palette for video modes EGA, VGA. Implementation of a palette for 16-color adapter modes VGA much more difficult. In addition to adapter palette support E.G.A. , the video adapter additionally contains 256 special DAC -registers, where for each color its 18-bit representation is stored (6 bits for each component). In this case, with the original logical color number using 6-bit palette registers E.G.A. the value from 0 to 63 is compared, as before, but it is no longer RGB - color decomposition, and number DAC -register containing physical color.

256-color for VGA. For 256-VGA the pixel value is directly used to index the array DAC registers.

Currently, the format is quite common True Color , in which each component is represented as a byte, which gives 256 gradations of brightness for each component: R =0…255, G =0…255, B =0…255. The number of colors is 256x256x256=16.7 million (2 24).

This coding method can be called component coding. Image codes on the computer True Color are represented as triplets of bytes, or are packed into a long integer (four-byte) - 32 bits (for example, this is done in Windows API):

C = 00000000 bbbbbbbb gggggggg rrrrrrrr .

Index palettes

When working with images in computer graphics systems, you often have to make a compromise between image quality (you need as many colors as possible) and the resources required to store and reproduce the image, calculated, for example, in memory capacity (you need to reduce the number of bytes per pixel). Additionally, a given image itself may only use a limited number of colors. For example, for drawing, two colors may be enough; for a human face, shades of pink, yellow, purple, red, green are important, and for the sky, shades of blue and gray are important. In these cases, using full color color coding is redundant.

When limiting the number of colors, use a palette that provides a set of colors that are important for a given image. A palette can be thought of as a table of colors. The palette establishes the relationship between the color code and its components in the selected color model.

Computer video systems usually provide the ability for the programmer to set their own color palette. Each color shade is represented by a single number, and this number does not express the color of the pixel, but the color index (its number). The color itself is searched for by this number in the accompanying color palette attached to the file. These color palettes are called index palettes.

An index palette is a table of data that stores information about what code a particular color is encoded with. This table is created and stored along with the graphic file.

Different images may have different color palettes. For example, in one image the color green may be coded at index 64, while in another this index may be assigned to the color pink. If you reproduce an image with a “foreign” color palette, the green tree on the screen may turn out to be pink.

Fixed palette

In cases where the color of the image is encoded in two bytes (mode High Color ), the screen can display 65 thousand colors. Of course, these are not all possible colors, but only one 256th part of the total continuous spectrum of colors available in the mode True Color . In such an image, each two-byte code also expresses some color from the general spectrum. But in this case, it is impossible to attach an index palette to the file, which would record which code corresponds to which color, since this table would have 65 thousand entries and its size would be hundreds of thousands of bytes. It hardly makes sense to attach a table to a file that may be larger in size than the file itself. In this case, the concept of a fixed palette is used. It does not need to be included with the file, since in any graphics file that has a 16-bit color encoding, the same code always expresses the same color.

Safe palette

The term safe palette is used in Web -graphics. Since the speed of data transfer on the Internet still leaves much to be desired, for registration Web -pages do not use graphics with color coding higher than 8-bit.

In this case, a problem arises due to the fact that the creator Web -page does not have the slightest idea about what model of computer and under the control of what programs his work will be viewed. He's not sure whether his "green tree" will turn red or orange on users' screens.

In this regard, the following decision was made. All the most popular viewing programs Web -pages (browsers) are pre-configured to a certain fixed palette. If the developer Web -page will use only this palette when creating illustrations, then he can be sure that users all over the world will see the drawing correctly. This palette does not have 256 colors, as one might expect, but only 216. This is due to the fact that not all computers connected to the Internet are capable of reproducing 256 colors.

Such a palette, which rigidly defines the indices for encoding 216 colors, is called a safe palette.

Raster and vector graphics.

The vast majority of computer graphics are of two types: raster and vector.

In raster graphics, the main element is pixel(short for the English words picture element, image element). A ¾ pixel is a basic square element of a raster image, within which color, brightness and other properties remain unchanged. The entire image consists of tiny squares of the same size, each of them has a certain color and brightness, and this is recorded in the file.

In other words, the principle is this: we take the surrounding continuous reality, divide it into small squares and enter it into the computer square by square. If the square pixels are invisible to the eye, then the digital image looks quite natural.

Almost all devices for inputting graphics into and outputting from a personal computer are built on the raster principle; the image in them is digitized in the form of raster dots. Drawings or photographs entered into a computer, for example from a scanner or via the Internet, will be of the raster type.

The measure of pixel size is permission. Resolution ¾ is the number of pixels per unit of length - one inch. Resolution is measured in dots per inch (dots per inch). One inch is equal to 2.54 cm.

In vector graphics, the main element is the line. More precisely segment: a line segment limited by two reference points. All line segments of the drawing are written in the file in the form of certain mathematical formulas. The color, thickness and other properties of segments and anchor points are also written in a certain way. The segments, connecting to each other through support points, form contours. Closed paths can be filled with color, gradient, texture, etc.

The purpose of vector graphics is to create drawings, logos, business graphics, etc.; simple and poor in picturesque terms, but precisely outlined. Such a drawing is not an exact reflection of reality; it expresses certain meanings and images that are understandable to other people. By the way, text is also vector graphics; all letters are created from vector contours.

Representation of color in a computer.

As already mentioned, in a computer everything is expressed as a combination of zeros and ones, including color. There are various options for describing color, the most common ones are listed below.

a) Bitmap mode. This is the most elementary representation - bitwise, the color of a pixel or vector object is encoded in one bit. This way you can encode only two options - black and white (or any other set of two colors, for example, red and green). Bitmap mode typically displays text as well as line art—black drawings on a white background.


b) Grayscale mode. To encode the brightness of tone black-and-white illustrations, one byte (8 bits) is used, which results in 2 8 = 256 shades of gray for each point. This is quite enough for black and white tone graphics; there is no need for more detail.

c) Index mode– here the color is encoded in one byte, in total the same 256 colors can be obtained. Of course, such a small number of color codes reduces the image quality.

It happens that when creating pictures, it is the index mode that is used. The index palette available in the program is called up and the appropriate color is selected. If there is no need or desire to make a more detailed selection, then the coloring ends here.

Index mode is often used on the Internet, where the loading time of a web page plays a significant role. The smaller the page size, the shorter the time. Saving on color descriptions also results in savings in the size of Internet banners.

G) Mode True Color or color model RGB The term True Color refers only to monitors, and the term RGB is much broader. This model is based on three colors: red, green and blue. Red, Green, Blue, the model is named after the first letters of the English names of these colors (Figure 1). Our vision is designed in such a way that any color visible to the human eye can be obtained by mixing these three primary colors.

The model is well suited for objects that emit light, in particular for monitor screens. Scanners, digital cameras and other devices for inputting graphics into a computer also work in the RGB model, because ultimately a person sees an electronic image on a monitor screen.

To encode the brightness of each of the primary colors, 256 values ​​are used, that is, one byte or 8 bits. In total, 24 bits must be spent on encoding the color of one point. In total, the coding system provides an unambiguous identification of 2 24 ≈ 16.8 million different colors.

In fact, such a huge number of colors on the screen is not required; a person distinguishes about 200,000 color shades. But such is the encoding system - no less than one byte is allocated for each channel. And when processing files, it happens that an excess of shades can be useful and even necessary.

Rice. 1. RGB color model.

e) CMYK color model(Figure 2). Here the main colors are cyan (Cyan), purple (Magenta), yellow (Yellow), black (Black). In the designation of the color model for black, not the first letter is taken, but the last, so that there is no confusion with the letter B of the RGB system.

Rice. 2. CMYK color model.

This model is used to describe reflected color, mainly in printing. Most color printing is done in CMYK (six-color and pantone printing are available, but consideration of these details is beyond the scope of this course). When printing a color electronic image, even on an office printer, RGB is automatically converted to CMYK.

When light is reflected from a surface, some of the light is absorbed, and the color is determined by those light waves that are not absorbed by the surface. The more different paints are used, the greater the absorption, the less reflection, the darker the surface looks. Mixing all the colors will give black. And the absence of any absorption will give a complete reflection, like in a mirror. If white color falls on the mirror, then this is zero staining.

When emitting light, the opposite is true - the more light waves emitted, the higher the brightness of the light. Uniform emission of all light waves corresponds to the color white. And the absence of emission (we neglect reflection here) corresponds to the color black.

As follows from the above, the RGB and CMYK models describe opposite processes. Therefore, in RGB, all zero indices correspond to black, and all ones correspond to white. In CMYK it’s the other way around: all zeros are white, and all ones are black.

In theory, the RGB and CMY (without K) models are mirror opposites: the primary colors of one model are complementary to the other and vice versa (Figures 1 and 2). Why is black also introduced?

The fact is that when moving to the inks actually used in printing, the theory does not work. Mixing cyan, purple and yellow paints produces a dark brown color rather than black. Meanwhile, black is the main color in printing: text is usually printed in black, and many non-color, black and white products are produced. Therefore, there is a need to introduce a separate, black coordinate in the color model.

Loading...Loading...