void src_shape(RenBase& rbase, color c1, color c2, double x1, double y1, double x2, double y2) { typedef RenBase renderer_base_type; typedef agg::gradient_x gradient_func_type; typedef agg::gradient_linear_color<color> color_func_type; typedef agg::span_interpolator_linear<> interpolator_type; typedef agg::span_allocator<color> span_allocator_type; typedef agg::span_gradient<color, interpolator_type, gradient_func_type, color_func_type> span_gradient_type; gradient_func_type gradient_func; // The gradient function agg::trans_affine gradient_mtx = gradient_affine(x1, y1, x2, y2, 100); interpolator_type span_interpolator(gradient_mtx); // Span interpolator span_allocator_type span_allocator; // Span Allocator color_func_type color_func(c1, c2); span_gradient_type span_gradient(span_interpolator, gradient_func, color_func, 0, 100); agg::rasterizer_scanline_aa<> ras; agg::scanline_u8 sl; agg::rounded_rect shape(x1, y1, x2, y2, 40); // agg::ellipse shape((x1+x2)/2, (y1+y2)/2, fabs(x2-x1)/2, fabs(y2-y1)/2, 100); ras.add_path(shape); agg::render_scanlines_aa(ras, sl, rbase, span_allocator, span_gradient); }
void radial_shape(RenBase& rbase, const ColorRamp& colors, double x1, double y1, double x2, double y2) { typedef RenBase renderer_base_type; typedef agg::gradient_radial gradient_func_type; typedef ColorRamp color_func_type; typedef agg::span_interpolator_linear<> interpolator_type; typedef agg::span_allocator<color> span_allocator_type; typedef agg::span_gradient<color, interpolator_type, gradient_func_type, color_func_type> span_gradient_type; gradient_func_type gradient_func; // The gradient function agg::trans_affine gradient_mtx; interpolator_type span_interpolator(gradient_mtx); // Span interpolator span_allocator_type span_allocator; // Span Allocator span_gradient_type span_gradient(span_interpolator, gradient_func, colors, 0, 100); double cx = (x1 + x2) / 2.0; double cy = (y1 + y2) / 2.0; double r = 0.5 * (((x2 - x1) < (y2 - y1)) ? (x2 - x1) : (y2 - y1)); gradient_mtx *= agg::trans_affine_scaling(r / 100.0); gradient_mtx *= agg::trans_affine_translation(cx, cy); gradient_mtx *= trans_affine_resizing(); gradient_mtx.invert(); agg::ellipse ell(cx, cy, r, r, 100); agg::conv_transform<agg::ellipse> trans(ell, trans_affine_resizing()); m_ras.add_path(trans); agg::render_scanlines_aa(m_ras, m_sl, rbase, span_allocator, span_gradient); }
void circle(RenBase& rbase, color c1, color c2, double x1, double y1, double x2, double y2, double shadow_alpha) { typedef RenBase renderer_base_type; typedef agg::gradient_x gradient_func_type; typedef agg::gradient_linear_color<color> color_func_type; typedef agg::span_interpolator_linear<> interpolator_type; typedef agg::span_allocator<color> span_allocator_type; typedef agg::span_gradient<color, interpolator_type, gradient_func_type, color_func_type> span_gradient_type; gradient_func_type gradient_func; // The gradient function agg::trans_affine gradient_mtx = gradient_affine(x1, y1, x2, y2, 100); interpolator_type span_interpolator(gradient_mtx); // Span interpolator span_allocator_type span_allocator; // Span Allocator color_func_type color_func(c1, c2); span_gradient_type span_gradient(span_interpolator, gradient_func, color_func, 0, 100); agg::rasterizer_scanline_aa<> ras; agg::scanline_u8 sl; double r = agg::calc_distance(x1, y1, x2, y2) / 2; agg::ellipse ell((x1+x2)/2+5, (y1+y2)/2-3, r, r, 100); ras.add_path(ell); agg::render_scanlines_aa_solid(ras, sl, rbase, agg::rgba(0.6, 0.6, 0.6, 0.7*shadow_alpha)); ell.init((x1+x2)/2, (y1+y2)/2, r, r, 100); ras.add_path(ell); agg::render_scanlines_aa(ras, sl, rbase, span_allocator, span_gradient); }
virtual void on_draw() { typedef agg::renderer_base<pixfmt> base_ren_type; pixfmt pf(rbuf_window()); base_ren_type ren_base(pf); ren_base.clear(agg::rgba(1, 1, 1)); agg::scanline_u8 sl; agg::rasterizer_scanline_aa<> ras; // Draw some background agg::ellipse ell; srand(1234); unsigned i; unsigned w = unsigned(width()); unsigned h = unsigned(height()); for (i = 0; i < 100; i++) { ell.init(rand() % w, rand() % h, rand() % 60 + 5, rand() % 60 + 5, 50); ras.add_path(ell); agg::render_scanlines_aa_solid( ras, sl, ren_base, agg::rgba(rand() / double(RAND_MAX), rand() / double(RAND_MAX), rand() / double(RAND_MAX), rand() / double(RAND_MAX) / 2.0)); } double parallelogram[6]; parallelogram[0] = m_x[0]; parallelogram[1] = m_y[0]; parallelogram[2] = m_x[1]; parallelogram[3] = m_y[1]; parallelogram[4] = m_x[2]; parallelogram[5] = m_y[2]; // Gradient shape function (linear, radial, custom, etc) //----------------- typedef agg::gradient_circle gradient_func_type; // Alpha gradient shape function (linear, radial, custom, etc) //----------------- typedef agg::gradient_xy gradient_alpha_func_type; // Span interpolator. This object is used in all span generators // that operate with transformations during iterating of the spans, // for example, image transformers use the interpolator too. //----------------- typedef agg::span_interpolator_linear<> interpolator_type; // Span allocator is an object that allocates memory for // the array of colors that will be used to render the // color spans. One object can be shared between different // span generators. //----------------- typedef agg::span_allocator<color_type> span_allocator_type; // Gradient colors array adaptor //----------------- typedef agg::pod_auto_array<color_type, 256> gradient_colors_type; // Finally, the gradient span generator working with the color_type // color type. //----------------- typedef agg::span_gradient<color_type, interpolator_type, gradient_func_type, gradient_colors_type> span_gradient_type; // Gradient alpha array adaptor //----------------- typedef agg::pod_auto_array<color_type::value_type, 256> gradient_alpha_type; // The alpha gradient span converter working with the color_type // color type. //----------------- typedef agg::span_gradient_alpha< color_type, interpolator_type, gradient_alpha_func_type, gradient_alpha_type> span_gradient_alpha_type; // Span converter type //----------------- typedef agg::span_converter<span_gradient_type, span_gradient_alpha_type> span_conv_type; // The gradient objects declarations //---------------- gradient_func_type gradient_func; // The gradient function gradient_alpha_func_type alpha_func; // The gradient function agg::trans_affine gradient_mtx; // Gradient affine transformer agg::trans_affine alpha_mtx; // Alpha affine transformer interpolator_type span_interpolator( gradient_mtx); // Span gradient interpolator interpolator_type span_interpolator_alpha( alpha_mtx); // Span alpha interpolator span_allocator_type span_allocator; // Span Allocator gradient_colors_type color_array; // The gradient colors // Declare the gradient span itself. // The last two arguments are so called "d1" and "d2" // defining two distances in pixels, where the gradient starts // and where it ends. The actual meaning of "d1" and "d2" depands // on the gradient function. //---------------- span_gradient_type span_gradient(span_interpolator, gradient_func, color_array, 0, 150); // Declare the gradient span itself. // The last two arguments are so called "d1" and "d2" // defining two distances in pixels, where the gradient starts // and where it ends. The actual meaning of "d1" and "d2" depands // on the gradient function. //---------------- gradient_alpha_type alpha_array; span_gradient_alpha_type span_gradient_alpha( span_interpolator_alpha, alpha_func, alpha_array, 0, 100); // Span converter declaration span_conv_type span_conv(span_gradient, span_gradient_alpha); // Finally we can draw a circle. //---------------- gradient_mtx *= agg::trans_affine_scaling(0.75, 1.2); gradient_mtx *= agg::trans_affine_rotation(-agg::pi / 3.0); gradient_mtx *= agg::trans_affine_translation(width() / 2, height() / 2); gradient_mtx.invert(); alpha_mtx.parl_to_rect(parallelogram, -100, -100, 100, 100); fill_color_array(color_array, agg::rgba(0, 0.19, 0.19), agg::rgba(0.7, 0.7, 0.19), agg::rgba(0.31, 0, 0)); // Fill Alpha array //---------------- for (i = 0; i < 256; i++) { alpha_array[i] = color_type::from_double(m_alpha.value(i / 255.0)); } ell.init(width() / 2, height() / 2, 150, 150, 100); ras.add_path(ell); // Render the circle with gradient plus alpha-gradient agg::render_scanlines_aa(ras, sl, ren_base, span_allocator, span_conv); // Draw the control points and the parallelogram //----------------- agg::rgba color_pnt(0, 0.4, 0.4, 0.31); ell.init(m_x[0], m_y[0], 5, 5, 20); ras.add_path(ell); agg::render_scanlines_aa_solid(ras, sl, ren_base, color_pnt); ell.init(m_x[1], m_y[1], 5, 5, 20); ras.add_path(ell); agg::render_scanlines_aa_solid(ras, sl, ren_base, color_pnt); ell.init(m_x[2], m_y[2], 5, 5, 20); ras.add_path(ell); agg::render_scanlines_aa_solid(ras, sl, ren_base, color_pnt); agg::vcgen_stroke stroke; stroke.add_vertex(m_x[0], m_y[0], agg::path_cmd_move_to); stroke.add_vertex(m_x[1], m_y[1], agg::path_cmd_line_to); stroke.add_vertex(m_x[2], m_y[2], agg::path_cmd_line_to); stroke.add_vertex(m_x[0] + m_x[2] - m_x[1], m_y[0] + m_y[2] - m_y[1], agg::path_cmd_line_to); stroke.add_vertex(0, 0, agg::path_cmd_end_poly | agg::path_flags_close); ras.add_path(stroke); agg::render_scanlines_aa_solid(ras, sl, ren_base, agg::rgba(0, 0, 0)); agg::render_ctrl(ras, sl, ren_base, m_alpha); }
virtual void on_draw() { pixfmt pixf(rbuf_window()); renderer_base rb(pixf); renderer_solid rs(rb); rb.clear(agg::rgba(1, 1, 1)); // When Gamma changes rebuild the gamma and gradient LUTs //------------------ if(m_old_gamma != m_gamma.value()) { m_gamma_lut.gamma(m_gamma.value()); build_gradient_lut(); m_old_gamma = m_gamma.value(); } // Gradient center. All gradient functions assume the // center being in the origin (0,0) and you can't // change it. But you can apply arbitrary transformations // to the gradient (see below). //------------------ double cx = initial_width() / 2; double cy = initial_height() / 2; double r = 100; // Focal center. Defined in the gradient coordinates, // that is, with respect to the origin (0,0) //------------------ double fx = m_mouse_x - cx; double fy = m_mouse_y - cy; gradient_func_type gradient_func(r, fx, fy); gradient_adaptor_type gradient_adaptor(gradient_func); agg::trans_affine gradient_mtx; // Making the affine matrix. Move to (cx,cy), // apply the resizing transformations and invert // the matrix. Gradients and images always assume the // inverse transformations. //------------------ gradient_mtx.translate(cx, cy); gradient_mtx *= trans_affine_resizing(); gradient_mtx.invert(); interpolator_type span_interpolator(gradient_mtx); span_gradient_type span_gradient(span_interpolator, gradient_adaptor, m_gradient_lut, 0, r); // Form the simple rectangle //------------------ m_rasterizer.reset(); m_rasterizer.move_to_d(0,0); m_rasterizer.line_to_d(width(), 0); m_rasterizer.line_to_d(width(), height()); m_rasterizer.line_to_d(0, height()); // Render the gradient to the whole screen and measure the time //------------------ start_timer(); agg::render_scanlines_aa(m_rasterizer, m_scanline, rb, m_alloc, span_gradient); double tm = elapsed_time(); // Draw the transformed circle that shows the gradient boundary //------------------ agg::ellipse e(cx, cy, r, r); agg::conv_stroke<agg::ellipse> estr(e); agg::conv_transform< agg::conv_stroke< agg::ellipse> > etrans(estr, trans_affine_resizing()); m_rasterizer.add_path(etrans); agg::render_scanlines_aa_solid(m_rasterizer, m_scanline, rb, agg::rgba(1,1,1)); // Show the gradient time //------------------ char buf[64]; agg::gsv_text t; t.size(10.0); agg::conv_stroke<agg::gsv_text> pt(t); pt.width(1.5); sprintf(buf, "%3.2f ms", tm); t.start_point(10.0, 35.0); t.text(buf); m_rasterizer.add_path(pt); agg::render_scanlines_aa_solid(m_rasterizer, m_scanline, rb, agg::rgba(0,0,0)); #if !LINEAR_RGB // Show the controls //------------------ agg::render_ctrl(m_rasterizer, m_scanline, rb, m_gamma); // Apply the inverse gamma to the whole buffer // (transform the colors to the perceptually uniform space) //------------------ pixf.apply_gamma_inv(m_gamma_lut); #endif }
virtual void on_draw() { double img_width = rbuf_img(0).width(); double img_height = rbuf_img(0).height(); typedef agg::pixfmt_bgr24 pixfmt; typedef agg::renderer_base<pixfmt> renderer_base; pixfmt pixf(rbuf_window()); pixfmt img_pixf(rbuf_img(0)); renderer_base rb(pixf); rb.clear(agg::rgba(1.0, 1.0, 1.0)); agg::trans_affine src_mtx; src_mtx *= agg::trans_affine_translation(-img_width/2, -img_height/2); src_mtx *= agg::trans_affine_rotation(m_angle.value() * agg::pi / 180.0); src_mtx *= agg::trans_affine_translation(img_width/2 + 10, img_height/2 + 10 + 40); src_mtx *= trans_affine_resizing(); agg::trans_affine img_mtx; img_mtx *= agg::trans_affine_translation(-img_width/2, -img_height/2); img_mtx *= agg::trans_affine_rotation(m_angle.value() * agg::pi / 180.0); img_mtx *= agg::trans_affine_scaling(m_scale.value()); img_mtx *= agg::trans_affine_translation(img_width/2 + 10, img_height/2 + 10 + 40); img_mtx *= trans_affine_resizing(); img_mtx.invert(); typedef agg::span_allocator<agg::rgba8> span_alloc_type; span_alloc_type sa; typedef agg::span_interpolator_adaptor<agg::span_interpolator_linear<>, periodic_distortion> interpolator_type; periodic_distortion* dist = 0; distortion_wave dist_wave; distortion_swirl dist_swirl; distortion_wave_swirl dist_wave_swirl; distortion_swirl_wave dist_swirl_wave; switch(m_distortion.cur_item()) { case 0: dist = &dist_wave; break; case 1: dist = &dist_swirl; break; case 2: dist = &dist_wave_swirl; break; case 3: dist = &dist_swirl_wave; break; } dist->period(m_period.value()); dist->amplitude(m_amplitude.value()); dist->phase(m_phase); double cx = m_center_x; double cy = m_center_y; img_mtx.transform(&cx, &cy); dist->center(cx, cy); interpolator_type interpolator(img_mtx, *dist); typedef agg::image_accessor_clip<pixfmt> img_source_type; img_source_type img_src(img_pixf, agg::rgba(1,1,1)); /* // Version without filtering (nearest neighbor) //------------------------------------------ typedef agg::span_image_filter_rgb_nn<img_source_type, interpolator_type> span_gen_type; span_gen_type sg(img_src, interpolator); //------------------------------------------ */ // Version with "hardcoded" bilinear filter and without // image_accessor (direct filter, the old variant) //------------------------------------------ typedef agg::span_image_filter_rgb_bilinear_clip<pixfmt, interpolator_type> span_gen_type; span_gen_type sg(img_pixf, agg::rgba(1,1,1), interpolator); //------------------------------------------ /* // Version with arbitrary 2x2 filter //------------------------------------------ typedef agg::span_image_filter_rgb_2x2<img_source_type, interpolator_type> span_gen_type; agg::image_filter<agg::image_filter_kaiser> filter; span_gen_type sg(img_src, interpolator, filter); //------------------------------------------ */ /* // Version with arbitrary filter //------------------------------------------ typedef agg::span_image_filter_rgb<img_source_type, interpolator_type> span_gen_type; agg::image_filter<agg::image_filter_spline36> filter; span_gen_type sg(img_src, interpolator, filter); //------------------------------------------ */ agg::rasterizer_scanline_aa<> ras; agg::scanline_u8 sl; double r = img_width; if(img_height < r) r = img_height; agg::ellipse ell(img_width / 2.0, img_height / 2.0, r / 2.0 - 20.0, r / 2.0 - 20.0, 200); agg::conv_transform<agg::ellipse> tr(ell, src_mtx); ras.add_path(tr); agg::render_scanlines_aa(ras, sl, rb, sa, sg); src_mtx *= ~trans_affine_resizing(); src_mtx *= agg::trans_affine_translation(img_width - img_width/10, 0.0); src_mtx *= trans_affine_resizing(); ras.add_path(tr); agg::render_scanlines_aa_solid(ras, sl, rb, agg::rgba8(0,0,0)); typedef agg::span_gradient<agg::rgba8, interpolator_type, agg::gradient_circle, color_array_type> gradient_span_gen; agg::gradient_circle gradient_function; color_array_type gradient_colors(m_gradient_colors); gradient_span_gen span_gradient(interpolator, gradient_function, gradient_colors, 0, 180); agg::trans_affine gr1_mtx; gr1_mtx *= agg::trans_affine_translation(-img_width/2, -img_height/2); gr1_mtx *= agg::trans_affine_scaling(0.8); gr1_mtx *= agg::trans_affine_rotation(m_angle.value() * agg::pi / 180.0); gr1_mtx *= agg::trans_affine_translation(img_width - img_width/10 + img_width/2 + 10, img_height/2 + 10 + 40); gr1_mtx *= trans_affine_resizing(); agg::trans_affine gr2_mtx; gr2_mtx *= agg::trans_affine_rotation(m_angle.value() * agg::pi / 180.0); gr2_mtx *= agg::trans_affine_scaling(m_scale.value()); gr2_mtx *= agg::trans_affine_translation(img_width - img_width/10 + img_width/2 + 10 + 50, img_height/2 + 10 + 40 + 50); gr2_mtx *= trans_affine_resizing(); gr2_mtx.invert(); cx = m_center_x + img_width - img_width/10; cy = m_center_y; gr2_mtx.transform(&cx, &cy); dist->center(cx, cy); interpolator.transformer(gr2_mtx); agg::conv_transform<agg::ellipse> tr2(ell, gr1_mtx); ras.add_path(tr2); agg::render_scanlines_aa(ras, sl, rb, sa, span_gradient); agg::render_ctrl(ras, sl, rb, m_angle); agg::render_ctrl(ras, sl, rb, m_scale); agg::render_ctrl(ras, sl, rb, m_amplitude); agg::render_ctrl(ras, sl, rb, m_period); agg::render_ctrl(ras, sl, rb, m_distortion); }