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

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.  * Filename:
  37.  * ---------
  38.  *  GIFLoader.c
  39.  *
  40.  * Project:
  41.  * --------
  42.  *  MAUI
  43.  *
  44.  * Description:
  45.  * ------------
  46.  *  
  47.  *
  48.  * Author:
  49.  * -------
  50.  *  
  51.  *
  52.  *==============================================================================
  53.  *             HISTORY
  54.  * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!! 
  55.  *------------------------------------------------------------------------------
  56.  * removed!
  57.  *
  58.  *------------------------------------------------------------------------------
  59.  * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!! 
  60.  *==============================================================================
  61.  *******************************************************************************/
  62. #include <stdio.h>
  63. #include <stdlib.h>
  64. #include <string.h>
  65. #include "ResDevice.h"
  66. #include "ResBytestream.h"
  67. #include "ImgDecoderDef.h"
  68. extern U32 image_static_row_data[];
  69. extern U32 image_static_palette[];
  70. extern U32 image_static_buffer[];
  71. /* GIF code from WINGUI.C  */
  72. /*****************************************************************************
  73.  * FUNCTION
  74.  *  GIF_get_byte
  75.  * DESCRIPTION
  76.  *  
  77.  * PARAMETERS
  78.  *  file        [?]     
  79.  * RETURNS
  80.  *  
  81.  *****************************************************************************/
  82. U8 GIF_get_byte(bytestream *file)
  83. {
  84.     /*----------------------------------------------------------------*/
  85.     /* Local Variables                                                */
  86.     /*----------------------------------------------------------------*/
  87.     /*----------------------------------------------------------------*/
  88.     /* Code Body                                                      */
  89.     /*----------------------------------------------------------------*/
  90.     return (bytestream_fgetbyte(file));
  91. }
  92. #if(!WINGUI_DIRECT_IMAGE_DISPLAY)
  93. /*****************************************************************************
  94.  * FUNCTION
  95.  *  GIF_write_line
  96.  * DESCRIPTION
  97.  *  
  98.  * PARAMETERS
  99.  *  ix                          [IN]        
  100.  *  iy                          [IN]        
  101.  *  b                           [?]         
  102.  *  buffer                      [?]         
  103.  *  length                      [IN]        
  104.  *  y                           [IN]        
  105.  *  palette                     [?]         
  106.  *  transparent_GIF             [IN]        
  107.  *  transparent_color_index     [IN]        
  108.  * RETURNS
  109.  *  void
  110.  *****************************************************************************/
  111. void GIF_write_line(
  112.         S32 ix,
  113.         S32 iy,
  114.         bitmap *b,
  115.         U8 *buffer,
  116.         S16 length,
  117.         S16 y,
  118.         U8 palette[][3],
  119.         U8 transparent_GIF,
  120.         U8 transparent_color_index)
  121. {
  122.     /*----------------------------------------------------------------*/
  123.     /* Local Variables                                                */
  124.     /*----------------------------------------------------------------*/
  125.     /*----------------------------------------------------------------*/
  126.     /* Code Body                                                      */
  127.     /*----------------------------------------------------------------*/
  128.     if (b == NULL)
  129.     {
  130.         return;
  131.     }
  132.     if (transparent_GIF)
  133.     {
  134.         {
  135.             S32 i;
  136.             U8 color_index;
  137.             U32 offset = (y + iy) * b->xsize + ix;
  138.             U16 *bitmap_data = (U16*) b->data;
  139.             U16 d;
  140.             for (i = 0; i < length; i++)
  141.             {
  142.                 color_index = (U8) buffer[i];
  143.                 d = MMI_RGB_TO_HW_FORMAT(palette[color_index][0], palette[color_index][1], palette[color_index][2]);
  144.                 if (color_index == transparent_color_index)
  145.                 {
  146.                     SET_RGB_TRANSPARENT_COLOR_16(d);
  147.                 }
  148.                 bitmap_data[offset++] = d;
  149.             }
  150.         }
  151.     }
  152.     else
  153.     {
  154.         {
  155.             S32 i;
  156.             U8 color_index;
  157.             U32 offset = (y + iy) * b->xsize + ix;
  158.             U16 *bitmap_data = (U16*) b->data;
  159.             U16 d;
  160.             for (i = 0; i < length; i++)
  161.             {
  162.                 color_index = (U8) buffer[i];
  163.                 d = MMI_RGB_TO_HW_FORMAT(palette[color_index][0], palette[color_index][1], palette[color_index][2]);
  164.                 bitmap_data[offset++] = d;
  165.             }
  166.         }
  167.     }
  168. }
  169. #endif /* (!WINGUI_DIRECT_IMAGE_DISPLAY) */ 
  170. #define GIF_MAX_CODES   4095
  171. S16 GIF_current_code_size, GIF_clear_code, GIF_end_code, GIF_new_codes, GIF_top_slot, GIF_slot;
  172. S16 GIF_navailable_bytes, GIF_nbits_left, GIF_b1;
  173. U8 GIF_byte_buffer[257], *GIF_pbytes;
  174. U16 GIF_code_mask[13] = {0x0000,
  175.     0x0001, 0x0003,
  176.     0x0007, 0x000f,
  177.     0x001f, 0x003f,
  178.     0x007f, 0x00ff,
  179.     0x01ff, 0x03ff,
  180.     0x07ff, 0x0fff
  181. };
  182. /*****************************************************************************
  183.  * FUNCTION
  184.  *  GIF_initialize_decoder
  185.  * DESCRIPTION
  186.  *  
  187.  * PARAMETERS
  188.  *  size        [IN]        
  189.  * RETURNS
  190.  *  void
  191.  *****************************************************************************/
  192. void GIF_initialize_decoder(S16 size)
  193. {
  194.     /*----------------------------------------------------------------*/
  195.     /* Local Variables                                                */
  196.     /*----------------------------------------------------------------*/
  197.     /*----------------------------------------------------------------*/
  198.     /* Code Body                                                      */
  199.     /*----------------------------------------------------------------*/
  200.     GIF_current_code_size = (S16) (size + 1);
  201.     GIF_top_slot = (S16) (1 << GIF_current_code_size);
  202.     GIF_clear_code = (S16) (1 << size);
  203.     GIF_end_code = (S16) (GIF_clear_code + 1);
  204.     GIF_slot = (GIF_new_codes) = (S16) (GIF_end_code + 1);
  205.     GIF_navailable_bytes = GIF_nbits_left = (S16) 0;
  206. }
  207. /*****************************************************************************
  208.  * FUNCTION
  209.  *  GIF_get_next_code
  210.  * DESCRIPTION
  211.  *  
  212.  * PARAMETERS
  213.  *  file        [?]     
  214.  * RETURNS
  215.  *  
  216.  *****************************************************************************/
  217. S16 GIF_get_next_code(bytestream *file)
  218. {
  219.     /*----------------------------------------------------------------*/
  220.     /* Local Variables                                                */
  221.     /*----------------------------------------------------------------*/
  222.     S16 i, x, ret;
  223.     /*----------------------------------------------------------------*/
  224.     /* Code Body                                                      */
  225.     /*----------------------------------------------------------------*/
  226.     if (GIF_nbits_left == 0)
  227.     {
  228.         if (GIF_navailable_bytes <= 0)
  229.         {
  230.             GIF_pbytes = GIF_byte_buffer;
  231.             GIF_navailable_bytes = GIF_get_byte(file);
  232.             if (GIF_navailable_bytes < 0)
  233.             {
  234.                 return (GIF_navailable_bytes);
  235.             }
  236.             else if (GIF_navailable_bytes > 0)
  237.             {
  238.                 for (i = 0; i < GIF_navailable_bytes; i++)
  239.                 {
  240.                     x = GIF_get_byte(file);
  241.                     if (x < 0)
  242.                     {
  243.                         return (x);
  244.                     }
  245.                     GIF_byte_buffer[i] = (U8) x;
  246.                 }
  247.             }
  248.         }
  249.         GIF_b1 = *GIF_pbytes++;
  250.         GIF_nbits_left = 8;
  251.         GIF_navailable_bytes--;
  252.     }
  253.     ret = (S16) (GIF_b1 >> (8 - GIF_nbits_left));
  254.     while (GIF_current_code_size > GIF_nbits_left)
  255.     {
  256.         if (GIF_navailable_bytes <= 0)
  257.         {
  258.             GIF_pbytes = GIF_byte_buffer;
  259.             GIF_navailable_bytes = GIF_get_byte(file);
  260.             if (GIF_navailable_bytes < 0)
  261.             {
  262.                 return (GIF_navailable_bytes);
  263.             }
  264.             else if (GIF_navailable_bytes > 0)
  265.             {
  266.                 for (i = 0; i < GIF_navailable_bytes; i++)
  267.                 {
  268.                     x = GIF_get_byte(file);
  269.                     if (x < 0)
  270.                     {
  271.                         return (x);
  272.                     }
  273.                     GIF_byte_buffer[i] = (U8) x;
  274.                 }
  275.             }
  276.         }
  277.         GIF_b1 = *GIF_pbytes++;
  278.         ret |= GIF_b1 << GIF_nbits_left;
  279.         GIF_nbits_left += 8;
  280.         GIF_navailable_bytes--;
  281.     }
  282.     GIF_nbits_left = (S16) (GIF_nbits_left - GIF_current_code_size);
  283.     ret &= GIF_code_mask[GIF_current_code_size];
  284.     return (ret);
  285. }
  286. S16 GIF_stack[GIF_MAX_CODES + 1];
  287. S16 GIF_suffix[GIF_MAX_CODES + 1];
  288. S16 GIF_prefix[GIF_MAX_CODES + 1];
  289. /*****************************************************************************
  290.  * FUNCTION
  291.  *  GIF_interlace_pass
  292.  * DESCRIPTION
  293.  *  
  294.  * PARAMETERS
  295.  *  y           [?]         
  296.  *  pass        [?]         
  297.  *  ysize       [IN]        
  298.  * RETURNS
  299.  *  void
  300.  *****************************************************************************/
  301. void GIF_interlace_pass(S16 *y, S16 *pass, S16 ysize)
  302. {
  303.     /*----------------------------------------------------------------*/
  304.     /* Local Variables                                                */
  305.     /*----------------------------------------------------------------*/
  306.     /*----------------------------------------------------------------*/
  307.     /* Code Body                                                      */
  308.     /*----------------------------------------------------------------*/
  309.     switch (*pass)
  310.     {
  311.         case 0:
  312.             (*y) += 8;
  313.             if (*y >= ysize)
  314.             {
  315.                 *y = 4;
  316.                 (*pass)++;
  317.             }
  318.             break;
  319.         case 1:
  320.             (*y) += 8;
  321.             if (*y >= ysize)
  322.             {
  323.                 *y = 2;
  324.                 (*pass)++;
  325.             }
  326.             break;
  327.         case 2:
  328.             (*y) += 4;
  329.             if (*y >= ysize)
  330.             {
  331.                 *y = 1;
  332.                 (*pass)++;
  333.             }
  334.             break;
  335.         case 3:
  336.             (*y) += 2;
  337.             break;
  338.     }
  339. }
  340. // #if(!WINGUI_DIRECT_IMAGE_DISPLAY)
  341. /*****************************************************************************
  342.  * FUNCTION
  343.  *  GIF_decoder
  344.  * DESCRIPTION
  345.  *  
  346.  * PARAMETERS
  347.  *  ix                          [IN]        
  348.  *  iy                          [IN]        
  349.  *  file                        [?]         
  350.  *  b                           [?]         
  351.  *  xsize                       [IN]        
  352.  *  ysize                       [IN]        
  353.  *  interlaced                  [IN]        
  354.  *  palette                     [?]         
  355.  *  transparent_GIF             [IN]        
  356.  *  transparent_color_index     [IN]        
  357.  * RETURNS
  358.  *  void
  359.  *****************************************************************************/
  360. void GIF_decoder(
  361.         S32 ix,
  362.         S32 iy,
  363.         bytestream *file,
  364.         bitmap *b,
  365.         S16 xsize,
  366.         S16 ysize,
  367.         U8 interlaced,
  368.         U8 palette[][3],
  369.         U8 transparent_GIF,
  370.         U8 transparent_color_index)
  371. {
  372.     /*----------------------------------------------------------------*/
  373.     /* Local Variables                                                */
  374.     /*----------------------------------------------------------------*/
  375.     S16 *stack_pointer;
  376.     U8 *buffer_pointer;
  377.     U8 *buffer;
  378.     S16 code, fc, oc, buffer_count, c, size, y = 0, pass = 0;
  379.     /*----------------------------------------------------------------*/
  380.     /* Code Body                                                      */
  381.     /*----------------------------------------------------------------*/
  382.     size = GIF_get_byte(file);
  383.     if (size < 0)
  384.     {
  385.         return;
  386.     }
  387.     GIF_initialize_decoder(size);
  388.     oc = fc = 0;
  389.     buffer = (U8*) image_static_row_data;
  390.     stack_pointer = GIF_stack;
  391.     buffer_pointer = buffer;
  392.     buffer_count = xsize;
  393.     while ((c = GIF_get_next_code(file)) != GIF_end_code)
  394.     {
  395.         if (c < 0)
  396.         {
  397.             return;
  398.         }
  399.         if (c == GIF_clear_code)
  400.         {
  401.             GIF_current_code_size = (S16) (size + 1);
  402.             GIF_slot = GIF_new_codes;
  403.             GIF_top_slot = (S16) (1 << GIF_current_code_size);
  404.             while ((c = GIF_get_next_code(file)) == GIF_clear_code);
  405.             if (c == GIF_end_code)
  406.             {
  407.                 break;
  408.             }
  409.             if (c >= GIF_slot)
  410.             {
  411.                 c = 0;
  412.             }
  413.             oc = fc = c;
  414.             *buffer_pointer++ = (U8) c;
  415.             if (--buffer_count == 0)
  416.             {
  417.                 GIF_write_line(ix, iy, b, buffer, xsize, y, palette, transparent_GIF, transparent_color_index);
  418.                 if (interlaced)
  419.                 {
  420.                     GIF_interlace_pass(&y, &pass, ysize);
  421.                 }
  422.                 else
  423.                 {
  424.                     y++;
  425.                 }
  426.                 buffer_pointer = buffer;
  427.                 buffer_count = xsize;
  428.             }
  429.         }
  430.         else
  431.         {
  432.             code = c;
  433.             if (code >= GIF_slot)
  434.             {
  435.                 code = oc;
  436.                 *stack_pointer++ = fc;
  437.             }
  438.             while (code >= GIF_new_codes)
  439.             {
  440.                 *stack_pointer++ = GIF_suffix[code];
  441.                 code = GIF_prefix[code];
  442.             }
  443.             *stack_pointer++ = code;
  444.             if (GIF_slot < GIF_top_slot)
  445.             {
  446.                 GIF_suffix[GIF_slot] = fc = code;
  447.                 GIF_prefix[GIF_slot++] = oc;
  448.                 oc = c;
  449.             }
  450.             if (GIF_slot >= GIF_top_slot)
  451.             {
  452.                 if (GIF_current_code_size < 12)
  453.                 {
  454.                     GIF_top_slot <<= 1;
  455.                     GIF_current_code_size++;
  456.                 }
  457.             }
  458.             while (stack_pointer > GIF_stack)
  459.             {
  460.                 *buffer_pointer++ = (U8) * (--stack_pointer);
  461.                 if (--buffer_count == 0)
  462.                 {
  463.                     GIF_write_line(ix, iy, b, buffer, xsize, y, palette, transparent_GIF, transparent_color_index);
  464.                     if (interlaced)
  465.                     {
  466.                         GIF_interlace_pass(&y, &pass, ysize);
  467.                     }
  468.                     else
  469.                     {
  470.                         y++;
  471.                     }
  472.                     buffer_pointer = buffer;
  473.                     buffer_count = xsize;
  474.                 }
  475.             }
  476.         }
  477.     }
  478.     if (buffer_count != xsize)
  479.     {
  480.         GIF_write_line(ix, iy, b, buffer, xsize, y, palette, transparent_GIF, transparent_color_index);
  481.     }
  482.     if (interlaced)
  483.     {
  484.         GIF_interlace_pass(&y, &pass, ysize);
  485.     }
  486.     else
  487.     {
  488.         y++;
  489.     }
  490. }
  491. /*****************************************************************************
  492.  * FUNCTION
  493.  *  Load_GIF
  494.  * DESCRIPTION
  495.  *  
  496.  * PARAMETERS
  497.  *  file                [?]     
  498.  *  total_frames        [?]     
  499.  * RETURNS
  500.  *  
  501.  *****************************************************************************/
  502. U8 Load_GIF(bytestream *file, S32 *total_frames)
  503. {
  504.     /*----------------------------------------------------------------*/
  505.     /* Local Variables                                                */
  506.     /*----------------------------------------------------------------*/
  507.     S8 gif_signature[4];
  508.     S8 descriptor_flags;
  509.     S16 bits_per_pixel;
  510.     S16 i, j, ncolors;
  511.     S16 x, y, xsize, ysize;
  512.     S8 interlace = 0;
  513.     S8 gif_done;
  514.     S16 screen_xsize, screen_ysize;
  515.     U8 transparent_color_index = 0;
  516.     U8 transparent_GIF = 0;
  517.     U8 palette[256][3];
  518.     S16 frame_counter = 0;
  519.     S16 dest_row_bytes = 0;
  520.     S32 bitmap_size;
  521.     S32 first_frame_xsize = -1, first_frame_ysize = -1;
  522.     /*----------------------------------------------------------------*/
  523.     /* Code Body                                                      */
  524.     /*----------------------------------------------------------------*/
  525.     if (file == NULL)
  526.     {
  527.         return (0);
  528.     }
  529.     /*   read the GIF file signature   */
  530.     bytestream_fseek(file, 0, SEEK_SET);
  531.     bytestream_fread((U8*) gif_signature, 1, 3, file);
  532.     gif_signature[3] = '';
  533.     if (strcmp((const char*)gif_signature, (const char*)"GIF"))
  534.     {
  535.         return (0);
  536.     }
  537.     bytestream_fseek(file, 3, SEEK_CUR);
  538.     screen_xsize = bytestream_fgetword(file);
  539.     screen_ysize = bytestream_fgetword(file);
  540.     printf("Screen Width=%d, Screen Height=%dn", screen_xsize, screen_ysize);
  541.     descriptor_flags = bytestream_fgetbyte(file);
  542.     bytestream_fseek(file, 2, SEEK_CUR);
  543.     if (descriptor_flags & 0x80)
  544.     {
  545.         bits_per_pixel = (S16) ((descriptor_flags & 0x07) + 1);
  546.         ncolors = (S16) (1 << bits_per_pixel);
  547.         /*  Read the global color palette */
  548.         for (i = 0; i < ncolors; i++)
  549.         {
  550.             for (j = 0; j < 3; j++)
  551.             {
  552.                 palette[i][j] = bytestream_fgetbyte(file);
  553.             }
  554.         }
  555.     }
  556.     gif_done = 0;
  557.     do
  558.     {
  559.         char block_type = bytestream_fgetbyte(file);
  560.         switch (block_type)
  561.         {
  562.             case '!':   /* Process the GIF extension block  */
  563.             {
  564.                 S32 block_size;
  565.                 S32 i;
  566.                 U8 label = bytestream_fgetbyte(file);
  567.                 U8 flags, color_index;
  568.                 if (label == 0xf9)
  569.                 {
  570.                     bytestream_fgetbyte(file);
  571.                     flags = bytestream_fgetbyte(file);
  572.                     bytestream_fgetbyte(file);
  573.                     bytestream_fgetbyte(file);
  574.                     color_index = bytestream_fgetbyte(file);
  575.                     if (flags & 0x01)
  576.                     {
  577.                         transparent_GIF = 1;
  578.                         transparent_color_index = color_index;
  579.                         printf("The image is has transparent color:");
  580.                         printf(
  581.                             "(%d,%d,%d)n",
  582.                             palette[color_index][0],
  583.                             palette[color_index][1],
  584.                             palette[color_index][2]);
  585.                     }
  586.                 }
  587.                 else
  588.                 {
  589.                     while ((block_size = bytestream_fgetbyte(file)) != 0)
  590.                     {
  591.                         for (i = 0; i < block_size; i++)
  592.                         {
  593.                             bytestream_fgetbyte(file);
  594.                         }
  595.                     }
  596.                 }
  597.             }
  598.                 break;
  599.             case ',':   /* Process the GIF image   */
  600.             {
  601.                 x = bytestream_fgetword(file);
  602.                 y = bytestream_fgetword(file);
  603.                 xsize = bytestream_fgetword(file);
  604.                 ysize = bytestream_fgetword(file);
  605.                 descriptor_flags = bytestream_fgetbyte(file);
  606.                 if (descriptor_flags & 0x80)
  607.                 {
  608.                     bits_per_pixel = (S16) ((descriptor_flags & 0x07) + 1);
  609.                     ncolors = (S16) (1 << bits_per_pixel);
  610.                     /* Read the local color palette  */
  611.                     for (i = 0; i < ncolors; i++)
  612.                     {
  613.                         for (j = 0; j < 3; j++)
  614.                         {
  615.                             palette[i][j] = bytestream_fgetbyte(file);
  616.                         }
  617.                     }
  618.                     printf("number of color:%dn", ncolors);
  619.                 }
  620.                 if (descriptor_flags & 0x40)
  621.                 {
  622.                     interlace = 1;
  623.                 }
  624.                 if (first_frame_xsize < 0)
  625.                 {
  626.                     first_frame_xsize = xsize;
  627.                     first_frame_ysize = ysize;
  628.                     bitmap_size = dest_row_bytes * ysize;
  629.                 }
  630.                 //                                                      GIF_decoder(x,y,file,b,xsize,ysize,interlace,palette,transparent_GIF,transparent_color_index);
  631.                 //                                                      if((frame_counter>=frame_number) && (b!=NULL)) gif_done=1;
  632.                 frame_counter++;
  633.             }
  634.                 break;
  635.             case '':
  636.                 if (bytestream_feof(file))
  637.                 {
  638.                     gif_done = 1;
  639.                 }
  640.                 break;
  641.             case ';':
  642.                 gif_done = 1;
  643.                 break;
  644.         }
  645.     } while (!gif_done);
  646.     *total_frames = frame_counter;
  647.     printf("Number of frames:%dn", frame_counter);
  648.     return (1);
  649. }
  650. #if 0
  651. /* under construction !*/
  652. /* under construction !*/
  653. /* under construction !*/
  654. /* under construction !*/
  655. /* under construction !*/
  656. /* under construction !*/
  657. /* under construction !*/
  658. /* under construction !*/
  659. /* under construction !*/
  660. /* under construction !*/
  661. /* under construction !*/
  662. /* under construction !*/
  663. /* under construction !*/
  664. /* under construction !*/
  665. /* under construction !*/
  666. /* under construction !*/
  667. /* under construction !*/
  668. /* under construction !*/
  669. /* under construction !*/
  670. /* under construction !*/
  671. /* under construction !*/
  672. /* under construction !*/
  673. /* under construction !*/
  674. /* under construction !*/
  675. /* under construction !*/
  676. /* under construction !*/
  677. /* under construction !*/
  678. /* under construction !*/
  679. /* under construction !*/
  680. /* under construction !*/
  681. /* under construction !*/
  682. /* under construction !*/
  683. /* under construction !*/
  684. /* under construction !*/
  685. /* under construction !*/
  686. /* under construction !*/
  687. /* under construction !*/
  688. /* under construction !*/
  689. /* under construction !*/
  690. /* under construction !*/
  691. /* under construction !*/
  692. /* under construction !*/
  693. /* under construction !*/
  694. /* under construction !*/
  695. /* under construction !*/
  696. /* under construction !*/
  697. /* under construction !*/
  698. /* under construction !*/
  699. /* under construction !*/
  700. /* under construction !*/
  701. /* under construction !*/
  702. /* under construction !*/
  703. /* under construction !*/
  704. /* under construction !*/
  705. /* under construction !*/
  706. /* under construction !*/
  707. /* under construction !*/
  708. /* under construction !*/
  709. /* under construction !*/
  710. /* under construction !*/
  711. /* under construction !*/
  712. /* under construction !*/
  713. /* under construction !*/
  714. /* under construction !*/
  715. /* under construction !*/
  716. /* under construction !*/
  717. /* under construction !*/
  718. /* under construction !*/
  719. /* under construction !*/
  720. /* under construction !*/
  721. /* under construction !*/
  722. /* under construction !*/
  723. /* under construction !*/
  724. /* under construction !*/
  725. /* under construction !*/
  726. /* under construction !*/
  727. /* under construction !*/
  728. /* under construction !*/
  729. /* under construction !*/
  730. /* under construction !*/
  731. /* under construction !*/
  732. /* under construction !*/
  733. /* under construction !*/
  734. /* under construction !*/
  735. /* under construction !*/
  736. /* under construction !*/
  737. /* under construction !*/
  738. /* under construction !*/
  739. /* under construction !*/
  740. /* under construction !*/
  741. /* under construction !*/
  742. /* under construction !*/
  743. /* under construction !*/
  744. /* under construction !*/
  745. /* under construction !*/
  746. /* under construction !*/
  747. /* under construction !*/
  748. /* under construction !*/
  749. /* under construction !*/
  750. /* under construction !*/
  751. /* under construction !*/
  752. /* under construction !*/
  753. /* under construction !*/
  754. /* under construction !*/
  755. /* under construction !*/
  756. /* under construction !*/
  757. /* under construction !*/
  758. /* under construction !*/
  759. /* under construction !*/
  760. /* under construction !*/
  761. /* under construction !*/
  762. /* under construction !*/
  763. /* under construction !*/
  764. /* under construction !*/
  765. /* under construction !*/
  766. /* under construction !*/
  767. /* under construction !*/
  768. /* under construction !*/
  769. /* under construction !*/
  770. /* under construction !*/
  771. /* under construction !*/
  772. /* under construction !*/
  773. /* under construction !*/
  774. /* under construction !*/
  775. /* under construction !*/
  776. /* under construction !*/
  777. /* under construction !*/
  778. /* under construction !*/
  779. /* under construction !*/
  780. /* under construction !*/
  781. /* under construction !*/
  782. /* under construction !*/
  783. /* under construction !*/
  784. /* under construction !*/
  785. /* under construction !*/
  786. /* under construction !*/
  787. /* under construction !*/
  788. /* under construction !*/
  789. /* under construction !*/
  790. /* under construction !*/
  791. /* under construction !*/
  792. #endif /* 0 */ 
  793. /*****************************************************************************
  794.  * FUNCTION
  795.  *  GIFLoader
  796.  * DESCRIPTION
  797.  *  
  798.  * PARAMETERS
  799.  *  in_filename         [?]     
  800.  *  out_filename        [?]     
  801.  * RETURNS
  802.  *  
  803.  *****************************************************************************/
  804. int GIFLoader(char *in_filename, char *out_filename)
  805. {
  806.     /*----------------------------------------------------------------*/
  807.     /* Local Variables                                                */
  808.     /*----------------------------------------------------------------*/
  809.     bitmap outimage;
  810.     FILE *infile;
  811.     FILE *outfile;
  812.     bytestream inimage;
  813.     S32 file_length;
  814.     U8 *buffer;
  815.     S32 i, bitmap_size;
  816.     S32 n_frames, frame_counter, temp_n_frames;
  817.     S32 total_data_size;
  818.     /*----------------------------------------------------------------*/
  819.     /* Code Body                                                      */
  820.     /*----------------------------------------------------------------*/
  821.     infile = fopen(in_filename, "rb");
  822.     if (infile == NULL)
  823.     {
  824.         printf("nError opening %s", in_filename);
  825.         return 0;
  826.     }
  827.     fseek(infile, 0, SEEK_END);
  828.     file_length = ftell(infile);
  829.     fseek(infile, 0, SEEK_SET);
  830.     buffer = (U8*) malloc(file_length);
  831.     if (buffer == NULL)
  832.     {
  833.         printf("nError allocating memory of size %d bytes", file_length);
  834.         fclose(infile);
  835.         return 0;
  836.     }
  837.     fread(buffer, 1, file_length, infile);
  838.     fclose(infile);
  839.     bytestream_initialize(&inimage, buffer, file_length);
  840.     /* Get the number of frames   */
  841.     Load_GIF(&inimage, &n_frames);
  842.     /* GIF_load(&inimage,NULL,DEVICE_COLOR_DEPTH,0,&n_frames); */
  843.     frame_counter = 0;
  844.     free(buffer);
  845.     return 1;
  846. }