Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7d73e2a

Browse files
committed
Agg: Use 32-bit scan line classes
When rendering objects, Agg rasterizes them into scan line objects (an x/y point, horizontal length, and colour), and the renderer class writes those to the pixels in the final buffer. Though we have determined that Agg buffers cannot be larger than 2**16, the scan line classes that we use contain 16-bit _signed_ integers internally, cutting off positive values at half the maximum. Since the renderer uses 32-bit integers, this can cause odd behaviour where any horizontal span that _starts_ before 2**15 (such as a horizontal spine) is rendered correctly even if it cross that point, but those that start after (such as a vertical spine or any portion of an angled line) end up clipped. For example, see how the spines and lines break in #28893. A similar problem occurs for resampled images, which also uses Agg scanlines internally. See the breakage in #26368 for an example. The example in that issue also contains horizontal spines that are wider than 2**15, which also exhibit strange behaviour. By moving to 32-bit scan lines, positions and lengths of the lines will no longer be clipped, and this fixes rendering on very large figures. Fixes #23826 Fixes #26368 Fixes #28893
1 parent 54d718e commit 7d73e2a

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/_backend_agg.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,10 @@ class RendererAgg
117117
typedef agg::renderer_scanline_bin_solid<renderer_base> renderer_bin;
118118
typedef agg::rasterizer_scanline_aa<agg::rasterizer_sl_clip_dbl> rasterizer;
119119

120-
typedef agg::scanline_p8 scanline_p8;
121-
typedef agg::scanline_bin scanline_bin;
120+
typedef agg::scanline32_p8 scanline_p8;
121+
typedef agg::scanline32_bin scanline_bin;
122122
typedef agg::amask_no_clip_gray8 alpha_mask_type;
123-
typedef agg::scanline_u8_am<alpha_mask_type> scanline_am;
123+
typedef agg::scanline32_u8_am<alpha_mask_type> scanline_am;
124124

125125
typedef agg::renderer_base<agg::pixfmt_gray8> renderer_base_alpha_mask_type;
126126
typedef agg::renderer_scanline_aa_solid<renderer_base_alpha_mask_type> renderer_alpha_mask_type;

src/_image_resample.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,7 @@ void resample(
712712

713713
using renderer_t = agg::renderer_base<output_pixfmt_t>;
714714
using rasterizer_t = agg::rasterizer_scanline_aa<agg::rasterizer_sl_clip_dbl>;
715+
using scanline_t = agg::scanline32_u8;
715716

716717
using reflect_t = agg::wrap_mode_reflect;
717718
using image_accessor_t = agg::image_accessor_wrap<input_pixfmt_t, reflect_t, reflect_t>;
@@ -739,7 +740,7 @@ void resample(
739740

740741
span_alloc_t span_alloc;
741742
rasterizer_t rasterizer;
742-
agg::scanline_u8 scanline;
743+
scanline_t scanline;
743744

744745
span_conv_alpha_t conv_alpha(params.alpha);
745746

0 commit comments

Comments
 (0)