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

Change default interpolation to nearest #4622

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

Closed
Closed
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
Prev Previous commit
Next Next commit
Merge pull request #5361 from mdboom/fast-text
Fix #347: Faster text rendering in Agg
  • Loading branch information
tacaswell committed Nov 5, 2015
commit a340827407cf8397f2aea4a94fba2dbf2691e217
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.
92 changes: 58 additions & 34 deletions 92 src/_backend_agg.h
Original file line number Diff line number Diff line change
Expand Up @@ -734,41 +734,65 @@ 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::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);
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);
}

for (int yi = text.y1; yi < text.y2; ++yi) {
pixFmt.blend_solid_hspan(text.x1, yi, (text.x2 - text.x1), gc.color,
&image(yi - (y - image.dim(0)), text.x1 - x));
}
}
}

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