Esempio n. 1
0
 the_application(agg::pix_format_e format, bool flip_y) :
     agg::platform_support(format, flip_y),
     m_alpha(2,  2,  200, 30,  6, !flip_y)
 {
     m_alpha.value(0, 1.0);
     m_alpha.value(1, 1.0);
     m_alpha.value(2, 1.0);
     m_alpha.value(3, 0.5);
     m_alpha.value(4, 0.5);
     m_alpha.value(5, 1.0);
     m_alpha.update_spline();
     add_ctrl(m_alpha);
 }
Esempio n. 2
0
    the_application(agg::pix_format_e format, bool flip_y) :
        agg::platform_support(format, flip_y),
        m_idx(-1),
        m_alpha(2,  2,  200, 30,  6, !flip_y)
    {
        m_x[0] = 257;    m_y[0] = 60;
        m_x[1] = 369;   m_y[1] = 170;
        m_x[2] = 143;   m_y[2] = 310;

        m_alpha.point(0, 0.0,     0.0);
        m_alpha.point(1, 1.0/5.0, 1.0 - 4.0/5.0);
        m_alpha.point(2, 2.0/5.0, 1.0 - 3.0/5.0);
        m_alpha.point(3, 3.0/5.0, 1.0 - 2.0/5.0);
        m_alpha.point(4, 4.0/5.0, 1.0 - 1.0/5.0);
        m_alpha.point(5, 1.0,     1.0);
        m_alpha.update_spline();
        add_ctrl(m_alpha);
    }
Esempio n. 3
0
    virtual void on_key(int x, int y, unsigned key, unsigned flags)
    {
        if(key == ' ')
        {
            FILE* fd = fopen(full_file_name("alpha"), "w");

            int i;
            for(i = 0; i < agg::span_conv_brightness_alpha_rgb8::array_size; i++)
            {
                int alpha = 
                    agg::int8u(m_alpha.value(double(i) / 
                             double(agg::span_conv_brightness_alpha_rgb8::array_size)) * 255.0);
                if(i % 32 == 0) fprintf(fd, "\n");
                fprintf(fd, "%3d, ", alpha);
            }

            fclose(fd);
        }
    }
Esempio n. 4
0
  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);
  }
Esempio n. 5
0
    virtual void on_draw()
    {
        typedef agg::pixfmt_bgr24 pixfmt;
        typedef agg::renderer_base<pixfmt> renderer_base;

        pixfmt pixf(rbuf_window());
        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(-initial_width()/2, -initial_height()/2);
        src_mtx *= agg::trans_affine_rotation(10.0 * agg::pi / 180.0);
        src_mtx *= agg::trans_affine_translation(initial_width()/2, initial_height()/2);
        src_mtx *= trans_affine_resizing();

        agg::trans_affine img_mtx = src_mtx;
        img_mtx.invert();

        typedef agg::span_allocator<agg::rgba8> span_alloc;

        unsigned i;

        unsigned char brightness_alpha_array[agg::span_conv_brightness_alpha_rgb8::array_size];
        for(i = 0; i < agg::span_conv_brightness_alpha_rgb8::array_size; i++)
        {
            brightness_alpha_array[i] = 
                agg::int8u(m_alpha.value(double(i) / 
                         double(agg::span_conv_brightness_alpha_rgb8::array_size)) * 255.0);
        }
        agg::span_conv_brightness_alpha_rgb8 color_alpha(brightness_alpha_array);



        typedef agg::image_accessor_clip<pixfmt> img_source_type;
        typedef agg::span_interpolator_linear<> interpolator_type; 
        typedef agg::span_image_filter_rgb_bilinear<img_source_type,
                                                    interpolator_type> span_gen;
        typedef agg::span_converter<span_gen,
                                    agg::span_conv_brightness_alpha_rgb8> span_conv;


        span_alloc sa;
        interpolator_type interpolator(img_mtx);
        pixfmt img_pixf(rbuf_img(0));
        img_source_type img_src(img_pixf, agg::rgba(0,0,0,0));
        span_gen sg(img_src, interpolator);
        span_conv sc(sg, color_alpha);
        agg::ellipse ell;
        agg::rasterizer_scanline_aa<> ras;
        agg::scanline_u8 sl;
        
        for(i = 0; i < 50; i++)
        {
            ell.init(m_x[i], m_y[i], m_rx[i], m_ry[i], 50);
            ras.add_path(ell);
            agg::render_scanlines_aa_solid(ras, sl, rb, m_colors[i]);
        }


        ell.init(initial_width()  / 2.0, 
                 initial_height() / 2.0, 
                 initial_width()  / 1.9, 
                 initial_height() / 1.9, 200);


        agg::conv_transform<agg::ellipse> tr(ell, src_mtx);


        ras.add_path(tr);
        agg::render_scanlines_aa(ras, sl, rb, sa, sc);

        agg::render_ctrl(ras, sl, rb, m_alpha);
    }