[x265] [PATCH] SAO: initialize bottom and right line numbers to be skipped for SAO statistics calculation only once
ashok at multicorewareinc.com
ashok at multicorewareinc.com
Thu Nov 19 12:44:58 CET 2015
# HG changeset patch
# User Ashok Kumar Mishra<ashok at multicorewareinc.com>
# Date 1446119115 -19800
# Thu Oct 29 17:15:15 2015 +0530
# Node ID c1575815b250fb02c1fdae803aead10a4997c835
# Parent f722fb55404bb80b26a55ba0a0a1b98d8f20b362
SAO: initialize bottom and right line numbers to be skipped for SAO statistics calculation only once
diff -r f722fb55404b -r c1575815b250 source/encoder/frameencoder.cpp
--- a/source/encoder/frameencoder.cpp Wed Nov 18 12:28:03 2015 +0530
+++ b/source/encoder/frameencoder.cpp Thu Oct 29 17:15:15 2015 +0530
@@ -1091,7 +1091,7 @@
/* SAO parameter estimation using non-deblocked pixels for CTU bottom and right boundary areas */
if (m_param->bEnableSAO && m_param->bSaoNonDeblocked)
- m_frameFilter.m_sao.calcSaoStatsCu_BeforeDblk(m_frame, col, row);
+ m_frameFilter.m_sao.calcPreDeblockSaoStatsCu(m_frame, col, row);
if (m_param->bEnableWavefront && curRow.completed >= 2 && row < m_numRows - 1 &&
(!m_bAllRowsStop || intRow + 1 < m_vbvResetTriggerRow))
diff -r f722fb55404b -r c1575815b250 source/encoder/sao.cpp
--- a/source/encoder/sao.cpp Wed Nov 18 12:28:03 2015 +0530
+++ b/source/encoder/sao.cpp Thu Oct 29 17:15:15 2015 +0530
@@ -138,6 +138,59 @@
CHECKED_MALLOC(m_countPreDblk, PerPlane, numCtu);
CHECKED_MALLOC(m_offsetOrgPreDblk, PerPlane, numCtu);
+ if (!m_param->bSaoNonDeblocked)
+ {
+ for (int typeIdc = 0; typeIdc < MAX_NUM_SAO_TYPE; typeIdc++)
+ {
+ m_skipLinesR[TEXT_LUMA][typeIdc] = 5;
+ m_skipLinesR[TEXT_CHROMA_U][typeIdc] = m_skipLinesR[TEXT_CHROMA_V][typeIdc] = 3;
+
+ m_skipLinesB[TEXT_LUMA ][typeIdc] = 4;
+ m_skipLinesB[TEXT_CHROMA_U][typeIdc] = m_skipLinesB[TEXT_CHROMA_V][typeIdc] = 2;
+ }
+ }
+ else
+ {
+ for (int typeIdc = 0; typeIdc < MAX_NUM_SAO_TYPE; typeIdc++)
+ {
+ switch (typeIdc)
+ {
+ case SAO_EO_0:
+ m_skipLinesR[TEXT_LUMA][typeIdc] = 5;
+ m_skipLinesR[TEXT_CHROMA_U][typeIdc] = m_skipLinesR[TEXT_CHROMA_V][typeIdc] = 3;
+
+ m_skipLinesB[TEXT_LUMA][typeIdc] = 3;
+ m_skipLinesB[TEXT_CHROMA_U][typeIdc] = m_skipLinesB[TEXT_CHROMA_V][typeIdc] = 1;
+ break;
+ case SAO_EO_1:
+ m_skipLinesR[TEXT_LUMA][typeIdc] = 4;
+ m_skipLinesR[TEXT_CHROMA_U][typeIdc] = m_skipLinesR[TEXT_CHROMA_V][typeIdc] = 2;
+
+ m_skipLinesB[TEXT_LUMA][typeIdc] = 4;
+ m_skipLinesB[TEXT_CHROMA_U][typeIdc] = m_skipLinesB[TEXT_CHROMA_V][typeIdc] = 2;
+ break;
+ case SAO_EO_2:
+ case SAO_EO_3:
+ m_skipLinesR[TEXT_LUMA][typeIdc] = 5;
+ m_skipLinesR[TEXT_CHROMA_U][typeIdc] = m_skipLinesR[TEXT_CHROMA_V][typeIdc] = 3;
+
+ m_skipLinesB[TEXT_LUMA][typeIdc] = 4;
+ m_skipLinesB[TEXT_CHROMA_U][typeIdc] = m_skipLinesB[TEXT_CHROMA_V][typeIdc] = 2;
+ break;
+ case SAO_BO:
+ m_skipLinesR[TEXT_LUMA][typeIdc] = 4;
+ m_skipLinesR[TEXT_CHROMA_U][typeIdc] = m_skipLinesR[TEXT_CHROMA_V][typeIdc] = 2;
+
+ m_skipLinesB[TEXT_LUMA][typeIdc] = 3;
+ m_skipLinesB[TEXT_CHROMA_U][typeIdc] = m_skipLinesB[TEXT_CHROMA_V][typeIdc] = 1;
+ break;
+ default:
+ X265_CHECK(0, "Not a supported type");
+ break;
+ }
+ }
+ }
+
m_clipTable = &(m_clipTableBase[rangeExt]);
for (int i = 0; i < rangeExt; i++)
@@ -701,14 +754,9 @@
ctuWidth = rpelx - lpelx;
ctuHeight = bpely - tpely;
- int startX;
- int startY;
- int endX;
- int endY;
-
- const int plane_offset = plane ? 2 : 0;
- int skipB = 4;
- int skipR = 5;
+ int startX, startY, endX, endY;
+ int* skipLinesR = m_skipLinesR[plane];
+ int* skipLinesB = m_skipLinesB[plane];
int8_t _upBuff[2 * (MAX_CU_SIZE + 16 + 16)], *upBuff1 = _upBuff + 16, *upBufft = upBuff1 + (MAX_CU_SIZE + 16 + 16);
@@ -738,14 +786,8 @@
// SAO_BO:
{
- if (m_param->bSaoNonDeblocked)
- {
- skipB = 3;
- skipR = 4;
- }
-
- endX = (rpelx == picWidth) ? ctuWidth : ctuWidth - skipR + plane_offset;
- endY = (bpely == picHeight) ? ctuHeight : ctuHeight - skipB + plane_offset;
+ endX = (rpelx == picWidth) ? ctuWidth : ctuWidth - skipLinesR[SAO_BO];
+ endY = (bpely == picHeight) ? ctuHeight : ctuHeight - skipLinesB[SAO_BO];
primitives.saoCuStatsBO(diff, rec0, stride, endX, endY, m_offsetOrg[plane][SAO_BO], m_count[plane][SAO_BO]);
}
@@ -753,31 +795,19 @@
{
// SAO_EO_0: // dir: -
{
- if (m_param->bSaoNonDeblocked)
- {
- skipB = 3;
- skipR = 5;
- }
+ startX = !lpelx;
+ endX = (rpelx == picWidth) ? ctuWidth - 1 : ctuWidth - skipLinesR[SAO_EO_0];
- startX = !lpelx;
- endX = (rpelx == picWidth) ? ctuWidth - 1 : ctuWidth - skipR + plane_offset;
-
- primitives.saoCuStatsE0(diff + startX, rec0 + startX, stride, endX - startX, ctuHeight - skipB + plane_offset, m_offsetOrg[plane][SAO_EO_0], m_count[plane][SAO_EO_0]);
+ primitives.saoCuStatsE0(diff + startX, rec0 + startX, stride, endX - startX, ctuHeight - skipLinesB[SAO_EO_0], m_offsetOrg[plane][SAO_EO_0], m_count[plane][SAO_EO_0]);
}
// SAO_EO_1: // dir: |
{
- if (m_param->bSaoNonDeblocked)
- {
- skipB = 4;
- skipR = 4;
- }
-
rec = rec0;
startY = !tpely;
- endX = (rpelx == picWidth) ? ctuWidth : ctuWidth - skipR + plane_offset;
- endY = (bpely == picHeight) ? ctuHeight - 1 : ctuHeight - skipB + plane_offset;
+ endX = (rpelx == picWidth) ? ctuWidth : ctuWidth - skipLinesR[SAO_EO_1];
+ endY = (bpely == picHeight) ? ctuHeight - 1 : ctuHeight - skipLinesB[SAO_EO_1];
if (!tpely)
{
rec += stride;
@@ -790,20 +820,14 @@
// SAO_EO_2: // dir: 135
{
- if (m_param->bSaoNonDeblocked)
- {
- skipB = 4;
- skipR = 5;
- }
-
fenc = fenc0;
rec = rec0;
startX = !lpelx;
- endX = (rpelx == picWidth) ? ctuWidth - 1 : ctuWidth - skipR + plane_offset;
+ endX = (rpelx == picWidth) ? ctuWidth - 1 : ctuWidth - skipLinesR[SAO_EO_2];
startY = !tpely;
- endY = (bpely == picHeight) ? ctuHeight - 1 : ctuHeight - skipB + plane_offset;
+ endY = (bpely == picHeight) ? ctuHeight - 1 : ctuHeight - skipLinesB[SAO_EO_2];
if (!tpely)
{
fenc += stride;
@@ -817,20 +841,14 @@
// SAO_EO_3: // dir: 45
{
- if (m_param->bSaoNonDeblocked)
- {
- skipB = 4;
- skipR = 5;
- }
-
fenc = fenc0;
rec = rec0;
startX = !lpelx;
- endX = (rpelx == picWidth) ? ctuWidth - 1 : ctuWidth - skipR + plane_offset;
+ endX = (rpelx == picWidth) ? ctuWidth - 1 : ctuWidth - skipLinesR[SAO_EO_3];
startY = !tpely;
- endY = (bpely == picHeight) ? ctuHeight - 1 : ctuHeight - skipB + plane_offset;
+ endY = (bpely == picHeight) ? ctuHeight - 1 : ctuHeight - skipLinesB[SAO_EO_3];
if (!tpely)
{
@@ -845,11 +863,9 @@
}
}
-void SAO::calcSaoStatsCu_BeforeDblk(Frame* frame, int idxX, int idxY)
+void SAO::calcPreDeblockSaoStatsCu(Frame* frame, int idxX, int idxY)
{
int addr = idxX + m_numCuInWidth * idxY;
-
- int x, y;
const CUData* cu = frame->m_encData->getPicCTU(addr);
const PicYuv* reconPic = m_frame->m_reconPic;
const pixel* fenc;
@@ -866,16 +882,10 @@
ctuWidth = rpelx - lpelx;
ctuHeight = bpely - tpely;
- int startX;
- int startY;
- int endX;
- int endY;
- int firstX, firstY;
+ int startX, startY, endX, endY, firstX, firstY;
int32_t* stats;
int32_t* count;
- int skipB, skipR;
-
int32_t _upBuff1[MAX_CU_SIZE + 2], *upBuff1 = _upBuff1 + 1;
int32_t _upBufft[MAX_CU_SIZE + 2], *upBufft = _upBufft + 1;
@@ -884,7 +894,6 @@
memset(m_countPreDblk[addr], 0, sizeof(PerPlane));
memset(m_offsetOrgPreDblk[addr], 0, sizeof(PerPlane));
- int plane_offset = 0;
for (int plane = 0; plane < NUM_PLANE; plane++)
{
if (plane == 1)
@@ -900,11 +909,10 @@
bpely >>= m_vChromaShift;
}
+ int* skipLinesR = m_skipLinesR[plane];
+ int* skipLinesB = m_skipLinesB[plane];
+
// SAO_BO:
-
- skipB = 3 - plane_offset;
- skipR = 4 - plane_offset;
-
stats = m_offsetOrgPreDblk[addr][plane][SAO_BO];
count = m_countPreDblk[addr][plane][SAO_BO];
@@ -913,12 +921,12 @@
fenc = fenc0;
rec = rec0;
- startX = (rpelx == picWidth) ? ctuWidth : ctuWidth - skipR;
- startY = (bpely == picHeight) ? ctuHeight : ctuHeight - skipB;
+ startX = (rpelx == picWidth) ? ctuWidth : ctuWidth - skipLinesR[SAO_BO];
+ startY = (bpely == picHeight) ? ctuHeight : ctuHeight - skipLinesB[SAO_BO];
- for (y = 0; y < ctuHeight; y++)
+ for (int y = 0; y < ctuHeight; y++)
{
- for (x = (y < startY ? startX : 0); x < ctuWidth; x++)
+ for (int x = (y < startY ? startX : 0); x < ctuWidth; x++)
{
int classIdx = 1 + (rec[x] >> boShift);
stats[classIdx] += (fenc[x] - rec[x]);
@@ -931,24 +939,21 @@
// SAO_EO_0: // dir: -
{
- skipB = 3 - plane_offset;
- skipR = 5 - plane_offset;
-
stats = m_offsetOrgPreDblk[addr][plane][SAO_EO_0];
count = m_countPreDblk[addr][plane][SAO_EO_0];
fenc = fenc0;
rec = rec0;
- startX = (rpelx == picWidth) ? ctuWidth - 1 : ctuWidth - skipR;
- startY = (bpely == picHeight) ? ctuHeight : ctuHeight - skipB;
+ startX = (rpelx == picWidth) ? ctuWidth - 1 : ctuWidth - skipLinesR[SAO_EO_0];
+ startY = (bpely == picHeight) ? ctuHeight : ctuHeight - skipLinesB[SAO_EO_0];
firstX = !lpelx;
// endX = (rpelx == picWidth) ? ctuWidth - 1 : ctuWidth;
endX = ctuWidth - 1; // not refer right CTU
- for (y = 0; y < ctuHeight; y++)
+ for (int y = 0; y < ctuHeight; y++)
{
- x = (y < startY ? startX : firstX);
+ int x = (y < startY ? startX : firstX);
int signLeft = signOf(rec[x] - rec[x - 1]);
for (; x < endX; x++)
{
@@ -967,17 +972,14 @@
// SAO_EO_1: // dir: |
{
- skipB = 4 - plane_offset;
- skipR = 4 - plane_offset;
-
stats = m_offsetOrgPreDblk[addr][plane][SAO_EO_1];
count = m_countPreDblk[addr][plane][SAO_EO_1];
fenc = fenc0;
rec = rec0;
- startX = (rpelx == picWidth) ? ctuWidth : ctuWidth - skipR;
- startY = (bpely == picHeight) ? ctuHeight - 1 : ctuHeight - skipB;
+ startX = (rpelx == picWidth) ? ctuWidth : ctuWidth - skipLinesR[SAO_EO_1];
+ startY = (bpely == picHeight) ? ctuHeight - 1 : ctuHeight - skipLinesB[SAO_EO_1];
firstY = !tpely;
// endY = (bpely == picHeight) ? ctuHeight - 1 : ctuHeight;
endY = ctuHeight - 1; // not refer below CTU
@@ -987,12 +989,12 @@
rec += stride;
}
- for (x = startX; x < ctuWidth; x++)
+ for (int x = startX; x < ctuWidth; x++)
upBuff1[x] = signOf(rec[x] - rec[x - stride]);
- for (y = firstY; y < endY; y++)
+ for (int y = firstY; y < endY; y++)
{
- for (x = (y < startY - 1 ? startX : 0); x < ctuWidth; x++)
+ for (int x = (y < startY - 1 ? startX : 0); x < ctuWidth; x++)
{
int signDown = signOf(rec[x] - rec[x + stride]);
int edgeType = signDown + upBuff1[x] + 2;
@@ -1012,17 +1014,14 @@
// SAO_EO_2: // dir: 135
{
- skipB = 4 - plane_offset;
- skipR = 5 - plane_offset;
-
stats = m_offsetOrgPreDblk[addr][plane][SAO_EO_2];
count = m_countPreDblk[addr][plane][SAO_EO_2];
fenc = fenc0;
rec = rec0;
- startX = (rpelx == picWidth) ? ctuWidth - 1 : ctuWidth - skipR;
- startY = (bpely == picHeight) ? ctuHeight - 1 : ctuHeight - skipB;
+ startX = (rpelx == picWidth) ? ctuWidth - 1 : ctuWidth - skipLinesR[SAO_EO_2];
+ startY = (bpely == picHeight) ? ctuHeight - 1 : ctuHeight - skipLinesB[SAO_EO_2];
firstX = !lpelx;
firstY = !tpely;
// endX = (rpelx == picWidth) ? ctuWidth - 1 : ctuWidth;
@@ -1035,12 +1034,12 @@
rec += stride;
}
- for (x = startX; x < endX; x++)
+ for (int x = startX; x < endX; x++)
upBuff1[x] = signOf(rec[x] - rec[x - stride - 1]);
- for (y = firstY; y < endY; y++)
+ for (int y = firstY; y < endY; y++)
{
- x = (y < startY - 1 ? startX : firstX);
+ int x = (y < startY - 1 ? startX : firstX);
upBufft[x] = signOf(rec[x + stride] - rec[x - 1]);
for (; x < endX; x++)
{
@@ -1064,17 +1063,14 @@
// SAO_EO_3: // dir: 45
{
- skipB = 4 - plane_offset;
- skipR = 5 - plane_offset;
-
stats = m_offsetOrgPreDblk[addr][plane][SAO_EO_3];
count = m_countPreDblk[addr][plane][SAO_EO_3];
fenc = fenc0;
rec = rec0;
- startX = (rpelx == picWidth) ? ctuWidth - 1 : ctuWidth - skipR;
- startY = (bpely == picHeight) ? ctuHeight - 1 : ctuHeight - skipB;
+ startX = (rpelx == picWidth) ? ctuWidth - 1 : ctuWidth - skipLinesR[SAO_EO_3];
+ startY = (bpely == picHeight) ? ctuHeight - 1 : ctuHeight - skipLinesB[SAO_EO_3];
firstX = !lpelx;
firstY = !tpely;
// endX = (rpelx == picWidth) ? ctuWidth - 1 : ctuWidth;
@@ -1087,12 +1083,12 @@
rec += stride;
}
- for (x = startX - 1; x < endX; x++)
+ for (int x = startX - 1; x < endX; x++)
upBuff1[x] = signOf(rec[x] - rec[x - stride + 1]);
- for (y = firstY; y < endY; y++)
+ for (int y = firstY; y < endY; y++)
{
- for (x = (y < startY - 1 ? startX : firstX); x < endX; x++)
+ for (int x = (y < startY - 1 ? startX : firstX); x < endX; x++)
{
int signDown = signOf(rec[x] - rec[x + stride - 1]);
int edgeType = signDown + upBuff1[x] + 2;
@@ -1111,7 +1107,6 @@
fenc += stride;
}
}
- plane_offset = 2;
}
}
diff -r f722fb55404b -r c1575815b250 source/encoder/sao.h
--- a/source/encoder/sao.h Wed Nov 18 12:28:03 2015 +0530
+++ b/source/encoder/sao.h Thu Oct 29 17:15:15 2015 +0530
@@ -97,6 +97,9 @@
pixel* m_tmpL1;
pixel* m_tmpL2;
+ int m_skipLinesR[MAX_NUM_COMPONENT][MAX_NUM_SAO_TYPE];
+ int m_skipLinesB[MAX_NUM_COMPONENT][MAX_NUM_SAO_TYPE];
+
public:
struct SAOContexts
@@ -136,7 +139,7 @@
void copySaoUnit(SaoCtuParam* saoUnitDst, const SaoCtuParam* saoUnitSrc);
void calcSaoStatsCu(int addr, int plane);
- void calcSaoStatsCu_BeforeDblk(Frame* pic, int idxX, int idxY);
+ void calcPreDeblockSaoStatsCu(Frame* pic, int idxX, int idxY);
void saoComponentParamDist(SAOParam* saoParam, int addr, int addrUp, int addrLeft, SaoCtuParam mergeSaoParam[2], double* mergeDist);
void sao2ChromaParamDist(SAOParam* saoParam, int addr, int addrUp, int addrLeft, SaoCtuParam mergeSaoParam[][2], double* mergeDist);
More information about the x265-devel
mailing list