📄 decoder.cpp
字号:
#include <fstream>
#include "jpegdeco.h"
#include "bitimage.h"
#include "bmpencod.h"
using namespace std ;
#pragma argsused
void Progress (BitmapImageCoder &coder,
void *data,
unsigned int currentpass,
unsigned int passcount,
unsigned int progress,
bool &cancel)
{
cout << currentpass << " of " << passcount << " " << progress << "% \r" << flush ;
return ;
}
void Usage (int argc, char *argv [])
{
char *program ;
if (argc != 0)
program = argv [0] ;
else
program = "DECODER" ;
cerr << "Usage: " << program << " [-v] input.jpg output.bmp" << endl ;
exit (1) ;
}
int main(int argc, char *argv [])
{
if (argc < 3)
{
Usage (argc, argv) ;
return 1 ;
}
JpegDecoder decoder ;
for (unsigned int ii = 1 ; ii < argc - 2 ; ++ ii)
{
if (argv [ii][0] != '-')
Usage (argc, argv) ;
switch (argv [ii][1])
{
case 'v':
decoder.SetVerbose (true) ;
break ;
default:
Usage (argc, argv) ;
}
}
decoder.SetVerbose (true) ;// for testing only, ZY, 2006.3.16
s
decoder.SetProgressFunction (Progress, NULL) ;
ifstream is (argv [argc - 2], ios::binary) ;
if (! is)
{
cerr << "Can't open input file " << argv [argc-2] << endl ; return 1 ;
}
BitmapImage image ;
cout << "Reading Image..." << endl ;
try
{
decoder.ReadImage (is, image) ;
}
catch (EGraphicsException &ee)
{
cerr << ee.what () << endl << flush ;
return 1 ;
}
cout << "Writing Output..." << endl ;
ofstream os (argv [argc-1], ios::binary|ios::trunc) ;
if (! os)
{
cerr << "Can't open output file " << argv [argc-1] << endl ;
return 1 ;
}
BmpEncoder bs ;
try
{
bs.WriteImage (os, image) ;
}
catch (EGraphicsException &ee)
{
cerr << ee.what () << endl << flush ;
return 1 ;
}
cout << "Done..." << endl << flush ;
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -