Public Member Functions | Public Attributes | Private Attributes

claw::graphic::jpeg::reader::source_manager Struct Reference

Source manager that allow us to read from a std::istream. More...

#include <jpeg.hpp>

List of all members.

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.

Detailed Description

Source manager that allow us to read from a std::istream.

Author:
Julien Jorge

Definition at line 88 of file jpeg.hpp.


Constructor & Destructor Documentation

claw::graphic::jpeg::reader::source_manager::source_manager ( std::istream &  is  ) 

Constructor.

Parameters:
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.

  : m_input(is), m_buffer_size(1024), m_stream_position(0)
{
  std::istream::pos_type pos = is.tellg();

  is.seekg( 0 , std::ios_base::end );
  m_stream_size = is.tellg() ;

  is.seekg( pos, std::ios_base::beg ) ;

  m_buffer = new JOCTET[m_buffer_size];
  pub.bytes_in_buffer = 0;
} // 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.

{
  delete[] m_buffer;
} // jpeg::reader::source_manager::~source_manager()


Member Function Documentation

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().

{
  unsigned int n = std::min( m_buffer_size, m_stream_size - m_stream_position );
  m_input.read( (char*)m_buffer, n );

  pub.next_input_byte = m_buffer;
  pub.bytes_in_buffer = n;

  m_stream_position += n;

  if (m_input)
    return TRUE;
  else
    return FALSE;
} // 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.

Parameters:
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.

{
  CLAW_PRECOND(num_bytes >=0);

  if ( (size_t)num_bytes <= pub.bytes_in_buffer )
    {
      pub.next_input_byte += num_bytes;
      pub.bytes_in_buffer -= num_bytes;
    }
  else
    {
      num_bytes -= pub.bytes_in_buffer;
      
      long div = num_bytes / m_buffer_size;
      long rest = num_bytes % m_buffer_size;

      for (long i=0; i!=(div+1); ++i)
        fill_input_buffer();

      pub.next_input_byte += rest;
      pub.bytes_in_buffer -= rest;
    }
} // jpeg::reader::source_manager::skip_input_data()


Member Data Documentation

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().

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().

The stream from which we get data.

Definition at line 103 of file jpeg.hpp.

Referenced by fill_input_buffer().

The current position in the stream.

Definition at line 115 of file jpeg.hpp.

Referenced by fill_input_buffer().

The size of the stream.

Definition at line 112 of file jpeg.hpp.

Referenced by fill_input_buffer(), and source_manager().

"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().


The documentation for this struct was generated from the following files: