]> git.sesse.net Git - mlt/commitdiff
Refactor to use mlt_image_format_size().
authorDan Dennedy <dan@dennedy.org>
Mon, 7 Mar 2011 06:02:06 +0000 (22:02 -0800)
committerDan Dennedy <dan@dennedy.org>
Mon, 7 Mar 2011 06:02:06 +0000 (22:02 -0800)
src/modules/avformat/filter_swscale.c
src/modules/avformat/producer_avformat.c
src/modules/core/filter_crop.c
src/modules/core/filter_resize.c
src/modules/core/producer_colour.c
src/modules/gtk2/filter_rescale.c
src/modules/kdenlive/filter_freeze.c
src/modules/kdenlive/producer_framebuffer.c

index 5bbe85c0eb1625c0b5743573b5c81e0b4d9c7971..5d5853ba49ce5287de757382edf4ff3b98069c12 100644 (file)
@@ -95,19 +95,19 @@ static int filter_scale( mlt_frame frame, uint8_t **image, mlt_image_format *for
 
        // Determine the bytes per pixel
        int bpp;
+       mlt_image_format_size( *format, 0, 0, &bpp );
+
+       // Set swscale flags to get good quality
        switch ( *format )
        {
                case mlt_image_yuv422:
-                       bpp = 2;
                        interp |= SWS_FULL_CHR_H_INP;
                        break;
                case mlt_image_rgb24:
-                       bpp = 3;
                        interp |= SWS_FULL_CHR_H_INT;
                        break;
                case mlt_image_rgb24a:
                case mlt_image_opengl:
-                       bpp = 4;
                        interp |= SWS_FULL_CHR_H_INT;
                        break;
                default:
index d5ffd0969980861f554e8b0ef50ccb990062d2da..1c370807e6f418d714a34c61936c0e87406dee1d 100644 (file)
@@ -953,23 +953,8 @@ static int allocate_buffer( mlt_frame frame, AVCodecContext *codec_context, uint
 
        if ( codec_context->pix_fmt == PIX_FMT_RGB32 )
                size = *width * ( *height + 1 ) * 4;
-       else switch ( *format )
-       {
-               case mlt_image_yuv420p:
-                       size = *width * 3 * ( *height + 1 ) / 2;
-                       break;
-               case mlt_image_rgb24:
-                       size = *width * ( *height + 1 ) * 3;
-                       break;
-               case mlt_image_rgb24a:
-               case mlt_image_opengl:
-                       size = *width * ( *height + 1 ) * 4;
-                       break;
-               default:
-                       *format = mlt_image_yuv422;
-                       size = *width * ( *height + 1 ) * 2;
-                       break;
-       }
+       else
+               size = mlt_image_format_size( *format, *width, *height, NULL );
 
        // Construct the output image
        *buffer = mlt_pool_alloc( size );
@@ -1027,24 +1012,7 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form
                                *height = 1080;
 
                        // Cache hit
-                       int size;
-                       switch ( *format )
-                       {
-                               case mlt_image_yuv420p:
-                                       size = *width * 3 * ( *height + 1 ) / 2;
-                                       break;
-                               case mlt_image_rgb24:
-                                       size = *width * ( *height + 1 ) * 3;
-                                       break;
-                               case mlt_image_rgb24a:
-                               case mlt_image_opengl:
-                                       size = *width * ( *height + 1 ) * 4;
-                                       break;
-                               default:
-                                       *format = mlt_image_yuv422;
-                                       size = *width * ( *height + 1 ) * 2;
-                                       break;
-                       }
+                       int size = mlt_image_format_size( *format, *width, *height, NULL );
                        mlt_properties_set_data( frame_properties, "avformat.image_cache", item, 0, ( mlt_destructor )mlt_cache_item_close, NULL );
                        mlt_frame_set_image( frame, *buffer, size, NULL );
                        // self->top_field_first = mlt_properties_get_int( frame_properties, "top_field_first" );
@@ -1376,7 +1344,7 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form
                        // Now handle the picture if we have one
                        if ( got_picture )
                        {
-                               if ( ( image_size = allocate_buffer( frame_properties, codec_context, buffer, format, width, height ) ) )
+                               if ( ( image_size = allocate_buffer( frame, codec_context, buffer, format, width, height ) ) )
                                {
                                        // Workaround 1088 encodings missing cropping info.
                                        if ( *height == 1088 && mlt_profile_dar( mlt_service_profile( MLT_PRODUCER_SERVICE( producer ) ) ) == 16.0/9.0 )
index 4477b156d9d1399c6596f0d1fda93a130fedc68c..0c230fdd9ae2f5825ef0a4e170b5c6fd3b06f6aa 100644 (file)
@@ -94,22 +94,6 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
        
                mlt_log_debug( NULL, "[filter crop] %s %dx%d -> %dx%d\n", mlt_image_format_name(*format),
                                 *width, *height, owidth, oheight);
-               switch ( *format )
-               {
-                       case mlt_image_yuv422:
-                               bpp = 2;
-                               break;
-                       case mlt_image_rgb24:
-                               bpp = 3;
-                               break;
-                       case mlt_image_rgb24a:
-                       case mlt_image_opengl:
-                               bpp = 4;
-                               break;
-                       default:
-                               // XXX: we only know how to crop packed formats
-                               return 1;
-               }
 
                // Provides a manual override for misreported field order
                if ( mlt_properties_get( properties, "meta.top_field_first" ) )
@@ -122,14 +106,15 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
                        mlt_properties_set_int( properties, "top_field_first", !mlt_properties_get_int( properties, "top_field_first" ) );
                
                // Create the output image
-               uint8_t *output = mlt_pool_alloc( owidth * ( oheight + 1 ) * bpp );
+               int size = mlt_image_format_size( *format, owidth, oheight, &bpp );
+               uint8_t *output = mlt_pool_alloc( size );
                if ( output )
                {
                        // Call the generic resize
                        crop( *image, output, bpp, *width, *height, left, right, top, bottom );
 
                        // Now update the frame
-                       mlt_frame_set_image( this, output, owidth * ( oheight + 1 ) * bpp, mlt_pool_release );
+                       mlt_frame_set_image( this, output, size, mlt_pool_release );
                        *image = output;
                }
 
index bb61e849fce8f2fb3f33d1b872c982a9105128f3..9f87f6f91108dabfb139ae3f87b5c4e1224ad279 100644 (file)
@@ -269,23 +269,7 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
                // Get the requested scale operation
                char *op = mlt_properties_get( MLT_FILTER_PROPERTIES( filter ), "scale" );
                int bpp;
-
-               switch ( *format )
-               {
-                       case mlt_image_yuv422:
-                               bpp = 2;
-                               break;
-                       case mlt_image_rgb24:
-                               bpp = 3;
-                               break;
-                       case mlt_image_rgb24a:
-                       case mlt_image_opengl:
-                               bpp = 4;
-                               break;
-                       default:
-                               // XXX: we only know how to resize packed formats
-                               return 1;
-               }
+               int size = mlt_image_format_size( *format, owidth, oheight, &bpp );
 
                // Provides a manual override for misreported field order
                if ( mlt_properties_get( properties, "meta.top_field_first" ) )
@@ -297,12 +281,11 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
                     mlt_properties_get_int( properties, "progressive" ) == 0 )
                {
                        // Get the input image, width and height
-                       int size = owidth * oheight * bpp;
                        uint8_t *new_image = mlt_pool_alloc( size );
                        mlt_frame_set_image( this, new_image, size, mlt_pool_release );
                        uint8_t *ptr = new_image + owidth * bpp;
                        memcpy( new_image, *image, owidth * bpp );
-                       memcpy( ptr, *image, size - owidth * bpp );
+                       memcpy( ptr, *image, owidth * ( oheight - 1 ) * bpp );
                        *image = new_image;
                        
                        // Set the normalised field order
index 03c41a2b6404595c92e345292e54a41444941cf7..60d999463a2f77edde238f4f8e6feb93bf3c1553 100644 (file)
@@ -130,23 +130,8 @@ static int producer_get_image( mlt_frame frame, uint8_t **buffer, mlt_image_form
                int i = *width * *height + 1;
                int bpp;
 
-               switch ( *format )
-               {
-                       case mlt_image_rgb24:
-                               bpp = 3;
-                               break;
-                       case mlt_image_rgb24a:
-                       case mlt_image_opengl:
-                               bpp = 4;
-                               break;
-                       default:
-                               bpp = 2;
-                               *format = mlt_image_yuv422;
-                               break;
-               }
-
                // Allocate the image
-               size = *width * *height * bpp;
+               size = mlt_image_format_size( *format, *width, *height, &bpp );
                uint8_t *p = image = mlt_pool_alloc( size );
 
                // Update the producer
index e4aa1b8cb4d133be485e0808d019534fe1d53f98..e7b574cadd51e0f51cad6b82a3e56bfd532f3d6e 100644 (file)
@@ -47,13 +47,16 @@ static int filter_scale( mlt_frame this, uint8_t **image, mlt_image_format *form
        else if ( strcmp( interps, "hyper" ) == 0 || strcmp( interps, "bicubic" ) == 0 )
                interp = PIXOPS_INTERP_HYPER;
 
+       int bpp;
+       int size = mlt_image_format_size( *format, owidth, oheight, &bpp );
+
        // Carry out the rescaling
        switch ( *format )
        {
        case mlt_image_yuv422:
        {
                // Create the output image
-               uint8_t *output = mlt_pool_alloc( owidth * ( oheight + 1 ) * 2 );
+               uint8_t *output = mlt_pool_alloc( size );
 
                // Calculate strides
                int istride = iwidth * 2;
@@ -62,7 +65,7 @@ static int filter_scale( mlt_frame this, uint8_t **image, mlt_image_format *form
                yuv422_scale_simple( output, owidth, oheight, ostride, *image, iwidth, iheight, istride, interp );
                
                // Now update the frame
-               mlt_frame_set_image( this, output, owidth * ( oheight + 1 ) * 2, mlt_pool_release );
+               mlt_frame_set_image( this, output, size, mlt_pool_release );
 
                // Return the output
                *image = output;
@@ -72,10 +75,8 @@ static int filter_scale( mlt_frame this, uint8_t **image, mlt_image_format *form
        case mlt_image_rgb24a:
        case mlt_image_opengl:
        {
-               int bpp = ( *format == mlt_image_rgb24 ? 3 : 4 );
-
                // Create the output image
-               uint8_t *output = mlt_pool_alloc( owidth * ( oheight + 1 ) * bpp );
+               uint8_t *output = mlt_pool_alloc( size );
 
                if ( strcmp( interps, "none" ) && ( iwidth != owidth || iheight != oheight ) )
                {
@@ -107,7 +108,7 @@ static int filter_scale( mlt_frame this, uint8_t **image, mlt_image_format *form
                        g_object_unref( scaled );
 
                        // Now update the frame
-                       mlt_frame_set_image( this, output, owidth * ( oheight + 1 ) * bpp, mlt_pool_release );
+                       mlt_frame_set_image( this, output, size, mlt_pool_release );
        
                        // Return the output
                        *image = output;
index 28feb895975ab53beae1022fe6b175a9a455c0cd..3f9dce7beac1e6f2eaba71911f8608e381d3b271 100755 (executable)
@@ -76,27 +76,9 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
                uint8_t *buffer = NULL;
                int error = mlt_frame_get_image( freeze_frame, &buffer, format, width, height, 1 );
 
-               int size = 0;
-               switch ( *format )
-               {
-                       case mlt_image_yuv420p:
-                               size = *width * 3 * ( *height + 1 ) / 2;
-                               break;
-                       case mlt_image_rgb24:
-                               size = *width * ( *height + 1 ) * 3;
-                               break;
-                       case mlt_image_rgb24a:
-                       case mlt_image_opengl:
-                               size = *width * ( *height + 1 ) * 4;
-                               break;
-                       default:
-                               *format = mlt_image_yuv422;
-                               size = *width * ( *height + 1 ) * 2;
-                               break;
-               }
-
                // Copy it to current frame
-               uint8_t *image_copy = mlt_pool_alloc( size );
+               int size = mlt_image_format_size( *format, *width, *height, NULL );
+               uint8_t *image_copy = mlt_pool_alloc( size );
                memcpy( image_copy, buffer, size );
                *image = image_copy;
                mlt_frame_set_image( this, *image, size, mlt_pool_release );
index 6ec1740a1bf6d4f661aa67f5fe6502addcf97803..1e3bba06742893ce30d930d08be4d4b22642034f 100644 (file)
@@ -85,26 +85,7 @@ static int framebuffer_get_image( mlt_frame this, uint8_t **image, mlt_image_for
        // Determine output buffer size
        *width = mlt_properties_get_int( frame_properties, "width" );
        *height = mlt_properties_get_int( frame_properties, "height" );
-       
-       int size;
-       switch ( *format )
-       {
-               case mlt_image_yuv420p:
-                       size = *width * 3 * ( *height + 1 ) / 2;
-                       break;
-               case mlt_image_rgb24:
-                       size = *width * ( *height + 1 ) * 3;
-                       break;
-               case mlt_image_rgb24a:
-               case mlt_image_opengl:
-                       size = *width * ( *height + 1 ) * 4;
-                       break;
-               default:
-                       *format = mlt_image_yuv422;
-                       size = *width * ( *height + 1 ) * 2;
-                       break;
-       }
-       
+       int size = mlt_image_format_size( *format, *width, *height, NULL );
 
        // Get output buffer
        int buffersize = 0;