diff options
author | Marek Dvoroznak <dvoromar@gmail.com> | 2014-01-13 19:40:28 +0100 |
---|---|---|
committer | Mikael Magnusson <mikachu@src.gnome.org> | 2015-02-27 19:13:59 +0100 |
commit | 97d3926bac332cc8d41b13dad43b8631d7d056e8 (patch) | |
tree | 228d60d243b73dd8700b39bdc53aafe8ed2c775c /libs | |
parent | e6283fa3c2d40185b401481d612152e809460116 (diff) |
operations: npd: add alpha blending
Diffstat (limited to 'libs')
-rw-r--r-- | libs/npd/graphics.c | 13 | ||||
-rw-r--r-- | libs/npd/graphics.h | 5 |
2 files changed, 8 insertions, 10 deletions
diff --git a/libs/npd/graphics.c b/libs/npd/graphics.c index 1cb88971..353b9a4e 100644 --- a/libs/npd/graphics.c +++ b/libs/npd/graphics.c @@ -54,7 +54,7 @@ npd_bilinear_color_interpolation (NPDColor *I0, out->a = npd_bilinear_interpolation (I0->a, I1->a, I2->a, I3->a, dx, dy); } -gfloat +static gfloat npd_blend_band (gfloat src, gfloat dst, gfloat src_alpha, @@ -73,11 +73,14 @@ npd_blend_colors (NPDColor *src, gfloat src_A = src->a / 255.0, dst_A = dst->a / 255.0; gfloat out_alpha = src_A + dst_A * (1 - src_A); - gfloat out_alpha_recip = 1 / out_alpha; + if (out_alpha > 0) + { + gfloat out_alpha_recip = 1 / out_alpha; - out_color->r = npd_blend_band (src->r, dst->r, src_A, dst_A, out_alpha_recip); - out_color->g = npd_blend_band (src->g, dst->g, src_A, dst_A, out_alpha_recip); - out_color->b = npd_blend_band (src->b, dst->b, src_A, dst_A, out_alpha_recip); + out_color->r = npd_blend_band (src->r, dst->r, src_A, dst_A, out_alpha_recip); + out_color->g = npd_blend_band (src->g, dst->g, src_A, dst_A, out_alpha_recip); + out_color->b = npd_blend_band (src->b, dst->b, src_A, dst_A, out_alpha_recip); + } out_color->a = out_alpha * 255; } diff --git a/libs/npd/graphics.h b/libs/npd/graphics.h index 89c1ab4b..902026b2 100644 --- a/libs/npd/graphics.h +++ b/libs/npd/graphics.h @@ -55,11 +55,6 @@ void npd_draw_model_into_image (NPDModel *model, void npd_draw_mesh (NPDModel *model, NPDDisplay *display); gboolean npd_is_color_transparent (NPDColor *color); -gfloat npd_blend_band (gfloat src, - gfloat dst, - gfloat src_alpha, - gfloat dst_alpha, - gfloat out_alpha_recip); extern void (*npd_draw_line) (NPDDisplay *display, gfloat x0, gfloat y0, |