📄 jpdequan.cpp
字号:
#include <iostream>
#include "jpdequan.h"
#include "jpegdeco.h"
#include "jpgexcep.h"
using namespace std ;
//
// Description:
//
// Class Default Constructor
//
JpegDecoderQuantizationTable::JpegDecoderQuantizationTable ()
{
table_defined = false ;
memset (data_values, 0, sizeof (data_values)) ;
return ;
}
//
// Description:
//
// This function reads a quantization table from a JPEG stream.
//
// Parameters:
// decoder: The JPEG decoder that owns the table and the JPEG stream.
// precision: The quantization table precision
//
void JpegDecoderQuantizationTable::ReadTable (JpegDecoder &decoder,
unsigned int precision)
{
// B 2.4.1
// Determine if 16-bit or 8-bit precision is used for the quantization
// values in the file.
if (precision == 1)
{
// Our source code only allows 8-bit data. The standard says
// 16-bit quantization tables are not allowed with 8-bit data.
// The commented code shows how 16-bit tables would be implemented.
//
// // Read 16-bit values.
// for (unsigned int ii = 0 ; ii < SampleSize ; ++ ii)
// {
// data_values[ii] = decoder.ReadWord () ;
// if (data_values[ii] == 0)
// throw EJpegBadData ("Zero value in quantization table") ;
// }
throw EJpegBadData ("Only 8-bit Data is Supported") ;
}
else if (precision == 0)
{
// Read 8-bit values.
for (unsigned int ii = 0 ; ii < JpegSampleSize ; ++ ii)
{
data_values[ii] = decoder.ReadByte () ;
if (data_values[ii] == 0)
throw EJpegBadData ("Zero value in quantization table") ;
}
}
else
{
throw EJpegBadData ("Invalid Quantization Table Precision") ;
}
table_defined = true ;
return ;
}
//
// Description:
//
// This is a debugging function that prints the contents
// of the quantization table to a stream.
//
// Parameters:
//
// strm: The output stream
//
void JpegDecoderQuantizationTable::Print (std::ostream &strm) const
{
for (unsigned int ii = 0 ; ii < JpegSampleWidth ; ++ ii)
{
strm << endl << " " ;
for (unsigned int jj = 0 ; jj < JpegSampleWidth ; ++ jj)
{
strm << dec
<< data_values [ii * JpegSampleWidth + jj]
<< " " ;
}
}
return ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -