upgrade lodepng to new version. remove malloc from imageutils

felipesanches-svg
don bright 2013-02-11 19:10:52 -06:00
parent a4fea6df86
commit 76f184c50b
3 changed files with 3806 additions and 3604 deletions

View File

@ -2,25 +2,16 @@
#include "lodepng.h"
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <iterator>
#include <algorithm>
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;
std::vector<unsigned char> dataout;
unsigned err = lodepng::encode(dataout, pixels, width, height, LCT_RGBA, 8);
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();
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff