?? advancejpeg-lscode.h
字號:
//編碼器操作方式定義
#define MaxMTestErrMeLimen(a) (((a)/3))
//#define MinMTestErrMeLimen(a) (((a)/8))
#define MinMTestErrMeLimen(a) (((a)/6))
#define MTestErrMeLimen(a) (((a)/4))
#define MAdjustErrMe(a) ((a)+(a))
#define MAdjustErrMe2(a) (4*(a))
#define MAX_RUN_TEST_THRESHOLD_NUMBER 3
#define MIN_MINCONTEXT(a) (a+(a)/6)
#define MIN_MDoubleMaxErrAdjust(a) (a+1)
#define MIN_MDoubleMaxErrAdjust2(a) (a+(a)/2+1)
#define MIN_MDoubleMaxErr(a) (a+a)
#define MID_MINCONTEXT(a) (a+((a)/3))
#define MID_MDoubleMaxErrAdjust(a) (a+((a)/6)+1)
#define MID_MDoubleMaxErrAdjust2(a) (a+(a)/3+1)
#define MID_MDoubleMaxErr(a) (a+a+((a)/3))
#define MAX_MINCONTEXT(a) (a+((a)*2/3))
#define MAX_MDoubleMaxErrAdjust(a) (a+((a)/3)+1)
#define MAX_MDoubleMaxErrAdjust2(a) (a+(a))
#define MAX_MDoubleMaxErr(a) (a+a+a)
#define MFilterGradeLimen(a) (((a)*3)/3)
//#define MFilterGradeLimen(a) (((a)*2)/3)
#define DEFAULT_ADJUST_WIN_LENGTH 6
#define RUN_APPEND_FILTER_CONTROL_MIN_RUNL 3//附加游程方式下的濾波控制最小檢測游程長度
#define BASIC_T1 3 // basic default threshold values
#define BASIC_T2 7
#define BASIC_T3 21
#define DEFAULT_RESET 64
//用于多波段編碼
#define UNIFORM_FLOAT_TO_INT_MUL 32767
#define STATISTIC_LINE_NUMBER 3
#define PIX_ADD 8192
#define MAX_PREDICT_ERR PIX_ADD
#define MAX_A_MUL 131068//4*32767
#define MIN_A_MUL 6553//0.2*32767
#define MAX_BAND_CONTEXT_NUMBER 64
#define BAND_CONTEXT_RANGE 64
#define MIN_STATISTIC_NUMBER 64
#define UPDATE_RELATIVE_LINE_NUMBER 2
#define ALLOW_PREDICTION_MIN_RELATIVE 26541//0.90*0.9*32767
#define NOT_PREDICTION_MAX_RELATIVE 22033//0.82*0.82*32767
//該類僅完成一次連續(xù)的圖像行編碼過程,在調(diào)用過程中,只要不復(fù)位,圖像的壓縮就是連續(xù)的。
//由于部分參數(shù)的優(yōu)化更新與行數(shù)有關(guān),類內(nèi)有當(dāng)前行指示。
/*
編碼調(diào)用辦法
一、初始化
1、定義編碼器對象(這是一個數(shù)據(jù)結(jié)構(gòu),提供圖像行壓縮的基本控制數(shù)據(jù)和圖像的上下文緩沖)
2、復(fù)位并初始化編碼器。(主要的圖像的上下文及壓縮控制數(shù)據(jù),為壓縮新的圖像作準(zhǔn)備)
二、壓縮過程調(diào)用
1、加載圖像數(shù)據(jù)。(要求圖像行數(shù)據(jù)是存在于某緩沖中,如果是可波段預(yù)測,則求行預(yù)測誤差數(shù)據(jù)。)
2、壓縮一行圖像數(shù)據(jù),壓縮比特流存放于指定地址緩沖區(qū)內(nèi)。(有比特流輸出)
3、壓縮控制參數(shù)的優(yōu)化更新。(內(nèi)部操作)
三、壓縮過程的結(jié)束
1、釋放編碼器申請的存貯空間。
譯碼調(diào)用辦法
一、初始化
1、定義譯碼器對象(這是一個數(shù)據(jù)結(jié)構(gòu),提供圖像行解壓縮的基本控制數(shù)據(jù)和圖像的上下文緩沖)
2、復(fù)位并初始化譯碼器。(主要的圖像的上下文及壓縮控制數(shù)據(jù),為解壓縮新的圖像作準(zhǔn)備)
二、解壓縮過程調(diào)用
1、加載圖像壓縮數(shù)據(jù)。(要求圖像行數(shù)據(jù)是存在于某緩沖中,如果是可波段預(yù)測,則求行預(yù)測誤差數(shù)據(jù)。)
2、解壓縮一行圖像數(shù)據(jù),輸出一個圖像行。
3、壓縮控制參數(shù)的優(yōu)化更新。(內(nèi)部操作)
三、壓縮過程的結(jié)束
1、釋放譯碼器申請的存貯空間。
*/
struct AdvanceJPEGLSMaxErrList
{
short int PixSeat,Sign;
};
class CDoubleErrorNumberFastCoding;
class CDoubleErrorRunFastCoding;
class CAdvanceJepgLSOneLineCode
{
private:
public:
//數(shù)據(jù)單元
int *lpImage;//圖象數(shù)據(jù)指針,波段預(yù)測時應(yīng)為預(yù)測誤差圖像
int OneSampleBits;
int AndCode;
int Pixel_ADD;
LPBYTE lpCodeStream;//編碼數(shù)據(jù)流
int CodeBitcp;
int LineN;//行計數(shù)
int A[367];//accumulated prediction error magnitude
int B[365];//computing the bias
// int CC[10];
int C[365];//storing prediction correction values
int N[367];//frequency of occurrence of each context
char qbpp;// number of bits needed to represent a mapped error value
char bpp;//number of bits needed to represent MAXVAL, with a minimum of 2
unsigned short int MAXVAL;//maximum possible image sample value over all components of a scan
short int RANGE;// range of prediction error representation
short int RESET;// threshold value at which A, B, and N are halved
BOOL EOLine;//end of line indicator, used in run mode
unsigned short int X;//number of samples per line in the component with largest horizontal dimension
short int MAX_C;// maximum allowed value of C[0..364], equal to 127
short int MIN_C;// minimum allowed value of C[0..364], equal to -128
short int LIMIT;// the value of glimit for a sample encoded in regular mode
unsigned short int qNEAR;// difference bound for near-lossless coding
int x;
int Ix;//the value of the current sample in the input image
int Ra,Rb,Rc,Rd,Raa;//reconstructed values of samples in the causal template
int *lpPrecedingLine,*lpCurrentLine,*lpThirdLine,*lpBuf1,*lpBuf2,*lpBuf3;
int *lpReconstructPrecedingLine,*lpReconstructCurrentLine,*lpBuf4,*lpBuf5;
int Rx;//reconstructed value of the current sample
int Px;//predicted value for the sample x
int T1, T2, T3;// thresholds for local gradients
int SIGN;//temporary variable used to hold the sign of a context
short int Q;//context determined from Q1, Q2, Q3
short int Q1,Q2,Q3;//region numbers of quantized local gradients
int Errval;//prediction error (quantized or unquantized, before and after modulo reduction)
int MErrval;//Errval mapped to non-negative integers in regular mode
int K;//Golomb coding variable for regular mode
int glimit;// number of bits to which the length of a Golomb code word is limited
short int J[32];// 32 variables indicating order of run-length codes
int RUNval;//repetitive reconstructed sample value in a run
int RUNcnt;//repetitive sample count for run mode
int RUNindex;//index for run mode order
int RItype;//index for run interruption coding
int TEMP;//auxiliary variable used in the calculation of the Golomb variable in run interruption coding
int map;//auxiliary variable for error mapping at run interruption
int EMErrval;//Errval mapped to non-negative integers in run interruption mode
short int Nn[2];// (365,366) 2 counters for negative prediction error for run interruption
int DoubleMaxError;//游程方式的檢測門限
int RunContext;//游程方式下的上下文控制門限
int MaxErrAdjust1;//第一級大誤差調(diào)節(jié)量
int MaxErrAdjust2;//第二級大誤差調(diào)節(jié)量
int RunTestThresholdStep;//游程方式下門限參數(shù)組指示。
int SetDoubleMaxError[MAX_RUN_TEST_THRESHOLD_NUMBER];//游程方式的檢測門限,預(yù)定值。
int SetRunContext[MAX_RUN_TEST_THRESHOLD_NUMBER];//游程方式下的上下文控制門限,預(yù)定值。
int SetMaxErrAdjust1[MAX_RUN_TEST_THRESHOLD_NUMBER];//第一級大誤差調(diào)節(jié)量,預(yù)定值。
int SetMaxErrAdjust2[MAX_RUN_TEST_THRESHOLD_NUMBER];//第二級大誤差調(diào)節(jié)量,預(yù)定值。
AdvanceJPEGLSMaxErrList *lpDoubleErrList;//存放每行大誤差位置和狀態(tài)
int DoubleErrN,DErrN,DDErrN;//大誤差數(shù),一級大誤差數(shù),二級大誤差數(shù)。
int AdjustErrorMe,TestErrorMeLimen;//平坦區(qū)單元均值調(diào)節(jié)值及調(diào)節(jié)檢測門限。
int AdjustWinLength,BakAdjustWinLength;//調(diào)節(jié)窗口長度。
int AdjustNumber,AllTestNumber;//單元調(diào)節(jié)數(shù)及總的測試單元數(shù),用于求單元調(diào)節(jié)率并用以控制單元調(diào)節(jié)檢測門限。
int RunPredication;//游程方式下的預(yù)測值
CDoubleErrorNumberFastCoding *lpDErrNumberFastCoding;//一級大誤差數(shù)編碼器
CDoubleErrorRunFastCoding *lpDErrRunFastCoding;//一級大誤差游程編碼器
CDoubleErrorNumberFastCoding *lpDDErrNumberFastCoding;//二級大誤差數(shù)編碼器
CDoubleErrorRunFastCoding *lpDDErrRunFastCoding;//二級大誤差游程編碼器
CDoubleErrorNumberFastCoding *lpTwoAdjustNumberFastCoding;//一級單元調(diào)節(jié)數(shù)編碼器
CDoubleErrorRunFastCoding *lpTwoAdjustRunFastCoding;//一級單元調(diào)節(jié)游程編碼器
CDoubleErrorNumberFastCoding *lpAdjustNumberFastCoding;//二級單元調(diào)節(jié)數(shù)編碼器
CDoubleErrorRunFastCoding *lpAdjustRunFastCoding;//二級單元調(diào)節(jié)游程編碼器
//用于多波段編碼
//AllowBandPrediction用在單象素編碼方式的切換,預(yù)波段預(yù)測可隨時啟用或關(guān)閉。
CAdvanceJepgLSOneLineCode *lpPredictionBandCode;//用于波段預(yù)測,可從該數(shù)據(jù)結(jié)構(gòu)中獲得預(yù)測波段的重建圖像數(shù)據(jù)
int A_Mul,B_Add,p;//用于波段預(yù)測的參數(shù)(線性預(yù)測)
//相關(guān)系數(shù)控制是否預(yù)測,當(dāng)相關(guān)系數(shù)小于某門限時:取消預(yù)測,此時,前行及前前行換成重建象素值(都加上PIX_ADD)。
//波段預(yù)測系數(shù)及相關(guān)系數(shù)還要更新,前行及前前行的預(yù)測系數(shù)要另行保存,以備預(yù)測開啟時用以求預(yù)測誤差重建值。
//開啟預(yù)測時:前行及前前行換成預(yù)測誤差重建值,設(shè)置開啟標(biāo)志
BOOL OpenOffBandPrediction,AllowBandPrediction;//初值為TRUE
int Last_A_Mul,Last_B_Add;//前行波段預(yù)測的參數(shù)(線性預(yù)測),初值與A_Mul,B_Add同
__int64 D_Cun,D_Pre,E_Cun,E_Pre,R_CunPre;
int PredictErr_D;//預(yù)測誤差的方差
int StatisticLinN;
public:
void UpdateBandPrediction();//更新波段預(yù)測參數(shù),更新變量A_Mul,A_Div,B_Add。
void InitBandPrediction();
void OpenBandPrediction();
void CloseBandPrediction();
void PrepareCode(int LineL,CAdvanceJepgLSOneLineCode *lpPredictionBand=NULL);
//用于多波段編碼
//函數(shù)
CAdvanceJepgLSOneLineCode();
~CAdvanceJepgLSOneLineCode();
BOOL CanEnterRUN();
BOOL GetNextSample();
void AppendToBitStream(int a,int b);//Function: appends the non-negative number a in binary form
//to the encoded bit stream, using b bits. Most significant bits are appended first.
//The process guarantees that b bits are sufficient to represent a exactly.
int Quantize(int a,int pNEAR);//Function: returns the quantized value of a following the procedure
//applied to Errval in Figure A.8 ("if" statement). This function is used to quantize
//the prediction error in near-lossless coding.
int ModRange(int a,int pRANGE);//Function: returns the value of a modulo RANGE as described in A.4.5.
int ComputeRx(int pNEAR);//Function: returns the reconstructed value Rx of the current sample
//as described in Figure A.8 (after the "if" statement). This function reconstructs
//the value of Rx from the quantized prediction error.
void InitialisationsCode(int OnePixelBit,int AllowMaxError);//初始化編碼器,一般在圖象數(shù)據(jù)加載之后
void EndCode();//主要是清除申請的緩沖區(qū),要在編碼數(shù)據(jù)處理完后方可結(jié)束
int RunPredicate();//游程方式下的預(yù)測
void ResetContext(int Seat);
int DoEncodeLine(LPBYTE lpImageBuf,int OneSampleBytes,LPBYTE lpCompressBuf,int CompressBitcp,double *lpErrorMse=NULL);//執(zhí)行一行圖像編碼操作
void AppendRunEncode(int Bgx,int Runl);
void EncodeDoubleError();//編碼一級大誤差
void EncodeDDoubleError();//編碼二級大誤差
void EncodeTwoAdjust(int *lpAdjustSequence,int AdjustLength,int TwoAdjustLength);//編碼二級調(diào)節(jié)序列
void EncodeAdjust(int *lpAdjustSequence,int AllAdjustLength,int AdjustLength);//編碼一級調(diào)節(jié)序列
//與譯碼有關(guān)的函數(shù)
int DoDecodeLine(LPBYTE lpImageBuf,int OneSampleBytes,LPBYTE lpCompressBuf,int CompressBitcp);//執(zhí)行一行圖像譯碼操作
BOOL SetNextSample();
int GetFromBitStream(int b);
int ReturnZeroBitNumber();
void AppendRunDecode(int Bgx,int Runl);
void DecodeDoubleError();
void DecodeDDoubleError();
int DecodeTwoAdjust(int *lpAdjustSequence,int AdjustLength);
int DecodeAdjust(int *lpAdjustSequence,int AllAdjustLength);
CString GetString();
};
//不含預(yù)測的單幅圖像壓縮實例
int OneImageAdvanceJPEGLSEncode(LPBYTE lpOneImageData,LPBYTE lpCompressBuf,
int Width,
int Height,
int AllowMaxError,
int OnePixelBits,
int OnePixelBytes);
int OneImageAdvanceJPEGLSDecode(LPBYTE lpOneImageData,LPBYTE lpCompressBuf,
int Width,
int Height,
int AllowMaxError,
int OnePixelBits,
int OnePixelBytes);
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -