diff options
author | Don Bright <hugh.m.bright@gmail.com> | 2013-09-12 02:01:16 (GMT) |
---|---|---|
committer | Don Bright <hugh.m.bright@gmail.com> | 2013-09-12 02:01:16 (GMT) |
commit | 4a2255f1996f8a0eccf05226ec129b09cf6c4151 (patch) | |
tree | 58b15abece2d31487e7a230bc2917e2024d2053b /src/imageutils-lodepng.cc | |
parent | ea92d9ce190adf34f48778c39ffaeca9b5a7da13 (diff) |
use background color when writing PNG with lodepng
Diffstat (limited to 'src/imageutils-lodepng.cc')
-rw-r--r-- | src/imageutils-lodepng.cc | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/imageutils-lodepng.cc b/src/imageutils-lodepng.cc index cd104d6..9f3afda 100644 --- a/src/imageutils-lodepng.cc +++ b/src/imageutils-lodepng.cc @@ -5,11 +5,20 @@ #include <vector> #include <iterator> #include <algorithm> +#include "rendersettings.h" bool write_png(std::ostream &output, unsigned char *pixels, int width, int height) { std::vector<unsigned char> dataout; - unsigned err = lodepng::encode(dataout, pixels, width, height, LCT_RGBA, 8); + lodepng::State state; + state.info_png.background_defined = true; + Color4f bg = RenderSettings::inst()->color(RenderSettings::BACKGROUND_COLOR); + state.info_png.background_r = bg(0); + state.info_png.background_g = bg(1); + state.info_png.background_b = bg(2); + state.info_png.color.colortype = LCT_RGBA; + state.info_png.color.bitdepth = 8; + unsigned err = lodepng::encode(dataout, pixels, width, height, state); if ( err ) return false; output.write( reinterpret_cast<const char *>(&dataout[0]), dataout.size()); if ( output.bad() ) std::cerr << "Error writing to ostream\n"; |