+/*****************************************************************************
+ * vout_RegisterOSDChannel: register an OSD channel
+ *****************************************************************************
+ * This function affects an ID to an OSD channel
+ *****************************************************************************/
+int vout_RegisterOSDChannel( vout_thread_t *p_vout )
+{
+ msg_Dbg( p_vout, "Registering OSD channel, ID: %i",
+ p_vout->i_channel_count + 1 );
+ return ++p_vout->i_channel_count;
+}
+
+/*****************************************************************************
+ * vout_ClearOSDChannel: clear an OSD channel
+ *****************************************************************************
+ * This function destroys the subpictures which belong to the OSD channel
+ * corresponding to i_channel_id.
+ *****************************************************************************/
+void vout_ClearOSDChannel( vout_thread_t *p_vout, int i_channel )
+{
+ int i_subpic; /* subpicture index */
+ subpicture_t * p_subpic = NULL; /* first free subpicture */
+
+ if( i_channel == DEFAULT_CHAN )
+ {
+ if( p_vout->p_default_channel != NULL )
+ {
+ vout_DestroySubPicture( p_vout, p_vout->p_default_channel );
+ }
+ p_vout->p_default_channel = NULL;
+ return;
+ }
+
+ vlc_mutex_lock( &p_vout->subpicture_lock );
+
+ for( i_subpic = 0; i_subpic < VOUT_MAX_SUBPICTURES; i_subpic++ )
+ {
+ p_subpic = &p_vout->p_subpicture[i_subpic];
+ if( p_subpic->i_status == FREE_SUBPICTURE
+ || ( p_subpic->i_status != RESERVED_SUBPICTURE
+ && p_subpic->i_status != READY_SUBPICTURE ) )
+ {
+ continue;
+ }
+
+ if( p_subpic->i_channel == i_channel )
+ {
+ while( p_subpic->p_region )
+ {
+ subpicture_region_t *p_region = p_subpic->p_region;
+ p_subpic->p_region = p_region->p_next;
+ spu_DestroyRegion( p_vout, p_region );
+ }
+
+ if( p_subpic->pf_destroy )
+ {
+ p_subpic->pf_destroy( p_subpic );
+ }
+ p_subpic->i_status = FREE_SUBPICTURE;
+ }
+ }
+
+ vlc_mutex_unlock( &p_vout->subpicture_lock );
+}
+
+/*****************************************************************************
+ * UpdateSPU: update subpicture settings
+ *****************************************************************************
+ * This function is called from CropCallback and at initialization time, to
+ * retrieve crop information from the input.
+ *****************************************************************************/
+static void UpdateSPU( vout_thread_t *p_vout, vlc_object_t *p_object )
+{
+ vlc_value_t val;
+
+ p_vout->b_force_alpha = VLC_FALSE;
+ p_vout->b_force_crop = VLC_FALSE;
+
+ if( var_Get( p_object, "highlight", &val ) || !val.b_bool ) return;
+
+ p_vout->b_force_crop = VLC_TRUE;
+ var_Get( p_object, "x-start", &val );
+ p_vout->i_crop_x = val.i_int;
+ var_Get( p_object, "y-start", &val );
+ p_vout->i_crop_y = val.i_int;
+ var_Get( p_object, "x-end", &val );
+ p_vout->i_crop_width = val.i_int - p_vout->i_crop_x;
+ var_Get( p_object, "y-end", &val );
+ p_vout->i_crop_height = val.i_int - p_vout->i_crop_y;
+
+#if 0
+ if( var_Get( p_object, "color", &val ) == VLC_SUCCESS )
+ {
+ int i;
+ for( i = 0; i < 4; i++ )
+ {
+ p_vout->pi_color[i] = ((uint8_t *)val.p_address)[i];
+ }
+ }
+#endif
+
+ if( var_Get( p_object, "contrast", &val ) == VLC_SUCCESS )
+ {
+ int i;
+ for( i = 0; i < 4; i++ )
+ {
+ p_vout->pi_alpha[i] = ((uint8_t *)val.p_address)[i];
+ p_vout->pi_alpha[i] = p_vout->pi_alpha[i] == 0xf ?
+ 0xff : p_vout->pi_alpha[i] << 4;
+ }
+ p_vout->b_force_alpha = VLC_TRUE;
+ }
+
+ msg_Dbg( p_vout, "crop: %i,%i,%i,%i, alpha: %i",
+ p_vout->i_crop_x, p_vout->i_crop_y,
+ p_vout->i_crop_width, p_vout->i_crop_height,
+ p_vout->b_force_alpha );
+}
+
+/*****************************************************************************
+ * CropCallback: called when the highlight properties are changed
+ *****************************************************************************
+ * This callback is called from the input thread when we need cropping
+ *****************************************************************************/
+static int CropCallback( vlc_object_t *p_object, char const *psz_var,
+ vlc_value_t oldval, vlc_value_t newval, void *p_data )
+{
+ UpdateSPU( (vout_thread_t *)p_data, p_object );
+ return VLC_SUCCESS;
+}
+
+/*****************************************************************************
+ * Buffers allocation callbacks for the filters
+ *****************************************************************************/
+static subpicture_t *spu_new_buffer( filter_t *p_filter )
+{
+ vout_thread_t *p_vout = (vout_thread_t *)p_filter->p_owner;
+ subpicture_t *p_spu;
+
+ p_spu = vout_CreateSubPicture( p_vout, !DEFAULT_CHAN, MEMORY_SUBPICTURE );
+ return p_spu;
+}
+
+static void spu_del_buffer( filter_t *p_filter, subpicture_t *p_spu )
+{
+ vout_thread_t *p_vout = (vout_thread_t *)p_filter->p_owner;
+ vout_DestroySubPicture( p_vout, p_spu );
+}