- Timestamp:
- May 8, 2012 3:06:18 PM (13 years ago)
- Location:
- trunk/src/VBox
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/GuestHost/SharedClipboard/clipboard-helper.cpp
r41083 r41210 6 6 /* 7 7 * Copyright (C) 2006-2008 Oracle Corporation 8 * Copyright (C) 2012 François Revol 8 9 * 9 10 * This file is part of VirtualBox Open Source Edition (OSE), as … … 265 266 } 266 267 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) || 268 int 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; 277 280 /** @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")); 281 286 return VERR_INVALID_PARAMETER; 282 287 } 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")); 289 295 return VERR_INVALID_PARAMETER; 290 296 } 291 297 292 dest = RTMemAlloc(cb);293 if ( dest == NULL)294 { 295 Log 298 pvDest = RTMemAlloc(cb); 299 if (!pvDest) 300 { 301 Log(("writeToPasteboard: cannot allocate memory for bitmap.\n")); 296 302 return VERR_NO_MEMORY; 297 303 } 298 304 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 *pp Dest = 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; 306 312 *pcbDest = cb; 307 313 return VINF_SUCCESS; 308 314 } 309 315 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")); 316 int 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")); 319 328 return VERR_INVALID_PARAMETER; 320 329 } 321 *pDest = ((uint8_t *)pSrc) + sizeof(BMFILEHEADER); 330 331 *ppvDest = ((uint8_t *)pvSrc) + sizeof(BMFILEHEADER); 322 332 *pcbDest = cbSrc - sizeof(BMFILEHEADER); 323 333 return VINF_SUCCESS; -
trunk/src/VBox/HostServices/SharedClipboard/darwin-pasteboard.cpp
r41183 r41210 6 6 /* 7 7 * Copyright (C) 2008-2012 Oracle Corporation 8 * Copyright (C) 2012 François Revol 8 9 * 9 10 * This file is part of VirtualBox Open Source Edition (OSE), as
Note:
See TracChangeset
for help on using the changeset viewer.