Ignore:
Timestamp:
20 Feb 2013, 22:07:43 (12 years ago)
Author:
tech
Message:

Reintegrated branch 5.1-dev0 rev. 295.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/Lib/TLibCommon/TComSampleAdaptiveOffset.cpp

    r56 r296  
    6666  m_pClipTable = NULL;
    6767  m_pClipTableBase = NULL;
    68 #if SAO_UNIT_INTERLEAVING
    6968  m_lumaTableBo = NULL;
    70 #else
    71   m_ppLumaTableBo0 = NULL;
    72   m_ppLumaTableBo1 = NULL;
    73 #endif
    7469  m_iUpBuff1 = NULL;
    7570  m_iUpBuff2 = NULL;
     
    136131  2,
    137132  2,
    138 #if !SAO_UNIT_INTERLEAVING
    139   1,
    140 #endif
    141133  1
    142134};
     
    161153  SAO_EO_LEN,
    162154  SAO_EO_LEN,
    163 #if !SAO_UNIT_INTERLEAVING
    164   SAO_BO_LEN,
    165 #endif
    166155  SAO_BO_LEN
    167156};
     
    259248   * m_iNumTotalParts must allow for sufficient storage in any allocated arrays */
    260249  m_iNumTotalParts  = max(3,m_aiNumCulPartsLevel[m_uiMaxSplitLevel]);
    261 #if !SAO_UNIT_INTERLEAVING
    262   UInt auiTable[2][LUMA_GROUP_NUM] =
    263   {{0, 0, 0, 0, 0, 0, 0, 0,
    264   1, 2, 3, 4, 5, 6, 7, 8,
    265   9,10,11,12,13,14,15,16,
    266   0, 0, 0, 0, 0, 0, 0, 0},
    267 
    268   {1, 2, 3, 4, 5, 6, 7, 8,
    269   0, 0, 0, 0, 0, 0, 0, 0,
    270   0, 0, 0, 0, 0, 0, 0, 0,
    271   9,10,11,12,13,14,15,16}};
    272 #endif
    273250
    274251  UInt uiInternalBitDepth = g_uiBitDepth+g_uiBitIncrement;
     
    276253  UInt uiBoRangeShift = uiInternalBitDepth - SAO_BO_BITS;
    277254
    278 #if SAO_UNIT_INTERLEAVING
    279255  m_lumaTableBo = new Pel [uiPixelRange];
    280256  for (Int k2=0; k2<uiPixelRange; k2++)
     
    282258    m_lumaTableBo[k2] = 1 + (k2>>uiBoRangeShift);
    283259  }
    284 #else
    285   m_ppLumaTableBo0 = new Pel [uiPixelRange];
    286   m_ppLumaTableBo1 = new Pel [uiPixelRange];
    287   for (Int k2=0; k2<uiPixelRange; k2++)
    288   {
    289     m_ppLumaTableBo0[k2] = auiTable[0][k2>>uiBoRangeShift];
    290     m_ppLumaTableBo1[k2] = auiTable[1][k2>>uiBoRangeShift];
    291   }
    292 #endif
    293260  m_iUpBuff1 = new Int[m_iPicWidth+2];
    294261  m_iUpBuff2 = new Int[m_iPicWidth+2];
     
    345312    delete [] m_iOffsetBo; m_iOffsetBo = NULL;
    346313  }
    347 #if SAO_UNIT_INTERLEAVING
    348314  if (m_lumaTableBo)
    349315  {
    350316    delete[] m_lumaTableBo; m_lumaTableBo = NULL;
    351317  }
    352 #else
    353   if (m_ppLumaTableBo0)
    354   {
    355     delete[] m_ppLumaTableBo0; m_ppLumaTableBo0 = NULL;
    356   }
    357   if (m_ppLumaTableBo1)
    358   {
    359     delete[] m_ppLumaTableBo1; m_ppLumaTableBo1 = NULL;
    360   }
    361 #endif
    362318
    363319
     
    416372    pcSaoParam->iNumClass[j] = m_iNumClass[j];
    417373  }
    418 #if SAO_UNIT_INTERLEAVING
    419374  pcSaoParam->numCuInWidth  = m_iNumCuInWidth;
    420375  pcSaoParam->numCuInHeight = m_iNumCuInHeight;
     
    422377  pcSaoParam->saoLcuParam[1] = new SaoLcuParam [m_iNumCuInHeight*m_iNumCuInWidth];
    423378  pcSaoParam->saoLcuParam[2] = new SaoLcuParam [m_iNumCuInHeight*m_iNumCuInWidth];
    424 #endif
    425379}
    426380
     
    448402
    449403  pSaoPart->UpPartIdx = iParentPartIdx;
    450 #if !SAO_UNIT_INTERLEAVING
    451   pSaoPart->bEnableFlag =  0;
    452 #endif
    453404  pSaoPart->iBestType   = -1;
    454405  pSaoPart->iLength     =  0;
    455406
    456 #if SAO_UNIT_INTERLEAVING
    457407  pSaoPart->bandPosition = 0;
    458408
    459409  for (j=0;j<MAX_NUM_SAO_OFFSETS;j++)
    460 #else
    461   for (j=0;j<MAX_NUM_SAO_CLASS;j++)
    462 #endif
    463410  {
    464411    pSaoPart->iOffset[j] = 0;
     
    545492  pcSaoParam->psSaoPart[1] = 0;
    546493  pcSaoParam->psSaoPart[2] = 0;
    547 #if SAO_UNIT_INTERLEAVING
    548494  if( pcSaoParam->saoLcuParam[0])
    549495  {
     
    558504    delete [] pcSaoParam->saoLcuParam[2]; pcSaoParam->saoLcuParam[2] = NULL;
    559505  }
    560 #endif
    561506}
    562507
     
    572517    for(Int i=0; i< m_aiNumCulPartsLevel[m_uiMaxSplitLevel]; i++)
    573518    {
    574 #if !SAO_UNIT_INTERLEAVING
    575       pcSaoParam->psSaoPart[c][i].bEnableFlag   =  0;
    576 #endif
    577519      pcSaoParam->psSaoPart[c][i].iBestType     = -1;
    578520      pcSaoParam->psSaoPart[c][i].iLength       =  0;
     
    582524      pcSaoParam->psSaoPart[c][i].iMinDist      = MAX_INT;
    583525      pcSaoParam->psSaoPart[c][i].iMinRate      = MAX_INT;
    584 #if SAO_UNIT_INTERLEAVING
    585526      pcSaoParam->psSaoPart[c][i].bandPosition = 0;
    586527      for (Int j=0;j<MAX_NUM_SAO_OFFSETS;j++)
    587 #else
    588       for (Int j=0;j<MAX_NUM_SAO_CLASS;j++)
    589 #endif
    590528      {
    591529        pcSaoParam->psSaoPart[c][i].iOffset[j] = 0;
     
    594532      }
    595533    }
    596 #if SAO_UNIT_INTERLEAVING
    597534    pcSaoParam->oneUnitFlag[0]   = 0;
    598535    pcSaoParam->oneUnitFlag[1]   = 0;
     
    601538    resetLcuPart(pcSaoParam->saoLcuParam[1]);
    602539    resetLcuPart(pcSaoParam->saoLcuParam[2]);
    603 #endif
    604540  }
    605541}
     
    882818      break;
    883819    }   
    884 #if SAO_UNIT_INTERLEAVING
    885820  case SAO_BO:
    886 #else
    887   case SAO_BO_0:
    888   case SAO_BO_1:
    889 #endif
    890821    {
    891822      for (y=0; y< height; y++)
     
    11081039      break;
    11091040    }   
    1110 #if SAO_UNIT_INTERLEAVING
    11111041  case SAO_BO:
    1112 #else
    1113   case SAO_BO_0:
    1114   case SAO_BO_1:
    1115 #endif
    11161042    {
    11171043      for (y=0; y<iLcuHeight; y++)
     
    11341060  }
    11351061}
    1136 #if !SAO_UNIT_INTERLEAVING
    1137 /** sample adaptive offset process for one partition
    1138  * \param   *psQTPart,  uiPartIdx,  iYCbCr
    1139  */
    1140 Void TComSampleAdaptiveOffset::processSaoOnePart(SAOQTPart *psQTPart, UInt uiPartIdx, Int iYCbCr)
    1141 {
    1142   int  i;
    1143   UInt uiEdgeType, uiTypeIdx;
    1144   Pel* ppLumaTable = NULL;
    1145   SAOQTPart*  pOnePart= &(psQTPart[uiPartIdx]);
    1146 
    1147   static Int iOffset[LUMA_GROUP_NUM];
    1148   Int LcuIdxX;
    1149   Int LcuIdxY;
    1150   Int iAddr;
    1151   Int iFrameWidthInCU = m_pcPic->getFrameWidthInCU();
    1152 
    1153   if(pOnePart->bEnableFlag)
    1154   {
    1155     uiTypeIdx = pOnePart->iBestType;
    1156     if (uiTypeIdx == SAO_BO_0 || uiTypeIdx == SAO_BO_1)
    1157     {
    1158       for (i=0;i<pOnePart->iLength;i++)
    1159         iOffset[i+1] = pOnePart->iOffset[i] << m_uiSaoBitIncrease;
    1160 
    1161       if (uiTypeIdx == SAO_BO_0 )
    1162       {
    1163         ppLumaTable = m_ppLumaTableBo0;
    1164       }
    1165       if (uiTypeIdx == SAO_BO_1 )
    1166       {
    1167         ppLumaTable = m_ppLumaTableBo1;
    1168       }
    1169 
    1170 #if FULL_NBIT
    1171       for (i=0;i<(1<<(g_uiBitDepth));i++)
    1172 #else
    1173       for (i=0;i<(1<<(g_uiBitIncrement+8));i++)
    1174 #endif
    1175       {
    1176         m_iOffsetBo[i] = m_pClipTable[i + iOffset[ppLumaTable[i]]];
    1177       }
    1178 
    1179     }
    1180     if (uiTypeIdx == SAO_EO_0 || uiTypeIdx == SAO_EO_1 || uiTypeIdx == SAO_EO_2 || uiTypeIdx == SAO_EO_3)
    1181     {
    1182       for (i=0;i<pOnePart->iLength;i++)
    1183       {
    1184         iOffset[i+1] = pOnePart->iOffset[i] << m_uiSaoBitIncrease;
    1185       }
    1186       for (uiEdgeType=0;uiEdgeType<6;uiEdgeType++)
    1187       {
    1188         m_iOffsetEo[uiEdgeType]= iOffset[m_auiEoTable[uiEdgeType]];
    1189       }
    1190     }
    1191     for (LcuIdxY = pOnePart->StartCUY; LcuIdxY<= pOnePart->EndCUY; LcuIdxY++)
    1192     {
    1193       for (LcuIdxX = pOnePart->StartCUX; LcuIdxX<= pOnePart->EndCUX; LcuIdxX++)
    1194       {
    1195         iAddr = LcuIdxY * iFrameWidthInCU + LcuIdxX;
    1196         processSaoCu(iAddr, uiTypeIdx, iYCbCr);
    1197       }
    1198     }
    1199   }
    1200 }
    1201 
    1202 /** Process quadtree sample adaptive offset
    1203  * \param  psQTPart, uiPartIdx, iYCbCr
    1204  */
    1205 Void TComSampleAdaptiveOffset::processSaoQuadTree(SAOQTPart *psQTPart, UInt uiPartIdx, Int iYCbCr)
    1206 {
    1207   SAOQTPart*  pSaoPart= &(psQTPart[uiPartIdx]);
    1208 
    1209   if (uiPartIdx == 0)
    1210   {
    1211     initTmpSaoQuadTree(psQTPart, iYCbCr);
    1212     xSaoAllPart(psQTPart, iYCbCr);
    1213     return;
    1214   }
    1215 
    1216   if (!pSaoPart->bSplit)
    1217   {
    1218     if (pSaoPart->bEnableFlag)
    1219     {
    1220       processSaoOnePart(psQTPart, uiPartIdx, iYCbCr);
    1221     }
    1222     return;
    1223   }
    1224 
    1225   if (pSaoPart->PartLevel < m_uiMaxSplitLevel)
    1226   {
    1227     processSaoQuadTree(psQTPart, pSaoPart->DownPartsIdx[0], iYCbCr);
    1228     processSaoQuadTree(psQTPart, pSaoPart->DownPartsIdx[1], iYCbCr);
    1229     processSaoQuadTree(psQTPart, pSaoPart->DownPartsIdx[2], iYCbCr);
    1230     processSaoQuadTree(psQTPart, pSaoPart->DownPartsIdx[3], iYCbCr);
    1231   }
    1232 }
    1233 
    1234 /** run SAO processing in LCU order
    1235  * \param *psQTPart,  iYCbCr
    1236  */
    1237 Void TComSampleAdaptiveOffset::xSaoAllPart(SAOQTPart *psQTPart, Int iYCbCr)
    1238 {
    1239   int  i;
    1240   UInt uiEdgeType;
    1241   Pel* ppLumaTable = NULL;
    1242   Int  iTypeIdx;
    1243 
    1244   static Int iOffset[LUMA_GROUP_NUM];
    1245   Int LcuIdxX;
    1246   Int LcuIdxY;
    1247   Int iAddr;
    1248   Int iFrameWidthInCU = m_pcPic->getFrameWidthInCU();
    1249   Int iFrameHeightInCU = m_pcPic->getFrameHeightInCU();
    1250   Int iPartIdx;
    1251   Pel *pRec;
    1252   Int iPicWidthTmp;
    1253   Int iStride;
    1254   Pel *pTmpUSwap;
    1255   Int iIsChroma = (iYCbCr == 0) ? 0:1;
    1256 
    1257   SAOQTPart*  pOnePart;
    1258 
    1259   for (LcuIdxY = 0; LcuIdxY< iFrameHeightInCU; LcuIdxY++)
    1260   {
    1261     iAddr = LcuIdxY * iFrameWidthInCU;
    1262     if (iYCbCr == 0)
    1263     {
    1264       pRec  = m_pcPic->getPicYuvRec()->getLumaAddr(iAddr);
    1265       iStride = m_pcPic->getStride();
    1266       iPicWidthTmp = m_iPicWidth;
    1267     }
    1268     else if (iYCbCr == 1)
    1269     {
    1270       pRec  = m_pcPic->getPicYuvRec()->getCbAddr(iAddr);
    1271       iStride = m_pcPic->getCStride();
    1272       iPicWidthTmp = m_iPicWidth>>1;
    1273     }
    1274     else
    1275     {
    1276       pRec  = m_pcPic->getPicYuvRec()->getCrAddr(iAddr);
    1277       iStride = m_pcPic->getCStride();
    1278       iPicWidthTmp = m_iPicWidth>>1;
    1279     }
    1280 
    1281 //     pRec += iStride*(m_uiMaxCUHeight-1);
    1282     for (i=0;i<(m_uiMaxCUHeight>>iIsChroma)+1;i++)
    1283     {
    1284       m_pTmpL1[i] = pRec[0];
    1285       pRec+=iStride;
    1286     }
    1287     pRec-=(iStride<<1);
    1288 
    1289     memcpy(m_pTmpU2, pRec, sizeof(Pel)*iPicWidthTmp);
    1290 
    1291     for (LcuIdxX = 0; LcuIdxX< iFrameWidthInCU; LcuIdxX++)
    1292     {
    1293       iAddr = LcuIdxY * iFrameWidthInCU + LcuIdxX;
    1294       iPartIdx = m_iLcuPartIdx[iAddr];
    1295       if (iPartIdx>=0)
    1296       {
    1297         pOnePart = &(psQTPart[iPartIdx]);
    1298         iTypeIdx = pOnePart->iBestType;
    1299         if (iTypeIdx>=0)
    1300         {
    1301           if (iTypeIdx == SAO_BO_0 || iTypeIdx == SAO_BO_1)
    1302           {
    1303             for (i=0;i<pOnePart->iLength;i++)
    1304               iOffset[i+1] = pOnePart->iOffset[i] << m_uiSaoBitIncrease;
    1305 
    1306             if (iTypeIdx == SAO_BO_0 )
    1307             {
    1308               ppLumaTable = m_ppLumaTableBo0;
    1309             }
    1310             if (iTypeIdx == SAO_BO_1 )
    1311             {
    1312               ppLumaTable = m_ppLumaTableBo1;
    1313             }
    1314 
    1315 #if FULL_NBIT
    1316             for (i=0;i<(1<<(g_uiBitDepth));i++)
    1317 #else
    1318             for (i=0;i<(1<<(g_uiBitIncrement+8));i++)
    1319 #endif
    1320             {
    1321               m_iOffsetBo[i] = m_pClipTable[i + iOffset[ppLumaTable[i]]];
    1322             }
    1323 
    1324           }
    1325           if (iTypeIdx == SAO_EO_0 || iTypeIdx == SAO_EO_1 || iTypeIdx == SAO_EO_2 || iTypeIdx == SAO_EO_3)
    1326           {
    1327             for (i=0;i<pOnePart->iLength;i++)
    1328             {
    1329               iOffset[i+1] = pOnePart->iOffset[i] << m_uiSaoBitIncrease;
    1330             }
    1331             for (uiEdgeType=0;uiEdgeType<6;uiEdgeType++)
    1332             {
    1333               m_iOffsetEo[uiEdgeType]= iOffset[m_auiEoTable[uiEdgeType]];
    1334             }
    1335           }
    1336           processSaoCu(iAddr, iTypeIdx, iYCbCr);
    1337         }
    1338       }
    1339       else
    1340       {
    1341         if (LcuIdxX != (iFrameWidthInCU-1))
    1342         {
    1343           if( m_iLcuPartIdx[iAddr+1] >=0)
    1344           {
    1345             if (iYCbCr == 0)
    1346             {
    1347               pRec  = m_pcPic->getPicYuvRec()->getLumaAddr(iAddr);
    1348               iStride = m_pcPic->getStride();
    1349             }
    1350             else if (iYCbCr == 1)
    1351             {
    1352               pRec  = m_pcPic->getPicYuvRec()->getCbAddr(iAddr);
    1353               iStride = m_pcPic->getCStride();
    1354             }
    1355             else
    1356             {
    1357               pRec  = m_pcPic->getPicYuvRec()->getCrAddr(iAddr);
    1358               iStride = m_pcPic->getCStride();
    1359             }
    1360             Int iWidthShift = m_uiMaxCUWidth>>iIsChroma;
    1361             for (i=0;i<(m_uiMaxCUHeight>>iIsChroma)+1;i++)
    1362             {
    1363               m_pTmpL1[i] = pRec[iWidthShift-1];
    1364               pRec+=iStride;
    1365             }
    1366           }
    1367         }
    1368       }
    1369     }
    1370     pTmpUSwap = m_pTmpU1;
    1371     m_pTmpU1  = m_pTmpU2;
    1372     m_pTmpU2  = pTmpUSwap;
    1373   }
    1374 }
    1375 
    1376 /** initialize buffer for quadtree boundary
    1377  * \param *psQTPart,  iYCbCr
    1378  */
    1379 Void TComSampleAdaptiveOffset::initTmpSaoQuadTree(SAOQTPart *psQTPart, Int iYCbCr)
    1380 {
    1381   Pel *pRec;
    1382   Int iPicWidthTmp;
    1383  
    1384 
    1385   memset(m_iLcuPartIdx,-1, sizeof(Int)*m_iNumCuInWidth*m_iNumCuInHeight);
    1386   convertSaoQt2Lcu(psQTPart, 0);
    1387 
    1388   if (iYCbCr == 0)
    1389   {
    1390     pRec       = m_pcPic->getPicYuvRec()->getLumaAddr();
    1391     iPicWidthTmp = m_iPicWidth;
    1392   }
    1393   else if (iYCbCr == 1)
    1394   {
    1395     pRec       = m_pcPic->getPicYuvRec()->getCbAddr();
    1396     iPicWidthTmp =  m_iPicWidth>>1;
    1397   }
    1398   else
    1399   {
    1400     pRec       = m_pcPic->getPicYuvRec()->getCrAddr();
    1401     iPicWidthTmp =  m_iPicWidth>>1;
    1402   }
    1403 
    1404   memcpy(m_pTmpU1, pRec, sizeof(Pel)*iPicWidthTmp);
    1405 }
    1406 
    1407 /** recursive covert quadtree partition index to each LCU
    1408  * \param psQTPart, uiPartIdx 
    1409  */
    1410 Void TComSampleAdaptiveOffset::convertSaoQt2Lcu(SAOQTPart *psQTPart,UInt uiPartIdx)
    1411 {
    1412 
    1413   SAOQTPart*  pSaoPart= &(psQTPart[uiPartIdx]);
    1414 
    1415   if (!pSaoPart->bSplit)
    1416   {
    1417     xSaoQt2Lcu(psQTPart, uiPartIdx);
    1418     return;
    1419   }
    1420 
    1421   if (pSaoPart->PartLevel < m_uiMaxSplitLevel)
    1422   {
    1423     convertSaoQt2Lcu(psQTPart, pSaoPart->DownPartsIdx[0]);
    1424     convertSaoQt2Lcu(psQTPart, pSaoPart->DownPartsIdx[1]);
    1425     convertSaoQt2Lcu(psQTPart, pSaoPart->DownPartsIdx[2]);
    1426     convertSaoQt2Lcu(psQTPart, pSaoPart->DownPartsIdx[3]);
    1427   }
    1428 }
    1429 
    1430 /** assign quadtree partition index to each LCU
    1431  * \param psQTPart, uiPartIdx 
    1432  */
    1433 
    1434 Void TComSampleAdaptiveOffset::xSaoQt2Lcu(SAOQTPart *psQTPart,UInt uiPartIdx)
    1435 {
    1436   Int LcuIdxX;
    1437   Int LcuIdxY;
    1438   Int iAddr;
    1439   Int iFrameWidthInCU = m_iNumCuInWidth;
    1440 
    1441   for (LcuIdxY = psQTPart[uiPartIdx].StartCUY; LcuIdxY<= psQTPart[uiPartIdx].EndCUY; LcuIdxY++)
    1442   {
    1443     for (LcuIdxX = psQTPart[uiPartIdx].StartCUX; LcuIdxX<= psQTPart[uiPartIdx].EndCUX; LcuIdxX++)
    1444     {
    1445       iAddr = LcuIdxY * iFrameWidthInCU + LcuIdxX;
    1446       if (psQTPart[uiPartIdx].bEnableFlag)
    1447       {
    1448         m_iLcuPartIdx[iAddr] = (Int)uiPartIdx;
    1449       }
    1450       else
    1451       {
    1452         m_iLcuPartIdx[iAddr] = -1;
    1453       }
    1454     }
    1455   }
    1456 }
    1457 #endif
    14581062/** Sample adaptive offset process
    14591063 * \param pcPic, pcSaoParam 
     
    14741078    }
    14751079
    1476 #if SAO_UNIT_INTERLEAVING
    14771080    if (m_saoInterleavingFlag)
    14781081    {
     
    14961099
    14971100
    1498 #else
    1499     Int iY  = 0;
    1500     processSaoQuadTree( pcSaoParam->psSaoPart[iY], 0 , iY);
    1501 
    1502     Int iCb = 1;
    1503     Int iCr = 2;
    1504     if (pcSaoParam->bSaoFlag[iCb])
    1505     {
    1506       processSaoQuadTree( pcSaoParam->psSaoPart[iCb], 0 , iCb);
    1507     }
    1508     if (pcSaoParam->bSaoFlag[iCr])
    1509     {
    1510       processSaoQuadTree( pcSaoParam->psSaoPart[iCr], 0 , iCr);
    1511     }
    1512 #endif
    15131101    m_pcPic = NULL;
    15141102  }
     
    15331121  }
    15341122}
    1535 #if SAO_UNIT_INTERLEAVING
    15361123/** Process SAO all units
    15371124 * \param saoLcuParam SAO LCU parameters
     
    17891376
    17901377
    1791 #endif
    17921378
    17931379//! \}
Note: See TracChangeset for help on using the changeset viewer.