[vlc-commits] [Git][videolan/vlc][master] 4 commits: spudec: don't hardcode the size of the internal buffer

Steve Lhomme (@robUx4) gitlab at videolan.org
Wed Jul 26 14:37:59 UTC 2023



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
439c9ef0 by Steve Lhomme at 2023-07-26T14:22:52+00:00
spudec: don't hardcode the size of the internal buffer

- - - - -
7826823f by Steve Lhomme at 2023-07-26T14:22:52+00:00
spudec: return early if there's no PXCTLI palette

- - - - -
2963ff61 by Steve Lhomme at 2023-07-26T14:22:52+00:00
spudec: don't skip new palette if there's 4 slots left

There may be 0, 1 or 2 new colors and the rest already known. There's
already a check not to overwrite in the palette.

- - - - -
6f6e71dc by Steve Lhomme at 2023-07-26T14:22:52+00:00
spudec: reindent

No functional changes.

- - - - -


2 changed files:

- modules/codec/spudec/parse.c
- modules/codec/spudec/spudec.c


Changes:

=====================================
modules/codec/spudec/parse.c
=====================================
@@ -110,78 +110,75 @@ static void ParsePXCTLI( decoder_t *p_dec, const subpicture_data_t *p_spu_data,
     plane_t *p_plane = &p_spu->p_region->p_picture->p[0];
     video_palette_t *p_palette = p_spu->p_region->fmt.p_palette;
 
+    if( !p_dec->fmt_in->subs.spu.b_palette )
+        return;
+
     for( size_t i=0;i<p_spu_data->i_pxclti; i++ )
     {
         uint16_t i_col = GetWBE(&p_spu_data->p_pxctli[i*6 + 0]);
         uint16_t i_color = GetWBE(&p_spu_data->p_pxctli[i*6 + 2]);
         uint16_t i_contrast = GetWBE(&p_spu_data->p_pxctli[i*6 + 4]);
 
-        if(p_palette->i_entries +4 >= VIDEO_PALETTE_COLORS_MAX)
-            break;
-
-        if( p_dec->fmt_in->subs.spu.b_palette )
+        /* Lookup the CLUT palette for the YUV values */
+        uint8_t idx[4];
+        uint8_t yuv[4][3];
+        uint8_t alpha[4];
+        idx[0] = (i_color >> 12)&0x0f;
+        idx[1] = (i_color >>  8)&0x0f;
+        idx[2] = (i_color >>  4)&0x0f;
+        idx[3] = i_color&0x0f;
+        CLUTIdxToYUV( &p_dec->fmt_in->subs, idx, yuv );
+
+        /* Process the contrast */
+        alpha[3] = (i_contrast >> 12)&0x0f;
+        alpha[2] = (i_contrast >>  8)&0x0f;
+        alpha[1] = (i_contrast >>  4)&0x0f;
+        alpha[0] = i_contrast&0x0f;
+
+        /* Create a new YUVA palette entries for the picture */
+        int index_map[4];
+        for( int j=0; j<4; j++ )
         {
-            /* Lookup the CLUT palette for the YUV values */
-            uint8_t idx[4];
-            uint8_t yuv[4][3];
-            uint8_t alpha[4];
-            idx[0] = (i_color >> 12)&0x0f;
-            idx[1] = (i_color >>  8)&0x0f;
-            idx[2] = (i_color >>  4)&0x0f;
-            idx[3] = i_color&0x0f;
-            CLUTIdxToYUV( &p_dec->fmt_in->subs, idx, yuv );
-
-            /* Process the contrast */
-            alpha[3] = (i_contrast >> 12)&0x0f;
-            alpha[2] = (i_contrast >>  8)&0x0f;
-            alpha[1] = (i_contrast >>  4)&0x0f;
-            alpha[0] = i_contrast&0x0f;
-
-            /* Create a new YUVA palette entries for the picture */
-            int index_map[4];
-            for( int j=0; j<4; j++ )
+            uint8_t yuvaentry[4];
+            yuvaentry[0] = yuv[j][0];
+            yuvaentry[1] = yuv[j][1];
+            yuvaentry[2] = yuv[j][2];
+            yuvaentry[3] = alpha[j] * 0x11;
+            int i_index = VIDEO_PALETTE_COLORS_MAX;
+            for( int k = p_palette->i_entries; k > 0; k-- )
             {
-                uint8_t yuvaentry[4];
-                yuvaentry[0] = yuv[j][0];
-                yuvaentry[1] = yuv[j][1];
-                yuvaentry[2] = yuv[j][2];
-                yuvaentry[3] = alpha[j] * 0x11;
-                int i_index = VIDEO_PALETTE_COLORS_MAX;
-                for( int k = p_palette->i_entries; k > 0; k-- )
+                if( !memcmp( p_palette->palette[k], yuvaentry, sizeof(uint8_t [4]) ) )
                 {
-                    if( !memcmp( p_palette->palette[k], yuvaentry, sizeof(uint8_t [4]) ) )
-                    {
-                        i_index = i;
-                        break;
-                    }
+                    i_index = i;
+                    break;
                 }
+            }
 
-                /* Add an entry in out palette */
-                if( i_index == VIDEO_PALETTE_COLORS_MAX )
+            /* Add an entry in out palette */
+            if( i_index == VIDEO_PALETTE_COLORS_MAX )
+            {
+                if(p_palette->i_entries == VIDEO_PALETTE_COLORS_MAX)
                 {
-                    if(p_palette->i_entries == VIDEO_PALETTE_COLORS_MAX)
-                    {
-                        msg_Warn( p_dec, "Cannot create new color, skipping PXCTLI" );
-                        return;
-                    }
-                    i_index = p_palette->i_entries++;
-                    memcpy( p_palette->palette[ i_index ], yuvaentry, sizeof(uint8_t [4]) );
+                    msg_Warn( p_dec, "Cannot create new color, skipping PXCTLI" );
+                    return;
                 }
-                index_map[j] = i_index;
+                i_index = p_palette->i_entries++;
+                memcpy( p_palette->palette[ i_index ], yuvaentry, sizeof(uint8_t [4]) );
             }
+            index_map[j] = i_index;
+        }
 
-            if( p_spu->p_region->i_x >= i_col )
-                i_col -= p_spu->p_region->i_x;
+        if( p_spu->p_region->i_x >= i_col )
+            i_col -= p_spu->p_region->i_x;
 
-            for( int j=0; j<p_plane->i_visible_lines; j++ )
+        for( int j=0; j<p_plane->i_visible_lines; j++ )
+        {
+            uint8_t *p_line = &p_plane->p_pixels[j * p_plane->i_pitch];
+            /* Extends to end of the line */
+            for( int k=i_col; k<p_plane->i_visible_pitch; k++ )
             {
-                uint8_t *p_line = &p_plane->p_pixels[j * p_plane->i_pitch];
-                /* Extends to end of the line */
-                for( int k=i_col; k<p_plane->i_visible_pitch; k++ )
-                {
-                    if( p_line[k] < 4 ) /* can forge write-again */
-                        p_line[k] = index_map[ p_line[k] ];
-                }
+                if( p_line[k] < 4 ) /* can forge write-again */
+                    p_line[k] = index_map[ p_line[k] ];
             }
         }
     }


=====================================
modules/codec/spudec/spudec.c
=====================================
@@ -144,7 +144,7 @@ static int Decode( decoder_t *p_dec, block_t *p_block )
     }
 
     /* FIXME: what the, we shouldn’t need to allocate 64k of buffer --sam. */
-    p_sys->i_spu = block_ChainExtract( p_spu_block, p_sys->buffer, 65536 );
+    p_sys->i_spu = block_ChainExtract( p_spu_block, p_sys->buffer, sizeof(p_sys->buffer) );
     p_sys->i_pts = p_spu_block->i_pts;
     block_ChainRelease( p_spu_block );
 



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/3917282dae74900d549b7507d8365ee8023aa2c1...6f6e71dcaecb49e5ac7a6b72734f81d95d8f0655

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/3917282dae74900d549b7507d8365ee8023aa2c1...6f6e71dcaecb49e5ac7a6b72734f81d95d8f0655
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