changeset 4275:0204da76bdb6

slicetype: Bidir cost estimation added to lookahead
author Deepthi Devaki <deepthidevaki@multicorewareinc.com>
date Tue, 08 Oct 2013 12:47:30 +0530
parents 9b3a427a1009
children 279e050947cf
files source/encoder/slicetype.cpp
diffstat 1 files changed, 60 insertions(+-), 0 deletions(-) [+]
line wrap: on
line diff
--- a/source/encoder/slicetype.cpp	Tue Oct 08 11:12:12 2013 +0530
+++ b/source/encoder/slicetype.cpp	Tue Oct 08 12:47:30 2013 +0530
@@ -407,6 +407,66 @@ void Lookahead::estimateCUCost(int cux, 
             *fenc_costs[i] = me.motionEstimate(i ? fref1 : fref0, mvmin, mvmax, mvp, numc, mvc, merange, *fenc_mvs[i]);
             COPY2_IF_LT(bcost, *fenc_costs[i], listused, i + 1);
         }
+        if (bBidir)
+        {
+            pixel subpelbuf1[X265_LOWRES_CU_SIZE * X265_LOWRES_CU_SIZE], subpelbuf2[X265_LOWRES_CU_SIZE * X265_LOWRES_CU_SIZE];
+            pixel *src0, *src1;
+            intptr_t stride0, stride1;
+            if (((*fenc_mvs[0]).x | (*fenc_mvs[0]).y) & 1)
+            {
+                int hpelA = ((*fenc_mvs[0]).y & 2) | (((*fenc_mvs[0]).x & 2) >> 1);
+                pixel *frefA = fref0->lowresPlane[hpelA] + pelOffset + ((*fenc_mvs[0]).x >> 2) + ((*fenc_mvs[0]).y >> 2) * fref0->lumaStride;
+
+                MV qmvB = (*fenc_mvs[0]) + MV(((*fenc_mvs[0]).x & 1) * 2, ((*fenc_mvs[0]).y & 1) * 2);
+                int hpelB = (qmvB.y & 2) | ((qmvB.x & 2) >> 1);
+                pixel *frefB = fref0->lowresPlane[hpelB] + pelOffset + (qmvB.x >> 2) + (qmvB.y >> 2) * fref0->lumaStride;
+
+                primitives.pixelavg_pp[PARTITION_8x8](subpelbuf1, X265_LOWRES_CU_SIZE, frefA, fref0->lumaStride, frefB, fref0->lumaStride, 32);
+                src0 = subpelbuf1;
+                stride0 = X265_LOWRES_CU_SIZE;
+            }
+            else
+            {
+                /* FPEL/HPEL */
+                int hpel = ((*fenc_mvs[0]).y & 2) | (((*fenc_mvs[0]).x & 2) >> 1);
+                src0 = fref0->lowresPlane[hpel] + pelOffset + ((*fenc_mvs[0]).x >> 2) + ((*fenc_mvs[0]).y >> 2) * fref0->lumaStride;
+                stride0 = fref0->lumaStride;
+            }
+            if (((*fenc_mvs[1]).x | (*fenc_mvs[1]).y) & 1)
+            {
+                int hpelA = ((*fenc_mvs[1]).y & 2) | (((*fenc_mvs[1]).x & 2) >> 1);
+                pixel *frefA = fref1->lowresPlane[hpelA] + pelOffset + ((*fenc_mvs[1]).x >> 2) + ((*fenc_mvs[1]).y >> 2) * fref1->lumaStride;
+
+                MV qmvB = (*fenc_mvs[1]) + MV(((*fenc_mvs[1]).x & 1) * 2, ((*fenc_mvs[1]).y & 1) * 2);
+                int hpelB = (qmvB.y & 2) | ((qmvB.x & 2) >> 1);
+                pixel *frefB = fref1->lowresPlane[hpelB] + pelOffset + (qmvB.x >> 2) + (qmvB.y >> 2) * fref1->lumaStride;
+
+                primitives.pixelavg_pp[PARTITION_8x8](subpelbuf2, X265_LOWRES_CU_SIZE, frefA, fref1->lumaStride, frefB, fref1->lumaStride, 32);
+                src1 = subpelbuf2;
+                stride1 = X265_LOWRES_CU_SIZE;
+            }
+            else
+            {
+                int hpel = ((*fenc_mvs[1]).y & 2) | (((*fenc_mvs[1]).x & 2) >> 1);
+                src1 = fref1->lowresPlane[hpel] + pelOffset + ((*fenc_mvs[1]).x >> 2) + ((*fenc_mvs[1]).y >> 2) * fref1->lumaStride;
+                stride1 = fref1->lumaStride;
+            }
+
+            pixel ref[X265_LOWRES_CU_SIZE * X265_LOWRES_CU_SIZE];
+            primitives.pixelavg_pp[PARTITION_8x8](ref, X265_LOWRES_CU_SIZE, src0, stride0, src1, stride1, 0);
+
+            int bicost = primitives.satd[PARTITION_8x8](fenc->lowresPlane[0] + pelOffset, fenc->lumaStride, ref, X265_LOWRES_CU_SIZE);
+            COPY2_IF_LT(bcost, bicost, listused, 3);
+
+            //Try 0,0 candidates
+            src0 = fref0->lowresPlane[0] + pelOffset;
+            src1 = fref1->lowresPlane[0] + pelOffset;
+
+            primitives.pixelavg_pp[PARTITION_8x8](ref, X265_LOWRES_CU_SIZE, src0, fref0->lumaStride, src1, fref1->lumaStride, 0);
+
+            bicost = primitives.satd[PARTITION_8x8](fenc->lowresPlane[0] + pelOffset, fenc->lumaStride, ref, X265_LOWRES_CU_SIZE);
+            COPY2_IF_LT(bcost, bicost, listused, 3);
+        }
     }
     if (!fenc->bIntraCalculated)
     {