openscad/src/imageutils-lodepng.cc

36 lines
1021 B
C++
Raw Normal View History

2013-01-24 07:02:31 +04:00
#include "lodepng.h"
#include <stdio.h>
#include <stdlib.h>
2013-01-24 07:02:31 +04:00
bool write_png(std::ostream &output, unsigned char *pixels, int width, int height)
{
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);
output.write( dataout, dataout_size );;
free( dataout );
return true;
}
2013-01-24 07:02:31 +04:00
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;
}