#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>
// 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 );
}
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;
}