235
235
"input clip height not divisible by 4 (%dx%d)\n", vi->width, vi->height )
236
236
FAIL_IF_ERROR( (opt->output_csp == X264_CSP_I420 || info->interlaced) && (vi->height&1),
237
237
"input clip height not divisible by 2 (%dx%d)\n", vi->width, vi->height )
238
const char *arg_name[2] = { NULL, "interlaced" };
239
AVS_Value arg_arr[2] = { res, avs_new_value_bool( info->interlaced ) };
240
238
char conv_func[14] = { "ConvertTo" };
241
239
strcat( conv_func, csp );
242
AVS_Value res2 = h->func.avs_invoke( h->env, conv_func, avs_new_value_array( arg_arr, 2 ), arg_name );
242
/* if doing a rgb <-> yuv conversion then range is handled via 'matrix'. though it's only supported in 2.56+ */
243
if( avs_version >= 2.56f && ((opt->output_csp == X264_CSP_RGB && avs_is_yuv( vi )) || (opt->output_csp != X264_CSP_RGB && avs_is_rgb( vi ))) )
245
// if converting from yuv, then we specify the matrix for the input, otherwise use the output's.
246
int use_pc_matrix = avs_is_yuv( vi ) ? opt->input_range == RANGE_PC : opt->output_range == RANGE_PC;
247
strcpy( matrix, use_pc_matrix ? "PC." : "Rec" );
248
strcat( matrix, "601" ); /* FIXME: use correct coefficients */
250
// notification that the input range has changed to the desired one
251
opt->input_range = opt->output_range;
253
const char *arg_name[] = { NULL, "interlaced", "matrix" };
254
AVS_Value arg_arr[] = { res, avs_new_value_bool( info->interlaced ), avs_new_value_string( matrix ) };
255
AVS_Value res2 = h->func.avs_invoke( h->env, conv_func, avs_new_value_array( arg_arr, arg_count ), arg_name );
243
256
FAIL_IF_ERROR( avs_is_error( res2 ), "couldn't convert input clip to %s\n", csp )
244
257
res = update_clip( h, &vi, res2, res );
259
/* if swscale is not available, change the range if necessary. This only applies to YUV-based CSPs however */
260
if( avs_is_yuv( vi ) && opt->output_range != RANGE_AUTO && ((opt->input_range == RANGE_PC) != opt->output_range) )
262
const char *levels = opt->output_range ? "TV->PC" : "PC->TV";
263
x264_cli_log( "avs", X264_LOG_WARNING, "performing %s conversion\n", levels );
264
AVS_Value arg_arr[] = { res, avs_new_value_string( levels ) };
265
const char *arg_name[] = { NULL, "levels" };
266
AVS_Value res2 = h->func.avs_invoke( h->env, "ColorYUV", avs_new_value_array( arg_arr, 2 ), arg_name );
267
FAIL_IF_ERROR( avs_is_error( res2 ), "couldn't convert range: %s\n", avs_as_error( res2 ) )
268
res = update_clip( h, &vi, res2, res );
269
// notification that the input range has changed to the desired one
270
opt->input_range = opt->output_range;
247
273
h->func.avs_release_value( res );