예제 #1
0
    the_application(agg::pix_format_e format, bool flip_y) :
        agg::platform_support(format, flip_y),
        m_polygons (5.0,     5.0, 5.0+205.0,  110.0,  !flip_y),
        m_operation(555.0,   5.0, 555.0+80.0, 55.0,  !flip_y),
        m_alpha_buf(0),
        m_alpha_mask_rbuf(),
        m_alpha_mask(m_alpha_mask_rbuf),
        m_x(0),
        m_y(0)
    {
        m_operation.add_item("AND");
        m_operation.add_item("SUB");
        m_operation.cur_item(0);
        add_ctrl(m_operation);
        m_operation.no_transform();

        m_polygons.add_item("Two Simple Paths");
        m_polygons.add_item("Closed Stroke");
        m_polygons.add_item("Great Britain and Arrows");
        m_polygons.add_item("Great Britain and Spiral");
        m_polygons.add_item("Spiral and Glyph");
        m_polygons.cur_item(3);
        add_ctrl(m_polygons);
        m_polygons.no_transform();
    }
예제 #2
0
    void perform_rendering(Scanline &sl, Ras &ras, Ren &ren, Clp &clp)
    {
        if(m_operation.cur_item() > 0)
        {
            ras.reset();
            switch(m_operation.cur_item())
            {
                case 1: clp.operation(agg::clipper_or);           break;
                case 2: clp.operation(agg::clipper_and);          break;
                case 3: clp.operation(agg::clipper_xor);          break;
                case 4: clp.operation(agg::clipper_a_minus_b);    break;
                case 5: clp.operation(agg::clipper_b_minus_a);    break;
            }
            agg::conv_poly_counter<Clp> counter(clp);


            start_timer();
            counter.rewind(0);
            double t1 = elapsed_time();

            ras.reset();
            double x;
            double y;
            unsigned cmd;
            start_timer();
            while(!agg::is_stop(cmd = counter.vertex(&x, &y)))
            {
                ras.add_vertex(x, y, cmd);
            }

            ren.color(agg::rgba(0.5, 0.0, 0, 0.5));
            agg::render_scanlines(ras, sl, ren);
            double t2 = elapsed_time();

            char buf[100];
            sprintf_s(buf, "Contours: %d      Points: %d", counter.m_contours, counter.m_points);
            agg::gsv_text txt;
            agg::conv_stroke<agg::gsv_text> txt_stroke(txt);
            txt_stroke.width(1.5);
            txt_stroke.line_cap(agg::round_cap);
            txt.size(10.0);
            txt.start_point(250, 5);
            txt.text(buf);
            ras.add_path(txt_stroke);
            ren.color(agg::rgba(0.0, 0.0, 0.0));
            agg::render_scanlines(ras, sl, ren);

            sprintf_s(buf, "Clipper=%.3fms Render=%.3fms", t1, t2);
            txt.start_point(250, 20);
            txt.text(buf);
            ras.add_path(txt_stroke);
            ren.color(agg::rgba(0.0, 0.0, 0.0));
            agg::render_scanlines(ras, sl, ren);
        }
    }
예제 #3
0
    template<class VertexSource> void generate_alpha_mask(VertexSource& vs)
    {
        unsigned cx = (unsigned)width();
        unsigned cy = (unsigned)height();

        delete [] m_alpha_buf;
        m_alpha_buf = new unsigned char[cx * cy];
        m_alpha_mask_rbuf.attach(m_alpha_buf, cx, cy, cx);

        typedef agg::renderer_base<agg::pixfmt_gray8> ren_base;
        typedef agg::renderer_scanline_aa_solid<ren_base> renderer;

        agg::pixfmt_gray8 pixf(m_alpha_mask_rbuf);
        ren_base rb(pixf);
        renderer ren(rb);

        start_timer();
        if(m_operation.cur_item() == 0)
        {
            rb.clear(agg::gray8(0));
            ren.color(agg::gray8(255));
        }
        else 
        {
            rb.clear(agg::gray8(255));
            ren.color(agg::gray8(0));
        }
        m_ras.add_path(vs);
        agg::render_scanlines(m_ras, m_sl, ren);
        double t1 = elapsed_time();

        char buf[100];
        sprintf(buf, "Generate AlphaMask: %.3fms", t1);
        draw_text(250, 20, buf);
    }
예제 #4
0
    the_application(agg::pix_format_e format, bool flip_y) :
        agg::platform_support(format, flip_y),
        m_step  (115,  5,    400, 11,     !flip_y),
        m_radius(115,  5+15, 400, 11+15,  !flip_y),
        m_filters(0.0, 0.0, 110.0, 210.0, !flip_y),
        m_normalize  (8.0, 215.0, "Normalize Filter", !flip_y),
        m_run        (8.0, 245.0, "RUN Test!", !flip_y),
        m_single_step(8.0, 230.0, "Single Step", !flip_y),
        m_refresh    (8.0, 265.0, "Refresh", !flip_y),
        m_cur_angle(0.0),
        m_cur_filter(1),
        m_num_steps(0),
        m_num_pix(0.0),
        m_time1(0),
        m_time2(0)
    {
        add_ctrl(m_radius);
        add_ctrl(m_step);
        add_ctrl(m_filters);
        add_ctrl(m_run);
        add_ctrl(m_single_step);
        add_ctrl(m_normalize);
        add_ctrl(m_refresh);
        m_run.text_size(7.5);
        m_single_step.text_size(7.5);
        m_normalize.text_size(7.5);
        m_refresh.text_size(7.5);
        m_normalize.status(true);

        m_radius.label("Filter Radius=%.3f");
        m_step.label("Step=%3.2f");
        m_radius.range(2.0, 8.0);
        m_radius.value(4.0);
        m_step.range(1.0, 10.0);
        m_step.value(5.0);

        m_filters.add_item("simple (NN)");
        m_filters.add_item("bilinear");
        m_filters.add_item("bicubic");
        m_filters.add_item("spline16");
        m_filters.add_item("spline36");
        m_filters.add_item("hanning");
        m_filters.add_item("hamming");
        m_filters.add_item("hermite");
        m_filters.add_item("kaiser");
        m_filters.add_item("quadric");
        m_filters.add_item("catrom");
        m_filters.add_item("gaussian");
        m_filters.add_item("bessel");
        m_filters.add_item("mitchell");
        m_filters.add_item("sinc");
        m_filters.add_item("lanczos");
        m_filters.add_item("blackman");
        m_filters.cur_item(1);

        m_filters.border_width(0, 0);
        m_filters.background_color(agg::rgba(0.0, 0.0, 0.0, 0.1));
        m_filters.text_size(6.0);
        m_filters.text_thickness(0.85);
    }
예제 #5
0
    the_application(agg::pix_format_e format, bool flip_y) :
        agg::platform_support(format, flip_y),
        m_gamma_lut(2.0),
        m_quad(4, 5.0),
        m_trans_type(400, 5.0, 430+170.0, 100.0, !flip_y),
        m_gamma(5.0, 5.0+15*0, 400-5, 10.0+15*0, !flip_y),
        m_blur (5.0, 5.0+15*1, 400-5, 10.0+15*1, !flip_y),
        m_old_gamma(2.0)
    {
        m_trans_type.text_size(7);
        m_trans_type.add_item("Affine No Resample");
        m_trans_type.add_item("Affine Resample");
        m_trans_type.add_item("Perspective No Resample LERP");
        m_trans_type.add_item("Perspective No Resample Exact");
        m_trans_type.add_item("Perspective Resample LERP");
        m_trans_type.add_item("Perspective Resample Exact");
        m_trans_type.cur_item(4);
        add_ctrl(m_trans_type);

        m_gamma.range(0.5, 3.0);
        m_gamma.value(2.0);
        m_gamma.label("Gamma=%.3f");
        add_ctrl(m_gamma);

        m_blur.range(0.5, 5.0);
        m_blur.value(1.0);
        m_blur.label("Blur=%.3f");
        add_ctrl(m_blur);
    }
예제 #6
0
 the_application(agg::pix_format_e format, bool flip_y) :
     agg::platform_support(format, flip_y),
     m_quad1(4, 5.0),
     m_quad2(4, 5.0),
     m_trans_type(420, 5.0, 420+130.0, 145.0, !flip_y),
     m_reset     (350, 5.0,  "Reset", !flip_y),
     m_mul1      (5.0,  5.0, 340.0, 12.0, !flip_y),
     m_mul2      (5.0, 20.0, 340.0, 27.0, !flip_y)
 {
     m_trans_type.add_item("Union");
     m_trans_type.add_item("Intersection");
     m_trans_type.add_item("Linear XOR");
     m_trans_type.add_item("Saddle XOR");
     m_trans_type.add_item("Abs Diff XOR");
     m_trans_type.add_item("A-B");
     m_trans_type.add_item("B-A");
     m_trans_type.cur_item(0);
     add_ctrl(m_trans_type);
     add_ctrl(m_reset);
     add_ctrl(m_mul1);
     add_ctrl(m_mul2);
     m_mul1.value(1.0);
     m_mul2.value(1.0);
     m_mul1.label("Opacity1=%.3f");
     m_mul2.label("Opacity2=%.3f");
 }
예제 #7
0
파일: conv_stroke.cpp 프로젝트: UIKit0/agg
  the_application(agg::pix_format_e format, bool flip_y)
      : agg::platform_support(format, flip_y),
        m_idx(-1),
        m_join(10.0, 10.0, 133.0, 80.0, !flip_y),
        m_cap(10.0, 80.0 + 10.0, 133.0, 80.0 + 80.0, !flip_y),
        m_width(130 + 10.0, 10.0 + 4.0, 500.0 - 10.0, 10.0 + 8.0 + 4.0,
                !flip_y),
        m_miter_limit(130 + 10.0, 20.0 + 10.0 + 4.0, 500.0 - 10.0,
                      20.0 + 10.0 + 8.0 + 4.0, !flip_y) {
    m_x[0] = 57 + 100;
    m_y[0] = 60;
    m_x[1] = 369 + 100;
    m_y[1] = 170;
    m_x[2] = 143 + 100;
    m_y[2] = 310;

    add_ctrl(m_join);
    m_join.text_size(7.5);
    m_join.text_thickness(1.0);
    m_join.add_item("Miter Join");
    m_join.add_item("Miter Join Revert");
    m_join.add_item("Round Join");
    m_join.add_item("Bevel Join");
    m_join.cur_item(2);

    add_ctrl(m_cap);
    m_cap.add_item("Butt Cap");
    m_cap.add_item("Square Cap");
    m_cap.add_item("Round Cap");
    m_cap.cur_item(2);

    add_ctrl(m_width);
    m_width.range(3.0, 40.0);
    m_width.value(20.0);
    m_width.label("Width=%1.2f");

    add_ctrl(m_miter_limit);
    m_miter_limit.range(1.0, 10.0);
    m_miter_limit.value(4.0);
    m_miter_limit.label("Miter Limit=%1.2f");

    m_join.no_transform();
    m_cap.no_transform();
    m_width.no_transform();
    m_miter_limit.no_transform();
  }
예제 #8
0
파일: graph_test.cpp 프로젝트: Bashakov/agg
    //------------------------------------------------------------------------
    void draw_scene(scanline_rasterizer& ras, 
                    solid_renderer& solid,
                    draft_renderer& draft)
    {
        ras.gamma(agg::gamma_none());
        srand(100);
        if(m_draw_nodes.status())
        {
            if(m_draft.status())
            {
                draw_nodes_draft();
            }
            else
            {
                draw_nodes_fine(ras);
            }
        }

        if(m_draw_edges.status())
        {
            if(m_draft.status()) 
            {
                switch(m_type.cur_item())
                {
                case 0: draw_lines_draft();    break;
                case 1: draw_curves_draft();   break;
                case 2: draw_dashes_draft();   break;
                }
            }
            else
            {
                switch(m_type.cur_item())
                {
                case 0: draw_lines_fine(ras, solid, draft);  break;
                case 1: draw_curves_fine(ras, solid, draft); break;
                case 2: draw_dashes_fine(ras, solid, draft); break;
                case 3: 
                case 4: draw_polygons(ras, solid, draft);    break;
                }
            }
        }
    }
예제 #9
0
    void on_ctrl_change()
    {
        if(m_single_step.status())
        {
            m_cur_angle += m_step.value();
            copy_img_to_img(1, 0);
            transform_image(m_step.value());
            m_num_steps++;
            force_redraw();
            m_single_step.status(false);
        }

        if(m_run.status())
        {
#ifdef AGG_ACCURATE_TIME
            start_timer();
            m_time1 = m_time2 = elapsed_time();
#else
            m_time1 = m_time2 = clock();
#endif
            m_num_pix = 0.0;
            wait_mode(false);
        }
        if(m_refresh.status() || m_filters.cur_item() != m_cur_filter)
        {
#ifdef AGG_ACCURATE_TIME
            start_timer();
            m_time1 = m_time2 = 0;
#else
            m_time1 = m_time2 = clock();
#endif
            m_num_pix = 0.0;
            m_cur_angle = 0.0;
            copy_img_to_img(1, 2);
            transform_image(0.0);
            m_refresh.status(false);
            m_cur_filter = m_filters.cur_item();
            m_num_steps = 0;
            force_redraw();
        }
    }
예제 #10
0
    the_application(agg::pix_format_e format, bool flip_y) :
        agg::platform_support(format, flip_y),
        m_polygons     (5.0,     5.0, 5.0+205.0,   110.0,  !flip_y),
        m_fill_rule    (200,     5.0, 200+105.0,    50.0,  !flip_y),
        m_scanline_type(300,     5.0, 300+115.0,    70.0,  !flip_y),
        m_operation    (535.0,   5.0, 535.0+115.0, 145.0,  !flip_y)
    {
        m_operation.add_item("None");
        m_operation.add_item("OR");
        m_operation.add_item("AND");
        m_operation.add_item("XOR Linear");
        m_operation.add_item("XOR Saddle");
        m_operation.add_item("A-B");
        m_operation.add_item("B-A");
        m_operation.cur_item(2);
        add_ctrl(m_operation);
        m_operation.no_transform();

        m_fill_rule.add_item("Even-Odd");
        m_fill_rule.add_item("Non Zero");
        m_fill_rule.cur_item(1);
        add_ctrl(m_fill_rule);
        m_fill_rule.no_transform();

        m_scanline_type.add_item("scanline_p");
        m_scanline_type.add_item("scanline_u");
        m_scanline_type.add_item("scanline_bin");
        m_scanline_type.cur_item(1);
        add_ctrl(m_scanline_type);
        m_scanline_type.no_transform();

        m_polygons.add_item("Two Simple Paths");
        m_polygons.add_item("Closed Stroke");
        m_polygons.add_item("Great Britain and Arrows");
        m_polygons.add_item("Great Britain and Spiral");
        m_polygons.add_item("Spiral and Glyph");
        m_polygons.cur_item(3);
        add_ctrl(m_polygons);
        m_polygons.no_transform();
    }
예제 #11
0
    void compose_path()
    {
        unsigned flag = 0;
        if (m_close.cur_item() == 1) flag = agg::path_flags_cw;
        if (m_close.cur_item() == 2) flag = agg::path_flags_ccw;

        m_path.remove_all();
        m_path.move_to(28.47, 6.45);
        m_path.curve3(21.58, 1.12, 19.82, 0.29);
        m_path.curve3(17.19, -0.93, 14.21, -0.93);
        m_path.curve3(9.57, -0.93, 6.57, 2.25);
        m_path.curve3(3.56, 5.42, 3.56, 10.60);
        m_path.curve3(3.56, 13.87, 5.03, 16.26);
        m_path.curve3(7.03, 19.58, 11.99, 22.51);
        m_path.curve3(16.94, 25.44, 28.47, 29.64);
        m_path.line_to(28.47, 31.40);
        m_path.curve3(28.47, 38.09, 26.34, 40.58);
        m_path.curve3(24.22, 43.07, 20.17, 43.07);
        m_path.curve3(17.09, 43.07, 15.28, 41.41);
        m_path.curve3(13.43, 39.75, 13.43, 37.60);
        m_path.line_to(13.53, 34.77);
        m_path.curve3(13.53, 32.52, 12.38, 31.30);
        m_path.curve3(11.23, 30.08, 9.38, 30.08);
        m_path.curve3(7.57, 30.08, 6.42, 31.35);
        m_path.curve3(5.27, 32.62, 5.27, 34.81);
        m_path.curve3(5.27, 39.01, 9.57, 42.53);
        m_path.curve3(13.87, 46.04, 21.63, 46.04);
        m_path.curve3(27.59, 46.04, 31.40, 44.04);
        m_path.curve3(34.28, 42.53, 35.64, 39.31);
        m_path.curve3(36.52, 37.21, 36.52, 30.71);
        m_path.line_to(36.52, 15.53);
        m_path.curve3(36.52, 9.13, 36.77, 7.69);
        m_path.curve3(37.01, 6.25, 37.57, 5.76);
        m_path.curve3(38.13, 5.27, 38.87, 5.27);
        m_path.curve3(39.65, 5.27, 40.23, 5.62);
        m_path.curve3(41.26, 6.25, 44.19, 9.18);
        m_path.line_to(44.19, 6.45);
        m_path.curve3(38.72, -0.88, 33.74, -0.88);
        m_path.curve3(31.35, -0.88, 29.93, 0.78);
        m_path.curve3(28.52, 2.44, 28.47, 6.45);
        m_path.close_polygon(flag);

        m_path.move_to(28.47, 9.62);
        m_path.line_to(28.47, 26.66);
        m_path.curve3(21.09, 23.73, 18.95, 22.51);
        m_path.curve3(15.09, 20.36, 13.43, 18.02);
        m_path.curve3(11.77, 15.67, 11.77, 12.89);
        m_path.curve3(11.77, 9.38, 13.87, 7.06);
        m_path.curve3(15.97, 4.74, 18.70, 4.74);
        m_path.curve3(22.41, 4.74, 28.47, 9.62);
        m_path.close_polygon(flag);
    }
예제 #12
0
    virtual void on_draw()
    {
        pixfmt pixf(rbuf_window());
        renderer_base rb(pixf);
        renderer_solid rs(rb);

        rb.clear(agg::rgba(1.0, 1.0, 1.0));
        rb.copy_from(rbuf_img(0), 0, 110, 35);

        agg::rasterizer_scanline_aa<> ras;
        agg::scanline_p8 sl;

        char buf[64]; 
        sprintf(buf, "NSteps=%d", m_num_steps);
        agg::gsv_text t;
        t.start_point(10.0, 295.0);
        t.size(10.0);
        t.text(buf);

        agg::conv_stroke<agg::gsv_text> pt(t);
        pt.width(1.5);

        ras.add_path(pt);
        rs.color(agg::rgba(0,0,0));
        agg::render_scanlines(ras, sl, rs);

        if(m_time1 != m_time2 && m_num_pix > 0.0)
        {
#ifdef AGG_ACCURATE_TIME
            sprintf(buf, "%3.2f Kpix/sec", m_num_pix / (m_time2 - m_time1));
#else
            sprintf(buf, "%3.2f Kpix/sec", m_num_pix / 
                                          1000.0 /
                                          (double(m_time2 - m_time1) / CLOCKS_PER_SEC));
#endif
            t.start_point(10.0, 310.0);
            t.text(buf);
            ras.add_path(pt);
            agg::render_scanlines(ras, sl, rs);
        }

        if(m_filters.cur_item() >= 14)
        {
            agg::render_ctrl(ras, sl, rs, m_radius);
        }
        agg::render_ctrl(ras, sl, rs, m_step);
        agg::render_ctrl(ras, sl, rs, m_filters);
        agg::render_ctrl(ras, sl, rs, m_run);
        agg::render_ctrl(ras, sl, rs, m_normalize);
        agg::render_ctrl(ras, sl, rs, m_single_step);
        agg::render_ctrl(ras, sl, rs, m_refresh);
    }
예제 #13
0
    the_application(agg::pix_format_e format, bool flip_y) :
        agg::platform_support(format, flip_y),
        m_polygons (5.0,     5.0, 5.0+205.0,  110.0,  !flip_y),
        m_operation(555.0,   5.0, 555.0+80.0, 130.0,  !flip_y)
    {
        m_operation.add_item("None");
        m_operation.add_item("OR");
        m_operation.add_item("AND");
        m_operation.add_item("XOR");
        m_operation.add_item("A-B");
        m_operation.add_item("B-A");
        m_operation.cur_item(2);
        add_ctrl(m_operation);

        m_polygons.add_item("Two Simple Paths");
        m_polygons.add_item("Closed Stroke");
        m_polygons.add_item("Great Britain and Arrows");
        m_polygons.add_item("Great Britain and Spiral");
        m_polygons.add_item("Spiral and Glyph");
        m_polygons.cur_item(3);
        add_ctrl(m_polygons);
    }
예제 #14
0
 the_application(agg::pix_format_e format, bool flip_y) :
     agg::platform_support(format, flip_y),
     m_quad(4, 5.0),
     m_trans_type(460, 5.0, 420+170.0, 60.0, !flip_y),
     m_test_flag(false)
 {
     m_trans_type.text_size(8);
     m_trans_type.text_thickness(1);
     m_trans_type.add_item("Affine");
     m_trans_type.add_item("Bilinear");
     m_trans_type.add_item("Perspective");
     m_trans_type.cur_item(2);
     add_ctrl(m_trans_type);
 }
예제 #15
0
파일: graph_test.cpp 프로젝트: Bashakov/agg
    the_application(agg::pix_format_e format, bool flip_y) :
        agg::platform_support(format, flip_y),
        m_type(-1, -1, -1, -1, !flip_y),
        m_width(110+80, 8.0, 110+200.0+80, 8.0 + 7.0, !flip_y),
        m_benchmark(110+200+80+8, 8.0-2.0, "Benchmark", !flip_y),
        m_draw_nodes(110+200+80+8, 8.0-2.0+15.0, "Draw Nodes", !flip_y),
        m_draw_edges(200+200+80+8, 8.0-2.0+15.0, "Draw Edges", !flip_y),
        m_draft(200+200+80+8, 8.0-2.0, "Draft Mode", !flip_y),
        m_translucent(110+80, 8.0-2.0+15.0, "Translucent Mode", !flip_y),
        m_graph(200, 100),
        m_gradient_colors(),
        m_draw(3)
    {
        add_ctrl(m_type);
        m_type.text_size(8.0);
        m_type.add_item("Solid lines");
        m_type.add_item("Bezier curves");
        m_type.add_item("Dashed curves");
        m_type.add_item("Poygons AA");
        m_type.add_item("Poygons Bin");
        m_type.cur_item(0);

        add_ctrl(m_width);
        m_width.num_steps(20);
        m_width.range(0.0, 5.0);
        m_width.value(2.0);
        m_width.label("Width=%1.2f");

        m_benchmark.text_size(8.0);
        m_draw_nodes.text_size(8.0);
        m_draft.text_size(8.0);
        m_draw_nodes.status(true);
        m_draw_edges.status(true);
        add_ctrl(m_benchmark);
        add_ctrl(m_draw_nodes);
        add_ctrl(m_draw_edges);
        add_ctrl(m_draft);
        add_ctrl(m_translucent);

        agg::rgba c1(1, 1, 0, 0.25);
        agg::rgba c2(0, 0, 1);

        int i;
        for(i = 0; i < 256; i++)
        {
            m_gradient_colors[i] = c1.gradient(c2, double(i) / 255.0);
        }
    }
예제 #16
0
파일: graph_test.cpp 프로젝트: Bashakov/agg
    void render_edge_fine(scanline_rasterizer& ras, 
                          solid_renderer& ren_fine,
                          draft_renderer& ren_draft,
                          Source& src)
    {
        double x, y;
        switch(m_draw)
        {
            case 0:
                src.rewind(0);
                while(!agg::is_stop(src.vertex(&x, &y)));
            break;

            case 1:
                ras.reset();
                ras.add_path(src);
            break;

            case 2:
                ras.reset();
                ras.add_path(src);
                ras.sort();
            break;

            case 3:
            {
                int r = rand() & 0x7F;
                int g = rand() & 0x7F;
                int b = rand() & 0x7F;
                int a = 255;
                if(m_translucent.status()) a = 80;
                ras.add_path(src);

                if(m_type.cur_item() < 4)
                {
                    ren_fine.color(agg::srgba8(r, g, b, a));
                    agg::render_scanlines(ras, m_sl, ren_fine);
                }
                else
                {
                    ren_draft.color(agg::srgba8(r, g, b, a));
                    agg::render_scanlines(ras, m_sl, ren_draft);
                }
            }
            break;
        }
    }
예제 #17
0
    the_application(agg::pix_format_e format, bool flip_y) :
        agg::platform_support(format, flip_y),
        m_alpha_dst(5, 5,    400, 11,    !flip_y),
        m_alpha_src(5, 5+15, 400, 11+15, !flip_y),
        m_comp_op(420, 5.0, 420+170.0, 395.0, !flip_y)
    {
        m_alpha_dst.label("Dst Alpha=%.2f");
        m_alpha_dst.value(1.0);
        add_ctrl(m_alpha_dst);

        m_alpha_src.label("Src Alpha=%.2f");
        m_alpha_src.value(1.0);
        add_ctrl(m_alpha_src);

        m_comp_op.text_size(6.8);
        m_comp_op.add_item("clear");
        m_comp_op.add_item("src");
        m_comp_op.add_item("dst");
        m_comp_op.add_item("src-over");
        m_comp_op.add_item("dst-over");
        m_comp_op.add_item("src-in");
        m_comp_op.add_item("dst-in");
        m_comp_op.add_item("src-out");
        m_comp_op.add_item("dst-out");
        m_comp_op.add_item("src-atop");
        m_comp_op.add_item("dst-atop");
        m_comp_op.add_item("xor");
        m_comp_op.add_item("plus");
        m_comp_op.add_item("minus");
        m_comp_op.add_item("multiply");
        m_comp_op.add_item("screen");
        m_comp_op.add_item("overlay");
        m_comp_op.add_item("darken");
        m_comp_op.add_item("lighten");
        m_comp_op.add_item("color-dodge");
        m_comp_op.add_item("color-burn");
        m_comp_op.add_item("hard-light");
        m_comp_op.add_item("soft-light");
        m_comp_op.add_item("difference");
        m_comp_op.add_item("exclusion");
        m_comp_op.add_item("contrast");
        m_comp_op.add_item("invert");
        m_comp_op.add_item("invert-rgb");
        m_comp_op.cur_item(3);
        add_ctrl(m_comp_op);
    }
예제 #18
0
    the_application(agg::pix_format_e format, bool flip_y) :
        agg::platform_support(format, flip_y),
        m_angle     (5,      5,    150,     12,    !flip_y),
        m_scale     (5,      5+15, 150,     12+15, !flip_y),
        m_period    (5+170,  5,    150+170, 12,    !flip_y),
        m_amplitude (5+170,  5+15, 150+170, 12+15, !flip_y),
        m_distortion(480,    5,    600,     90,    !flip_y),

        m_center_x(0.0),
        m_center_y(0.0),
        m_phase(0.0)
    {
        add_ctrl(m_angle);
        add_ctrl(m_scale);
        add_ctrl(m_amplitude);
        add_ctrl(m_period);
        add_ctrl(m_distortion);
        m_angle.label("Angle=%3.2f");
        m_scale.label("Scale=%3.2f");
        m_angle.range(-180.0, 180.0);
        m_angle.value(20.0);
        m_scale.range(0.1, 5.0);
        m_scale.value(1.0);

        m_amplitude.label("Amplitude=%3.2f");
        m_period.label("Period=%3.2f");
        m_amplitude.range(0.1, 40.0);
        m_period.range(0.1, 2.0);
        m_amplitude.value(10.0);
        m_period.value(1.0);

        m_distortion.add_item("Wave");
        m_distortion.add_item("Swirl");
        m_distortion.add_item("Wave-Swirl");
        m_distortion.add_item("Swirl-Wave");
        m_distortion.cur_item(0);

        unsigned i;
        const agg::int8u* p = g_gradient_colors;
        for(i = 0; i < 256; i++)
        {
            m_gradient_colors[i] = agg::rgba8(p[0], p[1], p[2], p[3]);
            p += 4;
        }
    }
예제 #19
0
    the_application(agg::pix_format_e format, bool flip_y) :
        agg::platform_support(format, flip_y),
        m_close      (10.0, 10.0, 130.0, 80.0, !flip_y),
        m_width      (130 + 10.0, 10.0 + 4.0, 130 + 300.0, 10.0 + 8.0 + 4.0, !flip_y),
        m_auto_detect(130 + 10.0, 10.0 + 4.0 + 16.0,    "Autodetect orientation if not defined", !flip_y)
    {
        add_ctrl(m_close);
        m_close.add_item("Close");
        m_close.add_item("Close CW");
        m_close.add_item("Close CCW");
        m_close.cur_item(0);

        add_ctrl(m_width);
        m_width.range(-100.0, 100.0);
        m_width.value(0.0);
        m_width.label("Width=%1.2f");

        add_ctrl(m_auto_detect);
    }
예제 #20
0
파일: graph_test.cpp 프로젝트: Bashakov/agg
 //------------------------------------------------------------------------
 void draw_polygons(scanline_rasterizer& ras, 
                    solid_renderer& solid,
                    draft_renderer& draft)
 {
     int i;
     if(m_type.cur_item() == 4)
     {
         ras.gamma(agg::gamma_threshold(0.5));
     }
     for(i = 0; i < m_graph.get_num_edges(); i++)
     {
         graph::edge b  = m_graph.get_edge(i);
         graph::node n1 = m_graph.get_node(b.node1, width(), height());
         graph::node n2 = m_graph.get_node(b.node2, width(), height());
         curve c(n1.x, n1.y, n2.x, n2.y);
         render_edge_fine(ras, solid, draft, c);
     }
     ras.gamma(agg::gamma_none());
 }
예제 #21
0
    the_application(agg::pix_format_e format, bool flip_y) :
        agg::platform_support(format, flip_y),
        m_quad(4, 5.0),
        m_trans_type(420, 5.0, 420+130.0, 55.0, !flip_y)
    {
        parse_lion();
        m_quad.xn(0) = g_x1;
        m_quad.yn(0) = g_y1;
        m_quad.xn(1) = g_x2;
        m_quad.yn(1) = g_y1;
        m_quad.xn(2) = g_x2;
        m_quad.yn(2) = g_y2;
        m_quad.xn(3) = g_x1;
        m_quad.yn(3) = g_y2;

        m_trans_type.add_item("Bilinear");
        m_trans_type.add_item("Perspective");
        m_trans_type.cur_item(0);
        add_ctrl(m_trans_type);
    }
예제 #22
0
    template<class RenBase> void render_scene(RenBase& rb)
    {
        typedef agg::comp_op_adaptor_rgba<color, order> blender_type;
        typedef agg::pixfmt_custom_blend_rgba<blender_type, agg::rendering_buffer> pixfmt_type;
        typedef agg::renderer_base<pixfmt_type> renderer_type;

        pixfmt_type pixf(rbuf_window());
        renderer_type ren(pixf);


        pixf.comp_op(agg::comp_op_difference);
        radial_shape(ren, m_ramp1, 50, 50, 50+320, 50+320);

        pixf.comp_op(m_comp_op.cur_item());
        double cx = 50;
        double cy = 50;
        radial_shape(ren, m_ramp2, cx+120-70, cy+120-70, cx+120+70, cy+120+70);
        radial_shape(ren, m_ramp2, cx+200-70, cy+120-70, cx+200+70, cy+120+70);
        radial_shape(ren, m_ramp2, cx+120-70, cy+200-70, cx+120+70, cy+200+70); 
        radial_shape(ren, m_ramp2, cx+200-70, cy+200-70, cx+200+70, cy+200+70);
    }
예제 #23
0
    //------------------------------------------------------------------------
    the_application(agg::pix_format_e format, bool flip_y) :
        agg::platform_support(format, flip_y),
        m_polygon_angle(5,  5,      145, 11,    !flip_y),
        m_polygon_scale(5,  5+14,   145, 12+14, !flip_y),
        m_image_angle  (155,  5,    300, 12,    !flip_y),
        m_image_scale  (155,  5+14, 300, 12+14, !flip_y),
        m_rotate_polygon(5, 5+14+14,    "Rotate Polygon", !flip_y),
        m_rotate_image  (5, 5+14+14+14, "Rotate Image", !flip_y),
        m_example(-3.0, 14+14+14+14, -3.0, 14+14+14+14, !flip_y),
        m_flag(0)
    {
        add_ctrl(m_polygon_angle);
        add_ctrl(m_polygon_scale);
        add_ctrl(m_image_angle);
        add_ctrl(m_image_scale);
        add_ctrl(m_rotate_polygon);
        add_ctrl(m_rotate_image);
        add_ctrl(m_example);

        m_polygon_angle.label("Polygon Angle=%3.2f");
        m_polygon_scale.label("Polygon Scale=%3.2f");
        m_polygon_angle.range(-180.0, 180.0);
        m_polygon_scale.range(0.1, 5.0);
        m_polygon_scale.value(1.0);

        m_image_angle.label("Image Angle=%3.2f");
        m_image_scale.label("Image Scale=%3.2f");
        m_image_angle.range(-180.0, 180.0);
        m_image_scale.range(0.1, 5.0);
        m_image_scale.value(1.0);

        m_example.add_item("0");
        m_example.add_item("1");
        m_example.add_item("2");
        m_example.add_item("3");
        m_example.add_item("4");
        m_example.add_item("5");
        m_example.add_item("6");
        m_example.cur_item(0);
    }
예제 #24
0
    the_application(agg::pix_format_e format, bool flip_y) :
        agg::platform_support(format, flip_y),
        m_idx(-1),
        m_cap(10.0, 10.0, 130.0, 80.0, !flip_y),
        m_width(130 + 10.0, 10.0 + 4.0, 130 + 150.0, 10.0 + 8.0 + 4.0, !flip_y),
        m_smooth(130 + 150.0 + 10.0, 10.0 + 4.0, 500 - 10.0, 10.0 + 8.0 + 4.0, !flip_y),
        m_close(130 + 10.0, 10.0 + 4.0 + 16.0,    "Close Polygons", !flip_y),
        m_even_odd(130 + 150.0 + 10.0, 10.0 + 4.0 + 16.0, "Even-Odd Fill", !flip_y)
    {
        m_x[0] = 57  + 100; m_y[0] = 60;
        m_x[1] = 369 + 100; m_y[1] = 170;
        m_x[2] = 143 + 100; m_y[2] = 310;

        add_ctrl(m_cap);
        m_cap.add_item("Butt Cap");
        m_cap.add_item("Square Cap");
        m_cap.add_item("Round Cap");
        m_cap.cur_item(0);
        m_cap.no_transform();

        add_ctrl(m_width);
        m_width.range(0.0, 10.0);
        m_width.value(3.0);
        m_width.label("Width=%1.2f");
        m_width.no_transform();

        add_ctrl(m_smooth);
        m_smooth.range(0.0, 2.0);
        m_smooth.value(1.0);
        m_smooth.label("Smooth=%1.2f");
        m_smooth.no_transform();

        add_ctrl(m_close);
        m_close.no_transform();

        add_ctrl(m_even_odd);
        m_even_odd.no_transform();
    }
예제 #25
0
    virtual void on_draw()
    {
        typedef agg::renderer_base<pixfmt> ren_base;

        pixfmt pixf(rbuf_window());
        ren_base renb(pixf);
        renb.clear(agg::rgba(1, 1, 1));

        agg::rasterizer_scanline_aa<> ras;
        agg::scanline_u8 sl;

        agg::line_cap_e           cap = agg::butt_cap;
        if(m_cap.cur_item() == 1) cap = agg::square_cap;
        if(m_cap.cur_item() == 2) cap = agg::round_cap;

        // Here we declare a very cheap-in-use path storage.
        // It allocates space for at most 20 vertices in stack and
        // never allocates memory. But be aware that adding more than
        // 20 vertices is fatal! 
        //------------------------
        typedef agg::path_base<
            agg::vertex_stl_storage<
                agg::pod_auto_vector<
                    agg::vertex_d, 20> > > path_storage_type;
        path_storage_type path;

        path.move_to(m_x[0], m_y[0]);
        path.line_to(m_x[1], m_y[1]);
        path.line_to((m_x[0]+m_x[1]+m_x[2]) / 3.0, (m_y[0]+m_y[1]+m_y[2]) / 3.0);
        path.line_to(m_x[2], m_y[2]);
        if(m_close.status()) path.close_polygon();

        path.move_to((m_x[0] + m_x[1]) / 2, (m_y[0] + m_y[1]) / 2);
        path.line_to((m_x[1] + m_x[2]) / 2, (m_y[1] + m_y[2]) / 2);
        path.line_to((m_x[2] + m_x[0]) / 2, (m_y[2] + m_y[0]) / 2);
        if(m_close.status()) path.close_polygon();

        if(m_even_odd.status()) ras.filling_rule(agg::fill_even_odd);

        // (1)
        ras.add_path(path);
        agg::render_scanlines_aa_solid(ras, sl, renb, agg::rgba(0.7, 0.5, 0.1, 0.5));
        // (1)

        // Start of (2, 3, 4)
        agg::conv_smooth_poly1<path_storage_type> smooth(path);
        smooth.smooth_value(m_smooth.value());

        // (2)
        ras.add_path(smooth);
        agg::render_scanlines_aa_solid(ras, sl, renb, agg::rgba(0.1, 0.5, 0.7, 0.1));
        // (2)


        // (3)
        agg::conv_stroke<agg::conv_smooth_poly1<path_storage_type> > smooth_outline(smooth);
        ras.add_path(smooth_outline);
        agg::render_scanlines_aa_solid(ras, sl, renb, agg::rgba(0.0, 0.6, 0.0, 0.8));
        // (3) 

        // (4)
        agg::conv_curve<agg::conv_smooth_poly1<path_storage_type> > curve(smooth);
        agg::conv_dash<agg::conv_curve<agg::conv_smooth_poly1<path_storage_type> >, agg::vcgen_markers_term> dash(curve);
        agg::conv_stroke<agg::conv_dash<agg::conv_curve<agg::conv_smooth_poly1<path_storage_type> >, agg::vcgen_markers_term> > stroke(dash);
        stroke.line_cap(cap);
        stroke.width(m_width.value());

        double k = ::pow(m_width.value(), 0.7);

        agg::arrowhead ah;
                              ah.head(4 * k, 4   * k, 3 * k, 2 * k);
        if(!m_close.status()) ah.tail(1 * k, 1.5 * k, 3 * k, 5 * k);

        agg::conv_marker<agg::vcgen_markers_term, agg::arrowhead> arrow(dash.markers(), ah);

        dash.add_dash(20.0, 5.0);
        dash.add_dash(5.0, 5.0);
        dash.add_dash(5.0, 5.0);
        dash.dash_start(10);

        ras.add_path(stroke);
        ras.add_path(arrow);
        agg::render_scanlines_aa_solid(ras, sl, renb, agg::rgba(0.0, 0.0, 0.0));
        // (4)


        ras.filling_rule(agg::fill_non_zero);
        agg::render_ctrl(ras, sl, renb, m_cap);
        agg::render_ctrl(ras, sl, renb, m_width);
        agg::render_ctrl(ras, sl, renb, m_smooth);
        agg::render_ctrl(ras, sl, renb, m_close);
        agg::render_ctrl(ras, sl, renb, m_even_odd);
    }
예제 #26
0
    virtual void on_draw()
    {
        pixfmt pixf(rbuf_window());
        renderer_base rb(pixf);

        rb.clear(agg::rgba(1.0, 1.0, 1.0));
        rb.copy_from(rbuf_img(0), 0, 110, 35);

        agg::rasterizer_scanline_aa<> ras;
        agg::scanline_u8 sl;

        agg::rendering_buffer img_rbuf(g_image, 4, 4, 4*4);

        double para[] = { 200, 40, 200+300, 40, 200+300, 40+300, 200, 40+300 };
        agg::trans_affine img_mtx(para, 0,0,4,4);

        typedef agg::span_interpolator_linear<> interpolator_type;
        interpolator_type interpolator(img_mtx);
        agg::span_allocator<agg::rgba8> sa;

        pixfmt img_pixf(img_rbuf);
        typedef agg::image_accessor_clone<pixfmt> img_source_type;
        img_source_type source(img_pixf);

        ras.reset();
        ras.move_to_d(para[0], para[1]);
        ras.line_to_d(para[2], para[3]);
        ras.line_to_d(para[4], para[5]);
        ras.line_to_d(para[6], para[7]);

        switch(m_filters.cur_item())
        {
        case 0:
        {
            typedef agg::span_image_filter_rgba_nn<img_source_type,
                    interpolator_type> span_gen_type;

            span_gen_type sg(source, interpolator);
            agg::render_scanlines_aa(ras, sl, rb, sa, sg);
        }
        break;

        case 1:
        case 2:
        case 3:
        case 4:
        case 5:
        case 6:
        case 7:
        case 8:
        case 9:
        case 10:
        case 11:
        case 12:
        case 13:
        case 14:
        case 15:
        case 16:
        {
            agg::image_filter_lut filter;
            bool norm = m_normalize.status();
            switch(m_filters.cur_item())
            {
            case 1:
                filter.calculate(agg::image_filter_bilinear(),                 norm);
                break;
            case 2:
                filter.calculate(agg::image_filter_bicubic(),                  norm);
                break;
            case 3:
                filter.calculate(agg::image_filter_spline16(),                 norm);
                break;
            case 4:
                filter.calculate(agg::image_filter_spline36(),                 norm);
                break;
            case 5:
                filter.calculate(agg::image_filter_hanning(),                  norm);
                break;
            case 6:
                filter.calculate(agg::image_filter_hamming(),                  norm);
                break;
            case 7:
                filter.calculate(agg::image_filter_hermite(),                  norm);
                break;
            case 8:
                filter.calculate(agg::image_filter_kaiser(),                   norm);
                break;
            case 9:
                filter.calculate(agg::image_filter_quadric(),                  norm);
                break;
            case 10:
                filter.calculate(agg::image_filter_catrom(),                   norm);
                break;
            case 11:
                filter.calculate(agg::image_filter_gaussian(),                 norm);
                break;
            case 12:
                filter.calculate(agg::image_filter_bessel(),                   norm);
                break;
            case 13:
                filter.calculate(agg::image_filter_mitchell(),                 norm);
                break;
            case 14:
                filter.calculate(agg::image_filter_sinc(m_radius.value()),     norm);
                break;
            case 15:
                filter.calculate(agg::image_filter_lanczos(m_radius.value()),  norm);
                break;
            case 16:
                filter.calculate(agg::image_filter_blackman(m_radius.value()), norm);
                break;
            }

            typedef agg::span_image_filter_rgba<img_source_type,
                    interpolator_type> span_gen_type;

            span_gen_type sg(source, interpolator, filter);
            agg::render_scanlines_aa(ras, sl, rb, sa, sg);

            agg::gamma_lut<agg::int8u, agg::int8u, 8, 8> gamma(m_gamma.value());
            pixf.apply_gamma_inv(gamma);

            double x_start = 5.0;
            double x_end   = 195.0;
            double y_start = 235.0;
            double y_end   = initial_height() - 5.0;
            double x_center = (x_start + x_end) / 2;

            agg::path_storage p;
            agg::conv_stroke<agg::path_storage> stroke(p);
            stroke.width(0.8);

            unsigned i;
            for(i = 0; i <= 16; i++)
            {
                double x = x_start + (x_end - x_start) * i / 16.0;
                p.remove_all();
                p.move_to(x+0.5, y_start);
                p.line_to(x+0.5, y_end);
                ras.add_path(stroke);
                agg::render_scanlines_aa_solid(ras, sl, rb,
                                               agg::rgba8(0, 0, 0, i == 8 ? 255 : 100));
            }

            double ys = y_start + (y_end - y_start) / 6.0;
            p.remove_all();
            p.move_to(x_start, ys);
            p.line_to(x_end,   ys);
            ras.add_path(stroke);
            agg::render_scanlines_aa_solid(ras, sl, rb, agg::rgba8(0, 0, 0));

            double radius = filter.radius();
            unsigned n = unsigned(radius * 256 * 2);
            double dx = (x_end - x_start) * radius / 8.0;
            double dy = y_end - ys;

            const agg::int16* weights = filter.weight_array();
            double xs = (x_end + x_start)/2.0 - (filter.diameter() * (x_end - x_start) / 32.0);
            unsigned nn = filter.diameter() * 256;
            p.remove_all();
            p.move_to(xs+0.5, ys + dy * weights[0] / agg::image_filter_scale);
            for(i = 1; i < nn; i++)
            {
                p.line_to(xs + dx * i / n + 0.5,
                          ys + dy * weights[i] / agg::image_filter_scale);
            }
            ras.add_path(stroke);
            agg::render_scanlines_aa_solid(ras, sl, rb, agg::rgba8(100, 0, 0));
        }
        break;
        }

        agg::render_ctrl(ras, sl, rb, m_gamma);
        if(m_filters.cur_item() >= 14)
        {
            agg::render_ctrl(ras, sl, rb, m_radius);
        }
        agg::render_ctrl(ras, sl, rb, m_filters);
        agg::render_ctrl(ras, sl, rb, m_normalize);
    }
예제 #27
0
    void render_scanline_boolean(Rasterizer& ras1, Rasterizer& ras2)
    {
        if(m_operation.cur_item() > 0)
        {
            agg::sbool_op_e op;
            switch(m_operation.cur_item())
            {
                case 1: op = agg::sbool_or;        break;
                case 2: op = agg::sbool_and;       break;
                case 3: op = agg::sbool_xor;       break;
                case 4: op = agg::sbool_xor_saddle;break;
                case 5: op = agg::sbool_a_minus_b; break;
                case 6: op = agg::sbool_b_minus_a; break;
            }

            typedef agg::renderer_base<pixfmt> renderer_base;
            pixfmt pixf(rbuf_window());
            renderer_base rb(pixf);

            double t1 = 0.0;
            double t2 = 0.0;
            unsigned num_spans = 0;

            switch(m_scanline_type.cur_item())
            {
                case 0:
                {
                    typedef agg::renderer_scanline_aa_solid<renderer_base> renderer_solid;
                    typedef agg::scanline_p8 scanline_type;

                    renderer_solid ren(rb);

                    scanline_type sl;
                    scanline_type sl1;
                    scanline_type sl2;

                    // The intermediate storage is used only to test the perfoprmance,
                    // the short variant can be as follows:
                    // ------------------------
                    // ren.color(agg::rgba(0.5, 0.0, 0, 0.5));
                    // agg::sbool_combine_shapes_aa(op, ras1, ras2, sl1, sl2, sl, ren);

                    agg::scanline_storage_aa8 storage;
                    agg::scanline_storage_aa8 storage1;
                    agg::scanline_storage_aa8 storage2;

                    agg::render_scanlines(ras1, sl, storage1);
                    agg::render_scanlines(ras2, sl, storage2);
    
                    start_timer();
                    for(int i = 0; i < 10; i++)
                    {
                        agg::sbool_combine_shapes_aa(op, storage1, storage2, sl1, sl2, sl, storage);
                    }
                    t1 = elapsed_time() / 10.0;

                    start_timer();
                    ren.color(agg::rgba(0.5, 0.0, 0, 0.5));
                    agg::render_scanlines(storage, sl, ren);
                    t2 = elapsed_time();

                    num_spans = count_spans(storage, sl);
                }
                break;

                case 1:
                {
                    typedef agg::renderer_scanline_aa_solid<renderer_base> renderer_solid;
                    typedef agg::scanline_u8 scanline_type;

                    renderer_solid ren(rb);

                    scanline_type sl;
                    scanline_type sl1;
                    scanline_type sl2;
                    agg::scanline_storage_aa8 storage;
                    agg::scanline_storage_aa8 storage1;
                    agg::scanline_storage_aa8 storage2;

                    agg::render_scanlines(ras1, sl, storage1);
                    agg::render_scanlines(ras2, sl, storage2);
    
                    start_timer();
                    for(int i = 0; i < 10; i++)
                    {
                        agg::sbool_combine_shapes_aa(op, storage1, storage2, sl1, sl2, sl, storage);
                    }
                    t1 = elapsed_time() / 10.0;

                    start_timer();
                    ren.color(agg::rgba(0.5, 0.0, 0, 0.5));
                    agg::render_scanlines(storage, sl, ren);
                    t2 = elapsed_time();

                    num_spans = count_spans(storage, sl);
                }
                break;


                case 2:
                {
                    typedef agg::renderer_scanline_bin_solid<renderer_base> renderer_solid;
                    typedef agg::scanline_bin scanline_type;

                    renderer_solid ren(rb);

                    scanline_type sl;
                    scanline_type sl1;
                    scanline_type sl2;

                    agg::scanline_storage_bin storage;
                    agg::scanline_storage_bin storage1;
                    agg::scanline_storage_bin storage2;

                    agg::render_scanlines(ras1, sl, storage1);
                    agg::render_scanlines(ras2, sl, storage2);
    
                    start_timer();
                    for(int i = 0; i < 10; i++)
                    {
                        agg::sbool_combine_shapes_bin(op, storage1, storage2, sl1, sl2, sl, storage);
                    }
                    t1 = elapsed_time() / 10.0;

                    start_timer();
                    ren.color(agg::rgba(0.5, 0.0, 0, 0.5));
                    agg::render_scanlines(storage, sl, ren);
                    t2 = elapsed_time();

                    num_spans = count_spans(storage, sl);
                }
                break;

            }


            char buf[100];
            sprintf(buf, "Combine=%.3fms\n\nRender=%.3fms\n\nnum_spans=%d", t1, t2, num_spans);
            agg::renderer_scanline_aa_solid<renderer_base> ren(rb);
            agg::scanline_p8 sl;
            agg::gsv_text txt;
            agg::conv_stroke<agg::gsv_text> txt_stroke(txt);
            txt_stroke.width(1.0);
            txt_stroke.line_cap(agg::round_cap);
            txt.size(8.0);
            txt.start_point(420, 40);
            txt.text(buf);
            ras1.add_path(txt_stroke);
            ren.color(agg::rgba(0.0, 0.0, 0.0));
            agg::render_scanlines(ras1, sl, ren);

        
        }
    }
예제 #28
0
    virtual void on_draw()
    {
        pixfmt pixf(rbuf_window());
        renderer_base rb(pixf);
        renderer_solid r(rb);
        rb.clear(agg::rgba(1, 1, 1));

        g_rasterizer.clip_box(0, 0, width(), height());

        if(m_trans_type.cur_item() == 0)
        {
            agg::trans_bilinear tr(g_x1, g_y1, g_x2, g_y2, m_quad.polygon());
            if(tr.is_valid())
            {
                //--------------------------
                // Render transformed lion
                //
                agg::conv_transform<agg::path_storage, 
                                    agg::trans_bilinear> trans(g_path, tr);

                agg::render_all_paths(g_rasterizer, g_scanline, r, trans, g_colors, g_path_idx, g_npaths);
                //--------------------------



                //--------------------------
                // Render transformed ellipse
                //
                agg::ellipse ell((g_x1 + g_x2) * 0.5, (g_y1 + g_y2) * 0.5, 
                                 (g_x2 - g_x1) * 0.5, (g_y2 - g_y1) * 0.5,
                                 200);
                agg::conv_stroke<agg::ellipse> ell_stroke(ell);
                ell_stroke.width(3.0);
                agg::conv_transform<agg::ellipse, 
                                    agg::trans_bilinear> trans_ell(ell, tr);

                agg::conv_transform<agg::conv_stroke<agg::ellipse>, 
                                    agg::trans_bilinear> trans_ell_stroke(ell_stroke, tr);

                g_rasterizer.add_path(trans_ell);
                r.color(agg::rgba(0.5, 0.3, 0.0, 0.3));
                agg::render_scanlines(g_rasterizer, g_scanline, r);

                g_rasterizer.add_path(trans_ell_stroke);
                r.color(agg::rgba(0.0, 0.3, 0.2, 1.0));
                agg::render_scanlines(g_rasterizer, g_scanline, r);
                //--------------------------

            }
        }
        else
        {
            agg::trans_perspective tr(g_x1, g_y1, g_x2, g_y2, m_quad.polygon());
            if(tr.is_valid())
            {

                //--------------------------
                // Render transformed lion
                //
                agg::conv_transform<agg::path_storage, 
                                    agg::trans_perspective> trans(g_path, tr);

                agg::render_all_paths(g_rasterizer, g_scanline, r, trans, g_colors, g_path_idx, g_npaths);

                //--------------------------



                //--------------------------
                // Render transformed ellipse
                //
                agg::ellipse ell((g_x1 + g_x2) * 0.5, (g_y1 + g_y2) * 0.5, 
                                 (g_x2 - g_x1) * 0.5, (g_y2 - g_y1) * 0.5,
                                 200);

                agg::conv_stroke<agg::ellipse> ell_stroke(ell);
                ell_stroke.width(3.0);
                agg::conv_transform<agg::ellipse, 
                                    agg::trans_perspective> trans_ell(ell, tr);


                agg::conv_transform<agg::conv_stroke<agg::ellipse>, 
                                    agg::trans_perspective> trans_ell_stroke(ell_stroke, tr);


                g_rasterizer.add_path(trans_ell);
                r.color(agg::rgba(0.5, 0.3, 0.0, 0.3));
                agg::render_scanlines(g_rasterizer, g_scanline, r);

                g_rasterizer.add_path(trans_ell_stroke);
                r.color(agg::rgba(0.0, 0.3, 0.2, 1.0));
                agg::render_scanlines(g_rasterizer, g_scanline, r);
                //--------------------------


                // Testing the reverse transformations
                //agg::trans_perspective tr2(m_quad.polygon(), g_x1, g_y1, g_x2, g_y2);
                //if(tr2.is_valid())
                //{
                //    double x, y;
                //    x = m_quad.xn(0); y = m_quad.yn(0); tr2.transform(&x, &y);
                //    g_rasterizer.move_to_d(x, y);
                //    x = m_quad.xn(1); y = m_quad.yn(1); tr2.transform(&x, &y);
                //    g_rasterizer.line_to_d(x, y);
                //    x = m_quad.xn(2); y = m_quad.yn(2); tr2.transform(&x, &y);
                //    g_rasterizer.line_to_d(x, y);
                //    x = m_quad.xn(3); y = m_quad.yn(3); tr2.transform(&x, &y);
                //    g_rasterizer.line_to_d(x, y);
                //    r.color(agg::rgba(0.5, 0.0, 0.0, 0.5));
                //    agg::render_scanlines(g_rasterizer, g_scanline, r);
                //}
                //else
                //{
                //    message("Singularity...");
                //}
            }
        }




        //--------------------------
        // Render the "quad" tool and controls
        g_rasterizer.add_path(m_quad);
        r.color(agg::rgba(0, 0.3, 0.5, 0.6));
        agg::render_scanlines(g_rasterizer, g_scanline, r);
        agg::render_ctrl(g_rasterizer, g_scanline, rb, m_trans_type);
        //--------------------------
    }
예제 #29
0
    unsigned render_sbool(Rasterizer& ras1, Rasterizer& ras2)
    {
        pixfmt pf(rbuf_window());
        agg::renderer_base<pixfmt> rb(pf);
        agg::renderer_scanline_aa_solid<agg::renderer_base<pixfmt> > ren(rb);
        agg::scanline_p8 sl;

        ras1.filling_rule(m_fill_rule.cur_item() ? agg::fill_non_zero : agg::fill_even_odd);
        ras2.filling_rule(m_fill_rule.cur_item() ? agg::fill_non_zero : agg::fill_even_odd);

        switch(m_polygons.cur_item())
        {
            case 0:
            {
                //------------------------------------
                // Two simple paths
                //
                agg::path_storage ps1;
                agg::path_storage ps2;

                double x = m_x - initial_width()/2 + 100;
                double y = m_y - initial_height()/2 + 100;
                ps1.move_to(x+140, y+145);
                ps1.line_to(x+225, y+44);
                ps1.line_to(x+296, y+219);
                ps1.close_polygon();

                ps1.line_to(x+226, y+289);
                ps1.line_to(x+82,  y+292);

                ps1.move_to(x+220, y+222);
                ps1.line_to(x+363, y+249);
                ps1.line_to(x+265, y+331);

                ps1.move_to(x+242, y+243);
                ps1.line_to(x+325, y+261);
                ps1.line_to(x+268, y+309);

                ps1.move_to(x+259, y+259);
                ps1.line_to(x+273, y+288);
                ps1.line_to(x+298, y+266);

                ps2.move_to(100+32,  100+77);
                ps2.line_to(100+473, 100+263);
                ps2.line_to(100+351, 100+290);
                ps2.line_to(100+354, 100+374);

                ras1.reset();
                ras1.add_path(ps1);
                ren.color(agg::rgba(0, 0, 0, 0.1));
                agg::render_scanlines(ras1, sl, ren);

                ras2.reset();
                ras2.add_path(ps2);
                ren.color(agg::rgba(0, 0.6, 0, 0.1));
                agg::render_scanlines(ras2, sl, ren);

                render_scanline_boolean(ras1, ras2);
            }
            break;

            case 1:
            {
                //------------------------------------
                // Closed stroke
                //
                agg::path_storage ps1;
                agg::path_storage ps2;
                agg::conv_stroke<agg::path_storage> stroke(ps2);
                stroke.width(15.0);

                double x = m_x - initial_width()/2 + 100;
                double y = m_y - initial_height()/2 + 100;
                ps1.move_to(x+140, y+145);
                ps1.line_to(x+225, y+44);
                ps1.line_to(x+296, y+219);
                ps1.close_polygon();

                ps1.line_to(x+226, y+289);
                ps1.line_to(x+82,  y+292);

                ps1.move_to(x+220-50, y+222);
                ps1.line_to(x+363-50, y+249);
                ps1.line_to(x+265-50, y+331);
                ps1.close_polygon();

                ps2.move_to(100+32,  100+77);
                ps2.line_to(100+473, 100+263);
                ps2.line_to(100+351, 100+290);
                ps2.line_to(100+354, 100+374);
                ps2.close_polygon();

                ras1.reset();
                ras1.add_path(ps1);
                ren.color(agg::rgba(0, 0, 0, 0.1));
                agg::render_scanlines(ras1, sl, ren);

                ras2.reset();
                ras2.add_path(stroke);
                ren.color(agg::rgba(0, 0.6, 0, 0.1));
                agg::render_scanlines(ras2, sl, ren);

                render_scanline_boolean(ras1, ras2);
            }
            break;


            case 2:
            {
                //------------------------------------
                // Great Britain and Arrows
                //
                agg::path_storage gb_poly;
                agg::path_storage arrows;
                make_gb_poly(gb_poly);
                make_arrows(arrows);

                agg::trans_affine mtx1;
                agg::trans_affine mtx2;
                mtx1 *= agg::trans_affine_translation(-1150, -1150);
                mtx1 *= agg::trans_affine_scaling(2.0);

                mtx2 = mtx1;
                mtx2 *= agg::trans_affine_translation(m_x - initial_width()/2, 
                                                      m_y - initial_height()/2);

                agg::conv_transform<agg::path_storage> trans_gb_poly(gb_poly, mtx1);
                agg::conv_transform<agg::path_storage> trans_arrows(arrows, mtx2);

                ras2.add_path(trans_gb_poly);
                ren.color(agg::rgba(0.5, 0.5, 0, 0.1));
                agg::render_scanlines(ras2, sl, ren);

                agg::conv_stroke<agg::conv_transform<agg::path_storage> > stroke_gb_poly(trans_gb_poly);
                stroke_gb_poly.width(0.1);
                ras1.add_path(stroke_gb_poly);
                ren.color(agg::rgba(0, 0, 0));
                agg::render_scanlines(ras1, sl, ren);
        
                ras2.add_path(trans_arrows);
                ren.color(agg::rgba(0.0, 0.5, 0.5, 0.1));
                agg::render_scanlines(ras2, sl, ren);

                ras1.reset();
                ras1.add_path(trans_gb_poly);

                render_scanline_boolean(ras1, ras2);
            }
            break;


            case 3:
            {
                //------------------------------------
                // Great Britain and a Spiral
                //
                spiral sp(m_x, m_y, 10, 150, 30, 0.0);
                agg::conv_stroke<spiral> stroke(sp);
                stroke.width(15.0);

                agg::path_storage gb_poly;
                make_gb_poly(gb_poly);

                agg::trans_affine mtx;
                mtx *= agg::trans_affine_translation(-1150, -1150);
                mtx *= agg::trans_affine_scaling(2.0);
                mtx *= trans_affine_resizing();

                agg::conv_transform<agg::path_storage> trans_gb_poly(gb_poly, mtx);


                ras1.add_path(trans_gb_poly);
                ren.color(agg::rgba(0.5, 0.5, 0, 0.1));
                agg::render_scanlines(ras1, sl, ren);

                agg::conv_stroke<agg::conv_transform<agg::path_storage> > stroke_gb_poly(trans_gb_poly);
                stroke_gb_poly.width(0.1);
                ras1.reset();
                ras1.add_path(stroke_gb_poly);
                ren.color(agg::rgba(0, 0, 0));
                agg::render_scanlines(ras1, sl, ren);
        
                ras2.reset();
                ras2.add_path(stroke);
                ren.color(agg::rgba(0.0, 0.5, 0.5, 0.1));
                agg::render_scanlines(ras2, sl, ren);

                ras1.reset();
                ras1.add_path(trans_gb_poly);
                render_scanline_boolean(ras1, ras2);
            }
            break;


            case 4:
            {
                //------------------------------------
                // Spiral and glyph
                //
                spiral sp(m_x, m_y, 10, 150, 30, 0.0);
                agg::conv_stroke<spiral> stroke(sp);
                stroke.width(15.0);

                agg::path_storage glyph;
                glyph.move_to(28.47, 6.45);
                glyph.curve3(21.58, 1.12, 19.82, 0.29);
                glyph.curve3(17.19, -0.93, 14.21, -0.93);
                glyph.curve3(9.57, -0.93, 6.57, 2.25);
                glyph.curve3(3.56, 5.42, 3.56, 10.60);
                glyph.curve3(3.56, 13.87, 5.03, 16.26);
                glyph.curve3(7.03, 19.58, 11.99, 22.51);
                glyph.curve3(16.94, 25.44, 28.47, 29.64);
                glyph.line_to(28.47, 31.40);
                glyph.curve3(28.47, 38.09, 26.34, 40.58);
                glyph.curve3(24.22, 43.07, 20.17, 43.07);
                glyph.curve3(17.09, 43.07, 15.28, 41.41);
                glyph.curve3(13.43, 39.75, 13.43, 37.60);
                glyph.line_to(13.53, 34.77);
                glyph.curve3(13.53, 32.52, 12.38, 31.30);
                glyph.curve3(11.23, 30.08, 9.38, 30.08);
                glyph.curve3(7.57, 30.08, 6.42, 31.35);
                glyph.curve3(5.27, 32.62, 5.27, 34.81);
                glyph.curve3(5.27, 39.01, 9.57, 42.53);
                glyph.curve3(13.87, 46.04, 21.63, 46.04);
                glyph.curve3(27.59, 46.04, 31.40, 44.04);
                glyph.curve3(34.28, 42.53, 35.64, 39.31);
                glyph.curve3(36.52, 37.21, 36.52, 30.71);
                glyph.line_to(36.52, 15.53);
                glyph.curve3(36.52, 9.13, 36.77, 7.69);
                glyph.curve3(37.01, 6.25, 37.57, 5.76);
                glyph.curve3(38.13, 5.27, 38.87, 5.27);
                glyph.curve3(39.65, 5.27, 40.23, 5.62);
                glyph.curve3(41.26, 6.25, 44.19, 9.18);
                glyph.line_to(44.19, 6.45);
                glyph.curve3(38.72, -0.88, 33.74, -0.88);
                glyph.curve3(31.35, -0.88, 29.93, 0.78);
                glyph.curve3(28.52, 2.44, 28.47, 6.45);
                glyph.close_polygon();

                glyph.move_to(28.47, 9.62);
                glyph.line_to(28.47, 26.66);
                glyph.curve3(21.09, 23.73, 18.95, 22.51);
                glyph.curve3(15.09, 20.36, 13.43, 18.02);
                glyph.curve3(11.77, 15.67, 11.77, 12.89);
                glyph.curve3(11.77, 9.38, 13.87, 7.06);
                glyph.curve3(15.97, 4.74, 18.70, 4.74);
                glyph.curve3(22.41, 4.74, 28.47, 9.62);
                glyph.close_polygon();

                agg::trans_affine mtx;
                mtx *= agg::trans_affine_scaling(4.0);
                mtx *= agg::trans_affine_translation(220, 200);
                agg::conv_transform<agg::path_storage> trans(glyph, mtx);
                agg::conv_curve<agg::conv_transform<agg::path_storage> > curve(trans);

                ras1.reset();
                ras1.add_path(stroke);
                ren.color(agg::rgba(0, 0, 0, 0.1));
                agg::render_scanlines(ras1, sl, ren);

                ras2.reset();
                ras2.add_path(curve);
                ren.color(agg::rgba(0, 0.6, 0, 0.1));
                agg::render_scanlines(ras2, sl, ren);

                render_scanline_boolean(ras1, ras2);
            }
            break;
        }

        return 0;
    }
예제 #30
0
파일: conv_stroke.cpp 프로젝트: UIKit0/agg
  virtual void on_draw() {
    typedef agg::renderer_base<pixfmt> ren_base;

    pixfmt pixf(rbuf_window());
    ren_base renb(pixf);
    renb.clear(agg::rgba(1, 1, 1));

    agg::rasterizer_scanline_aa<> ras;
    agg::scanline_p8 sl;

    agg::path_storage path;

    path.move_to(m_x[0], m_y[0]);
    path.line_to((m_x[0] + m_x[1]) / 2,
                 (m_y[0] + m_y[1]) / 2);  // This point is added only to check
                                          // for numerical stability
    path.line_to(m_x[1], m_y[1]);
    path.line_to(m_x[2], m_y[2]);
    path.line_to(m_x[2], m_y[2]);  // This point is added only to check for
                                   // numerical stability

    path.move_to((m_x[0] + m_x[1]) / 2, (m_y[0] + m_y[1]) / 2);
    path.line_to((m_x[1] + m_x[2]) / 2, (m_y[1] + m_y[2]) / 2);
    path.line_to((m_x[2] + m_x[0]) / 2, (m_y[2] + m_y[0]) / 2);
    path.close_polygon();

    agg::line_cap_e cap = agg::butt_cap;
    if (m_cap.cur_item() == 1) cap = agg::square_cap;
    if (m_cap.cur_item() == 2) cap = agg::round_cap;

    agg::line_join_e join = agg::miter_join;
    if (m_join.cur_item() == 1) join = agg::miter_join_revert;
    if (m_join.cur_item() == 2) join = agg::round_join;
    if (m_join.cur_item() == 3) join = agg::bevel_join;

    // (1)
    agg::conv_stroke<agg::path_storage> stroke(path);
    stroke.line_join(join);
    stroke.line_cap(cap);
    stroke.miter_limit(m_miter_limit.value());
    stroke.width(m_width.value());
    ras.add_path(stroke);
    agg::render_scanlines_aa_solid(ras, sl, renb, agg::rgba(0.8, 0.7, 0.6));
    // (1)

    // (2)
    agg::conv_stroke<agg::path_storage> poly1(path);
    poly1.width(1.5);
    ras.add_path(poly1);
    agg::render_scanlines_aa_solid(ras, sl, renb, agg::rgba(0, 0, 0));
    // (2)

    // (3)
    agg::conv_dash<agg::conv_stroke<agg::path_storage> > poly2_dash(stroke);
    agg::conv_stroke<agg::conv_dash<agg::conv_stroke<agg::path_storage> > >
        poly2(poly2_dash);
    poly2.miter_limit(4.0);
    poly2.width(m_width.value() / 5.0);
    poly2.line_cap(cap);
    poly2.line_join(join);
    poly2_dash.add_dash(20.0, m_width.value() / 2.5);
    ras.add_path(poly2);
    agg::render_scanlines_aa_solid(ras, sl, renb, agg::rgba(0, 0, 0.3));
    // (3)

    // (4)
    ras.add_path(path);
    agg::render_scanlines_aa_solid(ras, sl, renb,
                                   agg::rgba(0.0, 0.0, 0.0, 0.2));
    // (4)

    agg::render_ctrl(ras, sl, renb, m_join);
    agg::render_ctrl(ras, sl, renb, m_cap);
    agg::render_ctrl(ras, sl, renb, m_width);
    agg::render_ctrl(ras, sl, renb, m_miter_limit);
  }