[vlc-commits] [Git][videolan/vlc][master] 9 commits: bitmapinfoheader: map 16-bit BI_RGB to VLC_CODEC_BGR565LE

Steve Lhomme (@robUx4) gitlab at videolan.org
Thu Oct 5 10:46:20 UTC 2023



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
e9879dc9 by Steve Lhomme at 2023-10-05T10:32:50+00:00
bitmapinfoheader: map 16-bit BI_RGB to VLC_CODEC_BGR565LE

This corresponds to the actual format expected by the Windows player.

- - - - -
189c428d by Steve Lhomme at 2023-10-05T10:32:50+00:00
bitmapinfoheader: map 15-bit BI_RGB to VLC_CODEC_BGR555LE

This corresponds to the actual format expected by the Windows player.

- - - - -
a23c1780 by Steve Lhomme at 2023-10-05T10:32:50+00:00
bitmapinfoheader: return an error on unknown BI_RGB bitdepth on reading

We can't map them to a known usable chroma without a mask.

We're not supposed to use a mask with BI_RGB anyway.

- - - - -
51e4d089 by Steve Lhomme at 2023-10-05T10:32:50+00:00
bitmapinfoheader: remove unused MatchBitmapRGBMasks

- - - - -
5a4cf91c by Steve Lhomme at 2023-10-05T10:32:50+00:00
bitmapinfoheader: map more BI_BITFIELDS masks to existing chromas

- - - - -
6203841a by Steve Lhomme at 2023-10-05T10:32:50+00:00
bitmapinfoheader: map RGB mask table to match read mask with VLC chromas

- - - - -
4a74b6b8 by Steve Lhomme at 2023-10-05T10:32:50+00:00
bitmapinfoheader: don't fix the RGB masks

We don't need video_format_FixRgb() anymore since we already mapped the
known masks and we do set a mask when it's not mapped.

- - - - -
7409b05c by Steve Lhomme at 2023-10-05T10:32:50+00:00
bitmapinfoheader: only map known BI_BITFIELDS mask

We want to get rid of the mask, so we won't be able to carry fringe values.

- - - - -
050c31bf by Steve Lhomme at 2023-10-05T10:32:50+00:00
bitmapinfoheader: get masks from RGB table with VLC chromas

- - - - -


1 changed file:

- modules/demux/avi/bitmapinfoheader.h


Changes:

=====================================
modules/demux/avi/bitmapinfoheader.h
=====================================
@@ -42,14 +42,74 @@
 static const struct
 {
     vlc_fourcc_t codec;
-    uint32_t i_rmask, i_gmask, i_bmask;
+    uint32_t i_rmask, i_gmask, i_bmask, i_amask;
+    uint8_t depth;
 } bitmap_rgb_masks[] = {
     { VLC_CODEC_RGB15,      0x7c00, /* FIXME it should be B5G5R5LE */
                             0x03e0,
-                            0x001f, },
+                            0x001f, 0x0000, 15 },
     { VLC_CODEC_RGB16,      0xf800, /* FIXME it should be B5G6R5LE */
                             0x07e0,
-                            0x001f, },
+                            0x001f, 0x0000, 16 },
+    { VLC_CODEC_XRGB,       0x00ff0000,
+                            0x0000ff00,
+                            0x000000ff,
+                            0x00000000, 32 },
+    { VLC_CODEC_XBGR,       0x000000ff,
+                            0x0000ff00,
+                            0x00ff0000,
+                            0x00000000, 32 },
+    { VLC_CODEC_RGBX,       0xff000000,
+                            0x00ff0000,
+                            0x0000ff00,
+                            0x00000000, 32 },
+    { VLC_CODEC_BGRX,       0x0000ff00,
+                            0x00ff0000,
+                            0xff000000,
+                            0x00000000, 32 },
+    { VLC_CODEC_ARGB,       0x00ff0000,
+                            0x0000ff00,
+                            0x000000ff,
+                            0xff000000, 32 },
+    { VLC_CODEC_ABGR,       0x000000ff,
+                            0x0000ff00,
+                            0x00ff0000,
+                            0xff000000, 32 },
+    { VLC_CODEC_RGBA,       0xff000000,
+                            0x00ff0000,
+                            0x0000ff00,
+                            0x000000ff, 32 },
+    { VLC_CODEC_BGRA,       0x0000ff00,
+                            0x00ff0000,
+                            0xff000000,
+                            0x000000ff, 32 },
+
+    { VLC_CODEC_RGB24,      0xff0000,
+                            0x00ff00,
+                            0x0000ff,
+                            0x000000, 24 },
+    { VLC_CODEC_BGR24,      0x0000ff,
+                            0x00ff00,
+                            0xff0000,
+                            0x000000, 24 },
+
+    { VLC_CODEC_RGB565LE,   0xf800,
+                            0x07e0,
+                            0x001f,
+                            0x0000, 16 },
+    { VLC_CODEC_BGR565LE,   0x001f,
+                            0x07e0,
+                            0xf800,
+                            0x0000, 16 },
+
+    { VLC_CODEC_RGB555LE,   0x7c00,
+                            0x03e0,
+                            0x001f,
+                            0x0000, 15 },
+    { VLC_CODEC_BGR555LE,   0x001f,
+                            0x03e0,
+                            0x7c00,
+                            0x0000, 15 },
 };
 
 static inline void SetBitmapRGBMasks( vlc_fourcc_t i_fourcc, video_format_t *fmt )
@@ -68,20 +128,6 @@ static inline void SetBitmapRGBMasks( vlc_fourcc_t i_fourcc, video_format_t *fmt
     }
 }
 
-static inline bool MatchBitmapRGBMasks( const es_format_t *fmt )
-{
-    for( size_t i=0; i<ARRAY_SIZE(bitmap_rgb_masks); i++ )
-    {
-        if( bitmap_rgb_masks[i].codec == fmt->i_codec )
-        {
-            return fmt->video.i_rmask == bitmap_rgb_masks[i].i_rmask &&
-                   fmt->video.i_gmask == bitmap_rgb_masks[i].i_gmask &&
-                   fmt->video.i_bmask == bitmap_rgb_masks[i].i_bmask;
-        }
-    }
-    return false;
-}
-
 struct bitmapinfoheader_properties
 {
     bool b_flipped;
@@ -108,16 +154,9 @@ static inline int ParseBitmapInfoHeader( const VLC_BITMAPINFOHEADER *p_bih, size
         switch( p_bih->biBitCount )
         {
             case 32:
-                fmt->video.i_chroma = fmt->i_codec = VLC_CODEC_XBGR;
-                break;
             case 24:
-                fmt->video.i_chroma = fmt->i_codec = VLC_CODEC_BGR24;
-                break;
             case 16:
-                fmt->video.i_chroma = fmt->i_codec = VLC_CODEC_RGB16; /* RGB (5,6,5 bits) */
-                break;
-            case 15: /* RGB (B least 5 bits) */
-                fmt->video.i_chroma = fmt->i_codec = VLC_CODEC_RGB15;
+            case 15:
                 break;
             case 9: /* <- TODO check that */
                 fmt->video.i_chroma = fmt->i_codec = VLC_CODEC_I410;
@@ -144,79 +183,17 @@ static inline int ParseBitmapInfoHeader( const VLC_BITMAPINFOHEADER *p_bih, size
                 uint32_t amask = i_bihextra >= 4 * sizeof(uint32_t) ? GetDWLE( &p_bihextra[12] ) : 0;
 
                 vlc_fourcc_t known_chroma = 0;
-                switch( p_bih->biBitCount )
+                for( size_t i=0; i<ARRAY_SIZE(bitmap_rgb_masks); i++ )
                 {
-                    case 32:
-                        if (rmask == 0x00ff0000 &&
-                            gmask == 0x0000ff00 &&
-                            bmask == 0x000000ff &&
-                            amask == 0x00000000)
-                        {
-                            known_chroma = VLC_CODEC_XRGB;
-                        }
-                        else
-                        if (rmask == 0x000000ff &&
-                            gmask == 0x0000ff00 &&
-                            bmask == 0x00ff0000 &&
-                            amask == 0x00000000)
-                        {
-                            known_chroma = VLC_CODEC_XBGR;
-                        }
-                        else
-                        if (rmask == 0xff000000 &&
-                            gmask == 0x00ff0000 &&
-                            bmask == 0x0000ff00 &&
-                            amask == 0x00000000)
-                        {
-                            known_chroma = VLC_CODEC_RGBX;
-                        }
-                        else
-                        if (rmask == 0x0000ff00 &&
-                            gmask == 0x00ff0000 &&
-                            bmask == 0xff000000 &&
-                            amask == 0x00000000)
-                        {
-                            known_chroma = VLC_CODEC_BGRX;
-                        }
-                        if (rmask == 0x00ff0000 &&
-                            gmask == 0x0000ff00 &&
-                            bmask == 0x000000ff &&
-                            amask == 0xff000000)
-                        {
-                            known_chroma = VLC_CODEC_ARGB;
-                        }
-                        else
-                        if (rmask == 0x000000ff &&
-                            gmask == 0x0000ff00 &&
-                            bmask == 0x00ff0000 &&
-                            amask == 0xff000000)
-                        {
-                            known_chroma = VLC_CODEC_ABGR;
-                        }
-                        else
-                        if (rmask == 0xff000000 &&
-                            gmask == 0x00ff0000 &&
-                            bmask == 0x0000ff00 &&
-                            amask == 0x000000ff)
-                        {
-                            known_chroma = VLC_CODEC_RGBA;
-                        }
-                        else
-                        if (rmask == 0x0000ff00 &&
-                            gmask == 0x00ff0000 &&
-                            bmask == 0xff000000 &&
-                            amask == 0x000000ff)
-                        {
-                            known_chroma = VLC_CODEC_BGRA;
-                        }
-                        else
-                        {
-                            // unknown mask
-                            return VLC_ENOTSUP;
-                        }
-                        break;
-                    default:
+                    if (bitmap_rgb_masks[i].depth == p_bih->biBitCount &&
+                        bitmap_rgb_masks[i].i_rmask == rmask &&
+                        bitmap_rgb_masks[i].i_gmask == gmask &&
+                        bitmap_rgb_masks[i].i_bmask == bmask &&
+                        bitmap_rgb_masks[i].i_amask == amask )
+                    {
+                        known_chroma = bitmap_rgb_masks[i].codec;
                         break;
+                    }
                 }
 
                 if (known_chroma != 0)
@@ -226,13 +203,6 @@ static inline int ParseBitmapInfoHeader( const VLC_BITMAPINFOHEADER *p_bih, size
                     fmt->video.i_gmask = 0;
                     fmt->video.i_bmask = 0;
                 }
-                else if (amask == 0)
-                {
-                    fmt->video.i_rmask = rmask;
-                    fmt->video.i_gmask = gmask;
-                    fmt->video.i_bmask = bmask;
-                    video_format_FixRgb( &fmt->video );
-                }
                 else
                 {
                     // unsupported alpha mask
@@ -267,17 +237,14 @@ static inline int ParseBitmapInfoHeader( const VLC_BITMAPINFOHEADER *p_bih, size
             {
                 case 32: bi_rgb_chroma = VLC_CODEC_XBGR; break;
                 case 24: bi_rgb_chroma = VLC_CODEC_BGR24; break;
-                default: bi_rgb_chroma = 0; break;
+                case 16: bi_rgb_chroma = VLC_CODEC_BGR565LE; break;
+                case 15: bi_rgb_chroma = VLC_CODEC_BGR555LE; break;
+                default: return VLC_EINVAL;
             }
-            if (bi_rgb_chroma != 0)
-            {
-                fmt->video.i_chroma = fmt->i_codec = bi_rgb_chroma;
-                fmt->video.i_rmask = 0;
-                fmt->video.i_gmask = 0;
-                fmt->video.i_bmask = 0;
-            }
-            else
-                SetBitmapRGBMasks( fmt->i_codec, &fmt->video );
+            fmt->video.i_chroma = fmt->i_codec = bi_rgb_chroma;
+            fmt->video.i_rmask = 0;
+            fmt->video.i_gmask = 0;
+            fmt->video.i_bmask = 0;
         }
 
         p_props->i_stride = p_bih->biWidth * (p_bih->biBitCount >> 3);
@@ -354,6 +321,12 @@ static inline int CreateBitmapInfoHeader( const es_format_t *fmt,
             break;
         case VLC_CODEC_RGB24:
             return VLC_EINVAL;
+        case VLC_CODEC_BGR565LE:
+            biBitCount = 16;
+            break;
+        case VLC_CODEC_BGR555LE:
+            biBitCount = 16;
+            break;
         case VLC_CODEC_RGB16:
         case VLC_CODEC_RGB15:
             biBitCount = 16;
@@ -389,14 +362,24 @@ static inline int CreateBitmapInfoHeader( const es_format_t *fmt,
     p_bih->biClrUsed = 0;
     if( biCompression == BI_BITFIELDS )
     {
-        uint32_t i_rmask,i_gmask,i_bmask, i_amask;
-        int ret = vlc_RGBChromaToMask( fmt->i_codec, &i_rmask, &i_gmask,
-                                       &i_bmask, &i_amask );
-        if (ret != VLC_SUCCESS)
+        uint32_t i_rmask = 0,i_gmask,i_bmask, i_amask;
+        for( size_t i=0; i<ARRAY_SIZE(bitmap_rgb_masks); i++ )
+        {
+            if ( bitmap_rgb_masks[i].codec == fmt->i_codec )
+            {
+                i_rmask = bitmap_rgb_masks[i].i_rmask;
+                i_gmask = bitmap_rgb_masks[i].i_gmask;
+                i_bmask = bitmap_rgb_masks[i].i_bmask;
+                i_amask = bitmap_rgb_masks[i].i_amask;
+                break;
+            }
+        }
+        if (i_rmask == 0)
         {
             i_rmask = fmt->video.i_rmask;
             i_gmask = fmt->video.i_gmask;
             i_bmask = fmt->video.i_bmask;
+            i_amask = 0;
         }
         SetDWLE( &p_bmiColors[0], i_rmask );
         SetDWLE( &p_bmiColors[4], i_gmask );



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/8137f1b179a5264f472e7b2bded7773525cd6d6a...050c31bfafbd631e9967229ff29caeddd62afe7c

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/8137f1b179a5264f472e7b2bded7773525cd6d6a...050c31bfafbd631e9967229ff29caeddd62afe7c
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