ReactOS 0.4.16-dev-122-g325d74c
ftzopen.h File Reference
#include <ft2build.h>
Include dependency graph for ftzopen.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  FT_LzwStateRec_
 

Macros

#define FT_LZW_IN_BUFF_SIZE   64
 
#define FT_LZW_DEFAULT_STACK_SIZE   64
 
#define LZW_INIT_BITS   9
 
#define LZW_MAX_BITS   16
 
#define LZW_CLEAR   256
 
#define LZW_FIRST   257
 
#define LZW_BIT_MASK   0x1F
 
#define LZW_BLOCK_MASK   0x80
 
#define LZW_MASK(n)   ( ( 1U << (n) ) - 1U )
 

Typedefs

typedef enum FT_LzwPhase_ FT_LzwPhase
 
typedef struct FT_LzwStateRec_ FT_LzwStateRec
 
typedef struct FT_LzwStateRec_FT_LzwState
 

Enumerations

enum  FT_LzwPhase_ { FT_LZW_PHASE_START = 0 , FT_LZW_PHASE_CODE , FT_LZW_PHASE_STACK , FT_LZW_PHASE_EOF }
 

Functions

 ft_lzwstate_init (FT_LzwState state, FT_Stream source)
 
 ft_lzwstate_done (FT_LzwState state)
 
 ft_lzwstate_reset (FT_LzwState state)
 
 ft_lzwstate_io (FT_LzwState state, FT_Byte *buffer, FT_ULong out_size)
 

Macro Definition Documentation

◆ FT_LZW_DEFAULT_STACK_SIZE

#define FT_LZW_DEFAULT_STACK_SIZE   64

Definition at line 37 of file ftzopen.h.

◆ FT_LZW_IN_BUFF_SIZE

#define FT_LZW_IN_BUFF_SIZE   64

Definition at line 36 of file ftzopen.h.

◆ LZW_BIT_MASK

#define LZW_BIT_MASK   0x1F

Definition at line 45 of file ftzopen.h.

◆ LZW_BLOCK_MASK

#define LZW_BLOCK_MASK   0x80

Definition at line 46 of file ftzopen.h.

◆ LZW_CLEAR

#define LZW_CLEAR   256

Definition at line 42 of file ftzopen.h.

◆ LZW_FIRST

#define LZW_FIRST   257

Definition at line 43 of file ftzopen.h.

◆ LZW_INIT_BITS

#define LZW_INIT_BITS   9

Definition at line 39 of file ftzopen.h.

◆ LZW_MASK

#define LZW_MASK (   n)    ( ( 1U << (n) ) - 1U )

Definition at line 47 of file ftzopen.h.

◆ LZW_MAX_BITS

#define LZW_MAX_BITS   16

Definition at line 40 of file ftzopen.h.

Typedef Documentation

◆ FT_LzwPhase

◆ FT_LzwState

◆ FT_LzwStateRec

Enumeration Type Documentation

◆ FT_LzwPhase_

Enumerator
FT_LZW_PHASE_START 
FT_LZW_PHASE_CODE 
FT_LZW_PHASE_STACK 
FT_LZW_PHASE_EOF 

Definition at line 50 of file ftzopen.h.

51 {
56
@ FT_LZW_PHASE_EOF
Definition: ftzopen.h:55
@ FT_LZW_PHASE_CODE
Definition: ftzopen.h:53
@ FT_LZW_PHASE_STACK
Definition: ftzopen.h:54
@ FT_LZW_PHASE_START
Definition: ftzopen.h:52
enum FT_LzwPhase_ FT_LzwPhase

Function Documentation

◆ ft_lzwstate_done()

ft_lzwstate_done ( FT_LzwState  state)

Definition at line 228 of file ftzopen.c.

229 {
230 FT_Memory memory = state->memory;
231
232
234
235 if ( state->stack != state->stack_0 )
236 FT_FREE( state->stack );
237
238 FT_FREE( state->prefix );
239 state->suffix = NULL;
240
241 FT_ZERO( state );
242 }
static int state
Definition: maze.c:121
#define NULL
Definition: types.h:112
#define FT_FREE(ptr)
Definition: ftmemory.h:329
#define FT_ZERO(p)
Definition: ftmemory.h:237
typedefFT_BEGIN_HEADER struct FT_MemoryRec_ * FT_Memory
Definition: ftsystem.h:66
ft_lzwstate_reset(FT_LzwState state)
Definition: ftzopen.c:194
static char memory[1024 *256]
Definition: process.c:116

◆ ft_lzwstate_init()

ft_lzwstate_init ( FT_LzwState  state,
FT_Stream  source 
)

Definition at line 208 of file ftzopen.c.

210 {
211 FT_ZERO( state );
212
213 state->source = source;
214 state->memory = source->memory;
215
216 state->prefix = NULL;
217 state->suffix = NULL;
218 state->prefix_size = 0;
219
220 state->stack = state->stack_0;
221 state->stack_size = sizeof ( state->stack_0 );
222
224 }

◆ ft_lzwstate_io()

ft_lzwstate_io ( FT_LzwState  state,
FT_Byte buffer,
FT_ULong  out_size 
)

Definition at line 256 of file ftzopen.c.

259 {
260 FT_ULong result = 0;
261
262 FT_UInt old_char = state->old_char;
263 FT_UInt old_code = state->old_code;
264 FT_UInt in_code = state->in_code;
265
266
267 if ( out_size == 0 )
268 goto Exit;
269
270 switch ( state->phase )
271 {
273 {
274 FT_Byte max_bits;
275 FT_Int32 c;
276
277
278 /* skip magic bytes, and read max_bits + block_flag */
279 if ( FT_Stream_Seek( state->source, 2 ) != 0 ||
280 FT_Stream_TryRead( state->source, &max_bits, 1 ) != 1 )
281 goto Eof;
282
283 state->max_bits = max_bits & LZW_BIT_MASK;
284 state->block_mode = max_bits & LZW_BLOCK_MASK;
285 state->max_free = (FT_UInt)( ( 1UL << state->max_bits ) - 256 );
286
287 if ( state->max_bits > LZW_MAX_BITS )
288 goto Eof;
289
290 state->num_bits = LZW_INIT_BITS;
291 state->free_ent = ( state->block_mode ? LZW_FIRST
292 : LZW_CLEAR ) - 256;
293 in_code = 0;
294
295 state->free_bits = state->num_bits < state->max_bits
296 ? (FT_UInt)( ( 1UL << state->num_bits ) - 256 )
297 : state->max_free + 1;
298
300 if ( c < 0 || c > 255 )
301 goto Eof;
302
303 old_code = old_char = (FT_UInt)c;
304
305 if ( buffer )
306 buffer[result] = (FT_Byte)old_char;
307
308 if ( ++result >= out_size )
309 goto Exit;
310
311 state->phase = FT_LZW_PHASE_CODE;
312 }
313 /* fall-through */
314
316 {
317 FT_Int32 c;
319
320
321 NextCode:
323 if ( c < 0 )
324 goto Eof;
325
326 code = (FT_UInt)c;
327
328 if ( code == LZW_CLEAR && state->block_mode )
329 {
330 /* why not LZW_FIRST-256 ? */
331 state->free_ent = ( LZW_FIRST - 1 ) - 256;
332 state->buf_clear = 1;
333
334 /* not quite right, but at least more predictable */
335 old_code = 0;
336 old_char = 0;
337
338 goto NextCode;
339 }
340
341 in_code = code; /* save code for later */
342
343 if ( code >= 256U )
344 {
345 /* special case for KwKwKwK */
346 if ( code - 256U >= state->free_ent )
347 {
348 /* corrupted LZW stream */
349 if ( code - 256U > state->free_ent )
350 goto Eof;
351
352 FTLZW_STACK_PUSH( old_char );
353 code = old_code;
354 }
355
356 while ( code >= 256U )
357 {
358 if ( !state->prefix )
359 goto Eof;
360
361 FTLZW_STACK_PUSH( state->suffix[code - 256] );
362 code = state->prefix[code - 256];
363 }
364 }
365
366 old_char = code;
367 FTLZW_STACK_PUSH( old_char );
368
369 state->phase = FT_LZW_PHASE_STACK;
370 }
371 /* fall-through */
372
374 {
375 while ( state->stack_top > 0 )
376 {
377 state->stack_top--;
378
379 if ( buffer )
380 buffer[result] = state->stack[state->stack_top];
381
382 if ( ++result == out_size )
383 goto Exit;
384 }
385
386 /* now create new entry */
387 if ( state->free_ent < state->max_free )
388 {
389 if ( state->free_ent >= state->prefix_size &&
391 goto Eof;
392
393 FT_ASSERT( state->free_ent < state->prefix_size );
394
395 state->prefix[state->free_ent] = (FT_UShort)old_code;
396 state->suffix[state->free_ent] = (FT_Byte) old_char;
397
398 state->free_ent += 1;
399 }
400
401 old_code = in_code;
402
403 state->phase = FT_LZW_PHASE_CODE;
404 goto NextCode;
405 }
406
407 default: /* state == EOF */
408 ;
409 }
410
411 Exit:
412 state->old_code = old_code;
413 state->old_char = old_char;
414 state->in_code = in_code;
415
416 return result;
417
418 Eof:
419 state->phase = FT_LZW_PHASE_EOF;
420 goto Exit;
421 }
@ Eof
Definition: asmpp.cpp:31
#define FT_ASSERT(condition)
Definition: ftdebug.h:211
FT_Stream_TryRead(FT_Stream stream, FT_Byte *buffer, FT_ULong count)
Definition: ftstream.c:164
FT_Stream_Seek(FT_Stream stream, FT_ULong pos)
Definition: ftstream.c:57
unsigned long FT_ULong
Definition: fttypes.h:253
unsigned char FT_Byte
Definition: fttypes.h:154
unsigned short FT_UShort
Definition: fttypes.h:209
unsigned int FT_UInt
Definition: fttypes.h:231
#define FTLZW_STACK_PUSH(c)
Definition: ftzopen.c:245
static int ft_lzwstate_prefix_grow(FT_LzwState state)
Definition: ftzopen.c:156
static FT_Int32 ft_lzwstate_get_code(FT_LzwState state)
Definition: ftzopen.c:60
#define LZW_CLEAR
Definition: ftzopen.h:42
#define LZW_BLOCK_MASK
Definition: ftzopen.h:46
#define LZW_BIT_MASK
Definition: ftzopen.h:45
#define LZW_INIT_BITS
Definition: ftzopen.h:39
#define LZW_FIRST
Definition: ftzopen.h:43
#define LZW_MAX_BITS
Definition: ftzopen.h:40
GLuint buffer
Definition: glext.h:5915
const GLubyte * c
Definition: glext.h:8905
GLuint64EXT * result
Definition: glext.h:11304
#define c
Definition: ke_i.h:80
static HANDLE PIO_APC_ROUTINE PVOID PIO_STATUS_BLOCK ULONG PVOID ULONG PVOID ULONG out_size
Definition: file.c:100
static void Exit(void)
Definition: sock.c:1330
Definition: inflate.c:139

◆ ft_lzwstate_reset()

ft_lzwstate_reset ( FT_LzwState  state)

Definition at line 194 of file ftzopen.c.

195 {
196 state->in_eof = 0;
197 state->buf_offset = 0;
198 state->buf_size = 0;
199 state->buf_clear = 0;
200 state->buf_total = 0;
201 state->stack_top = 0;
202 state->num_bits = LZW_INIT_BITS;
203 state->phase = FT_LZW_PHASE_START;
204 }

Referenced by ft_lzwstate_done(), and ft_lzwstate_init().