comparison srf2fastq/io_lib-1.12.2/io_lib/deflate_interlaced.h @ 0:d901c9f41a6a default tip

Migrated tool version 1.0.1 from old tool shed archive to new tool shed repository
author dawe
date Tue, 07 Jun 2011 17:48:05 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:d901c9f41a6a
1 #ifndef _DEFLATE_SIMPLE_H_
2 #define _DEFLATE_SIMPLE_H_
3
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
7
8 /* inlined codes */
9 #define CODE_INLINE 0
10
11 /* predefined codes */
12 #define CODE_DNA 1 /* DNA, uppercase only */
13 #define CODE_DNA_AMBIG 2 /* DNA, uc with ambiguity codes */
14 #define CODE_ENGLISH 3 /* English text */
15 #define NCODES_STATIC 4 /* Cheat, but we count from 0 for ease */
16
17 /* predefined elsewhere in HUFF chunks, 128 onwards */
18 #define CODE_USER 128
19
20 #define MAX_CODE_LEN 15 /* maximum allowed by RFC 1951 */
21
22 #ifndef ZTR_FORM_STHUFF
23 # define ZTR_FORM_STHUFF 77
24 #endif
25
26 /* A single symbol and it's encoding */
27 typedef struct {
28 signed int symbol; /* 0-255 character, 256 = exception code, 257 = EOF */
29 int nbits;
30 unsigned int code;
31 int freq;
32 } huffman_code_t;
33
34 /* A collection of huffman_code_t along with decoding optimisations */
35 typedef struct {
36 huffman_code_t *codes;
37 int ncodes;
38 int codes_static;
39 huffman_code_t lookup[258]; /* Mapping of symbol character to code */
40 int max_code_len;
41 } huffman_codes_t;
42
43 /* Use for store_bits() and get_bits() */
44 typedef struct block {
45 unsigned char *data;
46 size_t alloc;
47 size_t byte;
48 int bit;
49 } block_t;
50
51 /* Tree and jump-table data structures used for fast decoding. */
52 typedef struct {
53 /* Graph construction */
54 unsigned short c[2]; /* child node */
55 signed short l[2]; /* symbol to emit on transition. -1 => none */
56 } htree_t;
57
58 typedef struct {
59 /* Byte-wise jumping table */
60 unsigned short jump;
61 unsigned char symbol[4];
62 unsigned char nsymbols;
63 unsigned char top_bit; /* bit 9 of symbol[] */
64 } h_jump4_t;
65
66
67 /* A collection of huffman_codes_t, for use with the multi-code codec */
68 typedef struct {
69 huffman_codes_t **codes;
70 int ncodes;
71 int code_set; /* (128-255) The user specified number for this encoding */
72
73 /* Cached binary version of codeset, assumes last block */
74 block_t *blk;
75 int bit_num; /* if 1st block, which bit will stored codes end on */
76
77 /* Cache huffman_multi_decode parameters */
78 h_jump4_t (*decode_J4)[16];
79 htree_t *decode_t;
80 } huffman_codeset_t;
81
82 block_t *block_create(unsigned char *data, size_t size);
83 void block_destroy(block_t *blk, int keep_data);
84 int block_resize(block_t *blk, size_t size);
85 void store_bytes(block_t *block, unsigned char *val, int nbytes);
86
87
88 int huffman_encode(block_t *blk, huffman_codes_t *c, int code_set,
89 unsigned char *data, int len);
90
91 block_t *huffman_decode(block_t *in, huffman_codes_t *c);
92
93 int huffman_multi_encode(block_t *blk, huffman_codeset_t *cs,
94 int code_set, unsigned char *data, int len);
95
96 block_t *huffman_multi_decode(block_t *in, huffman_codeset_t *cs);
97
98 huffman_codeset_t *codes2codeset(huffman_code_t *codes, int ncodes,
99 int code_num);
100 huffman_codeset_t *generate_code_set(int code_set, int ncodes,
101 unsigned char *data, int len,
102 int eof, int max_code_len,
103 int all_codes);
104
105 int store_codes(block_t *out,
106 huffman_codeset_t *c,
107 int last_block);
108 huffman_codeset_t *restore_codes(block_t *block, int *bfinal);
109 void huffman_codes_destroy(huffman_codes_t *c);
110 void huffman_codeset_destroy(huffman_codeset_t *cs);
111
112 #ifdef __cplusplus
113 }
114 #endif
115
116 #endif /* _DEFLATE_SIMPLE_H_ */