[x265] [PATCH] psy-rd: ported x264's few functions required for psy-rd feature

sumalatha at multicorewareinc.com sumalatha at multicorewareinc.com
Fri Mar 14 12:04:16 CET 2014


# HG changeset patch
# User Sumalatha Polureddy
# Date 1394795043 -19800
# Node ID 5b77edcf1a8792cb0c4de34b1ccd80940fc47d26
# Parent  dae8674085419080a8bdfd102ed416621a23f164
psy-rd: ported x264's few functions required for psy-rd feature

diff -r dae867408541 -r 5b77edcf1a87 source/encoder/CMakeLists.txt
--- a/source/encoder/CMakeLists.txt	Thu Mar 13 16:37:55 2014 +0530
+++ b/source/encoder/CMakeLists.txt	Fri Mar 14 16:34:03 2014 +0530
@@ -58,4 +58,5 @@
     reference.cpp reference.h
     encoder.cpp encoder.h
     api.cpp
-    weightPrediction.cpp)
+    weightPrediction.cpp
+    rdo.cpp rdo.h)
diff -r dae867408541 -r 5b77edcf1a87 source/encoder/rdo.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/source/encoder/rdo.cpp	Fri Mar 14 16:34:03 2014 +0530
@@ -0,0 +1,109 @@
+/*****************************************************************************
+ * Copyright (C) 2013 x265 project
+ *
+ * Authors: Sumalatha PoluReddy <sumalatha at multicorewareinc.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111, USA.
+ *
+ * This program is also available under a commercial proprietary license.
+ * For more information, contact us at licensing at multicorewareinc.com.
+ *****************************************************************************/
+
+#include "rdo.h"
+
+using namespace x265;
+
+static uint64_t cachedHadamard(TComDataCU* cu, int size, int x, int y, pixel *fenc)
+{
+    static const uint8_t hadamardShiftX[4] = {4,   4,   3,   3};
+    static const uint8_t hadamardShiftY[4] = {4-0, 3-0, 4-1, 3-1};
+    static const uint8_t  hadamardOffset[4] = {0,   1,   3,   5};
+    int cacheIndex = (x >> hadamardShiftX[size]) + (y >> hadamardShiftY[size])
+                    + hadamardOffset[size];
+    uint64_t res = cu->fencHadamardCache[cacheIndex];
+    if( res )
+        return res - 1;
+    else
+    {
+        //pixel *fenc = cu->getPic()->getori.p_fenc[0] + x + y*FENC_STRIDE;
+        res = primitives.pixel_hadamard_ac[size](fenc, FENC_STRIDE);
+        cu->fencHadamardCache[cacheIndex] = res + 1;
+        return res;
+    }
+}
+
+static int cachedSatd(TComDataCU* cu, int size, int x, int y, pixel *fenc)
+{
+    static const uint8_t satdShiftX[3] = {3,   2,   2};
+    static const uint8_t satdShiftY[3] = {2-1, 3-2, 2-2};
+    static const uint8_t  satdOffset[3] = {0,   8,   16};
+    pixel zero[16] = {0};
+    int cacheIndex = (x >> satdShiftX[size - 0/*PIXEL_8x4*/]) + (y >> satdShiftY[size - 0/*PIXEL_8x4*/])
+                    + satdOffset[size - 0/*PIXEL_8x4*/]; //TODO: need to check for PIXEL_8x4
+    int res = cu->fencSatdCache[cacheIndex];
+    if( res )
+        return res - 1;
+    else
+    {
+        //pixel *fenc = h->mb.pic.p_fenc[0] + x + y*FENC_STRIDE;
+        int dc = primitives.sad[size](fenc, FENC_STRIDE, zero, 0) >> 1;
+        res = primitives.satd[size](fenc, FENC_STRIDE, zero, 0) - dc;
+        cu->fencSatdCache[cacheIndex] = res + 1;
+        return res;
+    }
+}
+
+int ssdPlane(TComDataCU* cu, int size, int p, int x, int y, TComYuv* fencYuv, TComYuv* fdecYuv)
+{
+    static pixel zero[16] = {0};
+    int satd = 0;
+    pixel *fdec = fdecYuv->getLumaAddr();
+    pixel *fenc = fencYuv->getLumaAddr();
+
+    cu->getPic();
+
+    if( p == 0 && cu->getPic()->psyRd)
+    {
+        /* If the plane is smaller than 8x8, we can't do an SA8D; this probably isn't a big problem. */
+        if( size <= LUMA_8x8 )
+        {
+            uint64_t fdec_acs = primitives.pixel_hadamard_ac[size]( fdec, fdecYuv->getStride());
+            uint64_t fenc_acs = cachedHadamard( cu, size, x, y, fenc);
+            satd = abs((int32_t)fdec_acs - (int32_t)fenc_acs)
+                 + abs((int32_t)(fdec_acs>>32) - (int32_t)(fenc_acs>>32));
+            satd >>= 1;
+        }
+        else
+        {
+            int dc = primitives.sad[size]( fdec, fdecYuv->getStride(), zero, 0 ) >> 1;
+            satd = abs(primitives.satd[size]( fdec, fdecYuv->getStride(), zero, 0 ) - dc - cachedSatd( cu, size, x, y, fenc));
+        }
+        satd = (satd * (int)(cu->getPic()->psyRd * cu->m_psyRdLambda) + 128) >> 8;
+    }
+    return primitives.sse_pp[size](fenc, fencYuv->getStride(), fdec, fdecYuv->getStride()) + satd;
+}
+
+/* Reset fenc satd scores cache for psy RD */
+void cuInitFencCache(TComDataCU* cu, int b_satd)
+{
+    //if( h->param.analyse.i_trellis == 2 && h->mb.i_psy_trellis )
+        //x264_psy_trellis_init( h, h->param.analyse.b_transform_8x8 );
+    if(cu->getPic()->psyRd)
+        return;
+    /* Writes beyond the end of the array, but not a problem since fenc_satd_cache is right after. */
+    memset(cu->fencHadamardCache, 0, sizeof(cu->fencHadamardCache));
+    if( b_satd )
+        memset(cu->fencSatdCache, 0, sizeof(cu->fencSatdCache));
+}
\ No newline at end of file
diff -r dae867408541 -r 5b77edcf1a87 source/encoder/rdo.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/source/encoder/rdo.h	Fri Mar 14 16:34:03 2014 +0530
@@ -0,0 +1,32 @@
+
+/*****************************************************************************
+ * Copyright (C) 2013 x265 project
+ *
+ * Authors: Sumalatha PoluReddy <sumalatha at multicorewareinc.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111, USA.
+ *
+ * This program is also available under a commercial proprietary license.
+ * For more information, contact us at licensing at multicorewareinc.com.
+ *****************************************************************************/
+#include "primitives.h"
+#include "TLibCommon/TComYuv.h"
+#include "TLibCommon/TComDataCU.h"
+#include "TLibCommon\TComPic.h"
+
+using namespace x265;
+
+int ssdPlane(TComDataCU* cu, int size, int p, int x, int y, TComYuv* fencYuv, TComYuv* fdecYuv);
+void cuInitFencCache(TComDataCU* cu, int b_satd);
\ No newline at end of file


More information about the x265-devel mailing list