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

📄 pxcgifrn.cpp

📁 linux下的一款播放器
💻 CPP
📖 第 1 页 / 共 2 页
字号:
                rImageDim.cy     = pGIFCodec->GetLogicalScreenHeight();                rulNumFrames     = pGIFCodec->GetNumImages();                rpImageInfo      = NULL;                // Create a session object                CGIFRendererSession* pSession = new CGIFRendererSession();                if (pSession)                {                    // AddRef the object                    pSession->AddRef();                    // Set the session parameters                    pSession->m_pGIFCodec   = pGIFCodec;                    pSession->m_pGIFCodec->AddRef();                    pSession->m_ulNumFrames = rulNumFrames;                    // Allocate an array of FrameInfo structs                    pSession->m_pFrameInfo  = new CGIFRendererSession::FrameInfo [rulNumFrames];                    if (pSession->m_pFrameInfo)                    {                        // NULL out the frame info structs output buffer pointers                        for (UINT32 i = 0; i < rulNumFrames; i++)                        {                            pSession->m_pFrameInfo[i].m_pOutputBuffer = NULL;                        }                        // Add this session to the map                        retVal = m_pMapManager->AddEntry((void*) pSession, rulSessionHandle);                        if (SUCCEEDED(retVal))                        {                            // AddRef the session since it's now in the map                            pSession->AddRef();                            // Create an IHXValues for the image info                            IHXValues* pImageInfo = NULL;                            m_pCommonClassFactory->CreateInstance(CLSID_IHXValues, (void**) &pImageInfo);                            if (pImageInfo)                            {                                // Set the loop count in the image info struct                                pImageInfo->SetPropertyULONG32("LoopCount", pGIFCodec->GetLoopCount());                                // Assign the out parameter                                rpImageInfo = pImageInfo;                                rpImageInfo->AddRef();                            }                            HX_RELEASE(pImageInfo);                        }                    }                    else                    {                        retVal = HXR_OUTOFMEMORY;                    }                }                else                {                    retVal = HXR_OUTOFMEMORY;                }                HX_RELEASE(pSession);            }        }        HX_RELEASE(pGIFCodec);    }    return retVal;}STDMETHODIMP CRealPixGIFRendererCodec::GetFrameInfo(UINT32           ulSessionHandle,                                                    UINT32           ulFrameNum,                                                    REF(HXxRect)     rFrameDim,                                                    REF(IHXValues*) rpMoreInfo){    HX_RESULT retVal = HXR_FAIL;    if (m_pMapManager)    {        CGIFRendererSession* pSession = NULL;        m_pMapManager->GetEntry(ulSessionHandle, (void**) &pSession);        if (pSession)        {            if (pSession->m_pGIFCodec)            {                if (ulFrameNum < pSession->m_pGIFCodec->GetNumImages())                {                    CGIFImage* pImage = pSession->m_pGIFCodec->GetImage(ulFrameNum);                    if (pImage)                    {                        // Set the frame dimensions in the session                        pSession->m_pFrameInfo[ulFrameNum].m_cFrameDim.left   = pImage->GetImageLeft();                        pSession->m_pFrameInfo[ulFrameNum].m_cFrameDim.top    = pImage->GetImageTop();                        pSession->m_pFrameInfo[ulFrameNum].m_cFrameDim.right  = pImage->GetImageLeft() +                                                                                pImage->GetImageWidth();                        pSession->m_pFrameInfo[ulFrameNum].m_cFrameDim.bottom = pImage->GetImageTop() +                                                                                pImage->GetImageHeight();                        // Set the outgoing frame dimensions                        rFrameDim = pSession->m_pFrameInfo[ulFrameNum].m_cFrameDim;                        // Create an IHXValues                        IHXValues* pValues = NULL;                        retVal              = m_pCommonClassFactory->CreateInstance(CLSID_IHXValues,                                                                                    (void**) &pValues);                        if (pValues)                        {                            pValues->SetPropertyULONG32("DelayTime",        pImage->GetDelayTime());                            pValues->SetPropertyULONG32("DisposalMethod",   pImage->GetDisposalMethod());			    pValues->SetPropertyULONG32("UsesAlphaChannel", (pImage->Transparent() ? 1 : 0));                            // Set the outgoing parameter                            HX_RELEASE(rpMoreInfo);                            rpMoreInfo = pValues;                            rpMoreInfo->AddRef();                            retVal = HXR_OK;                        }                        HX_RELEASE(pValues);                    }                }            }        }    }    return retVal;}STDMETHODIMP CRealPixGIFRendererCodec::SetDecompressParam(UINT32      ulSessionHandle,                                                          UINT32      ulFrameNum,                                                          IHXBuffer* pOutputBuffer,                                                          HXxSize     cFrameDim,                                                          UINT32      ulRowStride,                                                          UINT32      ulBitsPerPixel,                                                          UINT32      ulColorFormat,                                                          BOOL        bRowsInverted,                                                          IHXValues* pMoreParam){    HX_RESULT retVal = HXR_FAIL;    if (m_pMapManager)    {        CGIFRendererSession* pSession = NULL;        m_pMapManager->GetEntry(ulSessionHandle, (void**) &pSession);        if (pSession)        {            if (ulFrameNum < pSession->m_ulNumFrames &&                pOutputBuffer                        &&                ulBitsPerPixel == 32                 &&                ulColorFormat == HX_RGB)            {                if (pSession->m_pGIFCodec)                {                    if (ulFrameNum < pSession->m_pGIFCodec->GetNumImages())                    {                        CGIFImage* pImage = pSession->m_pGIFCodec->GetImage(ulFrameNum);                        if (pImage)                        {                            if (cFrameDim.cx == HXxRECT_WIDTH(pSession->m_pFrameInfo[ulFrameNum].m_cFrameDim) &&                                cFrameDim.cy == HXxRECT_HEIGHT(pSession->m_pFrameInfo[ulFrameNum].m_cFrameDim))                            {                                // Set the frame parameters                                pSession->m_pFrameInfo[ulFrameNum].m_pOutputBuffer  = pOutputBuffer;                                pSession->m_pFrameInfo[ulFrameNum].m_ulRowStride    = ulRowStride;                                pSession->m_pFrameInfo[ulFrameNum].m_ulBitsPerPixel = ulBitsPerPixel;                                pSession->m_pFrameInfo[ulFrameNum].m_ulColorFormat  = ulColorFormat;                                pSession->m_pFrameInfo[ulFrameNum].m_bRowsInverted  = bRowsInverted;                                // Addref the output buffer                                pSession->m_pFrameInfo[ulFrameNum].m_pOutputBuffer->AddRef();                                retVal = HXR_OK;                            }                        }                    }                }            }        }    }    return retVal;}STDMETHODIMP CRealPixGIFRendererCodec::Decompress(UINT32      ulSessionHandle,                                                  IHXBuffer* pBuffer,                                                  IHXBuffer* pOpaquePacketData){    HX_RESULT retVal = HXR_OK;    if (m_pMapManager)    {        CGIFRendererSession* pSession = NULL;        retVal = m_pMapManager->GetEntry(ulSessionHandle, (void**) &pSession);        if (SUCCEEDED(retVal))        {            if (pBuffer && pOpaquePacketData && pSession->m_pGIFCodec)            {                if (pSession->m_pGIFCodec->GetValid())                {                    if (pSession->m_pGIFCodec->GetNeedPacket())                    {                        if (!pSession->m_pGIFCodec->DecompressFinished())                        {                            BYTE* pBuf = pOpaquePacketData->GetBuffer();                            if (pBuf)                            {                                // Unpack seq num                                UINT32 ulSeqNum = 0;                                UnPack32(pBuf, ulSeqNum);                                // Unpack flags                                UINT32 ulFlags = 0;                                UnPack32(pBuf, ulFlags);                                // Recover the "new frame" flag                                BOOL bNewImage = (ulFlags & 1 ? TRUE : FALSE);                                // Decompress this buffer                                retVal = pSession->m_pGIFCodec->Decompress(pBuffer->GetBuffer(),                                                                           pBuffer->GetSize(),                                                                           bNewImage);                                if (SUCCEEDED(retVal))                                {                                    if (pSession->m_pGIFCodec->DecompressFinished())                                    {                                        for (UINT32 i = 0; i < pSession->m_ulNumFrames; i++)                                        {                                            retVal = pSession->m_pGIFCodec->GetRGB32(i,                                                                                     pSession->m_pFrameInfo[i].m_pOutputBuffer->GetBuffer(),                                                                                     pSession->m_pFrameInfo[i].m_ulRowStride,                                                                                     pSession->m_pFrameInfo[i].m_bRowsInverted);                                            if (FAILED(retVal))                                            {                                                break;                                            }                                        }                                    }                                }                            }                            else                            {                                retVal = HXR_FAIL;                            }                        }                    }                    else                    {                        pSession->m_pGIFCodec->SetNeedPacket(TRUE);                    }                }            }            else            {                retVal = HXR_FAIL;            }        }    }    else    {        retVal = HXR_UNEXPECTED;    }    return retVal;}STDMETHODIMP CRealPixGIFRendererCodec::GetDecompressStatus(UINT32     ulSessionHandle,                                                           REF(INT32) rlStatus){    HX_RESULT retVal = HXR_FAIL;    if (m_pMapManager)    {        CGIFRendererSession* pSession = NULL;        retVal                        = m_pMapManager->GetEntry(ulSessionHandle, (void**) &pSession);        if (SUCCEEDED(retVal))        {            if (pSession->m_pGIFCodec)            {                if (pSession->m_pGIFCodec->GetValid())                {                    if (pSession->m_pGIFCodec->DecompressFinished())                    {                        rlStatus = DECOMPRESS_STATUS_FINISHED;                    }                    else                    {                        rlStatus = DECOMPRESS_STATUS_INPROGRESS;                    }                }                else                {                    rlStatus = DECOMPRESS_STATUS_ABORTED;                }            }            else            {                retVal = HXR_FAIL;            }        }    }    return retVal;}STDMETHODIMP CRealPixGIFRendererCodec::FinishDecompress(UINT32 ulSessionHandle){    HX_RESULT retVal = HXR_FAIL;    if (m_pMapManager)    {        CGIFRendererSession* pSession = NULL;        retVal = m_pMapManager->DeleteEntry(ulSessionHandle, (void**) &pSession);        HX_RELEASE(pSession);    }    return retVal;}HX_RESULT STDAPICALLTYPE CRealPixGIFRendererCodec::HXCreateInstance(IUnknown** ppIUnknown){    HX_RESULT retVal = HXR_OK;    if (ppIUnknown)    {        // Create renderer codec        CRealPixGIFRendererCodec* pCodec = new CRealPixGIFRendererCodec();        if (pCodec)        {            // QI for IUnknown            retVal = pCodec->QueryInterface(IID_IUnknown, (void**) ppIUnknown);        }        else        {            retVal = HXR_OUTOFMEMORY;        }        if (FAILED(retVal))        {            HX_DELETE(pCodec);        }    }    else    {        retVal = HXR_FAIL;    }    return retVal;}void CRealPixGIFRendererCodec::ReleaseAllSessions(){    if (m_pMapManager)    {        UINT32               ulHandle = 0;        CGIFRendererSession* pSession = NULL;        HX_RESULT            retVal   = m_pMapManager->GetFirstEntry(ulHandle, (void**) &pSession);        while (SUCCEEDED(retVal))        {            HX_RELEASE(pSession);            retVal = m_pMapManager->GetNextEntry(ulHandle, (void**) &pSession);        }        m_pMapManager->DeleteAllEntries();    }}

⌨️ 快捷键说明

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