FreeBASIC  0.91.0
fb_gfx_lzw.h
Go to the documentation of this file.
1 /* tiny LZW codec,
2  Based on code by Mark Nelson, Dr. Dobb's Journal October, 1989 */
3 
4 #ifndef __FB_GFX_LZW_H__
5 #define __FB_GFX_LZW_H__
6 
7 
8 #define MAX_CODE 4095
9 #define TABLE_SIZE 5021
10 
11 #define OUTPUT_CODE(c) \
12 { \
13  if (bit) { \
14  *out_buffer++ |= (c & 0xF) << 4; \
15  *out_buffer++ = c >> 4; \
16  size++; \
17  } \
18  else { \
19  *out_buffer++ = c & 0xFF; \
20  *out_buffer = c >> 8; \
21  } \
22  size++; \
23  if (size >= *out_size) \
24  return -1; \
25  bit ^= 1; \
26 }
27 
28 #define INPUT_CODE(c) \
29 { \
30  if (bit) { \
31  c = *in_buffer++ >> 4; \
32  c |= *in_buffer++ << 4; \
33  in_size--; \
34  } \
35  else { \
36  c = *in_buffer++; \
37  c |= (*in_buffer & 0xF) << 8; \
38  } \
39  in_size--; \
40  bit ^= 1; \
41 }
42 
43 
44 typedef struct LZW_ENTRY
45 {
46  short code;
47  unsigned short prefix;
48  unsigned char value;
49 } LZW_ENTRY;
50 
52 
53 #endif