From 31f84a59da72b31b932833ce1af7d78f0a67e185 Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Sat, 26 Jun 2010 03:02:06 +0200 Subject: Implement clipping (slightly incorrect) and masking (bzr r9508.1.4) --- src/display/cairo-utils.cpp | 113 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 src/display/cairo-utils.cpp (limited to 'src/display/cairo-utils.cpp') diff --git a/src/display/cairo-utils.cpp b/src/display/cairo-utils.cpp new file mode 100644 index 000000000..58db5d551 --- /dev/null +++ b/src/display/cairo-utils.cpp @@ -0,0 +1,113 @@ +/* + * Helper functions to use cairo with inkscape + * + * Copyright (C) 2007 bulia byak + * Copyright (C) 2008 Johan Engelen + * + * Released under GNU GPL + * + */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include +#include <2geom/matrix.h> +#include "display/cairo-utils.h" +#include "display/inkscape-cairo.h" +#include "color.h" + +namespace Inkscape { + +CairoGroup::CairoGroup(cairo_t *_ct) : ct(_ct), pushed(false) {} +CairoGroup::~CairoGroup() { + if (pushed) { + cairo_pattern_t *p = cairo_pop_group(ct); + cairo_pattern_destroy(p); + } +} +void CairoGroup::push() { + cairo_push_group(ct); + pushed = true; +} +void CairoGroup::push_with_content(cairo_content_t content) { + cairo_push_group_with_content(ct, content); + pushed = true; +} +cairo_pattern_t *CairoGroup::pop() { + if (pushed) { + cairo_pattern_t *ret = cairo_pop_group(ct); + pushed = false; + return ret; + } else { + throw std::logic_error("Cairo group popped without pushing it first"); + } +} +Cairo::RefPtr CairoGroup::popmm() { + if (pushed) { + cairo_pattern_t *ret = cairo_pop_group(ct); + Cairo::RefPtr retmm(new Cairo::Pattern(ret, true)); + pushed = false; + return retmm; + } else { + throw std::logic_error("Cairo group popped without pushing it first"); + } +} +void CairoGroup::pop_to_source() { + if (pushed) { + cairo_pop_group_to_source(ct); + pushed = false; + } +} + +CairoContext::CairoContext(cairo_t *obj, bool ref) + : Cairo::Context(obj, ref) +{} + +void CairoContext::transform(Geom::Matrix const &m) +{ + cairo_matrix_t cm; + cm.xx = m[0]; + cm.xy = m[2]; + cm.x0 = m[4]; + cm.yx = m[1]; + cm.yy = m[3]; + cm.y0 = m[5]; + cairo_transform(cobj(), &cm); +} + +void CairoContext::set_source_rgba32(guint32 color) +{ + double red = SP_RGBA32_R_F(color); + double gre = SP_RGBA32_G_F(color); + double blu = SP_RGBA32_B_F(color); + double alp = SP_RGBA32_A_F(color); + cairo_set_source_rgba(cobj(), red, gre, blu, alp); +} + +void CairoContext::append_path(Geom::PathVector const &pv) +{ + feed_pathvector_to_cairo(cobj(), pv); +} + +Cairo::RefPtr CairoContext::create(Cairo::RefPtr const &target) +{ + cairo_t *ct = cairo_create(target->cobj()); + Cairo::RefPtr ret(new CairoContext(ct, true)); + return ret; +} + +} // namespace Inkscape + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : -- cgit v1.2.3 From 13b15b7b977eecbededd1734f5ab001f0c44d21f Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Wed, 30 Jun 2010 00:41:48 +0200 Subject: Consolidate Cairo utils in display/cairo-utils.h. Fix icons harder. (bzr r9508.1.8) --- src/display/cairo-utils.cpp | 341 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 338 insertions(+), 3 deletions(-) (limited to 'src/display/cairo-utils.cpp') diff --git a/src/display/cairo-utils.cpp b/src/display/cairo-utils.cpp index 58db5d551..7bfdd7dd7 100644 --- a/src/display/cairo-utils.cpp +++ b/src/display/cairo-utils.cpp @@ -12,12 +12,19 @@ # include #endif +#include "display/cairo-utils.h" + #include -#include +#include <2geom/pathvector.h> +#include <2geom/bezier-curve.h> +#include <2geom/hvlinesegment.h> #include <2geom/matrix.h> -#include "display/cairo-utils.h" -#include "display/inkscape-cairo.h" +#include <2geom/point.h> +#include <2geom/path.h> +#include <2geom/transforms.h> +#include <2geom/sbasis-to-bezier.h> #include "color.h" +#include "helper/geom-curves.h" namespace Inkscape { @@ -101,6 +108,334 @@ Cairo::RefPtr CairoContext::create(Cairo::RefPtr c } // namespace Inkscape +/* + * Can be called recursively. + * If optimize_stroke == false, the view Rect is not used. + */ +static void +feed_curve_to_cairo(cairo_t *cr, Geom::Curve const &c, Geom::Matrix const & trans, Geom::Rect view, bool optimize_stroke) +{ + if( is_straight_curve(c) ) + { + Geom::Point end_tr = c.finalPoint() * trans; + if (!optimize_stroke) { + cairo_line_to(cr, end_tr[0], end_tr[1]); + } else { + Geom::Rect swept(c.initialPoint()*trans, end_tr); + if (swept.intersects(view)) { + cairo_line_to(cr, end_tr[0], end_tr[1]); + } else { + cairo_move_to(cr, end_tr[0], end_tr[1]); + } + } + } + else if(Geom::QuadraticBezier const *quadratic_bezier = dynamic_cast(&c)) { + std::vector points = quadratic_bezier->points(); + points[0] *= trans; + points[1] *= trans; + points[2] *= trans; + Geom::Point b1 = points[0] + (2./3) * (points[1] - points[0]); + Geom::Point b2 = b1 + (1./3) * (points[2] - points[0]); + if (!optimize_stroke) { + cairo_curve_to(cr, b1[0], b1[1], b2[0], b2[1], points[2][0], points[2][1]); + } else { + Geom::Rect swept(points[0], points[2]); + swept.expandTo(points[1]); + if (swept.intersects(view)) { + cairo_curve_to(cr, b1[0], b1[1], b2[0], b2[1], points[2][0], points[2][1]); + } else { + cairo_move_to(cr, points[2][0], points[2][1]); + } + } + } + else if(Geom::CubicBezier const *cubic_bezier = dynamic_cast(&c)) { + std::vector points = cubic_bezier->points(); + //points[0] *= trans; // don't do this one here for fun: it is only needed for optimized strokes + points[1] *= trans; + points[2] *= trans; + points[3] *= trans; + if (!optimize_stroke) { + cairo_curve_to(cr, points[1][0], points[1][1], points[2][0], points[2][1], points[3][0], points[3][1]); + } else { + points[0] *= trans; // didn't transform this point yet + Geom::Rect swept(points[0], points[3]); + swept.expandTo(points[1]); + swept.expandTo(points[2]); + if (swept.intersects(view)) { + cairo_curve_to(cr, points[1][0], points[1][1], points[2][0], points[2][1], points[3][0], points[3][1]); + } else { + cairo_move_to(cr, points[3][0], points[3][1]); + } + } + } +// else if(Geom::SVGEllipticalArc const *svg_elliptical_arc = dynamic_cast(c)) { +// //TODO: get at the innards and spit them out to cairo +// } + else { + //this case handles sbasis as well as all other curve types + Geom::Path sbasis_path = Geom::cubicbezierpath_from_sbasis(c.toSBasis(), 0.1); + + //recurse to convert the new path resulting from the sbasis to svgd + for(Geom::Path::iterator iter = sbasis_path.begin(); iter != sbasis_path.end(); ++iter) { + feed_curve_to_cairo(cr, *iter, trans, view, optimize_stroke); + } + } +} + + +/** Feeds path-creating calls to the cairo context translating them from the Path */ +static void +feed_path_to_cairo (cairo_t *ct, Geom::Path const &path) +{ + if (path.empty()) + return; + + cairo_move_to(ct, path.initialPoint()[0], path.initialPoint()[1] ); + + for(Geom::Path::const_iterator cit = path.begin(); cit != path.end_open(); ++cit) { + feed_curve_to_cairo(ct, *cit, Geom::identity(), Geom::Rect(), false); // optimize_stroke is false, so the view rect is not used + } + + if (path.closed()) { + cairo_close_path(ct); + } +} + +/** Feeds path-creating calls to the cairo context translating them from the Path, with the given transform and shift */ +static void +feed_path_to_cairo (cairo_t *ct, Geom::Path const &path, Geom::Matrix trans, Geom::OptRect area, bool optimize_stroke, double stroke_width) +{ + if (!area) + return; + if (path.empty()) + return; + + // Transform all coordinates to coords within "area" + Geom::Point shift = area->min(); + Geom::Rect view = *area; + view.expandBy (stroke_width); + view = view * (Geom::Matrix)Geom::Translate(-shift); + // Pass transformation to feed_curve, so that we don't need to create a whole new path. + Geom::Matrix transshift(trans * Geom::Translate(-shift)); + + Geom::Point initial = path.initialPoint() * transshift; + cairo_move_to(ct, initial[0], initial[1] ); + + for(Geom::Path::const_iterator cit = path.begin(); cit != path.end_open(); ++cit) { + feed_curve_to_cairo(ct, *cit, transshift, view, optimize_stroke); + } + + if (path.closed()) { + if (!optimize_stroke) { + cairo_close_path(ct); + } else { + cairo_line_to(ct, initial[0], initial[1]); + /* We cannot use cairo_close_path(ct) here because some parts of the path may have been + clipped and not drawn (maybe the before last segment was outside view area), which + would result in closing the "subpath" after the last interruption, not the entire path. + + However, according to cairo documentation: + The behavior of cairo_close_path() is distinct from simply calling cairo_line_to() with the equivalent coordinate + in the case of stroking. When a closed sub-path is stroked, there are no caps on the ends of the sub-path. Instead, + there is a line join connecting the final and initial segments of the sub-path. + + The correct fix will be possible when cairo introduces methods for moving without + ending/starting subpaths, which we will use for skipping invisible segments; then we + will be able to use cairo_close_path here. This issue also affects ps/eps/pdf export, + see bug 168129 + */ + } + } +} + +/** Feeds path-creating calls to the cairo context translating them from the PathVector, with the given transform and shift + * One must have done cairo_new_path(ct); before calling this function. */ +void +feed_pathvector_to_cairo (cairo_t *ct, Geom::PathVector const &pathv, Geom::Matrix trans, Geom::OptRect area, bool optimize_stroke, double stroke_width) +{ + if (!area) + return; + if (pathv.empty()) + return; + + for(Geom::PathVector::const_iterator it = pathv.begin(); it != pathv.end(); ++it) { + feed_path_to_cairo(ct, *it, trans, area, optimize_stroke, stroke_width); + } +} + +/** Feeds path-creating calls to the cairo context translating them from the PathVector + * One must have done cairo_new_path(ct); before calling this function. */ +void +feed_pathvector_to_cairo (cairo_t *ct, Geom::PathVector const &pathv) +{ + if (pathv.empty()) + return; + + for(Geom::PathVector::const_iterator it = pathv.begin(); it != pathv.end(); ++it) { + feed_path_to_cairo(ct, *it); + } +} + +void +ink_cairo_set_source_rgba32(cairo_t *ct, guint32 rgba) +{ + cairo_set_source_rgba(ct, SP_RGBA32_R_F(rgba), SP_RGBA32_G_F(rgba), SP_RGBA32_B_F(rgba), SP_RGBA32_A_F(rgba)); +} + +void +ink_cairo_set_source_color(cairo_t *ct, SPColor const &c, double opacity) +{ + cairo_set_source_rgba(ct, c.v.c[0], c.v.c[1], c.v.c[2], opacity); +} + +static void +ink_cairo_convert_matrix(cairo_matrix_t &cm, Geom::Matrix const &m) +{ + cm.xx = m[0]; + cm.xy = m[2]; + cm.x0 = m[4]; + cm.yx = m[1]; + cm.yy = m[3]; + cm.y0 = m[5]; +} + +void +ink_cairo_transform(cairo_t *ct, Geom::Matrix const &m) +{ + cairo_matrix_t cm; + ink_cairo_convert_matrix(cm, m); + cairo_transform(ct, &cm); +} + +void +ink_cairo_pattern_set_matrix(cairo_pattern_t *cp, Geom::Matrix const &m) +{ + cairo_matrix_t cm; + ink_cairo_convert_matrix(cm, m); + cairo_pattern_set_matrix(cp, &cm); +} + +// taken from Cairo sources +static inline guint32 premul_alpha(guint32 color, guint32 alpha) +{ + guint32 temp = alpha * color + 128; + return (temp + (temp >> 8)) >> 8; +} + +/** + * @brief Convert pixel data from GdkPixbuf format to ARGB. + * This will convert pixel data from GdkPixbuf format to Cairo's native pixel format. + * This involves premultiplying alpha and shuffling around the channels. + * Pixbuf data must have an alpha channel, otherwise the results are undefined + * (usually a segfault). + */ +void +convert_pixels_pixbuf_to_argb32(guchar *data, int w, int h, int stride) +{ + // TODO: optimize until it squeaks. + guint32 *ipx = reinterpret_cast(data); + + for (int i = 0; i < h; ++i) { + for (int j = 0; j < w; ++j) { + int index = i * stride / 4 + j; + guint32 c = ipx[index]; + guint32 o = 0; +#if G_BYTE_ORDER == G_LITTLE_ENDIAN + guint32 a = (c & 0xff000000) >> 24; +#else + guint32 a = (c & 0x000000ff); +#endif + if (a != 0) { + // extract color components +#if G_BYTE_ORDER == G_LITTLE_ENDIAN + guint32 r = (c & 0x000000ff); + guint32 g = (c & 0x0000ff00) >> 8; + guint32 b = (c & 0x00ff0000) >> 16; +#else + guint32 r = (c & 0xff000000) >> 24; + guint32 g = (c & 0x00ff0000) >> 16; + guint32 b = (c & 0x0000ff00) >> 8; +#endif + // premultiply + r = premul_alpha(r, a); + b = premul_alpha(b, a); + g = premul_alpha(g, a); + // combine into output + o = (a << 24) | (r << 16) | (g << 8) | (b); + } + ipx[index] = o; + } + } +} + +/** + * @brief Convert pixel data from ARGB to GdkPixbuf format. + * This will convert pixel data from GdkPixbuf format to Cairo's native pixel format. + * This involves premultiplying alpha and shuffling around the channels. + */ +void +convert_pixels_argb32_to_pixbuf(guchar *data, int w, int h, int stride) +{ + // TODO: optimize until it squeaks. + guint32 *ipx = reinterpret_cast(data); + for (int i = 0; i < h; ++i) { + for (int j = 0; j < w; ++j) { + int index = i * stride / 4 + j; + guint32 c = ipx[index]; + guint32 o = 0; + guint32 a = (c & 0xff000000) >> 24; + if (a != 0) { + // extract color components + guint32 r = (c & 0x00ff0000) >> 16; + guint32 g = (c & 0x0000ff00) >> 8; + guint32 b = (c & 0x000000ff); + // unpremultiply; adding a/2 gives correct rounding + // (taken from Cairo sources) + r = (r * 255 + a/2) / a; + b = (b * 255 + a/2) / a; + g = (g * 255 + a/2) / a; + // combine into output +#if G_BYTE_ORDER == G_LITTLE_ENDIAN + o = (r) | (g << 8) | (b << 16) | (a << 24); +#else + o = (r << 24) | (g << 16) | (b << 8) | (a); +#endif + } + ipx[index] = o; + } + } +} + +/** + * @brief Converts GdkPixbuf's data to premultiplied ARGB. + * This function will convert a GdkPixbuf in place into Cairo's native pixel format. + * Note that this is a hack intended to save memory. When the pixbuf is Cairo's format, + * using it with GTK will result in corrupted drawings. + */ +void +convert_pixbuf_normal_to_argb32_mutant(GdkPixbuf *pb) +{ + convert_pixels_pixbuf_to_argb32( + gdk_pixbuf_get_pixels(pb), + gdk_pixbuf_get_width(pb), + gdk_pixbuf_get_height(pb), + gdk_pixbuf_get_rowstride(pb)); +} + +/** + * @brief Converts GdkPixbuf's data back to its native format. + * Once this is done, the pixbuf can be used with GTK again. + */ +void +convert_pixbuf_argb32_to_normal(GdkPixbuf *pb) +{ + convert_pixels_argb32_to_pixbuf( + gdk_pixbuf_get_pixels(pb), + gdk_pixbuf_get_width(pb), + gdk_pixbuf_get_height(pb), + gdk_pixbuf_get_rowstride(pb)); +} + /* Local Variables: mode:c++ -- cgit v1.2.3 From b986b0fb26a23899a51e564ef07880a0166680cc Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Wed, 7 Jul 2010 18:41:53 +0200 Subject: Smaller intermediate rendering regions (bzr r9508.1.11) --- src/display/cairo-utils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/display/cairo-utils.cpp') diff --git a/src/display/cairo-utils.cpp b/src/display/cairo-utils.cpp index 7bfdd7dd7..8aaf838ed 100644 --- a/src/display/cairo-utils.cpp +++ b/src/display/cairo-utils.cpp @@ -413,7 +413,7 @@ convert_pixels_argb32_to_pixbuf(guchar *data, int w, int h, int stride) * using it with GTK will result in corrupted drawings. */ void -convert_pixbuf_normal_to_argb32_mutant(GdkPixbuf *pb) +convert_pixbuf_normal_to_argb32(GdkPixbuf *pb) { convert_pixels_pixbuf_to_argb32( gdk_pixbuf_get_pixels(pb), -- cgit v1.2.3 From 2f5eafec8d66d018d760b85a829c1d4ba1b0ed6d Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Wed, 7 Jul 2010 19:21:03 +0200 Subject: Switch to nearest neighbor filtering when image is larger than original (bzr r9508.1.12) --- src/display/cairo-utils.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/display/cairo-utils.cpp') diff --git a/src/display/cairo-utils.cpp b/src/display/cairo-utils.cpp index 8aaf838ed..bb401dc87 100644 --- a/src/display/cairo-utils.cpp +++ b/src/display/cairo-utils.cpp @@ -315,6 +315,20 @@ ink_cairo_pattern_set_matrix(cairo_pattern_t *cp, Geom::Matrix const &m) cairo_pattern_set_matrix(cp, &cm); } +void +ink_cairo_set_source_argb32_pixbuf(cairo_t *ct, GdkPixbuf *pb, double x, double y) +{ + guchar *data = gdk_pixbuf_get_pixels(pb); + int w = gdk_pixbuf_get_width(pb); + int h = gdk_pixbuf_get_height(pb); + int stride = gdk_pixbuf_get_rowstride(pb); + + cairo_surface_t *pbs = cairo_image_surface_create_for_data( + data, CAIRO_FORMAT_ARGB32, w, h, stride); + cairo_set_source_surface(ct, pbs, x, y); + cairo_surface_destroy(pbs); +} + // taken from Cairo sources static inline guint32 premul_alpha(guint32 color, guint32 alpha) { -- cgit v1.2.3 From 8217b2f74c9db38d7a64ce41eeb6c9659aae1ceb Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Mon, 12 Jul 2010 21:57:46 +0200 Subject: Gaussian blur (bzr r9508.1.15) --- src/display/cairo-utils.cpp | 72 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) (limited to 'src/display/cairo-utils.cpp') diff --git a/src/display/cairo-utils.cpp b/src/display/cairo-utils.cpp index bb401dc87..a063a62bb 100644 --- a/src/display/cairo-utils.cpp +++ b/src/display/cairo-utils.cpp @@ -329,6 +329,78 @@ ink_cairo_set_source_argb32_pixbuf(cairo_t *ct, GdkPixbuf *pb, double x, double cairo_surface_destroy(pbs); } +/** @brief Create an exact copy of a surface. + * Creates a surface that has the same type, content type, dimensions and contents + * as the specified surface. */ +cairo_surface_t * +ink_cairo_surface_copy(cairo_surface_t *s) +{ + cairo_surface_t *ns = ink_cairo_surface_create_identical(s); + + cairo_t *ct = cairo_create(ns); + cairo_set_source_surface(ct, s, 0, 0); + cairo_set_operator(ct, CAIRO_OPERATOR_SOURCE); + cairo_paint(ct); + cairo_destroy(ct); + + return ns; +} + +/** @brief Create a surface that differs only in pixel content. + * Creates a surface that has the same type, content type and dimensions + * as the specified surface. Pixel contents are not copied. */ +cairo_surface_t * +ink_cairo_surface_create_identical(cairo_surface_t *s) +{ + cairo_surface_t *ns = cairo_surface_create_similar(s, cairo_surface_get_content(s), + ink_cairo_surface_get_width(s), ink_cairo_surface_get_height(s)); + return ns; +} + +/** @brief Extract the alpha channel into a new surface. + * Creates a surface with a content type of CAIRO_CONTENT_ALPHA that contains + * the alpha values of pixels from @a s. */ +cairo_surface_t * +ink_cairo_extract_alpha(cairo_surface_t *s) +{ + cairo_surface_t *alpha = cairo_surface_create_similar(s, CAIRO_CONTENT_ALPHA, + ink_cairo_surface_get_width(s), ink_cairo_surface_get_height(s)); + + cairo_t *ct = cairo_create(alpha); + cairo_set_source_surface(ct, s, 0, 0); + cairo_set_operator(ct, CAIRO_OPERATOR_SOURCE); + cairo_paint(ct); + cairo_destroy(ct); + + return alpha; +} + +cairo_surface_t * +ink_cairo_surface_unshare(cairo_surface_t *s) +{ + if (cairo_surface_get_reference_count(s) > 1) { + return ink_cairo_surface_copy(s); + } else { + cairo_surface_reference(s); + return s; + } +} + +int +ink_cairo_surface_get_width(cairo_surface_t *surface) +{ + // For now only image surface is handled. + // Later add others, e.g. cairo-gl + assert(cairo_surface_get_type(surface) == CAIRO_SURFACE_TYPE_IMAGE); + return cairo_image_surface_get_width(surface); +} +int +ink_cairo_surface_get_height(cairo_surface_t *surface) +{ + assert(cairo_surface_get_type(surface) == CAIRO_SURFACE_TYPE_IMAGE); + return cairo_image_surface_get_height(surface); +} + // taken from Cairo sources static inline guint32 premul_alpha(guint32 color, guint32 alpha) { -- cgit v1.2.3 From bb8404b19557519bd828113fa93604b10e9e7fe3 Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Wed, 14 Jul 2010 04:32:10 +0200 Subject: Merge redundant *-fns.h into respective filter headers. Move gaussian blur to filters directory. Blend filter effect. (bzr r9508.1.16) --- src/display/cairo-utils.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'src/display/cairo-utils.cpp') diff --git a/src/display/cairo-utils.cpp b/src/display/cairo-utils.cpp index a063a62bb..36202f42e 100644 --- a/src/display/cairo-utils.cpp +++ b/src/display/cairo-utils.cpp @@ -337,11 +337,21 @@ ink_cairo_surface_copy(cairo_surface_t *s) { cairo_surface_t *ns = ink_cairo_surface_create_identical(s); - cairo_t *ct = cairo_create(ns); - cairo_set_source_surface(ct, s, 0, 0); - cairo_set_operator(ct, CAIRO_OPERATOR_SOURCE); - cairo_paint(ct); - cairo_destroy(ct); + if (cairo_surface_get_type(s) == CAIRO_SURFACE_TYPE_IMAGE) { + // use memory copy instead of using a Cairo context + cairo_surface_flush(s); + int stride = cairo_image_surface_get_stride(s); + int h = cairo_image_surface_get_height(s); + memcpy(cairo_image_surface_get_data(ns), cairo_image_surface_get_data(s), stride * h); + cairo_surface_mark_dirty(ns); + } else { + // generic implementation + cairo_t *ct = cairo_create(ns); + cairo_set_source_surface(ct, s, 0, 0); + cairo_set_operator(ct, CAIRO_OPERATOR_SOURCE); + cairo_paint(ct); + cairo_destroy(ct); + } return ns; } -- cgit v1.2.3 From 9edca8fe56eed686ef3d83c7caba23c82348efee Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Wed, 14 Jul 2010 08:42:21 +0200 Subject: Flood and merge filters (bzr r9508.1.17) --- src/display/cairo-utils.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/display/cairo-utils.cpp') diff --git a/src/display/cairo-utils.cpp b/src/display/cairo-utils.cpp index 36202f42e..ce56c21f5 100644 --- a/src/display/cairo-utils.cpp +++ b/src/display/cairo-utils.cpp @@ -367,6 +367,14 @@ ink_cairo_surface_create_identical(cairo_surface_t *s) return ns; } +cairo_surface_t * +ink_cairo_surface_create_same_size(cairo_surface_t *s, cairo_content_t c) +{ + cairo_surface_t *ns = cairo_surface_create_similar(s, c, + ink_cairo_surface_get_width(s), ink_cairo_surface_get_height(s)); + return ns; +} + /** @brief Extract the alpha channel into a new surface. * Creates a surface with a content type of CAIRO_CONTENT_ALPHA that contains * the alpha values of pixels from @a s. */ -- cgit v1.2.3 From ad8d4b3dc89eee0d50857f7cc48e9d54451aeb37 Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Sat, 17 Jul 2010 01:36:51 +0200 Subject: Composite filter (bzr r9508.1.20) --- src/display/cairo-utils.cpp | 47 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 9 deletions(-) (limited to 'src/display/cairo-utils.cpp') diff --git a/src/display/cairo-utils.cpp b/src/display/cairo-utils.cpp index ce56c21f5..c46caa7be 100644 --- a/src/display/cairo-utils.cpp +++ b/src/display/cairo-utils.cpp @@ -362,8 +362,7 @@ ink_cairo_surface_copy(cairo_surface_t *s) cairo_surface_t * ink_cairo_surface_create_identical(cairo_surface_t *s) { - cairo_surface_t *ns = cairo_surface_create_similar(s, cairo_surface_get_content(s), - ink_cairo_surface_get_width(s), ink_cairo_surface_get_height(s)); + cairo_surface_t *ns = ink_cairo_surface_create_same_size(s, cairo_surface_get_content(s)); return ns; } @@ -381,8 +380,7 @@ ink_cairo_surface_create_same_size(cairo_surface_t *s, cairo_content_t c) cairo_surface_t * ink_cairo_extract_alpha(cairo_surface_t *s) { - cairo_surface_t *alpha = cairo_surface_create_similar(s, CAIRO_CONTENT_ALPHA, - ink_cairo_surface_get_width(s), ink_cairo_surface_get_height(s)); + cairo_surface_t *alpha = ink_cairo_surface_create_same_size(s, CAIRO_CONTENT_ALPHA); cairo_t *ct = cairo_create(alpha); cairo_set_source_surface(ct, s, 0, 0); @@ -394,13 +392,44 @@ ink_cairo_extract_alpha(cairo_surface_t *s) } cairo_surface_t * -ink_cairo_surface_unshare(cairo_surface_t *s) +ink_cairo_surface_create_output(cairo_surface_t *image, cairo_surface_t *bg) +{ + cairo_content_t imgt = cairo_surface_get_content(image); + cairo_content_t bgt = cairo_surface_get_content(bg); + cairo_surface_t *out = NULL; + + if (bgt == CAIRO_CONTENT_ALPHA && imgt == CAIRO_CONTENT_ALPHA) { + out = ink_cairo_surface_create_identical(bg); + } else { + out = ink_cairo_surface_create_same_size(bg, CAIRO_CONTENT_COLOR_ALPHA); + } + + return out; +} + +void +ink_cairo_surface_blit(cairo_surface_t *src, cairo_surface_t *dest) { - if (cairo_surface_get_reference_count(s) > 1) { - return ink_cairo_surface_copy(s); + if (cairo_surface_get_type(src) == CAIRO_SURFACE_TYPE_IMAGE && + cairo_surface_get_type(dest) == CAIRO_SURFACE_TYPE_IMAGE && + cairo_image_surface_get_format(src) == cairo_image_surface_get_format(dest) && + cairo_image_surface_get_height(src) == cairo_image_surface_get_height(dest) && + cairo_image_surface_get_width(src) == cairo_image_surface_get_width(dest) && + cairo_image_surface_get_stride(src) == cairo_image_surface_get_stride(dest)) + { + // use memory copy instead of using a Cairo context + cairo_surface_flush(src); + int stride = cairo_image_surface_get_stride(src); + int h = cairo_image_surface_get_height(src); + memcpy(cairo_image_surface_get_data(dest), cairo_image_surface_get_data(src), stride * h); + cairo_surface_mark_dirty(dest); } else { - cairo_surface_reference(s); - return s; + // generic implementation + cairo_t *ct = cairo_create(dest); + cairo_set_source_surface(ct, src, 0, 0); + cairo_set_operator(ct, CAIRO_OPERATOR_SOURCE); + cairo_paint(ct); + cairo_destroy(ct); } } -- cgit v1.2.3 From 73150a4a03282c19b4b04bd2e3b5ff02fb15952e Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Sun, 18 Jul 2010 01:31:07 +0200 Subject: Component transfer filter (bzr r9508.1.24) --- src/display/cairo-utils.cpp | 7 ------- 1 file changed, 7 deletions(-) (limited to 'src/display/cairo-utils.cpp') diff --git a/src/display/cairo-utils.cpp b/src/display/cairo-utils.cpp index c46caa7be..a05d28170 100644 --- a/src/display/cairo-utils.cpp +++ b/src/display/cairo-utils.cpp @@ -448,13 +448,6 @@ ink_cairo_surface_get_height(cairo_surface_t *surface) return cairo_image_surface_get_height(surface); } -// taken from Cairo sources -static inline guint32 premul_alpha(guint32 color, guint32 alpha) -{ - guint32 temp = alpha * color + 128; - return (temp + (temp >> 8)) >> 8; -} - /** * @brief Convert pixel data from GdkPixbuf format to ARGB. * This will convert pixel data from GdkPixbuf format to Cairo's native pixel format. -- cgit v1.2.3 From 4b9f09e52f05a19f93546c075c7a3fb7be322ed7 Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Tue, 3 Aug 2010 04:05:53 +0200 Subject: Handle preserveAspectRatio for images (bzr r9508.1.41) --- src/display/cairo-utils.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'src/display/cairo-utils.cpp') diff --git a/src/display/cairo-utils.cpp b/src/display/cairo-utils.cpp index a05d28170..25a1e7988 100644 --- a/src/display/cairo-utils.cpp +++ b/src/display/cairo-utils.cpp @@ -288,8 +288,17 @@ ink_cairo_set_source_color(cairo_t *ct, SPColor const &c, double opacity) cairo_set_source_rgba(ct, c.v.c[0], c.v.c[1], c.v.c[2], opacity); } -static void -ink_cairo_convert_matrix(cairo_matrix_t &cm, Geom::Matrix const &m) +void ink_matrix_to_2geom(Geom::Matrix &m, cairo_matrix_t const &cm) +{ + m[0] = cm.xx; + m[2] = cm.xy; + m[4] = cm.x0; + m[1] = cm.yx; + m[3] = cm.yy; + m[5] = cm.y0; +} + +void ink_matrix_to_cairo(cairo_matrix_t &cm, Geom::Matrix const &m) { cm.xx = m[0]; cm.xy = m[2]; @@ -303,7 +312,7 @@ void ink_cairo_transform(cairo_t *ct, Geom::Matrix const &m) { cairo_matrix_t cm; - ink_cairo_convert_matrix(cm, m); + ink_matrix_to_cairo(cm, m); cairo_transform(ct, &cm); } @@ -311,7 +320,7 @@ void ink_cairo_pattern_set_matrix(cairo_pattern_t *cp, Geom::Matrix const &m) { cairo_matrix_t cm; - ink_cairo_convert_matrix(cm, m); + ink_matrix_to_cairo(cm, m); cairo_pattern_set_matrix(cp, &cm); } -- cgit v1.2.3 From 30884b9e814d7baaa2299803e8cb76cf203ca084 Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Wed, 4 Aug 2010 05:45:58 +0200 Subject: Wholesale cruft removal part 1 (bzr r9508.1.44) --- src/display/cairo-utils.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/display/cairo-utils.cpp') diff --git a/src/display/cairo-utils.cpp b/src/display/cairo-utils.cpp index 25a1e7988..15fceedae 100644 --- a/src/display/cairo-utils.cpp +++ b/src/display/cairo-utils.cpp @@ -457,6 +457,32 @@ ink_cairo_surface_get_height(cairo_surface_t *surface) return cairo_image_surface_get_height(surface); } +cairo_pattern_t * +ink_cairo_pattern_create_checkerboard() +{ + int const w = 8; + int const h = 8; + + cairo_surface_t *s = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 2*w, 2*h); + + cairo_t *ct = cairo_create(s); + cairo_set_operator(ct, CAIRO_OPERATOR_SOURCE); + cairo_set_source_rgb(ct, 0.75, 0.75, 0.75); + cairo_paint(ct); + cairo_set_source_rgb(ct, 0.5, 0.5, 0.5); + cairo_rectangle(ct, 0, 0, w, h); + cairo_rectangle(ct, w, h, w, h); + cairo_fill(ct); + cairo_destroy(ct); + + cairo_pattern_t *p = cairo_pattern_create_for_surface(s); + cairo_pattern_set_extend(p, CAIRO_EXTEND_REPEAT); + cairo_pattern_set_filter(p, CAIRO_FILTER_NEAREST); + + cairo_surface_destroy(s); + return p; +} + /** * @brief Convert pixel data from GdkPixbuf format to ARGB. * This will convert pixel data from GdkPixbuf format to Cairo's native pixel format. -- cgit v1.2.3 From 2cfc657521d2c22e9238ce1904a6a4a90d3b4517 Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Mon, 9 Aug 2010 22:45:22 +0200 Subject: Fix performance regression when displaying large images (bzr r9508.1.54) --- src/display/cairo-utils.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/display/cairo-utils.cpp') diff --git a/src/display/cairo-utils.cpp b/src/display/cairo-utils.cpp index 15fceedae..96219e834 100644 --- a/src/display/cairo-utils.cpp +++ b/src/display/cairo-utils.cpp @@ -326,6 +326,14 @@ ink_cairo_pattern_set_matrix(cairo_pattern_t *cp, Geom::Matrix const &m) void ink_cairo_set_source_argb32_pixbuf(cairo_t *ct, GdkPixbuf *pb, double x, double y) +{ + cairo_surface_t *pbs = ink_cairo_surface_create_for_argb32_pixbuf(pb); + cairo_set_source_surface(ct, pbs, x, y); + cairo_surface_destroy(pbs); +} + +cairo_surface_t * +ink_cairo_surface_create_for_argb32_pixbuf(GdkPixbuf *pb) { guchar *data = gdk_pixbuf_get_pixels(pb); int w = gdk_pixbuf_get_width(pb); @@ -334,8 +342,7 @@ ink_cairo_set_source_argb32_pixbuf(cairo_t *ct, GdkPixbuf *pb, double x, double cairo_surface_t *pbs = cairo_image_surface_create_for_data( data, CAIRO_FORMAT_ARGB32, w, h, stride); - cairo_set_source_surface(ct, pbs, x, y); - cairo_surface_destroy(pbs); + return pbs; } /** @brief Create an exact copy of a surface. -- cgit v1.2.3 From aa844be794b36b44b624e579db7f0945b5d3927b Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Sat, 14 Aug 2010 21:22:11 +0200 Subject: Completely remove NRPixBlock (bzr r9508.1.67) --- src/display/cairo-utils.cpp | 69 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 67 insertions(+), 2 deletions(-) (limited to 'src/display/cairo-utils.cpp') diff --git a/src/display/cairo-utils.cpp b/src/display/cairo-utils.cpp index 96219e834..ed4de8afc 100644 --- a/src/display/cairo-utils.cpp +++ b/src/display/cairo-utils.cpp @@ -464,11 +464,76 @@ ink_cairo_surface_get_height(cairo_surface_t *surface) return cairo_image_surface_get_height(surface); } +static int ink_cairo_surface_average_color_internal(cairo_surface_t *surface, double &rf, double &gf, double &bf, double &af) +{ + rf = gf = bf = af = 0.0; + cairo_surface_flush(surface); + int width = cairo_image_surface_get_width(surface); + int height = cairo_image_surface_get_height(surface); + int stride = cairo_image_surface_get_stride(surface); + unsigned char *data = cairo_image_surface_get_data(surface); + + /* TODO convert this to OpenMP somehow */ + for (int y = 0; y < height; ++y, data += stride) { + for (int x = 0; x < width; ++x) { + guint32 px = *reinterpret_cast(data + 4*x); + EXTRACT_ARGB32(px, a,r,g,b) + rf += r / 255.0; + gf += g / 255.0; + bf += b / 255.0; + af += a / 255.0; + } + } + return width * height; +} + +guint32 ink_cairo_surface_average_color(cairo_surface_t *surface) +{ + double rf,gf,bf,af; + ink_cairo_surface_average_color_premul(surface, rf,gf,bf,af); + guint32 r = round(rf * 255); + guint32 g = round(gf * 255); + guint32 b = round(bf * 255); + guint32 a = round(af * 255); + ASSEMBLE_ARGB32(px, a,r,g,b); + return px; +} + +void ink_cairo_surface_average_color(cairo_surface_t *surface, double &r, double &g, double &b, double &a) +{ + int count = ink_cairo_surface_average_color_internal(surface, r,g,b,a); + + r /= a; + g /= a; + b /= a; + a /= count; + + r = CLAMP(r, 0.0, 1.0); + g = CLAMP(g, 0.0, 1.0); + b = CLAMP(b, 0.0, 1.0); + a = CLAMP(a, 0.0, 1.0); +} + +void ink_cairo_surface_average_color_premul(cairo_surface_t *surface, double &r, double &g, double &b, double &a) +{ + int count = ink_cairo_surface_average_color_internal(surface, r,g,b,a); + + r /= count; + g /= count; + b /= count; + a /= count; + + r = CLAMP(r, 0.0, 1.0); + g = CLAMP(g, 0.0, 1.0); + b = CLAMP(b, 0.0, 1.0); + a = CLAMP(a, 0.0, 1.0); +} + cairo_pattern_t * ink_cairo_pattern_create_checkerboard() { - int const w = 8; - int const h = 8; + int const w = 6; + int const h = 6; cairo_surface_t *s = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 2*w, 2*h); -- cgit v1.2.3 From f6dba310bc22dc65845e0cd0743594545e356a59 Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Sun, 19 Jun 2011 11:01:29 +0200 Subject: Fix rendering of control points (bzr r9508.1.88) --- src/display/cairo-utils.cpp | 129 +++++++++++++++++++++++++------------------- 1 file changed, 74 insertions(+), 55 deletions(-) (limited to 'src/display/cairo-utils.cpp') diff --git a/src/display/cairo-utils.cpp b/src/display/cairo-utils.cpp index adf5dcb9a..90f65c33e 100644 --- a/src/display/cairo-utils.cpp +++ b/src/display/cairo-utils.cpp @@ -555,6 +555,62 @@ ink_cairo_pattern_create_checkerboard() return p; } +/* The following two functions use "from" instead of "to", because when you write: + val1 = argb32_from_pixbuf(val1); + the name of the format is closer to the value in that format. */ + +guint32 argb32_from_pixbuf(guint32 c) +{ + guint32 o = 0; +#if G_BYTE_ORDER == G_LITTLE_ENDIAN + guint32 a = (c & 0xff000000) >> 24; +#else + guint32 a = (c & 0x000000ff); +#endif + if (a != 0) { + // extract color components +#if G_BYTE_ORDER == G_LITTLE_ENDIAN + guint32 r = (c & 0x000000ff); + guint32 g = (c & 0x0000ff00) >> 8; + guint32 b = (c & 0x00ff0000) >> 16; +#else + guint32 r = (c & 0xff000000) >> 24; + guint32 g = (c & 0x00ff0000) >> 16; + guint32 b = (c & 0x0000ff00) >> 8; +#endif + // premultiply + r = premul_alpha(r, a); + b = premul_alpha(b, a); + g = premul_alpha(g, a); + // combine into output + o = (a << 24) | (r << 16) | (g << 8) | (b); + } + return o; +} + +guint32 pixbuf_from_argb32(guint32 c) +{ + guint32 a = (c & 0xff000000) >> 24; + if (a == 0) return 0; + + // extract color components + guint32 r = (c & 0x00ff0000) >> 16; + guint32 g = (c & 0x0000ff00) >> 8; + guint32 b = (c & 0x000000ff); + // unpremultiply; adding a/2 gives correct rounding + // (taken from Cairo sources) + r = (r * 255 + a/2) / a; + b = (b * 255 + a/2) / a; + g = (g * 255 + a/2) / a; + // combine into output +#if G_BYTE_ORDER == G_LITTLE_ENDIAN + guint32 o = (r) | (g << 8) | (b << 16) | (a << 24); +#else + guint32 o = (r << 24) | (g << 16) | (b << 8) | (a); +#endif + return o; +} + /** * @brief Convert pixel data from GdkPixbuf format to ARGB. * This will convert pixel data from GdkPixbuf format to Cairo's native pixel format. @@ -565,38 +621,11 @@ ink_cairo_pattern_create_checkerboard() void convert_pixels_pixbuf_to_argb32(guchar *data, int w, int h, int stride) { - // TODO: optimize until it squeaks. - guint32 *ipx = reinterpret_cast(data); - for (int i = 0; i < h; ++i) { + guint32 *px = reinterpret_cast(data + i*stride); for (int j = 0; j < w; ++j) { - int index = i * stride / 4 + j; - guint32 c = ipx[index]; - guint32 o = 0; -#if G_BYTE_ORDER == G_LITTLE_ENDIAN - guint32 a = (c & 0xff000000) >> 24; -#else - guint32 a = (c & 0x000000ff); -#endif - if (a != 0) { - // extract color components -#if G_BYTE_ORDER == G_LITTLE_ENDIAN - guint32 r = (c & 0x000000ff); - guint32 g = (c & 0x0000ff00) >> 8; - guint32 b = (c & 0x00ff0000) >> 16; -#else - guint32 r = (c & 0xff000000) >> 24; - guint32 g = (c & 0x00ff0000) >> 16; - guint32 b = (c & 0x0000ff00) >> 8; -#endif - // premultiply - r = premul_alpha(r, a); - b = premul_alpha(b, a); - g = premul_alpha(g, a); - // combine into output - o = (a << 24) | (r << 16) | (g << 8) | (b); - } - ipx[index] = o; + *px = argb32_from_pixbuf(*px); + ++px; } } } @@ -609,32 +638,11 @@ convert_pixels_pixbuf_to_argb32(guchar *data, int w, int h, int stride) void convert_pixels_argb32_to_pixbuf(guchar *data, int w, int h, int stride) { - // TODO: optimize until it squeaks. - guint32 *ipx = reinterpret_cast(data); for (int i = 0; i < h; ++i) { + guint32 *px = reinterpret_cast(data + i*stride); for (int j = 0; j < w; ++j) { - int index = i * stride / 4 + j; - guint32 c = ipx[index]; - guint32 o = 0; - guint32 a = (c & 0xff000000) >> 24; - if (a != 0) { - // extract color components - guint32 r = (c & 0x00ff0000) >> 16; - guint32 g = (c & 0x0000ff00) >> 8; - guint32 b = (c & 0x000000ff); - // unpremultiply; adding a/2 gives correct rounding - // (taken from Cairo sources) - r = (r * 255 + a/2) / a; - b = (b * 255 + a/2) / a; - g = (g * 255 + a/2) / a; - // combine into output -#if G_BYTE_ORDER == G_LITTLE_ENDIAN - o = (r) | (g << 8) | (b << 16) | (a << 24); -#else - o = (r << 24) | (g << 16) | (b << 8) | (a); -#endif - } - ipx[index] = o; + *px = pixbuf_from_argb32(*px); + ++px; } } } @@ -642,7 +650,7 @@ convert_pixels_argb32_to_pixbuf(guchar *data, int w, int h, int stride) /** * @brief Converts GdkPixbuf's data to premultiplied ARGB. * This function will convert a GdkPixbuf in place into Cairo's native pixel format. - * Note that this is a hack intended to save memory. When the pixbuf is Cairo's format, + * Note that this is a hack intended to save memory. When the pixbuf is in Cairo's format, * using it with GTK will result in corrupted drawings. */ void @@ -669,6 +677,17 @@ convert_pixbuf_argb32_to_normal(GdkPixbuf *pb) gdk_pixbuf_get_rowstride(pb)); } +guint32 argb32_from_rgba(guint32 in) +{ + guint32 r, g, b, a; + a = (in & 0x000000ff); + r = premul_alpha((in & 0xff000000) >> 24, a); + g = premul_alpha((in & 0x00ff0000) >> 16, a); + b = premul_alpha((in & 0x0000ff00) >> 8, a); + ASSEMBLE_ARGB32(px, a, r, g, b) + return px; +} + /* Local Variables: mode:c++ -- cgit v1.2.3 From 6973283a77d7becd6a5a1bd7396206c6840ca785 Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Wed, 13 Jul 2011 23:43:55 +0200 Subject: Fix crashes in print preview Fixed bugs: - https://launchpad.net/bugs/806105 (bzr r10450) --- src/display/cairo-utils.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/display/cairo-utils.cpp') diff --git a/src/display/cairo-utils.cpp b/src/display/cairo-utils.cpp index 90f65c33e..8b75f09a6 100644 --- a/src/display/cairo-utils.cpp +++ b/src/display/cairo-utils.cpp @@ -345,6 +345,18 @@ ink_cairo_surface_create_for_argb32_pixbuf(GdkPixbuf *pb) return pbs; } +/** @brief Cleanup function for GdkPixbuf. + * This function should be passed as the GdkPixbufDestroyNotify parameter + * to gdk_pixbuf_new_from_data when creating a GdkPixbuf backed by + * a Cairo surface. + */ +void +ink_cairo_pixbuf_cleanup(guchar *pixels, void *data) +{ + cairo_surface_t *surface = reinterpret_cast(data); + cairo_surface_destroy(surface); +} + /** @brief Create an exact copy of a surface. * Creates a surface that has the same type, content type, dimensions and contents * as the specified surface. */ -- cgit v1.2.3 From 122894f12a4f8214207f533ed26569fbab5ac9f7 Mon Sep 17 00:00:00 2001 From: "Jon A. Cruz" Date: Sun, 2 Oct 2011 01:26:17 -0700 Subject: Warning cleanup. (bzr r10655) --- src/display/cairo-utils.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/display/cairo-utils.cpp') diff --git a/src/display/cairo-utils.cpp b/src/display/cairo-utils.cpp index 8b75f09a6..a12a3d560 100644 --- a/src/display/cairo-utils.cpp +++ b/src/display/cairo-utils.cpp @@ -350,8 +350,7 @@ ink_cairo_surface_create_for_argb32_pixbuf(GdkPixbuf *pb) * to gdk_pixbuf_new_from_data when creating a GdkPixbuf backed by * a Cairo surface. */ -void -ink_cairo_pixbuf_cleanup(guchar *pixels, void *data) +void ink_cairo_pixbuf_cleanup(guchar * /*pixels*/, void *data) { cairo_surface_t *surface = reinterpret_cast(data); cairo_surface_destroy(surface); -- cgit v1.2.3 From b0c0eed3b05e20673469dc7b70cf3a92a42429b2 Mon Sep 17 00:00:00 2001 From: "Jon A. Cruz" Date: Sun, 2 Oct 2011 01:34:59 -0700 Subject: Removing redundant doxygen @brief tag. (bzr r10656) --- src/display/cairo-utils.cpp | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'src/display/cairo-utils.cpp') diff --git a/src/display/cairo-utils.cpp b/src/display/cairo-utils.cpp index a12a3d560..2e2eb42dd 100644 --- a/src/display/cairo-utils.cpp +++ b/src/display/cairo-utils.cpp @@ -345,7 +345,8 @@ ink_cairo_surface_create_for_argb32_pixbuf(GdkPixbuf *pb) return pbs; } -/** @brief Cleanup function for GdkPixbuf. +/** + * Cleanup function for GdkPixbuf. * This function should be passed as the GdkPixbufDestroyNotify parameter * to gdk_pixbuf_new_from_data when creating a GdkPixbuf backed by * a Cairo surface. @@ -356,9 +357,11 @@ void ink_cairo_pixbuf_cleanup(guchar * /*pixels*/, void *data) cairo_surface_destroy(surface); } -/** @brief Create an exact copy of a surface. +/** + * Create an exact copy of a surface. * Creates a surface that has the same type, content type, dimensions and contents - * as the specified surface. */ + * as the specified surface. + */ cairo_surface_t * ink_cairo_surface_copy(cairo_surface_t *s) { @@ -383,9 +386,11 @@ ink_cairo_surface_copy(cairo_surface_t *s) return ns; } -/** @brief Create a surface that differs only in pixel content. +/** + * Create a surface that differs only in pixel content. * Creates a surface that has the same type, content type and dimensions - * as the specified surface. Pixel contents are not copied. */ + * as the specified surface. Pixel contents are not copied. + */ cairo_surface_t * ink_cairo_surface_create_identical(cairo_surface_t *s) { @@ -401,9 +406,11 @@ ink_cairo_surface_create_same_size(cairo_surface_t *s, cairo_content_t c) return ns; } -/** @brief Extract the alpha channel into a new surface. +/** + * Extract the alpha channel into a new surface. * Creates a surface with a content type of CAIRO_CONTENT_ALPHA that contains - * the alpha values of pixels from @a s. */ + * the alpha values of pixels from @a s. + */ cairo_surface_t * ink_cairo_extract_alpha(cairo_surface_t *s) { @@ -623,7 +630,7 @@ guint32 pixbuf_from_argb32(guint32 c) } /** - * @brief Convert pixel data from GdkPixbuf format to ARGB. + * Convert pixel data from GdkPixbuf format to ARGB. * This will convert pixel data from GdkPixbuf format to Cairo's native pixel format. * This involves premultiplying alpha and shuffling around the channels. * Pixbuf data must have an alpha channel, otherwise the results are undefined @@ -642,7 +649,7 @@ convert_pixels_pixbuf_to_argb32(guchar *data, int w, int h, int stride) } /** - * @brief Convert pixel data from ARGB to GdkPixbuf format. + * Convert pixel data from ARGB to GdkPixbuf format. * This will convert pixel data from GdkPixbuf format to Cairo's native pixel format. * This involves premultiplying alpha and shuffling around the channels. */ @@ -659,7 +666,7 @@ convert_pixels_argb32_to_pixbuf(guchar *data, int w, int h, int stride) } /** - * @brief Converts GdkPixbuf's data to premultiplied ARGB. + * Converts GdkPixbuf's data to premultiplied ARGB. * This function will convert a GdkPixbuf in place into Cairo's native pixel format. * Note that this is a hack intended to save memory. When the pixbuf is in Cairo's format, * using it with GTK will result in corrupted drawings. @@ -675,7 +682,7 @@ convert_pixbuf_normal_to_argb32(GdkPixbuf *pb) } /** - * @brief Converts GdkPixbuf's data back to its native format. + * Converts GdkPixbuf's data back to its native format. * Once this is done, the pixbuf can be used with GTK again. */ void -- cgit v1.2.3