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

📄 pxjpgrnd.cpp

📁 linux下的一款播放器
💻 CPP
📖 第 1 页 / 共 3 页
字号:
        if (FAILED(retVal))        {            return retVal;        }        // Call the wrapper's ReadHeader() method        retVal = m_pDecomp->ReadHeader(pDecompValues);        if (FAILED(retVal))        {            HX_RELEASE(pDecompValues);            return retVal;        }        // Extract the parameters        UINT32 ulNumComponents;        pDecompValues->GetPropertyULONG32("InputImageWidth",  m_ulImageWidth);        pDecompValues->GetPropertyULONG32("InputImageHeight", m_ulImageHeight);        pDecompValues->GetPropertyULONG32("NumComponents",    ulNumComponents);        // Release our IHXValues object        HX_RELEASE(pDecompValues);        // Allocate a GImage        HX_RELEASE(m_pImage);        m_pImage = GImage::CreateObject();        if (!m_pImage)        {            return HXR_OUTOFMEMORY;        }        m_pImage->AddRef();        m_pImage->SetFactory(m_pCommonClassFactory);        // Initialize the GImage        UINT32 ulPadWidth  = m_ulImageWidth * 4;        retVal = m_pImage->Init(m_ulImageWidth, m_ulImageHeight, 4, ulPadWidth);        if (FAILED(retVal))        {            HX_RELEASE(m_pImage);            return retVal;        }        // Set the output buffer#ifdef _WINDOWS        BOOL bRowsInverted = TRUE;#else        BOOL bRowsInverted = FALSE;#endif        retVal = m_pDecomp->SetOutputParameters(m_pImage->GetImageBuffer(),                                                m_pImage->GetHeight() * m_pImage->GetRowStride(),                                                m_pImage->GetRowStride(),                                                bRowsInverted);        if (FAILED(retVal))        {            HX_RELEASE(m_pImage);            return retVal;        }    }    else    {        if (m_pDecomp->GetValid() == FALSE)        {            HX_RELEASE(pBuffer);            return HXR_OK;        }        /* If the packet is lost, then we need to insert data or surrender */        BYTE     *pData = pBuffer->GetBuffer() + 8;        UINT32    ulSequenceNumber;        UnPack32(pData, ulSequenceNumber);        BOOL      bLost = (ulSequenceNumber == m_pDecomp->GetLastSequenceNumber() + 1 ? FALSE : TRUE);        HX_RESULT retVal;        if (bLost == TRUE)        {            // Do we have restart markers in this image?            if (m_pDecomp->GetRestartInterval() == 0)            {                // This image has no restart markers. Therefore, we set the image to invalid                m_pDecomp->SetValid(FALSE);                HX_RELEASE(pBuffer);                return HXR_OK;            }             // Insert some fake data with proper restart markers            retVal = InsertDummyData(m_pDecomp, pBuffer);            if (FAILED(retVal))            {                HX_RELEASE(pBuffer);                return retVal;            }        }        // Update the last sequence number        m_pDecomp->SetLastSequenceNumber(ulSequenceNumber);        // Append this buffer to the wrapper's list        m_pDecomp->AppendBuffer(pBuffer);        // Release our reference on the buffer        HX_RELEASE(pBuffer);        // Now call decompress for the wrapper        retVal = m_pDecomp->Decompress();        if (FAILED(retVal))        {            m_pDecomp->SetValid(FALSE);        }    }    // If we've received all the packets we're going to receive, then we    // set the flag saying we've got an image to display    if (m_ulNumPackets >= m_ulTotalPackets)    {        MLOG_MISC(m_pErrorMessages,                  "0x%08x:CJPEGRenderer::OnPacketNoOffset()\n"                  "\tgot all packets - setting valid to TRUE\n", this);        // If we got one or more of our transparency parameters        // set after we starting decoding, then a flag was set        // in order to make us do an AdjustTransparency() after        // we finished decoding        if (m_bPendingTransparencyBlt)        {            UINT32 ulNumPix = m_pImage->GetWidth() * m_pImage->GetHeight();            BOOL bUseAlpha = m_bUsesAlphaChannel;            AdjustTransparency(m_pImage->GetImageBuffer(),                               ulNumPix,                               m_bMediaOpacitySpecified,                               m_ulMediaOpacity,                               m_bMediaChromaKeySpecified,                               m_ulMediaChromaKey,                               m_ulMediaChromaKeyTolerance,                               m_ulMediaChromaKeyOpacity,                               bUseAlpha);            m_bUsesAlphaChannel = bUseAlpha;            // Clear the flag            m_bPendingTransparencyBlt = FALSE;        }        // Now set the valid image flag        m_bValidImage = TRUE;    }    // If we are still getting packets past our display time,    // then force a redraw after receiving a packet    if (m_bPastDisplayTime && m_pSite)    {        // Redraw our data by damaging the entire area of our data        HXxSize size = {0, 0};        m_pSite->GetSize(size);        HXxRect damageRect = {0, 0, size.cx, size.cy};        m_pSite->DamageRect(damageRect);        m_pSite->ForceRedraw();    }    return HXR_OK;}STDMETHODIMP CJPEGRenderer::OnTimeSyncOffset(UINT32 ulTime){    MLOG_MISC(m_pErrorMessages,              "0x%08x:CJPEGRenderer::OnTimeSyncOffset(%lu)\n",              this, ulTime);    // Are we supposed to draw the image?    if (ulTime >= m_ulDisplayTime && !m_bPastDisplayTime)    {        MLOG_MISC(m_pErrorMessages,                  "\tforcing redraw in OnTimeSyncOffset(%lu)\n",                  ulTime);        m_bPastDisplayTime = TRUE;        // Redraw our data by damaging the entire area of our data        HXxSize size;        m_pSite->GetSize(size);        HXxRect damageRect = {0, 0, size.cx, size.cy };        m_pSite->DamageRect(damageRect);        m_pSite->ForceRedraw();    }    return HXR_OK;}STDMETHODIMP CJPEGRenderer::GetWindowSize(REF(HXxSize) rSize){    rSize.cx = m_ulImageWidth;    rSize.cy = m_ulImageHeight;    return HXR_OK;}STDMETHODIMP CJPEGRenderer::IsMouseOverActiveLink(INT16 x, INT16 y, REF(BOOL) rbActive, REF(IHXBuffer*) rpLink){    HX_RESULT retVal = HXR_OK;    // By default we are NOT over a link    rbActive = FALSE;    // Make sure mouse is in the window    if (x >= 0 && x < (INT16) m_ulImageWidth &&        y >= 0 && y < (INT16) m_ulImageHeight)    {        // Make sure a URL string exists        if (m_pURL)        {            // Make sure the URL string has non-zero length            if (m_pURL->GetLength() > 0)            {                // Create an IHXBuffer object                IHXBuffer* pLinkStr = NULL;                HX_RESULT   retVal   = m_pCommonClassFactory->CreateInstance(CLSID_IHXBuffer,                                                                             (void**) &pLinkStr);                if (SUCCEEDED(retVal))                {                    // Set the buffer's value                    retVal = pLinkStr->Set((const BYTE*) m_pURL->GetBuffer(0), m_pURL->GetLength() + 1);                    if (SUCCEEDED(retVal))                    {                        rbActive = TRUE;                        rpLink   = pLinkStr;                    }                }            }        }    }    return retVal;}STDMETHODIMP CJPEGRenderer::RMASurfaceUpdate(IHXVideoSurface* pSurface){    MLOG_MISC(m_pErrorMessages,              "0x%08x:CJPEGRenderer::RMASurfaceUpdate()\n"              "\tm_pImage=0x%08x\n"              "\tm_bValidImage=%lu\n"              "\tm_bPastDisplayTime=%lu\n",              this, m_pImage, m_bValidImage, m_bPastDisplayTime);    if (pSurface)    {	if (m_pImage && m_pImage->GetImageBuffer() && m_bPastDisplayTime)	{	    HXxSize size;	    m_pSite->GetSize(size);	    DrawToRMASurface(pSurface, 0, 0, size);	}	else if (m_pSite)	{	    pSurface->AddRef();	    // Get the current size of the site	    HXxSize size;	    m_pSite->GetSize(size);	    // The source rect is just a 1 by 1 black pixel that gets stretched to fit the destination	    HXxRect rDestRect   = { 0, 0, size.cx, size.cy};	    HXxRect rSrcRect    = { 0, 0, 1, 1};		    HXBitmapInfoHeader bih;	    bih.biSize          = sizeof(HXBitmapInfoHeader);	    bih.biWidth         = 1;	    bih.biHeight        = 1;	    bih.biPlanes        = 1;	    bih.biBitCount      = 32;            bih.biCompression   = HX_RGB;	    bih.biSizeImage     = 0;	    bih.biXPelsPerMeter = 0;	    bih.biYPelsPerMeter = 0;	    bih.biClrUsed       = 0;	    bih.biClrImportant  = 0;	    // Using 32 bit color so there is no color table just an array of RGBQUAD values.  So just set the	    // 1 bit in our bitmap to black.	    unsigned char pBuffer[4] = { 0,0,0,0 };	    pSurface->Blt(pBuffer,			       &bih,			       rDestRect,			       rSrcRect);	    pSurface->Release();	}    }    return HXR_OK;}STDMETHODIMP CJPEGRenderer::HandleClick(INT16 x, INT16 y){    if (m_pHyperNavigate && m_pURL && m_pURL->GetLength() > 0)    {	m_pHyperNavigate->GoToURL(*m_pURL, (m_ulTarget == kTargetPlayer) ? "_player" : (const char*) NULL);    }    return HXR_OK;}STDMETHODIMP CJPEGRenderer::SetPropertyULONG32(const char* pName, ULONG32 ulVal){    HX_RESULT retVal = HXR_OK;    if (pName)    {        // Check to see if this is a property we're interested        // in monitoring        if (!strcmp(pName, "mediaOpacity"))        {            m_ulMediaOpacity         = ulVal;            m_bMediaOpacitySpecified = TRUE;        }        else if (!strcmp(pName, "chromaKey"))        {            m_ulMediaChromaKey         = ulVal;            m_bMediaChromaKeySpecified = TRUE;        }        else if (!strcmp(pName, "chromaKeyTolerance"))        {            m_ulMediaChromaKeyTolerance = ulVal;        }        else if (!strcmp(pName, "chromaKeyOpacity"))        {            m_ulMediaChromaKeyOpacity = ulVal;        }        // Have we received the first packet yet?        if (m_bFirstPacket)        {            // If we haven't yet received the first packet, then            // we can set the parameters into the decoding object            // and the decoding will automatically include these            // parameters when it decodes. However, if the decoding            // has already started (i.e. - m_bFirstPacket == FALSE),            // then we will have to make a pass through our buffer            // at the end to force the opacity and enforce the            // chroma key.            if (m_bMediaOpacitySpecified)            {                m_pDecomp->SetOpacity(m_ulMediaOpacity);                if (m_ulMediaOpacity < 255)                {                    m_bUsesAlphaChannel = TRUE;                }            }            if (m_bMediaChromaKeySpecified)            {                m_pDecomp->SetChromaKeyInfo(m_ulMediaChromaKey,                                            m_ulMediaChromaKeyTolerance,                                            m_ulMediaChromaKeyOpacity);                m_bUsesAlphaChannel = TRUE;            }        }        else        {            // Have we finished decoding all the packets?            if (m_bValidImage)            {                // We have already decoded all the packets, so we can                // simply make a pass through the decoded buffer with the new                // transparency parameters.                UINT32 ulNumPix = m_pImage->GetWidth() * m_pImage->GetHeight();                BOOL bUseAlph   = m_bUsesAlphaChannel;                AdjustTransparency(m_pImage->GetImageBuffer(),                                   ulNumPix,                                   m_bMediaOpacitySpecified,                                   m_ulMediaOpacity,                                   m_bMediaChromaKeySpecified,                                   m_ulMediaChromaKey,                                   m_ulMediaChromaKeyTolerance,                                   m_ulMediaChromaKeyOpacity,                                   bUseAlph);                m_bUsesAlphaChannel = bUseAlph;            }            else            {                // We have processed some packets, but we're not                // done yet. Therefore, we must set a pending flag                // which will trigger a transparency pass through the buffer                // once the decoding is done.                m_bPendingTransparencyBlt = TRUE;            }        }        // Now pass it off to our grandparent class        retVal = CRNBaseRenderer::SetPropertyULONG32(pName, ulVal);    }    else    {        retVal = HXR_FAIL;    }    return retVal;}HX_RESULT STDAPICALLTYPE CJPEGRenderer::HXCreateInstance(IUnknown** ppIUnknown){    HX_RESULT retVal = HXR_OK;    if (ppIUnknown)    {        // Set default        *ppIUnknown = NULL;        // Create the object        CJPEGRenderer *pObj = new CJPEGRenderer();        if (pObj)        {            // QI for IUnknown            retVal = pObj->QueryInterface(IID_IUnknown, (void**) ppIUnknown);        }        else        {            retVal = HXR_OUTOFMEMORY;        }        if (FAILED(retVal))        {            HX_DELETE(pObj);        }    }    else    {        retVal = HXR_FAIL;    }    return HXR_OK;

⌨️ 快捷键说明

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