+// this routine gets a buffer for an uncompressed YUV420 video frame
+// with dimensions width x height.
+static inline hb_buffer_t * hb_video_buffer_init( int width, int height )
+{
+ // Y requires w x h bytes. U & V each require (w+1)/2 x
+ // (h+1)/2 bytes (the "+1" is to round up). We shift rather
+ // than divide by 2 since the compiler can't know these ints
+ // are positive so it generates very expensive integer divides
+ // if we do "/2". The code here matches the calculation for
+ // PIX_FMT_YUV420P in ffmpeg's avpicture_fill() which is required
+ // for most of HB's filters to work right.
+ return hb_buffer_init( width * height + ( ( width+1 ) >> 1 ) *
+ ( ( height+1 ) >> 1 ) * 2 );
+}
+
+// this routine 'moves' data from src to dst by interchanging 'data',
+// 'size' & 'alloc' between them and copying the rest of the fields
+// from src to dst.
+static inline void hb_buffer_swap_copy( hb_buffer_t *src, hb_buffer_t *dst )
+{
+ uint8_t *data = dst->data;
+ int size = dst->size;
+ int alloc = dst->alloc;
+
+ *dst = *src;
+
+ src->data = data;
+ src->size = size;
+ src->alloc = alloc;
+}
+