[vlc-commits] [Git][videolan/vlc][master] 11 commits: swscale: flatten the source video_palette_t when there is one

Steve Lhomme (@robUx4) gitlab at videolan.org
Wed Jul 19 09:28:41 UTC 2023



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
1df6df8b by Steve Lhomme at 2023-07-19T09:14:21+00:00
swscale: flatten the source video_palette_t when there is one

Make sure our internal buffer size actually matches the one in libavutil.
The same static_assert is also done in video.c.

- - - - -
7ac5f2fe by Steve Lhomme at 2023-07-19T09:14:21+00:00
vlc_es: turn the SPU_PALETTE_DEFINED into a flag

This will simplify the code when using the palette.

Reorder the fields to put the padding at the end.

- - - - -
e1ef9094 by Steve Lhomme at 2023-07-19T09:14:21+00:00
vobsub: don't initialize palette buffer

It's never used if p_sys->b_palette is false.

- - - - -
e2ba56ea by Steve Lhomme at 2023-07-19T09:14:21+00:00
vlc_es: use a define for the count of elements in CLUT SPUs

- - - - -
846a1b4c by Steve Lhomme at 2023-07-19T09:14:21+00:00
mux: mp4: fix SPU metadata discarded if there is no palette

- - - - -
c1663442 by Steve Lhomme at 2023-07-19T09:14:21+00:00
mux: mp4: do the CLUT endian swapping in the stack

Not need for an allocation for this.

The size of the data is always the size of spu.palette.

- - - - -
5833e0da by Steve Lhomme at 2023-07-19T09:14:21+00:00
demux: mkv: don't alloc/copy SPU extradata is not in SPU

- - - - -
10548599 by Steve Lhomme at 2023-07-19T09:14:21+00:00
demux: factorize the code to parse VobSub extra data

- - - - -
d47ab57c by Steve Lhomme at 2023-07-19T09:14:21+00:00
dvdnav: don't use CLUT packet is the size is too small

- - - - -
a4ac6c7a by Steve Lhomme at 2023-07-19T09:14:21+00:00
avcodec: unflatten the libavcodec palette

The libavcodec palette is a flat buffer and ours is not.

Internally the flat buffer is casted to a uint32_t[256].

- - - - -
282a25dd by Steve Lhomme at 2023-07-19T09:14:21+00:00
avcodec: fix sign mismatch warning

- - - - -


12 changed files:

- include/vlc_es.h
- modules/access/dvdnav.c
- modules/access/dvdread.c
- modules/codec/avcodec/video.c
- modules/codec/spudec/parse.c
- modules/demux/avformat/demux.c
- modules/demux/mkv/matroska_segment_parse.cpp
- modules/demux/mp4/essetup.c
- modules/demux/vobsub.c
- modules/demux/vobsub.h
- modules/mux/mp4/libmp4mux.c
- modules/video_chroma/swscale.c


Changes:

=====================================
include/vlc_es.h
=====================================
@@ -38,6 +38,7 @@
  * \see subs_format_t
  */
 #define VIDEO_PALETTE_COLORS_MAX 256
+#define VIDEO_PALETTE_CLUT_COUNT 16
 
 struct video_palette_t
 {
@@ -573,13 +574,14 @@ struct subs_format_t
 
     struct
     {
-        /*  */
-        uint32_t palette[16+1]; /* CLUT Palette AYVU */
-
         /* the width of the original movie the spu was extracted from */
         int i_original_frame_width;
         /* the height of the original movie the spu was extracted from */
         int i_original_frame_height;
+
+        /*  */
+        uint32_t palette[VIDEO_PALETTE_CLUT_COUNT]; /* CLUT Palette AYVU */
+        bool b_palette;
     } spu;
 
     struct
@@ -599,8 +601,6 @@ struct subs_format_t
     } cc;
 };
 
-#define SPU_PALETTE_DEFINED  0xbeefbeef
-
 /**
  * ES language definition
  */


=====================================
modules/access/dvdnav.c
=====================================
@@ -140,7 +140,7 @@ typedef struct
     es_out_id_t *spu_es;
 
     /* palette for menus */
-    uint32_t clut[16];
+    uint32_t clut[VIDEO_PALETTE_CLUT_COUNT];
     bool b_spu_change;
     struct
     {
@@ -958,19 +958,22 @@ static int Demux( demux_t *p_demux )
 
     case DVDNAV_SPU_CLUT_CHANGE:
     {
-        int i;
-
         msg_Dbg( p_demux, "DVDNAV_SPU_CLUT_CHANGE" );
-        /* Update color lookup table (16 *uint32_t in packet) */
-        memcpy( p_sys->clut, packet, 16 * sizeof( uint32_t ) );
-
-        /* HACK to get the SPU tracks registered in the right order */
-        for( i = 0; i < 0x1f; i++ )
+        if ( unlikely( i_len < sizeof( p_sys->clut ) ) )
+            msg_Err(  p_demux, "invalid CLUT size %zu", i_len );
+        else
         {
-            if( dvdnav_spu_stream_to_lang( p_sys->dvdnav, i ) != 0xffff )
-                ESNew( p_demux, 0xbd20 + i );
+            /* Update color lookup table (16 *uint32_t in packet) */
+            memcpy( p_sys->clut, packet, sizeof( p_sys->clut ) );
+
+            /* HACK to get the SPU tracks registered in the right order */
+            for( int i = 0; i < 0x1f; i++ )
+            {
+                if( dvdnav_spu_stream_to_lang( p_sys->dvdnav, i ) != 0xffff )
+                    ESNew( p_demux, 0xbd20 + i );
+            }
+            /* END HACK */
         }
-        /* END HACK */
         break;
     }
 
@@ -1631,9 +1634,10 @@ static void ESNew( demux_t *p_demux, int i_id )
         i_lang = dvdnav_spu_stream_to_lang( p_sys->dvdnav, i_id&0x1f );
 
         /* Palette */
-        tk->fmt.subs.spu.palette[0] = SPU_PALETTE_DEFINED;
-        memcpy( &tk->fmt.subs.spu.palette[1], p_sys->clut,
-                16 * sizeof( uint32_t ) );
+        tk->fmt.subs.spu.b_palette = true;
+        static_assert(sizeof(tk->fmt.subs.spu.palette) == sizeof(p_sys->clut),
+                      "CLUT palette size mismatch");
+        memcpy( tk->fmt.subs.spu.palette, p_sys->clut, sizeof( p_sys->clut ) );
 
         /* We select only when we are not in the menu */
         if( dvdnav_current_title_info( p_sys->dvdnav, &i_title, &i_part ) == DVDNAV_STATUS_OK &&


=====================================
modules/access/dvdread.c
=====================================
@@ -142,7 +142,7 @@ typedef struct
     int i_sar_den;
 
     /* SPU */
-    uint32_t clut[16];
+    uint32_t clut[VIDEO_PALETTE_CLUT_COUNT];
 } demux_sys_t;
 
 static int Control   ( demux_t *, int, va_list );
@@ -740,9 +740,10 @@ static void ESNew( demux_t *p_demux, int i_id, int i_lang )
     else if( tk->fmt.i_cat == SPU_ES )
     {
         /* Palette */
-        tk->fmt.subs.spu.palette[0] = SPU_PALETTE_DEFINED;
-        memcpy( &tk->fmt.subs.spu.palette[1], p_sys->clut,
-                16 * sizeof( uint32_t ) );
+        tk->fmt.subs.spu.b_palette = true;
+        static_assert(sizeof(tk->fmt.subs.spu.palette) == sizeof(p_sys->clut),
+                      "CLUT palette size mismatch");
+        memcpy( tk->fmt.subs.spu.palette, p_sys->clut, sizeof( p_sys->clut ) );
 
         if( psz_language[0] ) tk->fmt.psz_language = strdup( psz_language );
     }
@@ -986,7 +987,9 @@ static int DvdReadSetArea( demux_t *p_demux, int i_title, int i_chapter,
             }
         }
 
-        memcpy( p_sys->clut, p_pgc->palette, 16 * sizeof( uint32_t ) );
+        static_assert(sizeof(p_sys->clut) == sizeof(p_pgc->palette),
+                      "mismatch CLUT size");
+        memcpy( p_sys->clut, p_pgc->palette, sizeof( p_sys->clut ) );
 
         /* Sub Picture ES */
         for( int i = 1; i <= p_vts->vtsi_mat->nr_of_vts_subp_streams; i++ )


=====================================
modules/codec/avcodec/video.c
=====================================
@@ -944,7 +944,7 @@ static void map_dovi_metadata( vlc_video_dovi_metadata_t *out,
     static_assert(sizeof(out->nlq)    == sizeof(vdm->nlq),    "struct mismatch");
     memcpy(out->curves, vdm->curves, sizeof(out->curves));
     memcpy(out->nlq,    vdm->nlq,    sizeof(out->nlq));
-    for( int i = 0; i < ARRAY_SIZE( out->curves ); i++)
+    for( size_t i = 0; i < ARRAY_SIZE( out->curves ); i++)
         assert( out->curves[i].num_pivots <= ARRAY_SIZE( out->curves[i].pivots ));
 }
 #endif
@@ -1284,7 +1284,12 @@ static int DecodeBlock( decoder_t *p_dec, block_t **pp_block )
             {
                 uint8_t *pal = av_packet_new_side_data(pkt, AV_PKT_DATA_PALETTE, AVPALETTE_SIZE);
                 if (pal) {
-                    memcpy(pal, p_dec->fmt_in->video.p_palette->palette, AVPALETTE_SIZE);
+                    const video_palette_t *p_palette = p_dec->fmt_in->video.p_palette;
+                    for (size_t i=0; i<sizeof(p_palette->palette[0]); i++)
+                    {
+                        memcpy(pal, p_palette->palette[i], ARRAY_SIZE(p_palette->palette));
+                        pal += ARRAY_SIZE(p_palette->palette);
+                    }
                     p_sys->palette_sent = true;
                 }
             }
@@ -1424,7 +1429,12 @@ static int DecodeBlock( decoder_t *p_dec, block_t **pp_block )
             static_assert( sizeof(p_palette->palette) == AVPALETTE_SIZE,
                            "Palette size mismatch between vlc and libavutil" );
             assert( frame->data[1] != NULL );
-            memcpy( p_palette->palette, frame->data[1], AVPALETTE_SIZE );
+            const uint8_t *src = frame->data[1];
+            for (size_t i=0; i<sizeof(p_palette->palette[0]); i++)
+            {
+                memcpy(p_palette->palette[i], src, ARRAY_SIZE(p_palette->palette));
+                src += ARRAY_SIZE(p_palette->palette);
+            }
             p_palette->i_entries = AVPALETTE_COUNT;
             p_dec->fmt_out.video.i_chroma = VLC_CODEC_RGBP;
             if( decoder_UpdateVideoFormat( p_dec ) )


=====================================
modules/codec/spudec/parse.c
=====================================
@@ -96,7 +96,7 @@ static void CLUTIdxToYUV(const struct subs_format_t *subs,
 {
     for( int i = 0; i < 4 ; i++ )
     {
-        uint32_t i_ayvu = subs->spu.palette[1+idx[i]];
+        uint32_t i_ayvu = subs->spu.palette[idx[i]];
         /* FIXME: this job should be done sooner */
         yuv[3-i][0] = i_ayvu>>16;
         yuv[3-i][1] = i_ayvu;
@@ -119,7 +119,7 @@ static void ParsePXCTLI( decoder_t *p_dec, const subpicture_data_t *p_spu_data,
         if(p_palette->i_entries +4 >= VIDEO_PALETTE_COLORS_MAX)
             break;
 
-        if( p_dec->fmt_in->subs.spu.palette[0] == SPU_PALETTE_DEFINED )
+        if( p_dec->fmt_in->subs.spu.b_palette )
         {
             /* Lookup the CLUT palette for the YUV values */
             uint8_t idx[4];
@@ -437,7 +437,7 @@ static int ParseControlSeq( decoder_t *p_dec, vlc_tick_t i_pts,
                 return VLC_EGENERIC;
             }
 
-            if( p_dec->fmt_in->subs.spu.palette[0] == SPU_PALETTE_DEFINED )
+            if( p_dec->fmt_in->subs.spu.b_palette )
             {
                 uint8_t idx[4];
 


=====================================
modules/demux/avformat/demux.c
=====================================
@@ -548,41 +548,7 @@ int avformat_OpenDemux( vlc_object_t *p_this )
                 cp->extradata != NULL &&
                 cp->extradata_size > 0 )
             {
-                char *psz_start;
-                char *psz_buf = malloc( cp->extradata_size + 1);
-                if( psz_buf != NULL )
-                {
-                    memcpy( psz_buf, cp->extradata , cp->extradata_size );
-                    psz_buf[cp->extradata_size] = '\0';
-
-                    psz_start = strstr( psz_buf, "size:" );
-                    if( psz_start &&
-                        vobsub_size_parse( psz_start,
-                                           &es_fmt.subs.spu.i_original_frame_width,
-                                           &es_fmt.subs.spu.i_original_frame_height ) == VLC_SUCCESS )
-                    {
-                        msg_Dbg( p_demux, "original frame size: %dx%d",
-                                 es_fmt.subs.spu.i_original_frame_width,
-                                 es_fmt.subs.spu.i_original_frame_height );
-                    }
-                    else
-                    {
-                        msg_Warn( p_demux, "reading original frame size failed" );
-                    }
-
-                    psz_start = strstr( psz_buf, "palette:" );
-                    if( psz_start &&
-                        vobsub_palette_parse( psz_start, &es_fmt.subs.spu.palette[1] ) == VLC_SUCCESS )
-                    {
-                        es_fmt.subs.spu.palette[0] = SPU_PALETTE_DEFINED;
-                        msg_Dbg( p_demux, "vobsub palette read" );
-                    }
-                    else
-                    {
-                        msg_Warn( p_demux, "reading original palette failed" );
-                    }
-                    free( psz_buf );
-                }
+                vobsub_extra_parse(p_this, &es_fmt.subs, cp->extradata, cp->extradata_size);
             }
             else if( cp->codec_id == AV_CODEC_ID_DVB_SUBTITLE &&
                      cp->extradata_size > 3 )


=====================================
modules/demux/mkv/matroska_segment_parse.cpp
=====================================
@@ -2260,46 +2260,10 @@ bool matroska_segment_c::TrackInit( mkv_track_t * p_tk )
 
             p_tk->fmt.i_codec = VLC_CODEC_SPU;
             p_tk->b_no_duration = true;
-            if( p_tk->i_extra_data )
+            if( likely( p_tk->i_extra_data && p_tk->fmt.i_cat == SPU_ES ) )
             {
-                char *psz_start;
-                char *psz_buf = (char *)malloc( p_tk->i_extra_data + 1);
-                if( psz_buf != NULL )
-                {
-                    memcpy( psz_buf, p_tk->p_extra_data , p_tk->i_extra_data );
-                    psz_buf[p_tk->i_extra_data] = '\0';
-
-                    if (p_tk->fmt.i_cat == SPU_ES)
-                    {
-                        psz_start = strstr( psz_buf, "size:" );
-                        if( psz_start &&
-                            vobsub_size_parse( psz_start,
-                                               &p_tk->fmt.subs.spu.i_original_frame_width,
-                                               &p_tk->fmt.subs.spu.i_original_frame_height ) == VLC_SUCCESS )
-                        {
-                            msg_Dbg( vars.p_demuxer, "original frame size vobsubs: %dx%d",
-                                     p_tk->fmt.subs.spu.i_original_frame_width,
-                                     p_tk->fmt.subs.spu.i_original_frame_height );
-                        }
-                        else
-                        {
-                            msg_Warn( vars.p_demuxer, "reading original frame size for vobsub failed" );
-                        }
-
-                        psz_start = strstr( psz_buf, "palette:" );
-                        if( psz_start &&
-                            vobsub_palette_parse( psz_start, &p_tk->fmt.subs.spu.palette[1] ) == VLC_SUCCESS )
-                        {
-                            p_tk->fmt.subs.spu.palette[0] = SPU_PALETTE_DEFINED;
-                            msg_Dbg( vars.p_demuxer, "vobsub palette read" );
-                        }
-                        else
-                        {
-                            msg_Warn( vars.p_demuxer, "reading original palette failed" );
-                        }
-                    }
-                    free( psz_buf );
-                }
+                vobsub_extra_parse( VLC_OBJECT(vars.p_demuxer), &p_tk->fmt.subs,
+                                    p_tk->p_extra_data, p_tk->i_extra_data );
             }
         }
         S_CASE("S_DVBSUB")


=====================================
modules/demux/mp4/essetup.c
=====================================
@@ -129,14 +129,13 @@ static void SetupESDS( demux_t *p_demux, const mp4_track_t *p_track,
                    p_fmt );
 
     if( p_fmt->i_codec == VLC_CODEC_SPU &&
-            p_fmt->i_extra >= 16 * 4 )
+            p_fmt->i_extra >= sizeof(p_fmt->subs.spu.palette) )
     {
-        for( int i = 0; i < 16; i++ )
+        for( int i = 0; i < ARRAY_SIZE(p_fmt->subs.spu.palette); i++ )
         {
-            p_fmt->subs.spu.palette[1 + i] =
-                    GetDWBE((char*)p_fmt->p_extra + i * 4);
+            p_fmt->subs.spu.palette[i] = GetDWBE((char*)p_fmt->p_extra + i * 4);
         }
-        p_fmt->subs.spu.palette[0] = SPU_PALETTE_DEFINED;
+        p_fmt->subs.spu.b_palette = true;
     }
 }
 


=====================================
modules/demux/vobsub.c
=====================================
@@ -100,7 +100,7 @@ typedef struct
     int            i_original_frame_width;
     int            i_original_frame_height;
     bool           b_palette;
-    uint32_t       palette[16];
+    uint32_t       palette[VIDEO_PALETTE_CLUT_COUNT];
 } demux_sys_t;
 
 
@@ -152,7 +152,6 @@ static int Open ( vlc_object_t *p_this )
     p_sys->i_original_frame_width = -1;
     p_sys->i_original_frame_height = -1;
     p_sys->b_palette = false;
-    memset( p_sys->palette, 0, 16 * sizeof( uint32_t ) );
 
     /* Load the whole file */
     TextLoad( &p_sys->txt, p_demux->s );
@@ -542,8 +541,10 @@ static int ParseVobSubIDX( demux_t *p_demux )
             fmt.psz_language = language;
             if( p_sys->b_palette )
             {
-                fmt.subs.spu.palette[0] = SPU_PALETTE_DEFINED;
-                memcpy( &fmt.subs.spu.palette[1], p_sys->palette, 16 * sizeof( uint32_t ) );
+                fmt.subs.spu.b_palette = true;
+                static_assert(sizeof(fmt.subs.spu.palette) == sizeof(p_sys->palette),
+                              "vobsub palette size mismatch");
+                memcpy( fmt.subs.spu.palette, p_sys->palette, sizeof( p_sys->palette ) );
             }
 
             fmt.i_id = i_track_id;


=====================================
modules/demux/vobsub.h
=====================================
@@ -23,7 +23,7 @@
 static inline void vobsub_palette_argb2ayvu( const uint32_t *src, uint32_t *dst )
 {
     int i;
-    for( i = 0; i < 16; i++ )
+    for( i = 0; i < VIDEO_PALETTE_CLUT_COUNT; i++ )
     {
         uint8_t r, g, b, y, u, v;
         r = (src[i] >> 16) & 0xff;
@@ -38,7 +38,7 @@ static inline void vobsub_palette_argb2ayvu( const uint32_t *src, uint32_t *dst
 
 static inline int vobsub_palette_parse( const char *psz_buf, uint32_t *pu_palette )
 {
-    uint32_t palette[16];
+    uint32_t palette[VIDEO_PALETTE_CLUT_COUNT];
     if( sscanf( psz_buf, "palette: "
                 "%" SCNx32", %" SCNx32 ", %" SCNx32 ", %" SCNx32 ", "
                 "%" SCNx32", %" SCNx32 ", %" SCNx32 ", %" SCNx32 ", "
@@ -47,7 +47,7 @@ static inline int vobsub_palette_parse( const char *psz_buf, uint32_t *pu_palett
                 &palette[0], &palette[1], &palette[2], &palette[3],
                 &palette[4], &palette[5], &palette[6], &palette[7],
                 &palette[8], &palette[9], &palette[10], &palette[11],
-                &palette[12], &palette[13], &palette[14], &palette[15] ) == 16 )
+                &palette[12], &palette[13], &palette[14], &palette[15] ) == ARRAY_SIZE(palette) )
     {
         vobsub_palette_argb2ayvu( palette, pu_palette );
         return VLC_SUCCESS;
@@ -75,3 +75,42 @@ static inline int vobsub_size_parse( const char *psz_buf,
     }
 }
 
+static inline void vobsub_extra_parse(vlc_object_t *o, subs_format_t *subs,
+                                      const uint8_t *buf, size_t buf_size)
+{
+    char *psz_start;
+    char *psz_buf = (char*)malloc( buf_size + 1);
+    if( unlikely( psz_buf == NULL ) )
+        return;
+
+    memcpy( psz_buf, buf, buf_size );
+    psz_buf[buf_size] = '\0';
+
+    psz_start = strstr( psz_buf, "size:" );
+    if( psz_start &&
+        vobsub_size_parse( psz_start,
+                            &subs->spu.i_original_frame_width,
+                            &subs->spu.i_original_frame_height ) == VLC_SUCCESS )
+    {
+        msg_Dbg( o, "original frame size: %dx%d",
+                    subs->spu.i_original_frame_width,
+                    subs->spu.i_original_frame_height );
+    }
+    else
+    {
+        msg_Warn( o, "reading original frame size failed" );
+    }
+
+    psz_start = strstr( psz_buf, "palette:" );
+    if( psz_start &&
+        vobsub_palette_parse( psz_start, subs->spu.palette ) == VLC_SUCCESS )
+    {
+        subs->spu.b_palette = true;
+        msg_Dbg( o, "vobsub palette read" );
+    }
+    else
+    {
+        msg_Warn( o, "reading original palette failed" );
+    }
+    free( psz_buf );
+}


=====================================
modules/mux/mp4/libmp4mux.c
=====================================
@@ -543,36 +543,28 @@ static bo_t *GetEDTS( mp4mux_trackinfo_t *p_track, uint32_t i_movietimescale, bo
     return edts;
 }
 
-static bo_t *GetESDS(mp4mux_trackinfo_t *p_track)
+static bo_t *GetESDS(const mp4mux_trackinfo_t *p_track)
 {
     bo_t *esds;
-    const uint8_t *p_extradata = NULL;
-    int i_extradata = 0;
-    uint8_t *p_extradata_allocated = NULL;
+    const uint8_t *p_extradata = p_track->fmt.p_extra;
+    int i_extradata = p_track->fmt.i_extra;
+    uint32_t local_palette[ARRAY_SIZE(p_track->fmt.subs.spu.palette)];
 
     switch(p_track->fmt.i_codec)
     {
         case VLC_CODEC_SPU:
-            if(p_track->fmt.subs.spu.palette[0] == SPU_PALETTE_DEFINED)
+            if(p_track->fmt.subs.spu.b_palette)
             {
 #ifndef WORDS_BIGENDIAN
-                p_extradata = p_extradata_allocated = malloc(16*4);
-                if(p_extradata_allocated)
-                {
-                    for(int i=0; i<16; i++)
-                        SetDWBE(&p_extradata_allocated[i*4], p_track->fmt.subs.spu.palette[i+1]);
-                    i_extradata = 16*4;
-                }
+                for(size_t i=0; i<ARRAY_SIZE(p_track->fmt.subs.spu.palette); i++)
+                    SetDWBE(&local_palette[i], p_track->fmt.subs.spu.palette[i]);
+                p_extradata = (const uint8_t *) local_palette;
 #else
-                p_extradata = (const uint8_t *) &p_track->fmt.subs.spu.palette[1];
-                i_extradata = 16 * sizeof(p_track->fmt.subs.spu.palette[1]);
+                p_extradata = (const uint8_t *) p_track->fmt.subs.spu.palette;
 #endif
+                i_extradata = sizeof(p_track->fmt.subs.spu.palette);
             }
             break;
-        default:
-            p_extradata = p_track->fmt.p_extra;
-            i_extradata = p_track->fmt.i_extra;
-            break;
     }
 
     /* */
@@ -581,7 +573,6 @@ static bo_t *GetESDS(mp4mux_trackinfo_t *p_track)
     esds = box_full_new("esds", 0, 0);
     if(!esds)
     {
-        free(p_extradata_allocated);
         return NULL;
     }
 
@@ -685,8 +676,6 @@ static bo_t *GetESDS(mp4mux_trackinfo_t *p_track)
 
         for (int i = 0; i < i_extradata; i++)
             bo_add_8(esds, p_extradata[i]);
-
-        free(p_extradata_allocated);
     }
 
     /* SL_Descr mandatory */


=====================================
modules/video_chroma/swscale.c
=====================================
@@ -44,10 +44,6 @@
 
 #include "../codec/avcodec/chroma.h" // Chroma Avutil <-> VLC conversion
 
-/* Gruikkkkkkkkkk!!!!! */
-#undef AVPALETTE_SIZE
-#define AVPALETTE_SIZE (256 * sizeof(uint32_t))
-
 /*****************************************************************************
  * Module descriptor
  *****************************************************************************/
@@ -628,10 +624,22 @@ static void Convert( filter_t *p_filter, struct SwsContext *ctx,
                p_src, i_plane_count, b_swap_uvi );
     if( p_filter->fmt_in.video.i_chroma == VLC_CODEC_RGBP )
     {
-        memset( palette, 0, sizeof(palette) );
         if( p_filter->fmt_in.video.p_palette )
-            memcpy( palette, p_filter->fmt_in.video.p_palette->palette,
-                    __MIN( sizeof(video_palette_t), AVPALETTE_SIZE ) );
+        {
+            const video_palette_t *p_palette = p_filter->fmt_in.video.p_palette;
+            static_assert(sizeof(p_palette->palette) == AVPALETTE_SIZE,
+                          "Palette size mismatch between vlc and libavutil");
+            uint8_t *dst = palette;
+            for (size_t i=0; i<sizeof(p_palette->palette[0]); i++)
+            {
+                memcpy(dst, p_palette->palette[i], ARRAY_SIZE(p_palette->palette));
+                dst += ARRAY_SIZE(p_palette->palette);
+            }
+        }
+        else
+        {
+            memset( &palette, 0, sizeof(palette) );
+        }
         src[1] = palette;
         src_stride[1] = 4;
     }



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/61e5973c9f5a0b3b960d27dd21874f0edb251f30...282a25dd578ce72d342aa83bb0e62a5725574bd6

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/61e5973c9f5a0b3b960d27dd21874f0edb251f30...282a25dd578ce72d342aa83bb0e62a5725574bd6
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