symbimgdec.cpp
上传用户:dangjiwu
上传日期:2013-07-19
资源大小:42019k
文件大小:9k
源码类别:

Symbian

开发平台:

Visual C++

  1. /* ***** BEGIN LICENSE BLOCK ***** 
  2.  * Version: RCSL 1.0/RPSL 1.0 
  3.  *  
  4.  * Portions Copyright (c) 1995-2002 RealNetworks, Inc. All Rights Reserved. 
  5.  *      
  6.  * The contents of this file, and the files included with this file, are 
  7.  * subject to the current version of the RealNetworks Public Source License 
  8.  * Version 1.0 (the "RPSL") available at 
  9.  * http://www.helixcommunity.org/content/rpsl unless you have licensed 
  10.  * the file under the RealNetworks Community Source License Version 1.0 
  11.  * (the "RCSL") available at http://www.helixcommunity.org/content/rcsl, 
  12.  * in which case the RCSL will apply. You may also obtain the license terms 
  13.  * directly from RealNetworks.  You may not use this file except in 
  14.  * compliance with the RPSL or, if you have a valid RCSL with RealNetworks 
  15.  * applicable to this file, the RCSL.  Please see the applicable RPSL or 
  16.  * RCSL for the rights, obligations and limitations governing use of the 
  17.  * contents of the file.  
  18.  *  
  19.  * This file is part of the Helix DNA Technology. RealNetworks is the 
  20.  * developer of the Original Code and owns the copyrights in the portions 
  21.  * it created. 
  22.  *  
  23.  * This file, and the files included with this file, is distributed and made 
  24.  * available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 
  25.  * EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS ALL SUCH WARRANTIES, 
  26.  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS 
  27.  * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 
  28.  * 
  29.  * Technology Compatibility Kit Test Suite(s) Location: 
  30.  *    http://www.helixcommunity.org/content/tck 
  31.  * 
  32.  * Contributor(s): 
  33.  *  
  34.  * ***** END LICENSE BLOCK ***** */ 
  35. #include "hxtypes.h"
  36. #include "hxwintyp.h"
  37. #include "hlxclib/string.h"
  38. #include "hxcom.h"
  39. #include "hxccf.h"
  40. #include "ihxpckts.h"
  41. #include "hxvsurf.h"
  42. #include "unifimg.h"
  43. #include "nativeimgdec.h"
  44. #include "MdaImageConverter.h"
  45. #include "platform/symbian/symbimgdec.h"
  46. CSymbianImageDecoder::CSymbianImageDecoder() : CNativeImageDecoder()
  47. {
  48.     m_pConverter   = NULL;
  49.     m_pBitmap      = NULL;
  50.     m_pInputBuffer = NULL;
  51.     m_pInput       = NULL;
  52.     m_ulState      = kStateReady;
  53.     m_bIsWBMP      = FALSE;
  54.     m_pFormat      = NULL;
  55.     m_pCodec       = NULL;
  56. }
  57. CSymbianImageDecoder::~CSymbianImageDecoder()
  58. {
  59.     HX_DELETE(m_pConverter);
  60.     HX_DELETE(m_pBitmap);
  61.     HX_RELEASE(m_pInputBuffer);
  62.     HX_DELETE(m_pInput);
  63.     HX_DELETE(m_pFormat);
  64.     HX_DELETE(m_pCodec);
  65.     m_ulState = kStateReady;
  66. }
  67. STDMETHODIMP CSymbianImageDecoder::Decode(IUnknown*                    pContext,
  68.                                           CNativeImageDecoderResponse* pResponse,
  69.                                           IHXBuffer*                   pBuffer,
  70.                                           IHXBuffer*                   pMimeTypeStr)
  71. {
  72.     HX_RESULT retVal = HXR_FAIL;
  73.     if (pContext && pResponse && pBuffer && pMimeTypeStr)
  74.     {
  75.         // Save a copy of the context
  76.         HX_RELEASE(m_pContext);
  77.         m_pContext = pContext;
  78.         m_pContext->AddRef();
  79.         // Save a pointer to the response
  80.         m_pResponse = pResponse;
  81.         // Save a ref to the input buffer
  82.         HX_RELEASE(m_pInputBuffer);
  83.         m_pInputBuffer = pBuffer;
  84.         m_pInputBuffer->AddRef();
  85.         // Check if this is WBMP
  86.         m_bIsWBMP = FALSE;
  87.         const char* pszMimeType = (const char*) pMimeTypeStr->GetBuffer();
  88.         if (pszMimeType &&
  89.             (!strcmp(pszMimeType, IMAGE_MIMETYPE_WBMP) ||
  90.              !strcmp(pszMimeType, IMAGE_MIMETYPE_WBMP_STREAMED)))
  91.         {
  92.             m_bIsWBMP = TRUE;
  93.         }
  94.         // Get the common class factory
  95.         HX_RELEASE(m_pFactory);
  96.         retVal = m_pContext->QueryInterface(IID_IHXCommonClassFactory,
  97.                                             (void**) &m_pFactory);
  98.         if (SUCCEEDED(retVal))
  99.         {
  100.             // Create a TPtrC8 object to hold the input buffer
  101.             HX_DELETE(m_pInput);
  102.             m_pInput = new TPtrC8((const TUint8*) m_pInputBuffer->GetBuffer(),
  103.                                   (TInt) m_pInputBuffer->GetSize());
  104.             if (m_pInput)
  105.             {
  106.                 // Create the CMdaImageFileToBitmapUtility object
  107.                 HX_DELETE(m_pConverter);
  108.                 m_pConverter = CMdaImageDescToBitmapUtility::NewL(*this);
  109.                 if (m_pConverter)
  110.                 {
  111.                     // Create WBMP-related objects if necessary
  112.                     HX_DELETE(m_pFormat);
  113.                     HX_DELETE(m_pCodec);
  114.                     if (m_bIsWBMP)
  115.                     {
  116.                         m_pFormat = new TMdaWbmpClipFormat();
  117.                         m_pCodec  = new TMdaWbmpCodec();
  118.                     }
  119.                     // Set the state
  120.                     m_ulState = kStateOpenCompletePending;
  121.                     // Clear the return value
  122.                     retVal = HXR_OK;
  123.                     // Call the asynch OpenL() method
  124.                     m_pConverter->OpenL(*m_pInput, m_pFormat, m_pCodec);
  125.                 }
  126.             }
  127.         }
  128.     }
  129.     return retVal;    
  130. }
  131. void CSymbianImageDecoder::MiuoOpenComplete(TInt aError)
  132. {
  133.     if (m_ulState == kStateOpenCompletePending)
  134.     {
  135.         // We don't need the format and codec objects any more
  136.         HX_DELETE(m_pFormat);
  137.         HX_DELETE(m_pCodec);
  138.         // Save our status
  139.         TInt tErr = aError;
  140.         if (tErr == KErrNone)
  141.         {
  142.             // Get the size of the image
  143.             TFrameInfo frameInfo;
  144.             m_pConverter->FrameInfo(0, frameInfo);
  145.             // Create a bitmap
  146.             HX_DELETE(m_pBitmap);
  147.             m_pBitmap = new CFbsBitmap();
  148.             if (m_pBitmap)
  149.             {
  150.                 tErr = m_pBitmap->Create(frameInfo.iOverallSizeInPixels,
  151.                                          EColor4K);
  152.                 if (tErr == KErrNone)
  153.                 {
  154.                     // Set the state
  155.                     m_ulState = kStateConvertCompletePending;
  156.                     // Make the asynch call to ConvertL()
  157.                     m_pConverter->ConvertL(*m_pBitmap, 0);
  158.                 }
  159.             }
  160.             else
  161.             {
  162.                 tErr = KErrNoMemory;
  163.             }
  164.         }
  165.         if (tErr != KErrNone)
  166.         {
  167.             // Set the state
  168.             m_ulState = kStateReady;
  169.             // Call back failure
  170.             m_pResponse->DecodeDone(HXR_FAIL, NULL, NULL);
  171.         }
  172.     }
  173. }
  174. void CSymbianImageDecoder::MiuoConvertComplete(TInt aError)
  175. {
  176.     if (m_ulState == kStateConvertCompletePending)
  177.     {
  178.         // Set the state
  179.         m_ulState = kStateReady;
  180.         // Check the error
  181.         HX_RESULT retVal = HXR_FAIL;
  182.         // Check the error return
  183.         if (aError == KErrNone)
  184.         {
  185.             // Get the bitmap size
  186.             TSize cSize = m_pBitmap->SizeInPixels();
  187.             // Set the bitmap info header
  188.             HXBitmapInfoHeader cHdr;
  189.             cHdr.biSize          = 52;
  190.             cHdr.biWidth         = (INT32) cSize.iWidth;
  191.             cHdr.biHeight        = (INT32) cSize.iHeight;
  192.             cHdr.biPlanes        = 1;
  193.             cHdr.biBitCount      = 16;
  194.             cHdr.biCompression   = HX_BITFIELDS;
  195.             cHdr.biSizeImage     = 0;
  196.             cHdr.biXPelsPerMeter = 0;
  197.             cHdr.biYPelsPerMeter = 0;
  198.             cHdr.biClrUsed       = 0;
  199.             cHdr.biClrImportant  = 0;
  200.             cHdr.rcolor          = 0x0F00;
  201.             cHdr.gcolor          = 0x00F0;
  202.             cHdr.bcolor          = 0x000F;
  203.             // Create an IHXBuffer
  204.             IHXBuffer* pOutBuffer = NULL;
  205.             retVal = m_pFactory->CreateInstance(CLSID_IHXBuffer,
  206.                                                 (void**) &pOutBuffer);
  207.             if (SUCCEEDED(retVal))
  208.             {
  209.                 // Get the length of scanline in bytes
  210.                 UINT32 ulByteWidth  = (UINT32) CFbsBitmap::ScanLineLength(cSize.iWidth,
  211.                                                                           m_pBitmap->DisplayMode());
  212.                 // Get the total number of bytes in the bitmap
  213.                 UINT32 ulTotalBytes = ulByteWidth * cSize.iHeight;
  214.                 // Set the output buffer
  215.                 retVal = pOutBuffer->Set((const BYTE*) m_pBitmap->DataAddress(),
  216.                                          ulTotalBytes);
  217.                 if (SUCCEEDED(retVal))
  218.                 {
  219.                     // Call back to the response
  220.                     m_pResponse->DecodeDone(HXR_OK, &cHdr, pOutBuffer);
  221.                 }
  222.             }
  223.             // Now we can clean up
  224.             HX_RELEASE(pOutBuffer);
  225.             HX_DELETE(m_pInput);
  226.             HX_RELEASE(m_pInputBuffer);
  227.             HX_DELETE(m_pBitmap);
  228.             HX_DELETE(m_pConverter);
  229.         }
  230.         if (FAILED(retVal))
  231.         {
  232.             m_pResponse->DecodeDone(HXR_FAIL, NULL, NULL);
  233.         }
  234.     }
  235. }
  236. void CSymbianImageDecoder::MiuoCreateComplete(TInt aError)
  237. {
  238. }