X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2Fjdatadst.cxx;h=63ae9a171e1faa1db558adbff33bf519a0964e13;hb=331b611c7add834807f5b235ffc877ef6d0198ad;hp=3b85057033088a5165efae472ad333dd43262b58;hpb=fea9426f960497d2d9124ab532d2097f2915678f;p=gdcm.git diff --git a/src/jdatadst.cxx b/src/jdatadst.cxx index 3b850570..63ae9a17 100644 --- a/src/jdatadst.cxx +++ b/src/jdatadst.cxx @@ -19,11 +19,20 @@ /* Expanded data destination object for stdio output */ +extern "C" { + typedef boolean(*boolean_jpeg_compress_struct)(jpeg_compress_struct*); + typedef void(*void_jpeg_compress_struct)(jpeg_compress_struct*); +} + typedef struct { struct jpeg_destination_mgr pub; /* public fields */ - std::ofstream * outfile; /* target stream */ + std::ostream * outfile; /* target stream */ JOCTET * buffer; /* start of buffer */ +// boolean start_of_file; /* have we gotten any data yet? */ + + size_t frag_length; //we have to control this one to spec the size of the frag + size_t bytes_written; } my_destination_mgr; typedef my_destination_mgr * my_dest_ptr; @@ -79,18 +88,29 @@ empty_output_buffer (j_compress_ptr cinfo) { my_dest_ptr dest = (my_dest_ptr) cinfo->dest; -#if 0 - if (JFWRITE(dest->outfile, dest->buffer, OUTPUT_BUF_SIZE) != - (size_t) OUTPUT_BUF_SIZE) + if( dest->bytes_written == dest->frag_length ) + { + // Start the I/O suspension simply by returning false here: + return FALSE; + } + + size_t output_buf_size = OUTPUT_BUF_SIZE; + if( (dest->bytes_written + OUTPUT_BUF_SIZE) > dest->frag_length ) + { + output_buf_size = dest->frag_length - dest->bytes_written; + } + dest->outfile->write((char*)dest->buffer, output_buf_size); + size_t nbytes = output_buf_size; //dest->outfile->gcount(); + + if( nbytes <= 0 ) ERREXIT(cinfo, JERR_FILE_WRITE); -#else - dest->outfile->write((char*)dest->buffer, OUTPUT_BUF_SIZE); + if( dest->outfile->fail() ) ERREXIT(cinfo, JERR_FILE_WRITE); -#endif dest->pub.next_output_byte = dest->buffer; - dest->pub.free_in_buffer = OUTPUT_BUF_SIZE; + dest->pub.free_in_buffer = nbytes; //OUTPUT_BUF_SIZE; + dest->bytes_written += nbytes; return TRUE; } @@ -142,7 +162,7 @@ term_destination (j_compress_ptr cinfo) */ GLOBAL(void) -jpeg_stdio_dest (j_compress_ptr cinfo, std::ofstream * outfile) +jpeg_stdio_dest (j_compress_ptr cinfo, std::ostream * outfile, size_t frag_length, int flag) { my_dest_ptr dest; @@ -159,8 +179,16 @@ jpeg_stdio_dest (j_compress_ptr cinfo, std::ofstream * outfile) } dest = (my_dest_ptr) cinfo->dest; - dest->pub.init_destination = init_destination; - dest->pub.empty_output_buffer = empty_output_buffer; - dest->pub.term_destination = term_destination; + dest->pub.init_destination = reinterpret_cast(init_destination); + dest->pub.empty_output_buffer = reinterpret_cast(empty_output_buffer); + dest->pub.term_destination = reinterpret_cast(term_destination); dest->outfile = outfile; + + // Need to setup a new buffer, clean bytes_in_buffer and next_input_byte + if( flag ) + { + dest->bytes_written = 0; + } + // only upate the new fragment, valid for both 'flag' value + dest->frag_length = frag_length; }