[vlc-commits] [Git][videolan/vlc][master] 5 commits: dvbsub: set the palette padding in one call

Steve Lhomme (@robUx4) gitlab at videolan.org
Fri Jul 28 12:58:45 UTC 2023



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
1fa1e083 by Steve Lhomme at 2023-07-28T12:33:22+00:00
dvbsub: set the palette padding in one call

- - - - -
1ca02283 by Steve Lhomme at 2023-07-28T12:33:22+00:00
dvbsub: use calloc instead of alloc+set to 0

- - - - -
f72db28c by Steve Lhomme at 2023-07-28T12:33:22+00:00
dvbsub: simplify initialization of the empty encoder palette

- - - - -
df8707b2 by Steve Lhomme at 2023-07-28T12:33:22+00:00
dvbsub: simplify access to planes

It's more readable that way.

- - - - -
afa4159f by Steve Lhomme at 2023-07-28T12:33:22+00:00
dvbsub: simplify YuvaYuvp call

The temporary value is always the same as the source.

- - - - -


1 changed file:

- modules/codec/dvbsub.c


Changes:

=====================================
modules/codec/dvbsub.c
=====================================
@@ -78,6 +78,8 @@
 
 #include <vlc_bits.h>
 
+#include <limits.h>
+
 /* #define DEBUG_DVBSUB 1 */
 
 #define POSX_TEXT N_("Decoding X coordinate")
@@ -1736,11 +1738,11 @@ static int OpenEncoder( vlc_object_t *p_this )
 /* FIXME: this routine is a hack to convert VLC_CODEC_YUVA
  *        into VLC_CODEC_YUVP
  */
-static subpicture_t *YuvaYuvp( subpicture_t *p_subpic )
+static void YuvaYuvp( subpicture_t *p_subpic )
 {
     subpicture_region_t *p_region = NULL;
 
-    if( !p_subpic ) return NULL;
+    if( !p_subpic ) return;
 
     for( p_region = p_subpic->p_region; p_region; p_region = p_region->p_next )
     {
@@ -1754,10 +1756,10 @@ static subpicture_t *YuvaYuvp( subpicture_t *p_subpic )
         int *pi_delta;
 #endif
         int i_pixels = p_region->p_picture->p[0].i_visible_lines
-                        * p_region->p_picture->p[0].i_pitch;
+                        * p_region->p_picture->Y_PITCH;
         int i_iterator = p_region->p_picture->p[0].i_visible_lines * 3 / 4
-                            * p_region->p_picture->p[0].i_pitch
-                        + p_region->p_picture->p[0].i_pitch * 1 / 3;
+                            * p_region->p_picture->Y_PITCH
+                        + p_region->p_picture->Y_PITCH * 1 / 3;
         int i_tolerance = 0;
 
 #ifdef DEBUG_DVBSUB1
@@ -1798,10 +1800,10 @@ static subpicture_t *YuvaYuvp( subpicture_t *p_subpic )
             for( i = 0; i < i_pixels ; )
             {
                 uint8_t y, u, v, a;
-                y = p_region->p_picture->p[0].p_pixels[i];
-                u = p_region->p_picture->p[1].p_pixels[i];
-                v = p_region->p_picture->p[2].p_pixels[i];
-                a = p_region->p_picture->p[3].p_pixels[i];
+                y = p_region->p_picture->Y_PIXELS[i];
+                u = p_region->p_picture->U_PIXELS[i];
+                v = p_region->p_picture->V_PIXELS[i];
+                a = p_region->p_picture->A_PIXELS[i];
                 for( j = 0; j < p_fmt->p_palette->i_entries; j++ )
                 {
                     if( abs((int)p_fmt->p_palette->palette[j][0] - (int)y) <= i_tolerance &&
@@ -1844,12 +1846,9 @@ static subpicture_t *YuvaYuvp( subpicture_t *p_subpic )
 #endif
 
 #ifndef RANDOM_DITHERING
-        pi_delta = xmalloc( ( p_region->p_picture->p[0].i_pitch + 1 )
-                            * sizeof(int) * 4  );
-        for( i = 0; i < (p_region->p_picture->p[0].i_pitch + 1) * 4 ; i++ )
-        {
-            pi_delta[ i ] = 0;
-        }
+        pi_delta = calloc( ( p_region->p_picture->Y_PITCH + 1 ) * 4, sizeof(int) );
+        if (unlikely(pi_delta == NULL))
+            return;
 #endif
 
         /* Fill image with our new colours */
@@ -1857,16 +1856,16 @@ static subpicture_t *YuvaYuvp( subpicture_t *p_subpic )
         {
             int i_ydelta = 0, i_udelta = 0, i_vdelta = 0, i_adelta = 0;
 
-            for( n = 0; n < p_region->p_picture->p[0].i_pitch ; n++ )
+            for( n = 0; n < p_region->p_picture->Y_PITCH ; n++ )
             {
-                int i_offset = p * p_region->p_picture->p[0].i_pitch + n;
+                int i_offset = p * p_region->p_picture->Y_PITCH + n;
                 int y, u, v, a;
                 int i_mindist, i_best;
 
-                y = (int)p_region->p_picture->p[0].p_pixels[i_offset];
-                u = (int)p_region->p_picture->p[1].p_pixels[i_offset];
-                v = (int)p_region->p_picture->p[2].p_pixels[i_offset];
-                a = (int)p_region->p_picture->p[3].p_pixels[i_offset];
+                y = p_region->p_picture->Y_PIXELS[i_offset];
+                u = p_region->p_picture->U_PIXELS[i_offset];
+                v = p_region->p_picture->V_PIXELS[i_offset];
+                a = p_region->p_picture->A_PIXELS[i_offset];
 
                 /* Add dithering compensation */
 #ifdef RANDOM_DITHERING
@@ -1875,14 +1874,14 @@ static subpicture_t *YuvaYuvp( subpicture_t *p_subpic )
                 v += (((i_seed >> 16) & 0xff) - 0x80) * i_tolerance / 0x80;
                 a += (((i_seed >> 24) & 0xff) - 0x80) * i_tolerance / 0x80;
 #else
-                y += i_ydelta + pi_delta[ n * 4 ];
+                y += i_ydelta + pi_delta[ n * 4 + 0 ];
                 u += i_udelta + pi_delta[ n * 4 + 1 ];
                 v += i_vdelta + pi_delta[ n * 4 + 2 ];
                 a += i_adelta + pi_delta[ n * 4 + 3 ];
 #endif
 
                 /* Find best colour in palette */
-                for( i_mindist = 99999999, i_best = 0, j = 0; j < p_fmt->p_palette->i_entries; j++ )
+                for( i_mindist = INT_MAX, i_best = 0, j = 0; j < p_fmt->p_palette->i_entries; j++ )
                 {
                     int i_dist = 0;
 
@@ -1899,7 +1898,7 @@ static subpicture_t *YuvaYuvp( subpicture_t *p_subpic )
                 }
 
                 /* Set pixel to best color */
-                p_region->p_picture->p[0].p_pixels[i_offset] = i_best;
+                p_region->p_picture->Y_PIXELS[i_offset] = i_best;
 
                 /* Update dithering state */
 #ifdef RANDOM_DITHERING
@@ -1909,7 +1908,7 @@ static subpicture_t *YuvaYuvp( subpicture_t *p_subpic )
                 i_udelta = u - (int)p_fmt->p_palette->palette[i_best][1];
                 i_vdelta = v - (int)p_fmt->p_palette->palette[i_best][2];
                 i_adelta = a - (int)p_fmt->p_palette->palette[i_best][3];
-                pi_delta[ n * 4 ] = i_ydelta * 3 / 8;
+                pi_delta[ n * 4 + 0 ] = i_ydelta * 3 / 8;
                 pi_delta[ n * 4 + 1 ] = i_udelta * 3 / 8;
                 pi_delta[ n * 4 + 2 ] = i_vdelta * 3 / 8;
                 pi_delta[ n * 4 + 3 ] = i_adelta * 3 / 8;
@@ -1926,19 +1925,13 @@ static subpicture_t *YuvaYuvp( subpicture_t *p_subpic )
 
         /* pad palette */
         for( i = p_fmt->p_palette->i_entries; i < i_max_entries; i++ )
-        {
-            p_fmt->p_palette->palette[i][0] = 0;
-            p_fmt->p_palette->palette[i][1] = 0;
-            p_fmt->p_palette->palette[i][2] = 0;
-            p_fmt->p_palette->palette[i][3] = 0;
-        }
+            memset(p_fmt->p_palette->palette[i], 0, sizeof(p_fmt->p_palette->palette[i]));
         p_fmt->p_palette->i_entries = i_max_entries;
 #ifdef DEBUG_DVBSUB1
         /* p_enc not valid here */
         msg_Dbg( p_enc, "best palette has %d colors", p_fmt->p_palette->i_entries );
 #endif
     }
-    return p_subpic;
 } /* End of hack */
 
 /****************************************************************************
@@ -1946,7 +1939,6 @@ static subpicture_t *YuvaYuvp( subpicture_t *p_subpic )
  ****************************************************************************/
 static block_t *Encode( encoder_t *p_enc, subpicture_t *p_subpic )
 {
-    subpicture_t *p_temp = NULL;
     subpicture_region_t *p_region = NULL;
     bs_t bits, *s = &bits;
     block_t *p_block;
@@ -1959,13 +1951,12 @@ static block_t *Encode( encoder_t *p_enc, subpicture_t *p_subpic )
     p_region = p_subpic->p_region;
     if( p_region->fmt.i_chroma == VLC_CODEC_YUVA )
     {
-        p_temp = YuvaYuvp( p_subpic );
-        if( !p_temp )
+        if( !p_subpic )
         {
             msg_Err( p_enc, "no picture in subpicture" );
             return NULL;
         }
-        p_region = p_subpic->p_region;
+        YuvaYuvp( p_subpic );
     }
 
     /* Sanity check */
@@ -2146,7 +2137,7 @@ static void encode_clut( encoder_t *p_enc, bs_t *s, subpicture_t *p_subpic )
 {
     encoder_sys_t *p_sys = p_enc->p_sys;
     subpicture_region_t *p_region = p_subpic->p_region;
-    video_palette_t *p_pal, pal;
+    video_palette_t *p_pal, empty_palette = { .i_entries = 4 };
 
     /* Sanity check */
     if( !p_region ) return;
@@ -2156,17 +2147,7 @@ static void encode_clut( encoder_t *p_enc, bs_t *s, subpicture_t *p_subpic )
         p_pal = p_region->fmt.p_palette;
     }
     else
-    {
-        pal.i_entries = 4;
-        for( int i = 0; i < 4; i++ )
-        {
-            pal.palette[i][0] = 0;
-            pal.palette[i][1] = 0;
-            pal.palette[i][2] = 0;
-            pal.palette[i][3] = 0;
-        }
-        p_pal = &pal;
-    }
+        p_pal = &empty_palette;
 
     bs_write( s, 8, 0x0f ); /* Sync byte */
     bs_write( s, 8, DVBSUB_ST_CLUT_DEFINITION ); /* Segment type */



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/72d3fc2f7dad56c81401a17d063b6c310507766b...afa4159f27c6fdfb811dabece05da6fb1722b7e0

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/72d3fc2f7dad56c81401a17d063b6c310507766b...afa4159f27c6fdfb811dabece05da6fb1722b7e0
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list