/[freetype]/freetype2/src/lzw/ftlzw2.c
ViewVC logotype

Diff of /freetype2/src/lzw/ftlzw2.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by wl, Fri Oct 21 09:08:28 2005 UTC revision 1.3 by wl, Sun Oct 23 19:25:41 2005 UTC
# Line 61  Line 61 
61  /***************************************************************************/  /***************************************************************************/
62  /***************************************************************************/  /***************************************************************************/
63    
64  #define  FT_LZW_BUFFER_SIZE  4096  #define FT_LZW_BUFFER_SIZE  4096
65    
66    typedef struct FT_LZWFileRec_    typedef struct  FT_LZWFileRec_
67    {    {
68      FT_Stream       source;         /* parent/source stream        */      FT_Stream       source;         /* parent/source stream        */
69      FT_Stream       stream;         /* embedding stream            */      FT_Stream       stream;         /* embedding stream            */
70      FT_Memory       memory;         /* memory allocator            */      FT_Memory       memory;         /* memory allocator            */
71      FT_LzwStateRec  lzw;            /* lzw decompressor state      */      FT_LzwStateRec  lzw;            /* lzw decompressor state      */
72    
73      FT_Byte         buffer[ FT_LZW_BUFFER_SIZE ]; /* output buffer */      FT_Byte         buffer[FT_LZW_BUFFER_SIZE]; /* output buffer      */
74      FT_ULong        pos;                          /* position in output */      FT_ULong        pos;                        /* position in output */
75      FT_Byte*        cursor;      FT_Byte*        cursor;
76      FT_Byte*        limit;      FT_Byte*        limit;
77    
# Line 90  Line 90 
90           FT_STREAM_READ( head, 2 ) )           FT_STREAM_READ( head, 2 ) )
91        goto Exit;        goto Exit;
92    
93      /* head[0] && head[1] are the magic numbers     */      /* head[0] && head[1] are the magic numbers */
94      if ( head[0] != 0x1f ||      if ( head[0] != 0x1f ||
95           head[1] != 0x9d )           head[1] != 0x9d )
96        error = LZW_Err_Invalid_File_Format;        error = LZW_Err_Invalid_File_Format;
# Line 194  Line 194 
194    {    {
195      FT_Error  error = LZW_Err_Ok;      FT_Error  error = LZW_Err_Ok;
196    
197     /* first, we skip what we can from the output buffer  
198      */      /* first, we skip what we can from the output buffer */
199      {      {
200        FT_ULong  delta = (FT_ULong)( zip->limit - zip->cursor );        FT_ULong  delta = (FT_ULong)( zip->limit - zip->cursor );
201    
202    
203        if ( delta >= count )        if ( delta >= count )
204          delta = count;          delta = count;
205    
# Line 208  Line 209 
209        count -= delta;        count -= delta;
210      }      }
211    
212     /* next, we skip as many bytes remaining as possible      /* next, we skip as many bytes remaining as possible */
     */  
213      while ( count > 0 )      while ( count > 0 )
214      {      {
215        FT_ULong  delta = FT_LZW_BUFFER_SIZE;        FT_ULong  delta = FT_LZW_BUFFER_SIZE;
216        FT_ULong  numread;        FT_ULong  numread;
217    
218    
219        if ( delta > count )        if ( delta > count )
220          delta = count;          delta = count;
221    
# Line 247  Line 248 
248      /* seeking backwards. */      /* seeking backwards. */
249      if ( pos < zip->pos )      if ( pos < zip->pos )
250      {      {
251       /* if the new position is within the output buffer, simply        /* If the new position is within the output buffer, simply       */
252        * decrement pointers, otherwise, we'll reset the stream completely !!        /* decrement pointers, otherwise we reset the stream completely! */
253        */        if ( ( zip->pos - pos ) <= (FT_ULong)( zip->cursor - zip->buffer ) )
       if ( (zip->pos - pos) <= (FT_ULong)(zip->cursor - zip->buffer) )  
254        {        {
255          zip->cursor -= (zip->pos - pos);          zip->cursor -= zip->pos - pos;
256          zip->pos     = pos;          zip->pos     = pos;
257        }        }
258        else        else
# Line 353  Line 353 
353    
354    
355      /*      /*
356       *  Check the header right now; this prevents allocation a huge       *  Check the header right now; this prevents allocation of a huge
357       *  LZWFile object (400 KByte of heap memory) if not necessary.       *  LZWFile object (400 KByte of heap memory) if not necessary.
358       *       *
359       *  Did I mention that you should never use .Z compressed font       *  Did I mention that you should never use .Z compressed font
360       *  file?       *  files?
361       */       */
362      error = ft_lzw_check_header( source );      error = ft_lzw_check_header( source );
363      if ( error )      if ( error )
# Line 388  Line 388 
388      return error;      return error;
389    }    }
390    
391    
392  #include "ftzopen.c"  #include "ftzopen.c"
393    
394    

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26