⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 imagemgr.cpp

📁 linux下的一款播放器
💻 CPP
📖 第 1 页 / 共 4 页
字号:
                // Now we'll just try to find an unused one (minimum bytes = 0)                retVal = ChooseScratchBuffer(0, &pBuffer, &bFound);                if (SUCCEEDED(retVal))                {                    if (bFound)                    {                        // We found one that's not being used, but it's too small, so                        // let's realloc it to make it bigger.                        //                        // XXXMEH - Weird bug here - CHXBuffer only allows you do change                        // the size of the buffer IF AND ONLY IF the ref count is                        // one. Well, since we know we got this buffer from the list                        // we KNOW that the only refs on it are the list's and the                        // local one here. Sooooo, we artificially set the ref count                        // down and then up.                        UINT32 ulRefCount = pBuffer->Release();                        HX_ASSERT(ulRefCount == 1);                        retVal = pBuffer->SetSize(ulNumBytesNeeded);                        pBuffer->AddRef();#ifdef XXXMEH_DEBUG_LOG                        DEBUG_OUTF("c:\\realpix.log",                                   (s, "PXImageManager::GetScratchBuffer(%lu,0x%08x) - found unused existing buffer - RESIZED\n",                                   ulNumBytesNeeded, ppBuffer));#endif                    }                    else                    {                        // Well, we still haven't found one, so we'll have                        // to create one and add it to the list                        //                        /* Create an IHXBuffer */                        if (m_pCCF)                        {                               IUnknown* pUnk = NULL;                            m_pCCF->CreateInstance(CLSID_IHXBuffer, (void**)&pUnk);                            if (pUnk)                            {                                pUnk->QueryInterface(IID_IHXBuffer, (void**)&pBuffer);                            }                            HX_RELEASE(pUnk);                        }                           if (pBuffer)                        {                            // Set the size of the buffer                            retVal = pBuffer->SetSize(ulNumBytesNeeded);                            if (SUCCEEDED(retVal))                            {                                // Addref the object before adding it to the list                                pBuffer->AddRef();                                // Add the image to the scratch image list                                m_pScratchBufferList->AddTail((void*) pBuffer);#ifdef XXXMEH_DEBUG_LOG                                DEBUG_OUTF("c:\\realpix.log",                                           (s, "PXImageManager::GetScratchBuffer(%lu,0x%08x) - new buffer added to list\n",                                           ulNumBytesNeeded, ppBuffer));#endif                            }                        }                        else                        {                            retVal = HXR_OUTOFMEMORY;                        }                    }                }            }            else            {#ifdef XXXMEH_DEBUG_LOG                DEBUG_OUTF("c:\\realpix.log",                           (s, "PXImageManager::GetScratchBuffer(%lu,0x%08x) - found unused existing buffer with required size\n",                           ulNumBytesNeeded, ppBuffer));#endif            }        }    }    else    {        retVal = HXR_INVALID_PARAMETER;    }    // Assign the out parameter    if (SUCCEEDED(retVal))    {        *ppBuffer = pBuffer;        (*ppBuffer)->AddRef();    }    // Release local refs    HX_RELEASE(pBuffer);#ifdef XXXMEH_DEBUG_ASSERT    // Debug-only assert    HX_ASSERT(SUCCEEDED(retVal));#endif    return retVal;}HX_RESULT PXImageManager::GetImageHelper(UINT32 ulHandle, PXImageHelper** ppHelper){    HX_RESULT retVal = HXR_OK;    if (ulHandle && ppHelper)    {        if (m_pHandleToImageMap)        {            // Set out parameter default            *ppHelper = NULL;            // Check to see if there really is an entry for this handle            void* pVoid         = NULL;            BOOL  bEntryPresent = m_pHandleToImageMap->Lookup((LONG32) ulHandle, pVoid);            if (bEntryPresent)            {                // Get the helper object                *ppHelper = (PXImageHelper*) pVoid;                // Addref it before it leaves                (*ppHelper)->AddRef();            }            else            {                retVal = HXR_FAIL;            }        }        else        {            retVal = HXR_NOT_INITIALIZED;        }    }    else    {        retVal = HXR_INVALID_PARAMETER;    }    return retVal;}HX_RESULT PXImageManager::ChooseScratchBuffer(UINT32 ulMinBytes, IHXBuffer** ppBuffer, BOOL* pbFound){    HX_RESULT retVal = HXR_OK;    if (ppBuffer && pbFound)    {        if (m_pScratchBufferList)        {            // Run through the current list of scratch buffers, and try            // to find one with a ref count < 2 (not currently being used by anybody            // else) AND enough space            *pbFound         = FALSE;            LISTPOSITION pos = m_pScratchBufferList->GetHeadPosition();            while (pos)            {                IHXBuffer* pBuffer = (IHXBuffer*) m_pScratchBufferList->GetNext(pos);                if (pBuffer)                {                    if (GET_REFCOUNT(pBuffer) < 2 && pBuffer->GetSize() >= ulMinBytes)                    {                        *ppBuffer = pBuffer;                        (*ppBuffer)->AddRef();                        *pbFound = TRUE;                        break;                    }                }            }        }        else        {            retVal = HXR_NOT_INITIALIZED;        }    }    else    {        retVal = HXR_INVALID_PARAMETER;    }#ifdef XXXMEH_DEBUG_ASSERT    // Debug-only assert    HX_ASSERT(SUCCEEDED(retVal));#endif    return retVal;}UINT32 PXImageManager::GetMaxChannelDepth() const{    UINT32 ulRetVal = 0;    switch (m_ulDefaultBitsPerPixel)    {        case 16:            if (m_ulDefaultPixelFormat == HXCOLOR_RGB565_ID)            {                ulRetVal = 6;            }            else if (m_ulDefaultPixelFormat == HXCOLOR_RGB555_ID)            {                ulRetVal = 5;            }            break;        case 24:        case 32:            ulRetVal = 8;            break;        default:            break;    }    return ulRetVal;}HX_RESULT PXImageManager::PacketLost(){    return HXR_OK;}void PXImageManager::ReleaseScratchBuffers(){    if (m_pScratchBufferList)    {        // Run through the map, deleting all buffer objects        POSITION pos = m_pScratchBufferList->GetHeadPosition();        while (pos)        {            // Get the pointer to the next image            IHXBuffer* pBuffer = (IHXBuffer*) m_pScratchBufferList->GetNext(pos);            // Release the image            HX_RELEASE(pBuffer);        }        // Clear the list        m_pScratchBufferList->RemoveAll();    }}void PXImageManager::Reset(){    m_ulDisplayWidth        = 0;    m_ulDisplayHeight       = 0;    m_ulDefaultBitsPerPixel = 32;    m_ulDefaultPixelFormat  = HX_RGB;    m_bDefaultRowsInverted  = FALSE;    m_ulBackgroundColor     = 0;    m_ulBackgroundOpacity   = 255;}void PXImageManager::Deallocate(){    HX_RELEASE(m_pCodecManager);    HX_RELEASE(m_pErrorMessages);    HX_RELEASE(m_pCCF);    HX_RELEASE(m_pDisplayImage);    ReleasePresentationImages();    ReleaseScratchBuffers();    HX_DELETE(m_pHandleToImageMap);    HX_DELETE(m_pScratchBufferList);}HX_RESULT PXImageManager::ResolveAspectRatio(const PXRect& rSrc, const PXRect& rDst,                                             PXRect& rNewDst, PXRect& rEmpty1, PXRect& rEmpty2,                                             BOOL bRelativeToDst){    HXxRect cSrc, cDst, cNew, cEmp1, cEmp2;    CONVERT_PXRECT_TO_PNxRECT(rSrc, cSrc);    CONVERT_PXRECT_TO_PNxRECT(rDst, cDst);    HX_RESULT retVal = ResolveAspectRatio(cSrc, cDst, cNew, cEmp1, cEmp2, bRelativeToDst);    CONVERT_PNxRECT_TO_PXRECT(rNewDst, cNew);    CONVERT_PNxRECT_TO_PXRECT(rEmpty1, cEmp1);    CONVERT_PNxRECT_TO_PXRECT(rEmpty2, cEmp2);    return retVal;}HX_RESULT PXImageManager::ResolveAspectRatio(const HXxRect& rSrc, const HXxRect& rDst,                                             HXxRect& rNewDst, HXxRect& rEmpty1, HXxRect& rEmpty2,                                             BOOL bRelativeToDst){    HX_RESULT retVal = HXR_OK;    if (rSrc.right > rSrc.left && rSrc.bottom > rSrc.top &&        rDst.right > rDst.left && rDst.bottom > rDst.top)    {        INT32 lSrcW = HXxRECT_WIDTH(rSrc);        INT32 lSrcH = HXxRECT_HEIGHT(rSrc);        INT32 lDstW = HXxRECT_WIDTH(rDst);        INT32 lDstH = HXxRECT_HEIGHT(rDst);        INT32 lModW = 0;        INT32 lModH = 0;        if (lSrcW * lDstH > lSrcH * lDstW)        {            lModW          = lDstW;            lModH          = lSrcH * lDstW / lSrcW;            rNewDst.left   = rDst.left;            rNewDst.top    = rDst.top + (lDstH >> 1) - (lModH >> 1);            rNewDst.right  = rDst.right;            rNewDst.bottom = rNewDst.top + lModH;            rEmpty1.left   = rDst.left;            rEmpty1.top    = rDst.top;            rEmpty1.right  = rDst.right;            rEmpty1.bottom = rNewDst.top;            rEmpty2.left   = rDst.left;            rEmpty2.top    = rNewDst.bottom;            rEmpty2.right  = rDst.right;            rEmpty2.bottom = rDst.bottom;        }        else        {            lModW          = lSrcW * lDstH / lSrcH;            lModH          = lDstH;            rNewDst.left   = rDst.left + (lDstW >> 1) - (lModW >> 1);            rNewDst.top    = rDst.top;            rNewDst.right  = rNewDst.left + lModW;            rNewDst.bottom = rDst.bottom;            rEmpty1.left   = rDst.left;            rEmpty1.top    = rDst.top;            rEmpty1.right  = rNewDst.left;            rEmpty1.bottom = rDst.bottom;            rEmpty2.left   = rNewDst.right;            rEmpty2.top    = rDst.top;            rEmpty2.right  = rDst.right;            rEmpty2.bottom = rDst.bottom;        }    }    else    {        retVal = HXR_INVALID_PARAMETER;    }    if (bRelativeToDst)    {        rNewDst.left   -= rDst.left;        rNewDst.top    -= rDst.top;        rNewDst.right  -= rDst.left;        rNewDst.bottom -= rDst.top;        rEmpty1.left   -= rDst.left;        rEmpty1.top    -= rDst.top;        rEmpty1.right  -= rDst.left;        rEmpty1.bottom -= rDst.top;        rEmpty2.left   -= rDst.left;        rEmpty2.top    -= rDst.top;        rEmpty2.right  -= rDst.left;        rEmpty2.bottom -= rDst.top;    }    return retVal;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -