Commit 5e40df2b authored by changsheng gao's avatar changsheng gao
Browse files

allMerged07121632

parent 544093d2
......@@ -2,43 +2,43 @@
#include "BitStream.h"
#include <iostream>
// input value and length of current Huffman code
// write to data
Void BitStream:: writeBit(UInt value, UInt length)
{
// input value and length of current Huffman code
// write to data
UInt byteID = bitPos / 8;
UInt bitID = bitPos % 8;
if (length <= 8 - bitID)
UInt uiByteIdx = m_uiBitPos / 8;
UInt uiBitIdx = m_uiBitPos % 8;
if (length <= 8 - uiBitIdx)
{
data[byteID] += value << (8 - bitID - length);
bitPos += length;
m_puiData[uiByteIdx] += value << (8 - uiBitIdx - length);
m_uiBitPos += length;
}
else
{
UInt writein = value >> (length - (8 - bitID));
data[byteID] += writein;
bitPos += 8 - bitID;
writeBit(value - writein << (length - (8 - bitID)), length - (8 - bitID));
UInt writein = value >> (length - (8 - uiBitIdx));
m_puiData[uiByteIdx] += writein;
m_uiBitPos += 8 - uiBitIdx;
writeBit(value - (writein << (length - (8 - uiBitIdx))), length - (8 - uiBitIdx));
}
}
Void BitStream::init()
{
data = new unsigned char[MAXBYTENUM];
memset(data, 0, MAXBYTENUM);
bitPos = 0;
m_puiData = new UChar[MAXBYTENUM];
memset(m_puiData, 0, MAXBYTENUM);
m_uiBitPos = 0;
}
Void BitStream::destroy()
{
delete[] data;
data = NULL;
delete[] m_puiData;
m_puiData = NULL;
}
Void BitStream::saveBit(std::string filename)
{
FILE* fid;
fid = fopen(filename.c_str(), "wb");
fwrite(data, sizeof(unsigned char), ceil(bitPos / 8.0), fid);
fwrite(m_puiData, sizeof(unsigned char), ceil(m_uiBitPos / 8.0), fid);
fclose(fid);
}
\ No newline at end of file
......@@ -8,13 +8,14 @@
class BitStream
{
private:
UChar* data;
UInt bitPos; //num of bits
UChar* m_puiData;
UInt m_uiBitPos; //num of bits
public:
Void init();
Void destroy();
Void writeBit(UInt value, UInt length);
Void saveBit(std::string filename);
UChar* getData() { return m_puiData; }
Void init();
Void destroy();
Void writeBit(UInt value, UInt length);
Void saveBit(std::string filename);
};
#endif
\ No newline at end of file
......@@ -5,8 +5,8 @@ Void Cfg::parseCfg()
{
m_uiPicWidth = 416;
m_uiPicHeight = 240;
m_sInputFileName = //picture name, png
m_sOutputFileName = "jpeg.jpg"; //bitstream name, jpg
m_chromaFormat = CHROMA_420; //internal chroma format
m_sInputFileName = "G:/jpeg/images/BasketballPass_416x240_50.gbr"; //picture name, png
m_sOutputFileName = "G:/jpeg/images/jpeg.jpg"; //bitstream name, jpg
m_chromaFormat = CHROMA_444; //internal chroma format
m_dQp = 1;
}
\ No newline at end of file
......@@ -15,6 +15,7 @@ class Cfg
string m_sInputFileName; //picture name, png
string m_sOutputFileName; //bitstream name, jpg
Double m_dQp;
ChromaFormat m_chromaFormat; //internal chroma format
public:
......@@ -24,6 +25,7 @@ class Cfg
string getInputFileName() { return m_sInputFileName; }
string getOutputFileName() { return m_sOutputFileName; }
ChromaFormat getChromaFormat() { return m_chromaFormat; }
Double getQp() { return m_dQp; }
Void setPicWidth(UInt width) { m_uiPicWidth = width; }
Void setPicHeight(UInt height) { m_uiPicHeight = height; }
......
......@@ -3,7 +3,7 @@
Void CodingUnit::create() //allocate memory for YUV and coeff
{
m_puiCUYuvBuf = new Pel[CUSIZE*CUSIZE];
m_puiCUYuvBuf = new Short[CUSIZE*CUSIZE];
m_puiCuDctCoeff = new TCoeff[CUSIZE*CUSIZE];
m_puiCuQuanCoeff = new TCoeff[CUSIZE*CUSIZE];
}
......@@ -23,6 +23,7 @@ Void CodingUnit::initCU(ComponentID ch, UInt row, UInt col, CommonPic* pPic)
m_pPic = pPic;
UInt uiPicWidth = m_pPic->getPicWidth();
Pel* puiOrgPicBuf = m_pPic->getBufAddr(ch);
m_uiCUIdx = m_uiRow * uiPicWidth / CUSIZE + m_uiCol;
for (int i = 0; i < CUSIZE; i++)
{
for (int j = 0; j < CUSIZE; j++)
......@@ -30,6 +31,8 @@ Void CodingUnit::initCU(ComponentID ch, UInt row, UInt col, CommonPic* pPic)
m_puiCUYuvBuf[i*CUSIZE + j] = puiOrgPicBuf[row*uiPicWidth*CUSIZE + col*CUSIZE + i*uiPicWidth + j];
}
}
memset(m_puiCuDctCoeff, 0, CUSIZE*CUSIZE);
memset(m_puiCuQuanCoeff, 0, CUSIZE*CUSIZE);
}
//input: uiCuYuvBuf
......@@ -40,10 +43,10 @@ Void CodingUnit::compressCU()
quantize();
}
//input: m_puiCuQuanCoeff
//output: bitstream
Void CodingUnit::encodeCU()
{
//input: m_puiCuQuanCoeff
//output: bitstream
huffman();
}
......@@ -96,8 +99,9 @@ Void CodingUnit::quantize() // quantize dct coeff and copy quantized coeff to
UInt uiNumOfPixelInCU = CUSIZE * CUSIZE;
for (UInt n = 0; n < uiNumOfPixelInCU; n++)
{
*(m_puiCuQuanCoeff+n) = round( *(m_puiCuDctCoeff+n) / *(uiQuanTable+n) );
*(m_puiCuQuanCoeff+n) = TCoeff (round( *(m_puiCuDctCoeff+n) / Int(*(uiQuanTable+n)) )); //Int can not divided by UInt //https://stackoverflow.com/questions/5328269/int-divided-by-unsigned-int-causing-rollover
}
copyPartToPic();
}
//input: cu information
......@@ -112,10 +116,10 @@ Void CodingUnit::copyPartToPic()
}
}
//input:uiQuaDctCoeff
//output:pic.bitstream
Void CodingUnit::huffman() // quaDctCoeff>bitstream
{
//input:uiQuaDctCoeff
//output:pic.bitstream
huffmanDC();
huffmanAC();
}
......@@ -125,9 +129,10 @@ Void CodingUnit::huffmanDC()
//compute DC difference
TCoeff iDC, iDCLast, iDCDiff;
UInt uiNumPixelInCU = CUSIZE * CUSIZE;
UInt uiNumColInWidth = m_pPic->getPicWidth() / CUSIZE;
iDC = *(m_pPic->getQuanCoeffAddr(m_uiChannal, m_uiRow, m_uiCol));
iDCLast = (m_uiCUIdx == 0) ? 0 : *(m_pPic->getQuanCoeffAddr(m_uiChannal, m_uiRow, m_uiCol) - uiNumPixelInCU);
iDCLast = (Float(m_uiCUIdx) / Float(uiNumColInWidth) == 0) ? 0 : *(m_pPic->getQuanCoeffAddr(m_uiChannal, m_uiRow, m_uiCol) - uiNumPixelInCU);
iDCDiff = iDC - iDCLast;
UInt uiDCLength = getBitLengthOfValue(iDCDiff);
......@@ -155,15 +160,24 @@ Void CodingUnit::huffmanDC()
Void CodingUnit::huffmanAC()
{
#if DEBUG
UInt row = m_uiRow, col = m_uiCol;
cout << row << ' ' << col << endl;
#endif
UInt uiCUIdx = m_uiCUIdx;
UInt ch = m_uiChannal;
TCoeff* uiQuanCoeff = m_pPic->getQuanCoeffAddr(m_uiChannal, m_uiRow, m_uiCol);
UInt uiNumPixelInCU = CUSIZE * CUSIZE;
//derive EOB
UInt uiPosEOB = uiNumPixelInCU - 1;
while (*(uiQuanCoeff + g_uiZigZagTable[uiPosEOB]) != 0)
while (*(uiQuanCoeff + g_uiZigZagTable[uiPosEOB]) == 0 && uiPosEOB > 0)
{
uiPosEOB--;
}
#if DEBUG
cout << uiPosEOB << endl;
#endif
UInt uiZigZagEOB = g_uiZigZagTable[uiPosEOB];
//derive run and size
......@@ -175,7 +189,7 @@ Void CodingUnit::huffmanAC()
uiRun++;
if (uiRun == uiMaxRun)
{
UInt uiRunSize = (uiRun - 1) << 4 + 0; //F0
UInt uiRunSize = 0xF0; //F0
UInt uiCode, uiLength;
if (m_uiChannal == COMPONENT_Y)
{
......@@ -208,6 +222,7 @@ Void CodingUnit::huffmanAC()
uiCode = *(m_pPic->getHuffmanTableLumaAC() + uiRunSize);
uiLength = *(m_pPic->getHuffmanTableLumaAC() + ACLENGTH + uiRunSize);
}
//write run and size of nonzero value
m_pPic->getBitStream()->writeBit(uiCode, uiLength);
......@@ -220,7 +235,7 @@ Void CodingUnit::huffmanAC()
//write EOB
if (uiPosEOB != 63)
{
m_pPic->getBitStream()->writeBit(0, 8); //
(m_uiChannal == COMPONENT_Y) ? m_pPic->getBitStream()->writeBit(10, 4) : m_pPic->getBitStream()->writeBit(0, 2);
}
}
......@@ -228,6 +243,7 @@ UInt CodingUnit::getBitLengthOfValue(Int value)
{
UInt uiAbsValue = abs(value);
UInt length = 0;
if (uiAbsValue == 0) return 1;
while (uiAbsValue != 0)
{
length++;
......@@ -239,5 +255,5 @@ UInt CodingUnit::getBitLengthOfValue(Int value)
UInt CodingUnit::getComplement(Int value, UInt length)
{
if (value >= 0) { return value; }
else { return value + pow(2, length) - 1; }
else { return UInt(value + pow(2, length) - 1); }
}
\ No newline at end of file
......@@ -12,7 +12,7 @@ class CodingUnit
UInt m_uiCUIdx;
UInt m_uiRow;
UInt m_uiCol;
Pel* m_puiCUYuvBuf;
Short* m_puiCUYuvBuf;
TCoeff* m_puiCuDctCoeff;
TCoeff* m_puiCuQuanCoeff;
CommonPic* m_pPic;
......@@ -22,7 +22,7 @@ class CodingUnit
Void destroy(); //free memory
Void initCU(ComponentID ch, UInt row, UInt col, CommonPic* pPic);
Pel* getYuvAddr() { return m_puiCUYuvBuf; } //start address of yuv
Short* getYuvAddr() { return m_puiCUYuvBuf; } //start address of yuv
TCoeff* getDctCoeffAddr() { return m_puiCuDctCoeff; } //start address of dct
TCoeff* getQuanCoeffAddr() { return m_puiCuQuanCoeff; }
......
......@@ -2,15 +2,17 @@
#include "CommonPic.h"
#include "CodingUnit.h"
UChar clip(Double value);
Void CommonPic::compressPic()
{
computeQpTable();
for (UInt ch = COMPONENT_Y; ch < MAX_NUM_COMPONENT; ch++)
{
UInt uiScale = (ch == COMPONENT_Y) ? 1 : 2;
for (UInt uiRow = 0; uiRow < m_uiPicWidth / uiScale / CUSIZE; uiRow++)
UInt uiScale = (m_cfg->getChromaFormat() == CHROMA_444) ? 1 : (ch == COMPONENT_Y) ? 1 : 2;
for (UInt uiRow = 0; uiRow < m_uiPicHeight / uiScale / CUSIZE; uiRow++)
{
for (UInt uiCol = 0; uiCol < m_uiPicHeight / uiScale / CUSIZE; uiCol++)
for (UInt uiCol = 0; uiCol < m_uiPicWidth / uiScale / CUSIZE; uiCol++)
{
CodingUnit rcCU;
rcCU.create();
......@@ -26,10 +28,10 @@ Void CommonPic::encodePic()
{
for (UInt ch = COMPONENT_Y; ch < MAX_NUM_COMPONENT; ch++)
{
UInt uiScale = (ch == COMPONENT_Y) ? 1 : 2;
for (UInt uiRow = 0; uiRow < m_uiPicWidth / uiScale / CUSIZE; uiRow++)
UInt uiScale = (m_cfg->getChromaFormat() == CHROMA_444) ? 1 : (ch == COMPONENT_Y) ? 1 : 2;
for (UInt uiRow = 0; uiRow < m_uiPicHeight / uiScale / CUSIZE; uiRow++)
{
for (UInt uiCol = 0; uiCol < m_uiPicHeight / uiScale / CUSIZE; uiCol++)
for (UInt uiCol = 0; uiCol < m_uiPicWidth / uiScale / CUSIZE; uiCol++)
{
CodingUnit rcCU;
rcCU.create();
......@@ -49,24 +51,28 @@ Void CommonPic::destroy() //free memory
Void CommonPic::init(Cfg cfg)
{
m_cfg = &cfg;
m_uiOrgPicWidth = cfg.getPicWidth();
m_uiOrgPicHeight = cfg.getPicHeight();
ChromaFormat chromaFormat = cfg.getChromaFormat();
m_dQp = cfg.getQp();
m_uiQpTable[0] = new UInt[64];
m_uiQpTable[1] = new UInt[64];
UInt uiEvenPicWidth = m_uiOrgPicWidth % 2 ? m_uiOrgPicWidth + 1 : m_uiOrgPicWidth;
UInt uiEvenPicHeight = m_uiOrgPicHeight % 2 ? m_uiOrgPicHeight + 1 : m_uiOrgPicHeight;
m_uiPicWidth = uiEvenPicWidth % CUSIZE ? (uiEvenPicWidth / CUSIZE + 1) * CUSIZE : uiEvenPicWidth;
m_uiPicHeight = uiEvenPicHeight % CUSIZE ? (uiEvenPicHeight / CUSIZE + 1) * CUSIZE : uiEvenPicHeight;
for (int iComp = 0; iComp < MAX_NUM_COMPONENT; iComp++)
for (UInt iComp = 0; iComp < MAX_NUM_COMPONENT; iComp++)
{
UInt uiScale = (chromaFormat == CHROMA_420 && iComp != COMPONENT_Y) ? 4 : 1;
m_puiOrgPicRgb[iComp] = new Pel[m_uiOrgPicWidth * m_uiOrgPicWidth];
m_puiOrgPicRgb[iComp] = new Pel[m_uiOrgPicWidth * m_uiOrgPicHeight];
m_puiOrgPicYuv[iComp] = new Pel[uiEvenPicWidth * uiEvenPicHeight];
m_puiOrgPicBuf[iComp] = new Pel[m_uiPicWidth * m_uiPicHeight / uiScale];
m_uiPicDctCoeff[iComp] = new TCoeff[m_uiPicWidth * m_uiPicHeight / uiScale];
m_piPicQuanCoeff[iComp] = new TCoeff[m_uiPicWidth * m_uiPicHeight / uiScale];
memset(m_puiOrgPicRgb[iComp], 0, m_uiOrgPicWidth * m_uiOrgPicWidth);
memset(m_puiOrgPicRgb[iComp], 0, m_uiOrgPicWidth * uiEvenPicHeight);
memset(m_puiOrgPicYuv[iComp], 0, uiEvenPicWidth * uiEvenPicHeight);
memset(m_puiOrgPicBuf[iComp], 0, m_uiPicWidth * m_uiPicHeight / uiScale);
memset(m_uiPicDctCoeff[iComp], 0, m_uiPicWidth * m_uiPicHeight / uiScale);
......@@ -74,16 +80,21 @@ Void CommonPic::init(Cfg cfg)
}
readRgb(cfg.getInputFileName());
colorSpaceConvert(chromaFormat);
}
m_bitStream = new BitStream[1]; //!!!allocate memory for bitStream
m_bitStream->init();
huffmanTableGeneration();
}
//input: filename defined in cfg
//output: uiOrgPicRgb
Void CommonPic::readRgb(string sInputFileName) //read yuv to uiOrgPicYuv
{
FILE* file = fopen(sInputFileName.c_str(), "rb+");
fread(m_puiOrgPicRgb[COMPONENT_Y], sizeof(Pel), m_uiOrgPicHeight * m_uiOrgPicWidth, file);//R
fread(m_puiOrgPicRgb[COMPONENT_Cb], sizeof(Pel), m_uiOrgPicHeight * m_uiOrgPicWidth, file);//G
fread(m_puiOrgPicRgb[COMPONENT_Cr], sizeof(Pel), m_uiOrgPicHeight * m_uiOrgPicWidth, file);//B
fread(m_puiOrgPicRgb[COMPONENT_Cb], 1, m_uiOrgPicHeight * m_uiOrgPicWidth, file);//G
fread(m_puiOrgPicRgb[COMPONENT_Cr], 1, m_uiOrgPicHeight * m_uiOrgPicWidth, file);//B
fread(m_puiOrgPicRgb[COMPONENT_Y], 1, m_uiOrgPicHeight * m_uiOrgPicWidth, file);//R
fclose(file);
}
......@@ -96,9 +107,9 @@ Void CommonPic::colorSpaceConvert(ChromaFormat format) // color space convert, s
{
for (UInt j = 0; j < m_uiOrgPicWidth; j++)
{
m_puiOrgPicYuv[COMPONENT_Y][i * uiEvenPicWidth + j] = (Pel)(0.212600 * m_puiOrgPicRgb[COMPONENT_Y][i * m_uiOrgPicWidth + j] + 0.715200 * m_puiOrgPicRgb[COMPONENT_Cb][i * m_uiOrgPicWidth + j] + 0.072200 * m_puiOrgPicRgb[COMPONENT_Cr][i * m_uiOrgPicWidth + j]); //Y
m_puiOrgPicYuv[COMPONENT_Cb][i * uiEvenPicWidth + j] = (Pel)(-0.114572 * m_puiOrgPicRgb[COMPONENT_Y][i * m_uiOrgPicWidth + j] - 0.385428 * m_puiOrgPicRgb[COMPONENT_Cb][i * m_uiOrgPicWidth + j] + 0.5 * m_puiOrgPicRgb[COMPONENT_Cr][i * m_uiOrgPicWidth + j] + 128); //U
m_puiOrgPicYuv[COMPONENT_Cr][i * uiEvenPicWidth + j] = (Pel)(0.5 * m_puiOrgPicRgb[COMPONENT_Y][i * m_uiOrgPicWidth + j] - 0.454153 * m_puiOrgPicRgb[COMPONENT_Cb][i * m_uiOrgPicWidth + j] - 0.045847 * m_puiOrgPicRgb[COMPONENT_Cr][i * m_uiOrgPicWidth + j] + 128); //V
m_puiOrgPicYuv[COMPONENT_Y][i * uiEvenPicWidth + j] = clip(0.212600 * m_puiOrgPicRgb[COMPONENT_Y][i * m_uiOrgPicWidth + j] + 0.715200 * m_puiOrgPicRgb[COMPONENT_Cb][i * m_uiOrgPicWidth + j] + 0.072200 * m_puiOrgPicRgb[COMPONENT_Cr][i * m_uiOrgPicWidth + j]); //Y
m_puiOrgPicYuv[COMPONENT_Cb][i * uiEvenPicWidth + j] = clip(-0.114572 * m_puiOrgPicRgb[COMPONENT_Y][i * m_uiOrgPicWidth + j] - 0.385428 * m_puiOrgPicRgb[COMPONENT_Cb][i * m_uiOrgPicWidth + j] + 0.5 * m_puiOrgPicRgb[COMPONENT_Cr][i * m_uiOrgPicWidth + j] + 128); //U
m_puiOrgPicYuv[COMPONENT_Cr][i * uiEvenPicWidth + j] = clip(0.5 * m_puiOrgPicRgb[COMPONENT_Y][i * m_uiOrgPicWidth + j] - 0.454153 * m_puiOrgPicRgb[COMPONENT_Cb][i * m_uiOrgPicWidth + j] - 0.045847 * m_puiOrgPicRgb[COMPONENT_Cr][i * m_uiOrgPicWidth + j] + 128); //V
}
}
if (format == CHROMA_420)
......@@ -132,31 +143,20 @@ Void CommonPic::colorSpaceConvert(ChromaFormat format) // color space convert, s
}
}
}
}
Void CommonPic::writeHead()
{
writeStreamHeader();
writeQpTable();
writeFrameHeader();
writeHuffmanTable();
writeScanHeader();
}
Void CommonPic::huffmanTableGeneration()
{
huffmanTableGenerationBase(g_uiDCLengthDHT[0], g_uiDCSymbolDHT[0], this->getHuffmanTableLumaDC(), this->getHuffmanTableLumaDC()+DCLENGTH, true); //LumaDC
huffmanTableGenerationBase(g_uiDCLengthDHT[1], g_uiDCSymbolDHT[1], this->getHuffmanTableChromaDC(), this->getHuffmanTableChromaDC()+DCLENGTH, false); //ChromaDC
huffmanTableGenerationBase(g_uiACLengthDHT[0], g_uiACSymbolDHT[0], this->getHuffmanTableLumaAC(), this->getHuffmanTableLumaAC() + ACLENGTH, true); //LumaDC
huffmanTableGenerationBase(g_uiACLengthDHT[1], g_uiACSymbolDHT[1], this->getHuffmanTableChromaAC(), this->getHuffmanTableChromaAC() + ACLENGTH, false); //ChromaDC
huffmanTableGenerationBase(g_uiDCLengthDHT[0], g_uiDCSymbolDHT[0], this->getHuffmanTableLumaDC(), this->getHuffmanTableLumaDC()+DCLENGTH); //LumaDC
huffmanTableGenerationBase(g_uiDCLengthDHT[1], g_uiDCSymbolDHT[1], this->getHuffmanTableChromaDC(), this->getHuffmanTableChromaDC()+DCLENGTH); //ChromaDC
huffmanTableGenerationBase(g_uiACLengthDHT[0], g_uiACSymbolDHT[0], this->getHuffmanTableLumaAC(), this->getHuffmanTableLumaAC() + ACLENGTH); //LumaDC
huffmanTableGenerationBase(g_uiACLengthDHT[1], g_uiACSymbolDHT[1], this->getHuffmanTableChromaAC(), this->getHuffmanTableChromaAC() + ACLENGTH); //ChromaDC
}
Void CommonPic::huffmanTableGenerationBase(UInt* uiDHTLength, UInt* uiDHTSymbol, UInt* uiHuffmanTableCode, UInt* uiHuffmanTableLength, Bool bDCFlag)
Void CommonPic::huffmanTableGenerationBase(UInt* uiDHTLength, UInt* uiDHTSymbol, UInt* uiHuffmanTableCode, UInt* uiHuffmanTableLength)
{
UInt code = 0;
UInt uiLength = bDCFlag ? DCLENGTH : ACLENGTH;
UInt uiLength = 16;
for (UInt i = 0; i < uiLength; i++)
{
UInt num = uiDHTLength[i];
......@@ -183,7 +183,7 @@ Void CommonPic::computeQpTable() //compute QpTable according g_uiQpTableBase
{
for (UInt i = 0; i < CUSIZE*CUSIZE; i++)
{
*(m_uiQpTable[ch] + i) = (UInt)round(g_uiQpTableBase[ch][i] * m_uiQp);
*(m_uiQpTable[ch] + i) = (UInt)round(g_uiQpTableBase[ch][i] * m_dQp);
}
}
}
......@@ -196,6 +196,15 @@ TCoeff* CommonPic::getQuanCoeffAddr(const ComponentID ch, UInt uiRow, UInt uiCol
return m_piPicQuanCoeff[ch] + (uiRow*uiNumOfColInWidth + uiCol) * uiNumPixelInCU;
}
Void CommonPic::writeHead()
{
writeStreamHeader();
writeQpTable();
writeFrameHeader();
writeHuffmanTable();
writeScanHeader();
}
Void CommonPic::writeStreamHeader()
{
UInt Head_Table[20] = { 0xff, 0xd8, 0xff, 0xe0, 0x00, 0x10, 0x4a, 0x46, 0x49, 0x46,
......@@ -222,8 +231,8 @@ Void CommonPic::writeQpTable()
//write Q_table UV
m_bitStream->writeBit(0xff, 8);
m_bitStream->writeBit(0xdb, 8);
m_bitStream->writeBit(0x00, 8);
m_bitStream->writeBit(0x43, 16); // for AC
m_bitStream->writeBit(0x0043, 16); // for AC
m_bitStream->writeBit(0x01, 8);
for (UInt idx = 0; idx < uiNumOfPixelInCU; idx++)
{
......@@ -237,20 +246,20 @@ Void CommonPic::writeFrameHeader()
m_bitStream->writeBit(0xc0, 8);
m_bitStream->writeBit(0x0011, 16); //length of the bitstream of Q_table
m_bitStream->writeBit(0x08, 8); // precision
m_bitStream->writeBit(m_uiOrgPicWidth, 16);
m_bitStream->writeBit(m_uiOrgPicHeight, 16);
m_bitStream->writeBit(m_uiOrgPicWidth, 16);
m_bitStream->writeBit(0x03, 8);
m_bitStream->writeBit(0x01, 8);
m_bitStream->writeBit(0x01, 8); //Y
m_bitStream->writeBit(0x22, 8);
m_bitStream->writeBit(0x00, 8);
m_bitStream->writeBit(0x02, 8);
m_bitStream->writeBit(0x11, 8);
m_bitStream->writeBit(0x02, 8); //U
m_bitStream->writeBit(0x22, 8); // 0X22 for downsample 2
m_bitStream->writeBit(0x01, 8);
m_bitStream->writeBit(0x03, 8);
m_bitStream->writeBit(0x11, 8);
m_bitStream->writeBit(0x03, 8); //V
m_bitStream->writeBit(0x22, 8);
m_bitStream->writeBit(0x01, 8);
}
......@@ -335,3 +344,7 @@ Void CommonPic::writeEOI()
m_bitStream->writeBit(EQI[1], 8);
}
UChar clip(Double value)
{
return UChar( (value < 0) ? 0 : (value>255) ? 255 : value);
}
\ No newline at end of file
......@@ -23,7 +23,12 @@ class CommonPic
TCoeff* m_piPicQuanCoeff[MAX_NUM_COMPONENT];
UInt* m_uiQpTable[2];
UInt m_uiQp;
Double m_dQp;
UInt* m_uiDCLengthDHT[2];
UInt* m_uiDCSymbolDHT[2];
UInt* m_uiACLengthDHT[2];
UInt* m_uiACSymbolDHT[2];
UInt m_uiHuffmanTableLumaDC[2][DCLENGTH]; //1st dim for value, 2nd dim for length
UInt m_uiHuffmanTableChromaDC[2][DCLENGTH];
......@@ -76,7 +81,7 @@ class CommonPic
Void writeEOI();
Void huffmanTableGeneration();
Void huffmanTableGenerationBase(UInt* uiDHTLength, UInt* uiDHTSymbol, UInt* uiHuffmanTableCode, UInt* uiHuffmanTableLength, Bool bDCFlag);
Void huffmanTableGenerationBase(UInt* uiDHTLength, UInt* uiDHTSymbol, UInt* uiHuffmanTableCode, UInt* uiHuffmanTableLength);
};
......
......@@ -10,10 +10,10 @@ UInt g_uiZigZagTable[64] = { 0, 1, 8, 16, 9, 2, 3, 10,
53, 60, 61, 54, 47, 55, 62, 63 };
UInt g_uiDCLengthDHT[2][16] = { { 0x00, 0x01, 0x05, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, //Y
{ 0x00, 0x03, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00 } }; //UV
{ 0x00, 0x03, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00 } }; //UV
UInt g_uiDCSymbolDHT[2][12] = { { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b }, //Y
{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b } }; //UV
{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b } }; //UV
UInt g_uiACLengthDHT[2][16] { { 0x00, 0x02, 0x01, 0x03, 0x03, 0x02, 0x04, 0x03, 0x05, 0x05, 0x04, 0x04, 0x00, 0x00, 0x01, 0x7d}, //Y
{ 0x00, 0x02, 0x01, 0x02, 0x04, 0x04, 0x03, 0x04, 0x07, 0x05, 0x04, 0x04, 0x00, 0x01, 0x02, 0x77 }}; //UV
......@@ -48,4 +48,5 @@ UInt g_uiQpTableBase[2][CUSIZE*CUSIZE] = { { 16, 11, 10, 16, 24, 40, 51, 61, 12,
{ 17, 18, 24, 47, 99, 99, 99, 99, 18, 21, 26, 66, 99, 99, 99, 99,
24, 26, 56, 99, 99, 99, 99, 99, 47, 66, 99, 99, 99, 99, 99, 99,
99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99,
99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99 } };
\ No newline at end of file
99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99 } };
......@@ -9,10 +9,10 @@ int main ()
CommonPic rcPic;
rcPic.init(cfg);
rcPic.writeHead();
rcPic.compressPic();
rcPic.writeHead();
rcPic.encodePic();
rcPic.getBitStream()->saveBit(cfg.getOutputFileName());
rcPic.writeEOI();
rcPic.getBitStream()->saveBit(cfg.getOutputFileName());
rcPic.destroy();
}
......@@ -4,7 +4,8 @@
#define CUSIZE 8
#define DCLENGTH 12
#define ACLENGTH 256
#define MAXBYTENUM 1000000
#define MAXBYTENUM 10000000
#define DEBUG 0
typedef void Void;
typedef bool Bool;
......@@ -19,7 +20,7 @@ typedef unsigned int UInt;
typedef double Double;
typedef float Float;
typedef Short Pel; ///< pixel type
typedef unsigned char Pel; ///< pixel type
typedef Int TCoeff; ///< transform coefficient
enum ComponentID
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment