comimgff.cpp
来自「symbian 下的helix player源代码」· C++ 代码 · 共 1,025 行 · 第 1/3 页
CPP
1,025 行
/* ***** BEGIN LICENSE BLOCK *****
* Version: RCSL 1.0/RPSL 1.0
*
* Portions Copyright (c) 1995-2002 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
* Version 1.0 (the "RPSL") available at
* http://www.helixcommunity.org/content/rpsl unless you have licensed
* the file under the RealNetworks Community Source License Version 1.0
* (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.
*
* 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 "hxcom.h"
#include "hxtypes.h"
#include "hxwintyp.h"
#include "hxcomm.h"
#include "ihxpckts.h"
#include "hxfiles.h"
#include "hxformt.h"
#include "hxplugn.h"
#include "hxver.h"
#include "baseobj.h"
#include "pckunpck.h"
#include "jpegdef.h"
#include "wbmphdr.h"
#include "unifimg.h"
#include "comimgff.h"
#include "comimgff.ver"
#include "hxheap.h"
#ifdef _DEBUG
#undef HX_THIS_FILE
static const char HX_THIS_FILE[] = __FILE__;
#endif
const char* const CCommonImageFileFormat::m_pszDescription = "Helix Common Image File Format Plugin";
const char* const CCommonImageFileFormat::m_pszCopyright = HXVER_COPYRIGHT;
const char* const CCommonImageFileFormat::m_pszMoreInfoURL = HXVER_MOREINFO;
const char* const CCommonImageFileFormat::m_ppszFileMimeTypes[] = {"image/jpeg", "image/png", "image/x-wap.wbmp", NULL};
const char* const CCommonImageFileFormat::m_ppszFileExtensions[] = {"jpg", "jpeg", "jpe", "jfif", "png", "wbmp", NULL};
const char* const CCommonImageFileFormat::m_ppszFileOpenNames[] = {"Images (*.jpg,*.png,*.wbmp)", NULL};
const char* const CCommonImageFileFormat::m_ppszStreamMimeType[] = {"image/jpeg", "image/png", "image/x-wap.wbmp", NULL};
CCommonImageFileFormat::CCommonImageFileFormat()
{
m_lRefCount = 0;
m_pContext = NULL;
m_pFileObject = NULL;
m_pFormatResponse = NULL;
m_pCommonClassFactory = NULL;
m_pFileMimeMapper = NULL;
m_pURLStr = NULL;
m_pMimeTypeStr = NULL;
m_ulState = kStateReady;
m_ulFileOffset = 0;
m_ulDesiredFileOffset = 0;
m_ulRequestedFileOffset = 0;
m_ulHeaderReadSize = kInitialHeaderReadSize;
m_bFileObjectOpen = FALSE;
};
CCommonImageFileFormat::~CCommonImageFileFormat()
{
if (m_pFileObject)
{
m_pFileObject->Close();
}
HX_RELEASE(m_pContext);
HX_RELEASE(m_pFileObject);
HX_RELEASE(m_pFormatResponse);
HX_RELEASE(m_pCommonClassFactory);
HX_RELEASE(m_pFileMimeMapper);
HX_RELEASE(m_pURLStr);
HX_RELEASE(m_pMimeTypeStr);
};
STDMETHODIMP CCommonImageFileFormat::QueryInterface(REFIID riid, void** ppvObj)
{
HX_RESULT retVal = HXR_FAIL;
if (ppvObj)
{
// Set defaults
*ppvObj = NULL;
retVal = HXR_OK;
// Switch on iid
if (IsEqualIID(riid, IID_IUnknown))
{
AddRef();
*ppvObj = (IUnknown*) (CHXBaseCountingObject*) (IHXPlugin*) this;
}
else if (IsEqualIID(riid, IID_IHXPlugin))
{
AddRef();
*ppvObj = (IHXPlugin*) this;
}
else if (IsEqualIID(riid, IID_IHXFileFormatObject))
{
AddRef();
*ppvObj = (IHXFileFormatObject*) this;
}
else if (IsEqualIID(riid, IID_IHXFileResponse))
{
AddRef();
*ppvObj = (IHXFileResponse*) this;
}
else if (IsEqualIID(riid, IID_IHXFileMimeMapperResponse))
{
AddRef();
*ppvObj = (IHXFileMimeMapperResponse*) this;
}
else
{
retVal = HXR_NOINTERFACE;
}
}
return retVal;
}
STDMETHODIMP_(UINT32) CCommonImageFileFormat::AddRef()
{
return InterlockedIncrement(&m_lRefCount);
}
STDMETHODIMP_(UINT32) CCommonImageFileFormat::Release()
{
if (InterlockedDecrement(&m_lRefCount) > 0)
{
return m_lRefCount;
}
delete this;
return 0;
}
STDMETHODIMP CCommonImageFileFormat::GetPluginInfo(REF(BOOL) rbLoadMultiple,
REF(const char*) rpszDescription,
REF(const char*) rpszCopyright,
REF(const char*) rpszMoreInfoURL,
REF(UINT32) rulVersionNumber)
{
rbLoadMultiple = TRUE;
rpszDescription = (const char*) m_pszDescription;
rpszCopyright = (const char*) m_pszCopyright;
rpszMoreInfoURL = (const char*) m_pszMoreInfoURL;
rulVersionNumber = TARVER_ULONG32_VERSION;
return HXR_OK;
}
STDMETHODIMP CCommonImageFileFormat::InitPlugin(IUnknown* pContext)
{
HX_RESULT retVal = HXR_FAIL;
if (pContext)
{
// Save a copy of the calling context
HX_RELEASE(m_pContext);
m_pContext = pContext;
m_pContext->AddRef();
// Get an interface to the common class factory
HX_RELEASE(m_pCommonClassFactory);
retVal = m_pContext->QueryInterface(IID_IHXCommonClassFactory,
(void**) &m_pCommonClassFactory);
}
return retVal;
}
STDMETHODIMP CCommonImageFileFormat::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 CCommonImageFileFormat::InitFileFormat(IHXRequest* pRequest,
IHXFormatResponse* pFormatResponse,
IHXFileObject* pFileObject)
{
HX_RESULT retVal = HXR_FAIL;
if (pRequest && pFormatResponse && pFileObject)
{
if (m_ulState == kStateReady)
{
// Save members
HX_RELEASE(m_pFormatResponse);
m_pFormatResponse = pFormatResponse;
m_pFormatResponse->AddRef();
HX_RELEASE(m_pFileObject);
m_pFileObject = pFileObject;
m_pFileObject->AddRef();
// Get the URL from the request
const char* pszURL = NULL;
retVal = pRequest->GetURL(pszURL);
if (SUCCEEDED(retVal))
{
// Save the URL
HX_RELEASE(m_pURLStr);
retVal = CreateStringBuffer(m_pURLStr, pszURL, m_pContext);
if (SUCCEEDED(retVal))
{
// Set the state
m_ulState = kStateIFFInitDonePending;
// Clear the return value
retVal = HXR_OK;
// Init the file object
m_pFileObject->Init(HX_FILE_READ | HX_FILE_BINARY, this);
}
}
}
}
if (FAILED(retVal) && pFormatResponse)
{
pFormatResponse->InitDone(HXR_FAIL);
}
return retVal;
}
STDMETHODIMP CCommonImageFileFormat::GetFileHeader()
{
HX_RESULT retVal = HXR_UNEXPECTED;
if (m_ulState == kStateReady)
{
// Get an IHXValues object
IHXValues* pHeader = NULL;
retVal = m_pCommonClassFactory->CreateInstance(CLSID_IHXValues,
(void**) &pHeader);
if (SUCCEEDED(retVal))
{
// Set the stream count
pHeader->SetPropertyULONG32("StreamCount", 1);
// Call the response interface
m_pFormatResponse->FileHeaderReady(HXR_OK, pHeader);
}
HX_RELEASE(pHeader);
}
if (FAILED(retVal) && m_pFormatResponse)
{
m_pFormatResponse->FileHeaderReady(retVal, NULL);
}
return retVal;
}
STDMETHODIMP CCommonImageFileFormat::GetStreamHeader(UINT16 usStreamNum)
{
HX_RESULT retVal = HXR_UNEXPECTED;
if (m_ulState == kStateReady)
{
// Clear the return value
retVal = HXR_OK;
// Init the seeked file offset
m_ulRequestedFileOffset = 0;
// Set the state
m_ulState = kStateGSHSeekDonePending;
// Seek the file object to the beginning
m_pFileObject->Seek(m_ulRequestedFileOffset, FALSE);
}
if (FAILED(retVal) && m_pFormatResponse)
{
m_pFormatResponse->StreamHeaderReady(retVal, NULL);
}
return retVal;
}
STDMETHODIMP CCommonImageFileFormat::GetPacket(UINT16 usStreamNum)
{
HX_RESULT retVal = HXR_UNEXPECTED;
if (m_ulState == kStateReady && usStreamNum == 0)
{
// Clear the return value
retVal = HXR_OK;
// Are we already at the desired file offset?
if (m_ulDesiredFileOffset == m_ulFileOffset)
{
// Set the state
m_ulState = kStateGPReadDonePending;
// Read kPacketSize bytes
HX_RESULT res = m_pFileObject->Read(kPacketSize);
if( HXR_FAIL == res)
{
//All the data has been read.
ReadDone(HXR_FAIL, NULL );
}
}
else
{
// Set the state
m_ulState = kStateGPSeekDonePending;
// Save the value we are trying to seek to
m_ulRequestedFileOffset = m_ulDesiredFileOffset;
// Seek to the desired file offset
m_pFileObject->Seek(m_ulRequestedFileOffset, FALSE);
}
}
if (FAILED(retVal) && m_pFormatResponse)
{
m_pFormatResponse->StreamDone(0);
}
return retVal;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?