X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2Fjdatadst.cxx;h=63ae9a171e1faa1db558adbff33bf519a0964e13;hb=721d134c6e594b9a23bf1ce002ed87bfbc1576a7;hp=547eb2fda4e889cbf3ffc48a33b8934003c1cd1f;hpb=95e43356511d138225d8f718f632b3e7a8fcc106;p=gdcm.git diff --git a/src/jdatadst.cxx b/src/jdatadst.cxx index 547eb2fd..63ae9a17 100644 --- a/src/jdatadst.cxx +++ b/src/jdatadst.cxx @@ -27,8 +27,12 @@ extern "C" { 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; @@ -84,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; } @@ -147,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; @@ -168,4 +183,12 @@ jpeg_stdio_dest (j_compress_ptr cinfo, std::ofstream * outfile) 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; }