huffdeco.cpp

来自「超强jpeg解码程序」· C++ 代码 · 共 55 行

CPP
55
字号
#include <fstream>
#include "jpegdeco.h"
#include "jpdehuff.h"

using namespace std ;

JpegHuffmanDecoder table ;

main (int argc, char *argv [])
{
  unsigned int bytes ;

  if (argc != 3)
  {
    cerr << "Usage: " << argv [0] << " input-file output-file" << endl ;
    return 1 ;
  }

  ifstream input ;
  input.open (argv [1], ios::binary) ;
  if (! input)
  {
    cerr << "Can't open input file" << endl ;
    return 1 ;
  }

  JpegDecoder decoder (input) ;
  table.ReadTable (decoder) ;

  ofstream output ;
  output.open (argv [2]) ;
  if (! output)
  {
    cerr << "Can't open output file" << endl ;
    return 1 ;
  }

  UBYTE1 data = table.Decode (decoder) ;
  bytes = 0 ;
  while (! input.eof ())
  {
    ++ bytes ;
    if (bytes % 1000 == 0)
      cout << bytes << " Bytes\r" ;
    output.write ((char *) &data, 1) ;
    data = table.Decode (decoder) ;
  }
  cout << bytes << " bytes" << endl ;
  output.write ((char *) &data, 1) ;

  input.close () ;
  output.close () ;
  return 0 ;
}

⌨️ 快捷键说明

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