wbmphdr.cpp
Upload User: dangjiwu
Upload Date: 2013-07-19
Package Size: 42019k
Code Size: 6k
Category:

Symbian

Development Platform:

Visual C++

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Source last modified: $Id: wbmphdr.cpp,v 1.1.20.1 2004/07/09 01:53:03 hubbe Exp $
  3.  * 
  4.  * Portions Copyright (c) 1995-2004 RealNetworks, Inc. All Rights Reserved.
  5.  * 
  6.  * The contents of this file, and the files included with this file,
  7.  * are subject to the current version of the RealNetworks Public
  8.  * Source License (the "RPSL") available at
  9.  * http://www.helixcommunity.org/content/rpsl unless you have licensed
  10.  * the file under the current version of the RealNetworks Community
  11.  * Source License (the "RCSL") available at
  12.  * http://www.helixcommunity.org/content/rcsl, in which case the RCSL
  13.  * will apply. You may also obtain the license terms directly from
  14.  * RealNetworks.  You may not use this file except in compliance with
  15.  * the RPSL or, if you have a valid RCSL with RealNetworks applicable
  16.  * to this file, the RCSL.  Please see the applicable RPSL or RCSL for
  17.  * the rights, obligations and limitations governing use of the
  18.  * contents of the file.
  19.  * 
  20.  * Alternatively, the contents of this file may be used under the
  21.  * terms of the GNU General Public License Version 2 or later (the
  22.  * "GPL") in which case the provisions of the GPL are applicable
  23.  * instead of those above. If you wish to allow use of your version of
  24.  * this file only under the terms of the GPL, and not to allow others
  25.  * to use your version of this file under the terms of either the RPSL
  26.  * or RCSL, indicate your decision by deleting the provisions above
  27.  * and replace them with the notice and other provisions required by
  28.  * the GPL. If you do not delete the provisions above, a recipient may
  29.  * use your version of this file under the terms of any one of the
  30.  * RPSL, the RCSL or the GPL.
  31.  * 
  32.  * This file is part of the Helix DNA Technology. RealNetworks is the
  33.  * developer of the Original Code and owns the copyrights in the
  34.  * portions it created.
  35.  * 
  36.  * This file, and the files included with this file, is distributed
  37.  * and made available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY
  38.  * KIND, EITHER EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS
  39.  * ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES
  40.  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET
  41.  * ENJOYMENT OR NON-INFRINGEMENT.
  42.  * 
  43.  * Technology Compatibility Kit Test Suite(s) Location:
  44.  *    http://www.helixcommunity.org/content/tck
  45.  * 
  46.  * Contributor(s):
  47.  * 
  48.  * ***** END LICENSE BLOCK ***** */
  49. #include "hxtypes.h"
  50. #include "hxcom.h"
  51. #include "wbmphdr.h"
  52. // pndebug
  53. #include "hxheap.h"
  54. #ifdef _DEBUG
  55. #undef HX_THIS_FILE             
  56. static char HX_THIS_FILE[] = __FILE__;
  57. #endif
  58. HX_RESULT ParseWBMPHeader(BYTE*       pBuf,
  59.                           UINT32      ulSize,
  60.                           REF(UINT32) rulWidth,
  61.                           REF(UINT32) rulHeight,
  62.                           REF(UINT32) rulHeaderSize)
  63. {
  64.     HX_RESULT retVal = HXR_FAIL;
  65.     // Specification for WBMP header is found in Appendix A of
  66.     // the Wireless Application Envinorment from the WAP Forum at:
  67.     // http://www.wapforum.org/what/technical/SPEC-WAESpec-19990524.pdf
  68.     if (pBuf && ulSize)
  69.     {
  70.         // Get bitmap type
  71.         BYTE*     pBufStart  = pBuf;
  72.         BYTE*     pBufLimit  = pBuf + ulSize;
  73.         UINT32    ulType     = 0;
  74.         UINT32    ulNumBytes = 0;
  75.         HX_RESULT rv         = ParseMultiByteInteger(pBuf, pBufLimit - pBuf, ulType, ulNumBytes);
  76.         if (SUCCEEDED(rv))
  77.         {
  78.             // Make sure we have type 0
  79.             if (ulType == 0)
  80.             {
  81.                 // Advance the buffer pointer
  82.                 pBuf += ulNumBytes;
  83.                 // Get the FixHeaderField
  84.                 if (pBuf < pBufLimit)
  85.                 {
  86.                     UINT32 ulFixedHeader = *pBuf++;
  87.                     // For now, we only support extension header type 00
  88.                     if (ulFixedHeader == 0)
  89.                     {
  90.                         // Get the width
  91.                         rv = ParseMultiByteInteger(pBuf, pBufLimit - pBuf, rulWidth, ulNumBytes);
  92.                         if (SUCCEEDED(rv))
  93.                         {
  94.                             // Advance the pointer
  95.                             pBuf += ulNumBytes;
  96.                             // Get the height
  97.                             rv = ParseMultiByteInteger(pBuf, pBufLimit - pBuf, rulHeight, ulNumBytes);
  98.                             if (SUCCEEDED(rv))
  99.                             {
  100.                                 // Advance the pointer
  101.                                 pBuf += ulNumBytes;
  102.                                 // Clear the return value
  103.                                 retVal = HXR_OK;
  104.                                 // Compute the number of bytes used
  105.                                 rulHeaderSize = pBuf - pBufStart;
  106.                             }
  107.                         }
  108.                     }
  109.                 }
  110.             }
  111.         }
  112.     }
  113.     return retVal;
  114. }
  115. HX_RESULT ParseMultiByteInteger(BYTE* pBuf, INT32 lSize,
  116.                                 REF(UINT32) rulValue,
  117.                                 REF(UINT32) rulNumBytes)
  118. {
  119.     HX_RESULT retVal = HXR_FAIL;
  120.     if (pBuf && lSize > 0)
  121.     {
  122.         // WBMP's multi-byte format reserves the most significant bit
  123.         // as a continuation marker. If that bit = 0, then this byte
  124.         // is the last byte. If that bit = 1, then there are additional
  125.         // bytes. For instance, the value 0xA0 would be represented in
  126.         // this multi-byte format as 0x81 0x20. To parse this format,
  127.         // we have to find the last byte and then re-pack backwards from there.
  128.         // Find the end of the multi-byte integer
  129.         BYTE* pBufStart = pBuf;
  130.         BYTE* pBufLimit = pBuf + lSize;
  131.         rulValue        = 0;
  132.         while (pBuf < pBufLimit)
  133.         {
  134.             rulValue = (rulValue << 7) | (*pBuf & 0x7F);
  135.             if (!(*pBuf & 0x80))
  136.             {
  137.                 break;
  138.             }
  139.             pBuf++;
  140.         }
  141.         // Assign the rulNumBytes out parameter
  142.         rulNumBytes = pBuf - pBufStart + 1;
  143.         // Clear the return value
  144.         retVal = HXR_OK;
  145.     }
  146.     return retVal;
  147. }