Get the App
SLTechnology News&Howtos  ›  Servers  › 

AGG lesson 32 faster rendering algorithm for renderer_outline_aa Line Segment

Shulou Source: shulou.com Published: 2022-06-03 04:37:36 09月15日 Update

For children who once broke their knees and scraped their palms when running on campus! 1 preface

This chapter provides an example of using a new line segment rendering algorithm, which improves the speed by an average of 2 times compared with the existing stroke pipeline algorithm and, at best, 2.6 times the acceleration. Of course, the speed of this algorithm will only be fast when applied to thin lines, preferably less than 2 pixels.

Efficiency will be compared with conv_stroke in other chapters. The same cannot avoid introducing more restrictions, as you can see below. One more thing: conv_stroke is the most expensive converter.

The rasterizer itself works much faster, besides, in this case you won'tneed to use the most expensive converter, that is, conv_stroke.

2 header file

# include "agg/include/agg_rasterizer_outline_aa.h"

# include "agg/include/agg_renderer_outline_aa.h"

3 restrictions

1) the maximum lineweight has been hard-coded, with a maximum of 128pixels, in the agg::line_interpolator_aa_base class

Definition, the declared variable is max_half_width.

2) the link mode of line segments can only be miter. If the rendered lines are thick and the angle between the lines is very sharp, the connection between the segments may not be as accurate as the conv_stroke generation. Although it is not too demanding when rendering thick lines.

3) the line transmission at the end of the segment can only be butt_cap or round_cap. Besides, butt_cap is not anti-aliased. Round_cap looks better, but it affects performance, especially when you render dashed lines (dashed lines occupy 6 pixels, spacing is 3 pixels, about 1.5 times slower)

If you render a long line, you don't need to be so harsh. Call the agg::rasterizer_outline_aa::round_cap (true/false) setting.

4) in rendering some small graphic contours, the effect is not very good. But in rendering maps, characters, images, oscilloscopes and other performance has been very perfect.

5) of course, it is said to be the algorithm of rendering line segments, so it will not render points naturally.

4 code examples

1) simple example

Agg::rendering_buffer&rbuf = rbuf_window ()

Agg::pixfmt_bgr24 pixf (rbuf)

Typedef agg::renderer_outline_aa renderer_type

Agg::line_profile_aa profile

Profile.width (5); / / set lineweight

Renderer_type ren (pixf,profile)

Typedef agg::rasterizer_outline_aa rasterizer_type

Rasterizer_type ras (ren)

Ren.color (agg::rgba8 (25510)); / / sets the color of the line segment

Ras.move_to_d (100100)

Ras.line_to_d (500500)

Ras.render (false)

2) options are available

Agg::rendering_buffer & rbuf = rbuf_window ()

Agg::pixfmt_bgr24 pixf (rbuf)

Typedef agg::renderer_outline_aa renderer_type

Agg::line_profile_aa profile

Profile.gamma (agg::gamma_power (1.2)); / / optional

Profile.min_width (0.75); / / optional

Profile.smoother_width (0); / / optional

Profile.width (5); / / mandatory, lineweight is required

Renderer_type ren (pixf,profile)

Typedef agg::rasterizer_outline_aa rasterizer_type

Rasterizer_type ras (ren)

Ras.round_cap (false); / / optional line transfer at the end of the line segment

Ren.color (agg::rgba8 (255j0j0)); / / set the color, optional

Ras.move_to_d (100100)

Ras.line_to_d (500500)

Ras.line_to_d (300400)

Ras.render (false); / / mandatory, whether to form a closed curve, and false to draw a broken line

3) call add_path to add vertex source. You can not call ras.render.

Agg::rendering_buffer & rbuf = rbuf_window ()

Agg::pixfmt_bgr24 pixf (rbuf)

Typedef agg::renderer_outline_aa renderer_type

Agg::line_profile_aa profile

Profile.gamma (agg::gamma_power (1.2)); / / optional

Profile.min_width (0.75); / / optional

Profile.smoother_width (0); / / optional

Profile.width (5); / / mandatory lineweight setting

Renderer_type ren (pixf,profile)

Typedef agg::rasterizer_outline_aa rasterizer_type

Rasterizer_type ras (ren)

Ras.round_cap (false); / optional

Ren.color (agg::rgba8 (255j0J 0)); / / optional

Agg::path_storage ps

Ps.move_to (600600)

Ps.line_to (600100)

Ras.add_path (ps)

Details of the message:

Http://sourceforge.net/p/vector-agg/mailman/vector-agg-general/?viewmonth=200309&page=1

Tags: Segment algorithm Pixel mandatory time Speed Force maximum demanding between instance way Best Endpoint dashed Line Color limit Sharp expensive Code Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker OPPO Reno NVidia Shulou Information macOS