diff options
author | Tavian Barnes <tavianator@gmail.com> | 2009-11-18 23:30:38 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2009-11-18 23:30:38 -0500 |
commit | 5038d1f96af332e474a1e0a076bf5dead6855727 (patch) | |
tree | 128921e3bbdc29046695ac4d9c9fb8d7535bc49a /libdimension/png.c | |
parent | c576229cc54c0fb963967751281e6a42fc9230ea (diff) | |
download | dimension-5038d1f96af332e474a1e0a076bf5dead6855727.tar.xz |
Translucency support.
Diffstat (limited to 'libdimension/png.c')
-rw-r--r-- | libdimension/png.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/libdimension/png.c b/libdimension/png.c index 20190d8..1ad8a1a 100644 --- a/libdimension/png.c +++ b/libdimension/png.c @@ -96,8 +96,14 @@ dmnsn_png_optimizer_fn(dmnsn_canvas *canvas, dmnsn_canvas_optimizer optimizer, pixel[2] = sRGB.B*UINT16_MAX; } - /* color.filter + color.trans is in [0.0, 1.0] by definition */ - pixel[3] = (color.filter + color.trans)*UINT16_MAX; + double alpha = color.filter + color.trans; + if (alpha <= 0.0) { + pixel[3] = 0; + } else if (alpha >= 1.0) { + pixel[3] = UINT16_MAX; + } else { + pixel[3] = alpha*UINT16_MAX; + } } /* Payload to store function arguments for thread callbacks */ @@ -359,8 +365,14 @@ dmnsn_png_write_canvas_impl(dmnsn_progress *progress, row[4*x + 2] = sRGB.B*UINT16_MAX; } - /* color.filter + color.trans is in [0.0, 1.0] by definition */ - row[4*x + 3] = (color.filter + color.trans)*UINT16_MAX; + double alpha = color.filter + color.trans; + if (alpha <= 0.0) { + row[4*x + 3] = 0; + } else if (alpha >= 1.0) { + row[4*x + 3] = UINT16_MAX; + } else { + row[4*x + 3] = alpha*UINT16_MAX; + } } /* Write the row */ |