misc/libfreetype/src/lzw/ftzopen.h
author sheepluva
Thu, 03 May 2012 14:21:53 +0200
changeset 7017 19a434fc91fc
parent 5172 88f2e05288ba
permissions -rw-r--r--
visually indicate when map preview generation is in progress.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5172
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     1
/***************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     2
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     3
/*  ftzopen.h                                                              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     4
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     5
/*    FreeType support for .Z compressed files.                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     6
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     7
/*  This optional component relies on NetBSD's zopen().  It should mainly  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     8
/*  be used to parse compressed PCF fonts, as found with many X11 server   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     9
/*  distributions.                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    10
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    11
/*  Copyright 2005, 2006, 2007, 2008 by David Turner.                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    12
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    13
/*  This file is part of the FreeType project, and may only be used,       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    14
/*  modified, and distributed under the terms of the FreeType project      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    15
/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    16
/*  this file you indicate that you have read the license and              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    17
/*  understand and accept it fully.                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    18
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    19
/***************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    20
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    21
#ifndef __FT_ZOPEN_H__
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    22
#define __FT_ZOPEN_H__
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    23
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    24
#include <ft2build.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    25
#include FT_FREETYPE_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    26
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    27
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    28
  /*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    29
   *  This is a complete re-implementation of the LZW file reader,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    30
   *  since the old one was incredibly badly written, using
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    31
   *  400 KByte of heap memory before decompressing anything.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    32
   *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    33
   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    34
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    35
#define FT_LZW_IN_BUFF_SIZE        64
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    36
#define FT_LZW_DEFAULT_STACK_SIZE  64
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    37
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    38
#define LZW_INIT_BITS     9
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    39
#define LZW_MAX_BITS      16
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    40
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    41
#define LZW_CLEAR         256
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    42
#define LZW_FIRST         257
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    43
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    44
#define LZW_BIT_MASK      0x1f
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    45
#define LZW_BLOCK_MASK    0x80
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    46
#define LZW_MASK( n )     ( ( 1U << (n) ) - 1U )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    47
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    48
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    49
  typedef enum  FT_LzwPhase_
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    50
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    51
    FT_LZW_PHASE_START = 0,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    52
    FT_LZW_PHASE_CODE,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    53
    FT_LZW_PHASE_STACK,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    54
    FT_LZW_PHASE_EOF
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    55
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    56
  } FT_LzwPhase;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    57
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    58
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    59
  /*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    60
   *  state of LZW decompressor
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    61
   *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    62
   *  small technical note
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    63
   *  --------------------
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    64
   *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    65
   *  We use a few tricks in this implementation that are explained here to
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    66
   *  ease debugging and maintenance.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    67
   *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    68
   *  - First of all, the `prefix' and `suffix' arrays contain the suffix
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    69
   *    and prefix for codes over 256; this means that
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    70
   *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    71
   *      prefix_of(code) == state->prefix[code-256]
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    72
   *      suffix_of(code) == state->suffix[code-256]
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    73
   *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    74
   *    Each prefix is a 16-bit code, and each suffix an 8-bit byte.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    75
   *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    76
   *    Both arrays are stored in a single memory block, pointed to by
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    77
   *    `state->prefix'.  This means that the following equality is always
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    78
   *    true:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    79
   *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    80
   *      state->suffix == (FT_Byte*)(state->prefix + state->prefix_size)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    81
   *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    82
   *    Of course, state->prefix_size is the number of prefix/suffix slots
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    83
   *    in the arrays, corresponding to codes 256..255+prefix_size.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    84
   *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    85
   *  - `free_ent' is the index of the next free entry in the `prefix'
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    86
   *    and `suffix' arrays.  This means that the corresponding `next free
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    87
   *    code' is really `256+free_ent'.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    88
   *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    89
   *    Moreover, `max_free' is the maximum value that `free_ent' can reach.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    90
   *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    91
   *    `max_free' corresponds to `(1 << max_bits) - 256'.  Note that this
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    92
   *    value is always <= 0xFF00, which means that both `free_ent' and
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    93
   *    `max_free' can be stored in an FT_UInt variable, even on 16-bit
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    94
   *    machines.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    95
   *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    96
   *    If `free_ent == max_free', you cannot add new codes to the
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    97
   *    prefix/suffix table.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    98
   *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    99
   *  - `num_bits' is the current number of code bits, starting at 9 and
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   100
   *    growing each time `free_ent' reaches the value of `free_bits'.  The
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   101
   *    latter is computed as follows
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   102
   *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   103
   *      if num_bits < max_bits:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   104
   *         free_bits = (1 << num_bits)-256
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   105
   *      else:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   106
   *         free_bits = max_free + 1
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   107
   *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   108
   *    Since the value of `max_free + 1' can never be reached by
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   109
   *    `free_ent', `num_bits' cannot grow larger than `max_bits'.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   110
   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   111
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   112
  typedef struct  FT_LzwStateRec_
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   113
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   114
    FT_LzwPhase  phase;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   115
    FT_Int       in_eof;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   116
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   117
    FT_Byte      buf_tab[16];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   118
    FT_Int       buf_offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   119
    FT_Int       buf_size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   120
    FT_Bool      buf_clear;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   121
    FT_Offset    buf_total;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   122
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   123
    FT_UInt      max_bits;    /* max code bits, from file header   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   124
    FT_Int       block_mode;  /* block mode flag, from file header */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   125
    FT_UInt      max_free;    /* (1 << max_bits) - 256             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   126
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   127
    FT_UInt      num_bits;    /* current code bit number */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   128
    FT_UInt      free_ent;    /* index of next free entry */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   129
    FT_UInt      free_bits;   /* if reached by free_ent, increment num_bits */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   130
    FT_UInt      old_code;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   131
    FT_UInt      old_char;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   132
    FT_UInt      in_code;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   133
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   134
    FT_UShort*   prefix;      /* always dynamically allocated / reallocated */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   135
    FT_Byte*     suffix;      /* suffix = (FT_Byte*)(prefix + prefix_size)  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   136
    FT_UInt      prefix_size; /* number of slots in `prefix' or `suffix'    */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   137
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   138
    FT_Byte*     stack;       /* character stack */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   139
    FT_UInt      stack_top;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   140
    FT_Offset    stack_size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   141
    FT_Byte      stack_0[FT_LZW_DEFAULT_STACK_SIZE]; /* minimize heap alloc */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   142
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   143
    FT_Stream    source;      /* source stream */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   144
    FT_Memory    memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   145
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   146
  } FT_LzwStateRec, *FT_LzwState;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   147
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   148
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   149
  FT_LOCAL( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   150
  ft_lzwstate_init( FT_LzwState  state,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   151
                    FT_Stream    source );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   152
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   153
  FT_LOCAL( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   154
  ft_lzwstate_done( FT_LzwState  state );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   155
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   156
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   157
  FT_LOCAL( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   158
  ft_lzwstate_reset( FT_LzwState  state );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   159
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   160
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   161
  FT_LOCAL( FT_ULong )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   162
  ft_lzwstate_io( FT_LzwState  state,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   163
                  FT_Byte*     buffer,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   164
                  FT_ULong     out_size );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   165
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   166
/* */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   167
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   168
#endif /* __FT_ZOPEN_H__ */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   169
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   170
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   171
/* END */