use background color when writing PNG with lodepng

issue480
Don Bright 2013-09-11 21:01:16 -05:00
parent ea92d9ce19
commit 4a2255f199
1 changed files with 10 additions and 1 deletions

View File

@ -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";