📄 pxgifff.cpp
字号:
/* ***** BEGIN LICENSE BLOCK ***** * Source last modified: $Id: pxgifff.cpp,v 1.3.16.1 2004/07/09 01:54:22 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 ***** */// system#include <stdio.h>#include <stdlib.h>#include <string.h>// include#include "hxtypes.h"#include "hxcom.h"#include "hxcomm.h"#include "ihxpckts.h"#include "hxfiles.h"#include "hxformt.h"#include "hxplugn.h"#include "hxver.h"#include "hxerror.h"#include "hxxres.h"#include "hxxrsmg.h"#include "ihxfgbuf.h"#include "hxvsrc.h"#include "hxengin.h"#ifdef _MACINTOSH#include <ctype.h>#endif// pncont#include "hxstring.h"#include "hxslist.h"#include "chxpckts.h"#include "chxfgbuf.h"// pnmisc#include "hxurl.h"#include "unkimp.h"#include "baseobj.h"#ifdef _AIX#include "dllpath.h"ENABLE_MULTILOAD_DLLACCESS_PATHS(Pxgifff);#endif// pxcomlib#include "gstring.h"#include "pxutil.h"#include "pxcolor.h"#include "parseurl.h"#include "buffutil.h"// pxgiflib#include "lzw.h"#include "gifimage.h"#include "gifcodec.h"// coreres#include "pixres.h"// pxgifff#if defined(HELIX_FEATURE_VIEWSOURCE)#include "gifvsrc.h"#endif /* #if defined(HELIX_FEATURE_VIEWSOURCE) */#include "pxgifff.h"#include "giffdll.ver"// pndebug#include "errdbg.h"#include "hxheap.h"#ifdef _DEBUG#undef HX_THIS_FILE static const char HX_THIS_FILE[] = __FILE__;#endif#define BASE_GIFSTREAM_VERSION HX_ENCODE_PROD_VERSION(0, 0, 0, 0)#define MEDREP_GIFSTREAM_VERSION HX_ENCODE_PROD_VERSION(0, 1, 0, 0)const char * const CGIFFileFormat::m_pszDescription = "Helix GIF File Format Plugin";const char * const CGIFFileFormat::m_pszCopyright = HXVER_COPYRIGHT;const char * const CGIFFileFormat::m_pszMoreInfoURL = HXVER_MOREINFO;const char * const CGIFFileFormat::m_ppszFileMimeTypes[] = {"image/gif", NULL};const char * const CGIFFileFormat::m_ppszFileExtensions[] = {"gif", NULL};const char * const CGIFFileFormat::m_ppszFileOpenNames[] = {"GIF File Format (*.gif)", NULL};const char * const CGIFFileFormat::m_pszStreamMimeType = "application/vnd.rn-gifstream2";const char * const CGIFFileFormat::m_pszBadStreamMimeType = "application/vnd.rn-gifstream3";const UINT32 CGIFFileFormat::m_ulContentVersion = HX_ENCODE_PROD_VERSION(0, 0, 0, 0);const UINT32 CGIFFileFormat::m_ulStreamVersion = BASE_GIFSTREAM_VERSION;#ifdef _WINDOWSextern HINSTANCE g_hInstance;#endifCGIFFileFormat::CGIFFileFormat(){ m_lRefCount = 0; m_pContext = NULL; m_pFileObject = NULL; m_pFileStat = NULL; m_pFormatResponse = NULL; m_pCommonClassFactory = NULL; m_pError = NULL; m_ulBitRate = 0; m_ulPreroll = 0; m_ulDuration = 0; m_pURL = NULL; m_pRequestURL = NULL; m_ulSeekTime = 0; m_ucTarget = kTargetBrowser; m_ucURLType = kURLTypeNormal; m_lCurrentTime = 0; m_plImageStartTime = NULL; m_lCurImgIndex = 0; m_ulState = kStateConstructed; m_ulFileSize = 0; m_pGIFCodec = NULL; m_bReliable = FALSE; m_ulNumBytesRead = 0; m_pFileBuffer = NULL; m_pFragFileBuffer = NULL; m_ppPacket = NULL; m_ulNumPackets = 0; m_ulCurrentPacketIndex = 0; m_bParseFailed = FALSE; m_pMediaRepeatStr = NULL;}CGIFFileFormat::~CGIFFileFormat(){ Close();}STDMETHODIMP CGIFFileFormat::QueryInterface(REFIID riid, void **ppvObj){ if (IsEqualIID(riid, IID_IUnknown)) { AddRef(); *ppvObj = (IUnknown *) (IHXPlugin *) this; return HXR_OK; } else if (IsEqualIID(riid, IID_IHXPlugin)) { AddRef(); *ppvObj = (IHXPlugin *) this; return HXR_OK; } else if (IsEqualIID(riid, IID_IHXFileFormatObject)) { AddRef(); *ppvObj = (IHXFileFormatObject *) this; return HXR_OK; } else if (IsEqualIID(riid, IID_IHXFileResponse)) { AddRef(); *ppvObj = (IHXFileResponse *) this; return HXR_OK; } else if (IsEqualIID(riid, IID_IHXFileStatResponse)) { AddRef(); *ppvObj = (IHXFileStatResponse *) this; return HXR_OK; }#if defined(HELIX_FEATURE_VIEWSOURCE) else if (IsEqualIID(riid, IID_IHXFileViewSource)) { CGIFViewSource* pVsrc = new CGIFViewSource(m_pContext, (IUnknown*)(IHXPlugin*)this); if ( pVsrc == NULL ) { return HXR_FAIL; } return pVsrc->QueryInterface(riid, ppvObj); }#endif /* #if defined(HELIX_FEATURE_VIEWSOURCE) */ else if (IsEqualIID(riid, IID_IHXThreadSafeMethods)) { AddRef(); *ppvObj = (IHXThreadSafeMethods*)this; return HXR_OK; } *ppvObj = NULL; return HXR_NOINTERFACE;}STDMETHODIMP_(UINT32) CGIFFileFormat::AddRef(){ return InterlockedIncrement(&m_lRefCount);}STDMETHODIMP_(UINT32) CGIFFileFormat::Release(){ if (InterlockedDecrement(&m_lRefCount) > 0) { return m_lRefCount; } delete this; return 0;}STDMETHODIMP CGIFFileFormat::GetPluginInfo(REF(BOOL) bMultipleLoad, REF(const char*) pDescription, REF(const char*) pCopyright, REF(const char*) pMoreInfoURL, REF(ULONG32) ulVersionNumber){ bMultipleLoad = TRUE; // Must be true for file formats. pDescription = m_pszDescription; pCopyright = m_pszCopyright; pMoreInfoURL = m_pszMoreInfoURL; ulVersionNumber = TARVER_ULONG32_VERSION; return HXR_OK;}STDMETHODIMP CGIFFileFormat::GetFileFormatInfo(REF(const char **) rppszFileMimeTypes, REF(const char **) rppszFileExtensions, REF(const char **) rppszFileOpenNames){ rppszFileMimeTypes = (const char**) m_ppszFileMimeTypes; rppszFileExtensions = (const char**) m_ppszFileExtensions; rppszFileOpenNames = (const char**) m_ppszFileOpenNames; return HXR_OK;}STDMETHODIMP CGIFFileFormat::InitPlugin(IUnknown *pContext){ // Check for input error if (pContext == NULL) { return HXR_INVALID_PARAMETER; } // Save a copy of the context m_pContext = pContext; m_pContext->AddRef(); // Get an IHXCommonClassFactory interface from the context HX_RELEASE(m_pCommonClassFactory); HX_RESULT retVal = m_pContext->QueryInterface(IID_IHXCommonClassFactory, (void **) &m_pCommonClassFactory); if (retVal != HXR_OK) { HX_RELEASE(m_pContext); return HXR_NOINTERFACE; } // Get the IHXErrorMessages interface // It's OK if TLC doesn't support it. HX_RELEASE(m_pError); m_pContext->QueryInterface(IID_IHXErrorMessages, (void **) &m_pError); return HXR_OK;}STDMETHODIMP CGIFFileFormat::InitFileFormat(IHXRequest *pRequest, IHXFormatResponse *pFormatResponse, IHXFileObject *pFileObject){#ifdef XXXMEH_DEBUG_LOG const char* pszURLDbg = NULL; pRequest->GetURL(pszURLDbg); DEBUG_OUTF("pxgifff.log", (s, "0x%08x::InitFileFormat(): %s\n", this, pszURLDbg));#endif // Check for input error if (pRequest == NULL || pFormatResponse == NULL || pFileObject == NULL) { return HXR_INVALID_PARAMETER; } // Check state if (m_ulState != kStateConstructed) { return HXR_UNEXPECTED; } // Save a copy of the IHXFormatResponse m_pFormatResponse = pFormatResponse; m_pFormatResponse->AddRef(); // Get the URL string from the IHXRequest object const char *pszURL = NULL; HX_RESULT retVal = pRequest->GetURL(pszURL); if (retVal != HXR_OK) { return m_pFormatResponse->InitDone(retVal); } if (pszURL) { HX_DELETE(m_pRequestURL); m_pRequestURL = new CHXString(pszURL); } // Create an IHXValues object to hold the param name/value pairs IHXValues *pValues = NULL; retVal = m_pCommonClassFactory->CreateInstance(CLSID_IHXValues, (void**) &pValues); if (FAILED(retVal)) { return m_pFormatResponse->InitDone(retVal); } // Now add the following parameters to the IHXValues. These // parameters could have come as URL-encoded parameters or as // parameters in the request headers. These parameters will be // added as CString properties to the IHXValues. AddURLOrRequestParam(pRequest, "bitrate", m_pContext, pValues); AddURLOrRequestParam(pRequest, "duration", m_pContext, pValues); AddURLOrRequestParam(pRequest, "preroll", m_pContext, pValues); AddURLOrRequestParam(pRequest, "url", m_pContext, pValues); AddURLOrRequestParam(pRequest, "target", m_pContext, pValues); AddURLOrRequestParam(pRequest, "bgcolor", m_pContext, pValues); AddURLOrRequestParam(pRequest, "reliable", m_pContext, pValues); AddURLOrRequestParam(pRequest, "mediaRepeat", m_pContext, pValues); // Set the bitrate retVal = ExtractValueUINT32(pValues, "bitrate", kDefaultBitRate, m_ulBitRate); if (retVal != HXR_OK) { HX_RELEASE(pValues); ReportError(IDS_ERR_GIF_BADBITRATE); return m_pFormatResponse->InitDone(retVal); } // Set the duration retVal = ExtractValueTime(pValues, "duration", kDefaultDuration, m_ulDuration); if (retVal != HXR_OK) { HX_RELEASE(pValues); ReportError(IDS_ERR_GIF_BADDURATION); return m_pFormatResponse->InitDone(retVal); } // Set the preroll retVal = ExtractValueTime(pValues, "preroll", 0, m_ulPreroll); if (retVal != HXR_OK) { HX_RELEASE(pValues); ReportError(IDS_ERR_GIF_BADPREROLL); return m_pFormatResponse->InitDone(retVal); } // Set the URL CHXString cTmp; retVal = ExtractValueString(pValues, "url", NULL, cTmp); if (retVal != HXR_OK) { HX_RELEASE(pValues);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -