VirtualBox

Changeset 52958 in vbox for trunk/src/VBox/Main/src-server


Ignore:
Timestamp:
Oct 6, 2014 5:57:01 PM (10 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
96400
Message:

Main: merged IMachine::readSavedThumbnailToArray and readSavedThumbnailPNGToArray

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-server/MachineImpl.cpp

    r52934 r52958  
    63066306}
    63076307
    6308 
    6309 HRESULT Machine::readSavedThumbnailToArray(ULONG aScreenId, BOOL aBGR, ULONG *aWidth, ULONG *aHeight, std::vector<BYTE> &aData)
     6308HRESULT Machine::readSavedThumbnailToArray(ULONG aScreenId, BitmapFormat_T aBitmapFormat,
     6309                                          ULONG *aWidth, ULONG *aHeight, std::vector<BYTE> &aData)
    63106310{
    63116311    if (aScreenId != 0)
    63126312        return E_NOTIMPL;
     6313
     6314    if (   aBitmapFormat != BitmapFormat_BGR0
     6315        && aBitmapFormat != BitmapFormat_BGRA
     6316        && aBitmapFormat != BitmapFormat_RGBA
     6317        && aBitmapFormat != BitmapFormat_PNG)
     6318        return setError(E_NOTIMPL,
     6319                        tr("Unsupported saved thumbnail format 0x%08X"), aBitmapFormat);
    63136320
    63146321    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     
    63236330    if (RT_FAILURE(vrc))
    63246331        return setError(VBOX_E_IPRT_ERROR,
    6325                         tr("Saved screenshot data is not available (%Rrc)"),
     6332                        tr("Saved thumbnail data is not available (%Rrc)"),
    63266333                        vrc);
     6334
     6335    HRESULT hr = S_OK;
    63276336
    63286337    *aWidth = u32Width;
    63296338    *aHeight = u32Height;
    63306339
    6331     aData.resize(cbData);
    6332     /* Convert pixels to format expected by the API caller. */
    6333     if (aBGR)
    6334     {
    6335         /* [0] B, [1] G, [2] R, [3] A. */
    6336         for (unsigned i = 0; i < cbData; i += 4)
    6337         {
    6338             aData[i]     = pu8Data[i];
    6339             aData[i + 1] = pu8Data[i + 1];
    6340             aData[i + 2] = pu8Data[i + 2];
    6341             aData[i + 3] = 0xff;
    6342         }
    6343     }
    6344     else
    6345     {
    6346         /* [0] R, [1] G, [2] B, [3] A. */
    6347         for (unsigned i = 0; i < cbData; i += 4)
    6348         {
    6349             aData[i]     = pu8Data[i + 2];
    6350             aData[i + 1] = pu8Data[i + 1];
    6351             aData[i + 2] = pu8Data[i];
    6352             aData[i + 3] = 0xff;
     6340    if (cbData > 0)
     6341    {
     6342        /* Convert pixels to the format expected by the API caller. */
     6343        if (aBitmapFormat == BitmapFormat_BGR0)
     6344        {
     6345            /* [0] B, [1] G, [2] R, [3] 0. */
     6346            aData.resize(cbData);
     6347            memcpy(&aData.front(), pu8Data, cbData);
     6348        }
     6349        else if (aBitmapFormat == BitmapFormat_BGRA)
     6350        {
     6351            /* [0] B, [1] G, [2] R, [3] A. */
     6352            aData.resize(cbData);
     6353            for (uint32_t i = 0; i < cbData; i += 4)
     6354            {
     6355                aData[i]     = pu8Data[i];
     6356                aData[i + 1] = pu8Data[i + 1];
     6357                aData[i + 2] = pu8Data[i + 2];
     6358                aData[i + 3] = 0xff;
     6359            }
     6360        }
     6361        else if (aBitmapFormat == BitmapFormat_RGBA)
     6362        {
     6363            /* [0] R, [1] G, [2] B, [3] A. */
     6364            aData.resize(cbData);
     6365            for (uint32_t i = 0; i < cbData; i += 4)
     6366            {
     6367                aData[i]     = pu8Data[i + 2];
     6368                aData[i + 1] = pu8Data[i + 1];
     6369                aData[i + 2] = pu8Data[i];
     6370                aData[i + 3] = 0xff;
     6371            }
     6372        }
     6373        else if (aBitmapFormat == BitmapFormat_PNG)
     6374        {
     6375            uint8_t *pu8PNG = NULL;
     6376            uint32_t cbPNG = 0;
     6377            uint32_t cxPNG = 0;
     6378            uint32_t cyPNG = 0;
     6379
     6380            vrc = DisplayMakePNG(pu8Data, u32Width, u32Height, &pu8PNG, &cbPNG, &cxPNG, &cyPNG, 0);
     6381
     6382            if (RT_SUCCESS(vrc))
     6383            {
     6384                aData.resize(cbPNG);
     6385                if (cbPNG)
     6386                    memcpy(&aData.front(), pu8PNG, cbPNG);
     6387            }
     6388            else
     6389                hr = setError(VBOX_E_IPRT_ERROR,
     6390                              tr("Could not convert saved thumbnail to PNG (%Rrc)"),
     6391                              vrc);
     6392
     6393            RTMemFree(pu8PNG);
    63536394        }
    63546395    }
     
    63566397    freeSavedDisplayScreenshot(pu8Data);
    63576398
    6358     return S_OK;
    6359 }
    6360 
    6361 HRESULT Machine::readSavedThumbnailPNGToArray(ULONG aScreenId, ULONG *aWidth, ULONG *aHeight, std::vector<BYTE> &aData)
    6362 {
    6363     if (aScreenId != 0)
    6364         return E_NOTIMPL;
    6365 
    6366     AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    6367 
    6368     uint8_t *pu8Data = NULL;
    6369     uint32_t cbData = 0;
    6370     uint32_t u32Width = 0;
    6371     uint32_t u32Height = 0;
    6372 
    6373     int vrc = readSavedDisplayScreenshot(mSSData->strStateFilePath, 0 /* u32Type */, &pu8Data, &cbData, &u32Width, &u32Height);
    6374 
    6375     if (RT_FAILURE(vrc))
    6376         return setError(VBOX_E_IPRT_ERROR,
    6377                         tr("Saved screenshot data is not available (%Rrc)"),
    6378                         vrc);
    6379 
    6380     *aWidth = u32Width;
    6381     *aHeight = u32Height;
    6382 
    6383     HRESULT rc = S_OK;
    6384     uint8_t *pu8PNG = NULL;
    6385     uint32_t cbPNG = 0;
    6386     uint32_t cxPNG = 0;
    6387     uint32_t cyPNG = 0;
    6388 
    6389     vrc = DisplayMakePNG(pu8Data, u32Width, u32Height, &pu8PNG, &cbPNG, &cxPNG, &cyPNG, 0);
    6390 
    6391     if (RT_SUCCESS(vrc))
    6392     {
    6393         aData.resize(cbPNG);
    6394         if (cbPNG)
    6395             memcpy(&aData.front(), pu8PNG, cbPNG);
    6396         if (pu8PNG)
    6397             RTMemFree(pu8PNG);
    6398     }
    6399     else
    6400     {
    6401         if (pu8PNG)
    6402             RTMemFree(pu8PNG);
    6403         return setError(VBOX_E_IPRT_ERROR,
    6404                         tr("Could not convert screenshot to PNG (%Rrc)"),
    6405                         vrc);
    6406     }
    6407 
    6408     freeSavedDisplayScreenshot(pu8Data);
    6409 
    6410     return rc;
     6399    return hr;
    64116400}
    64126401
Note: See TracChangeset for help on using the changeset viewer.

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