[x265] [PATCH] YUV, Y4M Output: bitdepth confusion resolved

deepthi at multicorewareinc.com deepthi at multicorewareinc.com
Wed Nov 6 11:07:31 CET 2013


# HG changeset patch
# User Deepthi Nandakumar <deepthi at multicorewareinc.com>
# Date 1383732437 -19800
# Node ID e1b87cf4133e481cea131882ec5cf6bf80e55846
# Parent  bc99537483f101547312a589ceb3d428c176cfed
YUV, Y4M Output: bitdepth confusion resolved

diff -r bc99537483f1 -r e1b87cf4133e source/output/y4m.cpp
--- a/source/output/y4m.cpp	Tue Nov 05 22:21:55 2013 -0600
+++ b/source/output/y4m.cpp	Wed Nov 06 15:37:17 2013 +0530
@@ -67,41 +67,38 @@
     ofs.seekp(outPicPos);
     ofs << "FRAME\n";
 
-    if (pic.bitDepth > 8)
+#if HIGH_BIT_DEPTH    
+    // encoder gave us short pixels, downshift, then write
+    int shift = pic.bitDepth - 8;
+    if (pic.poc == 0)
     {
-        // encoder gave us short pixels, downshift, then write
-        int shift = pic.bitDepth - 8;
-        if (pic.poc == 0)
+        x265_log(NULL, X265_LOG_WARNING, "y4m: down-shifting reconstructed pixels to 8 bits\n");
+    }
+    for (int i = 0; i < x265_cli_csps[colorSpace].planes; i++)
+    {
+        uint16_t *src = (uint16_t*)pic.planes[i];
+        for (int h = 0; h < height >> x265_cli_csps[colorSpace].height[i]; h++)
         {
-            x265_log(NULL, X265_LOG_WARNING, "y4m: down-shifting reconstructed pixels to 8 bits\n");
-        }
-        for (int i = 0; i < x265_cli_csps[colorSpace].planes; i++)
-        {
-            uint16_t *src = (uint16_t*)pic.planes[i];
-            for (int h = 0; h < height >> x265_cli_csps[colorSpace].height[i]; h++)
+            for (int w = 0; w < width >> x265_cli_csps[colorSpace].width[i]; w++)
             {
-                for (int w = 0; w < width >> x265_cli_csps[colorSpace].width[i]; w++)
-                {
-                    buf[w] = (char)(src[w] >> shift);
-                }
+                buf[w] = (char)(src[w] >> shift);
+            }
 
-                ofs.write(buf, width >> x265_cli_csps[colorSpace].width[i]);
-                src += pic.stride[i];
-            }
+            ofs.write(buf, width >> x265_cli_csps[colorSpace].width[i]);
+            src += pic.stride[i];
         }
     }
-    else
+#else    
+    for (int i = 0; i < x265_cli_csps[colorSpace].planes; i++)
     {
-        for (int i = 0; i < x265_cli_csps[colorSpace].planes; i++)
+        char *src = (char*)pic.planes[i];
+        for (int h = 0; h < height >> x265_cli_csps[colorSpace].height[i]; h++)
         {
-            char *src = (char*)pic.planes[i];
-            for (int h = 0; h < height >> x265_cli_csps[colorSpace].height[i]; h++)
-            {
-                ofs.write(src, width >> x265_cli_csps[colorSpace].width[i]);
-                src += pic.stride[i];
-            }
+            ofs.write(src, width >> x265_cli_csps[colorSpace].width[i]);
+            src += pic.stride[i];
         }
     }
+#endif
 
     PPAStopCpuEventFunc(write_yuv);
     return true;
diff -r bc99537483f1 -r e1b87cf4133e source/output/yuv.cpp
--- a/source/output/yuv.cpp	Tue Nov 05 22:21:55 2013 -0600
+++ b/source/output/yuv.cpp	Wed Nov 06 15:37:17 2013 +0530
@@ -57,30 +57,27 @@
     uint32_t pixelbytes = (depth > 8) ? 2 : 1;
     ofs.seekp(pic.poc * frameSize * pixelbytes);
 
-    if (pic.bitDepth > 8)
+#if HIGH_BIT_DEPTH    
+    for (int i = 0; i < x265_cli_csps[colorSpace].planes; i++)
     {
-        for (int i = 0; i < x265_cli_csps[colorSpace].planes; i++)
+        uint16_t *src = (uint16_t*)pic.planes[0];
+        for (int h = 0; h < height; h++)
         {
-            uint16_t *src = (uint16_t*)pic.planes[0];
-            for (int h = 0; h < height; h++)
-            {
-                ofs.write((const char*)src, (width * pixelbytes) >> x265_cli_csps[colorSpace].width[i]);
-                src += pic.stride[i];
-            }
+            ofs.write((const char*)src, (width * pixelbytes) >> x265_cli_csps[colorSpace].width[i]);
+            src += pic.stride[i];
         }
-    }
-    else
+    }    
+#else    
+    for (int i = 0; i < x265_cli_csps[colorSpace].planes; i++)
     {
-        for (int i = 0; i < x265_cli_csps[colorSpace].planes; i++)
+        char *src = (char*)pic.planes[0];
+        for (int h = 0; h < height; h++)
         {
-            char *src = (char*)pic.planes[0];
-            for (int h = 0; h < height; h++)
-            {
-                ofs.write(src, width >> x265_cli_csps[colorSpace].width[i]);
-                src += pic.stride[i];
-            }
+            ofs.write(src, width >> x265_cli_csps[colorSpace].width[i]);
+            src += pic.stride[i];
         }
-    }
+    }    
+#endif
 
     PPAStopCpuEventFunc(write_yuv);
     return true;


More information about the x265-devel mailing list