2013-01-26 04:36:55 +04:00
|
|
|
#include "imageutils.h"
|
2013-01-24 07:02:31 +04:00
|
|
|
#include "lodepng.h"
|
|
|
|
#include <stdio.h>
|
2013-01-24 07:10:24 +04:00
|
|
|
#include <stdlib.h>
|
2013-02-12 05:10:52 +04:00
|
|
|
#include <vector>
|
|
|
|
#include <iterator>
|
|
|
|
#include <algorithm>
|
2013-09-12 06:01:16 +04:00
|
|
|
#include "rendersettings.h"
|
2013-01-24 07:02:31 +04:00
|
|
|
|
2013-01-24 09:05:15 +04:00
|
|
|
bool write_png(std::ostream &output, unsigned char *pixels, int width, int height)
|
2013-01-24 07:02:31 +04:00
|
|
|
{
|
2013-02-12 05:10:52 +04:00
|
|
|
std::vector<unsigned char> dataout;
|
2013-09-12 06:01:16 +04:00
|
|
|
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);
|
2013-02-12 05:10:52 +04:00
|
|
|
if ( err ) return false;
|
|
|
|
output.write( reinterpret_cast<const char *>(&dataout[0]), dataout.size());
|
|
|
|
if ( output.bad() ) std::cerr << "Error writing to ostream\n";
|
|
|
|
return output.good();
|
2013-01-24 07:02:31 +04:00
|
|
|
}
|