[vlc-devel] [PATCH] Correct scroll effect and clearing in TV+Graphics decoder

Kym Greenshields kym.greenshields at gmail.com
Tue Aug 2 21:55:41 CEST 2011


---
 modules/codec/cdg.c |   67 +++++++++++++++++++++++++++++++++++----------------
 1 files changed, 46 insertions(+), 21 deletions(-)

diff --git a/modules/codec/cdg.c b/modules/codec/cdg.c
index 322600a..f09c3f1 100644
--- a/modules/codec/cdg.c
+++ b/modules/codec/cdg.c
@@ -37,12 +37,12 @@
  *****************************************************************************/
 
 /* The screen size */
-#define CDG_SCREEN_WIDTH 300u
-#define CDG_SCREEN_HEIGHT 216u
+#define CDG_SCREEN_WIDTH 300
+#define CDG_SCREEN_HEIGHT 216
 
 /* The border of the screen size */
-#define CDG_SCREEN_BORDER_WIDTH 6u
-#define CDG_SCREEN_BORDER_HEIGHT 12u
+#define CDG_SCREEN_BORDER_WIDTH 6
+#define CDG_SCREEN_BORDER_HEIGHT 12
 
 /* The display part */
 #define CDG_DISPLAY_WIDTH  (CDG_SCREEN_WIDTH-2*CDG_SCREEN_BORDER_WIDTH)
@@ -50,6 +50,9 @@
 
 #define CDG_SCREEN_PITCH CDG_SCREEN_WIDTH
 
+#define CDG_TILES_WIDE		50
+#define CDG_TILES_HIGH		18
+
 struct decoder_sys_t
 {
     uint8_t  color[16][3];
@@ -59,6 +62,7 @@ struct decoder_sys_t
     uint8_t  *p_screen;
 
     int      i_packet;
+	int		 i_border_color;
 };
 
 #define CDG_PACKET_SIZE 24u
@@ -203,21 +207,33 @@ static int DecodeMemoryPreset( decoder_sys_t *p_cdg, const uint8_t *p_data )
 #endif
     /* if i_repeat > 0 we could ignore it if we have a reliable stream */
     ScreenFill( p_cdg, 0, 0, CDG_SCREEN_WIDTH, CDG_SCREEN_HEIGHT, i_color );
+	
+	/* Only update the border if it differs from this one */
+	if ( p_cdg->i_border_color != i_color ) {
+		ScreenFill( p_cdg,   0,   0,
+                CDG_SCREEN_WIDTH, CDG_SCREEN_BORDER_HEIGHT, p_cdg->i_border_color );
+		ScreenFill( p_cdg,   0, CDG_SCREEN_HEIGHT-CDG_SCREEN_BORDER_HEIGHT,
+                CDG_SCREEN_WIDTH, CDG_SCREEN_BORDER_HEIGHT, p_cdg->i_border_color );
+		ScreenFill( p_cdg,   0, CDG_SCREEN_BORDER_HEIGHT,
+                CDG_SCREEN_BORDER_WIDTH, CDG_SCREEN_HEIGHT-CDG_SCREEN_BORDER_HEIGHT, p_cdg->i_border_color );
+		ScreenFill( p_cdg,   CDG_SCREEN_WIDTH-CDG_SCREEN_BORDER_WIDTH, CDG_SCREEN_BORDER_HEIGHT,
+                CDG_SCREEN_BORDER_WIDTH, CDG_SCREEN_HEIGHT-CDG_SCREEN_BORDER_HEIGHT, p_cdg->i_border_color );
+    }
+	
+	/* As per IEC60908 - both pointers must be reset also */
+	p_cdg->i_offseth = p_cdg->i_offsetv = 0;
+	
     return 0;
 }
 static int DecodeBorderPreset( decoder_sys_t *p_cdg, const uint8_t *p_data )
 {
-    const int i_color = p_data[0]&0x0f;
-
-    /* */
-    ScreenFill( p_cdg,   0,   0,
-                CDG_SCREEN_WIDTH, CDG_SCREEN_BORDER_HEIGHT, i_color );
-    ScreenFill( p_cdg,   0, CDG_SCREEN_HEIGHT-CDG_SCREEN_BORDER_HEIGHT,
-                CDG_SCREEN_WIDTH, CDG_SCREEN_BORDER_HEIGHT, i_color );
-    ScreenFill( p_cdg,   0, CDG_SCREEN_BORDER_HEIGHT,
-                CDG_SCREEN_BORDER_WIDTH, CDG_SCREEN_HEIGHT-CDG_SCREEN_BORDER_HEIGHT, i_color );
-    ScreenFill( p_cdg,   CDG_SCREEN_WIDTH-CDG_SCREEN_BORDER_WIDTH, CDG_SCREEN_BORDER_HEIGHT,
-                CDG_SCREEN_BORDER_WIDTH, CDG_SCREEN_HEIGHT-CDG_SCREEN_BORDER_HEIGHT, i_color );
+    /*
+	 Testing has shown that only the internal border color needs
+	 to be updated at this point.
+	*/
+	
+	p_cdg->i_border_color = p_data[0] & 0x0f;
+	
     return 0;
 }
 
@@ -246,8 +262,14 @@ static int DecodeTileBlock( decoder_sys_t *p_cdg, const uint8_t *p_data, int doX
     p_color[0] = p_data[0] & 0x0f;
     p_color[1] = p_data[1] & 0x0f;
 
-    sy = (p_data[2] & 0x1f)*12;
-    sx = (p_data[3] & 0x3f)*6;
+	sy = (p_data[2] & 0x1f);
+	sx = (p_data[3] & 0x3f);
+	
+	if ( sy >= CDG_TILES_HIGH ) return 0;
+	if ( sx >= CDG_TILES_WIDE ) return 0;
+	
+    sy *= CDG_SCREEN_BORDER_HEIGHT;
+    sx *= CDG_SCREEN_BORDER_WIDTH;
 
     for( y = 0; y < 12; y++ )
     {
@@ -272,6 +294,7 @@ static int DecodeTileBlock( decoder_sys_t *p_cdg, const uint8_t *p_data, int doX
 
 static int DecodeScroll( decoder_sys_t *p_cdg, const uint8_t *p_data, int b_copy )
 {
+
     uint8_t copy[CDG_SCREEN_PITCH*CDG_SCREEN_HEIGHT];
 
     uint8_t color = p_data[0]&0x0f;
@@ -315,17 +338,17 @@ static int DecodeScroll( decoder_sys_t *p_cdg, const uint8_t *p_data, int b_copy
     ScreenFill( p_cdg, 0, 0, CDG_SCREEN_WIDTH, CDG_SCREEN_HEIGHT, color );
 
     /* Copy back */
-    for( unsigned y = 0; y < CDG_SCREEN_HEIGHT; y++ )
+    for( int y = 0; y < CDG_SCREEN_HEIGHT; y++ )
     {
         int dy = i_shiftv + y;
-        for( unsigned x = 0; x < CDG_SCREEN_WIDTH; x++ )
+        for( int x = 0; x < CDG_SCREEN_WIDTH; x++ )
         {
             int dx = i_shifth + x;
 
             if( b_copy )
             {
-                dy %= CDG_SCREEN_HEIGHT;
-                dx %= CDG_SCREEN_WIDTH;
+				dy = (dy + CDG_SCREEN_HEIGHT) % CDG_SCREEN_HEIGHT;
+				dx = (dx + CDG_SCREEN_WIDTH) % CDG_SCREEN_WIDTH;
             }
             else
             {
@@ -377,6 +400,8 @@ static int DecodePacket( decoder_sys_t *p_cdg, uint8_t *p_buffer, int i_buffer )
             /* FIXME what to do about that one ? */
             //CdgDebug( CDG_LOG_WARNING, "DecodeDefineTransparentColor not implemented\n" );
             //DecodeDefineTransparentColor( p_cdg, p_data );
+			//The payload for this is actually the opacity of all 16 colors.
+			//So 63 - p_cdg->data[n] / 63 gives alpha level.
             break;
         case 30:
             DecodeLoadColorTable( p_cdg, p_data, 0 );
-- 
1.7.6.msysgit.0




More information about the vlc-devel mailing list