X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2Fjdatasrc.cxx;h=cfb526abd8593898d18c825923ecb1f799227669;hb=df832cf7f90b4ca5aca2f628c1756fb276779fac;hp=199431c31444c7542b07af05e58a6ca2d2c933f3;hpb=70a3a0f95bf2240a6ef4b1d6523c0e6614437304;p=gdcm.git diff --git a/src/jdatasrc.cxx b/src/jdatasrc.cxx index 199431c3..cfb526ab 100644 --- a/src/jdatasrc.cxx +++ b/src/jdatasrc.cxx @@ -1,5 +1,5 @@ /* - * jdatasrc.c + * jdatasrc.cxx * * Copyright (C) 1994-1996, Thomas G. Lane. * This file is part of the Independent JPEG Group's software. @@ -18,14 +18,20 @@ /* Expanded data source object for stdio input */ +extern "C" { + typedef boolean(*boolean_jpeg_decompress_struct)(jpeg_decompress_struct*); + typedef void(*void_jpeg_decompress_struct)(jpeg_decompress_struct*); + typedef void(*void_jpeg_decompress_struct_long)(jpeg_decompress_struct*,long); +} + typedef struct { struct jpeg_source_mgr pub; /* public fields */ - std::ifstream *infile; /* source stream */ + std::istream *infile; /* source stream */ JOCTET * buffer; /* start of buffer */ boolean start_of_file; /* have we gotten any data yet? */ - //PixelReadConvert *pixels; - gdcm::JPEGFragment *frag; + + GDCM_NAME_SPACE::JPEGFragment *frag; size_t bytes_read; } my_source_mgr; @@ -90,25 +96,20 @@ fill_input_buffer (j_decompress_ptr cinfo) { my_src_ptr src = (my_src_ptr) cinfo->src; - //std::cerr << "Before comp:" << src->bytes_read << " / " << src->frag->Length << std::endl; - if( src->bytes_read == src->frag->Length ) + if( src->bytes_read == src->frag->GetLength() ) { - //std::cerr << "Sweet finished this fragment" << std::endl; + // Start the I/O suspension simply by returning false here: return FALSE; } size_t input_buf_size = INPUT_BUF_SIZE; - if( (src->bytes_read + INPUT_BUF_SIZE) > src->frag->Length ) + if( (src->bytes_read + INPUT_BUF_SIZE) > src->frag->GetLength() ) { - //std::cerr << "Woula error:" << src->bytes_read << " / " << src->frag->Length << std::endl; - input_buf_size = src->frag->Length - src->bytes_read; - //std::cerr << "Ok only reading: " << input_buf_size << " / " << INPUT_BUF_SIZE << std::endl; - } + input_buf_size = src->frag->GetLength() - src->bytes_read; + } - //std::cerr << "infile read:" << src->pub.bytes_in_buffer << std::endl; src->infile->read( (char*)src->buffer, input_buf_size); size_t nbytes = src->infile->gcount(); - //std::cerr << "input_buf_size=" << input_buf_size << " and nbytes=" << nbytes << std::endl; if (nbytes <= 0) { if (src->start_of_file) /* Treat empty input file as fatal error */ @@ -125,11 +126,7 @@ fill_input_buffer (j_decompress_ptr cinfo) src->start_of_file = FALSE; src->bytes_read += nbytes; - return TRUE; - // otherwise cause a suspension return - //std::cerr << "fill_input_buffer" << std::endl; - //return FALSE; } @@ -148,7 +145,6 @@ fill_input_buffer (j_decompress_ptr cinfo) METHODDEF(void) skip_input_data (j_decompress_ptr cinfo, long num_bytes) { - //std::cerr << "skip_input_data:" << num_bytes << std::endl; my_src_ptr src = (my_src_ptr) cinfo->src; /* Just a dumb implementation for now. Could use fseek() except @@ -202,7 +198,7 @@ term_source (j_decompress_ptr cinfo) */ GLOBAL(void) -jpeg_stdio_src (j_decompress_ptr cinfo, std::ifstream * infile, gdcm::JPEGFragment *frag, int flag) +jpeg_stdio_src (j_decompress_ptr cinfo, std::istream * infile, GDCM_NAME_SPACE::JPEGFragment *frag, int flag) { my_src_ptr src; @@ -224,24 +220,20 @@ jpeg_stdio_src (j_decompress_ptr cinfo, std::ifstream * infile, gdcm::JPEGFragme } src = (my_src_ptr) cinfo->src; - src->pub.init_source = init_source; - src->pub.fill_input_buffer = fill_input_buffer; - src->pub.skip_input_data = skip_input_data; + src->pub.init_source = reinterpret_cast(init_source); + src->pub.fill_input_buffer = reinterpret_cast(fill_input_buffer); + src->pub.skip_input_data = reinterpret_cast(skip_input_data); src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */ - src->pub.term_source = term_source; + src->pub.term_source = reinterpret_cast(term_source); src->infile = infile; + // Need to setup a new buffer, clean bytes_in_buffer and next_input_byte if( flag ) { - src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */ - src->pub.next_input_byte = NULL; /* until buffer loaded */ - src->frag = frag; - src->bytes_read = 0; + src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */ + src->pub.next_input_byte = NULL; /* until buffer loaded */ } - else - { - //only upate the new fragment - src->frag = frag; + //only upate the new fragment, valid for both 'flag' value + src->frag = frag; src->bytes_read = 0; - } }