]> git.sesse.net Git - vlc/commitdiff
* modules/codec/dvbsub.c: full 4 and 8 bits RLE encodings.
authorGildas Bazin <gbazin@videolan.org>
Sun, 23 Jan 2005 12:26:01 +0000 (12:26 +0000)
committerGildas Bazin <gbazin@videolan.org>
Sun, 23 Jan 2005 12:26:01 +0000 (12:26 +0000)
modules/codec/dvbsub.c

index 6446e5de4311173cd7ce2adb68b5e9bbda88cb79..69c856f2c9e4aab4ea376f7d5fa285a7750cea58 100644 (file)
@@ -1646,6 +1646,9 @@ static void encode_pixel_line_2bp( encoder_t *p_enc, bs_t *s,
 static void encode_pixel_line_4bp( encoder_t *p_enc, bs_t *s,
                                    subpicture_region_t *p_region,
                                    int i_line );
+static void encode_pixel_line_8bp( encoder_t *p_enc, bs_t *s,
+                                   subpicture_region_t *p_region,
+                                   int i_line );
 static void encode_pixel_data( encoder_t *p_enc, bs_t *s,
                                subpicture_region_t *p_region,
                                vlc_bool_t b_top )
@@ -1671,6 +1674,11 @@ static void encode_pixel_data( encoder_t *p_enc, bs_t *s,
             encode_pixel_line_4bp( p_enc, s, p_region, i_line );
             break;
 
+        case 256:
+            bs_write( s, 8, 0x12 ); /* 8 bit/pixel code string */
+            encode_pixel_line_8bp( p_enc, s, p_region, i_line );
+            break;
+
         default:
             msg_Err( p_enc, "subpicture palette (%i) not handled",
                      p_region->fmt.p_palette->i_entries );
@@ -1784,13 +1792,13 @@ static void encode_pixel_line_4bp( encoder_t *p_enc, bs_t *s,
     for( i = 0; i <= p_region->fmt.i_visible_width; i++ )
     {
         if( i != p_region->fmt.i_visible_width &&
-            p_data[i] == i_last_pixel && i_length != 1 )
+            p_data[i] == i_last_pixel && i_length != 280 )
         {
             i_length++;
             continue;
         }
 
-        if( i_length == 1 )
+        if( i_length == 1 || (i_length == 3 && i_last_pixel) || i_length == 8 )
         {
             /* 4bit/pixel code */
             if( i_last_pixel ) bs_write( s, 4, i_last_pixel );
@@ -1801,6 +1809,58 @@ static void encode_pixel_line_4bp( encoder_t *p_enc, bs_t *s,
                 bs_write( s, 1, 1 );
                 bs_write( s, 2, 0 ); /* pseudo color 0 */
             }
+            i_length--;
+        }
+
+        if( i_length == 2 )
+        {
+            if( i_last_pixel )
+            {
+                bs_write( s, 4, i_last_pixel );
+                bs_write( s, 4, i_last_pixel );
+            }
+            else
+            {
+                bs_write( s, 4, 0 );
+                bs_write( s, 1, 1 );
+                bs_write( s, 1, 1 );
+                bs_write( s, 2, 1 ); /* 2 * pseudo color 0 */
+            }
+        }
+        else if( !i_last_pixel && i_length >= 3 && i_length <= 9 )
+        {
+            bs_write( s, 4, 0 );
+            bs_write( s, 1, 0 );
+            bs_write( s, 3, i_length - 2 ); /* (i_length - 2) * color 0 */
+        }
+        else if( i_length > 2 )
+        {
+            bs_write( s, 4, 0 );
+            bs_write( s, 1, 1 );
+
+            if( i_length <= 7 )
+            {
+                bs_write( s, 1, 0 );
+                bs_write( s, 2, i_length - 4 );
+                bs_write( s, 4, i_last_pixel );
+            }
+            else
+            {
+                bs_write( s, 1, 1 );
+
+                if( i_length <= 24 )
+                {
+                    bs_write( s, 2, 2 );
+                    bs_write( s, 4, i_length - 9 );
+                    bs_write( s, 4, i_last_pixel );
+                }
+                else
+                {
+                    bs_write( s, 2, 3 );
+                    bs_write( s, 8, i_length - 25 );
+                    bs_write( s, 4, i_last_pixel );
+                }
+            }
         }
 
         if( i == p_region->fmt.i_visible_width ) break;
@@ -1815,3 +1875,63 @@ static void encode_pixel_line_4bp( encoder_t *p_enc, bs_t *s,
     /* Stuffing */
     bs_align_0( s );
 }
+
+static void encode_pixel_line_8bp( encoder_t *p_enc, bs_t *s,
+                                   subpicture_region_t *p_region,
+                                   int i_line )
+{
+    unsigned int i, i_length = 0;
+    int i_pitch = p_region->picture.p->i_pitch;
+    uint8_t *p_data = &p_region->picture.p->p_pixels[ i_pitch * i_line ];
+    int i_last_pixel = p_data[0];
+
+    for( i = 0; i <= p_region->fmt.i_visible_width; i++ )
+    {
+        if( i != p_region->fmt.i_visible_width &&
+            p_data[i] == i_last_pixel && i_length != 127 )
+        {
+            i_length++;
+            continue;
+        }
+
+        if( i_length == 1 && i_last_pixel )
+        {
+            /* 8bit/pixel code */
+            bs_write( s, 8, i_last_pixel );
+        }
+        else if( i_length == 2 && i_last_pixel )
+        {
+            /* 8bit/pixel code */
+            bs_write( s, 8, i_last_pixel );
+            bs_write( s, 8, i_last_pixel );
+        }
+        else if( i_length <= 127 )
+        {
+            bs_write( s, 8, 0 );
+
+            if( !i_last_pixel )
+            {
+                bs_write( s, 1, 0 );
+                bs_write( s, 7, i_length ); /* pseudo color 0 */
+            }
+            else
+            {
+                bs_write( s, 1, 1 );
+                bs_write( s, 7, i_length );
+                bs_write( s, 8, i_last_pixel );
+            }
+        }
+
+        if( i == p_region->fmt.i_visible_width ) break;
+
+        i_last_pixel = p_data[i];
+        i_length = 1;
+    }
+
+    /* Stop */
+    bs_write( s, 8, 0 );
+    bs_write( s, 8, 0 );
+
+    /* Stuffing */
+    bs_align_0( s );
+}