Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Fix #347: Faster text rendering in Agg #5361

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 5, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix #347: Faster text rendering in Agg
When the text isn't rotated, we can skip a lot of machinery by just
doing a direct blending of text pixels onto the output buffer.
  • Loading branch information
mdboom committed Nov 2, 2015
commit 340c25623bfd3f601bc8b13825467e463135ca3c
5 changes: 5 additions & 0 deletions 5 doc/users/whats_new/faster-text-rendering.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Faster text rendering
---------------------

Rendering text in the Agg backend is now less fuzzy and about 20%
faster to draw.
95 changes: 61 additions & 34 deletions 95 src/_backend_agg.h
Original file line number Diff line number Diff line change
Expand Up @@ -734,41 +734,68 @@ inline void RendererAgg::draw_text_image(GCAgg &gc, ImageArray &image, int x, in
typedef agg::renderer_scanline_aa<renderer_base, color_span_alloc_type, span_gen_type>
renderer_type;

theRasterizer.reset_clipping();
rendererBase.reset_clipping(true);
set_clipbox(gc.cliprect, theRasterizer);
if (angle != 0.0) {
agg::rendering_buffer srcbuf(
image.data(), (unsigned)image.dim(1),
(unsigned)image.dim(0), (unsigned)image.dim(1));
agg::pixfmt_gray8 pixf_img(srcbuf);

theRasterizer.reset_clipping();
rendererBase.reset_clipping(true);
set_clipbox(gc.cliprect, theRasterizer);

agg::trans_affine mtx;
mtx *= agg::trans_affine_translation(0, -image.dim(0));
mtx *= agg::trans_affine_rotation(-angle * agg::pi / 180.0);
mtx *= agg::trans_affine_translation(x, y);

agg::path_storage rect;
rect.move_to(0, 0);
rect.line_to(image.dim(1), 0);
rect.line_to(image.dim(1), image.dim(0));
rect.line_to(0, image.dim(0));
rect.line_to(0, 0);
agg::conv_transform<agg::path_storage> rect2(rect, mtx);

agg::trans_affine inv_mtx(mtx);
inv_mtx.invert();

agg::image_filter_lut filter;
filter.calculate(agg::image_filter_spline36());
interpolator_type interpolator(inv_mtx);
color_span_alloc_type sa;
image_accessor_type ia(pixf_img, agg::gray8(0));
image_span_gen_type image_span_generator(ia, interpolator, filter);
span_gen_type output_span_generator(&image_span_generator, gc.color);
renderer_type ri(rendererBase, sa, output_span_generator);

theRasterizer.add_path(rect2);
agg::render_scanlines(theRasterizer, slineP8, ri);
} else {
agg::rect_i fig, text;

fig.init(0, 0, width, height);
text.init(x, y - image.dim(0), x + image.dim(1), y);
text.clip(fig);

if (gc.cliprect.x1 != 0.0 || gc.cliprect.y1 != 0.0 || gc.cliprect.x2 != 0.0 || gc.cliprect.y2 != 0.0) {
agg::rect_i clip;

clip.init(int(mpl_round(gc.cliprect.x1)),
int(mpl_round(gc.cliprect.y1)),
int(mpl_round(gc.cliprect.x2)),
int(mpl_round(gc.cliprect.y2)));
text.clip(clip);
}

agg::rendering_buffer srcbuf(
image.data(), (unsigned)image.dim(1), (unsigned)image.dim(0), (unsigned)image.dim(1));
agg::pixfmt_gray8 pixf_img(srcbuf);

agg::trans_affine mtx;
mtx *= agg::trans_affine_translation(0, -image.dim(0));
mtx *= agg::trans_affine_rotation(-angle * agg::pi / 180.0);
mtx *= agg::trans_affine_translation(x, y);

agg::path_storage rect;
rect.move_to(0, 0);
rect.line_to(image.dim(1), 0);
rect.line_to(image.dim(1), image.dim(0));
rect.line_to(0, image.dim(0));
rect.line_to(0, 0);
agg::conv_transform<agg::path_storage> rect2(rect, mtx);

agg::trans_affine inv_mtx(mtx);
inv_mtx.invert();

agg::image_filter_lut filter;
filter.calculate(agg::image_filter_spline36());
interpolator_type interpolator(inv_mtx);
color_span_alloc_type sa;
image_accessor_type ia(pixf_img, agg::gray8(0));
image_span_gen_type image_span_generator(ia, interpolator, filter);
span_gen_type output_span_generator(&image_span_generator, gc.color);
renderer_type ri(rendererBase, sa, output_span_generator);

theRasterizer.add_path(rect2);
agg::render_scanlines(theRasterizer, slineP8, ri);
for (int yi = text.y1; yi < text.y2; ++yi) {
for (int xi = text.x1; xi < text.x2; ++xi) {
typename ImageArray::value_type pixel = image(
yi - (y - image.dim(0)), xi - x);
pixFmt.blend_pixel(xi, yi, gc.color, pixel);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not an agg expert, but it seems that blend_color_hspan could be even faster.

http://sourceforge.net/p/vector-agg/mailman/message/5116797/

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll play with that. blend_color_hspan doesn't take as inputs exactly the same thing that we have, so there may be overhead in creating that first negating any wins. Only benchmarking will tell.

}
}
}
}

class span_conv_alpha
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.