summaryrefslogtreecommitdiff
path: root/src/imageutils-lodepng.cc
blob: a034702848940b287831de8af88db8eed1853bac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include "imageutils.h"
#include "lodepng.h"
#include <stdio.h>
#include <stdlib.h>

bool write_png(std::ostream &output, unsigned char *pixels, int width, int height)
{
  //encoder.settings.zlibsettings.windowSize = 2048;
  //LodePNG_Text_add(&encoder.infoPng.text, "Comment", "Created with LodePNG");
  size_t dataout_size = -1;
	bool result = false;
  unsigned char *dataout = (unsigned char *)malloc(width*height*4);
	if (!dataout) {
		perror("Error allocating memory while writing png\n");
		return result;
	}
  LodePNG_encode(&dataout, &dataout_size, pixels, width, height, LCT_RGBA, 8);
	try {
		output.write( reinterpret_cast<const char*>(dataout), dataout_size );
		result = true;
	} catch (const std::ios_base::failure &e) {
    std::cerr << "Error writing to ostream:" << e.what() << "\n";
	}
	free( dataout );
  return result;
}
contact: Jan Huwald // Impressum