[x265] [PATCH] ratecontrol: fix bug in acEnergyVar with multiple color spaces

deepthi at multicorewareinc.com deepthi at multicorewareinc.com
Thu Feb 20 11:26:49 CET 2014


# HG changeset patch
# User Deepthi Nandakumar <deepthi at multicorewareinc.com>
# Date 1392891892 -19800
# Node ID 770a3cc7176924ecfa0bad2f06f5cdd97dd81957
# Parent  3389061b75a486e004409ab628c46fed39d03b72
ratecontrol: fix bug in acEnergyVar with multiple color spaces

diff -r 3389061b75a4 -r 770a3cc71769 source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cpp	Wed Feb 19 17:03:21 2014 -0600
+++ b/source/encoder/ratecontrol.cpp	Thu Feb 20 15:54:52 2014 +0530
@@ -56,9 +56,10 @@
 }
 
 /* Find the energy of each block in Y/Cb/Cr plane */
-static inline uint32_t acEnergyPlane(TComPic *pic, pixel* src, int srcStride, int bChroma)
+static inline uint32_t acEnergyPlane(TComPic *pic, pixel* src, int srcStride, int bChroma, int colorFormat)
 {
-    if (bChroma)
+    /* Support only 420 and 444 color spaces */
+    if (colorFormat == X265_CSP_I420 && bChroma)
     {
         ALIGN_VAR_8(pixel, pix[8 * 8]);
         primitives.luma_copy_pp[LUMA_8x8](pix, 8, src, srcStride);
@@ -74,13 +75,16 @@
     int stride = pic->getPicYuvOrg()->getStride();
     int cStride = pic->getPicYuvOrg()->getCStride();
     uint32_t blockOffsetLuma = block_x + (block_y * stride);
-    uint32_t blockOffsetChroma = (block_x >> 1) + ((block_y >> 1) * cStride);
+    int colorFormat = cfg->param.internalCsp;
+    int hShift = CHROMA_H_SHIFT(colorFormat);
+    int vShift = CHROMA_V_SHIFT(colorFormat);
+    uint32_t blockOffsetChroma = (block_x >> hShift) + ((block_y >> vShift) * cStride);
 
     uint32_t var;
 
-    var  = acEnergyPlane(pic, pic->getPicYuvOrg()->getLumaAddr() + blockOffsetLuma, stride, 0);
-    var += acEnergyPlane(pic, pic->getPicYuvOrg()->getCbAddr() + blockOffsetChroma, cStride, 1);
-    var += acEnergyPlane(pic, pic->getPicYuvOrg()->getCrAddr() + blockOffsetChroma, cStride, 2);
+    var  = acEnergyPlane(pic, pic->getPicYuvOrg()->getLumaAddr() + blockOffsetLuma, stride, 0, colorFormat);
+    var += acEnergyPlane(pic, pic->getPicYuvOrg()->getCbAddr() + blockOffsetChroma, cStride, 1, colorFormat);
+    var += acEnergyPlane(pic, pic->getPicYuvOrg()->getCrAddr() + blockOffsetChroma, cStride, 2, colorFormat);
     x265_emms();
     return var;
 }


More information about the x265-devel mailing list