예제 #1
0
void render_raster_marker(RendererType ren,
                          RasterizerType & ras,
                          image_data_rgba8 & src,
                          mapnik::feature_impl const& feature,
                          agg::trans_affine const& marker_tr,
                          double opacity)
{
    using color_type = typename RendererType::color_type;
    agg::scanline_bin sl;
    double width  = src.width();
    double height = src.height();
    double p[8];
    p[0] = 0;     p[1] = 0;
    p[2] = width; p[3] = 0;
    p[4] = width; p[5] = height;
    p[6] = 0;     p[7] = height;
    marker_tr.transform(&p[0], &p[1]);
    marker_tr.transform(&p[2], &p[3]);
    marker_tr.transform(&p[4], &p[5]);
    marker_tr.transform(&p[6], &p[7]);
    ras.move_to_d(p[0],p[1]);
    ras.line_to_d(p[2],p[3]);
    ras.line_to_d(p[4],p[5]);
    ras.line_to_d(p[6],p[7]);
    ren.color(color_type(feature.id()));
    agg::render_scanlines(ras, sl, ren);
}
예제 #2
0
void CAggMemoryDC::Rect(
    const GraphTypes::PointF& tl, 
    const GraphTypes::PointF& br,
    const GraphTypes::Color& clrfill,
    const GraphTypes::Color& clroutline,
    GraphTypes::REAL outline_width/*=1.0*/,
    bool bAA/*=false*/)
{
    if (m_buf==0)
        return;

    if(bAA)
    {
        PointF points[4];
        points[0].x=tl.x;
        points[0].y=tl.y;
        points[1].x=br.x;
        points[1].y=tl.y;
        points[2].x=br.x;
        points[2].y=br.y;
        points[3].x=tl.x;
        points[3].y=br.y;

        SolidPolygon(points, clrfill, 4, outline_width, clroutline); 
    }
    else
    {
        pixel_format pixf(m_rbuf);
        ren_base renb(pixf);

        primitive_renderer pren(renb);

        pren.fill_color(agg::rgba8(
            clrfill.GetR(),
            clrfill.GetG(),
            clrfill.GetB(),
            clrfill.GetA()));
        pren.line_color(agg::rgba8(
            clroutline.GetR(),
            clroutline.GetG(),
            clroutline.GetB(),
            clroutline.GetA()));

        double topx(tl.x), topy(tl.y), bottomx(br.x), bottomy(br.y);
        m_mtx.transform(&topx,&topy);
        m_mtx.transform(&bottomx,&bottomy);
        int x1=round_int(topx); 
        int y1=round_int(topy); 
        int x2=round_int(bottomx); 
        int y2=round_int(bottomy); 

        pren.solid_rectangle(x1, y1, x2, y2);
        pren.rectangle(x1, y1, x2, y2);
    }
}
예제 #3
0
파일: box2d.cpp 프로젝트: chillycher/mapnik
box2d<T>::box2d(const box2d_type &rhs, const agg::trans_affine& tr)
{
    double x0 = rhs.minx_, y0 = rhs.miny_;
    double x1 = rhs.maxx_, y1 = rhs.miny_;
    double x2 = rhs.maxx_, y2 = rhs.maxy_;
    double x3 = rhs.minx_, y3 = rhs.maxy_;
    tr.transform(&x0, &y0);
    tr.transform(&x1, &y1);
    tr.transform(&x2, &y2);
    tr.transform(&x3, &y3);
    init(x0, y0, x2, y2);
    expand_to_include(x1, y1);
    expand_to_include(x3, y3);
}
예제 #4
0
void CAggMemoryDC::Line(
    const PointF& p1,
    const PointF& p2, 
    const Color& clr)
{
    if (m_buf==0)
        return;

    CPoint _p1 = p1;
    CPoint _p2 = p2;

    pixel_format pixf(m_rbuf);
    ren_base renb(pixf);

    outline_renderer outline_rd(renb, s_lineprof);
    outline_rasterizer_aa outline_rt(outline_rd);

    outline_rd.profile(s_lineprof);
    outline_rd.color(agg::rgba8(clr.GetR(), clr.GetG(), clr.GetB(), clr.GetA()));
    outline_rd.clip_box(0, 0, m_rcUpdate.Width(), m_rcUpdate.Height());

    double p1x(p1.x), p1y(p1.y), p2x(p2.x), p2y(p2.y);
    m_mtx.transform(&p1x,&p1y);
    m_mtx.transform(&p2x,&p2y);

    outline_rt.move_to_d(p1x, p1y);
    outline_rt.line_to_d(p2x, p2y);
    //outline_rt.round_cap( 1 );
    outline_rt.render(false);
}
예제 #5
0
 void render_raster_marker(agg::trans_affine const& marker_tr)
 {
     double width  = src_.width();
     double height = src_.height();
     double p[8];
     p[0] = 0;     p[1] = 0;
     p[2] = width; p[3] = 0;
     p[4] = width; p[5] = height;
     p[6] = 0;     p[7] = height;
     marker_tr.transform(&p[0], &p[1]);
     marker_tr.transform(&p[2], &p[3]);
     marker_tr.transform(&p[4], &p[5]);
     marker_tr.transform(&p[6], &p[7]);
     ras_.move_to_d(p[0],p[1]);
     ras_.line_to_d(p[2],p[3]);
     ras_.line_to_d(p[4],p[5]);
     ras_.line_to_d(p[6],p[7]);
     RendererType ren(renb_);
     ren.color(color_type(feature_.id()));
     agg::render_scanlines(ras_, sl_, ren);
 }
예제 #6
0
 void render_raster_marker(agg::trans_affine const& marker_tr,
                           double opacity)
 {
     double width  = src_.width();
     double height = src_.height();
     double p[8];
     p[0] = 0;     p[1] = 0;
     p[2] = width; p[3] = 0;
     p[4] = width; p[5] = height;
     p[6] = 0;     p[7] = height;
     marker_tr.transform(&p[0], &p[1]);
     marker_tr.transform(&p[2], &p[3]);
     marker_tr.transform(&p[4], &p[5]);
     marker_tr.transform(&p[6], &p[7]);
     ras_.move_to_d(p[0],p[1]);
     ras_.line_to_d(p[2],p[3]);
     ras_.line_to_d(p[4],p[5]);
     ras_.line_to_d(p[6],p[7]);
     agg::span_allocator<color_type> sa;
     agg::image_filter_bilinear filter_kernel;
     agg::image_filter_lut filter(filter_kernel, false);
     agg::rendering_buffer marker_buf((unsigned char *)src_.getBytes(),
                                      src_.width(),
                                      src_.height(),
                                      src_.width()*4);
     agg::pixfmt_rgba32_pre pixf(marker_buf);
     typedef agg::image_accessor_clone<agg::pixfmt_rgba32_pre> img_accessor_type;
     typedef agg::span_interpolator_linear<agg::trans_affine> interpolator_type;
     typedef agg::span_image_filter_rgba_2x2<img_accessor_type,
                                             interpolator_type> span_gen_type;
     typedef agg::renderer_scanline_aa_alpha<renderer_base,
             agg::span_allocator<color_type>,
             span_gen_type> renderer_type;
     img_accessor_type ia(pixf);
     interpolator_type interpolator(agg::trans_affine(p, 0, 0, width, height) );
     span_gen_type sg(ia, interpolator, filter);
     renderer_type rp(renb_,sa, sg, unsigned(opacity*255));
     agg::render_scanlines(ras_, sl_, rp);
 }
예제 #7
0
//-----------------------------------------------------------------------------
int CAggMemoryDC::SetDIBitsToDevice(
    int x, 
    int y, 
    DWORD dwWidth, 
    DWORD dwHeight, 
    int xSrc, 
    int ySrc, 
    UINT uStartScan, 
    UINT cScanLines, 
    CONST VOID* lpvBits, 
    CONST BITMAPINFO* lpbmi, 
    UINT uColorUse)
{
    double dx = x;
    double dy = y;
    m_mtx.transform(&dx,&dy);
    return ::SetDIBitsToDevice(m_hDC, x, y, dwWidth, dwHeight, xSrc, ySrc, uStartScan, cScanLines, lpvBits, lpbmi, uColorUse);
}
예제 #8
0
Bounds::Bounds(const agg::trans_affine& trans, 
               agg::path_storage* path, pathAttr* attr, double dilation,
               double scale)
{
    double centx = attr->mCentroid.x;
    double centy = attr->mCentroid.y;
    trans.transform(&centx, &centy);

    mValid = attr->boundingRect(path, trans, mMin_X, mMin_Y, mMax_X, mMax_Y, scale);
    
    if (mValid && mMin_X <= centx && mMax_X >= centx &&
                  mMin_Y <= centy && mMax_Y >= centy && dilation != 1.0)
    {
        mMin_X = dilation * (mMin_X - centx) + centx;
        mMax_X = dilation * (mMax_X - centx) + centx;
        mMin_Y = dilation * (mMin_Y - centy) + centy;
        mMax_Y = dilation * (mMax_Y - centy) + centy;
    }
}
예제 #9
0
파일: draw_selection.cpp 프로젝트: hatc/ekc
void SelectionScanlineSweeper::DrawImpl_rgb(agg::rect_d rect, RenderingData *data, unsigned int width, unsigned int height, int stride,
																				agg::trans_affine const &mtx, agg::trans_affine const &viewport_mtx) {
	//ScanlineSource source(data);

	typedef agg::pixfmt_alpha_blend_rgb<agg::blender_rgb<agg::rgba8,  agg::order_rgb>, agg::scanline_accessor> pixfmt_type;
	typedef pixfmt_type::color_type                        color_type;
	typedef color_type::value_type                         value_type;
	typedef agg::renderer_base<pixfmt_type>                renderer_base;
	typedef agg::renderer_scanline_aa_solid<renderer_base> renderer_solid;

	agg::rasterizer_scanline_aa<> l_rasterizer;
	agg::scanline_u8              l_scanline;

	//pixfmt_type       pixfmt(agg::scanline_accessor(&source, ScanlineSource::get_scanline, width, height, stride));
	pixfmt_type       pixfmt((agg::scanline_accessor(data)));
	renderer_base     rb(pixfmt);

	l_rasterizer.clip_box(0.0, 0.0, width, height);
	l_rasterizer.filling_rule(agg::fill_non_zero);
	
	if (flip_y) {
		mtx.transform(&rect.x1, &rect.y1);
		mtx.transform(&rect.x2, &rect.y2);
	}
	
	double vertexes[] = {
		rect.x1, rect.y2,
		rect.x1, rect.y1,
		rect.x2, rect.y1,
		rect.x2, rect.y2
	};
	
	agg::test_vertex_source vertex_source(vertexes, 4);
	agg::conv_transform<agg::test_vertex_source> vertex_source_converted(vertex_source, viewport_mtx);
	l_rasterizer.add_path(vertex_source_converted);
	
	renderer_solid r(rb);
	{
		r.color(color);
		agg::render_scanlines(l_rasterizer, l_scanline, r);
	}
}
예제 #10
0
bool CAggMemoryDC::DrawTransparent(
    HBITMAP hBitmap,
    int x, 
    int y,
    int width,
    int height,
    int bmpWidth,
    int bmpHeight,
    COLORREF color)
{
    ATLASSERT(width>0&&height>0);
    double dx = x;
    double dy = y;
    m_mtx.transform(&dx,&dy);

    CDC dcImage;
    bool bOk=dcImage.CreateCompatibleDC(m_hDC) != NULL;
    HBITMAP oldbmp=dcImage.SelectBitmap(hBitmap);

    // if OS supports non-leaky TransparentBlt use it (also on printer)
    if(s_bTransOk)
    {
#ifndef _WIN32_WCE
        bOk=TransparentBlt(x, y, width, height, dcImage, 0, 0, bmpWidth, bmpHeight, color) != 0;
        if (!bOk) // just in case (e.g. printing), try emulation
            goto tryEmulate;
#endif
    }
    else
    {
tryEmulate:
        CBitmap bmpMono;
        bOk=bmpMono.CreateBitmap(width, height, 1, 1, NULL) != NULL;
        if (!bOk)
            return bOk;

        CDC dcMono;
        // Create dc for the mask
        bOk = dcMono.CreateCompatibleDC(m_hDC) != NULL;
        if (!bOk)
            return bOk;

        // Select the mask bitmap into its dc
        HBITMAP oldBitmapMono = (HBITMAP)::SelectObject(dcMono, bmpMono);

        if(bOk)
        {
            // Build mask based on transparent colour

            COLORREF crOldImg=dcImage.SetBkColor(color);
            bOk=dcMono.StretchBlt(0, 0, width, height, dcImage, 0, 0, bmpWidth, bmpHeight, SRCCOPY) != 0;
            dcImage.SetBkColor(crOldImg);

            // True Mask method - no flicker if destination is not actual display
            if(bOk)
                bOk=StretchBlt(x, y, width, height, dcImage, 0, 0, bmpWidth, bmpHeight, SRCINVERT) != 0;

            if(bOk) 
            {
                // setup the destination for monochrome blit
                COLORREF crOldBack = SetBkColor(RGB(255,255,255));
                COLORREF crOldText = SetTextColor(RGB(0,0,0));

                bOk=BitBlt(x, y, width, height, dcMono, 0, 0, SRCAND) != 0;

                SetBkColor(crOldBack);
                SetTextColor(crOldText);
            }

            if(bOk)
                bOk=StretchBlt(x, y, width, height, dcImage, 0, 0, bmpWidth, bmpHeight, SRCINVERT) != 0;
        }

        dcMono.SelectBitmap(oldBitmapMono);
    }

    dcImage.SelectBitmap(oldbmp);

    return bOk;
}
예제 #11
0
    void render_raster_marker(agg::trans_affine const& marker_tr,
                              double opacity)
    {
        using pixfmt_pre = agg::pixfmt_rgba32_pre;
        agg::scanline_u8 sl_;
        double width  = src_.width();
        double height = src_.height();
        if (std::fabs(1.0 - scale_factor_) < 0.001
            && (std::fabs(1.0 - marker_tr.sx) < agg::affine_epsilon)
            && (std::fabs(0.0 - marker_tr.shy) < agg::affine_epsilon)
            && (std::fabs(0.0 - marker_tr.shx) < agg::affine_epsilon)
            && (std::fabs(1.0 - marker_tr.sy) < agg::affine_epsilon))
        {
            agg::rendering_buffer src_buffer((unsigned char *)src_.getBytes(),src_.width(),src_.height(),src_.width() * 4);
            pixfmt_pre pixf_mask(src_buffer);
            if (snap_to_pixels_)
            {
                renb_.blend_from(pixf_mask,
                                 0,
                                 std::floor(marker_tr.tx + .5),
                                 std::floor(marker_tr.ty + .5),
                                 unsigned(255*opacity));
            }
            else
            {
                renb_.blend_from(pixf_mask,
                                 0,
                                 marker_tr.tx,
                                 marker_tr.ty,
                                 unsigned(255*opacity));
            }
        }
        else
        {
            using img_accessor_type = agg::image_accessor_clone<pixfmt_pre>;
            using interpolator_type = agg::span_interpolator_linear<>;
            //using span_gen_type = agg::span_image_filter_rgba_2x2<img_accessor_type,interpolator_type>;
            using span_gen_type = agg::span_image_resample_rgba_affine<img_accessor_type>;
            using renderer_type = agg::renderer_scanline_aa_alpha<renderer_base,
                                                                  agg::span_allocator<color_type>,
                                                                  span_gen_type>;

            double p[8];
            p[0] = 0;     p[1] = 0;
            p[2] = width; p[3] = 0;
            p[4] = width; p[5] = height;
            p[6] = 0;     p[7] = height;
            marker_tr.transform(&p[0], &p[1]);
            marker_tr.transform(&p[2], &p[3]);
            marker_tr.transform(&p[4], &p[5]);
            marker_tr.transform(&p[6], &p[7]);
            agg::span_allocator<color_type> sa;
            agg::image_filter_lut filter;
            filter.calculate(agg::image_filter_bilinear(), true);
            agg::rendering_buffer marker_buf((unsigned char *)src_.getBytes(),
                                             src_.width(),
                                             src_.height(),
                                             src_.width()*4);
            pixfmt_pre pixf(marker_buf);
            img_accessor_type ia(pixf);
            agg::trans_affine final_tr(p, 0, 0, width, height);
            if (snap_to_pixels_)
            {
                final_tr.tx = std::floor(final_tr.tx+.5);
                final_tr.ty = std::floor(final_tr.ty+.5);
            }
            interpolator_type interpolator(final_tr);
            span_gen_type sg(ia, interpolator, filter);
            renderer_type rp(renb_,sa, sg, unsigned(opacity*255));
            ras_.move_to_d(p[0],p[1]);
            ras_.line_to_d(p[2],p[3]);
            ras_.line_to_d(p[4],p[5]);
            ras_.line_to_d(p[6],p[7]);
            agg::render_scanlines(ras_, sl_, rp);
        }
    }
예제 #12
0
void render_raster_marker(RendererType renb, RasterizerType & ras, image_rgba8 const& src,
                          agg::trans_affine const& tr, double opacity,
                          float scale_factor, bool snap_to_pixels)
{
    using color_type = agg::rgba8;
    using const_rendering_buffer = util::rendering_buffer<image_rgba8>;
    using pixfmt_pre = agg::pixfmt_alpha_blend_rgba<agg::blender_rgba32_pre, const_rendering_buffer, agg::pixel32_type>;

    agg::scanline_u8 sl;
    double width  = src.width();
    double height = src.height();
    if (std::fabs(1.0 - scale_factor) < 0.001
        && (std::fabs(1.0 - tr.sx) < agg::affine_epsilon)
        && (std::fabs(0.0 - tr.shy) < agg::affine_epsilon)
        && (std::fabs(0.0 - tr.shx) < agg::affine_epsilon)
        && (std::fabs(1.0 - tr.sy) < agg::affine_epsilon))
    {
        const_rendering_buffer src_buffer(src);
        pixfmt_pre pixf_mask(src_buffer);
        if (snap_to_pixels)
        {
            renb.blend_from(pixf_mask,
                            0,
                            static_cast<int>(std::floor(tr.tx + .5)),
                            static_cast<int>(std::floor(tr.ty + .5)),
                            unsigned(255*opacity));
        }
        else
        {
            renb.blend_from(pixf_mask,
                            0,
                            static_cast<int>(tr.tx),
                            static_cast<int>(tr.ty),
                            unsigned(255*opacity));
        }
    }
    else
    {
        using img_accessor_type = agg::image_accessor_clone<pixfmt_pre>;
        using interpolator_type = agg::span_interpolator_linear<>;
        //using span_gen_type = agg::span_image_filter_rgba_2x2<img_accessor_type,interpolator_type>;
        using span_gen_type = agg::span_image_resample_rgba_affine<img_accessor_type>;
        using renderer_type = agg::renderer_scanline_aa_alpha<RendererType,
                                                              agg::span_allocator<color_type>,
                                                              span_gen_type>;

        double p[8];
        p[0] = 0;     p[1] = 0;
        p[2] = width; p[3] = 0;
        p[4] = width; p[5] = height;
        p[6] = 0;     p[7] = height;
        tr.transform(&p[0], &p[1]);
        tr.transform(&p[2], &p[3]);
        tr.transform(&p[4], &p[5]);
        tr.transform(&p[6], &p[7]);
        agg::span_allocator<color_type> sa;
        agg::image_filter_lut filter;
        filter.calculate(agg::image_filter_bilinear(), true);
        const_rendering_buffer src_buffer(src);
        pixfmt_pre pixf(src_buffer);
        img_accessor_type ia(pixf);
        agg::trans_affine final_tr(p, 0, 0, width, height);
        if (snap_to_pixels)
        {
            final_tr.tx = std::floor(final_tr.tx+.5);
            final_tr.ty = std::floor(final_tr.ty+.5);
        }
        interpolator_type interpolator(final_tr);
        span_gen_type sg(ia, interpolator, filter);
        renderer_type rp(renb, sa, sg, unsigned(opacity*255));
        ras.move_to_d(p[0],p[1]);
        ras.line_to_d(p[2],p[3]);
        ras.line_to_d(p[4],p[5]);
        ras.line_to_d(p[6],p[7]);
        agg::render_scanlines(ras, sl, rp);
    }
}