Commit 33b89d9e authored by Aolin Feng's avatar Aolin Feng
Browse files

yuv420

parent 5e40df2b
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.Cpp.Platform.targets(57,5): error MSB8020: The build tools for v120 (Platform Toolset = 'v120') cannot be found. To build using the v120 build tools, please install v120 build tools. Alternatively, you may upgrade to the current Visual Studio tools by selecting the Project menu or right-click the solution, and then selecting "Retarget solution".
File added
......@@ -23,6 +23,7 @@
<ClInclude Include="source\Cfg.h" />
<ClInclude Include="source\CodingUnit.h" />
<ClInclude Include="source\CommonPic.h" />
<ClInclude Include="source\CommonRom.h" />
<ClInclude Include="source\TypeDef.h" />
</ItemGroup>
<ItemGroup>
......@@ -30,12 +31,14 @@
<ClCompile Include="source\Cfg.cpp" />
<ClCompile Include="source\CodingUnit.cpp" />
<ClCompile Include="source\CommonPic.cpp" />
<ClCompile Include="source\CommonRom.cpp" />
<ClCompile Include="source\JPEGEncoder.cpp" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{AE771B59-71F4-4534-8949-8698E3BD9306}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>JPEG</RootNamespace>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
......@@ -47,7 +50,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
......@@ -60,7 +63,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
......
......@@ -30,6 +30,9 @@
<ClInclude Include="source\TypeDef.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="source\CommonRom.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="source\BitStream.cpp">
......@@ -47,5 +50,8 @@
<ClCompile Include="source\JPEGEncoder.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="source\CommonRom.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
\ No newline at end of file
......@@ -37,8 +37,45 @@ Void BitStream::destroy()
Void BitStream::saveBit(std::string filename)
{
UChar* puiData;
puiData = new UChar[MAXBYTENUM];
UInt posSrc = 0;
UInt pos = 0;
// add 0x00 after 0xff
while (posSrc < ceil(m_uiBitPos / 8.0)) // stop until get EOI (*(m_puiData + posSrc) != 0xff) || (*(m_puiData + posSrc + 1) != 0xd9)
{
if ((*(m_puiData + posSrc) == 0xff) && (*(m_puiData + posSrc + 1) != 0xd8)
&& (*(m_puiData + posSrc + 1) != 0xe0)
&& (*(m_puiData + posSrc + 1) != 0xdb)
&& (*(m_puiData + posSrc + 1) != 0xc0)
&& (*(m_puiData + posSrc + 1) != 0xc4)
&& (*(m_puiData + posSrc + 1) != 0xda)
&& (*(m_puiData + posSrc + 1) != 0xd9))
{
*(puiData + pos) = *(m_puiData + posSrc);
*(puiData + pos + 1) = 0x00;
pos += 2;
}
else
{
*(puiData + pos) = *(m_puiData + posSrc);
pos++;
}
posSrc++;
} //end while
if (m_uiBitPos % 8) {
UInt tail = 0xff >> (m_uiBitPos % 8);
printf("tail: %d\n", tail);
*(puiData + pos - 1) += tail;
}
// EOI
*(puiData + pos) = 0xff;
*(puiData + pos + 1) = 0xd9;
printf("%d %d %d\n", pos, posSrc, m_uiBitPos);
FILE* fid;
fid = fopen(filename.c_str(), "wb");
fwrite(m_puiData, sizeof(unsigned char), ceil(m_uiBitPos / 8.0), fid);
fwrite(puiData, sizeof(unsigned char), pos+2, fid);
fclose(fid);
}
\ No newline at end of file
......@@ -3,10 +3,10 @@
//set header and configs
Void Cfg::parseCfg()
{
m_uiPicWidth = 416;
m_uiPicHeight = 240;
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_uiPicWidth = 16;
m_uiPicHeight = 16;
m_sInputFileName = "E:/Research/Project/RSP_JPEG/test_16x16.gbr"; //picture name, png
m_sOutputFileName = "E:/Research/Project/RSP_JPEG/Output/jpeg16.jpg"; //bitstream name, jpg
m_chromaFormat = CHROMA_420; //internal chroma format
m_dQp = 1;
}
\ No newline at end of file
......@@ -22,13 +22,14 @@ Void CodingUnit::initCU(ComponentID ch, UInt row, UInt col, CommonPic* pPic)
m_uiCol = col;
m_pPic = pPic;
UInt uiPicWidth = m_pPic->getPicWidth();
Pel* puiOrgPicBuf = m_pPic->getBufAddr(ch);
UInt stride = (m_pPic->getCfg()->getChromaFormat() == CHROMA_420 && ch != COMPONENT_Y) ? uiPicWidth >> 1 : uiPicWidth;
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++)
{
m_puiCUYuvBuf[i*CUSIZE + j] = puiOrgPicBuf[row*uiPicWidth*CUSIZE + col*CUSIZE + i*uiPicWidth + j];
m_puiCUYuvBuf[i*CUSIZE + j] = puiOrgPicBuf[row*stride*CUSIZE + col*CUSIZE + i*stride + j];
}
}
memset(m_puiCuDctCoeff, 0, CUSIZE*CUSIZE);
......@@ -132,8 +133,12 @@ Void CodingUnit::huffmanDC()
UInt uiNumColInWidth = m_pPic->getPicWidth() / CUSIZE;
iDC = *(m_pPic->getQuanCoeffAddr(m_uiChannal, m_uiRow, m_uiCol));
iDCLast = (Float(m_uiCUIdx) / Float(uiNumColInWidth) == 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);
iDCLast = (m_uiChannal == COMPONENT_Y) ? DClastY : (m_uiChannal == COMPONENT_Cb) ? DClastU : DClastV;
iDCDiff = iDC - iDCLast;
if (m_uiChannal == COMPONENT_Y) DClastY = iDC;
else if (m_uiChannal == COMPONENT_Cb) DClastU = iDC;
else DClastV = iDC;
UInt uiDCLength = getBitLengthOfValue(iDCDiff);
......
......@@ -26,17 +26,34 @@ Void CommonPic::compressPic()
Void CommonPic::encodePic()
{
for (UInt ch = COMPONENT_Y; ch < MAX_NUM_COMPONENT; ch++)
{
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_uiPicWidth / uiScale / CUSIZE; uiCol++)
{
DClastY = 0;
DClastU = 0;
DClastV = 0;
for (UInt uiRow = 0; uiRow < m_uiPicHeight / CUSIZE / 2; uiRow++)
{
for (UInt uiCol = 0; uiCol < m_uiPicWidth / CUSIZE / 2; uiCol++)
{
for (UInt ch = COMPONENT_Y; ch < MAX_NUM_COMPONENT; ch++)
{
Bool bDownsample = (m_cfg->getChromaFormat() == CHROMA_444) ? 0 : (ch == COMPONENT_Y) ? 0 : 1;
CodingUnit rcCU;
rcCU.create();
rcCU.initCU((ComponentID)ch, uiRow, uiCol, this);
rcCU.encodeCU();
if (bDownsample)
{
rcCU.initCU((ComponentID)ch, uiRow, uiCol, this);
rcCU.encodeCU();
}
else
{
rcCU.initCU((ComponentID)ch, uiRow * 2, uiCol * 2, this);
rcCU.encodeCU();
rcCU.initCU((ComponentID)ch, uiRow * 2, uiCol * 2 + 1, this);
rcCU.encodeCU();
rcCU.initCU((ComponentID)ch, uiRow * 2 + 1, uiCol * 2, this);
rcCU.encodeCU();
rcCU.initCU((ComponentID)ch, uiRow * 2 + 1, uiCol * 2 + 1, this);
rcCU.encodeCU();
}
rcCU.destroy();
}
}
......@@ -191,7 +208,8 @@ Void CommonPic::computeQpTable() //compute QpTable according g_uiQpTableBase
//return address of (row, col) CU
TCoeff* CommonPic::getQuanCoeffAddr(const ComponentID ch, UInt uiRow, UInt uiCol)
{
UInt uiNumOfColInWidth = m_uiPicWidth / CUSIZE;
UInt uiScale = (m_cfg->getChromaFormat() == CHROMA_420 && ch != COMPONENT_Y) ? 2 : 1;
UInt uiNumOfColInWidth = m_uiPicWidth / CUSIZE / uiScale;
UInt uiNumPixelInCU = CUSIZE * CUSIZE;
return m_piPicQuanCoeff[ch] + (uiRow*uiNumOfColInWidth + uiCol) * uiNumPixelInCU;
}
......@@ -255,11 +273,11 @@ Void CommonPic::writeFrameHeader()
m_bitStream->writeBit(0x00, 8);
m_bitStream->writeBit(0x02, 8); //U
m_bitStream->writeBit(0x22, 8); // 0X22 for downsample 2
m_bitStream->writeBit(0x11, 8); // 0X22 for downsample 2
m_bitStream->writeBit(0x01, 8);
m_bitStream->writeBit(0x03, 8); //V
m_bitStream->writeBit(0x22, 8);
m_bitStream->writeBit(0x11, 8);
m_bitStream->writeBit(0x01, 8);
}
......
......@@ -45,6 +45,7 @@ class CommonPic
UInt getOrgPicHeight() { return m_uiOrgPicHeight; }
UInt getPicWidth() { return m_uiPicWidth; }
UInt getPicHeight() { return m_uiPicHeight; }
Cfg* getCfg() { return m_cfg; }
Void setOrgPicWidth(UInt width) { m_uiOrgPicWidth = width; }
Void setOrgPicHeight(UInt height) { m_uiOrgPicHeight = height; }
......
......@@ -50,3 +50,6 @@ UInt g_uiQpTableBase[2][CUSIZE*CUSIZE] = { { 16, 11, 10, 16, 24, 40, 51, 61, 12,
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 } };
TCoeff DClastY;
TCoeff DClastU;
TCoeff DClastV;
......@@ -15,4 +15,8 @@ extern UInt g_uiACSymbolDHT[2][162]; //UV
extern UInt g_uiQpTableBase[2][CUSIZE*CUSIZE];
extern TCoeff DClastY;
extern TCoeff DClastU;
extern TCoeff DClastV;
#endif
\ No newline at end of file
......@@ -12,7 +12,7 @@ int main ()
rcPic.compressPic();
rcPic.writeHead();
rcPic.encodePic();
rcPic.writeEOI();
//rcPic.writeEOI();
rcPic.getBitStream()->saveBit(cfg.getOutputFileName());
rcPic.destroy();
}
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