[cairo] Storing and repainting a rectangular region of interest
David Weiß
David.Weiss at ptvgroup.com
Fri May 23 07:41:27 PDT 2014
Hello,
I have the following problem:
I have to integrate cairo into an existing rendering application so I need to stick to the applications API as close as possible.
It requires me to implement two functions which work on rectangles:
The first gets a rectangle specification (x,y,width,height) and needs to save that exact area of the painted surface somehow, the second just restores the last saved rectangle.
My (not working) implementation looks like this:
void CairoEngine::SaveRegion(ptvlib::CRectI region)
{
cairo_surface_t* saved_surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, region.Width(), region.Height());
cairo_t* saved_context = cairo_create(saved_surface);
cairo_set_source_surface(saved_context, win32_surface, -region.left, -region.top);
cairo_set_operator(saved_context, CAIRO_OPERATOR_SOURCE);
cairo_paint(saved_context);
cairo_surface_flush(saved_surface);
cairo_destroy(saved_context);
saved_regions.push(std::make_pair(region, saved_surface));
}
void CairoEngine::ReplayRegion()
{
if(saved_regions.empty()) return;
ptvlib::CRectI region = saved_regions.top().first;
cairo_surface_t* saved_surface = saved_regions.top().second;
cairo_save(win32_context);
cairo_set_operator(win32_context, CAIRO_OPERATOR_SOURCE);
cairo_set_source_surface(win32_context, saved_surface, region.left, region.bottom);
cairo_paint(win32_context);
cairo_surface_flush(win32_surface);
cairo_surface_destroy(saved_surface);
cairo_restore(win32_context);
saved_regions.pop();
}
Any hints what I'm doing wrong?
Cheers,
--
David Weiß
Logistics Geographic Components
PTV GROUP
Haid-und-Neu-Str. 15, 76131 Karlsruhe, Germany
Phone +49 (0) 721 9651-7416
david.weiss at ptvgroup.com<mailto:david.weiss at ptvgroup.com>
www.ptvgroup.com<http://www.ptvgroup.com/>
http://www.facebook.com/pages/PTV-AG/308012842618
PTV Planung Transport Verkehr AG
Headquarters: Karlsruhe
Executive Board: Vincent Kobesen (CEO), Dr.-Ing. Thomas Schwerdtfeger
Chairman of the Supervisory Board: Dr. h.c. Frank-Jürgen Weise
Commercial Register (HRB-Nr): 109262
Local Court: Mannheim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cairographics.org/archives/cairo/attachments/20140523/ffc6bbcd/attachment.html>
More information about the cairo
mailing list