diff options
| author | Krzysztof Kosi??ski <tweenk.pl@gmail.com> | 2010-07-21 16:37:38 +0000 |
|---|---|---|
| committer | Krzysztof KosiĆski <tweenk.pl@gmail.com> | 2010-07-21 16:37:38 +0000 |
| commit | dd78fe909d51f28f7d2e42dcc17ffcb45eb39b23 (patch) | |
| tree | 2c331954debb4c2bc08181f16b0c6b0eb88690e3 /src/display/cairo-utils.h | |
| parent | Fix type mismatch of std::min args in ColorMatrixMatrix constructor (diff) | |
| download | inkscape-dd78fe909d51f28f7d2e42dcc17ffcb45eb39b23.tar.gz inkscape-dd78fe909d51f28f7d2e42dcc17ffcb45eb39b23.zip | |
Add unpremul_alpha utility function. Some preparations
(bzr r9508.1.26)
Diffstat (limited to 'src/display/cairo-utils.h')
| -rw-r--r-- | src/display/cairo-utils.h | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/display/cairo-utils.h b/src/display/cairo-utils.h index 02bfe0f73..12fcd8b3d 100644 --- a/src/display/cairo-utils.h +++ b/src/display/cairo-utils.h @@ -98,11 +98,18 @@ void convert_pixels_argb32_to_pixbuf(guchar *data, int w, int h, int rs); void convert_pixbuf_normal_to_argb32(GdkPixbuf *); void convert_pixbuf_argb32_to_normal(GdkPixbuf *); -inline guint32 premul_alpha(guint32 color, guint32 alpha) +G_GNUC_CONST inline guint32 +premul_alpha(guint32 color, guint32 alpha) { guint32 temp = alpha * color + 128; return (temp + (temp >> 8)) >> 8; } +G_GNUC_CONST inline guint32 +unpremul_alpha(guint32 color, guint32 alpha) +{ + // NOTE: you must check for alpha != 0 yourself. + return (255 * color + alpha/2) / alpha; +} // TODO: move those to 2Geom void feed_pathvector_to_cairo (cairo_t *ct, Geom::PathVector const &pathv, Geom::Matrix trans, Geom::OptRect area, bool optimize_stroke, double stroke_width); |
