- vout_thread_t *p_vout = (vout_thread_t *)p_this;
- int64_t i_aspect_num, i_aspect_den;
- unsigned int i_width, i_height;
-
- (void)oldval; (void)p_data;
-
- /* Restore defaults */
- p_vout->p->fmt_in.i_x_offset = p_vout->p->fmt_render.i_x_offset;
- p_vout->p->fmt_in.i_visible_width = p_vout->p->fmt_render.i_visible_width;
- p_vout->p->fmt_in.i_y_offset = p_vout->p->fmt_render.i_y_offset;
- p_vout->p->fmt_in.i_visible_height = p_vout->p->fmt_render.i_visible_height;
-
- if( !strcmp( psz_cmd, "crop" ) )
- {
- char *psz_end = NULL, *psz_parser = strchr( newval.psz_string, ':' );
- if( psz_parser )
- {
- /* We're using the 3:4 syntax */
- i_aspect_num = strtol( newval.psz_string, &psz_end, 10 );
- if( psz_end == newval.psz_string || !i_aspect_num ) goto crop_end;
-
- i_aspect_den = strtol( ++psz_parser, &psz_end, 10 );
- if( psz_end == psz_parser || !i_aspect_den ) goto crop_end;
-
- i_width = p_vout->p->fmt_in.i_sar_den*p_vout->p->fmt_render.i_visible_height *
- i_aspect_num / i_aspect_den / p_vout->p->fmt_in.i_sar_num;
- i_height = p_vout->p->fmt_render.i_visible_width*p_vout->p->fmt_in.i_sar_num *
- i_aspect_den / i_aspect_num / p_vout->p->fmt_in.i_sar_den;
-
- if( i_width < p_vout->p->fmt_render.i_visible_width )
- {
- p_vout->p->fmt_in.i_x_offset = p_vout->p->fmt_render.i_x_offset +
- (p_vout->p->fmt_render.i_visible_width - i_width) / 2;
- p_vout->p->fmt_in.i_visible_width = i_width;
- }
- else
- {
- p_vout->p->fmt_in.i_y_offset = p_vout->p->fmt_render.i_y_offset +
- (p_vout->p->fmt_render.i_visible_height - i_height) / 2;
- p_vout->p->fmt_in.i_visible_height = i_height;
- }
- }
- else
- {
- psz_parser = strchr( newval.psz_string, 'x' );
- if( psz_parser )
- {
- /* Maybe we're using the <width>x<height>+<left>+<top> syntax */
- unsigned int i_crop_width, i_crop_height, i_crop_top, i_crop_left;
-
- i_crop_width = strtol( newval.psz_string, &psz_end, 10 );
- if( psz_end != psz_parser ) goto crop_end;
-
- psz_parser = strchr( ++psz_end, '+' );
- i_crop_height = strtol( psz_end, &psz_end, 10 );
- if( psz_end != psz_parser ) goto crop_end;
-
- psz_parser = strchr( ++psz_end, '+' );
- i_crop_left = strtol( psz_end, &psz_end, 10 );
- if( psz_end != psz_parser ) goto crop_end;
-
- psz_end++;
- i_crop_top = strtol( psz_end, &psz_end, 10 );
- if( *psz_end != '\0' ) goto crop_end;
-
- if( i_crop_top + i_crop_height >= p_vout->p->fmt_render.i_visible_height ||
- i_crop_left + i_crop_width >= p_vout->p->fmt_render.i_visible_width )
- {
- msg_Err( p_vout, "Unable to crop over picture boundaries");
- return VLC_EGENERIC;
- }
-
- i_width = i_crop_width;
- p_vout->p->fmt_in.i_visible_width = i_width;
-
- i_height = i_crop_height;
- p_vout->p->fmt_in.i_visible_height = i_height;
-
- p_vout->p->fmt_in.i_x_offset = i_crop_left;
- p_vout->p->fmt_in.i_y_offset = i_crop_top;
- }
- else
- {
- /* Maybe we're using the <left>+<top>+<right>+<bottom> syntax */
- unsigned int i_crop_top, i_crop_left, i_crop_bottom, i_crop_right;
-
- psz_parser = strchr( newval.psz_string, '+' );
- i_crop_left = strtol( newval.psz_string, &psz_end, 10 );
- if( psz_end != psz_parser ) goto crop_end;
-
- psz_parser = strchr( ++psz_end, '+' );
- i_crop_top = strtol( psz_end, &psz_end, 10 );
- if( psz_end != psz_parser ) goto crop_end;
-
- psz_parser = strchr( ++psz_end, '+' );
- i_crop_right = strtol( psz_end, &psz_end, 10 );
- if( psz_end != psz_parser ) goto crop_end;
-
- psz_end++;
- i_crop_bottom = strtol( psz_end, &psz_end, 10 );
- if( *psz_end != '\0' ) goto crop_end;
-
- if( i_crop_top + i_crop_bottom >= p_vout->p->fmt_render.i_visible_height ||
- i_crop_right + i_crop_left >= p_vout->p->fmt_render.i_visible_width )
- {
- msg_Err( p_vout, "Unable to crop over picture boundaries" );
- return VLC_EGENERIC;
- }
-
- i_width = p_vout->p->fmt_render.i_visible_width
- - i_crop_left - i_crop_right;
- p_vout->p->fmt_in.i_visible_width = i_width;
-
- i_height = p_vout->p->fmt_render.i_visible_height
- - i_crop_top - i_crop_bottom;
- p_vout->p->fmt_in.i_visible_height = i_height;
-
- p_vout->p->fmt_in.i_x_offset = i_crop_left;
- p_vout->p->fmt_in.i_y_offset = i_crop_top;
- }
- }
+ vout_thread_t *vout = (vout_thread_t *)object;
+ VLC_UNUSED(cmd); VLC_UNUSED(oldval); VLC_UNUSED(data);
+ unsigned num, den;
+ unsigned y, x;
+ unsigned width, height;
+ unsigned left, top, right, bottom;
+
+ if (sscanf(newval.psz_string, "%u:%u", &num, &den) == 2) {
+ vout_ControlChangeCropRatio(vout, num, den);
+ } else if (sscanf(newval.psz_string, "%ux%u+%u+%u",
+ &width, &height, &x, &y) == 4) {
+ vout_ControlChangeCropWindow(vout, x, y, width, height);
+ } else if (sscanf(newval.psz_string, "%u+%u+%u+%u",
+ &left, &top, &right, &bottom) == 4) {
+ vout_ControlChangeCropBorder(vout, left, top, right, bottom);
+ } else if (*newval.psz_string == '\0') {
+ vout_ControlChangeCropRatio(vout, 0, 0);
+ } else {
+ msg_Err(object, "Unknown crop format (%s)", newval.psz_string);