+ var_Create( p_vout, "align", VLC_VAR_INTEGER );
+
+ fmt.i_width = fmt.i_visible_width = p_vout->render.i_width;
+ fmt.i_height = fmt.i_visible_height = p_vout->render.i_height;
+ fmt.i_x_offset = fmt.i_y_offset = 0;
+ fmt.i_chroma = p_vout->render.i_chroma;
+ fmt.i_aspect = p_vout->render.i_aspect;
+ fmt.i_sar_num = p_vout->render.i_aspect * fmt.i_height / fmt.i_width;
+ fmt.i_sar_den = VOUT_ASPECT_FACTOR;
+
+ w1 = p_vout->output.i_width / p_vout->p_sys->i_col;
+ w1 &= ~1;
+ h1 = w1 * VOUT_ASPECT_FACTOR / i_aspect&~1;
+ h1 &= ~1;
+
+ h2 = p_vout->output.i_height / p_vout->p_sys->i_row&~1;
+ h2 &= ~1;
+ w2 = h2 * i_aspect / VOUT_ASPECT_FACTOR&~1;
+ w2 &= ~1;
+
+ if ( h1 * p_vout->p_sys->i_row < p_vout->output.i_height )
+ {
+ unsigned int i_tmp;
+ i_target_width = w2;
+ i_target_height = h2;
+ i_vstart = 0;
+ i_vend = p_vout->output.i_height;
+ i_tmp = i_target_width * p_vout->p_sys->i_col;
+ while( i_tmp < p_vout->output.i_width ) i_tmp += p_vout->p_sys->i_col;
+ i_hstart = (( i_tmp - p_vout->output.i_width ) / 2)&~1;
+ i_hstart_rounded = ( ( i_tmp - p_vout->output.i_width ) % 2 ) ||
+ ( ( ( i_tmp - p_vout->output.i_width ) / 2 ) & 1 );
+ i_hend = i_hstart + p_vout->output.i_width;
+ }
+ else
+ {
+ unsigned int i_tmp;
+ i_target_height = h1;
+ i_target_width = w1;
+ i_hstart = 0;
+ i_hend = p_vout->output.i_width;
+ i_tmp = i_target_height * p_vout->p_sys->i_row;
+ while( i_tmp < p_vout->output.i_height ) i_tmp += p_vout->p_sys->i_row;
+ i_vstart = ( ( i_tmp - p_vout->output.i_height ) / 2 ) & ~1;
+ i_vstart_rounded = ( ( i_tmp - p_vout->output.i_height ) % 2 ) ||
+ ( ( ( i_tmp - p_vout->output.i_height ) / 2 ) & 1 );
+ i_vend = i_vstart + p_vout->output.i_height;
+ }
+ msg_Dbg( p_vout, "target resolution %dx%d", i_target_width, i_target_height );