gui_bytestream.c
上传用户:lqx1163
上传日期:2014-08-13
资源大小:9183k
文件大小:21k
源码类别:

MTK

开发平台:

C/C++

  1. /*****************************************************************************
  2. *  Copyright Statement:
  3. *  --------------------
  4. *  This software is protected by Copyright and the information contained
  5. *  herein is confidential. The software may not be copied and the information
  6. *  contained herein may not be used or disclosed except with the written
  7. *  permission of MediaTek Inc. (C) 2005
  8. *
  9. *  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
  10. *  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
  11. *  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
  12. *  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
  13. *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
  14. *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
  15. *  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
  16. *  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
  17. *  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
  18. *  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
  19. *  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
  20. *  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
  21. *
  22. *  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
  23. *  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
  24. *  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
  25. *  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
  26. *  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
  27. *
  28. *  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
  29. *  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
  30. *  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
  31. *  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
  32. *  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
  33. *
  34. *****************************************************************************/
  35. /*****************************************************************************
  36.  *
  37.  * Filename:
  38.  * ---------
  39.  *   gui_bytestream.c
  40.  *
  41.  * Project:
  42.  * --------
  43.  *   MAUI
  44.  *
  45.  * Description:
  46.  * ------------
  47.  *   Bytestream Interface for Image Decoder
  48.  *
  49.  *   (Deprecated by gdi_bytestream.c)
  50.  *
  51.  * Author:
  52.  * -------
  53.  *
  54.  *============================================================================
  55.  *             HISTORY
  56.  * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  57.  *------------------------------------------------------------------------------
  58.  * removed!
  59.  *
  60.  *------------------------------------------------------------------------------
  61.  * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  62.  *============================================================================
  63.  ****************************************************************************/
  64. /**
  65.  * Copyright Notice
  66.  * ?2002 - 2003, Pixtel Communications, Inc., 1489 43rd Ave. W.,
  67.  * Vancouver, B.C. V6M 4K8 Canada. All Rights Reserved.
  68.  *  (It is illegal to remove this copyright notice from this software or any
  69.  *  portion of it)
  70.  */
  71. /**********************************************************************************
  72.    Filename:      gui_bytestream.c
  73.    Author:        manju
  74.    Date Created:  June-10-2002
  75.    Contains:      bytestream data type
  76.                These are used to process ROM images of binary files
  77. **********************************************************************************/
  78. #include "gui_bytestream.h"
  79. #define GUI_BYTESTREAM_IRAM_PLACEMENT     0
  80. #if(GUI_BYTESTREAM_IRAM_PLACEMENT)
  81. #ifdef __MTK_TARGET__
  82. #pragma arm section code = "INTERNCODE"
  83. #endif 
  84. #endif /* (GUI_BYTESTREAM_IRAM_PLACEMENT) */ 
  85. /*****************************************************************************
  86.  * FUNCTION
  87.  *  bytestream_initialize
  88.  * DESCRIPTION
  89.  *  initialize a bytestraem
  90.  * PARAMETERS
  91.  *  file        [IN]        
  92.  *  data        [IN]        
  93.  *  size        [IN]        
  94.  * RETURNS
  95.  *  void
  96.  *****************************************************************************/
  97. void bytestream_initialize(bytestream *file, U8 *data, S32 size)
  98. {
  99.     /*----------------------------------------------------------------*/
  100.     /* Local Variables                                                */
  101.     /*----------------------------------------------------------------*/
  102.     /*----------------------------------------------------------------*/
  103.     /* Code Body                                                      */
  104.     /*----------------------------------------------------------------*/
  105.     file->data = data;
  106.     file->size = size;
  107.     file->current_offset = 0;
  108. }
  109. /*****************************************************************************
  110.  * FUNCTION
  111.  *  bytestream_fclose
  112.  * DESCRIPTION
  113.  *  close teh file
  114.  * PARAMETERS
  115.  *  file        [IN]        
  116.  * RETURNS
  117.  *  void
  118.  *****************************************************************************/
  119. void bytestream_fclose(bytestream *file)
  120. {
  121.     /*----------------------------------------------------------------*/
  122.     /* Local Variables                                                */
  123.     /*----------------------------------------------------------------*/
  124.     /*----------------------------------------------------------------*/
  125.     /* Code Body                                                      */
  126.     /*----------------------------------------------------------------*/
  127.     file->data = NULL;
  128.     file->size = 0;
  129.     file->current_offset = 0;
  130. }
  131. /*****************************************************************************
  132.  * FUNCTION
  133.  *  bytestream_fseek
  134.  * DESCRIPTION
  135.  *  seek a file pointer to particular position
  136.  * PARAMETERS
  137.  *  file        [IN]        
  138.  *  offset      [IN]        
  139.  *  mode        [IN]        
  140.  * RETURNS
  141.  *  byte- //true or false
  142.  *****************************************************************************/
  143. U8 bytestream_fseek(bytestream *file, S32 offset, S32 mode)
  144. {
  145.     /*----------------------------------------------------------------*/
  146.     /* Local Variables                                                */
  147.     /*----------------------------------------------------------------*/
  148.     S32 start_offset, final_offset;
  149.     /*----------------------------------------------------------------*/
  150.     /* Code Body                                                      */
  151.     /*----------------------------------------------------------------*/
  152.     switch (mode)
  153.     {
  154.         case SEEK_END:
  155.             start_offset = file->size - 1;
  156.             break;
  157.         case SEEK_SET:
  158.             start_offset = 0;
  159.             break;
  160.         case SEEK_CUR:
  161.         default:
  162.             start_offset = file->current_offset;
  163.             break;
  164.     }
  165.     final_offset = start_offset + offset;
  166.     if (final_offset < 0 || final_offset >= file->size)
  167.     {
  168.         return (1);
  169.     }
  170.     else
  171.     {
  172.         file->current_offset = final_offset;
  173.         return (0);
  174.     }
  175. }
  176. /*****************************************************************************
  177.  * FUNCTION
  178.  *  bytestream_feof
  179.  * DESCRIPTION
  180.  *  check if end of file
  181.  * PARAMETERS
  182.  *  file        [IN]        
  183.  * RETURNS
  184.  *  byte- //true or false
  185.  *****************************************************************************/
  186. U8 bytestream_feof(bytestream *file)
  187. {
  188.     /*----------------------------------------------------------------*/
  189.     /* Local Variables                                                */
  190.     /*----------------------------------------------------------------*/
  191.     /*----------------------------------------------------------------*/
  192.     /* Code Body                                                      */
  193.     /*----------------------------------------------------------------*/
  194.     if (file->current_offset >= file->size)
  195.     {
  196.         return (1);
  197.     }
  198.     else
  199.     {
  200.         return (0);
  201.     }
  202. }
  203. /*****************************************************************************
  204.  * FUNCTION
  205.  *  bytestream_fgetbyte
  206.  * DESCRIPTION
  207.  *  read a byte from fiel
  208.  * PARAMETERS
  209.  *  file        [IN]        
  210.  * RETURNS
  211.  *  byte-
  212.  *****************************************************************************/
  213. U8 bytestream_fgetbyte(bytestream *file)
  214. {
  215.     /*----------------------------------------------------------------*/
  216.     /* Local Variables                                                */
  217.     /*----------------------------------------------------------------*/
  218.     U8 c;
  219.     /*----------------------------------------------------------------*/
  220.     /* Code Body                                                      */
  221.     /*----------------------------------------------------------------*/
  222.     if (bytestream_feof(file))
  223.     {
  224.         return (0);
  225.     }
  226.     c = file->data[file->current_offset];
  227.     file->current_offset++;
  228.     return (c);
  229. }
  230. /*****************************************************************************
  231.  * FUNCTION
  232.  *  bytestream_fputbyte
  233.  * DESCRIPTION
  234.  *  insert a byte in file
  235.  * PARAMETERS
  236.  *  file        [IN]        
  237.  *  c           [IN]        
  238.  * RETURNS
  239.  *  byte- true or flase
  240.  *****************************************************************************/
  241. U8 bytestream_fputbyte(bytestream *file, U8 c)
  242. {
  243.     /*----------------------------------------------------------------*/
  244.     /* Local Variables                                                */
  245.     /*----------------------------------------------------------------*/
  246.     /*----------------------------------------------------------------*/
  247.     /* Code Body                                                      */
  248.     /*----------------------------------------------------------------*/
  249.     if (bytestream_feof(file))
  250.     {
  251.         return (0);
  252.     }
  253.     file->data[file->current_offset] = c;
  254.     file->current_offset++;
  255.     return (1);
  256. }
  257. /*****************************************************************************
  258.  * FUNCTION
  259.  *  bytestream_fread
  260.  * DESCRIPTION
  261.  *  get  word
  262.  * PARAMETERS
  263.  *  buffer      [OUT]       Data read from file
  264.  *  size        [IN]        // size of data
  265.  *  number      [IN]        // number of bytes to read
  266.  *  file        [IN]        File pointer
  267.  * RETURNS
  268.  *  size_t return number of bytes read from file
  269.  *****************************************************************************/
  270. size_t bytestream_fread(U8 *buffer, size_t size, size_t number, bytestream *file)
  271. {
  272.     /*----------------------------------------------------------------*/
  273.     /* Local Variables                                                */
  274.     /*----------------------------------------------------------------*/
  275.     U32 count = 0, i;
  276.     /*----------------------------------------------------------------*/
  277.     /* Code Body                                                      */
  278.     /*----------------------------------------------------------------*/
  279.     for (i = (U32) size * number; i; i--)
  280.     {
  281.         if (bytestream_feof(file))
  282.         {
  283.             break;
  284.         }
  285.         buffer[count++] = bytestream_fgetbyte(file);
  286.     }
  287.     return (count);
  288. }
  289. /*****************************************************************************
  290.  * FUNCTION
  291.  *  bytestream_fgetword
  292.  * DESCRIPTION
  293.  *  get  word
  294.  * PARAMETERS
  295.  *  file            [?]         
  296.  *  pointer(?)      [IN]        Of file
  297.  * RETURNS
  298.  *  word
  299.  *****************************************************************************/
  300. U16 bytestream_fgetword(bytestream *file)
  301. {
  302.     /*----------------------------------------------------------------*/
  303.     /* Local Variables                                                */
  304.     /*----------------------------------------------------------------*/
  305.     U16 MSB, LSB;
  306.     /*----------------------------------------------------------------*/
  307.     /* Code Body                                                      */
  308.     /*----------------------------------------------------------------*/
  309.     LSB = bytestream_fgetbyte(file);
  310.     MSB = bytestream_fgetbyte(file);
  311.     return ((U16) ((MSB << 8) | LSB));
  312. }
  313. /*****************************************************************************
  314.  * FUNCTION
  315.  *  bytestream_fgetdword
  316.  * DESCRIPTION
  317.  *  get  U32
  318.  * PARAMETERS
  319.  *  file            [?]         
  320.  *  pointer(?)      [IN]        Of file
  321.  * RETURNS
  322.  *  U32
  323.  *****************************************************************************/
  324. U32 bytestream_fgetdword(bytestream *file)
  325. {
  326.     /*----------------------------------------------------------------*/
  327.     /* Local Variables                                                */
  328.     /*----------------------------------------------------------------*/
  329.     U32 MSB, LSB;
  330.     /*----------------------------------------------------------------*/
  331.     /* Code Body                                                      */
  332.     /*----------------------------------------------------------------*/
  333.     LSB = bytestream_fgetword(file);
  334.     MSB = bytestream_fgetword(file);
  335.     return ((MSB << 16) | LSB);
  336. }
  337. /*****************************************************************************
  338.  * FUNCTION
  339.  *  bytestream_fputword
  340.  * DESCRIPTION
  341.  *  insert  word in  big endian format in file
  342.  * PARAMETERS
  343.  *  file            [?]         
  344.  *  w               [IN]        
  345.  *  word(?)         [IN]        D
  346.  *  pointer(?)      [IN]        Of file
  347.  * RETURNS
  348.  *  byte
  349.  *****************************************************************************/
  350. U8 bytestream_fputword(bytestream *file, U16 w)
  351. {
  352.     /*----------------------------------------------------------------*/
  353.     /* Local Variables                                                */
  354.     /*----------------------------------------------------------------*/
  355.     U8 MSB, LSB, rvalue;
  356.     /*----------------------------------------------------------------*/
  357.     /* Code Body                                                      */
  358.     /*----------------------------------------------------------------*/
  359.     LSB = (U8) (w & 0xff);
  360.     MSB = (U8) (w >> 8);
  361.     rvalue = bytestream_fputbyte(file, LSB);
  362.     rvalue = bytestream_fputbyte(file, MSB);
  363.     return (rvalue);
  364. }
  365. /*****************************************************************************
  366.  * FUNCTION
  367.  *  bytestream_fputword_bigendian
  368.  * DESCRIPTION
  369.  *  insert  word in  big endian format in file
  370.  * PARAMETERS
  371.  *  file            [?]         
  372.  *  w               [IN]        
  373.  *  word(?)         [IN]        D
  374.  *  pointer(?)      [IN]        Of file
  375.  * RETURNS
  376.  *  byte
  377.  *****************************************************************************/
  378. U8 bytestream_fputword_bigendian(bytestream *file, U16 w)
  379. {
  380.     /*----------------------------------------------------------------*/
  381.     /* Local Variables                                                */
  382.     /*----------------------------------------------------------------*/
  383.     U8 MSB, LSB, rvalue;
  384.     /*----------------------------------------------------------------*/
  385.     /* Code Body                                                      */
  386.     /*----------------------------------------------------------------*/
  387.     LSB = (U8) (w & 0xff);
  388.     MSB = (U8) (w >> 8);
  389.     rvalue = bytestream_fputbyte(file, MSB);
  390.     rvalue = bytestream_fputbyte(file, LSB);
  391.     return (rvalue);
  392. }
  393. /*****************************************************************************
  394.  * FUNCTION
  395.  *  bytestream_fputdword
  396.  * DESCRIPTION
  397.  *  insert  U32 in  big endian format in file
  398.  * PARAMETERS
  399.  *  file            [?]         
  400.  *  d               [IN]        
  401.  *  pointer(?)      [IN]        Of file
  402.  * RETURNS
  403.  *  byte
  404.  *****************************************************************************/
  405. U8 bytestream_fputdword(bytestream *file, U32 d)
  406. {
  407.     /*----------------------------------------------------------------*/
  408.     /* Local Variables                                                */
  409.     /*----------------------------------------------------------------*/
  410.     U16 MSB, LSB;
  411.     U8 rvalue;
  412.     /*----------------------------------------------------------------*/
  413.     /* Code Body                                                      */
  414.     /*----------------------------------------------------------------*/
  415.     LSB = (U16) (d & 0xffff);
  416.     MSB = (U16) (d >> 16);
  417.     rvalue = bytestream_fputword(file, LSB);
  418.     rvalue = bytestream_fputword(file, MSB);
  419.     return (rvalue);
  420. }
  421. /*****************************************************************************
  422.  * FUNCTION
  423.  *  bytestream_fputdword_bigendian
  424.  * DESCRIPTION
  425.  *  insert  U32 in  big endian format in file
  426.  * PARAMETERS
  427.  *  file            [?]         
  428.  *  d               [IN]        
  429.  *  pointer(?)      [IN]        Of file
  430.  * RETURNS
  431.  *  byte
  432.  *****************************************************************************/
  433. U8 bytestream_fputdword_bigendian(bytestream *file, U32 d)
  434. {
  435.     /*----------------------------------------------------------------*/
  436.     /* Local Variables                                                */
  437.     /*----------------------------------------------------------------*/
  438.     U16 MSB, LSB;
  439.     U8 rvalue;
  440.     /*----------------------------------------------------------------*/
  441.     /* Code Body                                                      */
  442.     /*----------------------------------------------------------------*/
  443.     LSB = (U16) (d & 0xffff);
  444.     MSB = (U16) (d >> 16);
  445.     rvalue = bytestream_fputword_bigendian(file, MSB);
  446.     rvalue = bytestream_fputword_bigendian(file, LSB);
  447.     return (rvalue);
  448. }
  449. /*****************************************************************************
  450.  * FUNCTION
  451.  *  bytestream_fgetword_bigendian
  452.  * DESCRIPTION
  453.  *  get word in  big endian format fron file
  454.  * PARAMETERS
  455.  *  file            [?]         
  456.  *  pointer(?)      [IN]        Of file
  457.  * RETURNS
  458.  *  word
  459.  *****************************************************************************/
  460. U16 bytestream_fgetword_bigendian(bytestream *file)
  461. {
  462.     /*----------------------------------------------------------------*/
  463.     /* Local Variables                                                */
  464.     /*----------------------------------------------------------------*/
  465.     U16 MSB, LSB;
  466.     /*----------------------------------------------------------------*/
  467.     /* Code Body                                                      */
  468.     /*----------------------------------------------------------------*/
  469.     MSB = bytestream_fgetbyte(file);
  470.     LSB = bytestream_fgetbyte(file);
  471.     return ((U16) ((MSB << 8) | LSB));
  472. }
  473. /*****************************************************************************
  474.  * FUNCTION
  475.  *  bytestream_fgetdword_bigendian
  476.  * DESCRIPTION
  477.  *  get dwordin big endian format fron file
  478.  * PARAMETERS
  479.  *  file            [?]         
  480.  *  pointer(?)      [IN]        Of file
  481.  * RETURNS
  482.  *  U32
  483.  *****************************************************************************/
  484. U32 bytestream_fgetdword_bigendian(bytestream *file)
  485. {
  486.     /*----------------------------------------------------------------*/
  487.     /* Local Variables                                                */
  488.     /*----------------------------------------------------------------*/
  489.     U32 MSB, LSB;
  490.     /*----------------------------------------------------------------*/
  491.     /* Code Body                                                      */
  492.     /*----------------------------------------------------------------*/
  493.     MSB = bytestream_fgetword_bigendian(file);
  494.     LSB = bytestream_fgetword_bigendian(file);
  495.     return ((MSB << 16) | LSB);
  496. }
  497. #if(GUI_BYTESTREAM_IRAM_PLACEMENT)
  498. #ifdef __MTK_TARGET__
  499. #pragma arm section code
  500. #endif 
  501. #endif /* (GUI_BYTESTREAM_IRAM_PLACEMENT) */ 
  502. /*****************************************************************************
  503.  * FUNCTION
  504.  *  bytestream_fgetvdata
  505.  * DESCRIPTION
  506.  *  Used to read variable length data: Useful only for MIDI files
  507.  * PARAMETERS
  508.  *  file            [?]         
  509.  *  pointer(?)      [IN]        Of file
  510.  * RETURNS
  511.  *  void
  512.  *****************************************************************************/
  513. /* Used to read variable length data: Useful only for MIDI files  */
  514. U32 bytestream_fgetvdata(bytestream *file)
  515. {
  516.     /*----------------------------------------------------------------*/
  517.     /* Local Variables                                                */
  518.     /*----------------------------------------------------------------*/
  519.     U32 rvalue;
  520.     U8 b;
  521.     /*----------------------------------------------------------------*/
  522.     /* Code Body                                                      */
  523.     /*----------------------------------------------------------------*/
  524.     if ((rvalue = bytestream_fgetbyte(file)) & 0x80)
  525.     {
  526.         rvalue &= 0x7f;
  527.         do
  528.         {
  529.             rvalue = (rvalue << 7) + ((b = bytestream_fgetbyte(file)) & 0x7f);
  530.         } while (b & 0x80);
  531.     }
  532.     return (rvalue);
  533. }