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

📄 imagemgr.cpp

📁 linux下的一款播放器
💻 CPP
📖 第 1 页 / 共 4 页
字号:
/* ***** BEGIN LICENSE BLOCK ***** * Source last modified: $Id: imagemgr.cpp,v 1.1.24.1 2004/07/09 01:51:47 hubbe Exp $ *  * Portions Copyright (c) 1995-2004 RealNetworks, Inc. All Rights Reserved. *  * The contents of this file, and the files included with this file, * are subject to the current version of the RealNetworks Public * Source License (the "RPSL") available at * http://www.helixcommunity.org/content/rpsl unless you have licensed * the file under the current version of the RealNetworks Community * Source License (the "RCSL") available at * http://www.helixcommunity.org/content/rcsl, in which case the RCSL * will apply. You may also obtain the license terms directly from * RealNetworks.  You may not use this file except in compliance with * the RPSL or, if you have a valid RCSL with RealNetworks applicable * to this file, the RCSL.  Please see the applicable RPSL or RCSL for * the rights, obligations and limitations governing use of the * contents of the file. *  * Alternatively, the contents of this file may be used under the * terms of the GNU General Public License Version 2 or later (the * "GPL") in which case the provisions of the GPL are applicable * instead of those above. If you wish to allow use of your version of * this file only under the terms of the GPL, and not to allow others * to use your version of this file under the terms of either the RPSL * or RCSL, indicate your decision by deleting the provisions above * and replace them with the notice and other provisions required by * the GPL. If you do not delete the provisions above, a recipient may * use your version of this file under the terms of any one of the * RPSL, the RCSL or the GPL. *  * This file is part of the Helix DNA Technology. RealNetworks is the * developer of the Original Code and owns the copyrights in the * portions it created. *  * This file, and the files included with this file, is distributed * and made available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY * KIND, EITHER EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS * ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET * ENJOYMENT OR NON-INFRINGEMENT. *  * Technology Compatibility Kit Test Suite(s) Location: *    http://www.helixcommunity.org/content/tck *  * Contributor(s): *  * ***** END LICENSE BLOCK ***** */// From include#include "hxtypes.h"#include "hxwintyp.h"#include "hxresult.h"#include "hxcom.h"#include "ihxpckts.h"#include "hxvsurf.h"#include "hxfiles.h"#include "hxerror.h"#include "hxccf.h"// From pncont#include "hxmap.h"#include "hxbuffer.h"#include "hxslist.h"// pnmisc#include "unkimp.h"#include "baseobj.h"// From pxcomlib#include "pxrect.h"#include "pxcolor.h"#include "pximage.h"#include "pxeffect.h"#include "pxrndcod.h"#include "pxcmpmgr.h"// pxrend#include "rncodmgr.h"#include "imghelpr.h"#include "imagemgr.h"// pndebug#include "errdbg.h"#include "hxheap.h"#ifdef _DEBUG#undef HX_THIS_FILE		static char HX_THIS_FILE[] = __FILE__;#endifBEGIN_INTERFACE_LIST(PXImageManager)END_INTERFACE_LISTPXImageManager::PXImageManager(){    Reset();    m_pCodecManager      = NULL;    m_pErrorMessages     = NULL;    m_pDisplayImage      = NULL;    m_pHandleToImageMap  = NULL;    m_pScratchBufferList = NULL;    m_pCCF               = NULL;}PXImageManager::~PXImageManager(){    Deallocate();}HX_RESULT PXImageManager::Init(PXRenderCodecManager* pCodecMgr, IHXErrorMessages* pErrorMessages,                               UINT32 ulW, UINT32 ulH, UINT32 ulBpp,                               UINT32 ulFormat, BOOL bInvert,                               UINT32 ulBackgroundColor, UINT32 ulBackgroundOpacity){    HX_RESULT retVal = HXR_OK;    if (pCodecMgr && ulW && ulH && ulBpp)    {        // Clear out anything that's already here        Deallocate();        Reset();        // Assign member variables        m_pCodecManager          = pCodecMgr;        m_pCodecManager->AddRef();        m_pErrorMessages         = pErrorMessages;        m_pErrorMessages->AddRef();        // try to get a common class factory from the error messages!        m_pErrorMessages->QueryInterface(IID_IHXCommonClassFactory, (void**)&m_pCCF);        m_ulDisplayWidth         = ulW;        m_ulDisplayHeight        = ulH;        m_ulDefaultBitsPerPixel  = ulBpp;        m_ulDefaultBytesPerPixel = (ulBpp + 7) >> 3;        m_ulDefaultPixelFormat   = ulFormat;        m_bDefaultRowsInverted   = bInvert;        m_ulBackgroundColor      = ulBackgroundColor;        m_ulBackgroundOpacity    = (ulBackgroundOpacity > 255 ? 255 : ulBackgroundOpacity);        // Create a display image object        retVal = PXImage::CreateObject(&m_pDisplayImage);        if (SUCCEEDED(retVal))        {            // Addref the image            m_pDisplayImage->AddRef();            // Set up the display image            retVal = m_pDisplayImage->Create((INT32) m_ulDisplayWidth,                                             (INT32) m_ulDisplayHeight,                                             m_ulDefaultBitsPerPixel,                                             m_ulDefaultPixelFormat,                                             m_bDefaultRowsInverted);            if (SUCCEEDED(retVal))            {#ifdef XXXMEH_DEBUG_LOG                DEBUG_OUTF("c:\\realpix.log",                           (s, "PXImageManager::Init() - created display image (w=%lu,h=%lu)\n",                           m_ulDisplayWidth, m_ulDisplayHeight));#endif                // Update the background color with the opacity                UINT32 ulAlpha = 255 - ulBackgroundOpacity;                m_ulBackgroundColor = (m_ulBackgroundColor & 0x00FFFFFF) |                                      ((ulAlpha << 24)     & 0xFF000000);                // Fill the display with the background color                retVal = m_pDisplayImage->Fill32(m_ulBackgroundColor);                if (SUCCEEDED(retVal))                {                    // Set the uses-alpha flag                    if (ulBackgroundOpacity < 255)                    {                        m_pDisplayImage->SetHasAlpha(TRUE);                    }                    // Create the map object                    m_pHandleToImageMap = new CHXMapLongToObj();                    if (m_pHandleToImageMap)                    {                        // Create the scratch image list                        HX_DELETE(m_pScratchBufferList);                        m_pScratchBufferList = new CHXSimpleList();                        if (!m_pScratchBufferList)                        {                            retVal = HXR_OUTOFMEMORY;                        }                    }                    else                    {                        retVal = HXR_OUTOFMEMORY;                    }                }            }        }    }    else    {        retVal = HXR_INVALID_PARAMETER;    }    if (FAILED(retVal))    {        Deallocate();        Reset();        HX_ASSERT(FALSE);    }    return retVal;}HX_RESULT PXImageManager::CreateImage(UINT32 ulHandle, UINT32 ulLength, const char* pszMimeType,                                      UINT32 ulOpaqueSize){#ifdef XXXMEH_DEBUG_LOG    DEBUG_OUTF("c:\\realpix.log",               (s, "PXImageManager::CreateImage(%lu,%lu,%s,%lu)\n",               ulHandle, ulLength, pszMimeType, ulOpaqueSize));#endif    HX_RESULT retVal = HXR_OK;    if (ulHandle && ulLength && pszMimeType)    {        if (m_pHandleToImageMap)        {            // Check to see if there's already an entry for this handle            BOOL  bNeedCreate   = TRUE;            void* pVoid         = NULL;            BOOL  bEntryPresent = m_pHandleToImageMap->Lookup((LONG32) ulHandle, pVoid);            if (bEntryPresent)            {                // There was already an entry for this image, so                // we will check to see if we have already successfully                // decoded the whole image. If so, then we will flag this                // image's data packets to be ignored. If not, then we will                // blow this image away and try to receive it again.                // XXXMEH - later, when we update the wire format to                // be more precise about what part of the file is being                // sent in every packet, then we won't have to blow away                // the whole image - we can selectively replace missing                // packets.                //                // Get the PXImageHelper object                PXImageHelper* pHelper = (PXImageHelper*) pVoid;                if (pHelper->AllBytesDecoded() && !pHelper->DecodeFailed())                {                    // Set the ignore data packets flag                    pHelper->SetIgnoreDataPackets(TRUE);                    // We don't need to create a new helper                    bNeedCreate = FALSE;#ifdef XXXMEH_DEBUG_OUT                    DEBUG_OUT(m_pErrorMessages,                              DOL_REALPIX_EXTENDED,                              (s, "Image (handle=%lu) already exists and completely decoded. IGNORING data packets.",                               ulHandle));#endif                }                else                {                    // Release this PXImageHelper object                    HX_RELEASE(pHelper);                    // Remove it from the map                    m_pHandleToImageMap->RemoveKey((LONG32) ulHandle);#ifdef XXXMEH_DEBUG_OUT                    DEBUG_OUT(m_pErrorMessages,                              DOL_REALPIX_EXTENDED,                              (s, "Image (handle=%lu) already exists but not completely decoded. RE-DECODING data packets.",                               ulHandle));#endif                }            }            if (bNeedCreate)            {                // Create the image helper object                PXImageHelper* pHelper = NULL;                retVal                 = PXImageHelper::CreateObject(&pHelper);                if (SUCCEEDED(retVal))                {                    // AddRef the object                    pHelper->AddRef();                    // Get the codec for this mime type                    BOOL      bPresent = FALSE;                    IUnknown* pUnk     = NULL;                    retVal             = m_pCodecManager->GetComponent(pszMimeType, &bPresent, &pUnk);                    if (SUCCEEDED(retVal))                    {                        if (bPresent)                        {                            // Init the helper object                            retVal = pHelper->Init(m_pErrorMessages, ulHandle, ulLength, pUnk, ulOpaqueSize,                                                   m_ulDisplayWidth, m_ulDisplayHeight, m_ulDefaultPixelFormat,                                                   m_ulDefaultBitsPerPixel, m_bDefaultRowsInverted);                            if (SUCCEEDED(retVal))                            {                                // AddRef the helper object before we add it to the map                                pHelper->AddRef();                                // Add the helper object to the map                                m_pHandleToImageMap->SetAt((LONG32) ulHandle, (void *) pHelper);                            }                        }                        else                        {                            retVal = HXR_FAIL;                        }                    }                    HX_RELEASE(pUnk);                }                HX_RELEASE(pHelper);            }        }        else        {            retVal = HXR_NOT_INITIALIZED;        }    }    else    {        retVal = HXR_INVALID_PARAMETER;    }#ifdef XXXMEH_DEBUG_ASSERT    // Debug-only assert    HX_ASSERT(SUCCEEDED(retVal));#endif    return retVal;}HX_RESULT PXImageManager::DeleteImage(UINT32 ulHandle){    HX_RESULT retVal = HXR_OK;    if (ulHandle)    {        if (m_pHandleToImageMap)        {            // 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)            {#ifdef XXXMEH_DEBUG_OUT                DEBUG_OUT(m_pErrorMessages,                          DOL_REALPIX_EXTENDED,                          (s, "Deleting image (handle=%lu)",                           ulHandle));#endif                // Release the object                PXImageHelper* pHelper = (PXImageHelper*) pVoid;                HX_RELEASE(pHelper);                // Remove it from the map                m_pHandleToImageMap->RemoveKey((LONG32) ulHandle);            }            else            {                retVal = HXR_FAIL;

⌨️ 快捷键说明

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