46
46
#endif
47
47
48
48
// Logical color space values for BMP files
49
+ // https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-wmf/eb4bbd50-b3ce-4917-895c-be31f214797f
49
50
#ifndef LCS_WINDOWS_COLOR_SPACE
50
51
// 0x57696E20 == "Win "
51
52
#define LCS_WINDOWS_COLOR_SPACE 0x57696E20
52
53
#endif
53
54
55
+ #ifndef LCS_sRGB
56
+ // 0x73524742 == "sRGB"
57
+ #define LCS_sRGB 0x73524742
58
+ #endif
59
+
60
+ // Logical/physical color relationship
61
+ // https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-wmf/9fec0834-607d-427d-abd5-ab240fb0db38
62
+ #ifndef LCS_GM_GRAPHICS
63
+ #define LCS_GM_GRAPHICS 0x00000002
64
+ #endif
65
+
54
66
static bool readRlePixels (SDL_Surface * surface , SDL_IOStream * src , int isRle8 )
55
67
{
56
68
/*
@@ -637,6 +649,12 @@ bool SDL_SaveBMP_IO(SDL_Surface *surface, SDL_IOStream *dst, bool closeio)
637
649
Uint32 bV4GammaGreen = 0 ;
638
650
Uint32 bV4GammaBlue = 0 ;
639
651
652
+ // The additional header members from the Win32 BITMAPV5HEADER struct (124 bytes in total)
653
+ Uint32 bV5Intent = 0 ;
654
+ Uint32 bV5ProfileData = 0 ;
655
+ Uint32 bV5ProfileSize = 0 ;
656
+ Uint32 bV5Reserved = 0 ;
657
+
640
658
// Make sure we have somewhere to save
641
659
if (!SDL_SurfaceValid (surface )) {
642
660
SDL_InvalidParamError ("surface" );
@@ -728,19 +746,25 @@ bool SDL_SaveBMP_IO(SDL_Surface *surface, SDL_IOStream *dst, bool closeio)
728
746
}
729
747
biClrImportant = 0 ;
730
748
731
- // Set the BMP info values for the version 4 header
749
+ // Set the BMP info values
732
750
if (save32bit && !saveLegacyBMP ) {
733
- biSize = 108 ;
751
+ biSize = 124 ;
752
+ // Version 4 values
734
753
biCompression = BI_BITFIELDS ;
735
754
// The BMP format is always little endian, these masks stay the same
736
755
bV4RedMask = 0x00ff0000 ;
737
756
bV4GreenMask = 0x0000ff00 ;
738
757
bV4BlueMask = 0x000000ff ;
739
758
bV4AlphaMask = 0xff000000 ;
740
- bV4CSType = LCS_WINDOWS_COLOR_SPACE ;
759
+ bV4CSType = LCS_sRGB ;
741
760
bV4GammaRed = 0 ;
742
761
bV4GammaGreen = 0 ;
743
762
bV4GammaBlue = 0 ;
763
+ // Version 5 values
764
+ bV5Intent = LCS_GM_GRAPHICS ;
765
+ bV5ProfileData = 0 ;
766
+ bV5ProfileSize = 0 ;
767
+ bV5Reserved = 0 ;
744
768
}
745
769
746
770
// Write the BMP info values
@@ -758,8 +782,9 @@ bool SDL_SaveBMP_IO(SDL_Surface *surface, SDL_IOStream *dst, bool closeio)
758
782
goto done ;
759
783
}
760
784
761
- // Write the BMP info values for the version 4 header
785
+ // Write the BMP info values
762
786
if (save32bit && !saveLegacyBMP ) {
787
+ // Version 4 values
763
788
if (!SDL_WriteU32LE (dst , bV4RedMask ) ||
764
789
!SDL_WriteU32LE (dst , bV4GreenMask ) ||
765
790
!SDL_WriteU32LE (dst , bV4BlueMask ) ||
@@ -777,6 +802,13 @@ bool SDL_SaveBMP_IO(SDL_Surface *surface, SDL_IOStream *dst, bool closeio)
777
802
!SDL_WriteU32LE (dst , bV4GammaBlue )) {
778
803
goto done ;
779
804
}
805
+ // Version 5 values
806
+ if (!SDL_WriteU32LE (dst , bV5Intent ) ||
807
+ !SDL_WriteU32LE (dst , bV5ProfileData ) ||
808
+ !SDL_WriteU32LE (dst , bV5ProfileSize ) ||
809
+ !SDL_WriteU32LE (dst , bV5Reserved )) {
810
+ goto done ;
811
+ }
780
812
}
781
813
782
814
// Write the palette (in BGR color order)
0 commit comments