Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

AGG lesson 25 pixel format renderers Pixel format Renderer

2025-03-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

1 declaration

Take a look at this statement:

Agg::pixfmt_rgb24 pixf (rbuf)

Here we create an underlying pixel rendering object (pixel renderingobject) and attach it to the rendering memory area (renderingbuffer), which is defined as follows:

Typedef pixel_formats_rgb24pixfmt_rgb24

The class template pixel_formats_rgb24 holds the specific pixel format information in memory. The only template parameter can be order_rgb24 or order_rgb23, which define the order of color channels.

Unlike rendering buffer, these classes operate with integer pixel coordinates because they know how to calculate the offset from a particular point X. You might say that it would be easier to save the width values of pixels in rendering buffer, but there are a lot of limitations in practice. Don't forget that the pixel width may be smaller than a byte, as is the case when a printer renders a high-resolution Broad W image. Therefore, we need to separate this function, the rendering_buffer class is used to speed up access to the "row", and pixelformat renderers is responsible for how to parse what the "row" is.

Pixel_formats_rgb24 (rendering_buffer&rb)

The constructor of the Pixel format renderer (pixecl formatrenderers) requires a reference to a rendering_buffer object that has been created and well initialized. The overhead of this build work is very small, basically initializing a pointer.

Member Functions

The Pixel format renderer (pixecl formatrenderers) must implement these interfaces:

Unsigned width () const {return masked rbuf-> width ();}

Unsigned height () const {returnm_rbuf- > height ();}

Returns the width and height of the memory area (in pixels)

Color_type pixel (int x, int y)

Returns the color of the pixel at the coordinate of (xPowery)

Void copy_pixel (int x, int y, constcolor_type& c)

Copy the colored pixels into the cache. If it is in its own RGB pixel format, it does not take into account the existence of alpha channels in the rgba8 copy source. If it is RGBA, it simply copies all the values, including R, G, B, and alpha channel values.

Void blend_pixel (int x, int y, constcolor_type& c, int8ucover)

This function mixes the pixel c with the color information with the pixel at the cache area (xmemy) (blending). Now let's explain the concept of "mixing". Blending is a key feature of anti-aliasing (anti-aliasing). In the color space of RGBA, we use rgba8 structures to represent colors. This structure has a data member int8u a, which is the alpha channel. However, in this function, we also see a parameter cover, which represents the coverage value of the pixel, for example, the size of the part of the pixel that is "covered" by the polygon. You can actually think of it as another alpha (or should you call it Beta? :). There are two reasons for this. First, the color type (color type) does not have to contain an alpha value. Even if the color type has an alpha value, its type does not have to be the same as the color type used in the anti-aliasing algorithm. Suppose you are using the "Hi-End" RGBA color space, which uses a floating-point range of four values, and alpha channel values also use floating-point numbers-for this case, it is too little to use a byte when mixing, but it is very good for anti-aliasing. Therefore, the cover value is a uniform alternate alpha value used for anti-aliasing. In most cases, it is defined in cover_type, but the int8u type is used directly in the rasterizer processor (rasterizers). This is deliberately defined, because if you need to enhance the capabilities of cover_type, it will make all existing pixel format rasterizer (pixel formatrasterizres) incompatible with cover_type. They are indeed incompatible, and when mixing colors, if the intermediate value is temporarily stored using the 32-bit value, then the maximum can only use the overlay value of 8-bit (coverage value) and the alpha value of 8-bit (alpha). If you use the value of 16-bit, you have to temporarily store it with the intermediate value of 64-bit, which can be very expensive for 32-bit platforms.

Void copy_hline (int x, int y, unsigned len,const color_type&c)

Void copy_vline (int x, int y, unsigned len,const color_type&c)

Use a certain color to draw a horizontal or vertical line.

Void blend_hline (int x, int y, unsignedlen, const color_type&c, int8u cover)

Void blend_vline (int x, int y, unsignedlen, const color_type&c, int8u cover)

Use the mode of mixed colors to draw horizontal (or vertical) lines with a certain color. The reason why we want to separate the two versions of copy and blend is because of efficiency. Although you can use an if/else (which is actually available in the blend version of the drawing function), this can affect efficiency in some situations, such as when you want to draw a lot of small markers, which is often encountered in different scatter plotting programs (scatter plotapplicatioin).

Void blend_solid_hspan (int x, int y unsigned len

Const color_type& Corey Const int8u* covers)

Void blend_solid_vspan (int x, int y unsigned len

Const color_type& Corey Const int8u* covers)

Mixed to draw a horizontal or vertical solid-color span, Span is almost the same as hline and vline, but it has an array containing coveragevalue. These two functions are used when rendering solid anti-aliased polygons.

Void blend_color_hspan (int x, int y unsigned len

Const color_type*colors, const int8u* covers)

Void blend_color_vspan (int x, int y, unsignedlen

Const color_type*colors, const int8u* covers)

Mix horizontal or vertical color span, these two functions are used in different span generators, such as gradient,p_w_picpath,patterns,Gouraud interpolation and so on. Function accepts a color array parameter that must be compatible with the pixel format used. For example, all existing RGB pixel formats in AGG are compatible with the rgb8 type. The covers parameter is an array of coverage value, which is the same as in blend_solid_hspan. This is optional and can be set to 0.

The following example is the spectrum that depicts sunlight. The rgba class contains the color parts of four floating-point numbers (including alpha), and this class has a static function from_wavelength and a corresponding constructor. Rgba8 can be constructed using rgba (this is a common strategy in AGG, that is, any color type can be constructed using rgba).

2 the main points of learning

This class populates the render cache from the pixel point of view, and fills the pixel value of the render cache by specifying the rgb8 structure.

Here to say a little more: rgb8 is 8-bit color value, the range is (0255), rgb is floating-point color value (0mem1).

3 overhead

Analyze the code:

Agg::rendering_buffer & rbuf = rbuf_window ()

Agg::pixfmt_bgr24 pixf (rbuf)

Typedef agg::renderer_base renderer_base_type

Renderer_base_type renb (pixf)

Agg::renderer_primitivesprimitive (renb)

The construction cost of pixel format renderer and basic renderer object is very small, only to get the pointer of the rendering cache, to render the rendering cache, without any memory allocation. For example, generating the pixel renderer pixfmt_bgr24 simply assigns the pointer of the render cache to the member variable m_buf of pixfmt_bgr24.

4 pixfmt_rgb24 competing for pixfmt_bgr24

On windows platform, the color components of the applied rendering cache are arranged as follows: BGR, not the usual RGB. So pixfmt_bgr24 instead of pixfmt_rgb24 is used, and the same is true for OpenGL when setting pixels.

5 View the color sequence of the render cache

Agg::rendering_buffer & rbuf = rbuf_window ()

Agg::pixfmt_bgr24 pixf (rbuf)

Agg::pixfmt_rgb24pixf1 (rbuf)

For (int I = 20 per I

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report