symbimgdec.cpp
来自「symbian 下的helix player源代码」· C++ 代码 · 共 248 行
CPP
248 行
/* ***** 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 "hxtypes.h"
#include "hxwintyp.h"
#include "hlxclib/string.h"
#include "hxcom.h"
#include "hxccf.h"
#include "ihxpckts.h"
#include "hxvsurf.h"
#include "unifimg.h"
#include "nativeimgdec.h"
#include "MdaImageConverter.h"
#include "platform/symbian/symbimgdec.h"
CSymbianImageDecoder::CSymbianImageDecoder() : CNativeImageDecoder()
{
m_pConverter = NULL;
m_pBitmap = NULL;
m_pInputBuffer = NULL;
m_pInput = NULL;
m_ulState = kStateReady;
m_bIsWBMP = FALSE;
m_pFormat = NULL;
m_pCodec = NULL;
}
CSymbianImageDecoder::~CSymbianImageDecoder()
{
HX_DELETE(m_pConverter);
HX_DELETE(m_pBitmap);
HX_RELEASE(m_pInputBuffer);
HX_DELETE(m_pInput);
HX_DELETE(m_pFormat);
HX_DELETE(m_pCodec);
m_ulState = kStateReady;
}
STDMETHODIMP CSymbianImageDecoder::Decode(IUnknown* pContext,
CNativeImageDecoderResponse* pResponse,
IHXBuffer* pBuffer,
IHXBuffer* pMimeTypeStr)
{
HX_RESULT retVal = HXR_FAIL;
if (pContext && pResponse && pBuffer && pMimeTypeStr)
{
// Save a copy of the context
HX_RELEASE(m_pContext);
m_pContext = pContext;
m_pContext->AddRef();
// Save a pointer to the response
m_pResponse = pResponse;
// Save a ref to the input buffer
HX_RELEASE(m_pInputBuffer);
m_pInputBuffer = pBuffer;
m_pInputBuffer->AddRef();
// Check if this is WBMP
m_bIsWBMP = FALSE;
const char* pszMimeType = (const char*) pMimeTypeStr->GetBuffer();
if (pszMimeType &&
(!strcmp(pszMimeType, IMAGE_MIMETYPE_WBMP) ||
!strcmp(pszMimeType, IMAGE_MIMETYPE_WBMP_STREAMED)))
{
m_bIsWBMP = TRUE;
}
// Get the common class factory
HX_RELEASE(m_pFactory);
retVal = m_pContext->QueryInterface(IID_IHXCommonClassFactory,
(void**) &m_pFactory);
if (SUCCEEDED(retVal))
{
// Create a TPtrC8 object to hold the input buffer
HX_DELETE(m_pInput);
m_pInput = new TPtrC8((const TUint8*) m_pInputBuffer->GetBuffer(),
(TInt) m_pInputBuffer->GetSize());
if (m_pInput)
{
// Create the CMdaImageFileToBitmapUtility object
HX_DELETE(m_pConverter);
m_pConverter = CMdaImageDescToBitmapUtility::NewL(*this);
if (m_pConverter)
{
// Create WBMP-related objects if necessary
HX_DELETE(m_pFormat);
HX_DELETE(m_pCodec);
if (m_bIsWBMP)
{
m_pFormat = new TMdaWbmpClipFormat();
m_pCodec = new TMdaWbmpCodec();
}
// Set the state
m_ulState = kStateOpenCompletePending;
// Clear the return value
retVal = HXR_OK;
// Call the asynch OpenL() method
m_pConverter->OpenL(*m_pInput, m_pFormat, m_pCodec);
}
}
}
}
return retVal;
}
void CSymbianImageDecoder::MiuoOpenComplete(TInt aError)
{
if (m_ulState == kStateOpenCompletePending)
{
// We don't need the format and codec objects any more
HX_DELETE(m_pFormat);
HX_DELETE(m_pCodec);
// Save our status
TInt tErr = aError;
if (tErr == KErrNone)
{
// Get the size of the image
TFrameInfo frameInfo;
m_pConverter->FrameInfo(0, frameInfo);
// Create a bitmap
HX_DELETE(m_pBitmap);
m_pBitmap = new CFbsBitmap();
if (m_pBitmap)
{
tErr = m_pBitmap->Create(frameInfo.iOverallSizeInPixels,
EColor4K);
if (tErr == KErrNone)
{
// Set the state
m_ulState = kStateConvertCompletePending;
// Make the asynch call to ConvertL()
m_pConverter->ConvertL(*m_pBitmap, 0);
}
}
else
{
tErr = KErrNoMemory;
}
}
if (tErr != KErrNone)
{
// Set the state
m_ulState = kStateReady;
// Call back failure
m_pResponse->DecodeDone(HXR_FAIL, NULL, NULL);
}
}
}
void CSymbianImageDecoder::MiuoConvertComplete(TInt aError)
{
if (m_ulState == kStateConvertCompletePending)
{
// Set the state
m_ulState = kStateReady;
// Check the error
HX_RESULT retVal = HXR_FAIL;
// Check the error return
if (aError == KErrNone)
{
// Get the bitmap size
TSize cSize = m_pBitmap->SizeInPixels();
// Set the bitmap info header
HXBitmapInfoHeader cHdr;
cHdr.biSize = 52;
cHdr.biWidth = (INT32) cSize.iWidth;
cHdr.biHeight = (INT32) cSize.iHeight;
cHdr.biPlanes = 1;
cHdr.biBitCount = 16;
cHdr.biCompression = HX_BITFIELDS;
cHdr.biSizeImage = 0;
cHdr.biXPelsPerMeter = 0;
cHdr.biYPelsPerMeter = 0;
cHdr.biClrUsed = 0;
cHdr.biClrImportant = 0;
cHdr.rcolor = 0x0F00;
cHdr.gcolor = 0x00F0;
cHdr.bcolor = 0x000F;
// Create an IHXBuffer
IHXBuffer* pOutBuffer = NULL;
retVal = m_pFactory->CreateInstance(CLSID_IHXBuffer,
(void**) &pOutBuffer);
if (SUCCEEDED(retVal))
{
// Get the length of scanline in bytes
UINT32 ulByteWidth = (UINT32) CFbsBitmap::ScanLineLength(cSize.iWidth,
m_pBitmap->DisplayMode());
// Get the total number of bytes in the bitmap
UINT32 ulTotalBytes = ulByteWidth * cSize.iHeight;
// Set the output buffer
retVal = pOutBuffer->Set((const BYTE*) m_pBitmap->DataAddress(),
ulTotalBytes);
if (SUCCEEDED(retVal))
{
// Call back to the response
m_pResponse->DecodeDone(HXR_OK, &cHdr, pOutBuffer);
}
}
// Now we can clean up
HX_RELEASE(pOutBuffer);
HX_DELETE(m_pInput);
HX_RELEASE(m_pInputBuffer);
HX_DELETE(m_pBitmap);
HX_DELETE(m_pConverter);
}
if (FAILED(retVal))
{
m_pResponse->DecodeDone(HXR_FAIL, NULL, NULL);
}
}
}
void CSymbianImageDecoder::MiuoCreateComplete(TInt aError)
{
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?