Beispiel #1
0
// returns set_lumage_transfer result
static int av_convert_image( uint8_t *out, uint8_t *in, int out_fmt, int in_fmt,
	int width, int height, int src_colorspace, int dst_colorspace, int use_full_range )
{
	AVPicture input;
	AVPicture output;
	int flags = SWS_BICUBIC | SWS_ACCURATE_RND;
	int error = -1;

	if ( out_fmt == AV_PIX_FMT_YUYV422 )
		flags |= SWS_FULL_CHR_H_INP;
	else
		flags |= SWS_FULL_CHR_H_INT;

	avpicture_fill( &input, in, in_fmt, width, height );
	avpicture_fill( &output, out, out_fmt, width, height );
	struct SwsContext *context = sws_getContext( width, height, in_fmt,
		width, height, out_fmt, flags, NULL, NULL, NULL);
	if ( context )
	{
		// libswscale wants the RGB colorspace to be SWS_CS_DEFAULT, which is = SWS_CS_ITU601.
		if ( out_fmt == AV_PIX_FMT_RGB24 || out_fmt == AV_PIX_FMT_RGBA )
			dst_colorspace = 601;
		error = set_luma_transfer( context, src_colorspace, dst_colorspace, use_full_range );
		sws_scale( context, (const uint8_t* const*) input.data, input.linesize, 0, height,
			output.data, output.linesize);
		sws_freeContext( context );
	}
	return error;
}
Beispiel #2
0
static void av_convert_image( uint8_t *out, uint8_t *in, int out_fmt, int in_fmt,
	int width, int height, int colorspace, int use_full_range )
{
	AVPicture input;
	AVPicture output;
	int flags = SWS_BICUBIC | SWS_ACCURATE_RND;

	if ( out_fmt == PIX_FMT_YUYV422 )
		flags |= SWS_FULL_CHR_H_INP;
	else
		flags |= SWS_FULL_CHR_H_INT;
#ifdef USE_MMX
	flags |= SWS_CPU_CAPS_MMX;
#endif
#ifdef USE_SSE
	flags |= SWS_CPU_CAPS_MMX2;
#endif

	avpicture_fill( &input, in, in_fmt, width, height );
	avpicture_fill( &output, out, out_fmt, width, height );
	struct SwsContext *context = sws_getContext( width, height, in_fmt,
		width, height, out_fmt, flags, NULL, NULL, NULL);
	if ( context )
	{
		set_luma_transfer( context, colorspace, use_full_range );
		sws_scale( context, (const uint8_t* const*) input.data, input.linesize, 0, height,
			output.data, output.linesize);
		sws_freeContext( context );
	}
}