📄 pximgfil.cpp
字号:
/* ***** BEGIN LICENSE BLOCK ***** * Source last modified: $Id: pximgfil.cpp,v 1.1.26.1 2004/07/09 01:54:51 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 ***** */// include#include "hxtypes.h"#include "hxwintyp.h"#include "hxcom.h"#include "hxresult.h"#include "hxcomm.h"#include "ihxpckts.h"// hxcont#include "hxslist.h"#include "hxstring.h"#include "hxmap.h"// hxmisc#include "baseobj.h"#include "unkimp.h"// pxcomlib#include "pxrect.h"#include "pxcolor.h"#include "pxeffect.h"#include "wirefmgr.h"#include "pxffmcod.h"#include "pxcmpmgr.h"#include "pxffcmgr.h"#include "pximgfil.h"// hxdebug#include "hxheap.h"#ifdef _DEBUG#undef HX_THIS_FILE static char HX_THIS_FILE[] = __FILE__;#endifPXImageFile::PXImageFile(PXWireFormatManager* pWireFormatManager, PXFileFormatCodecManager* pCodecManager, IHXCommonClassFactory* pCommonClassFactory){ HX_ASSERT(pWireFormatManager); if (pWireFormatManager) { m_pWireFormatManager = pWireFormatManager; m_pWireFormatManager->AddRef(); } HX_ASSERT(pCodecManager); if (pCodecManager) { m_pCodecManager = pCodecManager; m_pCodecManager->AddRef(); } HX_ASSERT(pCommonClassFactory); if (pCommonClassFactory) { m_pCommonClassFactory = pCommonClassFactory; m_pCommonClassFactory->AddRef(); } m_lRefCount = 0; m_ulHandle = 0; m_ulNumPackets = 0; m_ulTotalBytes = 0; m_ulImageWidth = 0; m_ulImageHeight = 0; m_pPacketList = NULL; m_pCookieList = NULL; m_pListItr = NULL;}PXImageFile::~PXImageFile(){ Deallocate();};void PXImageFile::Deallocate(){ HX_RELEASE(m_pWireFormatManager); HX_RELEASE(m_pCodecManager); HX_RELEASE(m_pCommonClassFactory); ReleaseAllPackets(); ClearCookieList(); HX_DELETE(m_pPacketList); HX_DELETE(m_pCookieList);}void PXImageFile::ReleaseAllPackets(){ if (m_pPacketList) { LISTPOSITION pos = m_pPacketList->GetHeadPosition(); while (pos) { IHXPacket* pPacket = (IHXPacket*) m_pPacketList->GetNext(pos); HX_RELEASE(pPacket); } m_pPacketList->RemoveAll(); }}void PXImageFile::ClearCookieList(){ if (m_pCookieList) { LISTPOSITION pos = m_pCookieList->GetHeadPosition(); while (pos) { CookiePair* pPair = (CookiePair*) m_pCookieList->GetNext(pos); if (pPair) { HX_RELEASE(pPair->m_pURLStr); HX_RELEASE(pPair->m_pCookie); } HX_DELETE(pPair); } m_pCookieList->RemoveAll(); }}STDMETHODIMP PXImageFile::QueryInterface(REFIID riid, void** ppvObj){ HX_RESULT retVal = HXR_OK; if (IsEqualIID(riid, IID_IUnknown)) { AddRef(); *ppvObj = (IUnknown *) this; } else { *ppvObj = NULL; retVal = HXR_NOINTERFACE; } return retVal;}STDMETHODIMP_(UINT32) PXImageFile::AddRef(){ return InterlockedIncrement(&m_lRefCount);}STDMETHODIMP_(UINT32) PXImageFile::Release(){ if (InterlockedDecrement(&m_lRefCount) > 0) return m_lRefCount; delete this; return 0;}HX_RESULT PXImageFile::AddCookie(IHXBuffer* pURLStr, IHXBuffer* pCookie){ HX_RESULT retVal = HXR_OK; if (pURLStr && pCookie) { if (!m_pCookieList) { m_pCookieList = new CHXSimpleList(); if (!m_pCookieList) { retVal = HXR_OUTOFMEMORY; } } if (SUCCEEDED(retVal)) { CookiePair* pPair = new CookiePair; if (pPair) { pPair->m_pURLStr = pURLStr; pPair->m_pURLStr->AddRef(); pPair->m_pCookie = pCookie; pPair->m_pCookie->AddRef(); m_pCookieList->AddTail((void*) pPair); } else { retVal = HXR_OUTOFMEMORY; } } } else { retVal = HXR_FAIL; } return retVal;}HX_RESULT PXImageFile::EnqueueCookiePacket(){ HX_RESULT retVal = HXR_OK; // Add the cookie packet if (m_pCookieList) { if (m_pCookieList->GetCount() > 0) { IHXBuffer** ppURL = NULL; ppURL = new IHXBuffer* [m_pCookieList->GetCount()]; if (ppURL) { IHXBuffer** ppCookie = NULL; ppCookie = new IHXBuffer* [m_pCookieList->GetCount()]; if (ppCookie) { UINT32 i = 0; LISTPOSITION pos = m_pCookieList->GetHeadPosition(); while (pos) { CookiePair* pPair = (CookiePair*) m_pCookieList->GetNext(pos); if (pPair) { ppURL[i] = pPair->m_pURLStr; ppCookie[i] = pPair->m_pCookie; i++; } } IHXPacket* pPacket = NULL; retVal = m_pWireFormatManager->SetCookieInfo(m_pCookieList->GetCount(), ppURL, ppCookie, 0, pPacket); if (SUCCEEDED(retVal)) { // Add this to the packet list // FALSE makes it add at the head instead of tail retVal = AddPacket(pPacket, FALSE); } HX_RELEASE(pPacket); } HX_VECTOR_DELETE(ppCookie); } HX_VECTOR_DELETE(ppURL); // Clear the cookie list ClearCookieList(); } } return retVal;}HX_RESULT PXImageFile::EnqueueImagePackets(UINT32 ulHandle, IHXBuffer* pFileBuffer){ HX_RESULT retVal = HXR_FAIL; if (ulHandle && pFileBuffer) { // Save the members m_ulHandle = ulHandle; // Get a codec to parse this image IHXRealPixFileFormatCodec* pCodec = NULL; retVal = m_pCodecManager->GetCodec(NULL, // file mime type NULL, // file name pFileBuffer, // file buffer pCodec); if (SUCCEEDED(retVal)) { // Get the mime type for this codec const char** ppTmp1 = NULL; const char** ppTmp2 = NULL; const char* pszStreamMime = NULL; UINT32 ulVer = 0; UINT32 ulMaxPerImg = 0; UINT32 ulMaxPerPckt = 0; retVal = pCodec->GetFileFormatCodecInfo(ppTmp1, ppTmp2, pszStreamMime, ulVer, ulMaxPerImg, ulMaxPerPckt); if (SUCCEEDED(retVal)) { IHXPacket* pImageHeaderPacket = NULL; retVal = m_pWireFormatManager->SetImageHeaderInfo(ulHandle, pFileBuffer->GetSize(), 0, pszStreamMime, 0, pImageHeaderPacket); if (SUCCEEDED(retVal)) { // Add image header packet to list tail retVal = AddPacket(pImageHeaderPacket); if (SUCCEEDED(retVal)) { // Parse the image UINT32 ulNumDataPackets = 0; IHXValues* pParam = NULL;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -