VirtualBox

Changeset 41210 in vbox


Ignore:
Timestamp:
May 8, 2012 3:06:18 PM (13 years ago)
Author:
vboxsync
Message:

GuestHost, HostService: darwin bitmap support, copyright header and some cleanups.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/GuestHost/clipboard-helper.h

    r41086 r41210  
    145145 * @param   pcbDest       Pointer to the size of the buffer for the destination data in bytes
    146146 */
    147 int vboxClipboardDibToBmp(const void *pSrc, size_t cbSrc, void **ppDest, size_t *pcbDest);
     147int vboxClipboardDibToBmp(const void *pvSrc, size_t cbSrc, void **ppvDest, size_t *pcbDest);
    148148
    149149/**
     
    158158 * @param   pcbDest       Pointer to the size of the destination data in bytes
    159159 */
    160 int vboxClipboardBmpGetDib(const void *pSrc, size_t cbSrc, const void **ppDest, size_t *pcbDest);
     160int vboxClipboardBmpGetDib(const void *pvSrc, size_t cbSrc, const void **ppvDest, size_t *pcbDest);
    161161
    162162
  • trunk/src/VBox/GuestHost/SharedClipboard/clipboard-helper.cpp

    r41083 r41210  
    66/*
    77 * Copyright (C) 2006-2008 Oracle Corporation
     8 * Copyright (C) 2012 François Revol
    89 *
    910 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    265266}
    266267
    267 int vboxClipboardDibToBmp(const void *pSrc, size_t cbSrc, void **ppDest, size_t *pcbDest)
    268 {
    269     size_t cb = sizeof(BMFILEHEADER) + cbSrc;
    270     PBMFILEHEADER pFileHeader;
    271     void *dest;
    272     size_t pixelOffset;
    273 
    274     PBMINFOHEADER pBitmapInfoHeader = (PBMINFOHEADER)pSrc;
    275     if (cbSrc < sizeof(BMINFOHEADER) ||
    276         RT_LE2H_U32(pBitmapInfoHeader->u32Size) < sizeof(BMINFOHEADER) ||
     268int vboxClipboardDibToBmp(const void *pvSrc, size_t cbSrc, void **ppvDest, size_t *pcbDest)
     269{
     270    size_t        cb            = sizeof(BMFILEHEADER) + cbSrc;
     271    PBMFILEHEADER pFileHeader   = NULL;
     272    void         *pvDest        = NULL;
     273    size_t        offPixel      = 0;
     274
     275    AssertPtrReturn(pvSrc,   VERR_INVALID_PARAMETER);
     276    AssertPtrReturn(ppvDest, VERR_INVALID_PARAMETER);
     277    AssertPtrReturn(pcbDest, VERR_INVALID_PARAMETER);
     278
     279    PBMINFOHEADER pBitmapInfoHeader = (PBMINFOHEADER)pvSrc;
    277280    /** @todo Support all the many versions of the DIB headers. */
    278         RT_LE2H_U32(pBitmapInfoHeader->u32Size) != sizeof(BMINFOHEADER))
    279     {
    280         Log (("vboxClipboardDibToBmp: invalid or unsupported bitmap data.\n"));
     281    if (   cbSrc < sizeof(BMINFOHEADER)
     282        || RT_LE2H_U32(pBitmapInfoHeader->u32Size) < sizeof(BMINFOHEADER)
     283        || RT_LE2H_U32(pBitmapInfoHeader->u32Size) != sizeof(BMINFOHEADER))
     284    {
     285        Log(("vboxClipboardDibToBmp: invalid or unsupported bitmap data.\n"));
    281286        return VERR_INVALID_PARAMETER;
    282287    }
    283     pixelOffset = sizeof(BMFILEHEADER)
    284         + RT_LE2H_U32(pBitmapInfoHeader->u32Size)
    285         + RT_LE2H_U32(pBitmapInfoHeader->u32ClrUsed) * sizeof(uint32_t);
    286     if (cbSrc < pixelOffset)
    287     {
    288         Log (("vboxClipboardDibToBmp: invalid bitmap data.\n"));
     288
     289    offPixel = sizeof(BMFILEHEADER)
     290                + RT_LE2H_U32(pBitmapInfoHeader->u32Size)
     291                + RT_LE2H_U32(pBitmapInfoHeader->u32ClrUsed) * sizeof(uint32_t);
     292    if (cbSrc < offPixel)
     293    {
     294        Log(("vboxClipboardDibToBmp: invalid bitmap data.\n"));
    289295        return VERR_INVALID_PARAMETER;
    290296    }
    291297
    292     dest = RTMemAlloc(cb);
    293     if (dest == NULL)
    294     {
    295         Log (("writeToPasteboard: cannot allocate memory for bitmap.\n"));
     298    pvDest = RTMemAlloc(cb);
     299    if (!pvDest)
     300    {
     301        Log(("writeToPasteboard: cannot allocate memory for bitmap.\n"));
    296302        return VERR_NO_MEMORY;
    297303    }
    298304
    299     pFileHeader = (PBMFILEHEADER)dest;
    300     pFileHeader->u16Type = BITMAPHEADERMAGIC;
    301     pFileHeader->u32Size = RT_H2LE_U32(cb);
    302     pFileHeader->u16Reserved1 = pFileHeader->u16Reserved2 = 0;
    303     pFileHeader->u32OffBits = RT_H2LE_U32(pixelOffset);
    304     memcpy((uint8_t *)dest + sizeof(BMFILEHEADER), pSrc, cbSrc);
    305     *ppDest = dest;
     305    pFileHeader = (PBMFILEHEADER)pvDest;
     306    pFileHeader->u16Type        = BITMAPHEADERMAGIC;
     307    pFileHeader->u32Size        = RT_H2LE_U32(cb);
     308    pFileHeader->u16Reserved1   = pFileHeader->u16Reserved2 = 0;
     309    pFileHeader->u32OffBits     = RT_H2LE_U32(offPixel);
     310    memcpy((uint8_t *)pvDest + sizeof(BMFILEHEADER), pvSrc, cbSrc);
     311    *ppvDest = pvDest;
    306312    *pcbDest = cb;
    307313    return VINF_SUCCESS;
    308314}
    309315
    310 int vboxClipboardBmpGetDib(const void *pSrc, size_t cbSrc, const void **pDest, size_t *pcbDest)
    311 {
    312     PBMFILEHEADER pFileHeader = (PBMFILEHEADER)pSrc;
    313 
    314     if (pFileHeader == NULL || cbSrc < sizeof(BMFILEHEADER) ||
    315         pFileHeader->u16Type != BITMAPHEADERMAGIC ||
    316         RT_LE2H_U32(pFileHeader->u32Size) != cbSrc)
    317     {
    318         Log (("vboxClipboardBmpGetDib: invalid bitmap data.\n"));
     316int vboxClipboardBmpGetDib(const void *pvSrc, size_t cbSrc, const void **ppvDest, size_t *pcbDest)
     317{
     318    AssertPtrReturn(pvSrc,   VERR_INVALID_PARAMETER);
     319    AssertPtrReturn(ppvDest, VERR_INVALID_PARAMETER);
     320    AssertPtrReturn(pcbDest, VERR_INVALID_PARAMETER);
     321
     322    PBMFILEHEADER pFileHeader = (PBMFILEHEADER)pvSrc;
     323    if (   cbSrc < sizeof(BMFILEHEADER)
     324        || pFileHeader->u16Type != BITMAPHEADERMAGIC
     325        || RT_LE2H_U32(pFileHeader->u32Size) != cbSrc)
     326    {
     327        Log(("vboxClipboardBmpGetDib: invalid bitmap data.\n"));
    319328        return VERR_INVALID_PARAMETER;
    320329    }
    321     *pDest = ((uint8_t *)pSrc) + sizeof(BMFILEHEADER);
     330
     331    *ppvDest = ((uint8_t *)pvSrc) + sizeof(BMFILEHEADER);
    322332    *pcbDest = cbSrc - sizeof(BMFILEHEADER);
    323333    return VINF_SUCCESS;
  • trunk/src/VBox/HostServices/SharedClipboard/darwin-pasteboard.cpp

    r41183 r41210  
    66/*
    77 * Copyright (C) 2008-2012 Oracle Corporation
     8 * Copyright (C) 2012 François Revol
    89 *
    910 * This file is part of VirtualBox Open Source Edition (OSE), as
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