diff options
author | don bright <hugh.m.bright@gmail.com> | 2013-01-26 05:20:25 (GMT) |
---|---|---|
committer | don bright <hugh.m.bright@gmail.com> | 2013-01-26 05:20:25 (GMT) |
commit | a66ad9c4bc10696cd3167d3217c9aad532167705 (patch) | |
tree | d1a8572792e3476d79f27b463761b2265fc05d58 /src/imageutils-lodepng.cc | |
parent | c116a0849c7531ec4d0e59b6d61aaf6137dcd568 (diff) |
add ostream to Context. improve error checking. fix indents
Diffstat (limited to 'src/imageutils-lodepng.cc')
-rw-r--r-- | src/imageutils-lodepng.cc | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/imageutils-lodepng.cc b/src/imageutils-lodepng.cc index 96d9d90..fab1cd9 100644 --- a/src/imageutils-lodepng.cc +++ b/src/imageutils-lodepng.cc @@ -9,8 +9,16 @@ bool write_png(std::ostream &output, unsigned char *pixels, int width, int heigh //LodePNG_Text_add(&encoder.infoPng.text, "Comment", "Created with LodePNG"); size_t dataout_size = -1; unsigned char *dataout = (unsigned char *)malloc(width*height*4); + if (!dataout) { + perror("Error allocating memory while writing png\n"); + return false; + } LodePNG_encode(&dataout, &dataout_size, pixels, width, height, LCT_RGBA, 8); - output.write( reinterpret_cast<const char*>(dataout), dataout_size );; + try { + output.write( reinterpret_cast<const char*>(dataout), dataout_size ); + } catch (const std::ios_base::failure &e) { + std::cerr << "Error writing to ostream:" << e.what() << "\n"; + } free( dataout ); return true; } |