[vlc-commits] [Git][videolan/vlc][master] 8 commits: bitmapinfoheader: always set the video format chroma for raw formats

Steve Lhomme (@robUx4) gitlab at videolan.org
Thu Sep 7 06:02:27 UTC 2023



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
17d2a2b2 by Steve Lhomme at 2023-09-07T05:42:34+00:00
bitmapinfoheader: always set the video format chroma for raw formats

This is already the case when calling SetBitmapRGBMasks().

- - - - -
2ebe827d by Steve Lhomme at 2023-09-07T05:42:34+00:00
bitmapinfoheader: set the default 16-/32-bit mask for BI_RGB

When BI_BITFIELDS is used we should respect the mask written in the file.
Or if the mask is not there. It's only possible for 16 and 32 biBitCount,
see [1].

It's OK to call SetBitmapRGBMasks() on formats with no mask, it will do
nothing.

[1] https://learn.microsoft.com/en-us/previous-versions/dd183376(v=vs.85)

- - - - -
45547085 by Steve Lhomme at 2023-09-07T05:42:34+00:00
bitmapinfoheader: map 32-bit RGB to VLC_CODEC_BGRX chromas

The mask set by SetBitmapRGBMasks() actually corresponds to VLC_CODEC_XRGB
but it's probably wrong. The comment even says "This is in BGR0 format".

It also matches the use of VLC_CODEC_BGRA when there's alpha.

- - - - -
c327c5bd by Steve Lhomme at 2023-09-07T05:42:34+00:00
bitmapinfoheader: map RV32 biCompression to VLC_CODEC_BGRX

This is a biCompression that is not the proper value for 32-bit raw RGB but
may exist. In libvacodec it's mapped to AV_PIX_FMT_BGR0.

- - - - -
e3242f75 by Steve Lhomme at 2023-09-07T05:42:34+00:00
bitmapinfoheader: map VLC_CODEC_ABGR

The other RGB+alpha chromas are mapped.

- - - - -
5c42f091 by Steve Lhomme at 2023-09-07T05:42:34+00:00
bitmapinfoheader: set a mask when writing RGB+alpha mapping

The video_format_t should not contain any mask for these chroma. We must
generate it.

- - - - -
04b03d4a by Steve Lhomme at 2023-09-07T05:42:34+00:00
bitmapinfoheader: encode VLC_CODEC_BGRX as BI_RGB

This is the proper memory layout [1].

[1] https://learn.microsoft.com/en-us/previous-versions/dd183376(v=vs.85)

- - - - -
e0d33454 by Steve Lhomme at 2023-09-07T05:42:34+00:00
bitmapinfoheader: add support for RGB+x writing

It's similar to writing RGB+alpha except there's no alpha component.
And VLC_CODEC_BGRX is mapped separately.

- - - - -


1 changed file:

- modules/demux/avi/bitmapinfoheader.h


Changes:

=====================================
modules/demux/avi/bitmapinfoheader.h
=====================================
@@ -113,33 +113,29 @@ static inline int ParseBitmapInfoHeader( VLC_BITMAPINFOHEADER *p_bih, size_t i_b
         switch( p_bih->biBitCount )
         {
             case 32:
-                fmt->i_codec = VLC_CODEC_RGB32;
-                SetBitmapRGBMasks( fmt->i_codec, &fmt->video );
+                fmt->video.i_chroma = fmt->i_codec = VLC_CODEC_RGB32;
                 break;
             case 24:
-                fmt->i_codec = VLC_CODEC_RGB24; /* BGR (see biBitCount) */
-                SetBitmapRGBMasks( fmt->i_codec, &fmt->video );
+                fmt->video.i_chroma = fmt->i_codec = VLC_CODEC_RGB24; /* BGR (see biBitCount) */
                 break;
             case 16:
-                fmt->i_codec = VLC_CODEC_RGB16; /* RGB (5,6,5 bits) */
-                SetBitmapRGBMasks( fmt->i_codec, &fmt->video );
+                fmt->video.i_chroma = fmt->i_codec = VLC_CODEC_RGB16; /* RGB (5,6,5 bits) */
                 break;
             case 15: /* RGB (B least 5 bits) */
-                fmt->i_codec = VLC_CODEC_RGB15;
-                SetBitmapRGBMasks( fmt->i_codec, &fmt->video );
+                fmt->video.i_chroma = fmt->i_codec = VLC_CODEC_RGB15;
                 break;
             case 9: /* <- TODO check that */
-                fmt->i_codec = VLC_CODEC_I410;
+                fmt->video.i_chroma = fmt->i_codec = VLC_CODEC_I410;
                 break;
             case 8:
                 if ( p_bih->biClrUsed )
-                    fmt->i_codec = VLC_CODEC_RGBP;
+                    fmt->video.i_chroma = fmt->i_codec = VLC_CODEC_RGBP;
                 else
-                    fmt->i_codec = VLC_CODEC_GREY;
+                    fmt->video.i_chroma = fmt->i_codec = VLC_CODEC_GREY;
                 break;
             default:
                 if( p_bih->biClrUsed < 8 )
-                    fmt->i_codec = VLC_CODEC_RGBP;
+                    fmt->video.i_chroma = fmt->i_codec = VLC_CODEC_RGBP;
                 break;
         }
 
@@ -150,14 +146,38 @@ static inline int ParseBitmapInfoHeader( VLC_BITMAPINFOHEADER *p_bih, size_t i_b
                 fmt->video.i_rmask = GetDWLE( &p_bihextra[0] );
                 fmt->video.i_gmask = GetDWLE( &p_bihextra[4] );
                 fmt->video.i_bmask = GetDWLE( &p_bihextra[8] );
+                video_format_FixRgb( &fmt->video );
                 if( i_bihextra >= 4 * sizeof(uint32_t) ) /* Alpha channel ? */
                 {
                     uint32_t i_alpha = GetDWLE( &p_bihextra[8] );
-                    if( fmt->i_codec == VLC_CODEC_RGB32 && i_alpha == 0xFF )
-                        fmt->i_codec = VLC_CODEC_BGRA;
+                    if( i_alpha == 0xFF )
+                    {
+                        switch (fmt->i_codec)
+                        {
+                            case VLC_CODEC_RGB32: // unknown mask
+                            case VLC_CODEC_BGRX:
+                                fmt->i_codec = fmt->video.i_chroma = VLC_CODEC_BGRA;
+                                break;
+                            case VLC_CODEC_RGBX:
+                                fmt->i_codec = fmt->video.i_chroma = VLC_CODEC_RGBA;
+                                break;
+                            case VLC_CODEC_XBGR:
+                                fmt->i_codec = fmt->video.i_chroma = VLC_CODEC_ABGR;
+                                break;
+                            case VLC_CODEC_XRGB:
+                                fmt->i_codec = fmt->video.i_chroma = VLC_CODEC_ARGB;
+                                break;
+                        }
+                    }
                 }
             }
-            SetBitmapRGBMasks( fmt->i_codec, &fmt->video ); /* override default masks shifts */
+            else
+            {
+                if (p_bih->biBitCount == 32)
+                    fmt->i_codec = VLC_CODEC_BGRX;
+                else
+                    SetBitmapRGBMasks( fmt->i_codec, &fmt->video );
+            }
         }
         else if( fmt->i_codec == VLC_CODEC_RGBP )
         {
@@ -174,6 +194,13 @@ static inline int ParseBitmapInfoHeader( VLC_BITMAPINFOHEADER *p_bih, size_t i_b
                 }
             }
         }
+        else
+        {
+            if (p_bih->biBitCount == 32)
+                fmt->i_codec = VLC_CODEC_BGRX;
+            else
+                SetBitmapRGBMasks( fmt->i_codec, &fmt->video );
+        }
 
         p_props->i_stride = p_bih->biWidth * (p_bih->biBitCount >> 3);
         /* Unintuitively RGB DIB are always coded from bottom to top,
@@ -198,7 +225,10 @@ static inline int ParseBitmapInfoHeader( VLC_BITMAPINFOHEADER *p_bih, size_t i_b
         }
 
         /* Shitty VLC muxed files storing chroma in biCompression */
-        SetBitmapRGBMasks( fmt->i_codec, &fmt->video );
+        if (p_bih->biCompression == VLC_FOURCC('R','V','3','2'))
+            fmt->i_codec = VLC_CODEC_BGRX;
+        else
+            SetBitmapRGBMasks( fmt->i_codec, &fmt->video );
     }
 
     video_format_Setup( &fmt->video, fmt->i_codec,
@@ -226,6 +256,16 @@ static inline VLC_BITMAPINFOHEADER * CreateBitmapInfoHeader( const es_format_t *
     bool b_has_alpha = false;
     switch( fmt->i_codec )
     {
+        case VLC_CODEC_BGRX:
+            biBitCount = 32;
+            biCompression = BI_RGB;
+            break;
+        case VLC_CODEC_XBGR:
+        case VLC_CODEC_XRGB:
+        case VLC_CODEC_RGBX:
+            biBitCount = 32;
+            biCompression = BI_BITFIELDS;
+            break;
         case VLC_CODEC_RGB32:
             biBitCount = 32;
             biCompression = MatchBitmapRGBMasks( fmt ) ? BI_RGB : BI_BITFIELDS;
@@ -233,6 +273,7 @@ static inline VLC_BITMAPINFOHEADER * CreateBitmapInfoHeader( const es_format_t *
         case VLC_CODEC_BGRA:
         case VLC_CODEC_RGBA:
         case VLC_CODEC_ARGB:
+        case VLC_CODEC_ABGR:
             biBitCount = 32;
             biCompression = BI_BITFIELDS;
             b_has_alpha = true;
@@ -279,14 +320,44 @@ static inline VLC_BITMAPINFOHEADER * CreateBitmapInfoHeader( const es_format_t *
     p_bih->biClrUsed = 0;
     if( biCompression == BI_BITFIELDS )
     {
-        SetDWBE( &p_bmiColors[0], fmt->video.i_rmask );
-        SetDWBE( &p_bmiColors[4], fmt->video.i_gmask );
-        SetDWBE( &p_bmiColors[8], fmt->video.i_bmask );
+        uint32_t i_rmask,i_gmask,i_bmask;
+        switch( fmt->i_codec )
+        {
+            case VLC_CODEC_ABGR:
+            case VLC_CODEC_XBGR:
+                i_rmask = hton32(0x000000ff);
+                i_gmask = hton32(0x0000ff00);
+                i_bmask = hton32(0x00ff0000);
+                break;
+            case VLC_CODEC_ARGB:
+            case VLC_CODEC_XRGB:
+                i_rmask = hton32(0x00ff0000);
+                i_gmask = hton32(0x0000ff00);
+                i_bmask = hton32(0x000000ff);
+                break;
+            case VLC_CODEC_RGBA:
+            case VLC_CODEC_RGBX:
+                i_rmask = hton32(0xff000000);
+                i_gmask = hton32(0x00ff0000);
+                i_bmask = hton32(0x0000ff00);
+                break;
+            case VLC_CODEC_BGRA:
+                i_rmask = hton32(0x0000ff00);
+                i_gmask = hton32(0x00ff0000);
+                i_bmask = hton32(0xff000000);
+                break;
+            default:
+                i_rmask = fmt->video.i_rmask;
+                i_gmask = fmt->video.i_gmask;
+                i_bmask = fmt->video.i_bmask;
+                break;
+        }
+        SetDWBE( &p_bmiColors[0], i_rmask );
+        SetDWBE( &p_bmiColors[4], i_gmask );
+        SetDWBE( &p_bmiColors[8], i_bmask );
         if( b_has_alpha )
         {
-            SetDWBE( &p_bmiColors[12], ~(fmt->video.i_rmask |
-                                         fmt->video.i_gmask |
-                                         fmt->video.i_bmask) );
+            SetDWBE( &p_bmiColors[12], ~(i_rmask | i_gmask | i_bmask) );
         }
     }
     else if( fmt->i_codec == VLC_CODEC_RGBP )



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/c282325941cf3ac530e832fe204cd68a3b3a8b17...e0d334542073f8cb93f89617149aa0ec2a9d45d4

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