VirtualBox

Changeset 85864 in vbox


Ignore:
Timestamp:
Aug 21, 2020 12:44:56 PM (4 years ago)
Author:
vboxsync
Message:

Consolidated all the different Bitmap (BMP) file format headers / definitions into new include/iprt/formats/bmp.h (part 2): Renaming + prefixing stuff.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/formats/bmp.h

    r85859 r85864  
    3434#include <iprt/assertcompile.h>
    3535
     36/** @name BMP header sizes (in bytes).
     37 * @{ . */
     38#define BMP_HDR_SIZE_FILE      14
     39#define BMP_HDR_SIZE_OS21      12
     40#define BMP_HDR_SIZE_OS22      64
     41#define BMP_HDR_SIZE_WIN3X     40
     42/** @} . */
     43
    3644#pragma pack(1)
    3745
    38 /** BMP File Format Bitmap Header. */
    39 typedef struct
     46/** BMP format file header. */
     47typedef struct BMPFILEHDR
    4048{
    41     /** File Type Identifier. */
    42     uint16_t      Type;
    43     /** Size of File. */
    44     uint32_t      FileSize;
     49    /** File type identifier ("magic"). */
     50    uint16_t      uType;
     51    /** Size of file in bytes. */
     52    uint32_t      cbFileSize;
    4553    /** Reserved (should be 0). */
    4654    uint16_t      Reserved1;
    4755    /** Reserved (should be 0). */
    4856    uint16_t      Reserved2;
    49     /** Offset to bitmap data. */
    50     uint32_t      Offset;
    51 } BMPINFO;
    52 AssertCompileSize(BMPINFO, 14);
    53 /** Pointer to a bitmap header. */
    54 typedef BMPINFO *PBMPINFO;
     57    /** Offset (in bytes) to bitmap data. */
     58    uint32_t      offBits;
     59} BMPFILEHDR;
     60AssertCompileSize(BMPFILEHDR, BMP_HDR_SIZE_FILE);
     61/** Pointer to a BMP format file header. */
     62typedef BMPFILEHDR *PBMPFILEHDR;
    5563
    56 /** OS/2 1.x Information Header Format. */
    57 typedef struct
     64/** OS/2 1.x BMP core header,
     65 *  also known as BITMAPCOREHEADER. */
     66typedef struct BMPOS2COREHDR
    5867{
    59     /** Size of Remaining Header. */
    60     uint32_t      Size;
    61     /** Width of Bitmap in Pixels. */
    62     uint16_t      Width;
    63     /** Height of Bitmap in Pixels. */
    64     uint16_t      Height;
    65     /** Number of Planes. */
    66     uint16_t      Planes;
    67     /** Color Bits Per Pixel. */
    68     uint16_t      BitCount;
    69 } OS2HDR;
    70 AssertCompileSize(OS2HDR, 12);
    71 /** Pointer to a OS/2 1.x header format. */
    72 typedef OS2HDR *POS2HDR;
     68    /** Size (in bytes) of remaining header. */
     69    uint32_t      cbSize;
     70    /** Width of bitmap in pixels. */
     71    uint16_t      uWidth;
     72    /** Height of bitmap in pixels. */
     73    uint16_t      uHeight;
     74    /** Number of planes. */
     75    uint16_t      cPlanes;
     76    /** Color bits per pixel. */
     77    uint16_t      cBits;
     78} BMPOS2COREHDR;
     79AssertCompileSize(BMPOS2COREHDR, BMP_HDR_SIZE_OS21);
     80/** Pointer to a OS/2 1.x BMP core header. */
     81typedef BMPOS2COREHDR *PBMPOS2COREHDR;
    7382
    74 /** OS/2 2.0 Information Header Format. */
    75 typedef struct
     83/** OS/2 2.0 BMP core header, version 2,
     84 *  also known as BITMAPCOREHEADER2. */
     85typedef struct BMPOS2COREHDR2
    7686{
    77     /** Size of Remaining Header. */
    78     uint32_t      Size;
    79     /** Width of Bitmap in Pixels. */
    80     uint32_t      Width;
    81     /** Height of Bitmap in Pixels. */
    82     uint32_t      Height;
    83     /** Number of Planes. */
    84     uint16_t      Planes;
    85     /** Color Bits Per Pixel. */
    86     uint16_t      BitCount;
    87     /** Compression Scheme (0=none). */
    88     uint32_t      Compression;
     87    /** Size (in bytes) of remaining header. */
     88    uint32_t      cbSize;
     89    /** Width of bitmap in pixels. */
     90    uint32_t      uWidth;
     91    /** Height of bitmap in pixels. */
     92    uint32_t      uHeight;
     93    /** Number of planes. */
     94    uint16_t      cPlanes;
     95    /** Color bits per pixel. */
     96    uint16_t      cBits;
     97    /** Compression scheme of type BMP_COMPRESSION_TYPE. */
     98    uint32_t      enmCompression;
    8999    /** Size of bitmap in bytes. */
    90     uint32_t      SizeImage;
    91     /** Horz. Resolution in Pixels/Meter. */
    92     uint32_t      XPelsPerMeter;
    93     /** Vert. Resolution in Pixels/Meter. */
    94     uint32_t      YPelsPerMeter;
    95     /** Number of Colors in Color Table. */
    96     uint32_t      ClrUsed;
    97     /** Number of Important Colors. */
    98     uint32_t      ClrImportant;
    99     /** Resolution Measurement Used. */
    100     uint16_t      Units;
    101     /** Reserved Fields (always 0). */
     100    uint32_t      cbSizeImage;
     101    /** Horz. resolution in pixels/meter. */
     102    uint32_t      uXPelsPerMeter;
     103    /** Vert. resolution in pixels/meter. */
     104    uint32_t      uYPelsPerMeter;
     105    /** Number of colors in color table. */
     106    uint32_t      cClrUsed;
     107    /** Number of important colors. */
     108    uint32_t      cClrImportant;
     109    /** Resolution measurement Used. */
     110    uint16_t      uUnits;
     111    /** Reserved fields (always 0). */
    102112    uint16_t      Reserved;
    103     /** Orientation of Bitmap. */
    104     uint16_t      Recording;
    105     /** Halftone Algorithm Used on Image. */
    106     uint16_t      Rendering;
    107     /** Halftone Algorithm Data. */
    108     uint32_t      Size1;
    109     /** Halftone Algorithm Data. */
    110     uint32_t      Size2;
    111     /** Color Table Format (always 0). */
    112     uint32_t      ColorEncoding;
    113     /** Misc. Field for Application Use  . */
    114     uint32_t      Identifier;
    115 } OS22HDR;
    116 AssertCompileSize(OS22HDR, 64);
    117 /** Pointer to a OS/2 2.0 header format . */
    118 typedef OS22HDR *POS22HDR;
     113    /** Orientation of bitmap. */
     114    uint16_t      uRecording;
     115    /** Halftone algorithm used on image. */
     116    uint16_t      enmHalftone;
     117    /** Halftone algorithm data. */
     118    uint32_t      uHalftoneParm1;
     119    /** Halftone algorithm data. */
     120    uint32_t      uHalftoneParm2;
     121    /** Color table format (always 0). */
     122    uint32_t      uColorEncoding;
     123    /** Misc. field for application use  . */
     124    uint32_t      uIdentifier;
     125} BMPOS2COREHDR2;
     126AssertCompileSize(BMPOS2COREHDR2, BMP_HDR_SIZE_OS22);
     127/** Pointer to an OS/2 2.0 BMP core header version 2. */
     128typedef BMPOS2COREHDR2 *PBMPOS2COREHDR2;
    119129
    120 /** Windows 3.x Information Header Format. */
    121 typedef struct
     130/** Windows 3.x BMP information header Format. */
     131typedef struct BMPWIN3XINFOHDR
    122132{
    123     /** Size of Remaining Header. */
    124     uint32_t      Size;
    125     /** Width of Bitmap in Pixels. */
    126     uint32_t      Width;
    127     /** Height of Bitmap in Pixels. */
    128     uint32_t      Height;
    129     /** Number of Planes. */
    130     uint16_t      Planes;
    131     /** Bits Per Pixel. */
    132     uint16_t      BitCount;
    133     /** Compression Scheme (0=none). */
    134     uint32_t      Compression;
     133    /** Size (in bytes) of remaining header. */
     134    uint32_t      cbSize;
     135    /** Width of bitmap in pixels. */
     136    uint32_t      uWidth;
     137    /** Height of bitmap in pixels. */
     138    uint32_t      uHeight;
     139    /** Number of planes. */
     140    uint16_t      cPlanes;
     141    /** Color bits per pixel. */
     142    uint16_t      cBits;
     143    /** Compression scheme of type BMP_COMPRESSION_TYPE. */
     144    uint32_t      enmCompression;
    135145    /** Size of bitmap in bytes. */
    136     uint32_t      SizeImage;
    137     /** Horz. Resolution in Pixels/Meter. */
    138     uint32_t      XPelsPerMeter;
    139     /** Vert. Resolution in Pixels/Meter. */
    140     uint32_t      YPelsPerMeter;
    141     /** Number of Colors in Color Table. */
    142     uint32_t      ClrUsed;
    143     /** Number of Important Colors. */
    144     uint32_t      ClrImportant;
    145 } WINHDR;
    146 /** Pointer to a Windows 3.x header format. */
    147 typedef WINHDR *PWINHDR;
     146    uint32_t      cbSizeImage;
     147    /** Horz. resolution in pixels/meter. */
     148    uint32_t      uXPelsPerMeter;
     149    /** Vert. resolution in pixels/meter. */
     150    uint32_t      uYPelsPerMeter;
     151    /** Number of colors in color table. */
     152    uint32_t      cClrUsed;
     153    /** Number of important colors. */
     154    uint32_t      cClrImportant;
     155} BMPWIN3XINFOHDR;
     156AssertCompileSize(BMPWIN3XINFOHDR, BMP_HDR_SIZE_WIN3X);
     157/** Pointer to a Windows 3.x BMP information header. */
     158typedef BMPWIN3XINFOHDR *PBMPWIN3XINFOHDR;
    148159
    149160#pragma pack()
    150161
    151 /** BMP file magic number. */
     162/** BMP file magic number for BMP / DIB. */
    152163#define BMP_HDR_MAGIC (RT_H2LE_U16_C(0x4d42))
    153164
    154 /** @name BMP compressions.
     165/** @name BMP compression types.
    155166 * @{ . */
    156 #define BMP_COMPRESS_NONE    0
    157 #define BMP_COMPRESS_RLE8    1
    158 #define BMP_COMPRESS_RLE4    2
    159 /** @} . */
    160 
    161 /** @name BMP header sizes.
    162  * @{ . */
    163 #define BMP_HEADER_OS21      12
    164 #define BMP_HEADER_OS22      64
    165 #define BMP_HEADER_WIN3      40
     167typedef enum BMP_COMPRESSION_TYPE
     168{
     169    BMP_COMPRESSION_TYPE_NONE = 0,
     170    BMP_COMPRESSION_TYPE_RLE8 = 1,
     171    BMP_COMPRESSION_TYPE_RLE4 = 2
     172} BMP_COMPRESSION_TYPE;
    166173/** @} . */
    167174
  • trunk/src/VBox/Devices/Graphics/DevVGA-SVGA3d-info.cpp

    r85858 r85864  
    18181818    if (cbPixel == 4)
    18191819    {
    1820         BITMAPV4HEADER bh;
    1821         RT_ZERO(bh);
    1822         bh.bV4Size          = sizeof(bh);
    1823         bh.bV4Width         = w;
    1824         bh.bV4Height        = -h;
    1825         bh.bV4Planes        = 1;
    1826         bh.bV4BitCount      = 32;
    1827         bh.bV4V4Compression = BI_BITFIELDS;
    1828         bh.bV4SizeImage     = cbBitmap;
    1829         bh.bV4XPelsPerMeter = 2835;
    1830         bh.bV4YPelsPerMeter = 2835;
    1831         // bh.bV4ClrUsed       = 0;
    1832         // bh.bV4ClrImportant  = 0;
    1833         bh.bV4RedMask       = 0x00ff0000;
    1834         bh.bV4GreenMask     = 0x0000ff00;
    1835         bh.bV4BlueMask      = 0x000000ff;
    1836         bh.bV4AlphaMask     = 0xff000000;
    1837         bh.bV4CSType        = LCS_WINDOWS_COLOR_SPACE;
    1838         // bh.bV4Endpoints     = {0};
    1839         // bh.bV4GammaRed      = 0;
    1840         // bh.bV4GammaGreen    = 0;
    1841         // bh.bV4GammaBlue     = 0;
    1842 
    1843         BMPINFO bf;
    1844         RT_ZERO(bf);
    1845         bf.Type     = BMP_HDR_MAGIC;
    1846         bf.FileSize = sizeof(bf) + sizeof(bh) + cbBitmap;
    1847         bf.Offset   = sizeof(bf) + sizeof(bh);
    1848 
    1849         fwrite(&bf, 1, sizeof(bf), f);
    1850         fwrite(&bh, 1, sizeof(bh), f);
     1820        BMPFILEHDR fileHdr;
     1821        RT_ZERO(fileHdr);
     1822        fileHdr.uType       = BMP_HDR_MAGIC;
     1823        fileHdr.cbFileSize = sizeof(fileHdr) + sizeof(BITMAPV4HEADER) + cbBitmap;
     1824        fileHdr.offBits    = sizeof(fileHdr) + sizeof(BITMAPV4HEADER);
     1825
     1826        BITMAPV4HEADER hdrV4;
     1827        RT_ZERO(hdrV4);
     1828        hdrV4.bV4Size          = sizeof(hdrV4);
     1829        hdrV4.bV4Width         = w;
     1830        hdrV4.bV4Height        = -h;
     1831        hdrV4.bV4Planes        = 1;
     1832        hdrV4.bV4BitCount      = 32;
     1833        hdrV4.bV4V4Compression = BI_BITFIELDS;
     1834        hdrV4.bV4SizeImage     = cbBitmap;
     1835        hdrV4.bV4XPelsPerMeter = 2835;
     1836        hdrV4.bV4YPelsPerMeter = 2835;
     1837        // hdrV4.bV4ClrUsed       = 0;
     1838        // hdrV4.bV4ClrImportant  = 0;
     1839        hdrV4.bV4RedMask       = 0x00ff0000;
     1840        hdrV4.bV4GreenMask     = 0x0000ff00;
     1841        hdrV4.bV4BlueMask      = 0x000000ff;
     1842        hdrV4.bV4AlphaMask     = 0xff000000;
     1843        hdrV4.bV4CSType        = LCS_WINDOWS_COLOR_SPACE;
     1844        // hdrV4.bV4Endpoints     = {0};
     1845        // hdrV4.bV4GammaRed      = 0;
     1846        // hdrV4.bV4GammaGreen    = 0;
     1847        // hdrV4.bV4GammaBlue     = 0;
     1848
     1849        fwrite(&fileHdr, 1, sizeof(fileHdr), f);
     1850        fwrite(&hdrV4, 1, sizeof(hdrV4), f);
    18511851    }
    18521852    else
    18531853#endif
    18541854    {
    1855         BMPINFO bf;
    1856         RT_ZERO(bf);
    1857         bf.Type     = BMP_HDR_MAGIC;
    1858         bf.FileSize = sizeof(BMPINFO) + sizeof(WINHDR) + cbBitmap;
    1859         bf.Offset   = sizeof(BMPINFO) + sizeof(WINHDR);
    1860 
    1861         WINHDR bi;
    1862         RT_ZERO(bi);
    1863         bi.Size      = sizeof(bi);
    1864         bi.Width     = w;
    1865         bi.Height    = -h;
    1866         bi.Planes    = 1;
    1867         bi.BitCount  = 32;
    1868         bi.SizeImage = cbBitmap;
    1869 
    1870         fwrite(&bf, 1, sizeof(bf), f);
    1871         fwrite(&bi, 1, sizeof(bi), f);
     1855        BMPFILEHDR fileHdr;
     1856        RT_ZERO(fileHdr);
     1857        fileHdr.uType      = BMP_HDR_MAGIC;
     1858        fileHdr.cbFileSize = sizeof(BMPFILEHDR) + sizeof(BMPWIN3XINFOHDR) + cbBitmap;
     1859        fileHdr.offBits    = sizeof(BMPFILEHDR) + sizeof(BMPWIN3XINFOHDR);
     1860
     1861        BMPWIN3XINFOHDR coreHdr;
     1862        RT_ZERO(coreHdr);
     1863        coreHdr.cbSize      = sizeof(coreHdr);
     1864        coreHdr.uWidth      = w;
     1865        coreHdr.uHeight     = -h;
     1866        coreHdr.cPlanes     = 1;
     1867        coreHdr.cBits       = 32;
     1868        coreHdr.cbSizeImage = cbBitmap;
     1869
     1870        fwrite(&fileHdr, 1, sizeof(fileHdr), f);
     1871        fwrite(&coreHdr, 1, sizeof(coreHdr), f);
    18721872    }
    18731873
  • trunk/src/VBox/Devices/Graphics/DevVGA.cpp

    r85863 r85864  
    38713871     * Get bitmap header data
    38723872     */
    3873     PBMPINFO pBmpInfo = (PBMPINFO)(pThisCC->pbLogo + sizeof(LOGOHDR));
    3874     PWINHDR  pWinHdr  = (PWINHDR)(pThisCC->pbLogo + sizeof(LOGOHDR) + sizeof(BMPINFO));
    3875 
    3876     if (pBmpInfo->Type == BMP_HDR_MAGIC)
    3877     {
    3878         switch (pWinHdr->Size)
     3873    PBMPFILEHDR      pFileHdr = (PBMPFILEHDR)(pThisCC->pbLogo + sizeof(LOGOHDR));
     3874    PBMPWIN3XINFOHDR pCoreHdr = (PBMPWIN3XINFOHDR)(pThisCC->pbLogo + sizeof(LOGOHDR) + sizeof(BMPFILEHDR));
     3875
     3876    if (pFileHdr->uType == BMP_HDR_MAGIC)
     3877    {
     3878        switch (pCoreHdr->cbSize)
    38793879        {
    3880             case BMP_HEADER_OS21:
     3880            case BMP_HDR_SIZE_OS21:
    38813881            {
    3882                 POS2HDR pOs2Hdr = (POS2HDR)pWinHdr;
    3883                 pThisCC->cxLogo = pOs2Hdr->Width;
    3884                 pThisCC->cyLogo = pOs2Hdr->Height;
    3885                 pThisCC->cLogoPlanes = pOs2Hdr->Planes;
    3886                 pThisCC->cLogoBits = pOs2Hdr->BitCount;
    3887                 pThisCC->LogoCompression = BMP_COMPRESS_NONE;
     3882                PBMPOS2COREHDR pOs2Hdr = (PBMPOS2COREHDR)pCoreHdr;
     3883                pThisCC->cxLogo = pOs2Hdr->uWidth;
     3884                pThisCC->cyLogo = pOs2Hdr->uHeight;
     3885                pThisCC->cLogoPlanes = pOs2Hdr->cPlanes;
     3886                pThisCC->cLogoBits = pOs2Hdr->cBits;
     3887                pThisCC->LogoCompression = BMP_COMPRESSION_TYPE_NONE;
    38883888                pThisCC->cLogoUsedColors = 0;
    38893889                break;
    38903890            }
    38913891
    3892             case BMP_HEADER_OS22:
     3892            case BMP_HDR_SIZE_OS22:
    38933893            {
    3894                 POS22HDR pOs22Hdr = (POS22HDR)pWinHdr;
    3895                 pThisCC->cxLogo = pOs22Hdr->Width;
    3896                 pThisCC->cyLogo = pOs22Hdr->Height;
    3897                 pThisCC->cLogoPlanes = pOs22Hdr->Planes;
    3898                 pThisCC->cLogoBits = pOs22Hdr->BitCount;
    3899                 pThisCC->LogoCompression = pOs22Hdr->Compression;
    3900                 pThisCC->cLogoUsedColors = pOs22Hdr->ClrUsed;
     3894                PBMPOS2COREHDR2 pOs22Hdr = (PBMPOS2COREHDR2)pCoreHdr;
     3895                pThisCC->cxLogo = pOs22Hdr->uWidth;
     3896                pThisCC->cyLogo = pOs22Hdr->uHeight;
     3897                pThisCC->cLogoPlanes = pOs22Hdr->cPlanes;
     3898                pThisCC->cLogoBits = pOs22Hdr->cBits;
     3899                pThisCC->LogoCompression = pOs22Hdr->enmCompression;
     3900                pThisCC->cLogoUsedColors = pOs22Hdr->cClrUsed;
    39013901                break;
    39023902            }
    39033903
    3904             case BMP_HEADER_WIN3:
    3905                 pThisCC->cxLogo = pWinHdr->Width;
    3906                 pThisCC->cyLogo = pWinHdr->Height;
    3907                 pThisCC->cLogoPlanes = pWinHdr->Planes;
    3908                 pThisCC->cLogoBits = pWinHdr->BitCount;
    3909                 pThisCC->LogoCompression = pWinHdr->Compression;
    3910                 pThisCC->cLogoUsedColors = pWinHdr->ClrUsed;
     3904            case BMP_HDR_SIZE_WIN3X:
     3905                pThisCC->cxLogo = pCoreHdr->uWidth;
     3906                pThisCC->cyLogo = pCoreHdr->uHeight;
     3907                pThisCC->cLogoPlanes = pCoreHdr->cPlanes;
     3908                pThisCC->cLogoBits = pCoreHdr->cBits;
     3909                pThisCC->LogoCompression = pCoreHdr->enmCompression;
     3910                pThisCC->cLogoUsedColors = pCoreHdr->cClrUsed;
    39113911                break;
    39123912
    39133913            default:
    3914                 AssertLogRelMsgFailedReturn(("Unsupported bitmap header size %u.\n", pWinHdr->Size),
     3914                AssertLogRelMsgFailedReturn(("Unsupported bitmap header size %u.\n", pCoreHdr->cbSize),
    39153915                                            VERR_INVALID_PARAMETER);
    39163916                break;
     
    39333933                              VERR_INVALID_PARAMETER);
    39343934
    3935         AssertLogRelMsgReturn(pThisCC->LogoCompression == BMP_COMPRESS_NONE,
     3935        AssertLogRelMsgReturn(pThisCC->LogoCompression == BMP_COMPRESSION_TYPE_NONE,
    39363936                               ("Unsupported %u compression.\n", pThisCC->LogoCompression),
    39373937                               VERR_INVALID_PARAMETER);
     
    39473947        if (pThisCC->cLogoPalEntries)
    39483948        {
    3949             const uint8_t *pbPal = pThisCC->pbLogo + sizeof(LOGOHDR) + sizeof(BMPINFO) + pWinHdr->Size; /* ASSUMES Size location (safe) */
     3949            const uint8_t *pbPal = pThisCC->pbLogo + sizeof(LOGOHDR) + sizeof(BMPFILEHDR) + pCoreHdr->cbSize; /* ASSUMES Size location (safe) */
    39503950
    39513951            for (uint16_t i = 0; i < pThisCC->cLogoPalEntries; i++)
     
    39693969         * Bitmap data offset
    39703970         */
    3971         pThisCC->pbLogoBitmap = pThisCC->pbLogo + sizeof(LOGOHDR) + pBmpInfo->Offset;
     3971        pThisCC->pbLogoBitmap = pThisCC->pbLogo + sizeof(LOGOHDR) + pFileHdr->offBits;
    39723972    }
    39733973    else
  • trunk/src/VBox/GuestHost/SharedClipboard/clipboard-common.cpp

    r85856 r85864  
    901901    AssertPtrReturn(pcbDest, VERR_INVALID_POINTER);
    902902
    903     PWINHDR pBmpWinHdr = (PWINHDR)pvSrc;
     903    PBMPWIN3XINFOHDR coreHdr = (PBMPWIN3XINFOHDR)pvSrc;
    904904    /** @todo Support all the many versions of the DIB headers. */
    905     if (   cbSrc < sizeof(WINHDR)
    906         || RT_LE2H_U32(pBmpWinHdr->Size) < sizeof(WINHDR)
    907         || RT_LE2H_U32(pBmpWinHdr->Size) != sizeof(WINHDR))
     905    if (   cbSrc < sizeof(BMPWIN3XINFOHDR)
     906        || RT_LE2H_U32(coreHdr->cbSize) < sizeof(BMPWIN3XINFOHDR)
     907        || RT_LE2H_U32(coreHdr->cbSize) != sizeof(BMPWIN3XINFOHDR))
    908908    {
    909909        return VERR_INVALID_PARAMETER;
    910910    }
    911911
    912     size_t offPixel = sizeof(BMPINFO)
    913                     + RT_LE2H_U32(pBmpWinHdr->Size)
    914                     + RT_LE2H_U32(pBmpWinHdr->ClrUsed) * sizeof(uint32_t);
     912    size_t offPixel = sizeof(BMPFILEHDR)
     913                    + RT_LE2H_U32(coreHdr->cbSize)
     914                    + RT_LE2H_U32(coreHdr->cClrUsed) * sizeof(uint32_t);
    915915    if (cbSrc < offPixel)
    916916        return VERR_INVALID_PARAMETER;
    917917
    918     size_t cbDst = sizeof(BMPINFO) + cbSrc;
     918    size_t cbDst = sizeof(BMPFILEHDR) + cbSrc;
    919919
    920920    void *pvDest = RTMemAlloc(cbDst);
     
    922922        return VERR_NO_MEMORY;
    923923
    924     PBMPINFO pBmpHdr = (PBMPINFO)pvDest;
    925 
    926     pBmpHdr->Type        = BMP_HDR_MAGIC;
    927     pBmpHdr->FileSize    = (uint32_t)RT_H2LE_U32(cbDst);
    928     pBmpHdr->Reserved1   = pBmpHdr->Reserved2 = 0;
    929     pBmpHdr->Offset      = (uint32_t)RT_H2LE_U32(offPixel);
    930 
    931     memcpy((uint8_t *)pvDest + sizeof(BMPINFO), pvSrc, cbSrc);
     924    PBMPFILEHDR fileHdr = (PBMPFILEHDR)pvDest;
     925
     926    fileHdr->uType       = BMP_HDR_MAGIC;
     927    fileHdr->cbFileSize  = (uint32_t)RT_H2LE_U32(cbDst);
     928    fileHdr->Reserved1   = 0;
     929    fileHdr->Reserved2   = 0;
     930    fileHdr->offBits     = (uint32_t)RT_H2LE_U32(offPixel);
     931
     932    memcpy((uint8_t *)pvDest + sizeof(BMPFILEHDR), pvSrc, cbSrc);
    932933
    933934    *ppvDest = pvDest;
     
    945946    AssertPtrReturn(pcbDest, VERR_INVALID_POINTER);
    946947
    947     PBMPINFO pBmpHdr = (PBMPINFO)pvSrc;
    948     if (   cbSrc < sizeof(BMPINFO)
    949         || pBmpHdr->Type != BMP_HDR_MAGIC
    950         || RT_LE2H_U32(pBmpHdr->FileSize) != cbSrc)
     948    PBMPFILEHDR pBmpHdr = (PBMPFILEHDR)pvSrc;
     949    if (   cbSrc < sizeof(BMPFILEHDR)
     950        || pBmpHdr->uType != BMP_HDR_MAGIC
     951        || RT_LE2H_U32(pBmpHdr->cbFileSize) != cbSrc)
    951952    {
    952953        return VERR_INVALID_PARAMETER;
    953954    }
    954955
    955     *ppvDest = ((uint8_t *)pvSrc) + sizeof(BMPINFO);
    956     *pcbDest = cbSrc - sizeof(BMPINFO);
     956    *ppvDest = ((uint8_t *)pvSrc) + sizeof(BMPFILEHDR);
     957    *pcbDest = cbSrc - sizeof(BMPFILEHDR);
    957958
    958959    return VINF_SUCCESS;
  • trunk/src/VBox/Main/src-client/RecordingStream.cpp

    r85858 r85864  
    637637
    638638#ifdef VBOX_RECORDING_DUMP
    639         BMPINFO bmpHdr;
    640         RT_ZERO(bmpHdr);
    641 
    642         WINHDR bmpDIBHdr;
    643         RT_ZERO(bmpDIBHdr);
    644 
    645         bmpHdr.Type     = BMP_HDR_MAGIC;
    646         bmpHdr.FileSize = (uint32_t)(sizeof(BMPINFO) + sizeof(WINHDR) + (w * h * uBytesPerPixel));
    647         bmpHdr.Offset   = (uint32_t)(sizeof(BMPINFO) + sizeof(WINHDR));
    648 
    649         bmpDIBHdr.Size          = sizeof(WINHDR);
    650         bmpDIBHdr.Width         = w;
    651         bmpDIBHdr.Height        = h;
    652         bmpDIBHdr.Planes        = 1;
    653         bmpDIBHdr.BitCount      = uBPP;
    654         bmpDIBHdr.XPelsPerMeter = 5000;
    655         bmpDIBHdr.YPelsPerMeter = 5000;
     639        BMPFILEHDR fileHdr;
     640        RT_ZERO(fileHdr);
     641
     642        BMPWIN3XINFOHDR coreHdr;
     643        RT_ZERO(coreHdr);
     644
     645        fileHdr.uType       = BMP_HDR_MAGIC;
     646        fileHdr.cbFileSize = (uint32_t)(sizeof(BMPFILEHDR) + sizeof(BMPWIN3XINFOHDR) + (w * h * uBytesPerPixel));
     647        fileHdr.offBits    = (uint32_t)(sizeof(BMPFILEHDR) + sizeof(BMPWIN3XINFOHDR));
     648
     649        coreHdr.cbSize         = sizeof(BMPWIN3XINFOHDR);
     650        coreHdr.uWidth         = w;
     651        coreHdr.uHeight        = h;
     652        coreHdr.cPlanes        = 1;
     653        coreHdr.cBits          = uBPP;
     654        coreHdr.uXPelsPerMeter = 5000;
     655        coreHdr.uYPelsPerMeter = 5000;
    656656
    657657        char szFileName[RTPATH_MAX];
     
    663663        if (RT_SUCCESS(rc2))
    664664        {
    665             RTFileWrite(fh, &bmpHdr,    sizeof(bmpHdr),    NULL);
    666             RTFileWrite(fh, &bmpDIBHdr, sizeof(bmpDIBHdr), NULL);
     665            RTFileWrite(fh, &fileHdr,    sizeof(fileHdr),    NULL);
     666            RTFileWrite(fh, &coreHdr, sizeof(coreHdr), NULL);
    667667        }
    668668#endif
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette