+/* ETSI 300 743 [7.2.1] */
+static void decode_display_definition( decoder_t *p_dec, bs_t *s )
+{
+ decoder_sys_t *p_sys = p_dec->p_sys;
+ uint16_t i_segment_length;
+ uint16_t i_processed_length = 40;
+ dvbsub_display_t *p_display;
+ dvbsub_display_t *p_old = p_sys->p_display;
+ int i_version;
+
+ i_segment_length = bs_read( s, 16 );
+ i_version = bs_read( s, 4 );
+
+ /* Check version number */
+ if( p_old && ( p_old->i_version == i_version ) )
+ {
+ /* The definition did not change */
+ bs_skip( s, 8*i_segment_length - 4 );
+ return;
+ }
+
+#ifdef DEBUG_DVBSUB
+ msg_Dbg( p_dec, "new display definition: %i", i_version );
+#endif
+ p_display = malloc( sizeof(dvbsub_display_t) );
+ if( p_display )
+ {
+ /* We don't have this version of the display definition: Parse it */
+ p_display->i_version = i_version;
+ p_display->b_windowed = bs_read( s, 1 );
+ bs_skip( s, 3 ); /* Reserved bits */
+ p_display->i_width = bs_read( s, 16 )+1;
+ p_display->i_height = bs_read( s, 16 )+1;
+
+ if( p_display->b_windowed )
+ {
+#ifdef DEBUG_DVBSUB
+ msg_Dbg( p_dec, "display definition with offsets (windowed)" );
+#endif
+ /* Coordinates are measured from the top left corner */
+ p_display->i_x = bs_read( s, 16 );
+ p_display->i_max_x = bs_read( s, 16 );
+ p_display->i_y = bs_read( s, 16 );
+ p_display->i_max_y = bs_read( s, 16 );
+ i_processed_length += 64;
+ }
+ }
+
+ p_sys->p_display = p_display;
+ free( p_old );
+
+ if( i_processed_length != i_segment_length*8 )
+ {
+ msg_Err( p_dec, "processed length %d != segment length %d",
+ i_processed_length, i_segment_length );
+ }
+
+#ifdef DEBUG_DVBSUB
+ msg_Dbg( p_dec, "version: %d, width: %d, height: %d",
+ p_display->i_version, p_display->i_width, p_display->i_height );
+ if( p_display->b_windowed )
+ msg_Dbg( p_dec, "xmin: %d, xmax: %d, ymin: %d, ymax: %d",
+ p_display->i_x, p_display->i_max_x, p_display->i_y, p_display->i_max_y );
+#endif
+}
+