mirror of https://github.com/vitalif/openscad
upgrade lodepng to new version. remove malloc from imageutils
parent
a4fea6df86
commit
76f184c50b
|
@ -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();
|
||||
}
|
||||
|
|
5503
src/lodepng.cpp
5503
src/lodepng.cpp
File diff suppressed because it is too large
Load Diff
1880
src/lodepng.h
1880
src/lodepng.h
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue