blob: 46b593d47b3de625db98487a7f760612f8ac2a2e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
#include "imageutils.h"
#include "lodepng.h"
#include <stdio.h>
#include <stdlib.h>
#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;
lodepng::State state;
state.encoder.auto_convert = LAC_NO;
// some png renderers have different interpretations of alpha, so don't use it
state.info_png.color.colortype = LCT_RGB;
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";
return output.good();
}
|