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-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
|
|
|
{
|
|
|
|
//encoder.settings.zlibsettings.windowSize = 2048;
|
|
|
|
//LodePNG_Text_add(&encoder.infoPng.text, "Comment", "Created with LodePNG");
|
|
|
|
size_t dataout_size = -1;
|
|
|
|
unsigned char *dataout = (unsigned char *)malloc(width*height*4);
|
2013-01-26 09:20:25 +04:00
|
|
|
if (!dataout) {
|
|
|
|
perror("Error allocating memory while writing png\n");
|
|
|
|
return false;
|
|
|
|
}
|
2013-01-24 07:02:31 +04:00
|
|
|
LodePNG_encode(&dataout, &dataout_size, pixels, width, height, LCT_RGBA, 8);
|
2013-01-26 09:20:25 +04:00
|
|
|
try {
|
|
|
|
output.write( reinterpret_cast<const char*>(dataout), dataout_size );
|
|
|
|
} catch (const std::ios_base::failure &e) {
|
|
|
|
std::cerr << "Error writing to ostream:" << e.what() << "\n";
|
|
|
|
}
|
2013-01-26 04:36:55 +04:00
|
|
|
free( dataout );
|
2013-01-24 07:02:31 +04:00
|
|
|
return true;
|
|
|
|
}
|