]> git.sesse.net Git - mlt/commitdiff
Add mlt_image_format_size()
authorDan Dennedy <dan@dennedy.org>
Mon, 7 Mar 2011 05:57:10 +0000 (21:57 -0800)
committerDan Dennedy <dan@dennedy.org>
Mon, 7 Mar 2011 05:57:10 +0000 (21:57 -0800)
src/framework/mlt_frame.c
src/framework/mlt_frame.h

index 11b2b609f4292ffc9a5063f39a5eb1950fe98eeb..71ea33e52623ef1c618e93f6cf087a68fd101a48 100644 (file)
@@ -385,6 +385,40 @@ const char * mlt_image_format_name( mlt_image_format format )
        return "invalid";
 }
 
+/** Get the number of bytes needed for an image.
+  *
+  * \public \memberof mlt_frame_s
+  * \param format the image format
+  * \param width width of the image in pixels
+  * \param height height of the image in pixels
+  * \param[out] bpp the number of bytes per pixel (optional)
+  * \return the number of bytes
+  */
+int mlt_image_format_size( mlt_image_format format, int width, int height, int *bpp )
+{
+       height += 1;
+       switch ( format )
+       {
+               case mlt_image_none:
+                       if ( bpp ) *bpp = 0;
+                       return 0;
+               case mlt_image_rgb24:
+                       if ( bpp ) *bpp = 3;
+                       return width * height * 3;
+               case mlt_image_opengl:
+               case mlt_image_rgb24a:
+                       if ( bpp ) *bpp = 4;
+                       return width * height * 4;
+               case mlt_image_yuv422:
+                       if ( bpp ) *bpp = 2;
+                       return width * height * 2;
+               case mlt_image_yuv420p:
+                       if ( bpp ) *bpp = 3 / 2;
+                       return width * height * 3 / 2;
+       }
+       return 0;
+}
+
 /** Get the image associated to the frame.
  *
  * You should express the desired format, width, and height as inputs. As long
index ead3098a9a8ada4dafd0120bdaf0b71a2ada6a1f..f54dee3a04414498723bffe185e5fb9c9b308afd 100644 (file)
@@ -135,6 +135,7 @@ extern mlt_properties mlt_frame_unique_properties( mlt_frame self, mlt_service s
 extern int mlt_sample_calculator( float fps, int frequency, int64_t position );
 extern int64_t mlt_sample_calculator_to_now( float fps, int frequency, int64_t position );
 extern const char * mlt_image_format_name( mlt_image_format format );
+extern int mlt_image_format_size( mlt_image_format format, int width, int height, int *bpp );
 extern const char * mlt_audio_format_name( mlt_audio_format format );
 extern void mlt_frame_write_ppm( mlt_frame frame );