[vlc-commits] [Git][videolan/vlc][master] 2 commits: codec: avcodec: set palette in proper order

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Fri Aug 11 13:18:37 UTC 2023



Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC


Commits:
7732e3e8 by Francois Cartegnie at 2023-08-11T12:55:13+00:00
codec: avcodec: set palette in proper order

- - - - -
c1769ceb by Francois Cartegnie at 2023-08-11T12:55:13+00:00
video_filter: swscale: write palette in proper order

- - - - -


2 changed files:

- modules/codec/avcodec/video.c
- modules/video_chroma/swscale.c


Changes:

=====================================
modules/codec/avcodec/video.c
=====================================
@@ -147,6 +147,33 @@ static uint32_t ffmpeg_CodecTag( vlc_fourcc_t fcc )
  * Local Functions
  *****************************************************************************/
 
+static void lavc_Frame8PaletteCopy( video_palette_t *dst, const uint8_t *src )
+{
+    // (A << 24) | (R << 16) | (G << 8) | B
+    // stored in host endianness
+    const uint8_t *srcp = src;
+    for(size_t i=0; i<AVPALETTE_COUNT; i++)
+    {
+        // we want RGBA byte order storage
+#ifdef WORDS_BIGENDIAN
+        // AV mem is ARGB in byte order
+        dst->palette[i][0] = srcp[1];
+        dst->palette[i][1] = srcp[2];
+        dst->palette[i][2] = srcp[3];
+        dst->palette[i][3] = srcp[0];
+#else
+        // AV mem is BGRA in byte order
+        dst->palette[i][0] = srcp[2];
+        dst->palette[i][1] = srcp[1];
+        dst->palette[i][2] = srcp[0];
+        dst->palette[i][3] = srcp[3];
+#endif
+        srcp += sizeof(dst->palette[0]);
+    }
+
+    dst->i_entries = AVPALETTE_COUNT;
+}
+
 /**
  * Sets the decoder output format.
  */
@@ -1430,13 +1457,7 @@ 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 );
-            const uint8_t *src = frame->data[1];
-            for (size_t i=0; i<ARRAY_SIZE(p_palette->palette); i++)
-            {
-                memcpy(p_palette->palette[i], src, sizeof(p_palette->palette[0]));
-                src += sizeof(p_palette->palette[0]);
-            }
-            p_palette->i_entries = AVPALETTE_COUNT;
+            lavc_Frame8PaletteCopy( p_palette, frame->data[1] );
             p_dec->fmt_out.video.i_chroma = VLC_CODEC_RGBP;
             if( decoder_UpdateVideoFormat( p_dec ) )
             {


=====================================
modules/video_chroma/swscale.c
=====================================
@@ -629,11 +629,22 @@ static void Convert( filter_t *p_filter, struct SwsContext *ctx,
             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 *cursor = palette;
-            for (size_t i=0; i<ARRAY_SIZE(p_palette->palette); i++)
+            uint8_t *dstp = palette;
+            for(int i=0; i<p_palette->i_entries; i++)
             {
-                memcpy(cursor, p_palette->palette[i], sizeof(p_palette->palette[0]));
-                cursor += sizeof(p_palette->palette[0]);
+                // we want ARGB in host endianess from RGBA in byte order
+#ifdef WORDS_BIGENDIAN
+                dstp[0] = srcpal->palette[i][3];
+                dstp[1] = srcpal->palette[i][0];
+                dstp[2] = srcpal->palette[i][1];
+                dstp[3] = srcpal->palette[i][2];
+#else
+                dstp[0] = p_palette->palette[i][2];
+                dstp[1] = p_palette->palette[i][1];
+                dstp[2] = p_palette->palette[i][0];
+                dstp[3] = p_palette->palette[i][3];
+#endif
+                dstp += sizeof(p_palette->palette[0]);
             }
         }
         else



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/0f108f598c0567e2bee3706044c6c8c782be2961...c1769ceb44277529f49b4fd7db8fb5fffccac611

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/0f108f598c0567e2bee3706044c6c8c782be2961...c1769ceb44277529f49b4fd7db8fb5fffccac611
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