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-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;
|
2013-09-12 06:47:23 +04:00
|
|
|
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;
|
2013-09-12 06:01:16 +04:00
|
|
|
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
|
|
|
}
|