From: buliabyak Date: Tue, 24 Jun 2008 02:28:57 +0000 (+0000) Subject: add helpers for creating cairo_t for a canvas buf X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=2aa7286c975e2f20280576be54adfa67d861cd7f;p=inkscape.git add helpers for creating cairo_t for a canvas buf --- diff --git a/src/display/inkscape-cairo.cpp b/src/display/inkscape-cairo.cpp index f97129031..063b56ae5 100644 --- a/src/display/inkscape-cairo.cpp +++ b/src/display/inkscape-cairo.cpp @@ -20,6 +20,7 @@ #include #include "../style.h" #include "nr-arena.h" +#include "sp-canvas.h" #include <2geom/pathvector.h> #include <2geom/matrix.h> #include <2geom/point.h> @@ -29,28 +30,43 @@ /** Creates a cairo context to render to the given pixblock on the given area */ cairo_t * -nr_create_cairo_context (NRRectL *area, NRPixBlock *pb) +nr_create_cairo_context_for_data (NRRectL *area, NRRectL *buf_area, unsigned char *px, unsigned int rowstride) { - if (!nr_rect_l_test_intersect (&pb->area, area)) + if (!nr_rect_l_test_intersect (buf_area, area)) return NULL; NRRectL clip; - nr_rect_l_intersect (&clip, &pb->area, area); - unsigned char *dpx = NR_PIXBLOCK_PX (pb) + (clip.y0 - pb->area.y0) * pb->rs + NR_PIXBLOCK_BPP (pb) * (clip.x0 - pb->area.x0); + nr_rect_l_intersect (&clip, buf_area, area); + unsigned char *dpx = px + (clip.y0 - buf_area->y0) * rowstride + 4 * (clip.x0 - buf_area->x0); int width = area->x1 - area->x0; int height = area->y1 - area->y0; // even though cairo cannot draw in nonpremul mode, select ARGB32 for R8G8B8A8N as the closest; later eliminate R8G8B8A8N everywhere cairo_surface_t* cst = cairo_image_surface_create_for_data (dpx, - ((pb->mode == NR_PIXBLOCK_MODE_R8G8B8A8P || pb->mode == NR_PIXBLOCK_MODE_R8G8B8A8N) ? CAIRO_FORMAT_ARGB32 : (pb->mode == NR_PIXBLOCK_MODE_R8G8B8? CAIRO_FORMAT_RGB24 : CAIRO_FORMAT_A8)), + CAIRO_FORMAT_ARGB32, width, height, - pb->rs); + rowstride); cairo_t *ct = cairo_create (cst); return ct; } +/** Creates a cairo context to render to the given SPCanvasBuf on the given area */ +cairo_t * +nr_create_cairo_context_canvasbuf (NRRectL *area, SPCanvasBuf *b) +{ + return nr_create_cairo_context_for_data (&(b->rect), &(b->rect), b->buf, b->buf_rowstride); +} + + +/** Creates a cairo context to render to the given NRPixBlock on the given area */ +cairo_t * +nr_create_cairo_context (NRRectL *area, NRPixBlock *pb) +{ + return nr_create_cairo_context_for_data (area, &(pb->area), NR_PIXBLOCK_PX (pb), pb->rs); +} + /** Feeds path-creating calls to the cairo context translating them from the SPCurve, with the given transform and shift */ void feed_curve_to_cairo (cairo_t *ct, NArtBpath const *bpath, NR::Matrix trans, NR::Maybe area, bool optimize_stroke, double stroke_width) diff --git a/src/display/inkscape-cairo.h b/src/display/inkscape-cairo.h index 58235523f..40cc77e76 100644 --- a/src/display/inkscape-cairo.h +++ b/src/display/inkscape-cairo.h @@ -13,6 +13,9 @@ #include <2geom/forward.h> +class SPCanvasBuf; + +cairo_t *nr_create_cairo_context_canvasbuf (NRRectL *area, SPCanvasBuf *b); cairo_t *nr_create_cairo_context (NRRectL *area, NRPixBlock *pb); void feed_curve_to_cairo (cairo_t *ct, NArtBpath const *bpath, NR::Matrix trans, NR::Maybe area, bool optimize_stroke, double stroke_width); void feed_path_to_cairo (cairo_t *ct, Geom::Path const &path, Geom::Matrix trans, NR::Maybe area, bool optimize_stroke, double stroke_width);