]> granicus.if.org Git - handbrake/commitdiff
libhb: add hb_image_init to create blank images
authorjstebbins <jstebbins.hb@gmail.com>
Fri, 19 Dec 2014 19:18:35 +0000 (19:18 +0000)
committerjstebbins <jstebbins.hb@gmail.com>
Fri, 19 Dec 2014 19:18:35 +0000 (19:18 +0000)
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6613 b64f7644-9d1e-0410-96f1-a4d463321fa5

libhb/fifo.c
libhb/internal.h

index 5e24adc2ab6249d6007825d127a785a7ccffbf98..4f231fb2c9c27d8df7ca8b9690e64383228436aa 100644 (file)
@@ -542,6 +542,11 @@ void hb_buffer_init_planes( hb_buffer_t * b )
     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(b->f.fmt);
     int p;
 
+    if (desc == NULL)
+    {
+        return;
+    }
+
     uint8_t has_plane[4] = {0,};
 
     for( p = 0; p < 4; p++ )
@@ -560,6 +565,10 @@ hb_buffer_t * hb_frame_buffer_init( int pix_fmt, int width, int height )
     int p;
     uint8_t has_plane[4] = {0,};
 
+    if (desc == NULL)
+    {
+        return NULL;
+    }
     for( p = 0; p < 4; p++ )
     {
         has_plane[desc->comp[p].plane] = 1;
@@ -598,6 +607,10 @@ void hb_video_buffer_realloc( hb_buffer_t * buf, int width, int height )
     int p;
     uint8_t has_plane[4] = {0,};
 
+    if (desc == NULL)
+    {
+        return;
+    }
     for( p = 0; p < 4; p++ )
     {
         has_plane[desc->comp[p].plane] = 1;
@@ -714,6 +727,73 @@ void hb_buffer_move_subs( hb_buffer_t * dst, hb_buffer_t * src )
 
 }
 
+hb_image_t * hb_image_init(int pix_fmt, int width, int height)
+{
+    const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
+    int p;
+    uint8_t has_plane[4] = {0,};
+
+    if (desc == NULL)
+    {
+        return NULL;
+    }
+    for (p = 0; p < 4; p++)
+    {
+        has_plane[desc->comp[p].plane] = 1;
+    }
+
+    int size = 0;
+    for (p = 0; p < 4; p++)
+    {
+        if (has_plane[p])
+        {
+            size += hb_image_stride( pix_fmt, width, p ) * 
+                    hb_image_height_stride( pix_fmt, height, p );
+        }
+    }
+
+    hb_image_t *image = calloc(1, sizeof(hb_image_t));
+    if (image == NULL)
+    {
+        return NULL;
+    }
+#if defined( SYS_DARWIN ) || defined( SYS_FREEBSD ) || defined( SYS_MINGW )
+    image->data  = malloc(size);
+#elif defined( SYS_CYGWIN )
+    /* FIXME */
+    image->data  = malloc(size + 17);
+#else
+    image->data  = memalign(16, size);
+#endif
+    if (image->data == NULL)
+    {
+        free(image);
+        return NULL;
+    }
+    image->format = pix_fmt;
+    image->width = width;
+    image->height = height;
+    memset(image->data, 0, size);
+
+    uint8_t * plane = image->data;
+    for (p = 0; p < 4; p++)
+    {
+        if (has_plane[p])
+        {
+            image->plane[p].data = plane;
+            image->plane[p].stride = hb_image_stride(pix_fmt, width, p );
+            image->plane[p].height_stride =
+                                    hb_image_height_stride(pix_fmt, height, p );
+            image->plane[p].width  = hb_image_width(pix_fmt, width, p );
+            image->plane[p].height = hb_image_height(pix_fmt, height, p );
+            image->plane[p].size   =
+                        image->plane[p].stride * image->plane[p].height_stride;
+            plane += image->plane[p].size;
+        }
+    }
+    return image;
+}
+
 hb_image_t * hb_buffer_to_image(hb_buffer_t *buf)
 {
     hb_image_t *image = calloc(1, sizeof(hb_image_t));
index 7fb266c8c8befe79db2942566116509ca4042b44..a45c85add3991648c6b3a1c87964b66b1aa71f50 100644 (file)
@@ -166,6 +166,7 @@ hb_buffer_t * hb_buffer_dup( const hb_buffer_t * src );
 int           hb_buffer_copy( hb_buffer_t * dst, const hb_buffer_t * src );
 void          hb_buffer_swap_copy( hb_buffer_t *src, hb_buffer_t *dst );
 void          hb_buffer_move_subs( hb_buffer_t * dst, hb_buffer_t * src );
+hb_image_t  * hb_image_init(int pix_fmt, int width, int height);
 hb_image_t  * hb_buffer_to_image(hb_buffer_t *buf);
 
 hb_fifo_t   * hb_fifo_init( int capacity, int thresh );