Source manager that allow us to read from a std::istream. More...
#include <jpeg.hpp>
Public Member Functions | |
source_manager (std::istream &is) | |
Constructor. | |
~source_manager () | |
Destructor. | |
boolean | fill_input_buffer () |
Fill the input buffer with new data. | |
void | skip_input_data (long num_bytes) |
Skip some bytes in the input buffer. | |
Public Attributes | |
struct jpeg_source_mgr | pub |
"public" fields, needed by the jpeg library. | |
Private Attributes | |
std::istream & | m_input |
The stream from which we get data. | |
const JOCTET * | m_buffer |
Pointer on the begining of the buffer. | |
const unsigned int | m_buffer_size |
Number of bytes in the buffer. | |
unsigned int | m_stream_size |
The size of the stream. | |
unsigned int | m_stream_position |
The current position in the stream. |
Source manager that allow us to read from a std::istream.
Definition at line 88 of file jpeg.hpp.
claw::graphic::jpeg::reader::source_manager::source_manager | ( | std::istream & | is | ) |
Constructor.
is | The stream we read from. |
Definition at line 97 of file jpeg_reader.cpp.
References m_buffer, m_buffer_size, m_stream_size, and pub.
00098 : m_input(is), m_buffer_size(1024), m_stream_position(0) 00099 { 00100 std::istream::pos_type pos = is.tellg(); 00101 00102 is.seekg( 0 , std::ios_base::end ); 00103 m_stream_size = is.tellg() ; 00104 00105 is.seekg( pos, std::ios_base::beg ) ; 00106 00107 m_buffer = new JOCTET[m_buffer_size]; 00108 pub.bytes_in_buffer = 0; 00109 } // jpeg::reader::source_manager::source_manager()
claw::graphic::jpeg::reader::source_manager::~source_manager | ( | ) |
Destructor.
Definition at line 115 of file jpeg_reader.cpp.
References m_buffer.
00116 { 00117 delete[] m_buffer; 00118 } // jpeg::reader::source_manager::~source_manager()
boolean claw::graphic::jpeg::reader::source_manager::fill_input_buffer | ( | ) |
Fill the input buffer with new data.
Definition at line 125 of file jpeg_reader.cpp.
References m_buffer, m_buffer_size, m_input, m_stream_position, m_stream_size, and pub.
Referenced by skip_input_data().
00126 { 00127 unsigned int n = std::min( m_buffer_size, m_stream_size - m_stream_position ); 00128 m_input.read( (char*)m_buffer, n ); 00129 00130 pub.next_input_byte = m_buffer; 00131 pub.bytes_in_buffer = n; 00132 00133 m_stream_position += n; 00134 00135 if (m_input) 00136 return TRUE; 00137 else 00138 return FALSE; 00139 } // jpeg::reader::source_manager::fill_input_buffer()
void claw::graphic::jpeg::reader::source_manager::skip_input_data | ( | long | num_bytes | ) |
Skip some bytes in the input buffer.
num_bytes | The number of bytes to skip. |
Definition at line 147 of file jpeg_reader.cpp.
References CLAW_PRECOND, fill_input_buffer(), m_buffer_size, and pub.
00148 { 00149 CLAW_PRECOND(num_bytes >=0); 00150 00151 if ( (size_t)num_bytes <= pub.bytes_in_buffer ) 00152 { 00153 pub.next_input_byte += num_bytes; 00154 pub.bytes_in_buffer -= num_bytes; 00155 } 00156 else 00157 { 00158 num_bytes -= pub.bytes_in_buffer; 00159 00160 long div = num_bytes / m_buffer_size; 00161 long rest = num_bytes % m_buffer_size; 00162 00163 for (long i=0; i!=(div+1); ++i) 00164 fill_input_buffer(); 00165 00166 pub.next_input_byte += rest; 00167 pub.bytes_in_buffer -= rest; 00168 } 00169 } // jpeg::reader::source_manager::skip_input_data()
const JOCTET* claw::graphic::jpeg::reader::source_manager::m_buffer [private] |
Pointer on the begining of the buffer.
Definition at line 106 of file jpeg.hpp.
Referenced by fill_input_buffer(), source_manager(), and ~source_manager().
const unsigned int claw::graphic::jpeg::reader::source_manager::m_buffer_size [private] |
Number of bytes in the buffer.
Definition at line 109 of file jpeg.hpp.
Referenced by fill_input_buffer(), skip_input_data(), and source_manager().
std::istream& claw::graphic::jpeg::reader::source_manager::m_input [private] |
The stream from which we get data.
Definition at line 103 of file jpeg.hpp.
Referenced by fill_input_buffer().
unsigned int claw::graphic::jpeg::reader::source_manager::m_stream_position [private] |
The current position in the stream.
Definition at line 115 of file jpeg.hpp.
Referenced by fill_input_buffer().
unsigned int claw::graphic::jpeg::reader::source_manager::m_stream_size [private] |
The size of the stream.
Definition at line 112 of file jpeg.hpp.
Referenced by fill_input_buffer(), and source_manager().
struct jpeg_source_mgr claw::graphic::jpeg::reader::source_manager::pub [read] |
"public" fields, needed by the jpeg library.
Definition at line 99 of file jpeg.hpp.
Referenced by claw::graphic::jpeg::reader::create_decompress_info(), fill_input_buffer(), skip_input_data(), and source_manager().