[vlc-commits] [Git][videolan/vlc][master] 3 commits: wingdi: fix handling of 256 color depth

Steve Lhomme (@robUx4) gitlab at videolan.org
Fri Feb 2 08:54:42 UTC 2024



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
5d652a80 by Jeffrey Knockel at 2024-02-02T08:36:46+00:00
wingdi: fix handling of 256 color depth

On Windows, 256 color bitmaps always have color palettes.  Prior to this
change, we wrote out 8bpp RGB bytes where GDI instead expected 8-bit
palette indexes.  Worse, we did not allocate memory for the palette, and
so GDI would read palette entries outside the end of the
vout_display_sys_t struct.  Since GDI will happily convert to and from
bitmaps of differing depths, we now write out a 24bpp bitmap for 256
color screen depths and let GDI convert to the paletted format.
Specifically [1], "[i]f the color formats of the source and destination
device contexts do not match, the BitBlt function converts the source
color format to match the destination format."  Similarly [2], "[i]f
destination, source, and pattern bitmaps do not have the same color
format, StretchBlt converts the source and pattern bitmaps to match the
destination bitmap."

[1] https://learn.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-bitblt
[2] https://learn.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-stretchblt

- - - - -
86283645 by Jeffrey Knockel at 2024-02-02T08:36:46+00:00
screen/win32: fix handling of 256 color depth

On Windows, 256 color bitmaps always have color palettes.  Prior to this
change, we captured palette indexes where we expected 8bpp RGB bytes.
Since GDI will happily convert[1] to and from bitmaps of differing
depths, we now write out a 24bpp bitmap for 256 color screen depths and
let GDI convert to the paletted format.  Specifically [1], "[i]f the
color formats of the source and destination device contexts do not
match, the BitBlt function converts the source color format to match the
destination format."

[1] https://learn.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-bitblt

- - - - -
0449bae0 by Jeffrey Knockel at 2024-02-02T08:36:46+00:00
screen/win32: use correct VLC codec for 16-bit

Switch from VLC_CODEC_BGR555LE to VLC_CODEC_RGB555LE for capture of
16-bit screens.  Note that the wingdi video output is already using
VLC_CODEC_RGB555LE for 16-bit output.  Documentation also demonstrates
that VLC_CODEC_RGB555LE is correct as VLC_CODEC_RGB555LE is internally
documented as "g3B5 0R5G2" and Microsoft documents 16-bit DIBs as having
the following format [1]:

"The relative intensities of red, green, and blue are represented with
five bits for each color component. The value for blue is in the least
significant five bits, followed by five bits each for green and red. The
most significant bit is not used."

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

- - - - -


2 changed files:

- modules/access/screen/win32.c
- modules/video_output/win32/wingdi.c


Changes:

=====================================
modules/access/screen/win32.c
=====================================
@@ -125,12 +125,18 @@ int screen_InitCaptureGDI( demux_t *p_demux )
     }
 
     i_bits_per_pixel = GetDeviceCaps( p_data->hdc_src, BITSPIXEL );
+
+    if (i_bits_per_pixel == 8)
+        /*
+         * We don't handle 256 color palettes, so let BitBlt() perform the
+         * conversion from 256 color palettes for us.
+         */
+        i_bits_per_pixel = 24;
+
     switch( i_bits_per_pixel )
     {
-    case 8: /* FIXME: set the palette */
-        i_chroma = VLC_CODEC_RGB233; break;
     case 16:    /* Yes it is really 15 bits (when using BI_RGB) */
-        i_chroma = VLC_CODEC_BGR555LE; break;
+        i_chroma = VLC_CODEC_RGB555LE; break;
     case 24:
         i_chroma = VLC_CODEC_RGB24; break;
     case 32:


=====================================
modules/video_output/win32/wingdi.c
=====================================
@@ -252,12 +252,16 @@ static int Init(vout_display_t *vd, video_format_t *fmt)
 
     video_format_TransformTo(fmt, ORIENT_NORMAL);
 
+    if (i_depth == 8)
+        /*
+         * We don't handle 256 color palettes, so let BitBlt()/StretchBlt()
+         * perform the conversion to 256 color palettes for us.
+         */
+        i_depth = 24;
+
     /* */
     msg_Dbg(vd, "GDI depth is %i", i_depth);
     switch (i_depth) {
-    case 8:
-        fmt->i_chroma = VLC_CODEC_RGB233;
-        break;
     case 16:
         fmt->i_chroma = VLC_CODEC_RGB555LE;
         break;



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/82f3c4334049eb38cc8abe160025fff5116cd782...0449bae03057e3a1abf3f7ef35161f6e34495e52

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/82f3c4334049eb38cc8abe160025fff5116cd782...0449bae03057e3a1abf3f7ef35161f6e34495e52
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