예제 #1
0
    //------------------------------------------------------------------------
    void create_star(agg::path_storage& ps)
    {
        double r = initial_width();
        if(initial_height() < r) r = initial_height();

        double r1 = r / 3 - 8.0;
        double r2 = r1 / 1.45;
        unsigned nr = 14;

        unsigned i;
        for(i = 0; i < nr; i++)
        {
            double a = agg::pi * 2.0 * i / nr - agg::pi / 2.0;
            double dx = cos(a);
            double dy = sin(a);

            if(i & 1)
            {
                ps.line_to(m_polygon_cx + dx * r1, m_polygon_cy + dy * r1);
            }
            else
            {
                if(i) ps.line_to(m_polygon_cx + dx * r2, m_polygon_cy + dy * r2);
                else  ps.move_to(m_polygon_cx + dx * r2, m_polygon_cy + dy * r2);
            }
        }
    }
예제 #2
0
 //------------------------------------------------------------------------
 virtual void on_init()
 {
     m_image_center_x = initial_width() / 2.0;
     m_image_center_y = initial_height() / 2.0;
     m_polygon_cx = m_image_cx = initial_width() / 2.0;
     m_polygon_cy = m_image_cy = initial_height() / 2.0;
 }
예제 #3
0
파일: circles.cpp 프로젝트: UIKit0/agg
  virtual void on_draw() {
    agg::rasterizer_scanline_aa<> pf;
    agg::scanline_p8 sl;

    typedef agg::renderer_base<pixfmt> renderer_base;

    pixfmt pixf(rbuf_window());
    renderer_base rb(pixf);

    rb.clear(agg::rgba(1, 1, 1));

    agg::ellipse e1;
    agg::conv_transform<agg::ellipse> t1(e1, trans_affine_resizing());

    unsigned i;
    unsigned n_drawn = 0;
    for (i = 0; i < m_num_points; i++) {
      double z = m_points[i].z;
      double alpha = 1.0;
      if (z < m_scale_ctrl_z.value1()) {
        alpha = 1.0 - (m_scale_ctrl_z.value1() - z) *
                          m_slider_ctrl_sel.value() * 100.0;
      }

      if (z > m_scale_ctrl_z.value2()) {
        alpha = 1.0 - (z - m_scale_ctrl_z.value2()) *
                          m_slider_ctrl_sel.value() * 100.0;
      }

      if (alpha > 1.0) alpha = 1.0;
      if (alpha < 0.0) alpha = 0.0;

      if (alpha > 0.0) {
        e1.init(m_points[i].x, m_points[i].y, m_slider_ctrl_size.value() * 5.0,
                m_slider_ctrl_size.value() * 5.0, 8);
        pf.add_path(t1);

        agg::render_scanlines_aa_solid(
            pf, sl, rb, agg::rgba(m_points[i].color.r, m_points[i].color.g,
                                  m_points[i].color.b, alpha));
        n_drawn++;
      }
    }

    agg::render_ctrl(pf, sl, rb, m_scale_ctrl_z);
    agg::render_ctrl(pf, sl, rb, m_slider_ctrl_sel);
    agg::render_ctrl(pf, sl, rb, m_slider_ctrl_size);

    char buf[10];
    sprintf(buf, "%08u", n_drawn);

    agg::gsv_text txt;
    txt.size(15.0);
    txt.text(buf);
    txt.start_point(10.0, initial_height() - 20.0);
    agg::gsv_text_outline<> txt_o(txt, trans_affine_resizing());
    pf.add_path(txt_o);
    agg::render_scanlines_aa_solid(pf, sl, rb, agg::rgba(0, 0, 0));
  }
예제 #4
0
파일: circles.cpp 프로젝트: UIKit0/agg
  void generate() {
    unsigned i;

    double rx = initial_width() / 3.5;
    double ry = initial_height() / 3.5;

    for (i = 0; i < m_num_points; i++) {
      double z = m_points[i].z = random_dbl(0.0, 1.0);
      double x = cos(z * 2.0 * agg::pi) * rx;
      double y = sin(z * 2.0 * agg::pi) * ry;

      double dist = random_dbl(0.0, rx / 2.0);
      double angle = random_dbl(0.0, agg::pi * 2.0);

      m_points[i].x = initial_width() / 2.0 + x + cos(angle) * dist;
      m_points[i].y = initial_height() / 2.0 + y + sin(angle) * dist;
      m_points[i].color =
          agg::rgba(m_spline_r.get(z) * 0.8, m_spline_g.get(z) * 0.8,
                    m_spline_b.get(z) * 0.8, 1.0);
    }
  }
예제 #5
0
bool MonitorWindow::open_and_resize(Monitor* m) {
  _m = m;
  
  pw = 0;
# ifdef QUARTZ_LIB
  if (!SpyDisplay[0]) {
    pw = (AbstractPlatformWindow*) new QuartzWindow;
  }
# endif
  
# ifdef XLIB
  if (!pw) {
    pw = (AbstractPlatformWindow*) new XPlatformWindow;
  }
# endif
  
  if (!pw) {
    warning("no window system for spy");
    return false;
  }
  
  // open the window, and resize for the spy
  // set size hints to don't care cause we will resize window below
  if (!  pw->open( compute_display_name(),
                  100, 100, 500, 500,
                  -1,  -1,  -1,  -1,
                  compute_window_name(),
                  "Spy",
                  SpyFont[0] ? SpyFont : pw->default_fixed_font_name(),
                  pw->default_fixed_font_size()))
    return false;
  
  // Spy uses fixed-width font and sizes window accordingly.
  // On some platforms, cannot get font till window is open.
  // So, now that window is opened, can ask spy for height, and
  // can set window place/size and size limits.
  if (!pw->change_extent( initial_left(), initial_top(), initial_width(), initial_height()))  { close();  return false; }
  if (!pw->change_size_hints( -1,  initial_width(), initial_height(), initial_height()))       { close();  return false; }
  return true;
}
예제 #6
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;
    }
예제 #7
0
void
CSS_Viewport::Constrain(const CSS_DeviceProperties& device_props)
{
	/* Sanity check for input values. */

	OP_ASSERT(device_props.device_width > 0 &&
			  device_props.device_height > 0 &&
			  device_props.viewport_width > 0 &&
			  device_props.viewport_height > 0 &&
			  device_props.font_size > 0);

	m_actual_zoom = m_zoom;
	m_actual_min_zoom = m_min_zoom;
	m_actual_max_zoom = m_max_zoom;
	m_actual_zoomable = m_zoomable;
	m_actual_orientation = m_orientation;

	/* 1. Resolve relative and absolute lengths, percentages, and keywords ('device-width',
		  'device-height') to pixel values for the 'min-width', 'max-width',
		  'min-height' and 'max-height' properties. */

	CSS_ViewportLength min_width = m_min_width.ToPixels(device_props, TRUE);
	CSS_ViewportLength max_width = m_max_width.ToPixels(device_props, TRUE);
	CSS_ViewportLength min_height = m_min_height.ToPixels(device_props, FALSE);
	CSS_ViewportLength max_height = m_max_height.ToPixels(device_props, FALSE);

	/* 2. If min-width or max-width is not 'auto', set width = MAX(min-width, MIN(max-width, initial-width)) */

	CSS_ViewportLength width;
	if (!min_width.IsAuto() || !max_width.IsAuto())
	{
		CSS_ViewportLength initial_width(device_props.viewport_width, CSS_ViewportLength::PX);
		width = Max(min_width, Min(max_width, initial_width));
	}

	/* 3. If min-height or max-height is not 'auto', set height = MAX(min-height, MIN(max-height, initial-height)) */

	CSS_ViewportLength height;
	if (!min_height.IsAuto() || !max_height.IsAuto())
	{
		CSS_ViewportLength initial_height(device_props.viewport_height, CSS_ViewportLength::PX);
		height = Max(min_height, Min(max_height, initial_height));
	}

	/* 4. If min-zoom is not 'auto' and max-zoom is not 'auto', set max-zoom = MAX(min-zoom, max-zoom) */

	if (m_actual_max_zoom != CSS_VIEWPORT_ZOOM_AUTO &&
		m_actual_min_zoom != CSS_VIEWPORT_ZOOM_AUTO &&
		m_actual_max_zoom < m_actual_min_zoom)
		m_actual_max_zoom = m_actual_min_zoom;

	/* 5. If zoom is not 'auto', set zoom = MIN(max-zoom, MAX(min-zoom, zoom)) */

	if (m_actual_zoom != CSS_VIEWPORT_ZOOM_AUTO)
	{
		if (m_actual_min_zoom != CSS_VIEWPORT_ZOOM_AUTO && m_actual_zoom < m_actual_min_zoom)
			m_actual_zoom = m_actual_min_zoom;
		else if (m_actual_max_zoom != CSS_VIEWPORT_ZOOM_AUTO && m_actual_zoom > m_actual_max_zoom)
			m_actual_zoom = m_actual_max_zoom;
	}

	if (width.IsAuto())
	{
		if (m_actual_zoom == CSS_VIEWPORT_ZOOM_AUTO)
			/* 6. If width and zoom are both 'auto', set width = initial-width */
			width = device_props.viewport_width;
		else if (height.IsAuto())
			/* 7. If width is 'auto', and height is 'auto', set width = (initial-width / zoom) */
			width = device_props.viewport_width / m_actual_zoom;
		else
			/* 8. If width is 'auto', set width = height * (initial-width / initial-height) */
			width = double(height) * device_props.viewport_width / double(device_props.viewport_height);
	}

	/* Check that width has been resolved. */
	OP_ASSERT(!width.IsAuto());

	/* 9. If height is 'auto', set height = width * (initial-height / initial-width) */

	if (height.IsAuto())
		height = double(width) * device_props.viewport_height / double(device_props.viewport_width);

	/* Check that height has been resolved. */
	OP_ASSERT(!height.IsAuto());

	if (m_actual_zoom != CSS_VIEWPORT_ZOOM_AUTO || m_actual_max_zoom != CSS_VIEWPORT_ZOOM_AUTO)
	{
		double max_initial_zoom = m_actual_zoom == CSS_VIEWPORT_ZOOM_AUTO ? m_actual_max_zoom : m_actual_zoom;

		/* 10. If zoom or max-zoom is not 'auto', set width = MAX(width, (initial-width / MIN(zoom, max-zoom))) */

		double extended_width(device_props.viewport_width / max_initial_zoom);
		if (double(width) < extended_width)
			width = extended_width;

		/* 11. If zoom or max-zoom is not 'auto', set height = MAX(height, (initial-height / MIN(zoom, max-zoom))) */

		double extended_height(device_props.viewport_height / max_initial_zoom);
		if (double(height) < extended_height)
			height = extended_height;
	}

	m_actual_width = width;
	m_actual_height = height;
}
예제 #8
0
    virtual void on_draw()
    {
        typedef agg::pixfmt_bgr24 pixfmt;
        typedef agg::renderer_base<pixfmt> renderer_base;
        typedef agg::renderer_scanline_aa_solid<renderer_base> renderer_solid;
        
        pixfmt pixf(rbuf_window());
        renderer_base rb(pixf);
        renderer_solid rs(rb);
        
        rb.clear(agg::rgba(1, 1, 1));

        agg::trans_affine mtx;
        agg::conv_transform<agg::path_storage, agg::trans_affine> trans(g_path, mtx);

        mtx *= agg::trans_affine_translation(-g_base_dx, -g_base_dy);
        mtx *= agg::trans_affine_scaling(g_scale, g_scale);
        mtx *= agg::trans_affine_rotation(g_angle + agg::pi);
        mtx *= agg::trans_affine_skewing(g_skew_x/1000.0, g_skew_y/1000.0);
        mtx *= agg::trans_affine_translation(initial_width()/4, initial_height()/2);
        mtx *= trans_affine_resizing();

        agg::rasterizer_scanline_aa<> ras2;
        agg::scanline_p8 sl;
        agg::scanline_u8 sl2;

        agg::render_all_paths(ras2, sl, rs, trans, g_colors, g_path_idx, g_npaths);

        mtx *= ~trans_affine_resizing();
        mtx *= agg::trans_affine_translation(initial_width()/2, 0);
        mtx *= trans_affine_resizing();

        agg::line_profile_aa profile;
        profile.width(1.0);
        agg::renderer_outline_aa<renderer_base> rp(rb, profile);
        agg::rasterizer_outline_aa<agg::renderer_outline_aa<renderer_base> > ras(rp);
        ras.round_cap(true);

        ras.render_all_paths(trans, g_colors, g_path_idx, g_npaths);

        agg::ellipse ell(m_cx, m_cy, 100.0, 100.0, 100);
        agg::conv_stroke<agg::ellipse> ell_stroke1(ell);
        ell_stroke1.width(6.0);
        agg::conv_stroke<agg::conv_stroke<agg::ellipse> > ell_stroke2(ell_stroke1);

        ell_stroke2.width(2.0);
        rs.color(agg::rgba(0,0.2,0));
        ras2.add_path(ell_stroke2);
        agg::render_scanlines(ras2, sl, rs);

        typedef agg::span_simple_blur_rgb24<agg::order_bgr> span_blur_gen;
        typedef agg::span_allocator<span_blur_gen::color_type> span_blur_alloc;

        span_blur_alloc sa;
        span_blur_gen sg;

        sg.source_image(rbuf_img(0));
        ras2.add_path(ell);

        copy_window_to_img(0);
        agg::render_scanlines_aa(ras2, sl2, rb, sa, sg);

        // More blur if desired :-)
        //copy_window_to_img(0);
        //agg::render_scanlines(ras2, sl2, rblur);
        //copy_window_to_img(0);
        //agg::render_scanlines(ras2, sl2, rblur);
        //copy_window_to_img(0);
        //agg::render_scanlines(ras2, sl2, rblur);
    }
예제 #9
0
 virtual void on_init()
 {
     m_mouse_y = initial_height() / 2;
     m_mouse_x = initial_width() / 2;
 }
예제 #10
0
    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
    }
예제 #11
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);
    }
예제 #12
0
파일: image1.cpp 프로젝트: xwang2713/agg
    virtual void on_draw()
    {
        typedef agg::renderer_base<pixfmt>     renderer_base;
        typedef agg::renderer_base<pixfmt_pre> renderer_base_pre;

        pixfmt            pixf(rbuf_window());
        pixfmt_pre        pixf_pre(rbuf_window());
        renderer_base     rb(pixf);
        renderer_base_pre rb_pre(pixf_pre);

        rb.clear(agg::rgba(1.0, 1.0, 1.0));

        agg::trans_affine src_mtx;
        src_mtx *= agg::trans_affine_translation(-initial_width()/2 - 10, -initial_height()/2 - 20 - 10);
        src_mtx *= agg::trans_affine_rotation(m_angle.value() * agg::pi / 180.0);
        src_mtx *= agg::trans_affine_scaling(m_scale.value());
        src_mtx *= agg::trans_affine_translation(initial_width()/2, initial_height()/2 + 20);
        src_mtx *= trans_affine_resizing();

        agg::trans_affine img_mtx;
        img_mtx *= agg::trans_affine_translation(-initial_width()/2 + 10, -initial_height()/2 + 20 + 10);
        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(initial_width()/2, initial_height()/2 + 20);
        img_mtx *= trans_affine_resizing();
        img_mtx.invert();

        agg::span_allocator<color_type> sa;

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

        typedef agg::image_accessor_clip<pixfmt> img_source_type;

        pixfmt img_pixf(rbuf_img(0));
        img_source_type img_src(img_pixf, agg::rgba_pre(0, 0.4, 0, 0.5));

        /*
                // 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_pre(0, 0.4, 0, 0.5), 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;
        ras.clip_box(0, 0, width(), height());
        agg::scanline_u8 sl;
        double r = initial_width();
        if(initial_height() - 60 < r) r = initial_height() - 60;
        agg::ellipse ell(initial_width()  / 2.0 + 10,
                         initial_height() / 2.0 + 20 + 10,
                         r / 2.0 + 16.0,
                         r / 2.0 + 16.0, 200);


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

        ras.add_path(tr);
        agg::render_scanlines_aa(ras, sl, rb_pre, sa, sg);

        agg::render_ctrl(ras, sl, rb, m_angle);
        agg::render_ctrl(ras, sl, rb, m_scale);
    }
예제 #13
0
    virtual void on_draw()
    {
        typedef agg::pixfmt_bgr24 pixfmt;
        typedef agg::renderer_base<pixfmt> renderer_base;
        typedef agg::renderer_scanline_aa_solid<renderer_base> renderer_solid;

        pixfmt pixf(rbuf_window());
        renderer_base rb(pixf);
        renderer_solid rs(rb);

        rb.clear(agg::rgba(1.0, 1.0, 1.0));
        agg::rasterizer_scanline_aa<> ras;
        agg::scanline_p8 sl;

        double x_start = 125.0;
        double x_end   = initial_width() - 15.0;
        double y_start = 10.0;
        double y_end   = initial_height() - 10.0;
        double x_center = (x_start + x_end) / 2;

        unsigned i;

        agg::path_storage p;
        agg::conv_stroke<agg::path_storage> pl(p);
        agg::conv_transform<agg::conv_stroke<agg::path_storage> > tr(pl, trans_affine_resizing());

        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(tr);
            rs.color(agg::rgba8(0, 0, 0, i == 8 ? 255 : 100));
            agg::render_scanlines(ras, sl, rs);
        }

        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(tr);
        rs.color(agg::rgba8(0, 0, 0));
        agg::render_scanlines(ras, sl, rs);


        pl.width(1.0);

        for(i = 0; i < m_num_filters; i++)
        {
            if(m_filters[i]->status())
            {
                m_filter_func[i]->set_radius(m_radius.value());
                unsigned j;

                double radius = m_filter_func[i]->radius();
                unsigned n = unsigned(radius * 256 * 2);
                double dy = y_end - ys;

                double xs = (x_end + x_start)/2.0 - (radius * (x_end - x_start) / 16.0);
                double dx = (x_end - x_start) * radius / 8.0;

                p.remove_all();
                p.move_to(xs+0.5, ys + dy * m_filter_func[i]->calc_weight(-radius));
                for(j = 1; j < n; j++)
                {
                    p.line_to(xs + dx * j / n + 0.5,
                              ys + dy * m_filter_func[i]->calc_weight(j / 256.0 - radius));
                }
                ras.add_path(tr);
                rs.color(agg::rgba8(100, 0, 0));
                agg::render_scanlines(ras, sl, rs);

                p.remove_all();
                unsigned xint;
                int ir = int(ceil(radius) + 0.1);

                for(xint = 0; xint < 256; xint++)
                {
                    int xfract;
                    double sum = 0;
                    for(xfract = -ir; xfract < ir; xfract++)
                    {
                        double xf = xint/256.0 + xfract;
                        if(xf >= -radius || xf <= radius)
                        {
                            sum += m_filter_func[i]->calc_weight(xf);
                        }
                    }

                    double x = x_center + ((-128.0 + xint) / 128.0) * radius * (x_end - x_start) / 16.0;
                    double y = ys + sum * 256 - 256;

                    if(xint == 0) p.move_to(x, y);
                    else          p.line_to(x, y);
                }
                ras.add_path(tr);
                rs.color(agg::rgba8(0, 100, 0));
                agg::render_scanlines(ras, sl, rs);

                agg::image_filter_lut normalized(*m_filter_func[i]);
                const agg::int16* weights = normalized.weight_array();

                xs = (x_end + x_start)/2.0 - (normalized.diameter() * (x_end - x_start) / 32.0);
                unsigned nn = normalized.diameter() * 256;
                p.remove_all();
                p.move_to(xs+0.5, ys + dy * weights[0] / agg::image_filter_scale);
                for(j = 1; j < nn; j++)
                {
                    p.line_to(xs + dx * j / n + 0.5,
                              ys + dy * weights[j] / agg::image_filter_scale);
                }
                ras.add_path(tr);
                rs.color(agg::rgba8(0, 0, 100, 255));
                agg::render_scanlines(ras, sl, rs);
            }
        }

        for(i = 0; i < m_num_filters; i++)
        {
            agg::render_ctrl(ras, sl, rb, *m_filters[i]);
        }
        if(m_sinc.status() || m_lanczos.status() || m_blackman.status())
        {
            agg::render_ctrl(ras, sl, rb, m_radius);
        }
    }
예제 #14
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);
    }
예제 #15
0
 //------------------------------------------------------------------------
 virtual void on_init()
 {
     m_polygon_cx = initial_width() / 2.0;
     m_polygon_cy = initial_height() / 2.0;
     generate_pattern();
 }
예제 #16
0
int MonitorWindow::initial_top()    { return  pw->screen_height() - initial_height(); }