[trunk] Make sure to handle ret value, and properly initialize output file

This commit is contained in:
Mathieu Malaterre 2014-02-24 14:22:25 +00:00
parent f42c26adbd
commit c91044a4a7
1 changed files with 24 additions and 8 deletions

View File

@ -40,7 +40,7 @@ void info_callback(const char *msg, void *v);
void error_callback(const char *msg, void *v) {
(void)msg;
(void)v;
assert(0);
puts(msg);
}
void warning_callback(const char *msg, void *v) {
(void)msg;
@ -87,6 +87,7 @@ int main(int argc, char *argv[])
cmptparm.dy = subsampling_dy;
cmptparm.w = image_width;
cmptparm.h = image_height;
strncpy(parameters.outfile, outputfile, sizeof(parameters.outfile)-1);
image = opj_image_create(numcomps, &cmptparm, color_space);
assert( image );
@ -113,8 +114,23 @@ int main(int argc, char *argv[])
opj_setup_encoder(l_codec, &parameters, image);
l_stream = opj_stream_create_default_file_stream_v3(parameters.outfile,OPJ_FALSE);
if( !l_stream )
{
fprintf( stderr, "Something went wrong during creation of stream\n" );
opj_destroy_codec(l_codec);
opj_image_destroy(image);
opj_stream_destroy_v3(l_stream);
return 1;
}
assert(l_stream);
bSuccess = opj_start_compress(l_codec,image,l_stream);
if( !bSuccess )
{
opj_stream_destroy_v3(l_stream);
opj_destroy_codec(l_codec);
opj_image_destroy(image);
return 0;
}
assert( bSuccess );
bSuccess = opj_encode(l_codec, l_stream);