]> git.sesse.net Git - mlt/commitdiff
Add conversion to profile colorspace.
authorDan Dennedy <dan@dennedy.org>
Tue, 14 Sep 2010 05:38:40 +0000 (22:38 -0700)
committerDan Dennedy <dan@dennedy.org>
Sun, 26 Sep 2010 22:20:15 +0000 (15:20 -0700)
src/modules/avformat/filter_avcolour_space.c

index 434c659fc2ca92dcfae3ad06e8f181cf0f4048d5..d3a0d5439ccf341f8bbc63ff7147b220a7f470e4 100644 (file)
@@ -21,6 +21,7 @@
 #include <framework/mlt_filter.h>
 #include <framework/mlt_frame.h>
 #include <framework/mlt_log.h>
+#include <framework/mlt_profile.h>
 
 // ffmpeg Header files
 #include <avformat.h>
@@ -84,10 +85,21 @@ static void set_luma_transfer( struct SwsContext *context, int colorspace, int n
                // Don't change these from defaults unless explicitly told to.
                if ( no_scale )
                        range = 1;
-               if ( colorspace == 709 )
-                       coefficients = sws_getCoefficients( SWS_CS_ITU709 );
-               else if ( colorspace == 240 )
+               switch ( colorspace )
+               {
+               case 170:
+               case 470:
+               case 601:
+               case 624:
+                       coefficients = sws_getCoefficients( SWS_CS_ITU601 );
+                       break;
+               case 240:
                        coefficients = sws_getCoefficients( SWS_CS_SMPTE240M );
+                       break;
+               case 709:
+                       coefficients = sws_getCoefficients( SWS_CS_ITU709 );
+                       break;
+               }
                sws_setColorspaceDetails( context, coefficients, range, coefficients, range,
                        brightness, contrast, saturation );
        }
@@ -224,12 +236,48 @@ static int convert_image( mlt_frame frame, uint8_t **image, mlt_image_format *fo
        return error;
 }
 
+static int get_image( mlt_frame frame, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable )
+{
+       int error = 0;
+       mlt_profile profile = (mlt_profile) mlt_frame_pop_get_image( frame );
+       mlt_properties properties = MLT_FRAME_PROPERTIES(frame);
+       mlt_image_format format_from = *format;
+       mlt_image_format format_to = mlt_image_rgb24;
+       
+       error = mlt_frame_get_image( frame, image, format, width, height, writable );
+       
+       if ( !error && *format == mlt_image_yuv422 && profile->colorspace > 0 &&
+            mlt_properties_get_int( properties, "colorspace" ) != profile->colorspace )
+       {
+               mlt_log_debug( NULL, "[filter avcolor_space] colorspace %d -> %d\n",
+                       mlt_properties_get_int( properties, "colorspace" ), profile->colorspace );
+               
+               // Convert to RGB using frame's colorspace
+               error = convert_image( frame, image, &format_from, format_to );
+
+               // Convert to YUV using profile's colorspace
+               if ( !error )
+               {
+                       *image = mlt_properties_get_data( properties, "image", NULL );
+                       format_from = mlt_image_rgb24;
+                       format_to = *format;
+                       mlt_properties_set_int( properties, "colorspace", profile->colorspace );
+                       error = convert_image( frame, image, &format_from, format_to );
+                       *image = mlt_properties_get_data( properties, "image", NULL );
+               }
+       }
+       
+       return error;
+}
+
 /** Filter processing.
 */
 
-static mlt_frame filter_process( mlt_filter this, mlt_frame frame )
+static mlt_frame filter_process( mlt_filter filter, mlt_frame frame )
 {
        frame->convert_image = convert_image;
+       mlt_frame_push_get_image( frame, mlt_service_profile( MLT_FILTER_SERVICE( filter ) ) );
+       mlt_frame_push_get_image( frame, get_image );
        return frame;
 }