File: imageutils-lodepng.cc

package info (click to toggle)
openscad 2011.12-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 9,080 kB
  • sloc: cpp: 19,710; python: 990; yacc: 558; sh: 537; ansic: 522; lex: 221; lisp: 147; xml: 36; makefile: 35
file content (24 lines) | stat: -rw-r--r-- 664 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include "lodepng.h"
#include <stdio.h>

bool write_png(const char *filename, 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;
  unsigned char *dataout = (unsigned char *)malloc(width*height*4);
  LodePNG_encode(&dataout, &dataout_size, pixels, width, height, LCT_RGBA, 8);
  //LodePNG_saveFile(dataout, dataout_size, "blah2.png");

  FILE *f = fopen(filename, "wb");
  if (!f) {
		free(dataout);
		return false;
	}

	fwrite(dataout, 1, dataout_size, f);
	fclose(f);
  free(dataout);
  return true;
}