blob: a71a017b15065d31d3403dbe1cc3a0d3802a1207 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
#include "imageutils.h"
#include "lodepng.h"
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <iterator>
#include <algorithm>
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();
}
|