⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jpginputfilestream.cpp

📁 Jpeg编解码器的源代码
💻 CPP
字号:
//
//  标题:  JpegInputFileStream实现
//
//  描述:
//
//    JpegInputFileStream implements JPEG input through a file.
//

#include <fstream>
#include "jpginputfilestream.h"

using namespace std ;

namespace Colosseum 
{
//
//  Description:
//
//    Default Constructor
//
JpegInputFileStream::JpegInputFileStream (unsigned int buffersize) 
: buffer_size (buffersize),
  input_buffer (new UBYTE1 [buffer_size]) 
{
  return ;
}
//
//  Description:
//
//    Class Destructor
//
JpegInputFileStream::~JpegInputFileStream () 
{
  delete input_buffer ; input_buffer = 0 ;
  return ;
}
//
//  Description:
//
//    This function gives access to the state of the input stream.
//
//  Return Value:
//
//    The state of the input stream.
//
JpegInputFileStream::operator bool () 
{
#if defined (_MSC_VER)
  bool result = static_cast<void*> (input_stream) != 0 ? true : false ;
#else
  bool result = static_cast<bool> (input_stream) ;
#endif
  return result ;
}
//
//  Description:
//
//    This function opens the input file.
//
//  Parameters:
//
//    filename : The name of the file to open
//
void JpegInputFileStream::open (const std::string &filename) 
{
  input_stream.open (filename.c_str (), ios::binary) ;
  return ;
}
//
//  Description:
//
//    This function closes the input stream.
//
void JpegInputFileStream::close () 
{
  if (input_stream)
    input_stream.close () ;

  return ;
}
//
//  Description:
//
//    This function reads the input stream and fills the input buffer.
//  
void JpegInputFileStream::fillBuffer () 
{
  input_stream.read (reinterpret_cast<char*>(input_buffer), buffer_size) ;
  int count = input_stream.gcount () ;
  if (count <= 0)
  {
    current_byte = 0 ;
    buffer_limit = 0 ;
  }
  else
  {
    current_byte = input_buffer ;
    buffer_limit = &input_buffer [count] ;
  }
  return ;
}
//
//  Description:
//
//    This function tells the caller if the end of the input stream
//    has been reached.
//
//  Return Value:
//  
//    true => The end of file has been reached
//    false => The end of file has not been reached
//
bool JpegInputFileStream::endReached () 
{
  return input_stream.eof () ;
}

//
//  Description:
//
//    This function returns the current position in the input stream.
//
//  Return Value:
//
//    The current input position.
//
InputByteStream::POSITIONTYPE JpegInputFileStream::tellg () 
{
  InputByteStream::POSITIONTYPE result = input_stream.tellg () ;
  result -= buffer_limit - current_byte ;
  return result ;
}
//
//  Description:
//
//    This function moves the input stream to a specified position.
//
//  Parameters:
//
//    position: The absolute position in the input stream to move to.
//
void JpegInputFileStream::seekg (InputByteStream::POSITIONTYPE position) 
{
  exitBitMode () ;
  input_stream.clear () ;
  input_stream.seekg (position) ;
  fillBuffer () ;
  return ;
}

} // End Namespace 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -