?? compressencode.h
字號:
//基于DCT的靜態圖像壓縮編碼類
//Huffman碼表
typedef struct tag_HUFFMAN_TABLE {
unsigned int code[256]; // code for each symbol
char size[256]; // length of code for each symbol
//If no code has been allocated for a symbol S, size[S] is 0
/* These two fields directly represent the contents of a JPEG DHT marker */
unsigned char bits[17]; /* bits[k] = # of symbols with codes of */
/* length k bits; bits[0] is unused */
unsigned char huffval[256]; /* The symbols, in order of incr code length */
/* This field is used only during compression. It's initialized FALSE when
* the table is created, and set TRUE when it's been output to the file.
* You could suppress output of a table by setting this to TRUE.
* (See jpeg_suppress_tables for an example.)*/
}HUFFMAN_TABLE;
class CompressEncode
{
private:
////////////////////////////////////////////////////////////////////////////
// Following data members should be computed in initialization
unsigned short m_nQuality, m_nScale;
//RGB轉化YCbCr顏色對應表
int m_RToY[256], m_GToY[256], m_BToY[256];
int m_RToCb[256], m_GToCb[256], m_BToCb[256];
int m_RToCr[256], m_GToCr[256], m_BToCr[256];
// To speed up, we precompute two DCT quant tables
unsigned short m_qtblY[64], m_qtblCbCr[64];
//用來寫入JPG文件頭
unsigned char m_dqtY[64], m_dqtCbCr[64];
HUFFMAN_TABLE m_htblYDC, m_htblYAC, m_htblCbCrDC, m_htblCbCrAC;
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
// Following are should be initialized for compressing every image
unsigned short m_nWidth, m_nHeight;
// Three dc records, used for dc differentize for Y/Cb/Cr
int m_dcY, m_dcCb, m_dcCr;
// The size (in bits) and value (in 4 byte buffer) to be written out
int m_nPutBits, m_nPutVal;
unsigned char *m_pOutBuf;
////////////////////////////////////////////////////////////////////////////
private:
void InitEncoder( void );
void InitColorTable( void );
void InitQuantTable( void );
void ScaleQuantTable(
unsigned short* tblRst,
unsigned char* tblStd,
unsigned short* tblAan
);
void ScaleTable(unsigned char* tbl, int scale, int max);
void InitHuffmanTable( void );
void ComputeHuffmanTable(
unsigned char * pBits,
unsigned char * pVal,
HUFFMAN_TABLE * pTbl
);
bool CompressOneTile(
unsigned char * pBgr //source data, in BGR format
);
void BGRToYCbCr(
unsigned char * pBgr, //tile source data, in BGR format, 768 bytes
unsigned char * pY, //out, Illuminance, 256 bytes
unsigned char * pCb, //out, Cb, 256 bytes
unsigned char * pCr //out, Cr, 256 bytes
);
void BGRToYCbCrEx(
unsigned char * pBgr, //in, tile data, in BGR format, 768 bytes
int * pBlock //out, Y: 256; Cb: 64; Cr: 64
);
void ForwardDct(
int* data, //source data, length is 64
int* coef //output dct coefficients
);
void Quantize(
int* coef, //coef is both in and out
int iBlock //block id; Y: 0,1,2,3; Cb: 4; Cr: 5
);
bool HuffmanEncode(
int* pCoef, // DCT coefficients
int iBlock // 0,1,2,3:Y; 4:Cb; 5:Cr;
);
bool EmitBits(
unsigned int code, //Huffman code
int size //Size in bits of the Huffman code
);
void EmitLeftBits(void);
void WriteJpegHeader(void);
void write_sos(void);
void write_sof(int code);
void write_app0(void);
void write_soi(void);
void write_dht(int IsCbCr, int IsAc);
void write_dqt(int index);
public:
CompressEncode(); //default quality is 50
CompressEncode( int nQuality );
~CompressEncode();
bool CompressImage(
unsigned char *pInBuf, //source data, bgr format, 3 bytes per pixel
unsigned char *pOutBuf, //destination buffer, in jpg format
int nWidthPix, //image width in pixels
int nHeight, //height
int& nOutputBytes //return number of bytes being written
);
};
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -