[x265] [PATCH 1 of 3] primitives: added C primitives for upShift/downShift of input pixels

murugan at multicorewareinc.com murugan at multicorewareinc.com
Mon Mar 31 14:22:55 CEST 2014


# HG changeset patch
# User Murugan Vairavel <murugan at multicorewareinc.com>
# Date 1396268437 -19800
#      Mon Mar 31 17:50:37 2014 +0530
# Node ID b0931c9326dc4a20718bf4d642c0ef1fcd7cd494
# Parent  6f7b323061dccfa7325a3bd6b0acd639d6377016
primitives: added C primitives for upShift/downShift of input pixels

diff -r 6f7b323061dc -r b0931c9326dc source/Lib/TLibCommon/TComPicYuv.cpp
--- a/source/Lib/TLibCommon/TComPicYuv.cpp	Sat Mar 29 20:27:43 2014 -0500
+++ b/source/Lib/TLibCommon/TComPicYuv.cpp	Mon Mar 31 17:50:37 2014 +0530
@@ -181,9 +181,6 @@
 
     if (pic.bitDepth < X265_DEPTH)
     {
-        /* 8bit input, 10bit internal depth. Do a simple up-shift of 2 bits */
-        assert(X265_DEPTH == 10);
-
         pixel *yPixel = getLumaAddr();
         pixel *uPixel = getCbAddr();
         pixel *vPixel = getCrAddr();
@@ -191,31 +188,11 @@
         uint8_t *yChar = (uint8_t*)pic.planes[0];
         uint8_t *uChar = (uint8_t*)pic.planes[1];
         uint8_t *vChar = (uint8_t*)pic.planes[2];
+        int shift = X265_MAX(0, X265_DEPTH - pic.bitDepth);
 
-        for (int r = 0; r < height; r++)
-        {
-            for (int c = 0; c < width; c++)
-            {
-                yPixel[c] = ((pixel)yChar[c]) << 2;
-            }
-
-            yPixel += getStride();
-            yChar += pic.stride[0] / sizeof(*yChar);
-        }
-
-        for (int r = 0; r < height >> m_vChromaShift; r++)
-        {
-            for (int c = 0; c < width >> m_hChromaShift; c++)
-            {
-                uPixel[c] = ((pixel)uChar[c]) << 2;
-                vPixel[c] = ((pixel)vChar[c]) << 2;
-            }
-
-            uPixel += getCStride();
-            vPixel += getCStride();
-            uChar += pic.stride[1] / sizeof(*uChar);
-            vChar += pic.stride[2] / sizeof(*vChar);
-        }
+        primitives.planecopy_cp(yChar, pic.stride[0] / sizeof(*yChar), yPixel, getStride(), width, height, shift);
+        primitives.planecopy_cp(uChar, pic.stride[1] / sizeof(*uChar), uPixel, getCStride(), width >> m_hChromaShift, height >> m_vChromaShift, shift);
+        primitives.planecopy_cp(vChar, pic.stride[2] / sizeof(*vChar), vPixel, getCStride(), width >> m_hChromaShift, height >> m_vChromaShift, shift);
     }
     else if (pic.bitDepth == 8)
     {
@@ -267,30 +244,10 @@
         int shift = X265_MAX(0, pic.bitDepth - X265_DEPTH);
 
         /* shift and mask pixels to final size */
-        for (int r = 0; r < height; r++)
-        {
-            for (int c = 0; c < width; c++)
-            {
-                yPixel[c] = (pixel)((yShort[c] >> shift) & mask);
-            }
 
-            yPixel += getStride();
-            yShort += pic.stride[0] / sizeof(*yShort);
-        }
-
-        for (int r = 0; r < height >> m_vChromaShift; r++)
-        {
-            for (int c = 0; c < width >> m_hChromaShift; c++)
-            {
-                uPixel[c] = (pixel)((uShort[c] >> shift) & mask);
-                vPixel[c] = (pixel)((vShort[c] >> shift) & mask);
-            }
-
-            uPixel += getCStride();
-            vPixel += getCStride();
-            uShort += pic.stride[1] / sizeof(*uShort);
-            vShort += pic.stride[2] / sizeof(*vShort);
-        }
+        primitives.planecopy_sp(yShort, pic.stride[0] / sizeof(*yShort), yPixel, getStride(), width, height, shift, mask);
+        primitives.planecopy_sp(uShort, pic.stride[1] / sizeof(*uShort), uPixel, getCStride(), width >> m_hChromaShift, height >> m_vChromaShift, shift, mask);
+        primitives.planecopy_sp(vShort, pic.stride[2] / sizeof(*vShort), vPixel, getCStride(), width >> m_hChromaShift, height >> m_vChromaShift, shift, mask);
     }
 
     /* extend the right edge if width was not multiple of the minimum CU size */
diff -r 6f7b323061dc -r b0931c9326dc source/common/pixel.cpp
--- a/source/common/pixel.cpp	Sat Mar 29 20:27:43 2014 -0500
+++ b/source/common/pixel.cpp	Mon Mar 31 17:50:37 2014 +0530
@@ -852,6 +852,34 @@
         dst  += dstStride;
     }
 }
+
+void planecopy_cp_c(uint8_t *src, intptr_t srcStride, pixel *dst, intptr_t dstStride, int width, int height, int shift)
+{
+    for (int r = 0; r < height; r++)
+    {
+        for (int c = 0; c < width; c++)
+        {
+            dst[c] = ((pixel)src[c]) << shift;
+        }
+
+        dst += dstStride;
+        src += srcStride;
+    }
+}
+
+void planecopy_sp_c(uint16_t *src, intptr_t srcStride, pixel *dst, intptr_t dstStride, int width, int height, int shift, uint16_t mask)
+{
+    for (int r = 0; r < height; r++)
+    {
+        for (int c = 0; c < width; c++)
+        {
+            dst[c] = (pixel)((src[c] >> shift) & mask);
+        }
+
+        dst += dstStride;
+        src += srcStride;
+    }
+}
 }  // end anonymous namespace
 
 namespace x265 {
@@ -1099,5 +1127,7 @@
     p.var[BLOCK_32x32] = pixel_var<32>;
     p.var[BLOCK_64x64] = pixel_var<64>;
     p.plane_copy_deinterleave_c = plane_copy_deinterleave_chroma;
+    p.planecopy_cp = planecopy_cp_c;
+    p.planecopy_sp = planecopy_sp_c;
 }
 }
diff -r 6f7b323061dc -r b0931c9326dc source/common/primitives.h
--- a/source/common/primitives.h	Sat Mar 29 20:27:43 2014 -0500
+++ b/source/common/primitives.h	Mon Mar 31 17:50:37 2014 +0530
@@ -163,6 +163,8 @@
 typedef void (*addAvg_t)(int16_t* src0, int16_t* src1, pixel* dst, intptr_t src0Stride, intptr_t src1Stride, intptr_t dstStride);
 
 typedef void (*saoCuOrgE0_t)(pixel * rec, int8_t * offsetEo, int lcuWidth, int8_t signLeft);
+typedef void (*planecopy_cp_t) (uint8_t *src, intptr_t srcStride, pixel *dst, intptr_t dstStride, int width, int height, int shift);
+typedef void (*planecopy_sp_t) (uint16_t *src, intptr_t srcStride, pixel *dst, intptr_t dstStride, int width, int height, int shift, uint16_t mask);
 
 /* Define a structure containing function pointers to optimized encoder
  * primitives.  Each pointer can reference either an assembly routine,
@@ -233,6 +235,8 @@
     extendCURowBorder_t extendRowBorder;
     // sao primitives
     saoCuOrgE0_t      saoCuOrgE0;
+    planecopy_cp_t    planecopy_cp;
+    planecopy_sp_t    planecopy_sp;
 
     struct
     {


More information about the x265-devel mailing list