[x264-devel] Add support for the new (4:4:4) colorspaces to x264_picture_alloc

Anton Mitrofanov git at videolan.org
Sat Jul 23 02:38:53 CEST 2011


x264 | branch: master | Anton Mitrofanov <BugMaster at narod.ru> | Mon Jul 18 15:20:05 2011 +0400| [c3445f63085a50bf34471470a324ba8f455625f6] | committer: Jason Garrett-Glaser

Add support for the new (4:4:4) colorspaces to x264_picture_alloc

> http://git.videolan.org/gitweb.cgi/x264.git/?a=commit;h=c3445f63085a50bf34471470a324ba8f455625f6
---

 common/common.c |   46 +++++++++++++++++++++++++++++++++-------------
 1 files changed, 33 insertions(+), 13 deletions(-)

diff --git a/common/common.c b/common/common.c
index 5a5e036..addd5cd 100644
--- a/common/common.c
+++ b/common/common.c
@@ -1057,27 +1057,47 @@ void x264_picture_init( x264_picture_t *pic )
  ****************************************************************************/
 int x264_picture_alloc( x264_picture_t *pic, int i_csp, int i_width, int i_height )
 {
+    typedef struct
+    {
+        int planes;
+        int width_fix8[3];
+        int height_fix8[3];
+    } x264_csp_tab_t;
+
+    static const x264_csp_tab_t x264_csp_tab[] =
+    {
+        [X264_CSP_I420] = { 3, { 256*1, 256/2, 256/2 }, { 256*1, 256/2, 256/2 } },
+        [X264_CSP_YV12] = { 3, { 256*1, 256/2, 256/2 }, { 256*1, 256/2, 256/2 } },
+        [X264_CSP_NV12] = { 2, { 256*1, 256*1 },        { 256*1, 256/2 },       },
+        [X264_CSP_I444] = { 3, { 256*1, 256*1, 256*1 }, { 256*1, 256*1, 256*1 } },
+        [X264_CSP_YV24] = { 3, { 256*1, 256*1, 256*1 }, { 256*1, 256*1, 256*1 } },
+        [X264_CSP_BGR]  = { 1, { 256*3 },               { 256*1 },              },
+        [X264_CSP_BGRA] = { 1, { 256*4 },               { 256*1 },              },
+        [X264_CSP_RGB]  = { 1, { 256*3 },               { 256*1 },              },
+    };
+
     int csp = i_csp & X264_CSP_MASK;
     if( csp <= X264_CSP_NONE || csp >= X264_CSP_MAX )
         return -1;
     x264_picture_init( pic );
     pic->img.i_csp = i_csp;
-    pic->img.i_plane = csp == X264_CSP_NV12 ? 2 : 3;
+    pic->img.i_plane = x264_csp_tab[csp].planes;
     int depth_factor = i_csp & X264_CSP_HIGH_DEPTH ? 2 : 1;
-    pic->img.plane[0] = x264_malloc( 3 * i_width * i_height / 2 * depth_factor );
-    if( !pic->img.plane[0] )
-        return -1;
-    pic->img.plane[1] = pic->img.plane[0] + i_width * i_height * depth_factor;
-    if( csp != X264_CSP_NV12 )
-        pic->img.plane[2] = pic->img.plane[1] + i_width * i_height / 4 * depth_factor;
-    pic->img.i_stride[0] = i_width * depth_factor;
-    if( csp == X264_CSP_NV12 )
-        pic->img.i_stride[1] = i_width * depth_factor;
-    else
+    int plane_offset[3] = {0};
+    int frame_size = 0;
+    for( int i = 0; i < pic->img.i_plane; i++ )
     {
-        pic->img.i_stride[1] = i_width / 2 * depth_factor;
-        pic->img.i_stride[2] = i_width / 2 * depth_factor;
+        int stride = (((int64_t)i_width * x264_csp_tab[csp].width_fix8[i]) >> 8) * depth_factor;
+        int plane_size = (((int64_t)i_height * x264_csp_tab[csp].height_fix8[i]) >> 8) * stride;
+        pic->img.i_stride[i] = stride;
+        plane_offset[i] = frame_size;
+        frame_size += plane_size;
     }
+    pic->img.plane[0] = x264_malloc( frame_size );
+    if( !pic->img.plane[0] )
+        return -1;
+    for( int i = 1; i < pic->img.i_plane; i++ )
+        pic->img.plane[i] = pic->img.plane[0] + plane_offset[i];
     return 0;
 }
 



More information about the x264-devel mailing list