/*
- * jdatasrc.c
+ * jdatasrc.cxx
*
* Copyright (C) 1994-1996, Thomas G. Lane.
* This file is part of the Independent JPEG Group's software.
*/
/* this is not a core library module, so it doesn't define JPEG_INTERNALS */
-#include <gdcmjpeg/jinclude.h>
-#include <gdcmjpeg/jerror.h>
/* 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? */
+
+ GDCM_NAME_SPACE::JPEGFragment *frag;
+ size_t bytes_read;
} my_source_mgr;
typedef my_source_mgr * my_src_ptr;
{
my_src_ptr src = (my_src_ptr) cinfo->src;
- src->infile->read( (char*)src->buffer, INPUT_BUF_SIZE);
+ if( src->bytes_read == src->frag->GetLength() )
+ {
+ // 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->GetLength() )
+ {
+ input_buf_size = src->frag->GetLength() - src->bytes_read;
+ }
+
+ src->infile->read( (char*)src->buffer, input_buf_size);
size_t nbytes = src->infile->gcount();
if (nbytes <= 0) {
src->pub.next_input_byte = src->buffer;
src->pub.bytes_in_buffer = nbytes;
src->start_of_file = FALSE;
+ src->bytes_read += nbytes;
return TRUE;
}
*/
GLOBAL(void)
-jpeg_stdio_src (j_decompress_ptr cinfo, std::ifstream * infile)
+jpeg_stdio_src (j_decompress_ptr cinfo, std::istream * infile, GDCM_NAME_SPACE::JPEGFragment *frag, int flag)
{
my_src_ptr src;
}
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<void_jpeg_decompress_struct>(init_source);
+ src->pub.fill_input_buffer = reinterpret_cast<boolean_jpeg_decompress_struct>(fill_input_buffer);
+ src->pub.skip_input_data = reinterpret_cast<void_jpeg_decompress_struct_long>(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<void_jpeg_decompress_struct>(term_source);
src->infile = infile;
- src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */
- src->pub.next_input_byte = NULL; /* until buffer loaded */
+
+ // 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 */
+ }
+ //only upate the new fragment, valid for both 'flag' value
+ src->frag = frag;
+ src->bytes_read = 0;
}