Visualization Library 2.0.0-b5

A lightweight C++ OpenGL middleware for 2D/3D graphics

VL     Star     Watch     Fork     Issue

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